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

87 lines
2.0 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
2024-10-10 10:32:17 +08:00
import { fetchAddPower, fetchDeletePower, fetchGetAllPowers, fetchGetPowerList, fetchUpdateBatchByPowerWithParentId, fetchUpdatePower } from '@/api/v1/power';
import { pageSizes } from '@/enums/baseConstant';
import { storeMessage } from '@/utils/message';
import { storePagination } from '@/store/useStorePagination';
/**
* Store
*/
export const usePowerStore = defineStore('powerStore', {
state() {
return {
// 权限列表
datalist: [],
// 权限树形结构
allPowerList: [],
// 查询表单
form: {
// 权限编码
powerCode: undefined,
// 权限名称
powerName: undefined,
// 请求路径
requestUrl: undefined,
},
// 分页查询结果
pagination: {
currentPage: 1,
2024-10-23 13:46:46 +08:00
pageSize: 30,
total: 1,
pageSizes,
},
// 加载
loading: false,
};
},
getters: {},
actions: {
2024-10-11 10:44:16 +08:00
/** 获取权限 */
async getPowerList() {
// 整理请求参数
const data = { ...this.pagination, ...this.form };
delete data.pageSizes;
delete data.total;
delete data.background;
// 获取权限列表
const result = await fetchGetPowerList(data);
// 公共页面函数hook
const pagination = storePagination.bind(this);
return pagination(result);
},
2024-10-11 10:44:16 +08:00
/** 添加权限 */
async addPower(data: any) {
const result = await fetchAddPower(data);
return storeMessage(result);
},
2024-10-11 10:44:16 +08:00
/** 修改权限 */
async updatePower(data: any) {
const result = await fetchUpdatePower(data);
return storeMessage(result);
},
2024-10-11 10:44:16 +08:00
/** 批量修改权限父级 */
2024-10-10 10:32:17 +08:00
async updateBatchByPowerWithParentId(data: any) {
const result = await fetchUpdateBatchByPowerWithParentId(data);
return storeMessage(result);
},
2024-10-11 10:44:16 +08:00
/** 删除权限 */
async deletePower(data: any) {
const result = await fetchDeletePower(data);
return storeMessage(result);
},
2024-10-11 10:44:16 +08:00
/** 获取所有权限 */
async getAllPowers() {
const result = await fetchGetAllPowers();
if (result.code !== 200) return;
this.allPowerList = result.data;
},
},
});