add editor
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
"pages/main/journal/index",
|
||||
"pages/main/journal-creater/index",
|
||||
"pages/main/journal-search/index",
|
||||
"pages/main/journal-editor/index",
|
||||
"pages/main/portfolio/index",
|
||||
"pages/main/travel/index",
|
||||
"pages/main/about/index",
|
||||
|
||||
@ -94,6 +94,7 @@ Component<JournalListData, {}, {}, ComponentInstance>({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/** 重置搜索页面 */
|
||||
resetPage() {
|
||||
const likeExample = this.data.searchValue ? {
|
||||
idea: this.data.searchValue,
|
||||
@ -116,6 +117,7 @@ Component<JournalListData, {}, {}, ComponentInstance>({
|
||||
isFinished: false
|
||||
});
|
||||
},
|
||||
/** 获取数据 */
|
||||
fetch() {
|
||||
if (this.data.isFetching || this.data.isFinished) {
|
||||
return;
|
||||
@ -159,19 +161,16 @@ Component<JournalListData, {}, {}, ComponentInstance>({
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 输入搜索 */
|
||||
onSearchChange(e: WechatMiniprogram.CustomEvent) {
|
||||
const value = e.detail.value.trim();
|
||||
this.setData({ searchValue: value });
|
||||
// 如果是清空操作,不使用防抖(clear 事件会处理)
|
||||
if (value === "" && this.debouncedSearch) {
|
||||
this.debouncedSearch.cancel();
|
||||
return;
|
||||
}
|
||||
// 使用防抖自动搜索
|
||||
// 使用防抖自动搜索(包括清空的情况)
|
||||
if (this.debouncedSearch) {
|
||||
this.debouncedSearch(value);
|
||||
}
|
||||
},
|
||||
/** 提交搜索 */
|
||||
onSearchSubmit(e: WechatMiniprogram.CustomEvent) {
|
||||
const value = e.detail.value.trim();
|
||||
// 立即搜索,取消防抖
|
||||
@ -180,6 +179,7 @@ Component<JournalListData, {}, {}, ComponentInstance>({
|
||||
}
|
||||
this.resetAndSearch(value);
|
||||
},
|
||||
/** 清空搜索 */
|
||||
onSearchClear() {
|
||||
// 取消防抖,立即搜索
|
||||
if (this.debouncedSearch) {
|
||||
@ -187,6 +187,11 @@ Component<JournalListData, {}, {}, ComponentInstance>({
|
||||
}
|
||||
this.resetAndSearch("");
|
||||
},
|
||||
/** 保留搜索关键字重新搜索 */
|
||||
reSearch() {
|
||||
this.resetAndSearch(this.data.searchValue);
|
||||
},
|
||||
/** 重置配置重新搜索 */
|
||||
resetAndSearch(keyword: string) {
|
||||
const likeExample = keyword ? {
|
||||
idea: keyword,
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="label">版本:</text>
|
||||
<text>1.4.0</text>
|
||||
<text>1.5.0</text>
|
||||
</view>
|
||||
<view class="item copyright">
|
||||
<text>{{copyright}}</text>
|
||||
|
||||
10
miniprogram/pages/main/journal-editor/index.json
Normal file
10
miniprogram/pages/main/journal-editor/index.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-dialog": "tdesign-miniprogram/dialog/dialog",
|
||||
"t-input": "tdesign-miniprogram/input/input"
|
||||
}
|
||||
}
|
||||
134
miniprogram/pages/main/journal-editor/index.less
Normal file
134
miniprogram/pages/main/journal-editor/index.less
Normal file
@ -0,0 +1,134 @@
|
||||
/* pages/main/journal-editor/index.wxss */
|
||||
.container {
|
||||
|
||||
.content {
|
||||
width: calc(100% - 64px);
|
||||
padding: 0 32px 32px 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
|
||||
.loading {
|
||||
padding: 64px 0;
|
||||
text-align: center;
|
||||
color: var(--theme-text-secondary);
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--theme-text-secondary);
|
||||
}
|
||||
|
||||
.section {
|
||||
width: 100%;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
&.time {
|
||||
display: flex;
|
||||
|
||||
.picker {
|
||||
margin-right: .25rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.media {
|
||||
|
||||
.gallery {
|
||||
gap: 10rpx;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
.item {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: var(--theme-bg-card);
|
||||
box-shadow: 1px 1px 6px var(--theme-shadow-light);
|
||||
border-radius: 2rpx;
|
||||
|
||||
&.add {
|
||||
color: var(--theme-wx);
|
||||
margin: 0;
|
||||
font-size: 80rpx;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
height: 200rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.video-container {
|
||||
position: relative;
|
||||
|
||||
|
||||
.play-icon {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
color: rgba(255, 255, 255, .8);
|
||||
z-index: 2;
|
||||
position: absolute;
|
||||
font-size: 128rpx;
|
||||
transform: translate(-50%, -50%);
|
||||
text-shadow: 4rpx 4rpx 0 rgba(0, 0, 0, .5);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.delete {
|
||||
top: 10rpx;
|
||||
right: 10rpx;
|
||||
color: rgba(0, 0, 0, .7);
|
||||
z-index: 3;
|
||||
position: absolute;
|
||||
font-size: 45rpx;
|
||||
}
|
||||
|
||||
.new-badge {
|
||||
top: 10rpx;
|
||||
left: 10rpx;
|
||||
color: var(--theme-wx);
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
position: absolute;
|
||||
font-size: 45rpx;
|
||||
text-shadow: 4rpx 4rpx 0 rgba(0, 0, 0, .5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.progress {
|
||||
width: 100%;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.ctrl {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
margin-top: 1rem;
|
||||
align-items: center;
|
||||
|
||||
.delete {
|
||||
width: 200rpx;
|
||||
}
|
||||
|
||||
.save {
|
||||
flex: 1;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.delete-dialog {
|
||||
padding: 16rpx 0;
|
||||
|
||||
.tips {
|
||||
color: var(--theme-text-secondary);
|
||||
font-size: 28rpx;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
}
|
||||
382
miniprogram/pages/main/journal-editor/index.ts
Normal file
382
miniprogram/pages/main/journal-editor/index.ts
Normal file
@ -0,0 +1,382 @@
|
||||
// pages/main/journal-editor/index.ts
|
||||
import Events from "../../../utils/Events";
|
||||
import Time from "../../../utils/Time";
|
||||
import Toolkit from "../../../utils/Toolkit";
|
||||
import config from "../../../config/index";
|
||||
import { Location, MediaItem, MediaItemType, WechatMediaItem } from "../../../types/UI";
|
||||
import { Journal } from "../../../types/Journal";
|
||||
import { MediaAttachExt, MediaAttachType } from "../../../types/Attachment";
|
||||
|
||||
interface JournalEditorData {
|
||||
id?: number;
|
||||
idea: string;
|
||||
date: string;
|
||||
time: string;
|
||||
mediaList: MediaItem[];
|
||||
newMediaList: WechatMediaItem[];
|
||||
location?: Location;
|
||||
isAuthLocation: boolean;
|
||||
isLoading: boolean;
|
||||
saveText: string;
|
||||
isSaving: boolean;
|
||||
saveProgress: number;
|
||||
mediaItemTypeEnum: any;
|
||||
deleteDialogVisible: boolean;
|
||||
deleteConfirmText: string;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: <JournalEditorData>{
|
||||
id: undefined,
|
||||
idea: "",
|
||||
date: "2025-06-28",
|
||||
time: "16:00",
|
||||
mediaList: [],
|
||||
newMediaList: [],
|
||||
location: undefined,
|
||||
saveText: "保存",
|
||||
isSaving: false,
|
||||
saveProgress: 0,
|
||||
isLoading: true,
|
||||
mediaItemTypeEnum: {
|
||||
...MediaItemType
|
||||
},
|
||||
isAuthLocation: false,
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
},
|
||||
async onLoad(options: any) {
|
||||
// 授权定位
|
||||
const setting = await wx.getSetting();
|
||||
wx.setStorageSync("isAuthLocation", setting.authSetting["scope.userLocation"]);
|
||||
let isAuthLocation = JSON.parse(wx.getStorageSync("isAuthLocation"));
|
||||
this.setData({ isAuthLocation });
|
||||
if (!isAuthLocation) {
|
||||
wx.authorize({
|
||||
scope: "scope.userLocation"
|
||||
}).then(() => {
|
||||
isAuthLocation = true;
|
||||
this.setData({ isAuthLocation });
|
||||
});
|
||||
}
|
||||
// 获取日记 ID
|
||||
const id = options.id ? parseInt(options.id) : undefined;
|
||||
if (!id) {
|
||||
wx.showToast({
|
||||
title: "缺少日志 ID",
|
||||
icon: "error"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
this.setData({ id });
|
||||
await this.loadJournalDetail(id);
|
||||
},
|
||||
/** 加载日记详情 */
|
||||
async loadJournalDetail(id: number) {
|
||||
wx.showLoading({ title: "加载中...", mask: true });
|
||||
try {
|
||||
const journal: Journal = await new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: `${config.url}/journal/${id}`,
|
||||
method: "POST",
|
||||
header: {
|
||||
Key: wx.getStorageSync("key")
|
||||
},
|
||||
success: (res: any) => {
|
||||
if (res.data.code === 20000) {
|
||||
resolve(res.data.data);
|
||||
} else {
|
||||
reject(new Error(res.data.message || "加载失败"));
|
||||
}
|
||||
},
|
||||
fail: reject
|
||||
});
|
||||
});
|
||||
const items = journal.items || [];
|
||||
const thumbItems = items.filter((item) => item.attachType === MediaAttachType.THUMB);
|
||||
|
||||
const mediaList: MediaItem[] = thumbItems.map((thumbItem) => {
|
||||
const ext = thumbItem.ext = JSON.parse(thumbItem.ext!.toString()) as MediaAttachExt;
|
||||
const thumbURL = `${config.url}/attachment/read/${thumbItem.mongoId}`;
|
||||
const sourceURL = `${config.url}/attachment/read/${ext.sourceMongoId}`;
|
||||
return {
|
||||
type: ext.isVideo ? MediaItemType.VIDEO : MediaItemType.IMAGE,
|
||||
thumbURL,
|
||||
sourceURL,
|
||||
size: thumbItem.size || 0,
|
||||
attachmentId: thumbItem.id
|
||||
} as MediaItem;
|
||||
});
|
||||
this.setData({
|
||||
idea: journal.idea || "",
|
||||
date: Time.toDate(journal.createdAt),
|
||||
time: Time.toTime(journal.createdAt),
|
||||
location: journal.location ? {
|
||||
lat: journal.lat,
|
||||
lng: journal.lng,
|
||||
text: journal.location
|
||||
} : undefined,
|
||||
mediaList,
|
||||
isLoading: false
|
||||
});
|
||||
wx.hideLoading();
|
||||
} catch (err: any) {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: err.message || "加载失败",
|
||||
icon: "error"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
}
|
||||
},
|
||||
/** 选择位置 */
|
||||
async chooseLocation() {
|
||||
const location = await wx.chooseLocation({});
|
||||
this.setData({
|
||||
location: {
|
||||
lat: location.latitude,
|
||||
lng: location.longitude,
|
||||
text: location.name
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 新增附件 */
|
||||
addMedia() {
|
||||
const that = this;
|
||||
wx.chooseMedia({
|
||||
mediaType: ["mix"],
|
||||
sourceType: ["album", "camera"],
|
||||
camera: "back",
|
||||
success(res) {
|
||||
wx.showLoading({
|
||||
title: "加载中..",
|
||||
mask: true
|
||||
});
|
||||
const tempFiles = res.tempFiles;
|
||||
const newMedia = tempFiles.map(item => {
|
||||
return {
|
||||
type: (<any>MediaItemType)[item.fileType.toUpperCase()],
|
||||
path: item.tempFilePath,
|
||||
thumbPath: item.thumbTempFilePath,
|
||||
size: item.size,
|
||||
duration: item.duration,
|
||||
raw: item
|
||||
} as WechatMediaItem;
|
||||
});
|
||||
that.setData({
|
||||
newMediaList: [...that.data.newMediaList, ...newMedia]
|
||||
});
|
||||
wx.hideLoading();
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 预览附件 */
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const isNewMedia = e.currentTarget.dataset.newMedia;
|
||||
const index = e.currentTarget.dataset.index;
|
||||
|
||||
const sources = this.data.mediaList.map(item => ({
|
||||
url: item.sourceURL,
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
const newSources = this.data.newMediaList.map(item => ({
|
||||
url: item.path,
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
const allSources = [...sources, ...newSources];
|
||||
const currentIndex = isNewMedia ? this.data.mediaList.length + index : index;
|
||||
wx.previewMedia({
|
||||
current: currentIndex,
|
||||
sources: allSources as WechatMiniprogram.MediaSource[]
|
||||
});
|
||||
},
|
||||
/** 删除附件 */
|
||||
deleteMedia(e: WechatMiniprogram.BaseEvent) {
|
||||
const isNewMedia = e.currentTarget.dataset.newMedia;
|
||||
const index = e.currentTarget.dataset.index;
|
||||
if (isNewMedia) {
|
||||
const mediaList = [...this.data.mediaList];
|
||||
mediaList.splice(index, 1);
|
||||
this.setData({ mediaList });
|
||||
} else {
|
||||
const newMediaList = [...this.data.newMediaList];
|
||||
newMediaList.splice(index, 1);
|
||||
this.setData({ newMediaList });
|
||||
}
|
||||
},
|
||||
/** 取消编辑 */
|
||||
cancel() {
|
||||
wx.navigateBack();
|
||||
},
|
||||
/** 删除记录 */
|
||||
deleteJournal() {
|
||||
this.setData({
|
||||
deleteDialogVisible: true,
|
||||
deleteConfirmText: ""
|
||||
});
|
||||
},
|
||||
/** 取消删除 */
|
||||
cancelDelete() {
|
||||
this.setData({
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
});
|
||||
},
|
||||
/** 确认删除 */
|
||||
confirmDelete() {
|
||||
const inputText = this.data.deleteConfirmText.trim();
|
||||
if (inputText !== "确认删除") {
|
||||
wx.showToast({
|
||||
title: "输入不匹配",
|
||||
icon: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
deleteDialogVisible: false
|
||||
});
|
||||
this.executeDelete();
|
||||
},
|
||||
/** 执行删除 */
|
||||
executeDelete() {
|
||||
wx.showLoading({ title: "删除中...", mask: true });
|
||||
wx.request({
|
||||
url: `${config.url}/journal/delete`,
|
||||
method: "POST",
|
||||
header: {
|
||||
Key: wx.getStorageSync("key"),
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: this.data.id,
|
||||
success: (res: any) => {
|
||||
wx.hideLoading();
|
||||
if (res.data.code === 20000 || res.statusCode === 200) {
|
||||
Events.emit("JOURNAL_REFRESH");
|
||||
Events.emit("JOURNAL_LIST_REFRESH");
|
||||
wx.showToast({
|
||||
title: "删除成功",
|
||||
icon: "success"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1000);
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: res.data.message || "删除失败",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: "删除失败",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 保存 */
|
||||
save() {
|
||||
const handleFail = () => {
|
||||
wx.showToast({ title: "保存失败", icon: "error" });
|
||||
this.setData({
|
||||
saveText: "保存",
|
||||
isSaving: false
|
||||
});
|
||||
};
|
||||
|
||||
this.setData({
|
||||
saveText: "正在保存..",
|
||||
isSaving: true
|
||||
});
|
||||
// 收集保留的附件 ID(缩略图 ID)
|
||||
const attachmentIds = this.data.mediaList.map(item => item.attachmentId);
|
||||
// 上传新媒体文件
|
||||
const uploadFiles = new Promise<string[]>((resolve, reject) => {
|
||||
const total = this.data.newMediaList.length;
|
||||
let completed = 0;
|
||||
if (total === 0) {
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
saveProgress: 0,
|
||||
});
|
||||
// 上传临时文件
|
||||
const uploadPromises = this.data.newMediaList.map((item) => {
|
||||
return new Promise<string>((uploadResolve, uploadReject) => {
|
||||
wx.uploadFile({
|
||||
url: `${config.url}/temp/file/upload`,
|
||||
filePath: item.path,
|
||||
name: "file",
|
||||
success: (resp) => {
|
||||
const result = JSON.parse(resp.data);
|
||||
if (result && result.code === 20000) {
|
||||
completed++;
|
||||
// 更新进度
|
||||
this.setData({
|
||||
saveProgress: (completed / total),
|
||||
});
|
||||
uploadResolve(result.data[0].id);
|
||||
} else {
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || '未知错误'}`));
|
||||
}
|
||||
},
|
||||
fail: (err) => uploadReject(new Error(`文件上传失败: ${err.errMsg}`))
|
||||
});
|
||||
});
|
||||
});
|
||||
// 并行执行所有文件上传
|
||||
Promise.all(uploadPromises).then((tempFileIds) => {
|
||||
this.setData({
|
||||
saveProgress: 1,
|
||||
});
|
||||
resolve(tempFileIds);
|
||||
}).catch(reject);
|
||||
});
|
||||
// 提交保存
|
||||
uploadFiles.then((tempFileIds) => {
|
||||
wx.request({
|
||||
url: `${config.url}/journal/update`,
|
||||
method: "POST",
|
||||
header: {
|
||||
Key: wx.getStorageSync("key")
|
||||
},
|
||||
data: {
|
||||
id: this.data.id,
|
||||
idea: this.data.idea,
|
||||
lat: this.data.location?.lat,
|
||||
lng: this.data.location?.lng,
|
||||
location: this.data.location?.text,
|
||||
createdAt: new Date(`${this.data.date}T${this.data.time}:00`).getTime(),
|
||||
// 保留的现有附件 ID
|
||||
attachmentIds,
|
||||
// 新上传的临时文件 ID
|
||||
tempFileIds
|
||||
},
|
||||
success: async (resp: any) => {
|
||||
if (resp.data.code === 20000 || resp.statusCode === 200) {
|
||||
Events.emit("JOURNAL_REFRESH");
|
||||
Events.emit("JOURNAL_LIST_REFRESH");
|
||||
wx.showToast({ title: "保存成功", icon: "success" });
|
||||
this.setData({
|
||||
saveText: "保存",
|
||||
isSaving: false,
|
||||
});
|
||||
await Toolkit.sleep(1000);
|
||||
wx.navigateBack();
|
||||
} else {
|
||||
handleFail();
|
||||
}
|
||||
},
|
||||
fail: handleFail
|
||||
});
|
||||
}).catch(handleFail);
|
||||
}
|
||||
});
|
||||
166
miniprogram/pages/main/journal-editor/index.wxml
Normal file
166
miniprogram/pages/main/journal-editor/index.wxml
Normal file
@ -0,0 +1,166 @@
|
||||
<!--pages/main/journal-editor/index.wxml-->
|
||||
<t-navbar title="编辑记录">
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
<scroll-view
|
||||
class="container"
|
||||
type="custom"
|
||||
scroll-y
|
||||
show-scrollbar="{{false}}"
|
||||
scroll-into-view="{{intoView}}"
|
||||
>
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<view class="section">
|
||||
<textarea
|
||||
class="idea"
|
||||
placeholder="这一刻的想法..."
|
||||
model:value="{{idea}}"
|
||||
/>
|
||||
</view>
|
||||
<view class="section time">
|
||||
<text class="label">时间:</text>
|
||||
<picker class="picker" mode="date" model:value="{{date}}">
|
||||
<view class="picker">
|
||||
{{date}}
|
||||
</view>
|
||||
</picker>
|
||||
<picker class="picker" mode="time" model:value="{{time}}">
|
||||
<view class="picker">
|
||||
{{time}}
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="section location">
|
||||
<text class="label">位置:</text>
|
||||
<text wx:if="{{location}}" bind:tap="chooseLocation">{{location.text}}</text>
|
||||
<text wx:else bind:tap="chooseLocation">选择位置..</text>
|
||||
</view>
|
||||
<view class="section media">
|
||||
<view class="gallery">
|
||||
<!-- 现有附件 -->
|
||||
<block wx:for="{{mediaList}}" wx:key="attachmentId">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close-circle-filled"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
<!-- 新选择附件 -->
|
||||
<block wx:for="{{newMediaList}}" wx:key="index">
|
||||
<view class="item new-item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 新增标识 -->
|
||||
<t-icon class="new-badge" name="add" />
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close-circle-filled"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
<t-button
|
||||
class="item add"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="addMedia"
|
||||
>
|
||||
<t-icon name="add" />
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
<progress
|
||||
wx:if="{{isSaving}}"
|
||||
class="progress"
|
||||
percent="{{saveProgress.toFixed(2) * 100}}"
|
||||
show-info
|
||||
stroke-width="4"
|
||||
/>
|
||||
<view class="ctrl">
|
||||
<t-button class="delete" theme="danger" bind:tap="deleteJournal" disabled="{{isSaving}}">删除记录</t-button>
|
||||
<t-button
|
||||
class="save"
|
||||
theme="primary"
|
||||
bind:tap="save"
|
||||
disabled="{{(!idea && mediaList.length === 0 && newMediaList.length === 0) || isSaving}}"
|
||||
>{{saveText}}</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<t-dialog
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除记录"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此记录的照片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
</view>
|
||||
<t-input
|
||||
class="confirm-input"
|
||||
model:value="{{deleteConfirmText}}"
|
||||
placeholder="请输入:确认删除"
|
||||
/>
|
||||
</view>
|
||||
</t-dialog>
|
||||
@ -1,12 +1,19 @@
|
||||
// pages/main/journal-search/index.ts
|
||||
import Events from "../../../utils/Events";
|
||||
|
||||
Page({
|
||||
onLoad() {
|
||||
Events.reset("JOURNAL_LIST_REFRESH", () => {
|
||||
const listRef = this.selectComponent('#listRef');
|
||||
if (listRef) {
|
||||
listRef.reSearch();
|
||||
}
|
||||
});
|
||||
},
|
||||
onNavigateItem(e: WechatMiniprogram.CustomEvent) {
|
||||
const { id } = e.detail;
|
||||
// TODO: 跳转到编辑页面或详情页
|
||||
wx.showToast({
|
||||
title: `编辑功能待开发 (ID: ${id})`,
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
wx.navigateTo({
|
||||
url: `/pages/main/journal-editor/index?id=${id}`
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
<view class="content">
|
||||
<journal-list
|
||||
id="listRef"
|
||||
searchable="{{true}}"
|
||||
mode="navigate"
|
||||
type="NORMAL"
|
||||
|
||||
55
miniprogram/types/Attachment.ts
Normal file
55
miniprogram/types/Attachment.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { Model } from "./Model";
|
||||
|
||||
/** 附件 */
|
||||
export type Attachment = {
|
||||
|
||||
/** 业务类型 */
|
||||
bizType: string;
|
||||
|
||||
/** 业务 ID */
|
||||
bizId: number;
|
||||
|
||||
/** 附件类型 */
|
||||
attachType?: MediaAttachType;
|
||||
|
||||
/** 文件名 */
|
||||
name: string;
|
||||
|
||||
/** 文件 MD5 */
|
||||
md5: string;
|
||||
|
||||
/** 访问 mongoId */
|
||||
mongoId: string;
|
||||
|
||||
/** 大小 */
|
||||
size: number;
|
||||
|
||||
/** 扩展数据 */
|
||||
ext?: string | MediaAttachExt;
|
||||
} & Model;
|
||||
|
||||
/** 媒体附件类型 */
|
||||
export enum MediaAttachType {
|
||||
|
||||
/** 原图 */
|
||||
SOURCE = "SOURCE",
|
||||
|
||||
/** 缩略图 */
|
||||
THUMB = "THUMB"
|
||||
}
|
||||
|
||||
/** 媒体附件扩展数据 */
|
||||
export type MediaAttachExt = {
|
||||
|
||||
/** 原文件附件 ID */
|
||||
sourceId: number;
|
||||
|
||||
/** 原文件访问 mongoId */
|
||||
sourceMongoId: string;
|
||||
|
||||
/** true 为图片 */
|
||||
isImage: boolean;
|
||||
|
||||
/** true 为视频 */
|
||||
isVideo: boolean;
|
||||
}
|
||||
@ -1,11 +1,54 @@
|
||||
import { QueryPage } from "./Model";
|
||||
import { Attachment } from "./Attachment";
|
||||
import { Model, QueryPage } from "./Model";
|
||||
|
||||
/** 日记 */
|
||||
export type Journal = {
|
||||
|
||||
/** 类型 */
|
||||
type: JournalType;
|
||||
|
||||
/** 想法、说明 */
|
||||
idea?: string;
|
||||
|
||||
/** 维度 */
|
||||
lat?: number;
|
||||
|
||||
/** 经度 */
|
||||
lng?: number;
|
||||
|
||||
/** 位置 */
|
||||
location?: string;
|
||||
|
||||
/** 天气 */
|
||||
weatcher?: string;
|
||||
|
||||
/** 附件(照片、视频等) */
|
||||
items?: Attachment[];
|
||||
} & Model;
|
||||
|
||||
/** 日记类型 */
|
||||
export enum JournalType {
|
||||
|
||||
/** 正常 */
|
||||
NORMAL = "NORMAL",
|
||||
|
||||
/** 专业拍摄 */
|
||||
PORTFOLIO = "PORTFOLIO"
|
||||
}
|
||||
|
||||
/** 日记页面查询对象 */
|
||||
export type JournalPage = {
|
||||
|
||||
/** 查询类型 */
|
||||
type: JournalPageType;
|
||||
} & QueryPage;
|
||||
|
||||
/** 日记页面查询类型 */
|
||||
export enum JournalPageType {
|
||||
|
||||
/** 正常查询所有附件 */
|
||||
NORMAL = "NORMAL",
|
||||
|
||||
/** 仅查询第一个附件用于预览 */
|
||||
PREVIEW = "PREVIEW"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// 基本实体模型
|
||||
/** 基本实体模型 */
|
||||
export type Model = {
|
||||
id?: number;
|
||||
|
||||
@ -7,37 +7,45 @@ export type Model = {
|
||||
deletedAt?: number;
|
||||
}
|
||||
|
||||
/** 基本返回对象 */
|
||||
export type Response = {
|
||||
code: number;
|
||||
msg?: string;
|
||||
data: object;
|
||||
}
|
||||
|
||||
/** 基本页面查询对象 */
|
||||
export type QueryPage = {
|
||||
|
||||
/** 页面下标,从 0 开始 */
|
||||
index: number;
|
||||
|
||||
/** 单页数据量 */
|
||||
size: number;
|
||||
|
||||
/** 排序 */
|
||||
orderMap?: { [key: string]: OrderType };
|
||||
|
||||
/** 全等比较条件(AND 连接) */
|
||||
equalsExample?: { [key: string]: string | undefined | null };
|
||||
|
||||
/** 模糊查询条件(OR 连接) */
|
||||
likeExample?: { [key: string]: string | undefined | null };
|
||||
}
|
||||
|
||||
/** 排序方式 */
|
||||
export enum OrderType {
|
||||
ASC = "ASC",
|
||||
DESC = "DESC"
|
||||
}
|
||||
|
||||
/** 页面查询返回 */
|
||||
export type QueryPageResult<T> = {
|
||||
total: number;
|
||||
list: T[];
|
||||
}
|
||||
|
||||
// 携带验证码的请求体
|
||||
export type CaptchaData<T> = {
|
||||
from: string;
|
||||
captcha: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
/** 键值对对象 */
|
||||
export type KeyValue<T> = {
|
||||
key: string;
|
||||
value: T;
|
||||
|
||||
64
miniprogram/types/UI.ts
Normal file
64
miniprogram/types/UI.ts
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
/** 系统媒体项目 */
|
||||
export type MediaItem = {
|
||||
|
||||
/** 类型 */
|
||||
type: MediaItemType;
|
||||
|
||||
/** 缩略图访问 URL */
|
||||
thumbURL: string;
|
||||
|
||||
/** 原图访问 URL */
|
||||
sourceURL: string;
|
||||
|
||||
/** 文件大小 */
|
||||
size: number;
|
||||
|
||||
/** 附件 ID */
|
||||
attachmentId: number;
|
||||
}
|
||||
|
||||
/** 微信媒体项目 */
|
||||
export type WechatMediaItem = {
|
||||
|
||||
/** 类型 */
|
||||
type: MediaItemType;
|
||||
|
||||
/** 本地路径 */
|
||||
path: string;
|
||||
|
||||
/** 缩略图路径 */
|
||||
thumbPath: string;
|
||||
|
||||
/** 文件大小 */
|
||||
size: number;
|
||||
|
||||
/** 时长(视频) */
|
||||
duration: number | undefined;
|
||||
|
||||
/** 微信原始媒体对象 */
|
||||
raw?: any;
|
||||
}
|
||||
|
||||
/** 媒体项目类型 */
|
||||
export enum MediaItemType {
|
||||
|
||||
/** 图片 */
|
||||
IMAGE,
|
||||
|
||||
/** 视频 */
|
||||
VIDEO
|
||||
}
|
||||
|
||||
/** 位置 */
|
||||
export type Location = {
|
||||
|
||||
/** 维度 */
|
||||
lat?: number;
|
||||
|
||||
/** 经度 */
|
||||
lng?: number;
|
||||
|
||||
/** 描述 */
|
||||
text?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user