重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const shopApi = require('../../api/shop')
|
||||
/**
|
||||
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
Page({
|
||||
/**
|
||||
* Purpose: data supports index.js by holding or executing the data page or API role.
|
||||
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
data: {
|
||||
/**
|
||||
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
keyword: '',
|
||||
/**
|
||||
* Purpose: list supports index.js by holding or executing the list page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
list: [],
|
||||
/**
|
||||
* Purpose: loading supports index.js by holding or executing the loading page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
loading: false,
|
||||
/**
|
||||
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
canCreate: false,
|
||||
/**
|
||||
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
initialized: false
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
|
||||
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入店铺管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
/**
|
||||
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
canCreate: permissionCodes.includes('shop:create')
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty('admin-shops')) {
|
||||
this.loadShops()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input page or API role.
|
||||
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
/**
|
||||
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleSearch supports index.js by holding or executing the handle search page or API role.
|
||||
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
handleSearch() {
|
||||
this.loadShops()
|
||||
},
|
||||
|
||||
async loadShops() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
/**
|
||||
* Purpose: loading supports index.js by holding or executing the loading page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await shopApi.listShops({
|
||||
/**
|
||||
* Purpose: page supports index.js by holding or executing the page page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
page: 1,
|
||||
/**
|
||||
* Purpose: size supports index.js by holding or executing the size page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
size: 20,
|
||||
/**
|
||||
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
keyword: this.data.keyword || undefined
|
||||
})
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
/**
|
||||
* Purpose: list supports index.js by holding or executing the list page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
/**
|
||||
* Purpose: displayStatusText supports index.js by holding or executing the display status text page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
displayStatusText: Number(item.status) === 0 ? '已停用' : '启用中'
|
||||
})),
|
||||
/**
|
||||
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
/**
|
||||
* Purpose: title supports index.js by holding or executing the title page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
title: error.message || '店铺加载失败',
|
||||
/**
|
||||
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
/**
|
||||
* Purpose: loading supports index.js by holding or executing the loading page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleCreate supports index.js by holding or executing the handle create page or API role.
|
||||
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
handleCreate() {
|
||||
clearTempRecord('currentShopRecord')
|
||||
navigation.navigate('/pages/shop-form/index', {
|
||||
/**
|
||||
* Purpose: mode supports index.js by holding or executing the mode page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleEdit supports index.js by holding or executing the handle edit page or API role.
|
||||
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
handleEdit(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
setTempRecord('currentShopRecord', shop)
|
||||
navigation.navigate('/pages/shop-form/index', {
|
||||
/**
|
||||
* Purpose: mode supports index.js by holding or executing the mode page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
mode: 'edit',
|
||||
/**
|
||||
* Purpose: id supports index.js by holding or executing the id page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
id: shop.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleStatus supports index.js by holding or executing the handle status page or API role.
|
||||
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
handleStatus(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
const nextStatus = Number(shop.status) === 0 ? 1 : 0
|
||||
shopApi.updateShopStatus(shop.id, nextStatus)
|
||||
.then(() => {
|
||||
wx.showToast({
|
||||
/**
|
||||
* Purpose: title supports index.js by holding or executing the title page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
title: '店铺状态已更新',
|
||||
/**
|
||||
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadShops()
|
||||
})
|
||||
.catch(error => {
|
||||
wx.showToast({
|
||||
/**
|
||||
* Purpose: title supports index.js by holding or executing the title page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
title: error.message || '状态更新失败',
|
||||
/**
|
||||
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
||||
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
icon: 'none'
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user