auth-web/src/store/system/power.ts

112 lines
2.7 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
2025-04-24 13:43:37 +08:00
import {
2025-04-27 22:16:06 +08:00
createPermission,
deletePermission,
2025-04-28 09:39:28 +08:00
exportPermission,
2025-04-27 22:16:06 +08:00
getPermissionList,
getPermissionPage,
2025-04-28 09:39:28 +08:00
importPermission,
2025-04-27 22:16:06 +08:00
updatePermission,
updatePermissionListByParentId,
2025-04-24 13:43:37 +08:00
} from '@/api/v1/system/power';
import { pageSizes } from '@/enums/baseConstant';
import { storeMessage } from '@/utils/message';
import { storePagination } from '@/store/useStorePagination';
2025-04-28 09:39:28 +08:00
import { downloadBlob } from '@/utils/sso';
/**
* Store
*/
2025-04-27 22:16:06 +08:00
export const usePermissionStore = defineStore('PermissionStore', {
2025-04-24 13:43:37 +08:00
state() {
return {
// 权限列表
datalist: [],
// 权限树形结构
allPowerList: [],
// 查询表单
form: {
// 权限编码
powerCode: undefined,
// 权限名称
powerName: undefined,
// 请求路径
requestUrl: undefined,
2025-04-26 10:25:12 +08:00
// 请求方法
requestMethod: undefined,
2025-04-24 13:43:37 +08:00
},
// 分页查询结果
pagination: {
currentPage: 1,
pageSize: 150,
total: 1,
pageSizes,
},
// 加载
loading: false,
};
},
getters: {},
actions: {
/** 获取权限 */
2025-04-27 22:16:06 +08:00
async fetchPermissionPage() {
2025-04-24 13:43:37 +08:00
// 整理请求参数
const data = { ...this.pagination, ...this.form };
delete data.pageSizes;
delete data.total;
delete data.background;
2025-04-24 13:43:37 +08:00
// 获取权限列表
2025-04-27 22:16:06 +08:00
const result = await getPermissionPage(data);
2025-04-24 13:43:37 +08:00
// 公共页面函数hook
const pagination = storePagination.bind(this);
return pagination(result);
},
2025-04-24 13:43:37 +08:00
/** 添加权限 */
2025-04-27 22:16:06 +08:00
async addPermission(data: any) {
const result = await createPermission(data);
2025-04-24 13:43:37 +08:00
return storeMessage(result);
},
2025-04-24 13:43:37 +08:00
/** 修改权限 */
2025-04-27 22:16:06 +08:00
async editPermission(data: any) {
const result = await updatePermission(data);
2025-04-24 13:43:37 +08:00
return storeMessage(result);
},
2025-04-27 22:16:06 +08:00
/** 删除权限 */
async removePermission(data: any) {
const result = await deletePermission(data);
2025-04-24 13:43:37 +08:00
return storeMessage(result);
},
2024-10-10 10:32:17 +08:00
2025-04-28 09:39:28 +08:00
/* 使用Excel导出权限 */
async downloadPermissionByFile() {
const result = await exportPermission();
downloadBlob(result, 'role.zip');
},
/* 使用文件导入权限 */
async uploadPermissionByFile(data: any) {
const result = await importPermission(data);
2025-04-24 13:43:37 +08:00
return storeMessage(result);
},
2025-04-24 13:43:37 +08:00
/** 获取所有权限 */
2025-04-27 22:16:06 +08:00
async loadPermissionList() {
const result = await getPermissionList();
2025-04-24 13:43:37 +08:00
if (result.code !== 200) return;
this.allPowerList = result.data;
},
2025-04-28 09:39:28 +08:00
/** 批量修改权限父级 */
async updatePermissionListByParentId(data: any) {
const result = await updatePermissionListByParentId(data);
return storeMessage(result);
},
2025-04-24 13:43:37 +08:00
},
});