182 lines
8.5 KiB
JavaScript
182 lines
8.5 KiB
JavaScript
/**
|
|
* Purpose: permissionApi supports index.js by holding or executing the permission 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 permissionApi = require('../../api/permission')
|
|
/**
|
|
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const userApi = require('../../api/user')
|
|
/**
|
|
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const navigation = require('../../utils/navigation')
|
|
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
|
|
|
/**
|
|
* Purpose: groupPermissions supports index.js by holding or executing the group permissions page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
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({
|
|
/**
|
|
* 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: permissionGroups supports index.js by holding or executing the permission groups 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.
|
|
*/
|
|
permissionGroups: [],
|
|
/**
|
|
* Purpose: users supports index.js by holding or executing the users 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.
|
|
*/
|
|
users: [],
|
|
/**
|
|
* 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: canAssign supports index.js by holding or executing the can assign 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.
|
|
*/
|
|
canAssign: 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('permission:create'),
|
|
/**
|
|
* Purpose: canAssign supports index.js by holding or executing the can assign 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.
|
|
*/
|
|
canAssign: permissionCodes.includes('permission:assign')
|
|
})
|
|
this.loadPageData()
|
|
},
|
|
|
|
async loadPageData() {
|
|
try {
|
|
const [permissions, users] = await Promise.all([
|
|
permissionApi.listAllPermissions(),
|
|
userApi.listAllUsers().catch(() => [])
|
|
])
|
|
this.setData({
|
|
/**
|
|
* Purpose: permissionGroups supports index.js by holding or executing the permission groups 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.
|
|
*/
|
|
permissionGroups: groupPermissions(permissions),
|
|
/**
|
|
* Purpose: users supports index.js by holding or executing the users 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.
|
|
*/
|
|
users: Array.isArray(users) ? users : []
|
|
})
|
|
} 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'
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleCreatePermission supports index.js by holding or executing the handle create permission 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.
|
|
*/
|
|
handleCreatePermission() {
|
|
clearTempRecord('currentPermission')
|
|
navigation.navigate('/pages/permission-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: 'definition-create'
|
|
}).catch(() => undefined)
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleEditPermission supports index.js by holding or executing the handle edit permission 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.
|
|
*/
|
|
handleEditPermission(event) {
|
|
const permission = event.currentTarget.dataset.permission
|
|
setTempRecord('currentPermission', permission)
|
|
navigation.navigate('/pages/permission-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: 'definition-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: permission.id
|
|
}).catch(() => undefined)
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleAssignUser supports index.js by holding or executing the handle assign user 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.
|
|
*/
|
|
handleAssignUser(event) {
|
|
const user = event.currentTarget.dataset.user
|
|
setTempRecord('currentUser', user)
|
|
navigation.navigate('/pages/permission-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: 'assign',
|
|
/**
|
|
* Purpose: userId supports index.js by holding or executing the user 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.
|
|
*/
|
|
userId: user.id
|
|
}).catch(() => undefined)
|
|
}
|
|
})
|