mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-12 21:53:48 +08:00
smart-app alpha 版本
This commit is contained in:
12
smart-app/src/store/index.js
Normal file
12
smart-app/src/store/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* pinia 状态管理
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:58:09
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import * as pinia from 'pinia';
|
||||
|
||||
export const store = pinia.createPinia();
|
||||
55
smart-app/src/store/modules/system/app-config.js
Normal file
55
smart-app/src/store/modules/system/app-config.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 项目的配置信息
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:53:47
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import { defineStore } from 'pinia';
|
||||
import { appDefaultConfig } from '/@/config/app-config';
|
||||
import localStorageKeyConst from '/@/constants/local-storage-key-const';
|
||||
import { smartSentry } from '/@/lib/smart-sentry';
|
||||
import { localRead } from '/@/utils/local-util';
|
||||
|
||||
let state = { ...appDefaultConfig };
|
||||
|
||||
let appConfigStr = localRead(localStorageKeyConst.APP_CONFIG);
|
||||
let language = appDefaultConfig.language;
|
||||
if (appConfigStr) {
|
||||
try {
|
||||
state = JSON.parse(appConfigStr);
|
||||
language = state.language;
|
||||
} catch (e) {
|
||||
smartSentry.captureError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取初始化的语言
|
||||
*/
|
||||
export const getInitializedLanguage = function () {
|
||||
return language;
|
||||
};
|
||||
|
||||
export const useAppConfigStore = defineStore({
|
||||
id: 'appConfig',
|
||||
state: () => ({
|
||||
// 读取config下的默认配置
|
||||
...state,
|
||||
}),
|
||||
actions: {
|
||||
reset() {
|
||||
for (const k in appDefaultConfig) {
|
||||
this[k] = appDefaultConfig[k];
|
||||
}
|
||||
},
|
||||
showHelpDoc() {
|
||||
this.helpDocFlag = true;
|
||||
},
|
||||
hideHelpDoc() {
|
||||
this.helpDocFlag = false;
|
||||
},
|
||||
},
|
||||
});
|
||||
83
smart-app/src/store/modules/system/user.js
Normal file
83
smart-app/src/store/modules/system/user.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 登录用户
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:55:09
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import _ from 'lodash';
|
||||
import { defineStore } from 'pinia';
|
||||
import { USER_TOKEN } from '/@/constants/local-storage-key-const';
|
||||
import { loginApi } from '/@/api/system/login-api';
|
||||
|
||||
const defaultUserInfo = {
|
||||
//员工id
|
||||
employeeId: '',
|
||||
//登录名
|
||||
loginName: '',
|
||||
//姓名
|
||||
actualName: '',
|
||||
//手机号
|
||||
phone: '',
|
||||
//部门id
|
||||
departmentId: '',
|
||||
//部门名词
|
||||
departmentName: '',
|
||||
//是否为超级管理员
|
||||
administratorFlag: true,
|
||||
//上次登录ip
|
||||
lastLoginIp: '',
|
||||
//上次登录ip地区
|
||||
lastLoginIpRegion: '',
|
||||
//上次登录 设备
|
||||
lastLoginUserAgent: '',
|
||||
//上次登录时间
|
||||
lastLoginTime: '',
|
||||
};
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
id: 'userStore',
|
||||
state: () => ({
|
||||
...defaultUserInfo,
|
||||
}),
|
||||
getters: {
|
||||
getToken(state) {
|
||||
return uni.getStorageSync(USER_TOKEN);
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
logout() {
|
||||
this.token = null;
|
||||
uni.removeStorage(USER_TOKEN);
|
||||
},
|
||||
clearUserLoginInfo() {
|
||||
this.setUserLoginInfo(defaultUserInfo);
|
||||
uni.removeStorage(USER_TOKEN);
|
||||
},
|
||||
async getLoginInfo() {
|
||||
let res = await loginApi.getLoginInfo();
|
||||
this.setUserLoginInfo(res.data);
|
||||
},
|
||||
//设置登录信息
|
||||
setUserLoginInfo(data) {
|
||||
// 用户基本信息
|
||||
this.token = data.token;
|
||||
this.employeeId = data.employeeId;
|
||||
this.loginName = data.loginName;
|
||||
this.actualName = data.actualName;
|
||||
this.phone = data.phone;
|
||||
this.departmentId = data.departmentId;
|
||||
this.departmentName = data.departmentName;
|
||||
this.administratorFlag = data.administratorFlag;
|
||||
this.lastLoginIp = data.lastLoginIp;
|
||||
this.lastLoginIpRegion = data.lastLoginIpRegion;
|
||||
this.lastLoginUserAgent = data.lastLoginUserAgent;
|
||||
this.lastLoginTime = data.lastLoginTime;
|
||||
|
||||
uni.setStorageSync(USER_TOKEN, data.token);
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user