重构项目文件夹目录

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,247 @@
/**
* 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')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
const { consumeDirty } = require('../../utils/page-state')
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: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: '',
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: [],
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false,
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入店铺管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: permissionCodes.includes('shop:create')
})
if (!this.data.initialized || consumeDirty('admin-shops')) {
this.loadShops()
}
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input 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.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: event.detail.value
})
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search 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.
*/
handleSearch() {
this.loadShops()
},
async loadShops() {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: true
})
try {
const result = await shopApi.listShops({
/**
* Purpose: page supports index.js by holding or executing the page 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.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size 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.
*/
size: 20,
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: this.data.keyword || undefined
})
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
/**
* Purpose: displayStatusText supports index.js by holding or executing the display status text 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.
*/
displayStatusText: Number(item.status) === 0 ? '已停用' : '启用中'
})),
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: true
})
} catch (error) {
if (requestId !== this._loadRequestId) {
return
}
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 {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false
})
}
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create 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.
*/
handleCreate() {
clearTempRecord('currentShopRecord')
navigation.navigate('/pages/shop-form/index', {
/**
* 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'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit(event) {
const shop = event.currentTarget.dataset.shop
setTempRecord('currentShopRecord', shop)
navigation.navigate('/pages/shop-form/index', {
/**
* 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: 'edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: shop.id
}).catch(() => undefined)
},
/**
* Purpose: handleStatus supports index.js by holding or executing the handle status 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.
*/
handleStatus(event) {
const shop = event.currentTarget.dataset.shop
const nextStatus = Number(shop.status) === 0 ? 1 : 0
shopApi.updateShopStatus(shop.id, nextStatus)
.then(() => {
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'
})
this.loadShops()
})
.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,50 @@
<navigation-bar title="店铺管理" 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="search-row">
<input class="field-input search-input" placeholder="按店铺名搜索" placeholder-class="placeholder" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch"></input>
<button class="secondary-btn" bindtap="handleSearch">搜索</button>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.shopName}}</text>
<text class="list-subtitle">{{item.address || '暂无地址'}}</text>
</view>
<text class="{{item.status === 0 ? 'danger-badge' : 'badge'}}">{{item.displayStatusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">营业时间</text>
<text class="meta-value">{{item.businessHours || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">描述</text>
<text class="meta-value">{{item.description || '暂无描述'}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-shop="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn" data-shop="{{item}}" bindtap="handleStatus">{{item.status === 0 ? '启用' : '停用'}}</view>
</view>
</view>
</block>
<view wx:if="{{loading && !list.length}}" class="empty-state">
<text class="empty-title">正在加载店铺列表</text>
</view>
<view wx:elif="{{!list.length}}" class="empty-state">
<text class="empty-title">暂无店铺</text>
<text class="empty-desc">如果这是首次部署后的无店铺管理员登录,可以直接在这里创建第一家店铺。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}