重构项目文件夹目录

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,267 @@
/**
* Purpose: userApi supports index.js by holding or executing the user 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 userApi = require('../../api/user')
/**
* 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: format supports index.js by holding or executing the format 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 format = require('../../utils/format')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
const { consumeDirty } = require('../../utils/page-state')
/**
* Purpose: TYPE_OPTIONS supports index.js by holding or executing the type options 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 TYPE_OPTIONS = [
{ label: '全部角色', value: '' },
{ label: '普通用户', value: 0 },
{ label: '店长', value: 2 },
{ label: '美甲师', value: 3 },
{ label: '管理员', value: 4 }
]
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: type supports index.js by holding or executing the type 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.
*/
type: '',
/**
* Purpose: typeOptions supports index.js by holding or executing the type 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.
*/
typeOptions: TYPE_OPTIONS,
/**
* 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: 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
}
if (!this.data.initialized || consumeDirty('admin-users')) {
this.loadUsers()
}
},
/**
* 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.loadUsers()
},
/**
* Purpose: handleTypeChange supports index.js by holding or executing the handle type 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.
*/
handleTypeChange(event) {
this.setData({
/**
* Purpose: type supports index.js by holding or executing the type 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.
*/
type: event.currentTarget.dataset.type
})
this.loadUsers()
},
async loadUsers() {
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 userApi.listUsers({
/**
* 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,
/**
* Purpose: type supports index.js by holding or executing the type 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.
*/
type: this.data.type === '' ? undefined : this.data.type
})
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: displayShopName supports index.js by holding or executing the display 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.
*/
displayShopName: format.buildShopName(item),
/**
* Purpose: displayTypeText supports index.js by holding or executing the display type 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.
*/
displayTypeText: format.getUserTypeText(item.type),
/**
* 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: format.getUserStatusText(item.status)
})),
/**
* 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: handleOpenDetail supports index.js by holding or executing the handle open detail 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.
*/
handleOpenDetail(event) {
const user = event.currentTarget.dataset.user
setTempRecord('currentUser', user)
navigation.navigate('/pages/user-detail/index', {
/**
* 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: user.id
}).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 user = event.currentTarget.dataset.user
setTempRecord('currentUser', user)
navigation.navigate('/pages/user-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: user.id
}).catch(() => undefined)
},
/**
* 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('currentUser')
navigation.navigate('/pages/user-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)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,63 @@
<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 class="chip-row">
<block wx:for="{{typeOptions}}" wx:key="label">
<view class="chip-btn {{type === item.value ? 'active' : ''}}" data-type="{{item.value}}" bindtap="handleTypeChange">{{item.label}}</view>
</block>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.nickname || '未命名用户'}} · {{item.account}}</text>
<text class="list-subtitle">{{item.displayShopName}}</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.displayTypeText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">手机号</text>
<text class="meta-value">{{item.phone || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">VIP</text>
<text class="meta-value">{{item.vipLevel || item.level || '普通'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">创建时间</text>
<text class="meta-value">{{item.createTime}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn" data-user="{{item}}" bindtap="handleOpenDetail">详情</view>
<view class="mini-btn primary" data-user="{{item}}" bindtap="handleEdit">编辑</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 class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}