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

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' })
+20 -1
View File
@@ -1,8 +1,27 @@
<view class="page no-tab">
<view wx:if="{{loading}}" class="loading-state">店铺设置加载中</view>
<block wx:else>
<view class="cover-card">
<view wx:if="{{coverImagePreviewUrl}}" class="cover-preview">
<image src="{{coverImagePreviewUrl}}" mode="aspectFill"></image>
</view>
<view wx:else class="cover-preview cover-empty">
<text>店铺主图</text>
</view>
<view class="cover-shade">
<view class="cover-copy">
<text class="cover-title">{{form.shopName || '店铺主图'}}</text>
<text class="cover-desc">我的页顶部展示这张图片</text>
</view>
<view class="cover-actions">
<button class="cover-btn" loading="{{coverUploading}}" bindtap="chooseCoverImage">更换主图</button>
<button wx:if="{{coverImagePreviewUrl}}" class="cover-remove" bindtap="removeCoverImage">移除</button>
</view>
</view>
</view>
<view class="card form-card">
<view class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" /></view>
<view class="field"><text class="field-label">店铺名称</text><input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" /></view>
<view class="field">
<view class="label-with-help">
<text class="field-label">默认时长</text>
+121 -1
View File
@@ -1,8 +1,128 @@
.cover-card {
position: relative;
height: 300rpx;
margin-bottom: 24rpx;
overflow: hidden;
border-radius: 22rpx;
background: linear-gradient(135deg, #7b9987, #c4996e);
box-shadow: 0 18rpx 36rpx rgba(83, 64, 44, 0.14);
}
.cover-preview,
.cover-preview image {
width: 100%;
height: 100%;
}
.cover-empty {
display: flex;
align-items: center;
justify-content: center;
color: rgba(255, 255, 255, 0.82);
font-size: 34rpx;
font-weight: 900;
}
.cover-shade {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20rpx;
padding: 28rpx;
background: linear-gradient(180deg, rgba(30, 24, 19, 0.08), rgba(30, 24, 19, 0.48));
}
.cover-copy {
min-width: 0;
color: #fffdf8;
}
.cover-title,
.cover-desc {
display: block;
}
.cover-title {
overflow: hidden;
font-size: 34rpx;
font-weight: 900;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.cover-desc {
margin-top: 8rpx;
font-size: 23rpx;
opacity: 0.9;
}
.cover-actions {
display: flex;
flex: 0 0 auto;
flex-direction: column;
gap: 10rpx;
}
.cover-btn,
.cover-remove {
display: flex;
align-items: center;
justify-content: center;
min-width: 154rpx;
min-height: 58rpx;
padding: 0 20rpx;
border-radius: 16rpx;
font-size: 24rpx;
font-weight: 900;
}
.cover-btn {
background: #fffdf8;
color: #72553b;
}
.cover-remove {
background: rgba(255, 253, 248, 0.18);
color: #fffdf8;
}
.form-card,
.rule-card {
padding: 10rpx 0;
overflow: hidden;
}
.field {
min-height: 108rpx;
padding: 12rpx 24rpx;
}
.field-label,
.label-with-help {
width: 180rpx;
min-width: 180rpx;
}
.field input,
.field-value {
min-height: 70rpx;
padding: 0 22rpx;
border: 1rpx solid #eadfd2;
border-radius: 18rpx;
background: #fffaf4;
line-height: 70rpx;
}
.label-with-help {
display: flex;
align-items: center;
min-width: 144rpx;
}
.label-with-help .field-label {