'use strict'; const MainService = require('../../main'); class roleService extends MainService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = 'list,add,delete,update,permission'; const _noNeedLog = '*'; const _noNeedAuth = 'list,add,delete,update,permission'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } async callSystemRole(methodName, data, defaultMessage) { const { service } = this; try { const result = await service.systems.setting.role[methodName](data); return this.success('ok', result); } catch (error) { return this.fail(error.message || defaultMessage, { code: Number(error.code) || 500, }); } } /** * 角色列表。 * @param {*} data 请求参数 */ async list(data = {}) { return this.callSystemRole('list', data, '获取角色列表失败'); } /** * 角色权限列表(兼容旧入口)。 * @param {*} data 请求参数 */ async permission(data = {}) { return this.callSystemRole('permission', data, '获取角色权限列表失败'); } /** * 新增角色。 * @param {*} data 请求参数 */ async add(data = {}) { return this.callSystemRole('add', data, '新增角色失败'); } /** * 删除角色。 * @param {*} data 请求参数 */ async delete(data = {}) { return this.callSystemRole('delete', data, '删除角色失败'); } /** * 更新角色。 * @param {*} data 请求参数 */ async update(data = {}) { return this.callSystemRole('update', data, '更新角色失败'); } } module.exports = roleService;