功能:收口小程序前后台安全与防重复提交
@@ -0,0 +1,91 @@
|
||||
# YumiNail-Admin-Program
|
||||
|
||||
## 项目定位
|
||||
|
||||
`YumiNail-Admin-Program` 是独立的后台管理小程序,用来承接平台管理员、店长、美甲师三类后台角色的移动端工作流。
|
||||
|
||||
它与以下端长期并存:
|
||||
|
||||
- `YumiNail-Frontend`:网页前台 + Web 后台
|
||||
- `WeChatProgram`:普通用户小程序
|
||||
- `YumiNail-Admin-Program`:移动端后台小程序
|
||||
|
||||
首版目标是“能力对齐 + 移动端重构”,不是把 Web 后台按 1:1 搬进小程序。
|
||||
|
||||
## 当前能力
|
||||
|
||||
- 后台账号密码登录
|
||||
- 登录前按账号预加载可登录店铺
|
||||
- 平台管理员支持无店铺登录后先进入店铺初始化
|
||||
- 工作台 / 订单 / 经营 / 我的 四个一级入口
|
||||
- 用户、作品、优惠券、标签、美甲师、店铺、权限管理页面
|
||||
- 后台分片上传链路复用
|
||||
- 店铺切换、权限显隐、按钮级禁用
|
||||
- 用户余额 / VIP 管理
|
||||
- 美甲师订单处理入口
|
||||
|
||||
## 目录结构
|
||||
|
||||
```text
|
||||
YumiNail-Admin-Program/
|
||||
├─ api/ 后台接口封装
|
||||
├─ assets/ tabBar 图标等静态资源
|
||||
├─ components/ 公共组件
|
||||
├─ pages/ 小程序页面
|
||||
├─ utils/ 请求、鉴权、权限、上传、导航等工具
|
||||
├─ app.js
|
||||
├─ app.json
|
||||
├─ app.wxss
|
||||
├─ project.config.json
|
||||
└─ sitemap.json
|
||||
```
|
||||
|
||||
## 关键约定
|
||||
|
||||
### 1. 接口基址
|
||||
|
||||
接口统一走:
|
||||
|
||||
- 开发工具 `develop` 环境:`http://127.0.0.1:80/admin/api`
|
||||
- 其他环境:`https://yunail.art/admin/api`
|
||||
|
||||
逻辑在:
|
||||
|
||||
- `utils/config.js`
|
||||
- `utils/request.js`
|
||||
|
||||
### 2. 会话存储
|
||||
|
||||
管理小程序与用户小程序完全隔离,固定使用以下本地存储键:
|
||||
|
||||
- `adminAccessToken`
|
||||
- `adminRefreshToken`
|
||||
- `adminUserInfo`
|
||||
- `adminPermissions`
|
||||
- `adminCurrentShop`
|
||||
|
||||
### 3. 权限真源
|
||||
|
||||
小程序只做导航和按钮显隐,最终权限以服务端为准:
|
||||
|
||||
- 服务端:`@RequirePermission`
|
||||
- 小程序端:`utils/permission.js`
|
||||
|
||||
### 4. 店铺上下文
|
||||
|
||||
- 平台管理员可跨店铺操作,也可在无店铺状态下登录
|
||||
- 店长和美甲师默认受当前店铺上下文限制
|
||||
- 表单页会按所选店铺联动过滤标签、优惠券、美甲师、作品等数据
|
||||
|
||||
## 导入与联调
|
||||
|
||||
1. 用微信开发者工具导入 `YumiNail-Admin-Program`
|
||||
2. 确认后端 `YumiNail-Core` 与 `YumiNail-Gateway` 已启动
|
||||
3. 开发环境如需走本地地址,确保网关监听在 `80`
|
||||
4. 使用后台账号登录,先验证店铺列表、权限菜单和订单页
|
||||
|
||||
## 本轮注意事项
|
||||
|
||||
- 本轮没有新增数据库表、没有改 SQL、没有改后端权限模型
|
||||
- 主要是新增独立小程序前端,并对齐现有后台接口
|
||||
- 代码层已做 JS 语法检查,但还需要你在微信开发者工具里做一次真实页面联调
|
||||
@@ -0,0 +1,44 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
login(data) {
|
||||
return request({
|
||||
url: '/auth/login',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
getLoginShops(account) {
|
||||
return request({
|
||||
url: `/auth/login-shops/${encodeURIComponent(account)}`
|
||||
})
|
||||
},
|
||||
|
||||
switchShop(shopId) {
|
||||
return request({
|
||||
url: '/auth/switch-shop',
|
||||
method: 'POST',
|
||||
data: {
|
||||
shopId: shopId || undefined
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
refreshToken(refreshToken) {
|
||||
return request({
|
||||
url: '/auth/refresh',
|
||||
method: 'POST',
|
||||
data: {
|
||||
refreshToken
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
logout() {
|
||||
return request({
|
||||
url: '/auth/logout',
|
||||
method: 'POST'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listCoupons(params) {
|
||||
return request({
|
||||
url: '/coupon/list',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
listAllCoupons(shopId) {
|
||||
return request({
|
||||
url: '/coupon/list/all',
|
||||
params: shopId ? { shopId } : undefined
|
||||
})
|
||||
},
|
||||
|
||||
getCouponDetail(id) {
|
||||
return request({
|
||||
url: `/coupon/detail/${id}`
|
||||
})
|
||||
},
|
||||
|
||||
createCoupon(data) {
|
||||
return request({
|
||||
url: '/coupon/create',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateCoupon(id, data) {
|
||||
return request({
|
||||
url: `/coupon/update/${id}`,
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
deleteCoupon(id) {
|
||||
return request({
|
||||
url: `/coupon/delete/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
},
|
||||
|
||||
assignCoupon(data) {
|
||||
return request({
|
||||
url: '/coupon/assign',
|
||||
method: 'POST',
|
||||
params: data,
|
||||
data: {}
|
||||
})
|
||||
},
|
||||
|
||||
distributeCoupon(data) {
|
||||
return request({
|
||||
url: '/coupon/distribute',
|
||||
method: 'POST',
|
||||
params: data,
|
||||
data: {}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
getStats() {
|
||||
return request({
|
||||
url: '/dashboard/stats'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
const request = require('../utils/request')
|
||||
const actionGuard = require('../utils/action-guard')
|
||||
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
|
||||
|
||||
function normalizeUploadResponse(response) {
|
||||
if (!response) {
|
||||
throw new Error('上传失败')
|
||||
}
|
||||
|
||||
if (response.statusCode === 401) {
|
||||
throw new Error('登录已过期,请重新登录')
|
||||
}
|
||||
|
||||
if (response.statusCode >= 400) {
|
||||
throw new Error('上传失败')
|
||||
}
|
||||
|
||||
let payload = response.data
|
||||
if (typeof payload === 'string') {
|
||||
try {
|
||||
payload = JSON.parse(payload)
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
if (payload && typeof payload === 'object' && Object.prototype.hasOwnProperty.call(payload, 'code')) {
|
||||
if (payload.code === 200) {
|
||||
return payload.data
|
||||
}
|
||||
throw new Error(payload.message || '上传失败')
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initChunkUpload(data) {
|
||||
return request({
|
||||
url: '/object-storage-file/upload/init',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
uploadChunkFile(options) {
|
||||
const signedHeaders = request.buildSignatureHeaders({
|
||||
url: '/object-storage-file/upload/chunk',
|
||||
method: 'POST',
|
||||
formData: {
|
||||
uploadId: String(options.uploadId),
|
||||
chunkIndex: String(options.chunkIndex),
|
||||
totalChunks: String(options.totalChunks)
|
||||
}
|
||||
})
|
||||
|
||||
return actionGuard.run(
|
||||
null,
|
||||
`POST:/object-storage-file/upload/chunk:${String(options.uploadId)}:${String(options.chunkIndex)}`,
|
||||
() => new Promise((resolve, reject) => {
|
||||
const task = wx.uploadFile({
|
||||
url: `${ADMIN_API_BASE_URL}/object-storage-file/upload/chunk`,
|
||||
filePath: options.filePath,
|
||||
name: 'chunk',
|
||||
timeout: REQUEST_TIMEOUT,
|
||||
formData: {
|
||||
uploadId: String(options.uploadId),
|
||||
chunkIndex: String(options.chunkIndex),
|
||||
totalChunks: String(options.totalChunks)
|
||||
},
|
||||
header: signedHeaders,
|
||||
success: response => {
|
||||
try {
|
||||
resolve(normalizeUploadResponse(response))
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
},
|
||||
fail: error => {
|
||||
reject(new Error(error.errMsg || '上传分片失败'))
|
||||
}
|
||||
})
|
||||
|
||||
if (task && typeof task.onProgressUpdate === 'function' && typeof options.onProgress === 'function') {
|
||||
task.onProgressUpdate(progress => {
|
||||
options.onProgress(progress)
|
||||
})
|
||||
}
|
||||
}),
|
||||
{
|
||||
message: '上传处理中,请勿重复操作'
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
completeChunkUpload(uploadId) {
|
||||
return request({
|
||||
url: '/object-storage-file/upload/complete',
|
||||
method: 'POST',
|
||||
data: {
|
||||
uploadId
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
cancelChunkUpload(uploadId) {
|
||||
return request({
|
||||
url: `/object-storage-file/upload/${uploadId}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
},
|
||||
|
||||
getSignedUrl(fileId) {
|
||||
return request({
|
||||
url: `/object-storage-file/get-signed-url/${fileId}`
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listNailArtists() {
|
||||
return request({
|
||||
url: '/nail-artist/list'
|
||||
})
|
||||
},
|
||||
|
||||
getNailArtistInfo(userId) {
|
||||
return request({
|
||||
url: `/nail-artist/get/${userId}`
|
||||
})
|
||||
},
|
||||
|
||||
saveNailArtistInfo(data) {
|
||||
return request({
|
||||
url: '/nail-artist/save',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listOrders(params) {
|
||||
return request({
|
||||
url: '/order/list',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
updateOrderStatus(id, status) {
|
||||
return request({
|
||||
url: `/order/update-status/${id}`,
|
||||
method: 'PUT',
|
||||
params: {
|
||||
status
|
||||
},
|
||||
data: {}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
getCurrentUserPermissions() {
|
||||
return request({
|
||||
url: '/permission/user/current'
|
||||
})
|
||||
},
|
||||
|
||||
getUserPermissions(userId) {
|
||||
return request({
|
||||
url: `/permission/user/${userId}`
|
||||
})
|
||||
},
|
||||
|
||||
getAssignablePermissionIds(userId) {
|
||||
return request({
|
||||
url: `/permission/assignable/${userId}`
|
||||
})
|
||||
},
|
||||
|
||||
listAllPermissions() {
|
||||
return request({
|
||||
url: '/permission/list/all'
|
||||
})
|
||||
},
|
||||
|
||||
createPermission(data) {
|
||||
return request({
|
||||
url: '/permission/create',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updatePermission(id, data) {
|
||||
return request({
|
||||
url: `/permission/update/${id}`,
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
deletePermission(id) {
|
||||
return request({
|
||||
url: `/permission/delete/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
},
|
||||
|
||||
assignUserPermissions(userId, permissionIds) {
|
||||
return request({
|
||||
url: `/permission/assign/${userId}`,
|
||||
method: 'POST',
|
||||
data: {
|
||||
permissionIds
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listProducts(params) {
|
||||
return request({
|
||||
url: '/product/list',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
listAllProducts() {
|
||||
return request({
|
||||
url: '/product/list/all'
|
||||
})
|
||||
},
|
||||
|
||||
createProduct(data) {
|
||||
return request({
|
||||
url: '/product/create',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateProduct(id, data) {
|
||||
return request({
|
||||
url: `/product/update/${id}`,
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
deleteProduct(id) {
|
||||
return request({
|
||||
url: `/product/delete/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listShops(params) {
|
||||
return request({
|
||||
url: '/shops/list',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
listAllShops() {
|
||||
return request({
|
||||
url: '/shops/list/all'
|
||||
})
|
||||
},
|
||||
|
||||
getShop(id) {
|
||||
return request({
|
||||
url: `/shops/${id}`
|
||||
})
|
||||
},
|
||||
|
||||
createShop(data) {
|
||||
return request({
|
||||
url: '/shops/create',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateShop(id, data) {
|
||||
return request({
|
||||
url: `/shops/update/${id}`,
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateShopStatus(id, status) {
|
||||
return request({
|
||||
url: `/shops/status/${id}`,
|
||||
method: 'PUT',
|
||||
data: {
|
||||
status
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
deleteShop(id) {
|
||||
return request({
|
||||
url: `/shops/delete/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listAllTags() {
|
||||
return request({
|
||||
url: '/tag/list/all'
|
||||
})
|
||||
},
|
||||
|
||||
listTagsByShopId(shopId) {
|
||||
return request({
|
||||
url: `/tag/list/by-shop/${shopId}`
|
||||
})
|
||||
},
|
||||
|
||||
getTagById(id) {
|
||||
return request({
|
||||
url: `/tag/get/${id}`
|
||||
})
|
||||
},
|
||||
|
||||
createTag(data) {
|
||||
return request({
|
||||
url: '/tag/create',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateTag(id, data) {
|
||||
return request({
|
||||
url: `/tag/update/${id}`,
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
deleteTag(id) {
|
||||
return request({
|
||||
url: `/tag/delete/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
listUsers(params) {
|
||||
return request({
|
||||
url: '/user/list',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
listAllUsers() {
|
||||
return request({
|
||||
url: '/user/list/all'
|
||||
})
|
||||
},
|
||||
|
||||
listArtists(shopId) {
|
||||
return request({
|
||||
url: '/user/list/artists',
|
||||
params: shopId ? { shopId } : undefined
|
||||
})
|
||||
},
|
||||
|
||||
createUser(data) {
|
||||
return request({
|
||||
url: '/user/create',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateUser(id, data) {
|
||||
return request({
|
||||
url: `/user/update/${id}`,
|
||||
method: 'PUT',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updateUserStatus(id, status) {
|
||||
return request({
|
||||
url: `/user/status/${id}`,
|
||||
method: 'PUT',
|
||||
data: {
|
||||
status
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
deleteUser(id) {
|
||||
return request({
|
||||
url: `/user/delete/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
},
|
||||
|
||||
unbindUser(id) {
|
||||
return request({
|
||||
url: `/user/unbind/${id}`,
|
||||
method: 'PUT',
|
||||
data: {}
|
||||
})
|
||||
},
|
||||
|
||||
resetPassword(id) {
|
||||
return request({
|
||||
url: `/user/reset-password/${id}`,
|
||||
method: 'POST'
|
||||
})
|
||||
},
|
||||
|
||||
getCurrentUserInfo() {
|
||||
return request({
|
||||
url: '/user/info'
|
||||
})
|
||||
},
|
||||
|
||||
getUserAsset(id) {
|
||||
return request({
|
||||
url: `/user/${id}/asset`
|
||||
})
|
||||
},
|
||||
|
||||
getUserBalanceHistory(id) {
|
||||
return request({
|
||||
url: `/user/${id}/balance/history`
|
||||
})
|
||||
},
|
||||
|
||||
changeUserBalance(id, data) {
|
||||
return request({
|
||||
url: `/user/${id}/balance/change`,
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
overrideUserVip(id, data) {
|
||||
return request({
|
||||
url: `/user/${id}/vip/override`,
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
recalculateUserVip(id) {
|
||||
return request({
|
||||
url: `/user/${id}/vip/recalculate`,
|
||||
method: 'POST'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
const auth = require('./utils/auth')
|
||||
const permission = require('./utils/permission')
|
||||
const { resetLoading } = require('./utils/loading')
|
||||
const idleSession = require('./utils/idle-session')
|
||||
const { IDLE_TIMEOUT_MS, IDLE_WARNING_MS } = require('./utils/config')
|
||||
const permissionApi = require('./api/permission')
|
||||
const authApi = require('./api/auth')
|
||||
|
||||
function buildCurrentShop(userInfo) {
|
||||
if (!userInfo || !userInfo.shopId) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
id: userInfo.shopId,
|
||||
shopName: userInfo.shopName || ''
|
||||
}
|
||||
}
|
||||
|
||||
App({
|
||||
globalData: {
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
permissions: [],
|
||||
permissionCodes: [],
|
||||
pageDirtyFlags: {}
|
||||
},
|
||||
|
||||
onLaunch() {
|
||||
idleSession.init({
|
||||
timeoutMs: IDLE_TIMEOUT_MS,
|
||||
warningMs: IDLE_WARNING_MS,
|
||||
isLoggedIn: () => auth.isLoggedIn(),
|
||||
onLogout: () => this.handleIdleLogout()
|
||||
})
|
||||
this.bootstrapSession()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
idleSession.onAppShow()
|
||||
},
|
||||
|
||||
onHide() {
|
||||
idleSession.onAppHide()
|
||||
},
|
||||
|
||||
bootstrapSession() {
|
||||
resetLoading()
|
||||
|
||||
const userInfo = auth.getStoredUserInfo()
|
||||
const currentShop = auth.getCurrentShop() || buildCurrentShop(userInfo)
|
||||
const permissions = auth.getStoredPermissions()
|
||||
|
||||
if (currentShop) {
|
||||
auth.setCurrentShop(currentShop)
|
||||
}
|
||||
|
||||
this.globalData.isLoggedIn = auth.isLoggedIn()
|
||||
this.globalData.userInfo = userInfo
|
||||
this.globalData.currentShop = currentShop
|
||||
this.setPermissionState(permissions)
|
||||
|
||||
if (this.globalData.isLoggedIn && !permissions.length) {
|
||||
this.loadCurrentPermissions().catch(() => undefined)
|
||||
}
|
||||
},
|
||||
|
||||
setPermissionState(permissions) {
|
||||
const list = Array.isArray(permissions) ? permissions : []
|
||||
this.globalData.permissions = list
|
||||
this.globalData.permissionCodes = permission.getPermissionCodes(list)
|
||||
},
|
||||
|
||||
async setAdminSession(payload) {
|
||||
auth.setSession(payload)
|
||||
this.bootstrapSession()
|
||||
await this.loadCurrentPermissions().catch(() => [])
|
||||
},
|
||||
|
||||
async loadCurrentPermissions() {
|
||||
if (!auth.isLoggedIn()) {
|
||||
auth.clearPermissions()
|
||||
this.setPermissionState([])
|
||||
return []
|
||||
}
|
||||
|
||||
const permissions = await permissionApi.getCurrentUserPermissions()
|
||||
auth.setPermissions(permissions)
|
||||
this.setPermissionState(permissions)
|
||||
return permissions
|
||||
},
|
||||
|
||||
refreshUserInfo(userInfo) {
|
||||
auth.updateStoredUserInfo(userInfo)
|
||||
|
||||
if (userInfo && userInfo.shopId) {
|
||||
auth.setCurrentShop({
|
||||
id: userInfo.shopId,
|
||||
shopName: userInfo.shopName || ''
|
||||
})
|
||||
}
|
||||
|
||||
this.bootstrapSession()
|
||||
},
|
||||
|
||||
clearAdminSession() {
|
||||
auth.clearSession()
|
||||
this.globalData.isLoggedIn = false
|
||||
this.globalData.userInfo = null
|
||||
this.globalData.currentShop = null
|
||||
this.globalData.pageDirtyFlags = {}
|
||||
this.setPermissionState([])
|
||||
},
|
||||
|
||||
async handleIdleLogout() {
|
||||
if (!auth.isLoggedIn()) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await authApi.logout()
|
||||
} catch (error) {}
|
||||
this.clearAdminSession()
|
||||
wx.showToast({
|
||||
title: '长时间未操作,已退出登录',
|
||||
icon: 'none'
|
||||
})
|
||||
setTimeout(() => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}, 260)
|
||||
},
|
||||
|
||||
async switchAdminShop(shopId) {
|
||||
const payload = await authApi.switchShop(shopId)
|
||||
await this.setAdminSession(payload)
|
||||
return payload
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/login/index",
|
||||
"pages/workbench/index",
|
||||
"pages/orders/index",
|
||||
"pages/manage/index",
|
||||
"pages/profile/index",
|
||||
"pages/users/index",
|
||||
"pages/user-detail/index",
|
||||
"pages/user-form/index",
|
||||
"pages/products/index",
|
||||
"pages/product-form/index",
|
||||
"pages/coupons/index",
|
||||
"pages/coupon-form/index",
|
||||
"pages/coupon-distribute/index",
|
||||
"pages/tags/index",
|
||||
"pages/tag-form/index",
|
||||
"pages/artists/index",
|
||||
"pages/artist-form/index",
|
||||
"pages/shops/index",
|
||||
"pages/shop-form/index",
|
||||
"pages/permissions/index",
|
||||
"pages/permission-form/index",
|
||||
"pages/order-detail/index"
|
||||
],
|
||||
"window": {
|
||||
"navigationBarTextStyle": "white",
|
||||
"navigationStyle": "custom",
|
||||
"backgroundTextStyle": "dark",
|
||||
"backgroundColor": "#081518"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#7e8f8c",
|
||||
"selectedColor": "#f07e57",
|
||||
"backgroundColor": "#081518",
|
||||
"borderStyle": "black",
|
||||
"position": "bottom",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/workbench/index",
|
||||
"text": "工作台",
|
||||
"iconPath": "assets/tabbar/workbench.png",
|
||||
"selectedIconPath": "assets/tabbar/workbench-active.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/orders/index",
|
||||
"text": "订单",
|
||||
"iconPath": "assets/tabbar/orders.png",
|
||||
"selectedIconPath": "assets/tabbar/orders-active.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/manage/index",
|
||||
"text": "经营",
|
||||
"iconPath": "assets/tabbar/manage.png",
|
||||
"selectedIconPath": "assets/tabbar/manage-active.png"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/profile/index",
|
||||
"text": "我的",
|
||||
"iconPath": "assets/tabbar/profile.png",
|
||||
"selectedIconPath": "assets/tabbar/profile-active.png"
|
||||
}
|
||||
]
|
||||
},
|
||||
"style": "v2",
|
||||
"sitemapLocation": "sitemap.json",
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
}
|
||||
@@ -0,0 +1,481 @@
|
||||
page {
|
||||
min-height: 100%;
|
||||
background:
|
||||
radial-gradient(circle at top left, rgba(240, 126, 87, 0.18), transparent 30%),
|
||||
linear-gradient(180deg, #071417 0%, #0d2225 30%, #f5f0e8 30%, #f5f0e8 100%);
|
||||
color: #132024;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
view,
|
||||
text,
|
||||
button,
|
||||
input,
|
||||
textarea,
|
||||
scroll-view,
|
||||
swiper,
|
||||
swiper-item,
|
||||
picker,
|
||||
label,
|
||||
image,
|
||||
checkbox,
|
||||
checkbox-group {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
image {
|
||||
display: block;
|
||||
}
|
||||
|
||||
button {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
button::after {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.page-shell {
|
||||
min-height: 100vh;
|
||||
padding-bottom: calc(env(safe-area-inset-bottom) + 36rpx);
|
||||
}
|
||||
|
||||
.page-stack {
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.hero-panel {
|
||||
padding: 34rpx 30rpx;
|
||||
border-radius: 36rpx;
|
||||
background: linear-gradient(140deg, rgba(8, 21, 24, 0.96) 0%, rgba(20, 51, 52, 0.96) 100%);
|
||||
color: #f6efe7;
|
||||
box-shadow: 0 26rpx 64rpx rgba(7, 20, 23, 0.28);
|
||||
}
|
||||
|
||||
.hero-kicker {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
font-weight: 700;
|
||||
letter-spacing: 3rpx;
|
||||
color: #f7b296;
|
||||
}
|
||||
|
||||
.hero-title {
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
font-size: 48rpx;
|
||||
line-height: 1.2;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.hero-desc {
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.8;
|
||||
color: rgba(246, 239, 231, 0.78);
|
||||
}
|
||||
|
||||
.surface-card {
|
||||
margin-top: 24rpx;
|
||||
padding: 28rpx;
|
||||
border-radius: 30rpx;
|
||||
background: rgba(255, 252, 247, 0.96);
|
||||
border: 1rpx solid rgba(19, 32, 36, 0.08);
|
||||
box-shadow: 0 18rpx 44rpx rgba(26, 39, 42, 0.08);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
display: block;
|
||||
font-size: 34rpx;
|
||||
font-weight: 800;
|
||||
color: #132024;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
display: block;
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.7;
|
||||
color: #60706d;
|
||||
}
|
||||
|
||||
.field-group {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: block;
|
||||
margin-bottom: 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
color: #294248;
|
||||
}
|
||||
|
||||
.field-input,
|
||||
.field-picker,
|
||||
.field-textarea {
|
||||
width: 100%;
|
||||
min-height: 92rpx;
|
||||
padding: 0 24rpx;
|
||||
border-radius: 24rpx;
|
||||
background: #eef1ea;
|
||||
border: 1rpx solid rgba(19, 32, 36, 0.08);
|
||||
color: #132024;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.field-picker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.field-textarea {
|
||||
min-height: 200rpx;
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #9eaaa5;
|
||||
}
|
||||
|
||||
.status-text {
|
||||
display: block;
|
||||
margin-top: 10rpx;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.status-text.success {
|
||||
color: #2d8d60;
|
||||
}
|
||||
|
||||
.status-text.error {
|
||||
color: #be4f3b;
|
||||
}
|
||||
|
||||
.status-text.warning {
|
||||
color: #a66817;
|
||||
}
|
||||
|
||||
.primary-btn,
|
||||
.secondary-btn,
|
||||
.danger-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-height: 88rpx;
|
||||
padding: 0 28rpx;
|
||||
border-radius: 999rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: linear-gradient(135deg, #f8a37c 0%, #f07e57 100%);
|
||||
color: #fffaf4;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: rgba(8, 21, 24, 0.04);
|
||||
color: #173036;
|
||||
border: 1rpx solid rgba(8, 21, 24, 0.1);
|
||||
}
|
||||
|
||||
.danger-btn {
|
||||
background: rgba(190, 79, 59, 0.12);
|
||||
color: #b94432;
|
||||
}
|
||||
|
||||
.action-row {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.action-row .primary-btn,
|
||||
.action-row .secondary-btn,
|
||||
.action-row .danger-btn {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.badge-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.badge,
|
||||
.soft-badge,
|
||||
.danger-badge,
|
||||
.success-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 48rpx;
|
||||
padding: 0 18rpx;
|
||||
border-radius: 999rpx;
|
||||
font-size: 22rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.badge {
|
||||
background: rgba(240, 126, 87, 0.14);
|
||||
color: #d05f3d;
|
||||
}
|
||||
|
||||
.soft-badge {
|
||||
background: rgba(8, 21, 24, 0.06);
|
||||
color: #50625f;
|
||||
}
|
||||
|
||||
.danger-badge {
|
||||
background: rgba(190, 79, 59, 0.12);
|
||||
color: #b94432;
|
||||
}
|
||||
|
||||
.success-badge {
|
||||
background: rgba(45, 141, 96, 0.12);
|
||||
color: #2d8d60;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 16rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 24rpx;
|
||||
border-radius: 24rpx;
|
||||
background: rgba(8, 21, 24, 0.04);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
color: #667774;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
display: block;
|
||||
margin-top: 10rpx;
|
||||
font-size: 34rpx;
|
||||
font-weight: 800;
|
||||
color: #132024;
|
||||
}
|
||||
|
||||
.stat-note {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 22rpx;
|
||||
color: #7b8a87;
|
||||
}
|
||||
|
||||
.list-card {
|
||||
margin-top: 18rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 26rpx;
|
||||
background: #ffffff;
|
||||
border: 1rpx solid rgba(19, 32, 36, 0.08);
|
||||
}
|
||||
|
||||
.list-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.list-title {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
line-height: 1.5;
|
||||
font-weight: 800;
|
||||
color: #132024;
|
||||
}
|
||||
|
||||
.list-subtitle {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 22rpx;
|
||||
color: #768582;
|
||||
}
|
||||
|
||||
.meta-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12rpx 20rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.meta-item {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
display: block;
|
||||
font-size: 21rpx;
|
||||
color: #82918e;
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
font-size: 25rpx;
|
||||
color: #1b3035;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.list-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.mini-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 132rpx;
|
||||
min-height: 62rpx;
|
||||
padding: 0 20rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(8, 21, 24, 0.05);
|
||||
color: #173036;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.mini-btn.primary {
|
||||
background: rgba(240, 126, 87, 0.14);
|
||||
color: #cf5e3c;
|
||||
}
|
||||
|
||||
.mini-btn.danger {
|
||||
background: rgba(190, 79, 59, 0.12);
|
||||
color: #b94432;
|
||||
}
|
||||
|
||||
.search-row,
|
||||
.filter-row {
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.chip-row,
|
||||
.checkbox-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.chip-btn,
|
||||
.checkbox-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 60rpx;
|
||||
padding: 0 20rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(8, 21, 24, 0.05);
|
||||
color: #4d625f;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.chip-btn.active,
|
||||
.checkbox-chip.active {
|
||||
background: rgba(240, 126, 87, 0.16);
|
||||
color: #c85b39;
|
||||
}
|
||||
|
||||
.checkbox-chip.disabled {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
margin-top: 24rpx;
|
||||
padding: 72rpx 36rpx;
|
||||
border-radius: 30rpx;
|
||||
background: rgba(255, 252, 247, 0.8);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.empty-title {
|
||||
display: block;
|
||||
font-size: 34rpx;
|
||||
font-weight: 800;
|
||||
color: #132024;
|
||||
}
|
||||
|
||||
.empty-desc {
|
||||
display: block;
|
||||
margin-top: 14rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.8;
|
||||
color: #758582;
|
||||
}
|
||||
|
||||
.fab {
|
||||
position: fixed;
|
||||
right: 28rpx;
|
||||
bottom: calc(env(safe-area-inset-bottom) + 128rpx);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 112rpx;
|
||||
height: 112rpx;
|
||||
border-radius: 999rpx;
|
||||
background: linear-gradient(135deg, #f8a37c 0%, #f07e57 100%);
|
||||
color: #fffaf4;
|
||||
box-shadow: 0 22rpx 50rpx rgba(240, 126, 87, 0.3);
|
||||
font-size: 38rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.hint-card {
|
||||
margin-top: 18rpx;
|
||||
padding: 20rpx 22rpx;
|
||||
border-radius: 24rpx;
|
||||
background: rgba(240, 126, 87, 0.12);
|
||||
color: #8f4d33;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.divider-line {
|
||||
width: 100%;
|
||||
height: 2rpx;
|
||||
margin: 18rpx 0;
|
||||
background: rgba(19, 32, 36, 0.08);
|
||||
}
|
||||
|
||||
.image-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 14rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.image-chip {
|
||||
padding: 18rpx 14rpx;
|
||||
border-radius: 24rpx;
|
||||
background: rgba(8, 21, 24, 0.04);
|
||||
font-size: 22rpx;
|
||||
color: #50625f;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
After Width: | Height: | Size: 688 B |
|
After Width: | Height: | Size: 585 B |
|
After Width: | Height: | Size: 979 B |
|
After Width: | Height: | Size: 950 B |
|
After Width: | Height: | Size: 890 B |
|
After Width: | Height: | Size: 871 B |
|
After Width: | Height: | Size: 780 B |
|
After Width: | Height: | Size: 793 B |
@@ -0,0 +1,110 @@
|
||||
Component({
|
||||
options: {
|
||||
multipleSlots: true // 在组件定义时的选项中启用多slot支持
|
||||
},
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
properties: {
|
||||
extClass: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
background: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
back: {
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
loading: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
homeButton: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
animated: {
|
||||
// 显示隐藏的时候opacity动画效果
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
show: {
|
||||
// 显示隐藏导航,隐藏的时候navigation-bar的高度占位还在
|
||||
type: Boolean,
|
||||
value: true,
|
||||
observer: '_showChange'
|
||||
},
|
||||
// back为true的时候,返回的页面深度
|
||||
delta: {
|
||||
type: Number,
|
||||
value: 1
|
||||
},
|
||||
},
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
displayStyle: ''
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
const rect = wx.getMenuButtonBoundingClientRect()
|
||||
const platform = (wx.getDeviceInfo() || wx.getSystemInfoSync()).platform
|
||||
const isAndroid = platform === 'android'
|
||||
const isDevtools = platform === 'devtools'
|
||||
const { windowWidth, safeArea: { top = 0, bottom = 0 } = {} } = wx.getWindowInfo() || wx.getSystemInfoSync()
|
||||
this.setData({
|
||||
ios: !isAndroid,
|
||||
innerPaddingRight: `padding-right: ${windowWidth - rect.left}px`,
|
||||
leftWidth: `width: ${windowWidth - rect.left}px`,
|
||||
safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${top}px); padding-top: ${top}px` : ``
|
||||
})
|
||||
},
|
||||
},
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
_showChange(show) {
|
||||
const animated = this.data.animated
|
||||
let displayStyle = ''
|
||||
if (animated) {
|
||||
displayStyle = `opacity: ${show ? '1' : '0'
|
||||
};transition:opacity 0.5s;`
|
||||
} else {
|
||||
displayStyle = `display: ${show ? '' : 'none'}`
|
||||
}
|
||||
this.setData({
|
||||
displayStyle
|
||||
})
|
||||
},
|
||||
back() {
|
||||
const data = this.data
|
||||
const pages = getCurrentPages()
|
||||
if (data.delta && pages.length > data.delta) {
|
||||
wx.navigateBack({
|
||||
delta: data.delta
|
||||
})
|
||||
return
|
||||
}
|
||||
this.triggerEvent('back', { delta: data.delta }, {})
|
||||
},
|
||||
home() {
|
||||
wx.switchTab({
|
||||
url: '/pages/workbench/index'
|
||||
})
|
||||
this.triggerEvent('home', {}, {})
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"component": true,
|
||||
"styleIsolation": "apply-shared",
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<view class="weui-navigation-bar {{extClass}}">
|
||||
<view class="weui-navigation-bar__inner {{ios ? 'ios' : 'android'}}" style="color: {{color}}; background: {{background}}; {{displayStyle}}; {{innerPaddingRight}}; {{safeAreaTop}};">
|
||||
|
||||
<!-- 左侧按钮 -->
|
||||
<view class='weui-navigation-bar__left' style="{{leftWidth}};">
|
||||
<block wx:if="{{back || homeButton}}">
|
||||
<!-- 返回上一页 -->
|
||||
<block wx:if="{{back}}">
|
||||
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_goback">
|
||||
<view
|
||||
bindtap="back"
|
||||
class="weui-navigation-bar__btn_goback_wrapper"
|
||||
hover-class="weui-active"
|
||||
hover-stay-time="100"
|
||||
aria-role="button"
|
||||
aria-label="返回"
|
||||
>
|
||||
<view class="weui-navigation-bar__button weui-navigation-bar__btn_goback"></view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
<!-- 返回首页 -->
|
||||
<block wx:if="{{homeButton}}">
|
||||
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_home">
|
||||
<view
|
||||
bindtap="home"
|
||||
class="weui-navigation-bar__btn_home_wrapper"
|
||||
hover-class="weui-active"
|
||||
aria-role="button"
|
||||
aria-label="首页"
|
||||
>
|
||||
<view class="weui-navigation-bar__button weui-navigation-bar__btn_home"></view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<slot name="left"></slot>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<!-- 标题 -->
|
||||
<view class='weui-navigation-bar__center'>
|
||||
<view wx:if="{{loading}}" class="weui-navigation-bar__loading" aria-role="alert">
|
||||
<view
|
||||
class="weui-loading"
|
||||
aria-role="img"
|
||||
aria-label="加载中"
|
||||
></view>
|
||||
</view>
|
||||
<block wx:if="{{title}}">
|
||||
<text>{{title}}</text>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<slot name="center"></slot>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<!-- 右侧留空 -->
|
||||
<view class='weui-navigation-bar__right'>
|
||||
<slot name="right"></slot>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,99 @@
|
||||
.weui-navigation-bar {
|
||||
--weui-FG-0:rgba(0,0,0,.9);
|
||||
--height: 44px;
|
||||
--left: 16px;
|
||||
}
|
||||
.weui-navigation-bar .android {
|
||||
--height: 48px;
|
||||
}
|
||||
|
||||
.weui-navigation-bar {
|
||||
overflow: hidden;
|
||||
color: var(--weui-FG-0);
|
||||
flex: none;
|
||||
position: relative;
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__inner {
|
||||
position: relative;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
height: calc(var(--height) + env(safe-area-inset-top));
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding-top: env(safe-area-inset-top);
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__left {
|
||||
position: relative;
|
||||
padding-left: var(--left);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__btn_goback_wrapper {
|
||||
padding: 11px 18px 11px 16px;
|
||||
margin: -11px -18px -11px -16px;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__btn_goback_wrapper.weui-active {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__btn_goback {
|
||||
font-size: 12px;
|
||||
width: 12px;
|
||||
height: 24px;
|
||||
-webkit-mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
|
||||
mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
|
||||
-webkit-mask-size: cover;
|
||||
mask-size: cover;
|
||||
background-color: currentColor;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__center {
|
||||
font-size: 17px;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.weui-navigation-bar__loading {
|
||||
margin-right: 4px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.weui-loading {
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
display: block;
|
||||
background: transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") no-repeat;
|
||||
background-size: 100%;
|
||||
margin-left: 0;
|
||||
animation: loading linear infinite 1s;
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
from {
|
||||
transform: rotate(0);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
const artistApi = require('../../api/nail-artist')
|
||||
const userApi = require('../../api/user')
|
||||
const tagApi = require('../../api/tag')
|
||||
const productApi = require('../../api/product')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
function buildCheckableList(list, selectedIds, labelKey) {
|
||||
return (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
valueId: normalizeId(item.id),
|
||||
labelText: item[labelKey],
|
||||
checked: selectedIds.includes(normalizeId(item.id))
|
||||
}))
|
||||
}
|
||||
|
||||
function syncSelectedIds(selectedIds, list) {
|
||||
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
|
||||
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
|
||||
}
|
||||
|
||||
function filterProductsByShop(products, shopId) {
|
||||
const targetShopId = normalizeId(shopId)
|
||||
if (!targetShopId) {
|
||||
return []
|
||||
}
|
||||
|
||||
return (Array.isArray(products) ? products : []).filter(item => normalizeId(item.shopId) === targetShopId)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
userId: '',
|
||||
shops: [],
|
||||
shopIndex: 0,
|
||||
shopLabel: '',
|
||||
statusOptions: ['营业中', '休息中'],
|
||||
statusIndex: 0,
|
||||
userForm: {
|
||||
nickname: '',
|
||||
account: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
signature: ''
|
||||
},
|
||||
artistForm: {
|
||||
identity: '',
|
||||
experience: '',
|
||||
rating: '',
|
||||
portfolioText: ''
|
||||
},
|
||||
tags: [],
|
||||
products: []
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentArtist = getTempRecord('currentArtist', null)
|
||||
this.setData({
|
||||
mode,
|
||||
userId: options && options.userId ? options.userId : ''
|
||||
})
|
||||
|
||||
this._selectedTagIds = []
|
||||
this._selectedProductIds = []
|
||||
this._allProducts = []
|
||||
|
||||
if (mode === 'edit' && currentArtist) {
|
||||
this._selectedTagIds = format.splitCsv(currentArtist.skills)
|
||||
this._selectedProductIds = format.splitCsv(currentArtist.portfolio)
|
||||
this._initialShopId = currentArtist.shopId
|
||||
this.setData({
|
||||
artistForm: {
|
||||
identity: currentArtist.identity || '',
|
||||
experience: currentArtist.experience || '',
|
||||
rating: currentArtist.rating || '',
|
||||
portfolioText: ''
|
||||
},
|
||||
userForm: {
|
||||
nickname: currentArtist.nickname || '',
|
||||
account: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
signature: currentArtist.signature || ''
|
||||
},
|
||||
statusIndex: Number(currentArtist.status) === 0 ? 1 : 0
|
||||
})
|
||||
}
|
||||
|
||||
this.loadDependencies()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentArtist')
|
||||
},
|
||||
|
||||
async loadDependencies() {
|
||||
const app = getApp()
|
||||
const currentShop = app.globalData.currentShop
|
||||
const operator = app.globalData.userInfo || {}
|
||||
|
||||
try {
|
||||
const [shops, products, users] = await Promise.all([
|
||||
shopApi.listAllShops(),
|
||||
productApi.listAllProducts(),
|
||||
userApi.listAllUsers()
|
||||
])
|
||||
|
||||
let availableShops = Array.isArray(shops) ? shops : []
|
||||
if (Number(operator.type) !== 4 && currentShop) {
|
||||
availableShops = availableShops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
|
||||
}
|
||||
|
||||
let shopIndex = 0
|
||||
if (this._initialShopId) {
|
||||
const index = availableShops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
|
||||
if (index >= 0) {
|
||||
shopIndex = index
|
||||
}
|
||||
}
|
||||
const selectedShop = availableShops[shopIndex]
|
||||
this._allProducts = Array.isArray(products) ? products : []
|
||||
|
||||
if (this.data.mode === 'edit') {
|
||||
const userRecord = (Array.isArray(users) ? users : []).find(item => normalizeId(item.id) === normalizeId(this.data.userId))
|
||||
if (userRecord) {
|
||||
this.setData({
|
||||
userForm: {
|
||||
nickname: userRecord.nickname || '',
|
||||
account: userRecord.account || '',
|
||||
phone: userRecord.phone || '',
|
||||
password: '',
|
||||
signature: userRecord.signature || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.setData({
|
||||
shops: availableShops,
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
|
||||
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化美甲师表单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async loadShopScopedOptions(shopId) {
|
||||
if (!normalizeId(shopId)) {
|
||||
this._selectedTagIds = []
|
||||
this._selectedProductIds = []
|
||||
this.setData({
|
||||
tags: [],
|
||||
products: []
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const tagList = await tagApi.listTagsByShopId(shopId)
|
||||
const productList = filterProductsByShop(this._allProducts, shopId)
|
||||
this._selectedTagIds = syncSelectedIds(this._selectedTagIds, tagList)
|
||||
this._selectedProductIds = syncSelectedIds(this._selectedProductIds, productList)
|
||||
this.setData({
|
||||
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
|
||||
products: buildCheckableList(productList, this._selectedProductIds, 'title')
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
tags: [],
|
||||
products: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '店铺关联数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleUserInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
let value = event.detail.value
|
||||
|
||||
if (field === 'account') {
|
||||
value = String(value || '').replace(/[^A-Za-z0-9]/g, '')
|
||||
}
|
||||
if (field === 'phone') {
|
||||
value = String(value || '').replace(/[^\d]/g, '').slice(0, 11)
|
||||
}
|
||||
|
||||
this.setData({
|
||||
[`userForm.${field}`]: value
|
||||
})
|
||||
},
|
||||
|
||||
handleArtistInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`artistForm.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
},
|
||||
|
||||
handleStatusChange(event) {
|
||||
this.setData({
|
||||
statusIndex: Number(event.detail.value)
|
||||
})
|
||||
},
|
||||
|
||||
handleTagChange(event) {
|
||||
this._selectedTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
tags: this.data.tags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
handleProductChange(event) {
|
||||
this._selectedProductIds = event.detail.value || []
|
||||
this.setData({
|
||||
products: this.data.products.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedProductIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
validateForm() {
|
||||
if (!this.data.userForm.nickname) {
|
||||
return '请输入美甲师昵称'
|
||||
}
|
||||
if (!this.data.userForm.account) {
|
||||
return '请输入账号'
|
||||
}
|
||||
if (!this.data.userForm.phone || this.data.userForm.phone.length !== 11) {
|
||||
return '请输入 11 位手机号'
|
||||
}
|
||||
if (this.data.mode === 'create' && !this.data.userForm.password) {
|
||||
return '新增美甲师时必须设置密码'
|
||||
}
|
||||
if (!this.data.shops[this.data.shopIndex]) {
|
||||
return '请选择所属店铺'
|
||||
}
|
||||
return ''
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const errorMessage = this.validateForm()
|
||||
if (errorMessage) {
|
||||
wx.showToast({
|
||||
title: errorMessage,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const selectedShop = this.data.shops[this.data.shopIndex]
|
||||
const userPayload = {
|
||||
nickname: this.data.userForm.nickname,
|
||||
account: this.data.userForm.account,
|
||||
phone: this.data.userForm.phone,
|
||||
signature: this.data.userForm.signature || undefined,
|
||||
type: 3,
|
||||
shopIds: selectedShop ? [Number(selectedShop.id)] : []
|
||||
}
|
||||
|
||||
if (this.data.userForm.password) {
|
||||
userPayload.password = this.data.userForm.password
|
||||
}
|
||||
|
||||
try {
|
||||
let targetUserId = this.data.userId
|
||||
if (this.data.mode === 'edit') {
|
||||
await userApi.updateUser(targetUserId, userPayload)
|
||||
} else {
|
||||
targetUserId = await userApi.createUser(userPayload)
|
||||
}
|
||||
|
||||
await artistApi.saveNailArtistInfo({
|
||||
userId: Number(targetUserId),
|
||||
identity: this.data.artistForm.identity || undefined,
|
||||
experience: this.data.artistForm.experience ? Number(this.data.artistForm.experience) : 0,
|
||||
skills: this._selectedTagIds.join(',') || undefined,
|
||||
rating: this.data.artistForm.rating ? Number(this.data.artistForm.rating) : 0,
|
||||
status: this.data.statusIndex === 1 ? 0 : 1,
|
||||
portfolio: this._selectedProductIds.join(',') || undefined,
|
||||
nickname: this.data.userForm.nickname,
|
||||
shopId: selectedShop ? Number(selectedShop.id) : undefined,
|
||||
signature: this.data.userForm.signature || undefined
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '美甲师已更新' : '美甲师已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/artists/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<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="{{userForm.nickname}}" data-field="nickname" bindinput="handleUserInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">账号</text>
|
||||
<input class="field-input" value="{{userForm.account}}" data-field="account" bindinput="handleUserInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">手机号</text>
|
||||
<input class="field-input" type="number" value="{{userForm.phone}}" data-field="phone" bindinput="handleUserInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">{{mode === 'edit' ? '密码(留空则不修改)' : '登录密码'}}</text>
|
||||
<input class="field-input" password value="{{userForm.password}}" data-field="password" bindinput="handleUserInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">签名</text>
|
||||
<textarea class="field-textarea" value="{{userForm.signature}}" data-field="signature" bindinput="handleUserInput"></textarea>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">所属店铺</text>
|
||||
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
|
||||
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">职业信息</text>
|
||||
<view class="field-group">
|
||||
<text class="field-label">身份标签</text>
|
||||
<input class="field-input" value="{{artistForm.identity}}" data-field="identity" bindinput="handleArtistInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">从业年限</text>
|
||||
<input class="field-input" type="number" value="{{artistForm.experience}}" data-field="experience" bindinput="handleArtistInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">评分</text>
|
||||
<input class="field-input" type="digit" value="{{artistForm.rating}}" data-field="rating" bindinput="handleArtistInput"></input>
|
||||
</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">擅长标签</text>
|
||||
<checkbox-group bindchange="handleTagChange">
|
||||
<block wx:for="{{tags}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">作品集</text>
|
||||
<checkbox-group bindchange="handleProductChange">
|
||||
<block wx:for="{{products}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">保存美甲师</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
const artistApi = require('../../api/nail-artist')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
list: [],
|
||||
canCreate: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入美甲师管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('user:create') || permissionCodes.includes('nail_artist:edit')
|
||||
})
|
||||
this.loadArtists()
|
||||
},
|
||||
|
||||
async loadArtists() {
|
||||
try {
|
||||
const list = await artistApi.listNailArtists()
|
||||
this.setData({
|
||||
list: (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
displayStatusText: Number(item.status) === 0 ? '休息中' : '营业中'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '美甲师列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentArtist')
|
||||
navigation.navigate('/pages/artist-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const artist = event.currentTarget.dataset.artist
|
||||
setTempRecord('currentArtist', artist)
|
||||
navigation.navigate('/pages/artist-form/index', {
|
||||
mode: 'edit',
|
||||
userId: artist.userId
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<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>
|
||||
<text class="section-desc">店长只能看到并管理自己门店的美甲师;平台管理员可跨店查看,移动端表单集中处理账号和档案两部分信息。</text>
|
||||
</view>
|
||||
|
||||
<block wx:for="{{list}}" wx:key="id">
|
||||
<view class="list-card">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.nickname}}</text>
|
||||
<text class="list-subtitle">{{item.identity || '未设置身份'}} · {{item.shopName || '当前店铺'}}</text>
|
||||
</view>
|
||||
<text class="{{item.status === 0 ? 'soft-badge' : 'badge'}}">{{item.displayStatusText}}</text>
|
||||
</view>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">从业年限</text>
|
||||
<text class="meta-value">{{item.experience || 0}} 年</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">评分</text>
|
||||
<text class="meta-value">{{item.rating || 0}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn primary" data-artist="{{item}}" bindtap="handleEdit">编辑</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:if="{{!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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
const couponApi = require('../../api/coupon')
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
coupon: null,
|
||||
users: [],
|
||||
quantity: 1
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const coupon = getTempRecord('currentCoupon', null)
|
||||
this.setData({
|
||||
coupon
|
||||
})
|
||||
this.loadUsers()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentCoupon')
|
||||
},
|
||||
|
||||
async loadUsers() {
|
||||
try {
|
||||
const users = await userApi.listAllUsers()
|
||||
this.setData({
|
||||
users: (Array.isArray(users) ? users : []).map(item => ({
|
||||
...item,
|
||||
valueId: String(item.id),
|
||||
checked: false
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '可发放用户加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleUserCheck(event) {
|
||||
const selected = event.detail.value || []
|
||||
this.setData({
|
||||
users: this.data.users.map(item => ({
|
||||
...item,
|
||||
checked: selected.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
handleQuantityInput(event) {
|
||||
this.setData({
|
||||
quantity: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const selectedUserIds = this.data.users.filter(item => item.checked).map(item => Number(item.id))
|
||||
if (!selectedUserIds.length) {
|
||||
wx.showToast({
|
||||
title: '请至少选择一个用户',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await couponApi.distributeCoupon({
|
||||
couponId: this.data.coupon.id,
|
||||
userIds: selectedUserIds,
|
||||
quantity: Number(this.data.quantity || 1)
|
||||
})
|
||||
wx.showToast({
|
||||
title: '优惠券已发放',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/coupons/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '发放失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<navigation-bar title="发放优惠券" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view class="surface-card" wx:if="{{coupon}}">
|
||||
<text class="section-title">{{coupon.couponName}}</text>
|
||||
<text class="section-desc">选择用户后批量发放,数量默认 1。移动端只保留高频发放能力,不把 Web 的宽表格搬过来。</text>
|
||||
<view class="field-group">
|
||||
<text class="field-label">发放数量</text>
|
||||
<input class="field-input" type="number" value="{{quantity}}" bindinput="handleQuantityInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">选择用户</text>
|
||||
<checkbox-group bindchange="handleUserCheck">
|
||||
<block wx:for="{{users}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.nickname || item.account}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">确认发放</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
const couponApi = require('../../api/coupon')
|
||||
const tagApi = require('../../api/tag')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
function buildCheckableList(list, selectedIds, labelKey) {
|
||||
return (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
valueId: normalizeId(item.id),
|
||||
labelText: item[labelKey],
|
||||
checked: selectedIds.includes(normalizeId(item.id))
|
||||
}))
|
||||
}
|
||||
|
||||
function syncSelectedIds(selectedIds, list) {
|
||||
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
|
||||
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
couponId: '',
|
||||
shops: [],
|
||||
shopIndex: 0,
|
||||
shopLabel: '',
|
||||
couponTypeOptions: ['折扣券', '满减券'],
|
||||
couponTypeIndex: 0,
|
||||
couponTypeLabel: '折扣券',
|
||||
vipLevelOptions: ['普通', '青铜', '白银', '黄金'],
|
||||
vipLevelIndex: 0,
|
||||
vipLevelLabel: '普通',
|
||||
startDate: '',
|
||||
startTime: '',
|
||||
endDate: '',
|
||||
endTime: '',
|
||||
availableTags: [],
|
||||
unavailableTags: [],
|
||||
form: {
|
||||
couponName: '',
|
||||
couponCode: '',
|
||||
discountValue: '',
|
||||
minAmount: '',
|
||||
reduceAmount: '',
|
||||
totalCount: '',
|
||||
couponScene: '',
|
||||
autoMatch: false
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentCoupon = getTempRecord('currentCoupon', null)
|
||||
this.setData({
|
||||
mode,
|
||||
couponId: options && options.id ? options.id : ''
|
||||
})
|
||||
|
||||
this._selectedAvailableTagIds = []
|
||||
this._selectedUnavailableTagIds = []
|
||||
|
||||
if (mode === 'edit' && currentCoupon) {
|
||||
const start = format.parseDateTimeToPicker(currentCoupon.startTime)
|
||||
const end = format.parseDateTimeToPicker(currentCoupon.endTime)
|
||||
this._selectedAvailableTagIds = Array.isArray(currentCoupon.availableTags) ? currentCoupon.availableTags.map(item => String(item.id)) : []
|
||||
this._selectedUnavailableTagIds = Array.isArray(currentCoupon.unavailableTags) ? currentCoupon.unavailableTags.map(item => String(item.id)) : []
|
||||
this._initialShopId = currentCoupon.shopId
|
||||
this.setData({
|
||||
form: {
|
||||
couponName: currentCoupon.couponName || '',
|
||||
couponCode: currentCoupon.couponCode || '',
|
||||
discountValue: currentCoupon.discountValue || '',
|
||||
minAmount: currentCoupon.minAmount || '',
|
||||
reduceAmount: currentCoupon.reduceAmount || '',
|
||||
totalCount: currentCoupon.totalCount || '',
|
||||
couponScene: currentCoupon.couponScene || '',
|
||||
autoMatch: Number(currentCoupon.autoMatch) === 1
|
||||
},
|
||||
couponTypeIndex: Number(currentCoupon.couponType) === 2 ? 1 : 0,
|
||||
couponTypeLabel: Number(currentCoupon.couponType) === 2 ? '满减券' : '折扣券',
|
||||
vipLevelIndex: this.data.vipLevelOptions.findIndex(item => item === (currentCoupon.requiredVipLevel || '普通')),
|
||||
vipLevelLabel: currentCoupon.requiredVipLevel || '普通',
|
||||
startDate: start.date,
|
||||
startTime: start.time,
|
||||
endDate: end.date,
|
||||
endTime: end.time
|
||||
})
|
||||
}
|
||||
|
||||
this.loadDependencies()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentCoupon')
|
||||
},
|
||||
|
||||
async loadDependencies() {
|
||||
const app = getApp()
|
||||
const currentShop = app.globalData.currentShop
|
||||
const operator = app.globalData.userInfo || {}
|
||||
|
||||
try {
|
||||
const shopList = await shopApi.listAllShops()
|
||||
|
||||
let shops = Array.isArray(shopList) ? shopList : []
|
||||
if (Number(operator.type) !== 4 && currentShop) {
|
||||
shops = shops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
|
||||
}
|
||||
|
||||
let shopIndex = 0
|
||||
if (this._initialShopId) {
|
||||
const index = shops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
|
||||
if (index >= 0) {
|
||||
shopIndex = index
|
||||
}
|
||||
}
|
||||
const selectedShop = shops[shopIndex]
|
||||
|
||||
this.setData({
|
||||
shops,
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
|
||||
await this.loadTagOptions(selectedShop ? selectedShop.id : '')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化优惠券表单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async loadTagOptions(shopId) {
|
||||
if (!normalizeId(shopId)) {
|
||||
this._selectedAvailableTagIds = []
|
||||
this._selectedUnavailableTagIds = []
|
||||
this.setData({
|
||||
availableTags: [],
|
||||
unavailableTags: []
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const tagList = await tagApi.listTagsByShopId(shopId)
|
||||
this._selectedAvailableTagIds = syncSelectedIds(this._selectedAvailableTagIds, tagList)
|
||||
this._selectedUnavailableTagIds = syncSelectedIds(this._selectedUnavailableTagIds, tagList)
|
||||
this.setData({
|
||||
availableTags: buildCheckableList(tagList, this._selectedAvailableTagIds, 'tagName'),
|
||||
unavailableTags: buildCheckableList(tagList, this._selectedUnavailableTagIds, 'tagName')
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
availableTags: [],
|
||||
unavailableTags: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '可用标签加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const value = event.detail.value
|
||||
this.setData({
|
||||
[`form.${field}`]: value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
this.loadTagOptions(selectedShop ? selectedShop.id : '')
|
||||
},
|
||||
|
||||
handleCouponTypeChange(event) {
|
||||
const couponTypeIndex = Number(event.detail.value)
|
||||
this.setData({
|
||||
couponTypeIndex,
|
||||
couponTypeLabel: this.data.couponTypeOptions[couponTypeIndex]
|
||||
})
|
||||
},
|
||||
|
||||
handleVipLevelChange(event) {
|
||||
const vipLevelIndex = Number(event.detail.value)
|
||||
this.setData({
|
||||
vipLevelIndex,
|
||||
vipLevelLabel: this.data.vipLevelOptions[vipLevelIndex]
|
||||
})
|
||||
},
|
||||
|
||||
handleDateTimeChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[field]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleAutoMatchChange(event) {
|
||||
this.setData({
|
||||
'form.autoMatch': event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleAvailableTagChange(event) {
|
||||
this._selectedAvailableTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
availableTags: this.data.availableTags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedAvailableTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
handleUnavailableTagChange(event) {
|
||||
this._selectedUnavailableTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
unavailableTags: this.data.unavailableTags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedUnavailableTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const selectedShop = this.data.shops[this.data.shopIndex]
|
||||
if (!this.data.form.couponName) {
|
||||
wx.showToast({
|
||||
title: '请输入优惠券名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!selectedShop) {
|
||||
wx.showToast({
|
||||
title: '请选择所属店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
couponCode: this.data.form.couponCode || undefined,
|
||||
couponName: this.data.form.couponName,
|
||||
couponType: this.data.couponTypeIndex === 1 ? 2 : 1,
|
||||
discountValue: this.data.couponTypeIndex === 0 ? Number(this.data.form.discountValue || 0) : undefined,
|
||||
minAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.minAmount || 0) : undefined,
|
||||
reduceAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.reduceAmount || 0) : undefined,
|
||||
totalCount: this.data.form.totalCount ? Number(this.data.form.totalCount) : undefined,
|
||||
startTime: format.buildDateTime(this.data.startDate, this.data.startTime),
|
||||
endTime: format.buildDateTime(this.data.endDate, this.data.endTime),
|
||||
shopId: selectedShop.id,
|
||||
couponScene: this.data.form.couponScene || undefined,
|
||||
requiredVipLevel: this.data.vipLevelLabel || undefined,
|
||||
autoMatch: this.data.form.autoMatch ? 1 : 0,
|
||||
availableTagIds: this._selectedAvailableTagIds.map(item => Number(item)),
|
||||
unavailableTagIds: this._selectedUnavailableTagIds.map(item => Number(item))
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.data.mode === 'edit') {
|
||||
await couponApi.updateCoupon(this.data.couponId, payload)
|
||||
} else {
|
||||
await couponApi.createCoupon(payload)
|
||||
}
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '优惠券已更新' : '优惠券已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/coupons/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<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.couponName}}" data-field="couponName" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">所属店铺</text>
|
||||
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
|
||||
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">券类型</text>
|
||||
<picker mode="selector" range="{{couponTypeOptions}}" value="{{couponTypeIndex}}" bindchange="handleCouponTypeChange">
|
||||
<view class="field-picker">{{couponTypeLabel}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">优惠编码</text>
|
||||
<input class="field-input" value="{{form.couponCode}}" data-field="couponCode" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view wx:if="{{couponTypeIndex === 0}}" class="field-group">
|
||||
<text class="field-label">折扣值</text>
|
||||
<input class="field-input" type="digit" value="{{form.discountValue}}" data-field="discountValue" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<block wx:if="{{couponTypeIndex === 1}}">
|
||||
<view class="field-group">
|
||||
<text class="field-label">满多少可用</text>
|
||||
<input class="field-input" type="digit" value="{{form.minAmount}}" data-field="minAmount" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">减免金额</text>
|
||||
<input class="field-input" type="digit" value="{{form.reduceAmount}}" data-field="reduceAmount" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
</block>
|
||||
<view class="field-group">
|
||||
<text class="field-label">总数量</text>
|
||||
<input class="field-input" type="number" value="{{form.totalCount}}" data-field="totalCount" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">优惠场景</text>
|
||||
<input class="field-input" value="{{form.couponScene}}" data-field="couponScene" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">VIP 等级限制</text>
|
||||
<picker mode="selector" range="{{vipLevelOptions}}" value="{{vipLevelIndex}}" bindchange="handleVipLevelChange">
|
||||
<view class="field-picker">{{vipLevelLabel}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">开始日期 / 时间</text>
|
||||
<view class="action-row">
|
||||
<picker mode="date" value="{{startDate}}" data-field="startDate" bindchange="handleDateTimeChange">
|
||||
<view class="field-picker">{{startDate || '开始日期'}}</view>
|
||||
</picker>
|
||||
<picker mode="time" value="{{startTime}}" data-field="startTime" bindchange="handleDateTimeChange">
|
||||
<view class="field-picker">{{startTime || '开始时间'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">结束日期 / 时间</text>
|
||||
<view class="action-row">
|
||||
<picker mode="date" value="{{endDate}}" data-field="endDate" bindchange="handleDateTimeChange">
|
||||
<view class="field-picker">{{endDate || '结束日期'}}</view>
|
||||
</picker>
|
||||
<picker mode="time" value="{{endTime}}" data-field="endTime" bindchange="handleDateTimeChange">
|
||||
<view class="field-picker">{{endTime || '结束时间'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">自动匹配</text>
|
||||
<switch checked="{{form.autoMatch}}" bindchange="handleAutoMatchChange"></switch>
|
||||
</view>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">可用标签</text>
|
||||
<checkbox-group bindchange="handleAvailableTagChange">
|
||||
<block wx:for="{{availableTags}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">不可用标签</text>
|
||||
<checkbox-group bindchange="handleUnavailableTagChange">
|
||||
<block wx:for="{{unavailableTags}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">保存优惠券</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
const couponApi = require('../../api/coupon')
|
||||
const format = require('../../utils/format')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
list: [],
|
||||
canCreate: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入优惠券管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('coupon:create')
|
||||
})
|
||||
this.loadCoupons()
|
||||
},
|
||||
|
||||
async loadCoupons() {
|
||||
try {
|
||||
const result = await couponApi.listCoupons({
|
||||
page: 1,
|
||||
size: 20
|
||||
})
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayTypeText: format.getCouponTypeText(item.couponType),
|
||||
displayValueText: format.getCouponValueText(item),
|
||||
displayShopName: item.shopName || '当前店铺'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '优惠券加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentCoupon')
|
||||
navigation.navigate('/pages/coupon-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const coupon = event.currentTarget.dataset.coupon
|
||||
setTempRecord('currentCoupon', coupon)
|
||||
navigation.navigate('/pages/coupon-form/index', {
|
||||
mode: 'edit',
|
||||
id: coupon.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDistribute(event) {
|
||||
const coupon = event.currentTarget.dataset.coupon
|
||||
setTempRecord('currentCoupon', coupon)
|
||||
navigation.navigate('/pages/coupon-distribute/index', {
|
||||
id: coupon.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const coupon = event.currentTarget.dataset.coupon
|
||||
wx.showModal({
|
||||
title: '删除优惠券',
|
||||
content: `确认删除优惠券“${coupon.couponName}”吗?`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await couponApi.deleteCoupon(coupon.id)
|
||||
wx.showToast({
|
||||
title: '优惠券已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadCoupons()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '优惠券删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<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>
|
||||
<text class="section-desc">普通券、VIP 自动券都在这里维护;发放动作单独收口到移动端发放页,避免一屏塞太多字段。</text>
|
||||
</view>
|
||||
|
||||
<block wx:for="{{list}}" wx:key="id">
|
||||
<view class="list-card">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.couponName}}</text>
|
||||
<text class="list-subtitle">{{item.displayShopName}} · {{item.displayTypeText}}</text>
|
||||
</view>
|
||||
<text class="badge">{{item.displayValueText}}</text>
|
||||
</view>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">可用时间</text>
|
||||
<text class="meta-value">{{item.startTime}} ~ {{item.endTime}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">剩余数量</text>
|
||||
<text class="meta-value">{{item.remainingCount || item.totalCount || '--'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn" data-coupon="{{item}}" bindtap="handleDistribute">发放</view>
|
||||
<view class="mini-btn primary" data-coupon="{{item}}" bindtap="handleEdit">编辑</view>
|
||||
<view class="mini-btn danger" data-coupon="{{item}}" bindtap="handleDelete">删除</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:if="{{!list.length}}" class="empty-state">
|
||||
<text class="empty-title">暂无优惠券</text>
|
||||
<text class="empty-desc">可以先创建普通券,也可以为每家店铺维护自己的 VIP 自动券模板。</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
const ACCOUNT_REGEX = /[^A-Za-z0-9]/g
|
||||
|
||||
Page({
|
||||
data: {
|
||||
redirect: '',
|
||||
form: {
|
||||
account: '',
|
||||
password: '',
|
||||
shopId: ''
|
||||
},
|
||||
loginShops: [],
|
||||
loginShopIndex: -1,
|
||||
loginShopDisplayName: '',
|
||||
allowShoplessLogin: false,
|
||||
loginShopMessage: '',
|
||||
accountStatusText: '',
|
||||
accountStatusType: '',
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this._lookupTicket = 0
|
||||
this.setData({
|
||||
redirect: options && options.redirect ? options.redirect : ''
|
||||
})
|
||||
|
||||
if (auth.isLoggedIn()) {
|
||||
navigation.redirectAfterLogin(this.data.redirect).catch(() => undefined)
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (this._accountTimer) {
|
||||
clearTimeout(this._accountTimer)
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
let value = event.detail.value
|
||||
|
||||
if (field === 'account') {
|
||||
value = String(value || '').replace(ACCOUNT_REGEX, '')
|
||||
this.resetAccountState()
|
||||
if (value) {
|
||||
this.scheduleAccountLookup(value)
|
||||
}
|
||||
}
|
||||
|
||||
this.setData({
|
||||
[`form.${field}`]: value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.loginShops[index]
|
||||
|
||||
this.setData({
|
||||
loginShopIndex: index,
|
||||
loginShopDisplayName: shop ? shop.shopName || '' : '',
|
||||
'form.shopId': shop ? shop.id : ''
|
||||
})
|
||||
},
|
||||
|
||||
resetAccountState() {
|
||||
if (this._accountTimer) {
|
||||
clearTimeout(this._accountTimer)
|
||||
}
|
||||
|
||||
this._lookupTicket += 1
|
||||
|
||||
this.setData({
|
||||
accountStatusText: '',
|
||||
accountStatusType: '',
|
||||
loginShops: [],
|
||||
loginShopIndex: -1,
|
||||
loginShopDisplayName: '',
|
||||
allowShoplessLogin: false,
|
||||
loginShopMessage: '',
|
||||
'form.shopId': ''
|
||||
})
|
||||
},
|
||||
|
||||
scheduleAccountLookup(account) {
|
||||
if (this._accountTimer) {
|
||||
clearTimeout(this._accountTimer)
|
||||
}
|
||||
|
||||
const ticket = this._lookupTicket + 1
|
||||
this._lookupTicket = ticket
|
||||
this._accountTimer = setTimeout(() => {
|
||||
this.loadLoginShops(account, ticket)
|
||||
}, 420)
|
||||
},
|
||||
|
||||
applyLoginShopSelection(selection) {
|
||||
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
|
||||
const allowShoplessLogin = Boolean(selection && selection.allowShoplessLogin)
|
||||
let loginShopIndex = -1
|
||||
let loginShopDisplayName = ''
|
||||
let shopId = ''
|
||||
|
||||
if (!allowShoplessLogin && shops.length === 1) {
|
||||
loginShopIndex = 0
|
||||
loginShopDisplayName = shops[0].shopName || ''
|
||||
shopId = shops[0].id
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loginShops: shops,
|
||||
allowShoplessLogin,
|
||||
loginShopMessage: (selection && selection.message) || '',
|
||||
loginShopIndex,
|
||||
loginShopDisplayName,
|
||||
'form.shopId': shopId,
|
||||
accountStatusText: shops.length || allowShoplessLogin ? '该账号可用于后台登录' : '当前账号暂时不可用于后台登录',
|
||||
accountStatusType: shops.length || allowShoplessLogin ? 'success' : 'warning'
|
||||
})
|
||||
},
|
||||
|
||||
async loadLoginShops(account, ticket) {
|
||||
if (!account) {
|
||||
this.resetAccountState()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await authApi.getLoginShops(account)
|
||||
if (ticket !== this._lookupTicket || this.data.form.account !== account) {
|
||||
return
|
||||
}
|
||||
this.applyLoginShopSelection(result)
|
||||
} catch (error) {
|
||||
if (ticket !== this._lookupTicket || this.data.form.account !== account) {
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
loginShops: [],
|
||||
loginShopIndex: -1,
|
||||
loginShopDisplayName: '',
|
||||
allowShoplessLogin: false,
|
||||
loginShopMessage: '',
|
||||
'form.shopId': '',
|
||||
accountStatusText: error.message || '该后台账号不存在或不可登录',
|
||||
accountStatusType: 'error'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
validateForm() {
|
||||
const form = this.data.form
|
||||
if (!form.account) {
|
||||
return '请输入后台账号'
|
||||
}
|
||||
if (!form.password) {
|
||||
return '请输入登录密码'
|
||||
}
|
||||
if (!this.data.allowShoplessLogin && this.data.loginShops.length && !form.shopId) {
|
||||
return '请选择登录店铺'
|
||||
}
|
||||
return ''
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const errorMessage = this.validateForm()
|
||||
if (errorMessage) {
|
||||
wx.showToast({
|
||||
title: errorMessage,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const payload = await runWithLoading(() => authApi.login({
|
||||
account: this.data.form.account,
|
||||
password: this.data.form.password,
|
||||
shopId: this.data.form.shopId || undefined
|
||||
}))
|
||||
|
||||
await getApp().setAdminSession(payload)
|
||||
|
||||
wx.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
await navigation.redirectAfterLogin(this.data.redirect)
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '登录失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<navigation-bar title="后台管理" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack login-stack">
|
||||
<view class="hero-panel">
|
||||
<text class="hero-kicker">YUMINAIL ADMIN</text>
|
||||
<text class="hero-title">把日常经营带到手机上</text>
|
||||
<text class="hero-desc">平台管理员、店长、美甲师共用一套后台能力。首版保持业务能力对齐,交互按移动端重构,不把网页表格硬搬到手机里。</text>
|
||||
<view class="badge-row">
|
||||
<text class="badge">平台管理员</text>
|
||||
<text class="soft-badge">店长</text>
|
||||
<text class="soft-badge">美甲师</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">账号密码登录</text>
|
||||
<text class="section-desc">输入后台账号后,会自动预加载可登录店铺。管理员在系统尚无店铺时,也可无店铺登录并先进入店铺管理。</text>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">后台账号</text>
|
||||
<input class="field-input" placeholder="仅支持字母和数字" placeholder-class="placeholder" value="{{form.account}}" data-field="account" bindinput="handleInputChange"></input>
|
||||
<text wx:if="{{accountStatusText}}" class="status-text {{accountStatusType}}">{{accountStatusText}}</text>
|
||||
</view>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">登录密码</text>
|
||||
<input class="field-input" password placeholder="请输入后台密码" placeholder-class="placeholder" value="{{form.password}}" data-field="password" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{loginShops.length}}" class="field-group">
|
||||
<text class="field-label">登录店铺</text>
|
||||
<picker mode="selector" range="{{loginShops}}" range-key="shopName" value="{{loginShopIndex}}" bindchange="handleShopChange">
|
||||
<view class="field-picker">{{loginShopDisplayName || '请选择本次登录店铺'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{allowShoplessLogin || loginShopMessage}}" class="hint-card">{{loginShopMessage || '当前账号允许无店铺登录,可先进入店铺管理完成初始化。'}}</view>
|
||||
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" loading="{{loading}}" disabled="{{loading}}" bindtap="handleSubmit">进入管理台</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.login-stack {
|
||||
padding-top: 40rpx;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
modules: []
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入经营模块')) {
|
||||
return
|
||||
}
|
||||
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo
|
||||
const currentShop = app.globalData.currentShop
|
||||
const permissionCodes = app.globalData.permissionCodes || []
|
||||
|
||||
this.setData({
|
||||
userInfo,
|
||||
currentShop,
|
||||
modules: permission.getManageModules(userInfo, permissionCodes, currentShop)
|
||||
})
|
||||
},
|
||||
|
||||
handleOpenModule(event) {
|
||||
const module = event.currentTarget.dataset.module
|
||||
if (!module) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!module.allowed) {
|
||||
wx.showToast({
|
||||
title: module.disabledReason || '当前账号没有进入该模块的权限',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
navigation.navigate(module.path).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<navigation-bar title="经营" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view class="hero-panel">
|
||||
<text class="hero-kicker">按权限展示</text>
|
||||
<text class="hero-title">{{currentShop ? currentShop.shopName : '平台级入口'}}</text>
|
||||
<text class="hero-desc">这里不复刻网页后台的大表格首页,而是把可用模块拆成移动端更好点到的入口卡片。</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!currentShop && userInfo && userInfo.type === 4}}" class="hint-card">当前是无店铺管理员登录状态。用户、作品、优惠券、标签、美甲师等强店铺模块会先置灰,避免误操作。</view>
|
||||
|
||||
<block wx:for="{{modules}}" wx:key="key">
|
||||
<view class="list-card" data-module="{{item}}" bindtap="handleOpenModule">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.title}}</text>
|
||||
<text class="list-subtitle">{{item.description}}</text>
|
||||
</view>
|
||||
<text class="{{item.allowed ? 'badge' : 'soft-badge'}}">{{item.allowed ? '可进入' : '待解锁'}}</text>
|
||||
</view>
|
||||
<view wx:if="{{!item.allowed}}" class="hint-card">{{item.disabledReason}}</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
order: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const order = getTempRecord('currentOrder', null)
|
||||
this.setData({
|
||||
order: order ? {
|
||||
...order,
|
||||
displayStatusText: format.getOrderStatusText(order),
|
||||
displayCreateTime: format.formatDateTime(order.createTime)
|
||||
} : null
|
||||
})
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentOrder')
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/orders/index')
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<navigation-bar title="订单详情" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view wx:if="{{order}}" class="surface-card">
|
||||
<text class="section-title">{{order.orderNo}}</text>
|
||||
<text class="section-desc">{{order.displayStatusText}} · {{order.displayCreateTime}}</text>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">用户昵称</text>
|
||||
<text class="meta-value">{{order.customerNickname || order.userNickname || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">脱敏手机号</text>
|
||||
<text class="meta-value">{{order.customerPhoneMasked || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">所属店铺</text>
|
||||
<text class="meta-value">{{order.shopName || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">美甲师</text>
|
||||
<text class="meta-value">{{order.artistName || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">应付金额</text>
|
||||
<text class="meta-value">¥{{order.payAmount || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">备注</text>
|
||||
<text class="meta-value">{{order.remark || '暂无备注'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="empty-state">
|
||||
<text class="empty-title">订单详情暂不可用</text>
|
||||
<text class="empty-desc">当前详情页优先复用列表页已拉取的数据。如果你是直接打开该页面,请先回到订单列表重新进入。</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
const orderApi = require('../../api/order')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
const format = require('../../utils/format')
|
||||
const { setTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty, markDirty } = require('../../utils/page-state')
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: '待服务', value: 1 },
|
||||
{ label: '已完成', value: 2 },
|
||||
{ label: '已取消', value: 0 }
|
||||
]
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
status: '',
|
||||
statusOptions: STATUS_OPTIONS,
|
||||
list: [],
|
||||
total: 0,
|
||||
loading: false,
|
||||
userInfo: null,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入订单管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
userInfo: getApp().globalData.userInfo
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty('admin-orders')) {
|
||||
this.loadOrders()
|
||||
}
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.loadOrders().finally(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleStatusChange(event) {
|
||||
const status = event.currentTarget.dataset.status
|
||||
this.setData({
|
||||
status
|
||||
})
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await orderApi.listOrders({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined,
|
||||
status: this.data.status === '' ? undefined : this.data.status
|
||||
})
|
||||
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayStatusText: format.getOrderStatusText(item),
|
||||
displayCreateTime: format.formatDateTime(item.createTime)
|
||||
})),
|
||||
total: Number(result && result.total) || 0,
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '订单加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
handleOpenOrder(event) {
|
||||
const order = event.currentTarget.dataset.order
|
||||
if (!order) {
|
||||
return
|
||||
}
|
||||
|
||||
setTempRecord('currentOrder', order)
|
||||
navigation.navigate('/pages/order-detail/index', {
|
||||
id: order.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
async handleProcessOrder(event) {
|
||||
const order = event.currentTarget.dataset.order
|
||||
if (!order) {
|
||||
return
|
||||
}
|
||||
|
||||
const isArtist = permission.isNailArtist(this.data.userInfo)
|
||||
const options = isArtist
|
||||
? [{ label: '标记为已完成', status: 2 }]
|
||||
: [
|
||||
{ label: '调整为待服务', status: 1 },
|
||||
{ label: '标记为已完成', status: 2 },
|
||||
{ label: '标记为已取消', status: 0 }
|
||||
]
|
||||
|
||||
wx.showActionSheet({
|
||||
itemList: options.map(item => item.label),
|
||||
success: async result => {
|
||||
const target = options[result.tapIndex]
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await orderApi.updateOrderStatus(order.id, target.status)
|
||||
markDirty('admin-workbench')
|
||||
wx.showToast({
|
||||
title: '订单状态已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadOrders()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '订单处理失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
},
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<navigation-bar title="订单" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view class="hero-panel">
|
||||
<text class="hero-kicker">预约履约</text>
|
||||
<text class="hero-title">按当前角色范围查看订单</text>
|
||||
<text class="hero-desc">店长和平台管理员看当前权限范围订单,美甲师仅看属于自己的预约单,并只能完成属于自己的订单。</text>
|
||||
</view>
|
||||
|
||||
<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="{{statusOptions}}" wx:key="label">
|
||||
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{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.orderNo}}</text>
|
||||
<text class="list-subtitle">{{item.customerNickname || item.userNickname || '未命名用户'}} · {{item.customerPhoneMasked || '--'}}</text>
|
||||
</view>
|
||||
<text class="badge">{{item.displayStatusText}}</text>
|
||||
</view>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">订单金额</text>
|
||||
<text class="meta-value">¥{{item.payAmount}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">所属门店</text>
|
||||
<text class="meta-value">{{item.shopName || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">美甲师</text>
|
||||
<text class="meta-value">{{item.artistName || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">下单时间</text>
|
||||
<text class="meta-value">{{item.displayCreateTime}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn" data-order="{{item}}" bindtap="handleOpenOrder">查看详情</view>
|
||||
<view wx:if="{{item.status !== 2}}" class="mini-btn primary" data-order="{{item}}" bindtap="handleProcessOrder">处理订单</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:if="{{!list.length && !loading}}" class="empty-state">
|
||||
<text class="empty-title">暂无订单</text>
|
||||
<text class="empty-desc">当前筛选条件下没有符合的订单记录,切换状态或清空关键字后再试一次。</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
const permissionApi = require('../../api/permission')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permissionUtils = require('../../utils/permission')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
function buildPermissionGroups(list, checkedIds, assignableIds) {
|
||||
const groups = permissionUtils.groupPermissionsByGroup(list)
|
||||
return Object.keys(groups).map(group => ({
|
||||
group,
|
||||
items: groups[group].map(item => ({
|
||||
...item,
|
||||
valueId: String(item.id),
|
||||
checked: checkedIds.includes(String(item.id)),
|
||||
disabled: assignableIds.length ? !assignableIds.includes(String(item.id)) : false
|
||||
}))
|
||||
}))
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'definition-create',
|
||||
title: '',
|
||||
userId: '',
|
||||
currentUser: null,
|
||||
permissionGroups: [],
|
||||
form: {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'definition-create'
|
||||
this.setData({
|
||||
mode,
|
||||
userId: options && options.userId ? options.userId : '',
|
||||
title: mode === 'assign' ? '分配权限' : (mode === 'definition-edit' ? '编辑权限' : '新增权限')
|
||||
})
|
||||
|
||||
if (mode === 'assign') {
|
||||
this.loadAssignData()
|
||||
return
|
||||
}
|
||||
|
||||
const currentPermission = getTempRecord('currentPermission', null)
|
||||
if (mode === 'definition-edit' && currentPermission) {
|
||||
this.setData({
|
||||
form: {
|
||||
permissionCode: currentPermission.permissionCode || '',
|
||||
permissionName: currentPermission.permissionName || '',
|
||||
permissionGroup: currentPermission.permissionGroup || '',
|
||||
description: currentPermission.description || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentPermission')
|
||||
},
|
||||
|
||||
async loadAssignData() {
|
||||
const currentUser = getTempRecord('currentUser', null)
|
||||
this.setData({
|
||||
currentUser
|
||||
})
|
||||
|
||||
try {
|
||||
const [allPermissions, currentPermissions, assignableIds] = await Promise.all([
|
||||
permissionApi.listAllPermissions(),
|
||||
permissionApi.getUserPermissions(this.data.userId),
|
||||
permissionApi.getAssignablePermissionIds(this.data.userId)
|
||||
])
|
||||
|
||||
const checkedIds = (Array.isArray(currentPermissions) ? currentPermissions : []).map(item => String(item.id))
|
||||
const normalizedAssignableIds = (Array.isArray(assignableIds) ? assignableIds : []).map(item => String(item))
|
||||
|
||||
this.setData({
|
||||
permissionGroups: buildPermissionGroups(allPermissions, checkedIds, normalizedAssignableIds)
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '权限数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handlePermissionCheck(event) {
|
||||
const selected = event.detail.value || []
|
||||
this.setData({
|
||||
permissionGroups: this.data.permissionGroups.map(group => ({
|
||||
...group,
|
||||
items: group.items.map(item => ({
|
||||
...item,
|
||||
checked: item.disabled ? item.checked : selected.includes(item.valueId)
|
||||
}))
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (this.data.mode === 'assign') {
|
||||
const permissionIds = []
|
||||
this.data.permissionGroups.forEach(group => {
|
||||
group.items.forEach(item => {
|
||||
if (item.checked) {
|
||||
permissionIds.push(Number(item.id))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
try {
|
||||
await permissionApi.assignUserPermissions(this.data.userId, permissionIds)
|
||||
wx.showToast({
|
||||
title: '权限已保存',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/permissions/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '权限保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.data.form.permissionCode || !this.data.form.permissionName) {
|
||||
wx.showToast({
|
||||
title: '请补全权限编码和名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.data.mode === 'definition-edit') {
|
||||
const currentPermission = getTempRecord('currentPermission', null)
|
||||
await permissionApi.updatePermission(currentPermission.id, this.data.form)
|
||||
} else {
|
||||
await permissionApi.createPermission(this.data.form)
|
||||
}
|
||||
wx.showToast({
|
||||
title: '权限定义已保存',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/permissions/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<navigation-bar title="{{title}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view wx:if="{{mode === 'assign'}}" class="surface-card">
|
||||
<text class="section-title">{{currentUser.nickname || currentUser.account}}</text>
|
||||
<text class="section-desc">只能勾选当前账号被允许拥有的权限。超出允许范围的权限会直接置灰,避免前端只给出“保存失败”的笼统提示。</text>
|
||||
<checkbox-group bindchange="handlePermissionCheck">
|
||||
<block wx:for="{{permissionGroups}}" wx:key="group">
|
||||
<view class="list-card">
|
||||
<text class="list-title">{{item.group}}</text>
|
||||
<view class="checkbox-grid">
|
||||
<block wx:for="{{item.items}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}} {{item.disabled ? 'disabled' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" disabled="{{item.disabled}}" />
|
||||
{{item.permissionName}}
|
||||
</label>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">保存权限</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="surface-card">
|
||||
<text class="section-title">权限定义</text>
|
||||
<view class="field-group">
|
||||
<text class="field-label">权限编码</text>
|
||||
<input class="field-input" value="{{form.permissionCode}}" data-field="permissionCode" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">权限名称</text>
|
||||
<input class="field-input" value="{{form.permissionName}}" data-field="permissionName" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">权限分组</text>
|
||||
<input class="field-input" value="{{form.permissionGroup}}" data-field="permissionGroup" 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="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">保存权限定义</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
const permissionApi = require('../../api/permission')
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
function groupPermissions(list) {
|
||||
const map = {}
|
||||
;(Array.isArray(list) ? list : []).forEach(item => {
|
||||
const group = item.permissionGroup || '未分组'
|
||||
if (!map[group]) {
|
||||
map[group] = []
|
||||
}
|
||||
map[group].push(item)
|
||||
})
|
||||
|
||||
return Object.keys(map).map(group => ({
|
||||
group,
|
||||
items: map[group]
|
||||
}))
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
permissionGroups: [],
|
||||
users: [],
|
||||
canCreate: false,
|
||||
canAssign: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入权限管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('permission:create'),
|
||||
canAssign: permissionCodes.includes('permission:assign')
|
||||
})
|
||||
this.loadPageData()
|
||||
},
|
||||
|
||||
async loadPageData() {
|
||||
try {
|
||||
const [permissions, users] = await Promise.all([
|
||||
permissionApi.listAllPermissions(),
|
||||
userApi.listAllUsers().catch(() => [])
|
||||
])
|
||||
this.setData({
|
||||
permissionGroups: groupPermissions(permissions),
|
||||
users: Array.isArray(users) ? users : []
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '权限数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreatePermission() {
|
||||
clearTempRecord('currentPermission')
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'definition-create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEditPermission(event) {
|
||||
const permission = event.currentTarget.dataset.permission
|
||||
setTempRecord('currentPermission', permission)
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'definition-edit',
|
||||
id: permission.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleAssignUser(event) {
|
||||
const user = event.currentTarget.dataset.user
|
||||
setTempRecord('currentUser', user)
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'assign',
|
||||
userId: user.id
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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>
|
||||
<text class="section-desc">移动端不再铺宽表格,先选用户,再进入分组权限页勾选保存。服务端会继续兜底拦截超范围授权。</text>
|
||||
<block wx:for="{{users}}" 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.account}} · {{item.shopName || '多店铺账号'}}</text>
|
||||
</view>
|
||||
<text class="soft-badge">{{item.type === 4 ? '管理员' : item.type === 2 ? '店长' : item.type === 3 ? '美甲师' : '用户'}}</text>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view wx:if="{{canAssign}}" class="mini-btn primary" data-user="{{item}}" bindtap="handleAssignUser">配置权限</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="section-title">权限字典</text>
|
||||
<text class="section-desc">当前代码真实使用的权限定义都集中在这里,便于在手机上快速检查分组和描述是否合理。</text>
|
||||
</view>
|
||||
<view wx:if="{{canCreate}}" class="mini-btn primary" bindtap="handleCreatePermission">新增</view>
|
||||
</view>
|
||||
<block wx:for="{{permissionGroups}}" wx:key="group">
|
||||
<view class="list-card">
|
||||
<text class="list-title">{{item.group}}</text>
|
||||
<block wx:for="{{item.items}}" wx:key="id">
|
||||
<view class="divider-line"></view>
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-subtitle">{{item.permissionCode}}</text>
|
||||
<text class="list-title">{{item.permissionName}}</text>
|
||||
<text class="list-subtitle">{{item.description || '暂无描述'}}</text>
|
||||
</view>
|
||||
<view wx:if="{{canCreate}}" class="mini-btn" data-permission="{{item}}" bindtap="handleEditPermission">编辑</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
const productApi = require('../../api/product')
|
||||
const tagApi = require('../../api/tag')
|
||||
const userApi = require('../../api/user')
|
||||
const couponApi = require('../../api/coupon')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const cache = require('../../utils/cache')
|
||||
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')
|
||||
const { CACHE_TTL } = require('../../utils/config')
|
||||
|
||||
const DRAFT_KEY = 'admin-product-form'
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
function buildCheckableList(list, selectedIds, labelKey) {
|
||||
return (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
valueId: normalizeId(item.id),
|
||||
labelText: item[labelKey],
|
||||
checked: selectedIds.includes(normalizeId(item.id))
|
||||
}))
|
||||
}
|
||||
|
||||
function syncSelectedIds(selectedIds, list) {
|
||||
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
|
||||
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
productId: '',
|
||||
shops: [],
|
||||
shopIndex: 0,
|
||||
shopLabel: '',
|
||||
tags: [],
|
||||
artists: [],
|
||||
coupons: [],
|
||||
uploading: false,
|
||||
uploadProgress: 0,
|
||||
form: {
|
||||
title: '',
|
||||
description: '',
|
||||
price: '',
|
||||
approximateDuration: '',
|
||||
likeCount: '',
|
||||
collectCount: '',
|
||||
imageFileIds: [],
|
||||
shopId: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentProduct = getTempRecord('currentProduct', null)
|
||||
const draft = getDraftValue(DRAFT_KEY, null)
|
||||
this.setData({
|
||||
mode,
|
||||
productId: options && options.id ? options.id : ''
|
||||
})
|
||||
|
||||
this._selectedTagIds = []
|
||||
this._selectedArtistIds = []
|
||||
this._selectedCouponIds = []
|
||||
|
||||
if (mode === 'edit' && currentProduct) {
|
||||
this._selectedTagIds = format.splitCsv(currentProduct.tags)
|
||||
this._selectedArtistIds = format.splitCsv(currentProduct.bookableArtists)
|
||||
this._selectedCouponIds = format.splitCsv(currentProduct.availableCoupons)
|
||||
this._initialShopId = currentProduct.shopId
|
||||
this.setData({
|
||||
form: {
|
||||
title: currentProduct.title || '',
|
||||
description: currentProduct.description || '',
|
||||
price: currentProduct.price || '',
|
||||
approximateDuration: currentProduct.approximateDuration || '',
|
||||
likeCount: currentProduct.likeCount || '',
|
||||
collectCount: currentProduct.collectCount || '',
|
||||
imageFileIds: format.splitCsv(currentProduct.imageFileIds),
|
||||
shopId: currentProduct.shopId || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (draft && draft.mode === mode) {
|
||||
this._selectedTagIds = Array.isArray(draft.selectedTagIds) ? draft.selectedTagIds : this._selectedTagIds
|
||||
this._selectedArtistIds = Array.isArray(draft.selectedArtistIds) ? draft.selectedArtistIds : this._selectedArtistIds
|
||||
this._selectedCouponIds = Array.isArray(draft.selectedCouponIds) ? draft.selectedCouponIds : this._selectedCouponIds
|
||||
this._initialShopId = draft.form && draft.form.shopId ? draft.form.shopId : this._initialShopId
|
||||
this.setData({
|
||||
form: {
|
||||
...this.data.form,
|
||||
...(draft.form || {})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.loadDependencies()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentProduct')
|
||||
clearDraftTimer(this)
|
||||
},
|
||||
|
||||
scheduleProductDraft() {
|
||||
scheduleDraftSave(this, DRAFT_KEY, () => ({
|
||||
mode: this.data.mode,
|
||||
form: {
|
||||
...this.data.form,
|
||||
imageFileIds: this.data.form.imageFileIds.slice()
|
||||
},
|
||||
selectedTagIds: this._selectedTagIds.slice(),
|
||||
selectedArtistIds: this._selectedArtistIds.slice(),
|
||||
selectedCouponIds: this._selectedCouponIds.slice()
|
||||
}))
|
||||
},
|
||||
|
||||
async loadDependencies() {
|
||||
const app = getApp()
|
||||
const currentShop = app.globalData.currentShop
|
||||
const operator = app.globalData.userInfo || {}
|
||||
|
||||
try {
|
||||
const shopList = await cache.remember('admin:shops:all', CACHE_TTL.dict, () => shopApi.listAllShops())
|
||||
|
||||
let shops = Array.isArray(shopList) ? shopList : []
|
||||
if (Number(operator.type) !== 4 && currentShop) {
|
||||
shops = shops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
|
||||
}
|
||||
|
||||
let shopIndex = 0
|
||||
if (this._initialShopId) {
|
||||
const index = shops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
|
||||
if (index >= 0) {
|
||||
shopIndex = index
|
||||
}
|
||||
}
|
||||
const selectedShop = shops[shopIndex]
|
||||
|
||||
this.setData({
|
||||
shops,
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : '',
|
||||
'form.shopId': selectedShop ? selectedShop.id : ''
|
||||
})
|
||||
|
||||
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化作品表单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async loadShopScopedOptions(shopId) {
|
||||
if (!normalizeId(shopId)) {
|
||||
this._selectedTagIds = []
|
||||
this._selectedArtistIds = []
|
||||
this._selectedCouponIds = []
|
||||
this.setData({
|
||||
tags: [],
|
||||
artists: [],
|
||||
coupons: []
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const [tagList, artistList, couponList] = await Promise.all([
|
||||
tagApi.listTagsByShopId(shopId),
|
||||
userApi.listArtists(shopId),
|
||||
couponApi.listAllCoupons(shopId)
|
||||
])
|
||||
|
||||
this._selectedTagIds = syncSelectedIds(this._selectedTagIds, tagList)
|
||||
this._selectedArtistIds = syncSelectedIds(this._selectedArtistIds, artistList)
|
||||
this._selectedCouponIds = syncSelectedIds(this._selectedCouponIds, couponList)
|
||||
|
||||
this.setData({
|
||||
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
|
||||
artists: buildCheckableList(artistList, this._selectedArtistIds, 'nickname'),
|
||||
coupons: buildCheckableList(couponList, this._selectedCouponIds, 'couponName')
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
tags: [],
|
||||
artists: [],
|
||||
coupons: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '店铺关联数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : '',
|
||||
'form.shopId': selectedShop ? selectedShop.id : ''
|
||||
})
|
||||
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleTagChange(event) {
|
||||
this._selectedTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
tags: this.data.tags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleArtistChange(event) {
|
||||
this._selectedArtistIds = event.detail.value || []
|
||||
this.setData({
|
||||
artists: this.data.artists.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedArtistIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleCouponChange(event) {
|
||||
this._selectedCouponIds = event.detail.value || []
|
||||
this.setData({
|
||||
coupons: this.data.coupons.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedCouponIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
async handleUploadImages() {
|
||||
try {
|
||||
const files = await upload.chooseImageFiles({ count: 9 })
|
||||
this.setData({
|
||||
uploading: true,
|
||||
uploadProgress: 0
|
||||
})
|
||||
const result = await upload.uploadImageFiles({
|
||||
files,
|
||||
scene: 'admin-product-image',
|
||||
onProgress: progress => {
|
||||
this.setData({
|
||||
uploadProgress: Math.round(progress)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
this.setData({
|
||||
'form.imageFileIds': this.data.form.imageFileIds.concat(result.map(item => String(item.id)))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '图片上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
uploading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (!this.data.form.title) {
|
||||
wx.showToast({
|
||||
title: '请输入作品标题',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.data.form.shopId) {
|
||||
wx.showToast({
|
||||
title: '请选择所属店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.data.form.price) {
|
||||
wx.showToast({
|
||||
title: '请输入作品价格',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
shopId: this.data.form.shopId || undefined,
|
||||
title: this.data.form.title,
|
||||
description: this.data.form.description || undefined,
|
||||
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
|
||||
price: Number(this.data.form.price),
|
||||
tags: this._selectedTagIds.join(',') || undefined,
|
||||
likeCount: this.data.form.likeCount ? Number(this.data.form.likeCount) : undefined,
|
||||
collectCount: this.data.form.collectCount ? Number(this.data.form.collectCount) : undefined,
|
||||
approximateDuration: this.data.form.approximateDuration || undefined,
|
||||
bookableArtists: this._selectedArtistIds.join(',') || undefined,
|
||||
availableCoupons: this._selectedCouponIds.join(',') || undefined
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.data.mode === 'edit') {
|
||||
await productApi.updateProduct(this.data.productId, payload)
|
||||
} else {
|
||||
await productApi.createProduct(payload)
|
||||
}
|
||||
clearDraft(DRAFT_KEY)
|
||||
markDirty('admin-products')
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '作品已更新' : '作品已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/products/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<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.title}}" data-field="title" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">所属店铺</text>
|
||||
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
|
||||
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">作品价格</text>
|
||||
<input class="field-input" type="digit" value="{{form.price}}" data-field="price" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">大约耗时</text>
|
||||
<input class="field-input" value="{{form.approximateDuration}}" data-field="approximateDuration" 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>
|
||||
<input class="field-input" type="number" value="{{form.likeCount}}" data-field="likeCount" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">收藏数量</text>
|
||||
<input class="field-input" type="number" value="{{form.collectCount}}" data-field="collectCount" bindinput="handleInputChange"></input>
|
||||
</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 class="field-group">
|
||||
<text class="field-label">绑定标签</text>
|
||||
<checkbox-group bindchange="handleTagChange">
|
||||
<block wx:for="{{tags}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">可预约美甲师</text>
|
||||
<checkbox-group bindchange="handleArtistChange">
|
||||
<block wx:for="{{artists}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">可用优惠券</text>
|
||||
<checkbox-group bindchange="handleCouponChange">
|
||||
<block wx:for="{{coupons}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.labelText}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</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 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
const productApi = require('../../api/product')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
const PAGE_KEY = 'admin-products'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
list: [],
|
||||
loading: false,
|
||||
canCreate: false,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入作品管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('product:create')
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty(PAGE_KEY)) {
|
||||
this.loadProducts()
|
||||
}
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadProducts()
|
||||
},
|
||||
|
||||
async loadProducts() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await productApi.listProducts({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined
|
||||
})
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayPrice: format.formatPrice(item.price),
|
||||
displayShopName: item.shopName || '当前店铺',
|
||||
displayDuration: item.approximateDuration || '未设置时长',
|
||||
displayTagText: Array.isArray(item.tagList) ? item.tagList.join(' / ') : (item.tags || '未设置标签')
|
||||
})),
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '作品列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentProduct')
|
||||
navigation.navigate('/pages/product-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const product = event.currentTarget.dataset.product
|
||||
setTempRecord('currentProduct', product)
|
||||
navigation.navigate('/pages/product-form/index', {
|
||||
mode: 'edit',
|
||||
id: product.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const product = event.currentTarget.dataset.product
|
||||
wx.showModal({
|
||||
title: '删除作品',
|
||||
content: `确认删除作品“${product.title}”吗?`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await productApi.deleteProduct(product.id)
|
||||
wx.showToast({
|
||||
title: '作品已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadProducts()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '作品删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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.title}}</text>
|
||||
<text class="list-subtitle">{{item.displayShopName}} · {{item.displayDuration}}</text>
|
||||
</view>
|
||||
<text class="badge">¥{{item.displayPrice}}</text>
|
||||
</view>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">标签</text>
|
||||
<text class="meta-value">{{item.displayTagText}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">点赞 / 收藏</text>
|
||||
<text class="meta-value">{{item.likeCount || 0}} / {{item.collectCount || 0}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn primary" data-product="{{item}}" bindtap="handleEdit">编辑</view>
|
||||
<view class="mini-btn danger" data-product="{{item}}" bindtap="handleDelete">删除</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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
permissionCodes: [],
|
||||
roleLabel: '',
|
||||
shopScopeText: '',
|
||||
currentShopText: ''
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入个人中心')) {
|
||||
return
|
||||
}
|
||||
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo
|
||||
const currentShop = app.globalData.currentShop
|
||||
const shopScopeText = userInfo
|
||||
? (Array.isArray(userInfo.shopNames) && userInfo.shopNames.length
|
||||
? userInfo.shopNames.join(' / ')
|
||||
: (userInfo.shopName || '--'))
|
||||
: '--'
|
||||
|
||||
this.setData({
|
||||
userInfo,
|
||||
currentShop,
|
||||
permissionCodes: app.globalData.permissionCodes || [],
|
||||
roleLabel: userInfo ? permission.getRoleLabel(userInfo.type) : '--',
|
||||
shopScopeText,
|
||||
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为无店铺登录'
|
||||
})
|
||||
},
|
||||
|
||||
handleOpenOrders() {
|
||||
navigation.switchTab('/pages/orders/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
handleOpenManage() {
|
||||
navigation.switchTab('/pages/manage/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
async handleSwitchShop() {
|
||||
const userInfo = this.data.userInfo
|
||||
if (!userInfo || !userInfo.account) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await authApi.getLoginShops(userInfo.account)
|
||||
const shops = Array.isArray(result && result.shops) ? result.shops : []
|
||||
const allowShoplessLogin = Boolean(result && result.allowShoplessLogin)
|
||||
const items = shops.map(shop => ({
|
||||
label: shop.shopName,
|
||||
value: shop.id
|
||||
}))
|
||||
|
||||
if (allowShoplessLogin && permission.isPlatformAdmin(userInfo)) {
|
||||
items.unshift({
|
||||
label: '无店铺登录',
|
||||
value: ''
|
||||
})
|
||||
}
|
||||
|
||||
if (!items.length) {
|
||||
wx.showToast({
|
||||
title: '当前账号没有可切换的店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
wx.showActionSheet({
|
||||
itemList: items.map(item => item.label),
|
||||
success: async action => {
|
||||
const target = items[action.tapIndex]
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await getApp().switchAdminShop(target.value || undefined)
|
||||
wx.showToast({
|
||||
title: '店铺已切换',
|
||||
icon: 'none'
|
||||
})
|
||||
this.onShow()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '切换店铺失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '店铺列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleLogout() {
|
||||
try {
|
||||
await authApi.logout().catch(() => undefined)
|
||||
} finally {
|
||||
getApp().clearAdminSession()
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<navigation-bar title="我的" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view class="hero-panel">
|
||||
<text class="hero-kicker">{{userInfo.account || '后台账号'}}</text>
|
||||
<text class="hero-title">{{userInfo.nickname || '未设置昵称'}}</text>
|
||||
<text class="hero-desc">当前角色:{{roleLabel}}。{{currentShopText}}</text>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">账号信息</text>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">账号</text>
|
||||
<text class="meta-value">{{userInfo.account || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">权限数</text>
|
||||
<text class="meta-value">{{permissionCodes.length}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">店铺状态</text>
|
||||
<text class="meta-value">{{currentShop ? currentShop.shopName : '无店铺登录'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">可登录店铺</text>
|
||||
<text class="meta-value">{{shopScopeText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="secondary-btn" bindtap="handleSwitchShop">切换店铺</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">常用入口</text>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn primary" bindtap="handleOpenOrders">查看订单</view>
|
||||
<view class="mini-btn" bindtap="handleOpenManage">经营模块</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">退出登录</text>
|
||||
<text class="section-desc">退出后会清理管理端会话、当前店铺和权限快照;再次进入需要重新登录。</text>
|
||||
<view class="action-row">
|
||||
<button class="danger-btn" bindtap="handleLogout">退出当前账号</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
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')
|
||||
|
||||
const DRAFT_KEY = 'admin-shop-form'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
shopId: '',
|
||||
uploading: false,
|
||||
uploadProgress: 0,
|
||||
statusOptions: ['启用', '停用'],
|
||||
statusIndex: 0,
|
||||
form: {
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: []
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentShop = getTempRecord('currentShopRecord', null)
|
||||
const draft = getDraftValue(DRAFT_KEY, null)
|
||||
|
||||
this.setData({
|
||||
mode,
|
||||
shopId: options && options.id ? options.id : ''
|
||||
})
|
||||
|
||||
if (mode === 'edit' && currentShop) {
|
||||
this.setData({
|
||||
form: {
|
||||
shopName: currentShop.shopName || '',
|
||||
description: currentShop.description || '',
|
||||
address: currentShop.address || '',
|
||||
businessHours: currentShop.businessHours || '',
|
||||
coverImageFileId: currentShop.coverImageFileId || '',
|
||||
imageFileIds: currentShop.imageFileIds ? String(currentShop.imageFileIds).split(',').filter(Boolean) : []
|
||||
},
|
||||
statusIndex: Number(currentShop.status) === 0 ? 1 : 0
|
||||
})
|
||||
}
|
||||
|
||||
if (draft && draft.mode === mode) {
|
||||
this.setData({
|
||||
form: {
|
||||
...this.data.form,
|
||||
...draft.form
|
||||
},
|
||||
statusIndex: draft.statusIndex === 1 ? 1 : this.data.statusIndex
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentShopRecord')
|
||||
clearDraftTimer(this)
|
||||
},
|
||||
|
||||
scheduleShopDraft() {
|
||||
scheduleDraftSave(this, DRAFT_KEY, () => ({
|
||||
mode: this.data.mode,
|
||||
statusIndex: this.data.statusIndex,
|
||||
form: {
|
||||
...this.data.form,
|
||||
imageFileIds: this.data.form.imageFileIds.slice()
|
||||
}
|
||||
}))
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
this.scheduleShopDraft()
|
||||
},
|
||||
|
||||
handleStatusChange(event) {
|
||||
this.setData({
|
||||
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({
|
||||
count: isBanner ? 1 : 9
|
||||
})
|
||||
this.setData({
|
||||
uploading: true,
|
||||
uploadProgress: 0
|
||||
})
|
||||
const results = await upload.uploadImageFiles({
|
||||
files,
|
||||
scene,
|
||||
onProgress: progress => {
|
||||
this.setData({
|
||||
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({
|
||||
title: error.message || '图片上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
uploading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (!this.data.form.shopName) {
|
||||
wx.showToast({
|
||||
title: '请输入店铺名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
shopName: this.data.form.shopName,
|
||||
description: this.data.form.description || undefined,
|
||||
address: this.data.form.address || undefined,
|
||||
businessHours: this.data.form.businessHours || undefined,
|
||||
coverImageFileId: this.data.form.coverImageFileId || undefined,
|
||||
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
|
||||
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({
|
||||
title: this.data.mode === 'edit' ? '店铺已更新' : '店铺已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/shops/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
list: [],
|
||||
loading: false,
|
||||
canCreate: false,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入店铺管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('shop:create')
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty('admin-shops')) {
|
||||
this.loadShops()
|
||||
}
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadShops()
|
||||
},
|
||||
|
||||
async loadShops() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await shopApi.listShops({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined
|
||||
})
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayStatusText: Number(item.status) === 0 ? '已停用' : '启用中'
|
||||
})),
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '店铺加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentShopRecord')
|
||||
navigation.navigate('/pages/shop-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
setTempRecord('currentShopRecord', shop)
|
||||
navigation.navigate('/pages/shop-form/index', {
|
||||
mode: 'edit',
|
||||
id: shop.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleStatus(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
const nextStatus = Number(shop.status) === 0 ? 1 : 0
|
||||
shopApi.updateShopStatus(shop.id, nextStatus)
|
||||
.then(() => {
|
||||
wx.showToast({
|
||||
title: '店铺状态已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadShops()
|
||||
})
|
||||
.catch(error => {
|
||||
wx.showToast({
|
||||
title: error.message || '状态更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
wx.showModal({
|
||||
title: '删除店铺',
|
||||
content: `确认删除店铺“${shop.shopName}”吗?该操作会联动清理店铺下资源。`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await shopApi.deleteShop(shop.id)
|
||||
wx.showToast({
|
||||
title: '店铺已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadShops()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '店铺删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<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 class="mini-btn danger" data-shop="{{item}}" bindtap="handleDelete">删除</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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
const tagApi = require('../../api/tag')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
tagId: '',
|
||||
shops: [],
|
||||
shopIndex: -1,
|
||||
shopLabel: '',
|
||||
form: {
|
||||
tagName: '',
|
||||
textColor: '#2b2b2b',
|
||||
bgColor: '#f6e5df',
|
||||
borderColor: '#ef9a79'
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentTag = getTempRecord('currentTag', null)
|
||||
this.setData({
|
||||
mode,
|
||||
tagId: options && options.id ? options.id : ''
|
||||
})
|
||||
|
||||
if (mode === 'edit' && currentTag) {
|
||||
this.setData({
|
||||
form: {
|
||||
tagName: currentTag.tagName || '',
|
||||
textColor: currentTag.textColor || '#2b2b2b',
|
||||
bgColor: currentTag.bgColor || '#f6e5df',
|
||||
borderColor: currentTag.borderColor || '#ef9a79'
|
||||
}
|
||||
})
|
||||
this._initialShopId = currentTag.shopId
|
||||
}
|
||||
|
||||
this.loadShops()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentTag')
|
||||
},
|
||||
|
||||
async loadShops() {
|
||||
const app = getApp()
|
||||
const operator = app.globalData.userInfo || {}
|
||||
const currentShop = app.globalData.currentShop
|
||||
|
||||
try {
|
||||
const list = await shopApi.listAllShops()
|
||||
let shops = Array.isArray(list) ? list : []
|
||||
|
||||
if (Number(operator.type) !== 4 && currentShop) {
|
||||
shops = shops.filter(item => String(item.id) === String(currentShop.id))
|
||||
}
|
||||
|
||||
let shopIndex = 0
|
||||
if (this._initialShopId) {
|
||||
const targetIndex = shops.findIndex(item => String(item.id) === String(this._initialShopId))
|
||||
if (targetIndex >= 0) {
|
||||
shopIndex = targetIndex
|
||||
}
|
||||
}
|
||||
|
||||
const selectedShop = shops[shopIndex]
|
||||
this.setData({
|
||||
shops,
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化标签页面失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const selectedShop = this.data.shops[this.data.shopIndex]
|
||||
if (!this.data.form.tagName) {
|
||||
wx.showToast({
|
||||
title: '请输入标签名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!selectedShop) {
|
||||
wx.showToast({
|
||||
title: '请选择所属店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...this.data.form,
|
||||
shopId: selectedShop.id
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.data.mode === 'edit') {
|
||||
await tagApi.updateTag(this.data.tagId, payload)
|
||||
} else {
|
||||
await tagApi.createTag(payload)
|
||||
}
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '标签已更新' : '标签已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/tags/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<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.tagName}}" data-field="tagName" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">所属店铺</text>
|
||||
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
|
||||
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">文字颜色</text>
|
||||
<input class="field-input" value="{{form.textColor}}" data-field="textColor" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">背景颜色</text>
|
||||
<input class="field-input" value="{{form.bgColor}}" data-field="bgColor" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">边框颜色</text>
|
||||
<input class="field-input" value="{{form.borderColor}}" data-field="borderColor" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">保存标签</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
const tagApi = require('../../api/tag')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
list: []
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入标签管理')) {
|
||||
return
|
||||
}
|
||||
this.loadTags()
|
||||
},
|
||||
|
||||
async loadTags() {
|
||||
try {
|
||||
const list = await tagApi.listAllTags()
|
||||
this.setData({
|
||||
list: (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
displayShopName: item.shopName || '当前店铺'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '标签加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentTag')
|
||||
navigation.navigate('/pages/tag-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const tag = event.currentTarget.dataset.tag
|
||||
setTempRecord('currentTag', tag)
|
||||
navigation.navigate('/pages/tag-form/index', {
|
||||
mode: 'edit',
|
||||
id: tag.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const tag = event.currentTarget.dataset.tag
|
||||
wx.showModal({
|
||||
title: '删除标签',
|
||||
content: `确认删除标签“${tag.tagName}”吗?`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await tagApi.deleteTag(tag.id)
|
||||
wx.showToast({
|
||||
title: '标签已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadTags()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '标签删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<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>
|
||||
<text class="section-desc">标签按店铺绑定,同名标签可以在不同店铺重复存在,适合移动端用卡片方式快速维护。</text>
|
||||
</view>
|
||||
|
||||
<block wx:for="{{list}}" wx:key="id">
|
||||
<view class="list-card">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.tagName}}</text>
|
||||
<text class="list-subtitle">{{item.displayShopName}}</text>
|
||||
</view>
|
||||
<text class="soft-badge">颜色标签</text>
|
||||
</view>
|
||||
<view class="badge-row">
|
||||
<text class="soft-badge">{{item.textColor || '#333333'}}</text>
|
||||
<text class="soft-badge">{{item.bgColor || '#f5f5f5'}}</text>
|
||||
<text class="soft-badge">{{item.borderColor || '#dddddd'}}</text>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn primary" data-tag="{{item}}" bindtap="handleEdit">编辑</view>
|
||||
<view class="mini-btn danger" data-tag="{{item}}" bindtap="handleDelete">删除</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:if="{{!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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord, setTempRecord } = require('../../utils/storage')
|
||||
|
||||
const CHANGE_SCENE_OPTIONS = ['MANUAL_RECHARGE', 'MANUAL_INCREASE', 'MANUAL_DEDUCT']
|
||||
const VIP_LEVEL_OPTIONS = ['普通', '青铜', '白银', '黄金']
|
||||
|
||||
Page({
|
||||
data: {
|
||||
user: null,
|
||||
asset: null,
|
||||
balanceHistory: [],
|
||||
changeSceneIndex: 0,
|
||||
vipLevelIndex: 0,
|
||||
balanceForm: {
|
||||
amount: '',
|
||||
externalOrderNo: '',
|
||||
remark: ''
|
||||
},
|
||||
vipRemark: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const cached = getTempRecord('currentUser', null)
|
||||
if (cached && (!options || !options.id || String(cached.id) === String(options.id))) {
|
||||
this.setUser(cached)
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入用户详情')) {
|
||||
return
|
||||
}
|
||||
this.loadAssetData()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentUser')
|
||||
},
|
||||
|
||||
async loadAssetData() {
|
||||
if (!this.data.user) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const [asset, balanceHistory] = await Promise.all([
|
||||
userApi.getUserAsset(this.data.user.id).catch(() => null),
|
||||
userApi.getUserBalanceHistory(this.data.user.id).catch(() => [])
|
||||
])
|
||||
|
||||
this.setData({
|
||||
asset,
|
||||
balanceHistory: (Array.isArray(balanceHistory) ? balanceHistory : []).map(item => ({
|
||||
...item,
|
||||
displayChangeTime: format.formatDateTime(item.changeTime),
|
||||
amountBadgeClass: Number(item.amount) >= 0 ? 'success-badge' : 'danger-badge'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '用户资产数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleEdit() {
|
||||
setTempRecord('currentUser', this.data.user)
|
||||
navigation.navigate('/pages/user-form/index', {
|
||||
mode: 'edit',
|
||||
id: this.data.user.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handlePermissionAssign() {
|
||||
setTempRecord('currentUser', this.data.user)
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'assign',
|
||||
userId: this.data.user.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleBalanceInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`balanceForm.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleVipRemarkInput(event) {
|
||||
this.setData({
|
||||
vipRemark: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSceneChange(event) {
|
||||
this.setData({
|
||||
changeSceneIndex: Number(event.detail.value)
|
||||
})
|
||||
},
|
||||
|
||||
handleVipLevelChange(event) {
|
||||
this.setData({
|
||||
vipLevelIndex: Number(event.detail.value)
|
||||
})
|
||||
},
|
||||
|
||||
async handleBalanceChange() {
|
||||
try {
|
||||
await userApi.changeUserBalance(this.data.user.id, {
|
||||
amount: Number(this.data.balanceForm.amount),
|
||||
changeScene: CHANGE_SCENE_OPTIONS[this.data.changeSceneIndex],
|
||||
externalOrderNo: this.data.balanceForm.externalOrderNo || undefined,
|
||||
remark: this.data.balanceForm.remark || undefined
|
||||
})
|
||||
wx.showToast({
|
||||
title: '余额已调整',
|
||||
icon: 'none'
|
||||
})
|
||||
this.setData({
|
||||
balanceForm: {
|
||||
amount: '',
|
||||
externalOrderNo: '',
|
||||
remark: ''
|
||||
}
|
||||
})
|
||||
this.loadAssetData()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '余额调整失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleVipOverride() {
|
||||
try {
|
||||
await userApi.overrideUserVip(this.data.user.id, {
|
||||
vipLevel: VIP_LEVEL_OPTIONS[this.data.vipLevelIndex],
|
||||
remark: this.data.vipRemark || undefined
|
||||
})
|
||||
wx.showToast({
|
||||
title: 'VIP 等级已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadAssetData()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || 'VIP 更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleVipRecalculate() {
|
||||
try {
|
||||
await userApi.recalculateUserVip(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '已恢复自动判级',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadAssetData()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || 'VIP 重算失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleResetPassword() {
|
||||
try {
|
||||
await userApi.resetPassword(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '密码已重置',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '密码重置失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleUserAction(event) {
|
||||
const action = event.currentTarget.dataset.action
|
||||
if (action === 'disable') {
|
||||
this.updateUserStatus(this.data.user.status === 0 ? 1 : 0)
|
||||
return
|
||||
}
|
||||
if (action === 'delete') {
|
||||
this.confirmDelete()
|
||||
return
|
||||
}
|
||||
if (action === 'unbind') {
|
||||
this.confirmUnbind()
|
||||
}
|
||||
},
|
||||
|
||||
async updateUserStatus(status) {
|
||||
try {
|
||||
await userApi.updateUserStatus(this.data.user.id, status)
|
||||
wx.showToast({
|
||||
title: '用户状态已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
const user = {
|
||||
...this.data.user,
|
||||
status
|
||||
}
|
||||
this.setUser(user)
|
||||
setTempRecord('currentUser', user)
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '状态更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
confirmDelete() {
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '删除后该账号将不再出现在前端可见列表中,确认继续吗?',
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await userApi.deleteUser(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '用户已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/users/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
confirmUnbind() {
|
||||
wx.showModal({
|
||||
title: '确认解绑',
|
||||
content: '解绑后,该用户将无法登录当前店铺,确认继续吗?',
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await userApi.unbindUser(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '已解除当前店铺绑定',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '解绑失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
setUser(user) {
|
||||
this.setData({
|
||||
user: user ? {
|
||||
...user,
|
||||
displayTypeText: format.getUserTypeText(user.type),
|
||||
displayShopName: format.buildShopName(user),
|
||||
displayStatusText: format.getUserStatusText(user.status),
|
||||
displayCreateTime: format.formatDateTime(user.createTime)
|
||||
} : null
|
||||
})
|
||||
}
|
||||
})
|
||||