This commit is contained in:
qsh
2026-02-03 11:46:59 +08:00
parent 20ab62b473
commit ec95ab4933
18 changed files with 197 additions and 967 deletions

View File

@@ -1,9 +1,10 @@
import { createPinia } from 'pinia'
import { useUserStore } from './modules/user'
import { useConfigStore } from './modules/config'
import { createPinia } from 'pinia';
import { useUserStore } from './modules/user';
import { useConfigStore } from './modules/config';
import { useTenantStore } from './modules/tenant';
const pinia = createPinia()
const pinia = createPinia();
export default pinia
export default pinia;
export { useUserStore, useConfigStore }
export { useUserStore, useConfigStore, useTenantStore };

View File

@@ -0,0 +1,45 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import config from '@/config';
import storage from '@/utils/storage';
import constant from '@/utils/constant';
import { isEmpty } from '@/utils/validate';
import { getTenantInfo, updateTenant } from '@/api/system/tenant';
export const useTenantStore = defineStore('tenant', () => {
const tenantInfo = ref(storage.get(constant.tenantInfo));
const SET_TENANT_INFO = val => {
tenantInfo.value = val;
storage.set(constant.tenantInfo, val);
};
const getTenant = () => {
return new Promise(resolve => {
getTenantInfo({ id: config.appInfo.tenantId }).then(res => {
if (!isEmpty(res.data)) {
SET_TENANT_INFO(res.data);
}
resolve(res);
});
});
};
const updateTenantInfo = data => {
return new Promise(resolve => {
updateTenant(data).then(res => {
if (!isEmpty(res.data)) {
getTenant();
}
resolve(res);
});
});
};
return {
tenantInfo,
SET_TENANT_INFO,
getTenant,
updateTenantInfo
};
});

View File

@@ -14,6 +14,7 @@ export const useUserStore = defineStore('user', () => {
const token = ref(getToken());
const id = ref(storage.get(constant.id));
const name = ref(storage.get(constant.name));
const currentRole = ref(storage.get('currentRole'));
const avatar = ref(storage.get(constant.avatar));
const roles = ref(storage.get(constant.roles));
const permissions = ref(storage.get(constant.permissions));
@@ -29,6 +30,10 @@ export const useUserStore = defineStore('user', () => {
name.value = val;
storage.set(constant.name, val);
};
const SET_CURRENT_ROLE = val => {
currentRole.value = val;
storage.set('currentRole', val);
};
const SET_AVATAR = val => {
avatar.value = val;
storage.set(constant.avatar, val);
@@ -69,8 +74,9 @@ export const useUserStore = defineStore('user', () => {
if (!isHttp(avatar)) {
avatar = isEmpty(avatar) ? defAva : baseUrl + avatar;
}
const userid = isEmpty(user) || isEmpty(user.userId) ? '' : user.userId;
const username = isEmpty(user) || isEmpty(user.userName) ? '' : user.userName;
const userid = isEmpty(user) || isEmpty(user.id) ? '' : user.id;
const username = isEmpty(user) || isEmpty(user.nickname) ? '' : user.nickname;
const role = isEmpty(user) || isEmpty(user.currentRole) ? '' : user.currentRole;
if (res.data.roles && res.data.roles.length > 0) {
SET_ROLES(res.data.roles);
SET_PERMISSIONS(res.data.permissions);
@@ -80,6 +86,7 @@ export const useUserStore = defineStore('user', () => {
SET_ID(userid);
SET_NAME(username);
SET_AVATAR(avatar);
SET_CURRENT_ROLE(role);
resolve(res);
})
.catch(error => {
@@ -95,6 +102,7 @@ export const useUserStore = defineStore('user', () => {
.then(() => {
SET_TOKEN('');
SET_ROLES([]);
SET_CURRENT_ROLE('');
SET_PERMISSIONS([]);
removeToken();
storage.clean();
@@ -110,6 +118,7 @@ export const useUserStore = defineStore('user', () => {
token,
id,
name,
currentRole,
avatar,
roles,
permissions,