优化店务小程序店铺设置和表单体验

This commit is contained in:
2026-07-22 15:41:12 +08:00
parent 492cbab0fd
commit b9989f8344
14 changed files with 543 additions and 44 deletions
+50 -3
View File
@@ -2,6 +2,7 @@ const shopApi = require('../../api/shop')
const dateUtil = require('../../utils/date')
const { BRAND_CONFIG } = require('../../utils/config')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
const { chooseImageFilePath, uploadObjectFile, resolveUploadedImagePreviewUrl } = require('../../utils/upload')
const PRESETS = [
{ value: 'EVERYDAY', label: '全周营业', workDays: [1, 2, 3, 4, 5, 6, 7], startTime: '10:00', endTime: '22:00' },
@@ -66,6 +67,10 @@ function buildExceptionSummary(item) {
return `${item.workDate} ${exceptionTypeLabel(item.exceptionType)} ${String(item.startTime || '').slice(0, 5)}-${String(item.endTime || '').slice(0, 5)}`
}
function resolveFirstImageUrl(urls) {
return Array.isArray(urls) ? String(urls[0] || '').trim() : ''
}
Page({
data: {
presets: PRESETS,
@@ -78,6 +83,8 @@ Page({
exceptions: [],
loading: false,
saving: false,
coverUploading: false,
coverImagePreviewUrl: '',
form: {
shopName: BRAND_CONFIG.defaultShopName,
startTime: '10:00',
@@ -86,7 +93,8 @@ Page({
rule: '必须选择已有作品作为项目来源',
schedulePresetType: 'EVERYDAY',
scheduleWorkDays: [1, 2, 3, 4, 5, 6, 7],
scheduleRemark: ''
scheduleRemark: '',
coverImageFileId: ''
},
exceptionForm: {
workDate: dateUtil.formatDate(new Date()),
@@ -118,10 +126,12 @@ Page({
rule: settings.description || this.data.form.rule,
schedulePresetType: settings.schedulePresetType || preset.value,
scheduleWorkDays: copyWorkDays(settings.scheduleWorkDays || preset.workDays),
scheduleRemark: settings.scheduleRemark || ''
scheduleRemark: settings.scheduleRemark || '',
coverImageFileId: settings.coverImageFileId || ''
}
this.setData({
form,
coverImagePreviewUrl: resolveFirstImageUrl(settings.coverImageUrls),
presetOptions: buildPresetOptions(form.schedulePresetType),
weekdayOptions: buildWeekdayOptions(form.scheduleWorkDays),
exceptions: (exceptions || []).map(item => ({
@@ -142,6 +152,42 @@ Page({
this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value })
},
async chooseCoverImage() {
if (this.data.coverUploading || this.data.saving) {
return
}
try {
const filePath = await chooseImageFilePath()
if (!filePath) {
return
}
this.setData({ coverUploading: true })
const uploadResult = await uploadObjectFile(filePath)
const fileId = String(uploadResult && uploadResult.id ? uploadResult.id : '').trim()
if (!fileId) {
throw new Error('店铺主图上传失败:上传接口未返回文件ID')
}
this.setData({
'form.coverImageFileId': fileId,
coverImagePreviewUrl: resolveUploadedImagePreviewUrl(uploadResult, filePath)
})
} catch (error) {
wx.showToast({ title: error.message || '店铺主图上传失败', icon: 'none' })
} finally {
this.setData({ coverUploading: false })
}
},
removeCoverImage() {
if (this.data.coverUploading || this.data.saving) {
return
}
this.setData({
'form.coverImageFileId': '',
coverImagePreviewUrl: ''
})
},
onExceptionInput(event) {
this.setData({ [`exceptionForm.${event.currentTarget.dataset.field}`]: event.detail.value })
},
@@ -257,7 +303,8 @@ Page({
description: form.rule,
schedulePresetType: form.schedulePresetType,
scheduleWorkDays: encodeWorkDays(workDays),
scheduleRemark: String(form.scheduleRemark || '').trim()
scheduleRemark: String(form.scheduleRemark || '').trim(),
coverImageFileId: String(form.coverImageFileId || '').trim()
})
markPlanningRefresh()
wx.showToast({ title: '已保存', icon: 'success' })