1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import {defineStore, storeToRefs} from 'pinia';
- import {Cookie, Session} from '@/utils/storage';
- import { getUserInfo } from "@/api/login/user";
- import {useThemeConfig} from "@/stores/themeConfig";
- /**
- * @description 用户信息
- * @methods getUserInfos 获取用户信息
- * @methods setUserInfos 设置用户信息
- */
- export const useUserInfo = defineStore('userInfo', {
- state: (): UserInfosStates => ({
- userInfos: {
- account: '', // 账号
- name: '',// 姓名
- phoneNo: '', //电话
- staffNo: '', // 工号
- id: '',
- photo: '', //头像
- authBtnList: [], // 授权按钮数组
- defaultTelNo: '', // 默认分机号
- token: '',
- showTelControl: false, // 是否展示坐席操作电话面板
- orgName:'', // 组织名称
- roles: [], // 角色
- isCenter: false, // 当前本部门是否是中心
- monitor: false, // 是否是班长
- },
- }),
- actions: {
- async setUserInfos(buttons: string[]) {
- if (Session.get('userInfo')) { //有缓存 取缓存
- this.userInfos = Session.get('userInfo');
- } else {
- this.userInfos = await this.getApiUserInfo(buttons) as any;
- }
- },
- async getApiUserInfo(buttons: string[]) {
- try {
- // 个人信息
- let userInfo: any = await getUserInfo();
- this.userInfos.name = userInfo.result?.user.name ?? '暂无名称';
- this.userInfos.account = userInfo.result?.user.account ?? '';
- this.userInfos.phoneNo = userInfo.result?.user.phoneNo ?? '';
- this.userInfos.staffNo = userInfo.result?.user.staffNo ?? '';
- this.userInfos.defaultTelNo = userInfo.result.defaultTelNo ?? '';
- this.userInfos.id = userInfo.result?.user.id ?? '';
- this.userInfos.roles = userInfo.result?.user.roles ?? [];
- this.userInfos.token = Cookie.get('token') ?? '';
- this.userInfos.photo = "";
- this.userInfos.orgName = userInfo.result?.user.organization?.name ?? '';
- this.userInfos.isCenter = userInfo.result?.user.organization?.isCenter ?? false;
- this.userInfos.monitor = userInfo.result?.monitor ?? false;
- //授权按钮
- this.userInfos.showTelControl = buttons.includes('public:seat:panel'); // 查询是否有展示面板权限
- this.userInfos.authBtnList = buttons;
- Session.set('userInfo', this.userInfos);
- const storesThemeConfig = useThemeConfig();
- const { themeConfig } = storeToRefs(storesThemeConfig);
- if(themeConfig.value.isWatermark){
- storesThemeConfig.setThemeConfig({
- ...storesThemeConfig.themeConfig,
- watermarkText:[this.userInfos.name, this.userInfos.orgName]
- })
- }
- return this.userInfos;
- } catch (error) {
- this.userInfos = {
- account: '暂无名称', // 账号
- name: '',// 姓名
- phoneNo: '', //电话
- staffNo: '', // 工号
- id: '',
- photo: '', //头像
- authBtnList: [], // 授权按钮数组
- defaultTelNo: '', // 默认分机号
- token: '',
- showTelControl: false, // 是否展示坐席操作电话面板
- orgName:'', // 组织名称
- roles: [], // 角色
- isCenter: false, // 当前部门是否是中心
- monitor: false, // 是否是班长
- }
- Session.set('userInfo', this.userInfos);
- return this.userInfos;
- }
- },
- },
- });
|