feat(mp, web, calendar): 新增微信收藏夹与日历批量生成功能
- 新增微信小程序版个人收藏夹全套功能,包含聚合首页、收藏列表、编辑、详情页面与配套后端API - 新增web版时光助手门户与个人收藏夹工具,支持与小程序共享后端数据 - 优化日历提醒工具:替换本地bootstrap资源为公共CDN版本,新增批量生成循环提醒的前端界面与后端逻辑,新增数据库batch_id字段,更新鉴权配置文件 - 补充项目配置、站点地图、调试诊断脚本等配套文件 - 完善各模块的页面配置与样式文件
This commit is contained in:
@@ -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 全局样式 */
|
||||
Reference in New Issue
Block a user