feat(mp, web, calendar): 新增微信收藏夹与日历批量生成功能
- 新增微信小程序版个人收藏夹全套功能,包含聚合首页、收藏列表、编辑、详情页面与配套后端API - 新增web版时光助手门户与个人收藏夹工具,支持与小程序共享后端数据 - 优化日历提醒工具:替换本地bootstrap资源为公共CDN版本,新增批量生成循环提醒的前端界面与后端逻辑,新增数据库batch_id字段,更新鉴权配置文件 - 补充项目配置、站点地图、调试诊断脚本等配套文件 - 完善各模块的页面配置与样式文件
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
const api = require('../../../../api.js')
|
||||
|
||||
const formatDate = iso => {
|
||||
if (!iso) return ''
|
||||
const d = new Date(iso)
|
||||
if (isNaN(d.getTime())) return iso
|
||||
const pad = n => n < 10 ? '0' + n : '' + n
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
id: '',
|
||||
item: null,
|
||||
createdAtText: '',
|
||||
updatedAtText: '',
|
||||
error: '',
|
||||
imageUrls: [],
|
||||
hasNonImageAttachment: false,
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options && options.id ? String(options.id) : ''
|
||||
if (!id) {
|
||||
this.setData({ loading: false, error: '缺少 ID 参数' })
|
||||
return
|
||||
}
|
||||
this.setData({ id })
|
||||
this.loadItem(id)
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (this.data.id && !this.data.loading) {
|
||||
this.loadItem(this.data.id)
|
||||
}
|
||||
},
|
||||
|
||||
async loadItem(id) {
|
||||
this.setData({ loading: true, error: '' })
|
||||
try {
|
||||
const res = await api.personalCollect.get(id)
|
||||
const item = res.data || null
|
||||
const images = (item && item.attachments || []).filter(a => a && a.isImage && a.filePath)
|
||||
const imageUrls = images.map(a => `https://traesite.umersoft.com:8975/${a.filePath}`)
|
||||
const attachments = (item && item.attachments || []).map(a => ({
|
||||
...a,
|
||||
url: a.filePath ? `https://traesite.umersoft.com:8975/${a.filePath}` : '',
|
||||
}))
|
||||
const hasNonImage = (item.attachments || []).some(a => !a.isImage)
|
||||
this.setData({
|
||||
item: Object.assign({}, item, { attachments }),
|
||||
createdAtText: formatDate(item.createdAt || ''),
|
||||
updatedAtText: formatDate(item.updatedAt || ''),
|
||||
imageUrls,
|
||||
hasNonImageAttachment: !!hasNonImage,
|
||||
})
|
||||
} catch (e) {
|
||||
this.setData({ error: e && e.message ? e.message : '加载失败' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
onPreviewImage(e) {
|
||||
const url = e.currentTarget.dataset.url
|
||||
if (!url || !this.data.imageUrls.length) return
|
||||
wx.previewImage({
|
||||
current: url,
|
||||
urls: this.data.imageUrls,
|
||||
})
|
||||
},
|
||||
|
||||
onOpenFile(e) {
|
||||
const url = e.currentTarget.dataset.url
|
||||
const name = e.currentTarget.dataset.name || 'file'
|
||||
if (!url) return
|
||||
wx.showLoading({ title: '打开中...', mask: true })
|
||||
wx.downloadFile({
|
||||
url,
|
||||
timeout: 120000,
|
||||
success: (res) => {
|
||||
wx.hideLoading()
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.tempFilePath) {
|
||||
wx.openDocument({
|
||||
filePath: res.tempFilePath,
|
||||
showMenu: true,
|
||||
fileType: this.detectFileType(name),
|
||||
success: () => {},
|
||||
fail: (err) => {
|
||||
wx.showModal({
|
||||
title: '打开失败',
|
||||
content: err && err.errMsg ? err.errMsg : '无法预览此类型文件',
|
||||
showCancel: false,
|
||||
})
|
||||
},
|
||||
})
|
||||
} else {
|
||||
wx.showModal({
|
||||
title: '下载失败',
|
||||
content: `HTTP ${res.statusCode}`,
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: '下载失败',
|
||||
content: err && err.errMsg ? err.errMsg : '网络错误',
|
||||
showCancel: false,
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
detectFileType(name) {
|
||||
const ext = (name || '').split('.').pop().toLowerCase()
|
||||
const map = {
|
||||
pdf: 'pdf',
|
||||
doc: 'doc', docx: 'doc',
|
||||
xls: 'xls', xlsx: 'xls',
|
||||
ppt: 'ppt', pptx: 'ppt',
|
||||
}
|
||||
return map[ext] || ''
|
||||
},
|
||||
|
||||
onEditTap() {
|
||||
if (!this.data.id) return
|
||||
wx.navigateTo({
|
||||
url: `/kits/personal_collect/pages/edit/edit?id=${encodeURIComponent(this.data.id)}`,
|
||||
})
|
||||
},
|
||||
|
||||
onDeleteTap() {
|
||||
const title = this.data.item && this.data.item.title
|
||||
? this.data.item.title
|
||||
: (this.data.item && this.data.item.remark && this.data.item.remark.slice(0, 10)) || '此收藏'
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: `确定删除「${title}」吗?删除后不再显示。`,
|
||||
confirmText: '删除',
|
||||
confirmColor: '#e05561',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
wx.showLoading({ title: '删除中...', mask: true })
|
||||
await api.personalCollect.remove(this.data.id)
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '已删除', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
wx.navigateBack()
|
||||
}, 800)
|
||||
} catch (err) {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: '删除失败',
|
||||
content: err && err.message ? err.message : '请重试',
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"navigationBarTitleText": "收藏详情",
|
||||
"backgroundTextStyle": "light"
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<view wx:if="{{loading}}" class="container">
|
||||
<view class="empty">加载中...</view>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{error}}" class="container">
|
||||
<view class="card" style="border-color:#55333a;">
|
||||
<text style="color:#e05561;">⚠️ {{error}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{!item}}" class="container">
|
||||
<view class="empty">未找到该收藏</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="container" style="padding-bottom: 200rpx;">
|
||||
<view class="card">
|
||||
<view wx:if="{{item.title}}" style="font-size: 40rpx; font-weight:600; color:#ffffff; line-height:1.4;">{{item.title}}</view>
|
||||
<view class="divider"></view>
|
||||
|
||||
<view wx:if="{{item.remark}}" style="white-space: pre-wrap; font-size: 28rpx; color:#e8e8f0; line-height:1.8;">{{item.remark}}</view>
|
||||
|
||||
<view wx:if="{{item.tags && item.tags.length}}" style="margin-top: 32rpx;">
|
||||
<block wx:for="{{item.tags}}" wx:for-item="tag" wx:key="*this">
|
||||
<view class="tag">#{{tag}}</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view class="divider"></view>
|
||||
|
||||
<view class="row" style="margin-bottom: 12rpx;">
|
||||
<text class="muted small" style="width: 180rpx;">创建时间</text>
|
||||
<text class="small">{{createdAtText || '-'}}</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="muted small" style="width: 180rpx;">更新时间</text>
|
||||
<text class="small">{{updatedAtText || '-'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{item.attachments && item.attachments.length}}" class="card">
|
||||
<view style="font-size: 30rpx; font-weight:600; color:#ffffff; margin-bottom: 24rpx;">附件 ({{item.attachments.length}})</view>
|
||||
<view class="attachments-grid">
|
||||
<block wx:for="{{item.attachments}}" wx:for-item="att" wx:key="id">
|
||||
<view class="attachment-thumb">
|
||||
<block wx:if="{{att.isImage}}">
|
||||
<image
|
||||
src="{{att.url}}"
|
||||
mode="aspectFill"
|
||||
data-url="{{att.url}}"
|
||||
bindtap="onPreviewImage"
|
||||
/>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<text class="attachment-icon" data-url="{{att.url}}" data-name="{{att.fileName}}" catchtap="onOpenFile" style="padding: 20rpx;">📄</text>
|
||||
</block>
|
||||
<view class="attachment-name" data-url="{{att.url}}" data-name="{{att.fileName}}" catchtap="{{att.isImage ? 'onPreviewImage' : 'onOpenFile'}}">{{att.fileName}}</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<view wx:if="{{hasNonImageAttachment}}" class="muted small" style="margin-top: 24rpx;">
|
||||
💡 非图片附件点击名称即可下载并使用微信自带文档查看器打开。
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{item}}" style="position:fixed; left:0; right:0; bottom:0; padding:24rpx 32rpx; background:#0f0f1a; border-top:1rpx solid #2a2a44; box-sizing:border-box; display:flex; gap:20rpx; z-index:99;">
|
||||
<view class="btn btn-ghost" style="flex:1;" bindtap="onDeleteTap">删除</view>
|
||||
<view class="btn btn-primary" style="flex:1;" bindtap="onEditTap">编辑</view>
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* 详情页独立样式,大部分复用 app.wxss 全局样式 */
|
||||
@@ -0,0 +1,345 @@
|
||||
const api = require('../../../../api.js')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isEdit: false,
|
||||
loading: true,
|
||||
saving: false,
|
||||
id: '',
|
||||
title: '',
|
||||
remark: '',
|
||||
tagsText: '',
|
||||
attachments: [],
|
||||
uploadGroupId: '',
|
||||
error: '',
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options && options.id ? String(options.id) : ''
|
||||
this.setData({ isEdit: !!id, id })
|
||||
this.generateUploadGroupId()
|
||||
if (id) {
|
||||
this.loadItem(id)
|
||||
} else {
|
||||
this.applyClipPrefill()
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
applyClipPrefill() {
|
||||
try {
|
||||
const text = wx.getStorageSync('mp_ta_clip_text')
|
||||
if (!text || typeof text !== 'string') return
|
||||
const mode = wx.getStorageSync('mp_ta_clip_mode') || 'new'
|
||||
try { wx.removeStorageSync('mp_ta_clip_text') } catch (e) {}
|
||||
try { wx.removeStorageSync('mp_ta_clip_mode') } catch (e) {}
|
||||
const title = ((String(text || '').split('\n').map(s => s.trim()).find(s => s.length) || '').slice(0, 28)) || '文字收藏'
|
||||
this.setData({
|
||||
title: title,
|
||||
remark: text,
|
||||
})
|
||||
wx.showToast({
|
||||
title: mode === 'append' ? '已追加剪贴板文字' : '已预填剪贴板文字',
|
||||
icon: 'none',
|
||||
duration: 1600,
|
||||
})
|
||||
} catch (e) {}
|
||||
},
|
||||
|
||||
generateUploadGroupId() {
|
||||
const ts = Date.now().toString(36)
|
||||
const rnd = Math.random().toString(36).slice(2, 10)
|
||||
this.setData({ uploadGroupId: `${ts}_${rnd}` })
|
||||
},
|
||||
|
||||
async loadItem(id) {
|
||||
this.setData({ loading: true, error: '' })
|
||||
try {
|
||||
const res = await api.personalCollect.get(id)
|
||||
const item = res.data || {}
|
||||
const tags = Array.isArray(item.tags) ? item.tags : []
|
||||
const attachments = (item.attachments || []).map(a => ({
|
||||
...a,
|
||||
url: a.filePath ? `https://traesite.umersoft.com:8975/${a.filePath}` : '',
|
||||
uploaded: true,
|
||||
uploading: false,
|
||||
}))
|
||||
this.setData({
|
||||
title: item.title || '',
|
||||
remark: item.remark || '',
|
||||
tagsText: tags.join(', '),
|
||||
attachments,
|
||||
})
|
||||
} catch (e) {
|
||||
this.setData({ error: e && e.message ? e.message : '加载失败' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
onTitleInput(e) {
|
||||
this.setData({ title: String(e.detail.value || '') })
|
||||
},
|
||||
|
||||
onRemarkInput(e) {
|
||||
this.setData({ remark: String(e.detail.value || '') })
|
||||
},
|
||||
|
||||
onTagsInput(e) {
|
||||
this.setData({ tagsText: String(e.detail.value || '') })
|
||||
},
|
||||
|
||||
async onChooseAttachments() {
|
||||
try {
|
||||
const files = await api.chooseChatAttachments(9 - this.data.attachments.length)
|
||||
if (!files || !files.length) return
|
||||
for (const f of files) {
|
||||
await this.uploadOne(f)
|
||||
}
|
||||
} catch (e) {
|
||||
const msg = e && e.message ? String(e.message) : ''
|
||||
if (msg.indexOf('cancel') !== -1 || msg.indexOf('取消') !== -1) return
|
||||
if (msg.indexOf('auth') !== -1 || msg.indexOf('deny') !== -1 || msg.indexOf('权限') !== -1 || msg.indexOf('授权') !== -1) {
|
||||
wx.showModal({
|
||||
title: '需要聊天文件权限',
|
||||
content: '请点击右上角「···」→ 设置,打开「聊天记录」权限后重试。',
|
||||
showCancel: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.showModal({
|
||||
title: '选择失败',
|
||||
content: msg || '请重试',
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async uploadOne(tempFile) {
|
||||
const tempId = `tmp_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
|
||||
const isImage = tempFile.type === 'image' || /\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(tempFile.name || '')
|
||||
const pending = {
|
||||
id: tempId,
|
||||
fileName: tempFile.name || '未命名',
|
||||
filePath: '',
|
||||
fileSize: Number(tempFile.size || 0),
|
||||
isImage,
|
||||
url: tempFile.path || tempFile.tempFilePath || '',
|
||||
uploaded: false,
|
||||
uploading: true,
|
||||
error: '',
|
||||
}
|
||||
const list = this.data.attachments.concat([pending])
|
||||
this.setData({ attachments: list })
|
||||
|
||||
const idx = list.length - 1
|
||||
try {
|
||||
const res = await api.personalCollect.upload(tempFile.path || tempFile.tempFilePath, this.data.uploadGroupId)
|
||||
const data = (res && res.data) || {}
|
||||
const attachment = {
|
||||
id: data.id || tempId,
|
||||
fileName: data.fileName || tempFile.name || '未命名',
|
||||
storedName: data.storedName || '',
|
||||
filePath: data.filePath || '',
|
||||
fileSize: Number(data.fileSize || tempFile.size || 0),
|
||||
mimeType: data.mimeType || '',
|
||||
isImage: !!data.isImage || isImage,
|
||||
url: data.url || (data.filePath ? `https://traesite.umersoft.com:8975/${data.filePath}` : '') || '',
|
||||
groupId: data.groupId || '',
|
||||
uploaded: true,
|
||||
uploading: false,
|
||||
error: '',
|
||||
}
|
||||
const next = this.data.attachments.slice()
|
||||
next[idx] = attachment
|
||||
this.setData({ attachments: next })
|
||||
this.autoFillFromAttachments(false)
|
||||
} catch (e) {
|
||||
const next = this.data.attachments.slice()
|
||||
next[idx] = Object.assign({}, next[idx], {
|
||||
uploading: false,
|
||||
error: e && e.message ? e.message : '上传失败',
|
||||
})
|
||||
this.setData({ attachments: next })
|
||||
}
|
||||
},
|
||||
|
||||
autoFillFromAttachments(force) {
|
||||
if (this.data.isEdit && !force) return
|
||||
const atts = this.data.attachments.filter(a => a && a.uploaded)
|
||||
if (!atts.length) return
|
||||
const hasTitle = !!(this.data.title || '').trim()
|
||||
const hasRemark = !!(this.data.remark || '').trim()
|
||||
const { title, remark } = this.buildAutoText(atts)
|
||||
const patch = {}
|
||||
if (!hasTitle || force) patch.title = title
|
||||
if (!hasRemark || force) patch.remark = remark
|
||||
if (Object.keys(patch).length) this.setData(patch)
|
||||
},
|
||||
|
||||
buildAutoText(atts) {
|
||||
const images = atts.filter(a => a.isImage)
|
||||
const files = atts.filter(a => !a.isImage)
|
||||
const imageCount = images.length
|
||||
const fileCount = files.length
|
||||
const total = atts.length
|
||||
const pad = n => n < 10 ? '0' + n : '' + n
|
||||
const now = new Date()
|
||||
const ts = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`
|
||||
|
||||
const humanSize = bytes => {
|
||||
const n = Number(bytes || 0)
|
||||
if (n < 1024) return n + ' B'
|
||||
if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB'
|
||||
return (n / 1024 / 1024).toFixed(2) + ' MB'
|
||||
}
|
||||
|
||||
let title = ''
|
||||
if (total === 1) {
|
||||
const only = atts[0]
|
||||
const rawName = only.fileName || '附件'
|
||||
const ext = (rawName.split('.').pop() || '').toLowerCase()
|
||||
const stem = rawName.lastIndexOf('.') > 0 ? rawName.slice(0, rawName.lastIndexOf('.')) : rawName
|
||||
if (only.isImage) {
|
||||
title = `图片 - ${ts}`
|
||||
} else {
|
||||
title = stem || rawName
|
||||
}
|
||||
} else if (imageCount > 0 && fileCount === 0) {
|
||||
title = `${imageCount} 张图片 - ${ts}`
|
||||
} else if (fileCount > 0 && imageCount === 0) {
|
||||
if (fileCount === 1) {
|
||||
const only = files[0]
|
||||
const rawName = only.fileName || '附件'
|
||||
const stem = rawName.lastIndexOf('.') > 0 ? rawName.slice(0, rawName.lastIndexOf('.')) : rawName
|
||||
title = stem || rawName
|
||||
} else {
|
||||
title = `${fileCount} 个文件 - ${ts}`
|
||||
}
|
||||
} else {
|
||||
title = `${imageCount} 图 + ${fileCount} 文件 - ${ts}`
|
||||
}
|
||||
|
||||
const lines = []
|
||||
lines.push(`附件数量:${total}`)
|
||||
if (imageCount) lines.push(`图片:${imageCount} 张`)
|
||||
if (fileCount) lines.push(`文件:${fileCount} 个`)
|
||||
lines.push('')
|
||||
lines.push('附件清单:')
|
||||
atts.slice(0, 9).forEach((a, i) => {
|
||||
lines.push(` ${i + 1}. ${a.fileName || '未命名'}(${humanSize(a.fileSize)})`)
|
||||
})
|
||||
if (atts.length > 9) lines.push(` ... 另有 ${atts.length - 9} 个附件未列出`)
|
||||
lines.push('')
|
||||
lines.push(`整理时间:${ts}`)
|
||||
const remark = lines.join('\n')
|
||||
|
||||
return { title, remark }
|
||||
},
|
||||
|
||||
onPreviewImage(e) {
|
||||
const url = e.currentTarget.dataset.url
|
||||
const urls = this.data.attachments.filter(a => a && a.isImage && a.url).map(a => a.url)
|
||||
if (!url || !urls.length) return
|
||||
wx.previewImage({
|
||||
current: url,
|
||||
urls,
|
||||
})
|
||||
},
|
||||
|
||||
onRemoveAttachment(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const idx = this.data.attachments.findIndex(a => a.id === id)
|
||||
if (idx < 0) return
|
||||
const next = this.data.attachments.slice()
|
||||
next.splice(idx, 1)
|
||||
this.setData({ attachments: next })
|
||||
},
|
||||
|
||||
onRetryUpload(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const idx = this.data.attachments.findIndex(a => a.id === id)
|
||||
if (idx < 0) return
|
||||
const att = this.data.attachments[idx]
|
||||
if (!att || att.uploaded || !att.url) return
|
||||
this.uploadOne({
|
||||
name: att.fileName || '未命名',
|
||||
size: att.fileSize || 0,
|
||||
type: att.isImage ? 'image' : 'file',
|
||||
path: att.url,
|
||||
}).then(() => {
|
||||
const next = this.data.attachments.slice()
|
||||
next.splice(idx, 1)
|
||||
this.setData({ attachments: next })
|
||||
})
|
||||
},
|
||||
|
||||
parseTags(text) {
|
||||
const s = String(text || '').trim()
|
||||
if (!s) return []
|
||||
return s
|
||||
.split(/[,,\s]+/)
|
||||
.map(t => t.trim())
|
||||
.filter(Boolean)
|
||||
},
|
||||
|
||||
async onSave() {
|
||||
if (this.data.saving) return
|
||||
const title = this.data.title.trim()
|
||||
const remark = this.data.remark.trim()
|
||||
if (!title && !remark) {
|
||||
wx.showToast({ title: '标题或备注至少填一个', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const errorAtt = this.data.attachments.find(a => a && a.error)
|
||||
if (errorAtt) {
|
||||
wx.showModal({
|
||||
title: '存在上传失败的附件',
|
||||
content: `「${errorAtt.fileName}」上传失败:${errorAtt.error}。请移除或重试后再保存。`,
|
||||
showCancel: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
const uploading = this.data.attachments.find(a => a && a.uploading)
|
||||
if (uploading) {
|
||||
wx.showToast({ title: '请等待附件上传完成', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const attachmentIds = this.data.attachments
|
||||
.filter(a => a && a.uploaded && a.id)
|
||||
.map(a => a.id)
|
||||
|
||||
const payload = {
|
||||
title,
|
||||
remark,
|
||||
tags: this.parseTags(this.data.tagsText),
|
||||
attachmentIds,
|
||||
}
|
||||
this.setData({ saving: true })
|
||||
wx.showLoading({ title: this.data.isEdit ? '保存中...' : '创建中...', mask: true })
|
||||
try {
|
||||
if (this.data.isEdit) {
|
||||
await api.personalCollect.update(Object.assign({ id: this.data.id }, payload))
|
||||
} else {
|
||||
await api.personalCollect.create(payload)
|
||||
}
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: this.data.isEdit ? '已保存' : '已创建',
|
||||
icon: 'success',
|
||||
})
|
||||
setTimeout(() => {
|
||||
wx.navigateBack()
|
||||
}, 800)
|
||||
} catch (e) {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: this.data.isEdit ? '保存失败' : '创建失败',
|
||||
content: e && e.message ? e.message : '请重试',
|
||||
showCancel: false,
|
||||
})
|
||||
} finally {
|
||||
this.setData({ saving: false })
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"navigationBarTitleText": "编辑收藏",
|
||||
"backgroundTextStyle": "light"
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<view wx:if="{{loading}}" class="container">
|
||||
<view class="empty">加载中...</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="container" style="padding-bottom: 200rpx;">
|
||||
<view wx:if="{{error}}" class="card" style="border-color:#55333a;">
|
||||
<text style="color:#e05561; font-size: 26rpx;">⚠️ {{error}}</text>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">标题</text>
|
||||
<input
|
||||
class="input"
|
||||
placeholder="输入标题(必填或填备注)"
|
||||
placeholder-style="color:#555570"
|
||||
value="{{title}}"
|
||||
bindinput="onTitleInput"
|
||||
maxlength="200"
|
||||
style="color:#ffffff;"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">备注</text>
|
||||
<textarea
|
||||
class="textarea"
|
||||
placeholder="输入备注信息"
|
||||
placeholder-style="color:#555570"
|
||||
value="{{remark}}"
|
||||
bindinput="onRemarkInput"
|
||||
maxlength="4000"
|
||||
auto-height
|
||||
style="color:#ffffff;"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<text class="input-label">标签(逗号或空格分隔,如:工作, 重要)</text>
|
||||
<input
|
||||
class="input"
|
||||
placeholder="标签1, 标签2"
|
||||
placeholder-style="color:#555570"
|
||||
value="{{tagsText}}"
|
||||
bindinput="onTagsInput"
|
||||
maxlength="500"
|
||||
style="color:#ffffff;"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<view class="row row-between" style="margin-bottom: 16rpx;">
|
||||
<text class="input-label" style="margin-bottom:0;">附件(从聊天选择,最多 9 个)</text>
|
||||
<view class="btn btn-ghost mini-btn" bindtap="onChooseAttachments" style="margin:0;">+ 从聊天选</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{attachments.length === 0}}" class="card" style="text-align:center; color:#555570; border-style: dashed;">
|
||||
<text>还没有附件,点右上角按钮选择</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{attachments.length > 0}}" class="attachments-grid">
|
||||
<block wx:for="{{attachments}}" wx:key="id">
|
||||
<view class="attachment-thumb">
|
||||
<block wx:if="{{item.isImage && item.url}}">
|
||||
<image
|
||||
src="{{item.url}}"
|
||||
mode="aspectFill"
|
||||
data-url="{{item.url}}"
|
||||
bindtap="onPreviewImage"
|
||||
/>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<text class="attachment-icon">📄</text>
|
||||
</block>
|
||||
|
||||
<view class="attachment-name">{{item.fileName}}</view>
|
||||
|
||||
<view wx:if="{{item.uploading}}" style="position:absolute; left:0; right:0; top:0; bottom:0; background:rgba(0,0,0,0.55); display:flex; align-items:center; justify-content:center;">
|
||||
<text style="color:#fff; font-size:22rpx;">上传中...</text>
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{item.error}}" style="position:absolute; left:0; right:0; top:0; bottom:0; background:rgba(88,20,30,0.7); display:flex; align-items:center; justify-content:center; flex-direction:column; padding: 12rpx; box-sizing:border-box;">
|
||||
<text style="color:#fff; font-size:20rpx; line-height:1.4; text-align:center;">上传失败</text>
|
||||
<view style="margin-top:8rpx; padding:6rpx 16rpx; background:#fff; color:#1a1a2e; border-radius:8rpx; font-size:20rpx;" catchtap="onRetryUpload" data-id="{{item.id}}">重试</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
style="position:absolute; top:8rpx; right:8rpx; width:44rpx; height:44rpx; border-radius:22rpx; background:rgba(0,0,0,0.55); display:flex; align-items:center; justify-content:center; color:#fff; font-size:28rpx; line-height:1;"
|
||||
catchtap="onRemoveAttachment"
|
||||
data-id="{{item.id}}"
|
||||
>×</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view style="position:fixed; left:0; right:0; bottom:0; padding:24rpx 32rpx; background:#0f0f1a; border-top:1rpx solid #2a2a44; box-sizing:border-box; z-index:99;">
|
||||
<view class="btn btn-primary btn-block {{saving ? '' : ''}}" style="opacity: {{saving ? 0.6 : 1}};" bindtap="onSave">
|
||||
{{isEdit ? (saving ? '保存中...' : '保存修改') : (saving ? '创建中...' : '创建收藏')}}
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* 编辑页独立样式,大部分复用 app.wxss 全局样式 */
|
||||
@@ -0,0 +1,110 @@
|
||||
const api = require('../../../../api.js')
|
||||
|
||||
const formatDate = iso => {
|
||||
if (!iso) return ''
|
||||
const d = new Date(iso)
|
||||
if (isNaN(d.getTime())) return iso
|
||||
const pad = n => n < 10 ? '0' + n : '' + n
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
keyword: '',
|
||||
items: [],
|
||||
error: '',
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.refresh()
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.refresh().finally(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
|
||||
onSearchInput(e) {
|
||||
const val = e.detail && e.detail.value !== undefined ? String(e.detail.value) : ''
|
||||
this.setData({ keyword: val })
|
||||
},
|
||||
|
||||
onSearchConfirm() {
|
||||
this.refresh()
|
||||
},
|
||||
|
||||
onClearSearch() {
|
||||
this.setData({ keyword: '' })
|
||||
this.refresh()
|
||||
},
|
||||
|
||||
async refresh() {
|
||||
this.setData({ loading: true, error: '' })
|
||||
try {
|
||||
const res = await api.personalCollect.list(this.data.keyword || '')
|
||||
const raw = Array.isArray(res.data) ? res.data : []
|
||||
const items = raw.map(item => ({
|
||||
...item,
|
||||
updatedAtText: formatDate(item.updatedAt || item.createdAt || ''),
|
||||
tagsText: (item.tags || []).join(' · '),
|
||||
previewImage: (item.attachments || []).find(a => a && a.isImage && a.filePath) || null,
|
||||
fileCount: Array.isArray(item.attachments) ? item.attachments.length : 0,
|
||||
}))
|
||||
this.setData({ items })
|
||||
} catch (e) {
|
||||
this.setData({ error: e && e.message ? e.message : '加载失败' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
onViewTap(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
wx.navigateTo({
|
||||
url: `/kits/personal_collect/pages/detail/detail?id=${encodeURIComponent(id)}`,
|
||||
})
|
||||
},
|
||||
|
||||
onEditTap(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
wx.navigateTo({
|
||||
url: `/kits/personal_collect/pages/edit/edit?id=${encodeURIComponent(id)}`,
|
||||
})
|
||||
},
|
||||
|
||||
onDeleteTap(e) {
|
||||
const id = e.currentTarget.dataset.id
|
||||
const title = e.currentTarget.dataset.title || '此收藏'
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: `确定删除「${title}」吗?删除后不再显示。`,
|
||||
confirmText: '删除',
|
||||
confirmColor: '#e05561',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
wx.showLoading({ title: '删除中...', mask: true })
|
||||
await api.personalCollect.remove(id)
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '已删除', icon: 'success' })
|
||||
this.refresh()
|
||||
} catch (err) {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: '删除失败',
|
||||
content: err && err.message ? err.message : '请重试',
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
onAddTap() {
|
||||
wx.navigateTo({
|
||||
url: '/kits/personal_collect/pages/edit/edit',
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"navigationBarTitleText": "微信收藏夹",
|
||||
"enablePullDownRefresh": true,
|
||||
"backgroundTextStyle": "light"
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<view class="container" style="padding-bottom: 200rpx;">
|
||||
<view class="page-header">
|
||||
<view class="page-title">微信收藏夹</view>
|
||||
<view class="page-subtitle">保存聊天里的图片与文件,标签搜索管理。</view>
|
||||
</view>
|
||||
|
||||
<view class="search-box">
|
||||
<text class="search-icon">🔍</text>
|
||||
<input
|
||||
class="search-input"
|
||||
placeholder="搜索标题 / 备注 / 标签"
|
||||
placeholder-style="color:#555570"
|
||||
value="{{keyword}}"
|
||||
bindinput="onSearchInput"
|
||||
bindconfirm="onSearchConfirm"
|
||||
confirm-type="search"
|
||||
/>
|
||||
<view wx:if="{{keyword}}" bindtap="onClearSearch" style="padding: 0 8rpx;">
|
||||
<text style="color:#8888a8; font-size: 36rpx;">×</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{error}}" class="card" style="border-color:#55333a;">
|
||||
<text style="color:#e05561; font-size: 26rpx;">⚠️ {{error}}</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loading}}" class="empty">加载中...</view>
|
||||
|
||||
<block wx:if="{{!loading && items.length === 0}}">
|
||||
<view class="empty">
|
||||
<view style="font-size: 80rpx; margin-bottom: 24rpx;">📁</view>
|
||||
<view>{{keyword ? '没有匹配的收藏' : '还没有收藏,点右下角 + 新建'}}</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<block wx:for="{{items}}" wx:key="id">
|
||||
<view class="card" bindtap="onViewTap" data-id="{{item.id}}">
|
||||
<view class="row row-between">
|
||||
<view style="flex:1; min-width:0;">
|
||||
<view wx:if="{{item.title}}" style="font-size: 32rpx; font-weight: 600; color:#ffffff; margin-bottom: 12rpx;">{{item.title}}</view>
|
||||
<view wx:if="{{!item.title && item.remark}}" style="font-size: 32rpx; font-weight: 600; color:#ffffff; margin-bottom: 12rpx; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;">{{item.remark}}</view>
|
||||
<view wx:if="{{item.remark && item.title}}" class="muted small" style="display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5;">{{item.remark}}</view>
|
||||
</view>
|
||||
<view wx:if="{{item.previewImage}}" style="width:128rpx; height:128rpx; margin-left: 24rpx; border-radius: 16rpx; overflow: hidden; background:#12121f; flex-shrink:0;">
|
||||
<image
|
||||
src="https://traesite.umersoft.com:8975/{{item.previewImage.filePath}}"
|
||||
mode="aspectFill"
|
||||
style="width:100%; height:100%;"
|
||||
/>
|
||||
</view>
|
||||
<view wx:elif="{{item.fileCount > 0}}" style="width:128rpx; height:128rpx; margin-left: 24rpx; border-radius: 16rpx; background:#12121f; display:flex; align-items:center; justify-content:center; flex-direction: column; flex-shrink:0;">
|
||||
<text style="font-size: 40rpx;">📎</text>
|
||||
<text class="muted small" style="margin-top: 8rpx;">{{item.fileCount}} 个</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{item.tagsText}}" style="margin-top: 20rpx;">
|
||||
<block wx:for="{{item.tags}}" wx:for-item="tag" wx:key="*this">
|
||||
<view class="tag">#{{tag}}</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view class="row row-between" style="margin-top: 20rpx;">
|
||||
<text class="muted small">更新于 {{item.updatedAtText}}</text>
|
||||
</view>
|
||||
|
||||
<view class="item-actions">
|
||||
<view class="btn btn-ghost mini-btn" catchtap="onViewTap" data-id="{{item.id}}">查看</view>
|
||||
<view class="btn btn-ghost mini-btn" catchtap="onEditTap" data-id="{{item.id}}">编辑</view>
|
||||
<view class="spacer"></view>
|
||||
<view class="btn btn-danger mini-btn" catchtap="onDeleteTap" data-id="{{item.id}}" data-title="{{item.title || (item.remark && item.remark.slice(0, 10)) || '此收藏'}}">删除</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view class="fab" bindtap="onAddTap">+</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* 列表页独立样式,大部分复用 app.wxss 全局样式 */
|
||||
Reference in New Issue
Block a user