重构店铺设置展示与编辑流程
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
const shopApi = require('../../api/shop')
|
||||
const { BRAND_CONFIG } = require('../../utils/config')
|
||||
const { chooseImageFilePath, uploadObjectFile, resolveUploadedImagePreviewUrl } = require('../../utils/upload')
|
||||
|
||||
const DEFAULT_SHOP_INTRO = '专注法式、晕染与手绘设计,适合想要温柔质感的客人。'
|
||||
|
||||
function resolveFirstImageUrl(urls) {
|
||||
return Array.isArray(urls) ? String(urls[0] || '').trim() : ''
|
||||
}
|
||||
|
||||
function introLength(value) {
|
||||
return String(value || '').length
|
||||
}
|
||||
|
||||
function buildShopPayload(settings, form) {
|
||||
return {
|
||||
shopName: String(form.shopName || '').trim(),
|
||||
description: String(form.rule || '').trim(),
|
||||
address: settings.address || '',
|
||||
mapProvider: settings.mapProvider || '',
|
||||
longitude: settings.longitude,
|
||||
latitude: settings.latitude,
|
||||
businessHours: settings.businessHours || '',
|
||||
schedulePresetType: settings.schedulePresetType || '',
|
||||
scheduleWorkDays: settings.scheduleWorkDays || '',
|
||||
scheduleRemark: settings.scheduleRemark || '',
|
||||
coverImageFileId: String(form.coverImageFileId || '').trim(),
|
||||
imageFileIds: String(settings.imageFileIds || '').trim(),
|
||||
themePrimaryColor: settings.themePrimaryColor || '',
|
||||
themeSecondaryColor: settings.themeSecondaryColor || '',
|
||||
themeAccentColor: settings.themeAccentColor || '',
|
||||
themePageBgColor: settings.themePageBgColor || '',
|
||||
themeCardBgColor: settings.themeCardBgColor || '',
|
||||
themeBackgroundImageFileId: settings.themeBackgroundImageFileId || '',
|
||||
status: settings.status,
|
||||
authorizationStartDate: settings.authorizationStartDate,
|
||||
authorizationDays: settings.authorizationDays,
|
||||
authorizationExpireTime: settings.authorizationExpireTime
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
saving: false,
|
||||
coverUploading: false,
|
||||
coverImagePreviewUrl: '',
|
||||
introLength: introLength(DEFAULT_SHOP_INTRO),
|
||||
settingsSnapshot: {},
|
||||
form: {
|
||||
shopName: BRAND_CONFIG.defaultShopName,
|
||||
rule: DEFAULT_SHOP_INTRO,
|
||||
coverImageFileId: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadSettings()
|
||||
},
|
||||
|
||||
async loadSettings() {
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const settings = await shopApi.settings()
|
||||
const form = {
|
||||
shopName: settings.shopName || settings.name || this.data.form.shopName,
|
||||
rule: settings.description || DEFAULT_SHOP_INTRO,
|
||||
coverImageFileId: settings.coverImageFileId || ''
|
||||
}
|
||||
this.setData({
|
||||
settingsSnapshot: settings || {},
|
||||
form,
|
||||
introLength: introLength(form.rule),
|
||||
coverImagePreviewUrl: resolveFirstImageUrl(settings.coverImageUrls)
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '店铺档案加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const value = event.detail.value
|
||||
const nextData = { [`form.${field}`]: value }
|
||||
if (field === 'rule') {
|
||||
nextData.introLength = introLength(value)
|
||||
}
|
||||
this.setData(nextData)
|
||||
},
|
||||
|
||||
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: ''
|
||||
})
|
||||
},
|
||||
|
||||
async save() {
|
||||
const shopName = String(this.data.form.shopName || '').trim()
|
||||
if (!shopName) {
|
||||
wx.showToast({ title: '请填写店铺名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ saving: true })
|
||||
try {
|
||||
await shopApi.saveSettings(buildShopPayload(this.data.settingsSnapshot, this.data.form))
|
||||
wx.showToast({ title: '店铺档案已保存', icon: 'success' })
|
||||
wx.navigateBack()
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '店铺档案保存失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ saving: false })
|
||||
}
|
||||
},
|
||||
|
||||
back() {
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "编辑店铺档案"
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<view class="page no-tab shop-profile-page">
|
||||
<view wx:if="{{loading}}" class="loading-state">店铺档案加载中</view>
|
||||
<block wx:else>
|
||||
<view class="page-heading">
|
||||
<text class="page-title">编辑店铺档案</text>
|
||||
<text class="page-subtitle">让客人先认识你的店,再决定要不要预约。</text>
|
||||
</view>
|
||||
|
||||
<view class="edit-tip-card">
|
||||
<text class="edit-tip-title">门店第一眼</text>
|
||||
<text class="edit-tip-text">店铺名称、介绍和封面会展示在用户端门店详情页。</text>
|
||||
</view>
|
||||
|
||||
<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 class="cover-empty-title">店铺封面</text>
|
||||
<text class="cover-empty-desc">上传一张能代表风格的作品图</text>
|
||||
</view>
|
||||
<view class="cover-badge">门店封面</view>
|
||||
<view class="cover-actions">
|
||||
<button class="cover-btn" loading="{{coverUploading}}" disabled="{{coverUploading || saving}}" bindtap="chooseCoverImage">{{coverUploading ? '上传中' : '更换主图'}}</button>
|
||||
<button wx:if="{{coverImagePreviewUrl}}" class="cover-remove" disabled="{{coverUploading || saving}}" bindtap="removeCoverImage">移除</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card form-card">
|
||||
<view class="form-header">
|
||||
<text class="form-kicker">门店档案</text>
|
||||
<text class="form-title">保存后返回主页面查看展示效果</text>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">店铺名称</text>
|
||||
<input value="{{form.shopName}}" data-field="shopName" bindinput="onInput" placeholder="请输入店铺名称" />
|
||||
</view>
|
||||
<view class="field field-column">
|
||||
<text class="field-label">门店介绍</text>
|
||||
<view class="intro-editor">
|
||||
<textarea
|
||||
value="{{form.rule}}"
|
||||
data-field="rule"
|
||||
bindinput="onInput"
|
||||
maxlength="120"
|
||||
auto-height="{{false}}"
|
||||
placeholder="写下门店风格、擅长方向、服务氛围"
|
||||
placeholder-class="intro-placeholder"
|
||||
></textarea>
|
||||
<text class="intro-count">{{introLength}}/120</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<button class="secondary-btn bottom-half-btn" disabled="{{saving || coverUploading}}" bindtap="back">取消</button>
|
||||
<button class="primary-btn bottom-half-btn" loading="{{saving}}" disabled="{{saving || coverUploading}}" bindtap="save">保存档案</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,239 @@
|
||||
.shop-profile-page {
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 250, 242, 0.96), rgba(247, 240, 232, 0.96)),
|
||||
linear-gradient(135deg, rgba(89, 121, 102, 0.14), rgba(181, 134, 86, 0.12));
|
||||
}
|
||||
|
||||
.page-heading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
margin: 4rpx 0 22rpx;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
color: #2f2a25;
|
||||
font-size: 36rpx;
|
||||
font-weight: 900;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.page-subtitle,
|
||||
.form-title {
|
||||
color: #8a796a;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
padding: 48rpx 24rpx;
|
||||
color: #7b7167;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.edit-tip-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8rpx;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 22rpx 24rpx;
|
||||
border-radius: 22rpx;
|
||||
background: #fff0ed;
|
||||
}
|
||||
|
||||
.edit-tip-title {
|
||||
color: #3e312d;
|
||||
font-size: 29rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.edit-tip-text {
|
||||
color: #9f6c64;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.cover-card {
|
||||
position: relative;
|
||||
height: 340rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 28rpx;
|
||||
background:
|
||||
linear-gradient(135deg, rgba(73, 101, 85, 0.95), rgba(179, 131, 90, 0.95)),
|
||||
radial-gradient(circle at 24% 22%, rgba(255, 245, 223, 0.28), transparent 36%);
|
||||
box-shadow: 0 22rpx 46rpx rgba(83, 64, 44, 0.18);
|
||||
}
|
||||
|
||||
.cover-preview,
|
||||
.cover-preview image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.cover-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10rpx;
|
||||
color: rgba(255, 255, 255, 0.82);
|
||||
}
|
||||
|
||||
.cover-empty-title {
|
||||
font-size: 36rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.cover-empty-desc {
|
||||
font-size: 23rpx;
|
||||
font-weight: 600;
|
||||
opacity: 0.86;
|
||||
}
|
||||
|
||||
.cover-badge {
|
||||
position: absolute;
|
||||
top: 26rpx;
|
||||
left: 28rpx;
|
||||
z-index: 2;
|
||||
padding: 8rpx 20rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(255, 244, 222, 0.88);
|
||||
color: #5b4635;
|
||||
font-size: 22rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.cover-actions {
|
||||
position: absolute;
|
||||
right: 28rpx;
|
||||
bottom: 26rpx;
|
||||
left: 28rpx;
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.cover-btn,
|
||||
.cover-remove {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 64rpx;
|
||||
padding: 0 20rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.cover-btn {
|
||||
flex: 1;
|
||||
background: #fff8ed;
|
||||
color: #6d4d35;
|
||||
}
|
||||
|
||||
.cover-remove {
|
||||
min-width: 150rpx;
|
||||
background: rgba(255, 253, 248, 0.18);
|
||||
color: #fffdf8;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
margin-top: 24rpx;
|
||||
padding: 12rpx 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.form-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6rpx;
|
||||
padding: 26rpx 26rpx 8rpx;
|
||||
}
|
||||
|
||||
.form-kicker {
|
||||
color: #92734f;
|
||||
font-size: 22rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 108rpx;
|
||||
gap: 18rpx;
|
||||
padding: 12rpx 24rpx;
|
||||
border-bottom: 1rpx solid #eee8df;
|
||||
}
|
||||
|
||||
.field:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.field-column {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
min-height: 232rpx;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
flex: 0 0 160rpx;
|
||||
color: #625c55;
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.field-column .field-label {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.field input,
|
||||
.intro-editor {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 70rpx;
|
||||
padding: 0 22rpx;
|
||||
border: 1rpx solid #eadfd2;
|
||||
border-radius: 18rpx;
|
||||
background: #fff8f2;
|
||||
color: #3d3128;
|
||||
font-size: 28rpx;
|
||||
line-height: 70rpx;
|
||||
}
|
||||
|
||||
.intro-editor {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-height: 156rpx;
|
||||
padding: 18rpx 22rpx 42rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.intro-editor textarea {
|
||||
width: 100%;
|
||||
height: 104rpx;
|
||||
color: #3d3128;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.intro-placeholder {
|
||||
color: #b4a79b;
|
||||
}
|
||||
|
||||
.intro-count {
|
||||
position: absolute;
|
||||
right: 22rpx;
|
||||
bottom: 12rpx;
|
||||
color: #b2a396;
|
||||
font-size: 20rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.fixed-bottom {
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.bottom-half-btn {
|
||||
flex: 1;
|
||||
}
|
||||
Reference in New Issue
Block a user