重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,423 @@
/**
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopApi = require('../../api/shop')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: upload supports index.js by holding or executing the upload page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const upload = require('../../utils/upload')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
const { markDirty } = require('../../utils/page-state')
/**
* Purpose: DRAFT_KEY supports index.js by holding or executing the draft key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const DRAFT_KEY = 'admin-shop-form'
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create',
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: '',
/**
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploading: false,
/**
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadProgress: 0,
/**
* Purpose: statusOptions supports index.js by holding or executing the status options page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusOptions: ['启用', '停用'],
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: 0,
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: shopName supports index.js by holding or executing the shop name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopName: '',
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: '',
/**
* Purpose: address supports index.js by holding or executing the address page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
address: '',
/**
* Purpose: businessHours supports index.js by holding or executing the business hours page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
businessHours: '',
/**
* Purpose: coverImageFileId supports index.js by holding or executing the cover image file id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coverImageFileId: '',
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: []
}
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
const mode = options && options.mode ? options.mode : 'create'
const currentShop = getTempRecord('currentShopRecord', null)
const draft = getDraftValue(DRAFT_KEY, null)
this.setData({
mode,
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: options && options.id ? options.id : ''
})
if (mode === 'edit' && currentShop) {
this.setData({
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: shopName supports index.js by holding or executing the shop name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopName: currentShop.shopName || '',
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: currentShop.description || '',
/**
* Purpose: address supports index.js by holding or executing the address page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
address: currentShop.address || '',
/**
* Purpose: businessHours supports index.js by holding or executing the business hours page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
businessHours: currentShop.businessHours || '',
/**
* Purpose: coverImageFileId supports index.js by holding or executing the cover image file id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coverImageFileId: currentShop.coverImageFileId || '',
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: currentShop.imageFileIds ? String(currentShop.imageFileIds).split(',').filter(Boolean) : []
},
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: Number(currentShop.status) === 0 ? 1 : 0
})
}
if (draft && draft.mode === mode) {
this.setData({
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
...this.data.form,
...draft.form
},
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: draft.statusIndex === 1 ? 1 : this.data.statusIndex
})
}
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
clearTempRecord('currentShopRecord')
clearDraftTimer(this)
},
/**
* Purpose: scheduleShopDraft supports index.js by holding or executing the schedule shop draft page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
scheduleShopDraft() {
scheduleDraftSave(this, DRAFT_KEY, () => ({
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: this.data.mode,
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: this.data.statusIndex,
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
...this.data.form,
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: this.data.form.imageFileIds.slice()
}
}))
},
/**
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleInputChange(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
this.scheduleShopDraft()
},
/**
* Purpose: handleStatusChange supports index.js by holding or executing the handle status change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleStatusChange(event) {
this.setData({
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: Number(event.detail.value)
})
this.scheduleShopDraft()
},
async handleUploadBanner() {
await this.handleUpload('admin-shop-banner', true)
},
async handleUploadImages() {
await this.handleUpload('admin-shop-image', false)
},
async handleUpload(scene, isBanner) {
try {
const files = await upload.chooseImageFiles({
/**
* Purpose: count supports index.js by holding or executing the count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
count: isBanner ? 1 : 9
})
this.setData({
/**
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploading: true,
/**
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadProgress: 0
})
const results = await upload.uploadImageFiles({
files,
scene,
/**
* Purpose: onProgress supports index.js by holding or executing the on progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
onProgress: progress => {
this.setData({
/**
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadProgress: Math.round(progress)
})
}
})
if (isBanner) {
this.setData({
'form.coverImageFileId': results[0] ? String(results[0].id) : ''
})
} else {
this.setData({
'form.imageFileIds': this.data.form.imageFileIds.concat(results.map(item => String(item.id)))
})
}
this.scheduleShopDraft()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '图片上传失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({
/**
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploading: false
})
}
},
async handleSubmit() {
if (!this.data.form.shopName) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请输入店铺名称',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
const payload = {
/**
* Purpose: shopName supports index.js by holding or executing the shop name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopName: this.data.form.shopName,
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: this.data.form.description || undefined,
/**
* Purpose: address supports index.js by holding or executing the address page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
address: this.data.form.address || undefined,
/**
* Purpose: businessHours supports index.js by holding or executing the business hours page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
businessHours: this.data.form.businessHours || undefined,
/**
* Purpose: coverImageFileId supports index.js by holding or executing the cover image file id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coverImageFileId: this.data.form.coverImageFileId || undefined,
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
/**
* Purpose: status supports index.js by holding or executing the status page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
status: this.data.statusIndex === 1 ? 0 : 1
}
try {
if (this.data.mode === 'edit') {
await shopApi.updateShop(this.data.shopId, payload)
} else {
await shopApi.createShop(payload)
}
clearDraft(DRAFT_KEY)
markDirty('admin-shops')
markDirty('admin-workbench')
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: this.data.mode === 'edit' ? '店铺已更新' : '店铺已创建',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
navigation.goBack('/pages/shops/index')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '保存失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,55 @@
<navigation-bar title="{{mode === 'edit' ? '编辑店铺' : '新增店铺'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">店铺信息</text>
<view class="field-group">
<text class="field-label">店铺名称</text>
<input class="field-input" value="{{form.shopName}}" data-field="shopName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">店铺地址</text>
<input class="field-input" value="{{form.address}}" data-field="address" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">营业时间</text>
<input class="field-input" value="{{form.businessHours}}" data-field="businessHours" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">店铺描述</text>
<textarea class="field-textarea" value="{{form.description}}" data-field="description" bindinput="handleInputChange"></textarea>
</view>
<view class="field-group">
<text class="field-label">状态</text>
<picker mode="selector" range="{{statusOptions}}" value="{{statusIndex}}" bindchange="handleStatusChange">
<view class="field-picker">{{statusOptions[statusIndex]}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">Banner 图</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleUploadBanner">上传 Banner</view>
</view>
<view wx:if="{{form.coverImageFileId}}" class="image-grid">
<view class="image-chip">{{form.coverImageFileId}}</view>
</view>
</view>
<view class="field-group">
<text class="field-label">店铺图片</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleUploadImages">上传图片</view>
</view>
<view wx:if="{{form.imageFileIds.length}}" class="image-grid">
<block wx:for="{{form.imageFileIds}}" wx:key="*this">
<view class="image-chip">{{item}}</view>
</block>
</view>
</view>
<view wx:if="{{uploading}}" class="hint-card">图片上传中,当前进度 {{uploadProgress}}%</view>
<view class="action-row">
<button class="primary-btn" disabled="{{uploading}}" bindtap="handleSubmit">保存店铺</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}