Files

268 lines
13 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 18:45:41 +08:00
/**
* 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')
2026-05-23 18:45:41 +08:00
/**
* 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')
2026-05-23 18:45:41 +08:00
/**
* 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')
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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: {
2026-05-23 18:45:41 +08:00
/**
* 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: '',
2026-05-23 18:45:41 +08:00
/**
* 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: '',
2026-05-23 18:45:41 +08:00
/**
* 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,
2026-05-23 18:45:41 +08:00
/**
* 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: [],
2026-05-23 18:45:41 +08:00
/**
* 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,
2026-05-23 18:45:41 +08:00
/**
* 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
},
2026-05-23 18:45:41 +08:00
/**
* 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()
}
},
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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
})
},
2026-05-23 18:45:41 +08:00
/**
* 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()
},
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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,
2026-05-23 18:45:41 +08:00
/**
* 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,
2026-05-23 18:45:41 +08:00
/**
* 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,
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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,
2026-05-23 18:45:41 +08:00
/**
* 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),
2026-05-23 18:45:41 +08:00
/**
* 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),
2026-05-23 18:45:41 +08:00
/**
* 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)
})),
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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 || '用户列表加载失败',
2026-05-23 18:45:41 +08:00
/**
* 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({
2026-05-23 18:45:41 +08:00
/**
* 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
})
}
}
},
2026-05-23 18:45:41 +08:00
/**
* 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', {
2026-05-23 18:45:41 +08:00
/**
* 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)
},
2026-05-23 18:45:41 +08:00
/**
* 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', {
2026-05-23 18:45:41 +08:00
/**
* 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',
2026-05-23 18:45:41 +08:00
/**
* 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)
},
2026-05-23 18:45:41 +08:00
/**
* 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', {
2026-05-23 18:45:41 +08:00
/**
* 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)
}
})