完善大屏弹窗和画板
This commit is contained in:
parent
a566232907
commit
5c820e5de8
2
.env
2
.env
@ -8,4 +8,4 @@ VITE_OPEN = false
|
||||
VITE_OPEN_CDN = false
|
||||
|
||||
# public path 配置线上环境路径(打包)、本地通过 http-server 访问时,请置空即可
|
||||
VITE_PUBLIC_PATH = /vue-next-admin-preview/
|
||||
# VITE_PUBLIC_PATH = /vue-next-admin-preview/
|
@ -2,4 +2,4 @@
|
||||
ENV = development
|
||||
|
||||
# 本地环境接口地址
|
||||
VITE_API_URL = http://localhost:8888/
|
||||
VITE_API_URL = http://www.linxyun.com
|
@ -2,4 +2,4 @@
|
||||
ENV = production
|
||||
|
||||
# 线上环境接口地址
|
||||
VITE_API_URL = https://lyt-top.gitee.io/vue-next-admin-preview/
|
||||
VITE_API_URL = http://www.linxyun.com/
|
79
src/api/linxyun/base/index.ts
Normal file
79
src/api/linxyun/base/index.ts
Normal file
@ -0,0 +1,79 @@
|
||||
import request from '/@/utils/request';
|
||||
import request_out from '/@/utils/request_outside';
|
||||
import { getApiUrl } from '/@/api/linxyun/linxyunapi';
|
||||
import { AxiosRequestHeaders } from 'axios';
|
||||
interface IResp {
|
||||
code: string;
|
||||
success: boolean;
|
||||
msg: string;
|
||||
Records?: any;
|
||||
TotalSize?: string;
|
||||
RowCnt?: string;
|
||||
data?: any;
|
||||
}
|
||||
export function httpRequestApi() {
|
||||
return {
|
||||
Post: (uriName: string, params?: object, data?: object, header?: AxiosRequestHeaders): Promise<IResp> => {
|
||||
let url = getApiUrl(uriName);
|
||||
return request<IResp>({
|
||||
url: url,
|
||||
method: 'post',
|
||||
data: data,
|
||||
params: params,
|
||||
headers: header ?? {},
|
||||
}).then((response) => response.data); // 返回响应中的 data
|
||||
},
|
||||
Get: (uriName: string, params: object): Promise<IResp> => {
|
||||
let url = getApiUrl(uriName);
|
||||
return request<IResp>({
|
||||
url: url,
|
||||
method: 'get',
|
||||
params: params,
|
||||
}).then((response) => response.data); // 返回响应中的 data
|
||||
},
|
||||
SyncPost: async (
|
||||
uriName: string,
|
||||
params: object = {},
|
||||
data: object = {},
|
||||
headers: AxiosRequestHeaders = {} as AxiosRequestHeaders // 类型断言
|
||||
): Promise<IResp> => {
|
||||
let url = getApiUrl(uriName);
|
||||
const response = await request<IResp>({
|
||||
url: url,
|
||||
method: 'post',
|
||||
data: data,
|
||||
params: params,
|
||||
headers,
|
||||
});
|
||||
return response.data; // 返回响应中的 data
|
||||
},
|
||||
|
||||
SyncGet: async (uriName: string, params: object): Promise<IResp> => {
|
||||
let url = getApiUrl(uriName);
|
||||
const response = await request<IResp>({
|
||||
url: url,
|
||||
method: 'get',
|
||||
params: params,
|
||||
});
|
||||
return response.data; // 返回响应中的 data
|
||||
},
|
||||
SyncPostOutside: async (url: string, params: object, data: object, onUploadProgress = () => {}) => {
|
||||
const response = await request_out({
|
||||
url: url,
|
||||
method: 'post',
|
||||
data: data,
|
||||
params: params,
|
||||
onUploadProgress,
|
||||
});
|
||||
return response.data; // 返回响应中的 data
|
||||
},
|
||||
SyncGetOutside: async (url: string, params: object) => {
|
||||
const response = await request_out({
|
||||
url: url,
|
||||
method: 'get',
|
||||
params: params,
|
||||
});
|
||||
return response.data; // 返回响应中的 data
|
||||
},
|
||||
};
|
||||
}
|
48
src/api/linxyun/center.js
Normal file
48
src/api/linxyun/center.js
Normal file
@ -0,0 +1,48 @@
|
||||
import request from '/@/utils/request';
|
||||
|
||||
export function queryProjectUserInfoq(params) {
|
||||
return request({
|
||||
url: '/eslithe/queryProjectUserInfoq.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function queryEnterprise(params) {
|
||||
return request({
|
||||
url: '/eslithe/queryEnterprise.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function queryHaveEnterprise(params) {
|
||||
return request({
|
||||
url: '/eslithe/queryHaveEnterprise.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
export function updateUserPasswd(params) {
|
||||
return request({
|
||||
url: '/eslithe/updateUserPasswd.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function ResetUserPasswdReq(params) {
|
||||
return request({
|
||||
url: '/eslithe/ResetUserPasswdReq.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function BeginResetUserPasswdReq(params) {
|
||||
return request({
|
||||
url: '/eslithe/BeginResetUserPasswdReq.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
30
src/api/linxyun/linxyunapi.ts
Normal file
30
src/api/linxyun/linxyunapi.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import {BASE_API} from '/@/config.js'
|
||||
const apiUrl = new Map<string, string>();
|
||||
// apiurl.set('queryEnumOptions', '/eslithe/queryEnumOptionsNew.action');
|
||||
// apiurl.set('addEnumOptions', '/eslithe/add_dev_enum_options.action');
|
||||
// apiurl.set('updateEnumOptions', '/eslithe/update_dev_enum_options.action');
|
||||
// apiurl.set('delEnumOptions', '/eslithe/delete_dev_enum_options.action');
|
||||
|
||||
// apiName: url/uri/api name
|
||||
export function getApiUrl(apiName: string) {
|
||||
let url = '';
|
||||
if (apiName.indexOf('http') === 0) {
|
||||
// 全量Url
|
||||
url = apiName;
|
||||
} else {
|
||||
let uri = '';
|
||||
if (apiName.indexOf('/') === 0) {
|
||||
//全量URI
|
||||
uri = apiName;
|
||||
} else {
|
||||
uri = apiUrl.get(apiName);
|
||||
if (uri) {
|
||||
uri = BASE_API.URL_PRE + uri;
|
||||
} else {
|
||||
uri = BASE_API.URL_PRE + BASE_API.PROJECT_URI + '/' + apiName + '.action';
|
||||
}
|
||||
}
|
||||
url = BASE_API.SERVER_IP + uri;
|
||||
}
|
||||
return url;
|
||||
}
|
275
src/api/linxyun/user.js
Normal file
275
src/api/linxyun/user.js
Normal file
@ -0,0 +1,275 @@
|
||||
import request from '/@/utils/request';
|
||||
const API_URL_PRE = import.meta.env.VITE_API_URL
|
||||
export function login(data) {
|
||||
const param = {};
|
||||
param.UserID = data.username;
|
||||
param.Passwd = data.password;
|
||||
param.CustomerType = 1;
|
||||
return request({
|
||||
url: API_URL_PRE + '/login.action',
|
||||
method: 'post',
|
||||
data: param,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取林栖云平台账户信息
|
||||
* @param {} token
|
||||
* @returns
|
||||
*/
|
||||
export function getInfo(token) {
|
||||
return request({
|
||||
url: API_URL_PRE + '/info',
|
||||
method: 'get',
|
||||
params: { token },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @returns
|
||||
*/
|
||||
export function logout() {
|
||||
return request({
|
||||
url: API_URL_PRE + '/logout.action',
|
||||
method: 'post',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户菜单权限
|
||||
* @returns
|
||||
*/
|
||||
export function getMenuPermissions() {
|
||||
const data = {};
|
||||
data.current = 1;
|
||||
data.limit = 400;
|
||||
return request({
|
||||
url: API_URL_PRE + '/userMenu.action',
|
||||
method: 'get',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限
|
||||
* @returns
|
||||
*/
|
||||
export function getBtnPermissions() {
|
||||
const data = {};
|
||||
data.current = 1;
|
||||
data.limit = 400;
|
||||
return request({
|
||||
url: API_URL_PRE + '/userButton.action',
|
||||
method: 'get',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 根据用户ID获取平台用户信息
|
||||
* @param {UserID} params
|
||||
* @returns
|
||||
* */
|
||||
export function queryUserInfo(data) {
|
||||
return request({
|
||||
url: API_URL_PRE + '/queryUserInfo.action',
|
||||
method: 'post',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 增加平台登录用户
|
||||
* @param {User} params
|
||||
* @returns
|
||||
* */
|
||||
export function addUserAccount(data) {
|
||||
return request({
|
||||
url: API_URL_PRE + '/addUserAccount.action',
|
||||
method: 'post',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
|
||||
export function QueryEnterpriseMember(params) {
|
||||
return request({
|
||||
url: '/eslithe/QueryEnterpriseMember.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function QueryProjecRole(params) {
|
||||
return request({
|
||||
url: '/eslithe/QueryProjecRole.action',
|
||||
method: 'post',
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function QueryProjectMember(params) {
|
||||
return request({
|
||||
url: '/eslithe/QueryProjectMember.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function AddProjectMember(params) {
|
||||
return request({
|
||||
url: '/eslithe/AddProjectMember.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function BatchAddProjectMember(params) {
|
||||
return request({
|
||||
url: '/eslithe/BatchAddProjectMember.action',
|
||||
method: 'post',
|
||||
data: { Records: params },
|
||||
});
|
||||
}
|
||||
|
||||
export function updateProjectMember(params) {
|
||||
return request({
|
||||
url: '/eslithe/updateProjectMember.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteProjectMember(params) {
|
||||
return request({
|
||||
url: '/eslithe/deleteProjectMember.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function updateUserInfo(params) {
|
||||
return request({
|
||||
url: '/eslithe/updateUserInfo.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function updateUserEnterpriseInfo(params) {
|
||||
return request({
|
||||
url: '/eslithe/updateUserEnterpriseInfo.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteUserBelong(params) {
|
||||
return request({
|
||||
url: '/eslithe/deleteUserBelong.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @param {User} data
|
||||
* @returns
|
||||
*/
|
||||
export function updateUserInfoSelf(data) {
|
||||
return request({
|
||||
url: API_URL_PRE + '/updateUserInfoSelf.action',
|
||||
method: 'post',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新平台用户信息
|
||||
* @param {User} data
|
||||
* @returns
|
||||
*/
|
||||
export function updateUserInfomation(data) {
|
||||
return request({
|
||||
url: API_URL_PRE + '/updateUserInfomation.action',
|
||||
method: 'post',
|
||||
params: data,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统角色信息
|
||||
* @param
|
||||
* @returns
|
||||
*/
|
||||
export function queryRoles() {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/queryRoles.action`,
|
||||
method: 'post',
|
||||
});
|
||||
}
|
||||
|
||||
export function queryRole(params) {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/queryRole.action`,
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function addRole(params) {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/addRole.action`,
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function updateRole(params) {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/updateRole.action`,
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteRole(params) {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/deleteRole.action`,
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function queryRoleFunc(params) {
|
||||
return request({
|
||||
url: '/role/queryRoleFunc.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function queryFuncTree(params) {
|
||||
return request({
|
||||
url: '/eslithe/queryFuncTree.action',
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function delAllRoleFunc(params) {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/delAllRoleFunc.action`,
|
||||
method: 'post',
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
export async function addRoleFuncList(params, data) {
|
||||
return request({
|
||||
url: `/${localStorage.getItem('projectCode')}/addRoleFuncList.action`,
|
||||
method: 'post',
|
||||
data: data,
|
||||
params: params,
|
||||
});
|
||||
}
|
65
src/config.js
Normal file
65
src/config.js
Normal file
@ -0,0 +1,65 @@
|
||||
var BASE_URL = ''
|
||||
var BASE_API = null
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
BASE_API = {
|
||||
SERVER_IP: 'http://www.linxyun.com',
|
||||
// SERVER_IP: 'http://121.229.160.133:8088',
|
||||
GetFileConfigUrl: '/smartroadlamp/genFileConfig.action',
|
||||
// 部署时是否要加前缀,后端API地址需要统计加上这串,当部署不需要时,该串配置成空串就可以
|
||||
URL_PRE: '',
|
||||
// 显示的项目名称
|
||||
PROJECT_NAME: '智慧路灯',
|
||||
PROJECT_URI: '/smartroadlamp',
|
||||
ContainCustmerID: '0',
|
||||
CustomerType: 1,
|
||||
// 项目ID
|
||||
ENT_CODE: '56',
|
||||
SubSysID: '2',
|
||||
// 提示消息显示时长
|
||||
MSG_SHOW_TIME: 3000,
|
||||
IS_TEST: false,
|
||||
// 是否开启国际化
|
||||
I18N: false,
|
||||
// 管理员角色编码
|
||||
MANAGER_ROLE: '2101'
|
||||
}
|
||||
BASE_URL = BASE_API.SERVER_IP + BASE_API.URL_PRE + BASE_API.PROJECT_URI // qe环境
|
||||
// BASE_URL = 'http://dev.linxyun.com:8080'
|
||||
// BASE_URL = 'http://42.192.98.233:8080/usercenter' // qe环境
|
||||
} else {
|
||||
BASE_API = {
|
||||
SERVER_IP: 'http://www.linxyun.com',
|
||||
GetFileConfigUrl: '/smartroadlamp/genFileConfig.action',
|
||||
// 部署时是否要加前缀,后端API地址需要统计加上这串,当部署不需要时,该串配置成空串就可以
|
||||
URL_PRE: '',
|
||||
// 显示的项目名称
|
||||
PROJECT_NAME: '智慧路灯',
|
||||
PROJECT_URI: '/smartroadlamp',
|
||||
ContainCustmerID: '0',
|
||||
CustomerType: 1,
|
||||
// 项目ID
|
||||
ENT_CODE: '56',
|
||||
SubSysID: '2',
|
||||
// 提示消息显示时长
|
||||
MSG_SHOW_TIME: 3000,
|
||||
IS_TEST: false,
|
||||
// 是否开启国际化
|
||||
I18N: false,
|
||||
// 管理员角色编码
|
||||
MANAGER_ROLE: '2100'
|
||||
}
|
||||
BASE_URL = BASE_API.SERVER_IP + BASE_API.URL_PRE + BASE_API.PROJECT_URI // 生产环境
|
||||
// BASE_URL = 'http://dev.linxyun.com:8080'
|
||||
}
|
||||
//http://dev.linxyun.com:8080
|
||||
const config = {
|
||||
base_url: BASE_API.SERVER_IP + BASE_API.URL_PRE,
|
||||
project_url: BASE_API.URL_PRE + BASE_API.PROJECT_URI,
|
||||
project_pre: BASE_API.URL_PRE,
|
||||
server_addr: BASE_API.SERVER_IP,
|
||||
ent_code: BASE_API.ENT_CODE,
|
||||
msg_show_time: BASE_API.MSG_SHOW_TIME,
|
||||
sub_sys_id: BASE_API.SubSysID
|
||||
}
|
||||
|
||||
export { config, BASE_API }
|
41
src/main.ts
41
src/main.ts
@ -5,10 +5,11 @@ import router from '/@/router';
|
||||
import { directive } from '/@/directive/index';
|
||||
import { i18n } from '/@/i18n/index';
|
||||
import other from '/@/utils/other';
|
||||
|
||||
import { useErrorInfo } from '/@/stores/errorInfo';
|
||||
import ElementPlus from 'element-plus';
|
||||
import '/@/theme/index.scss';
|
||||
import VueGridLayout from 'vue-grid-layout';
|
||||
import mitt from 'mitt';
|
||||
// import zhCN from "element-plus/dist/locale/zh-cn.mjs" //引入中文
|
||||
const app = createApp(App);
|
||||
|
||||
@ -16,3 +17,41 @@ directive(app);
|
||||
other.elSvg(app);
|
||||
|
||||
app.use(pinia).use(router).use(ElementPlus).use(i18n).use(VueGridLayout).mount('#app');
|
||||
|
||||
app.config.globalProperties.mittBus = mitt();
|
||||
app.config.errorHandler = (err, vm, info) => {
|
||||
console.error('[全局异常]', err, vm, info);
|
||||
};
|
||||
// 初始化错误码信息
|
||||
let errInfo = new Map<string, string>();
|
||||
errInfo.set('1006', '用户不存在或密码不匹配');
|
||||
errInfo.set('204', '参数错误');
|
||||
errInfo.set('240', 'URI不存在')
|
||||
errInfo.set('241', 'URI已经存在')
|
||||
errInfo.set('200', '参数错误');
|
||||
errInfo.set('320', '服务的路由异常,请联系管理员');
|
||||
errInfo.set('998', '处理超时,服务配置出错,请联系管理员');
|
||||
errInfo.set('9998', '登录超时,请重新登录');
|
||||
errInfo.set('401', '登录超时,请重新登录');
|
||||
errInfo.set('1005', '操作失败');
|
||||
errInfo.set('1007', '用户已经存在');
|
||||
errInfo.set('1008', '操作ID配置错误,请联系管理员');
|
||||
errInfo.set('1009', '用户ID参数错误');
|
||||
errInfo.set('1010', '用户不存在或密码不匹配');
|
||||
errInfo.set('1011', '用户邮箱地址错误');
|
||||
errInfo.set('1012', '邮箱地址已经存在');
|
||||
errInfo.set('1013', '手机号码格式不正确');
|
||||
errInfo.set('1014', '手机号码已经存在');
|
||||
errInfo.set('1020', '登录验证出错');
|
||||
errInfo.set('1021', '用户没有登录');
|
||||
errInfo.set('1022', '用户状态不正常');
|
||||
errInfo.set('1023', '发送验证码失败');
|
||||
errInfo.set('1024', '验证码验证失败');
|
||||
errInfo.set('1030', '用户组已经存在');
|
||||
errInfo.set('1031', '用户组不经存在');
|
||||
errInfo.set('1999', '操作出错');
|
||||
errInfo.set('886000', '前端处理验证数据出错');
|
||||
errInfo.set('2012','请先删除内容')
|
||||
const storesErrorInfo = useErrorInfo();
|
||||
// const { errorInfo } = storeToRefs(storesErrorInfo);
|
||||
storesErrorInfo.setErrorInfo(errInfo);
|
29
src/stores/errorInfo.ts
Normal file
29
src/stores/errorInfo.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ErrorInfoStates } from './interface';
|
||||
|
||||
/**
|
||||
* 路由缓存列表
|
||||
* @methods setCacheKeepAlive 设置要缓存的路由 names(开启 Tagsview)
|
||||
* @methods addCachedView 添加要缓存的路由 names(关闭 Tagsview)
|
||||
* @methods delCachedView 删除要缓存的路由 names(关闭 Tagsview)
|
||||
* @methods delOthersCachedViews 右键菜单`关闭其它`,删除要缓存的路由 names(关闭 Tagsview)
|
||||
* @methods delAllCachedViews 右键菜单`全部关闭`,删除要缓存的路由 names(关闭 Tagsview)
|
||||
*/
|
||||
export const useErrorInfo = defineStore('errorInfo', {
|
||||
state: (): ErrorInfoStates => ({
|
||||
errorInfo: new Map<string, string>()
|
||||
}),
|
||||
actions: {
|
||||
async setErrorInfo(data: Map<string, string>) {
|
||||
this.errorInfo = data;
|
||||
},
|
||||
async addErrorInfo(code: string, msg: string) {
|
||||
this.errorInfo.set(code, msg);
|
||||
},
|
||||
async delErrorInfo(code: string) {
|
||||
const msg = this.errorInfo.get(code);
|
||||
this.errorInfo.delete(code);
|
||||
return msg;
|
||||
}
|
||||
},
|
||||
});
|
115
src/stores/interface/index.ts
Normal file
115
src/stores/interface/index.ts
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 定义接口来定义对象的类型
|
||||
* `stores` 全部类型定义在这里
|
||||
*/
|
||||
|
||||
// 用户信息
|
||||
export interface UserInfosState {
|
||||
CustomerID: string;
|
||||
CustomerType: string;
|
||||
EntCode: string;
|
||||
Extend: string;
|
||||
LoginID: string;
|
||||
Token: string;
|
||||
UserID: string;
|
||||
UserRoles: string[];
|
||||
UserType: string;
|
||||
UnitID: string;
|
||||
authBtnList: string[];
|
||||
photo: string;
|
||||
roles: string[];
|
||||
time: number;
|
||||
UserName: string;
|
||||
}
|
||||
export interface UserInfosStates {
|
||||
userInfos: UserInfosState | null;
|
||||
}
|
||||
|
||||
// 路由缓存列表
|
||||
export interface KeepAliveNamesState {
|
||||
keepAliveNames: string[];
|
||||
cachedViews: string[];
|
||||
}
|
||||
|
||||
// 后端返回原始路由(未处理时)
|
||||
export interface RequestOldRoutesState {
|
||||
requestOldRoutes: string[];
|
||||
}
|
||||
|
||||
// TagsView 路由列表
|
||||
export interface TagsViewRoutesState {
|
||||
tagsViewRoutes: string[];
|
||||
isTagsViewCurrenFull: Boolean;
|
||||
}
|
||||
|
||||
// 路由列表
|
||||
export interface RoutesListState {
|
||||
routesList: string[];
|
||||
isColumnsMenuHover: Boolean;
|
||||
isColumnsNavHover: Boolean;
|
||||
currentRouteChildRoutesList: Array<Record<string, any>>;
|
||||
}
|
||||
|
||||
// 布局配置
|
||||
export interface ThemeConfigState {
|
||||
isDrawer: boolean;
|
||||
primary: string;
|
||||
topBar: string;
|
||||
topBarColor: string;
|
||||
isTopBarColorGradual: boolean;
|
||||
menuBar: string;
|
||||
menuBarColor: string;
|
||||
isMenuBarColorGradual: boolean;
|
||||
columnsMenuBar: string;
|
||||
columnsMenuBarColor: string;
|
||||
isColumnsMenuBarColorGradual: boolean;
|
||||
isCollapse: boolean;
|
||||
isUniqueOpened: boolean;
|
||||
isFixedHeader: boolean;
|
||||
isFixedHeaderChange: boolean;
|
||||
isClassicSplitMenu: boolean;
|
||||
isLockScreen: boolean;
|
||||
lockScreenTime: number;
|
||||
isShowLogo: boolean;
|
||||
isShowLogoChange: boolean;
|
||||
isBreadcrumb: boolean;
|
||||
isTagsview: boolean;
|
||||
isBreadcrumbIcon: boolean;
|
||||
isTagsviewIcon: boolean;
|
||||
isCacheTagsView: boolean;
|
||||
isSortableTagsView: boolean;
|
||||
isShareTagsView: boolean;
|
||||
isFooter: boolean;
|
||||
isGrayscale: boolean;
|
||||
isInvert: boolean;
|
||||
isIsDark: boolean;
|
||||
isWartermark: boolean;
|
||||
wartermarkText: string;
|
||||
tagsStyle: string;
|
||||
animation: string;
|
||||
columnsAsideStyle: string;
|
||||
columnsAsideLayout: string;
|
||||
layout: string;
|
||||
isRequestRoutes: boolean;
|
||||
globalTitle: string;
|
||||
globalViceTitle: string;
|
||||
globalI18n: string;
|
||||
globalComponentSize: string;
|
||||
}
|
||||
export interface ThemeConfigStates {
|
||||
themeConfig: ThemeConfigState;
|
||||
}
|
||||
|
||||
export interface ErrorInfoStates {
|
||||
errorInfo: Map<string, string>;
|
||||
}
|
||||
|
||||
export interface WebsiteState {
|
||||
SiteID: string;
|
||||
CustomerID: string;
|
||||
EntCode: string;
|
||||
}
|
||||
|
||||
export interface WebsiteStates {
|
||||
webSiteInfo: WebsiteState;
|
||||
}
|
10
src/stores/interface/objectDesjgn.ts
Normal file
10
src/stores/interface/objectDesjgn.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export interface ICurrentTableInfo {
|
||||
TabName: string;
|
||||
Alias: string;
|
||||
Remarks: string;
|
||||
EntCode: string | number;
|
||||
}
|
||||
|
||||
export interface IObjectDesjgn {
|
||||
currentTableInfo: ICurrentTableInfo;
|
||||
}
|
@ -1,15 +1,30 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import Cookies from 'js-cookie';
|
||||
import { UserInfosStates, UserInfosState, WebsiteState } from './interface';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { useWebSite } from '/@/stores/websiteState';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { httpRequestApi } from '/@/api/linxyun/base';
|
||||
|
||||
const httpRequest = httpRequestApi();
|
||||
/**
|
||||
* 用户信息
|
||||
* @methods setUserInfos 设置用户信息
|
||||
*/
|
||||
export const useUserInfo = defineStore('userInfo', {
|
||||
state: (): UserInfosState => ({
|
||||
state: (): UserInfosStates => ({
|
||||
userInfos: {
|
||||
userName: '',
|
||||
CustomerID: '',
|
||||
CustomerType: '',
|
||||
EntCode: '',
|
||||
UserName: '',
|
||||
LoginID: '',
|
||||
Extend: '',
|
||||
Token: '',
|
||||
UserID: '',
|
||||
UnitID: '',
|
||||
UserRoles: [],
|
||||
UserType: '',
|
||||
photo: '',
|
||||
time: 0,
|
||||
roles: [],
|
||||
@ -17,56 +32,110 @@ export const useUserInfo = defineStore('userInfo', {
|
||||
},
|
||||
}),
|
||||
actions: {
|
||||
async setUserInfos() {
|
||||
async setUserInfos(loginUser: UserInfosState | null) {
|
||||
if (loginUser) {
|
||||
this.userInfos = loginUser;
|
||||
} else if (Session.get('userInfo')) {
|
||||
this.userInfos = Session.get('userInfo');
|
||||
}
|
||||
// 存储用户信息到浏览器缓存
|
||||
if (Session.get('userInfo')) {
|
||||
this.userInfos = Session.get('userInfo');
|
||||
} else {
|
||||
const userInfos = <UserInfos>await this.getApiUserInfo();
|
||||
this.userInfos = userInfos;
|
||||
// 从本地存储中还原
|
||||
try {
|
||||
const user_loc = localStorage.getItem('user');
|
||||
if (user_loc && user_loc.length > 0) {
|
||||
const userInfos: any = JSON.parse(user_loc);
|
||||
this.userInfos = userInfos;
|
||||
} else {
|
||||
this.userInfos = null;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('read userinfo from local store exception!', e);
|
||||
this.userInfos = null;
|
||||
}
|
||||
}
|
||||
return this.userInfos;
|
||||
},
|
||||
// 模拟接口数据
|
||||
// https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP
|
||||
async getApiUserInfo() {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
// 模拟数据,请求接口时,记得删除多余代码及对应依赖的引入
|
||||
const userName = Cookies.get('userName');
|
||||
// 模拟数据
|
||||
let defaultRoles: Array<string> = [];
|
||||
let defaultAuthBtnList: Array<string> = [];
|
||||
// admin 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
||||
let adminRoles: Array<string> = ['admin'];
|
||||
// admin 按钮权限标识
|
||||
let adminAuthBtnList: Array<string> = ['btn.add', 'btn.del', 'btn.edit', 'btn.link'];
|
||||
// test 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
||||
let testRoles: Array<string> = ['common'];
|
||||
// test 按钮权限标识
|
||||
let testAuthBtnList: Array<string> = ['btn.add', 'btn.link'];
|
||||
// 不同用户模拟不同的用户权限
|
||||
if (userName === 'admin') {
|
||||
defaultRoles = adminRoles;
|
||||
defaultAuthBtnList = adminAuthBtnList;
|
||||
} else {
|
||||
defaultRoles = testRoles;
|
||||
defaultAuthBtnList = testAuthBtnList;
|
||||
async getApiUserInfo(loginUser: any) {
|
||||
const resp = await httpRequest.SyncPost('login', {}, loginUser);
|
||||
// const resp = await httpRequest.SyncPost('/eslithe/linxyunLogin.action', {}, loginUser);
|
||||
console.log('wwwwwwwwwwww', resp);
|
||||
const user = resp.data;
|
||||
if (!user) {
|
||||
ElMessage.error('账户或密码错误!');
|
||||
Promise.reject();
|
||||
return null;
|
||||
}
|
||||
if (user.code === '1010') {
|
||||
ElMessage.error('账户或密码错误!');
|
||||
Promise.reject();
|
||||
return null;
|
||||
} else if (user.code === '1006') {
|
||||
ElMessage.error('账户不存在或身份有误!');
|
||||
Promise.reject();
|
||||
return null;
|
||||
} else {
|
||||
Cookies.set('UserName', user.UserName);
|
||||
Session.set('token', user.Token);
|
||||
let UnitID = ''
|
||||
const Extend = user.Extend
|
||||
console.log('Extend', Extend)
|
||||
if (Extend) {
|
||||
console.log('Extend', Extend)
|
||||
const userExtends: string[] = Extend.split("=")
|
||||
console.log('userExtends', userExtends)
|
||||
if (userExtends.length >=2) {
|
||||
UnitID = userExtends[1]
|
||||
}
|
||||
// 用户信息模拟数据
|
||||
const userInfos = {
|
||||
userName: userName,
|
||||
photo:
|
||||
userName === 'admin'
|
||||
? 'https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500'
|
||||
: 'https://img2.baidu.com/it/u=2370931438,70387529&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
|
||||
time: new Date().getTime(),
|
||||
roles: defaultRoles,
|
||||
authBtnList: defaultAuthBtnList,
|
||||
};
|
||||
Session.set('userInfo', userInfos);
|
||||
resolve(userInfos);
|
||||
}, 0);
|
||||
});
|
||||
console.log('userExtends UnitID: ', UnitID)
|
||||
}
|
||||
|
||||
// admin 页面权限标识,对应路由 meta.roles,用于控制路由的显示/隐藏
|
||||
// admin 按钮权限标识
|
||||
let adminAuthBtnList: Array<string> = ['btn.add', 'btn.del', 'btn.edit', 'btn.link'];
|
||||
// 用户信息模拟数据
|
||||
const userInfos: UserInfosState = {
|
||||
UserID: user.UserID as string,
|
||||
UserName: user.UserName as string,
|
||||
CustomerID: user.CustomerID as string,
|
||||
CustomerType: user.CustomerType as string,
|
||||
EntCode: user.EntCode as string,
|
||||
LoginID: user.LoginID as string,
|
||||
Extend: user.Extend as string,
|
||||
Token: user.Token as string,
|
||||
UnitID: UnitID as string,
|
||||
UserRoles: user.UserRoles as Array<string>,
|
||||
UserType: user.UserType as string,
|
||||
photo: 'https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500',
|
||||
time: new Date().getTime(),
|
||||
roles: ['admin'],
|
||||
authBtnList: adminAuthBtnList,
|
||||
};
|
||||
window.localStorage.setItem('user', JSON.stringify(userInfos));
|
||||
window.localStorage.setItem('name', user.UserName);
|
||||
window.localStorage.setItem('userType', user.UserType);
|
||||
window.localStorage.setItem('enterpriseID', user.CustomerID);
|
||||
this.setUserInfos(userInfos);
|
||||
const website: WebsiteState = { EntCode: '50', CustomerID: '0', SiteID: '24' };
|
||||
const storesWebsite = useWebSite();
|
||||
await storesWebsite.setWebSite(website);
|
||||
|
||||
return userInfos;
|
||||
}
|
||||
},
|
||||
async frontLogout() {
|
||||
window.localStorage.removeItem('user');
|
||||
window.localStorage.removeItem('name');
|
||||
window.localStorage.removeItem('userType');
|
||||
window.localStorage.removeItem('enterpriseID');
|
||||
await this.setUserInfos(null);
|
||||
Cookies.set('UserName', '');
|
||||
Cookies.set('token', '');
|
||||
Session.set('UserName', '');
|
||||
Session.set('token', '');
|
||||
},
|
||||
},
|
||||
});
|
||||
|
42
src/stores/websiteState.ts
Normal file
42
src/stores/websiteState.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import Cookies from 'js-cookie';
|
||||
import { WebsiteState, WebsiteStates } from './interface';
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
* @methods setWebInfos 设置用户信息
|
||||
*/
|
||||
export const useWebSite = defineStore('webSite', {
|
||||
state: (): WebsiteStates => ({
|
||||
webSiteInfo: {
|
||||
CustomerID: '',
|
||||
EntCode: '',
|
||||
SiteID: '',
|
||||
},
|
||||
}),
|
||||
actions: {
|
||||
async setWebSite(data: WebsiteState | null) {
|
||||
if (data == null) {
|
||||
this.webSiteInfo = { CustomerID: '', EntCode: '', SiteID: '' };
|
||||
Cookies.removeItem('Website');
|
||||
localStorage.removeItem('Website');
|
||||
} else {
|
||||
this.webSiteInfo = data;
|
||||
Cookies.set('Website', this.webSiteInfo);
|
||||
localStorage.setItem('Website', JSON.stringify(data));
|
||||
}
|
||||
},
|
||||
|
||||
async getWebSite() {
|
||||
if (!this.webSiteInfo || !this.webSiteInfo.SiteID) {
|
||||
const websiteLoc = localStorage.getItem('Website');
|
||||
if (websiteLoc) {
|
||||
const website: any = JSON.parse(websiteLoc);
|
||||
this.webSiteInfo = website;
|
||||
}
|
||||
}
|
||||
|
||||
return this.webSiteInfo;
|
||||
},
|
||||
},
|
||||
});
|
@ -1,67 +1,198 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import axios from 'axios';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import qs from 'qs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useErrorInfo } from '/@/stores/errorInfo';
|
||||
import { UserInfosState } from '/@/stores/interface';
|
||||
import {BASE_API} from '/@/config.js'
|
||||
|
||||
|
||||
// 配置新建一个 axios 实例
|
||||
const service: AxiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL,
|
||||
axios.defaults.timeout = 50000;
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL as any,
|
||||
timeout: 50000,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
paramsSerializer: {
|
||||
serialize(params) {
|
||||
return qs.stringify(params, { allowDots: true });
|
||||
},
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
|
||||
});
|
||||
|
||||
// 添加请求拦截器
|
||||
let loadingNum = 0;
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 在发送请求之前做些什么 token
|
||||
if (Session.get('token')) {
|
||||
config.headers!['Authorization'] = `${Session.get('token')}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
(config) => {
|
||||
// 处理 token 头部
|
||||
const token = Session.get('token');
|
||||
if (token) {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
Authorization: token,
|
||||
Token: token,
|
||||
};
|
||||
}
|
||||
|
||||
// 处理 dde-sa 自定义头部
|
||||
const data = typeof config.data === 'string' ? JSON.parse(config.data) : config.data;
|
||||
if (data?.ddesa) {
|
||||
config.headers['dde-sa'] = data.ddesa;
|
||||
} else {
|
||||
delete config.headers['dde-sa'];
|
||||
}
|
||||
|
||||
// POST 请求空数据处理
|
||||
if (config.method === 'post' && (config.data === null || config.data === 'null')) {
|
||||
delete config.data;
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
console.error('Request Interceptor Error: ', error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 添加响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
// 对响应数据做点什么
|
||||
console.log('responseresponse', response, loadingNum);
|
||||
// loadingNum--;
|
||||
// if (loadingNum === 0) {
|
||||
// setTimeout(() => {
|
||||
// NextLoading.done();
|
||||
// }, 500);
|
||||
// }
|
||||
const res = response.data;
|
||||
if (res.code && res.code !== 0) {
|
||||
// `token` 过期或者账号已在别处登录
|
||||
if (res.code === 401 || res.code === 4001) {
|
||||
Session.clear(); // 清除浏览器全部临时缓存
|
||||
window.location.href = '/'; // 去登录页
|
||||
ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
}
|
||||
const storesErrorInfo = useErrorInfo();
|
||||
const { errorInfo } = storeToRefs(storesErrorInfo);
|
||||
if (res.code === '9998' || res.code === '1021') {
|
||||
ElMessage({
|
||||
message: '登录超时,请重新登录!',
|
||||
type: 'error',
|
||||
duration: BASE_API.MSG_SHOW_TIME,
|
||||
});
|
||||
Session.clear();
|
||||
const storeuser = useUserInfo();
|
||||
storeuser.setUserInfos({} as UserInfosState);
|
||||
window.location.href = '/'; // 去登录页
|
||||
|
||||
return Promise.reject(service.interceptors.response);
|
||||
} else {
|
||||
return res;
|
||||
let msg = '操作出错,请稍侯再试';
|
||||
if (res.code === undefined || res.code === null || res.code === '' || res.code !== '0000') {
|
||||
if (res.code === 0) {
|
||||
return response.data;
|
||||
}
|
||||
msg = errorInfo.value.get(res.code) as string;
|
||||
if (msg === undefined || msg === null || msg === '') {
|
||||
msg = '操作出错,请稍侯再试';
|
||||
}
|
||||
if (res.code !== undefined && res.code !== null) {
|
||||
msg = res.code + '-' + msg;
|
||||
}
|
||||
|
||||
ElMessage({
|
||||
message: msg,
|
||||
type: 'error',
|
||||
duration: BASE_API.MSG_SHOW_TIME,
|
||||
});
|
||||
return Promise.reject('error');
|
||||
}
|
||||
}
|
||||
return handleResponse(res);
|
||||
},
|
||||
(error) => {
|
||||
// 对响应错误做点什么
|
||||
if (error.message.indexOf('timeout') != -1) {
|
||||
ElMessage.error('网络超时');
|
||||
} else if (error.message == 'Network Error') {
|
||||
ElMessage.error('网络连接错误');
|
||||
console.log(error);
|
||||
if (error.request.status === 401) {
|
||||
ElMessage({
|
||||
message: '登录超时,请重新登录!',
|
||||
type: 'error',
|
||||
duration: BASE_API.MSG_SHOW_TIME,
|
||||
});
|
||||
Session.clear();
|
||||
localStorage.clear();
|
||||
const storeuser = useUserInfo();
|
||||
storeuser.setUserInfos({} as UserInfosState);
|
||||
window.location.href = '/'; // 去登录页
|
||||
return Promise.reject(service.interceptors.response);
|
||||
}
|
||||
if (error.request.status === 404) {
|
||||
ElMessage({
|
||||
message: '没有找到服务',
|
||||
type: 'error',
|
||||
duration: BASE_API.MSG_SHOW_TIME,
|
||||
});
|
||||
// 退回到上一个页面。或者跳转到404页面
|
||||
// const router = useRouter();
|
||||
// router.go(-1);
|
||||
} else {
|
||||
if (error.response.data) ElMessage.error(error.response.statusText);
|
||||
else ElMessage.error('接口路径找不到');
|
||||
const storesErrorInfo = useErrorInfo();
|
||||
const { errorInfo } = storeToRefs(storesErrorInfo);
|
||||
let msg = errorInfo.value.get(error.request.status);
|
||||
if (msg === undefined || msg === null || msg === '') {
|
||||
msg = '操作出错,请稍侯再试';
|
||||
}
|
||||
ElMessage({
|
||||
message: error.request.status + '-' + msg,
|
||||
type: 'error',
|
||||
duration: 3000,
|
||||
});
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
interface IResp {
|
||||
code: string;
|
||||
success: boolean;
|
||||
msg: string;
|
||||
Records?: any;
|
||||
TotalSize?: string;
|
||||
RowCnt?: string;
|
||||
data?: any;
|
||||
}
|
||||
function handleResponse(res: any): IResp {
|
||||
// console.log('handleResponse res: ', res);
|
||||
if (res.data && isJsonString(res.data)) {
|
||||
const data = JSON.parse(res.data);
|
||||
// console.log('handleResponse:', data);
|
||||
if (data.Records || data.RowCnt) {
|
||||
return {
|
||||
...data,
|
||||
code: res.code,
|
||||
success: res.success,
|
||||
msg: res.msg,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
data: data,
|
||||
code: res.code,
|
||||
success: res.success,
|
||||
msg: res.msg,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
data: res.data,
|
||||
code: res.code,
|
||||
success: res.success,
|
||||
msg: res.msg,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function isJsonString(str: string) {
|
||||
if (typeof str === 'string') {
|
||||
try {
|
||||
var obj = JSON.parse(str);
|
||||
if (typeof obj === 'object' && obj) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出 axios 实例
|
||||
export default service;
|
||||
|
68
src/utils/request.ts.back
Normal file
68
src/utils/request.ts.back
Normal file
@ -0,0 +1,68 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import qs from 'qs';
|
||||
import {config} from '/@/config.js';
|
||||
|
||||
// 配置新建一个 axios 实例
|
||||
const service: AxiosInstance = axios.create({
|
||||
baseURL: config.base_url,
|
||||
timeout: 50000,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
paramsSerializer: {
|
||||
serialize(params) {
|
||||
return qs.stringify(params, { allowDots: true });
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// 添加请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 在发送请求之前做些什么 token
|
||||
if (Session.get('token')) {
|
||||
config.headers!['Authorization'] = `${Session.get('token')}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 添加响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
// 对响应数据做点什么
|
||||
const res = response.data;
|
||||
if (res.code && res.code !== 0) {
|
||||
// `token` 过期或者账号已在别处登录
|
||||
if (res.code === 401 || res.code === 4001) {
|
||||
Session.clear(); // 清除浏览器全部临时缓存
|
||||
window.location.href = '/'; // 去登录页
|
||||
ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
}
|
||||
return Promise.reject(service.interceptors.response);
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
// 对响应错误做点什么
|
||||
if (error.message.indexOf('timeout') != -1) {
|
||||
ElMessage.error('网络超时');
|
||||
} else if (error.message == 'Network Error') {
|
||||
ElMessage.error('网络连接错误');
|
||||
} else {
|
||||
if (error.response.data) ElMessage.error(error.response.statusText);
|
||||
else ElMessage.error('接口路径找不到');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 导出 axios 实例
|
||||
export default service;
|
61
src/utils/request_outside.ts
Normal file
61
src/utils/request_outside.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import axios from 'axios';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { Session } from '/@/utils/storage';
|
||||
|
||||
// 配置新建一个 axios 实例
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL as any,
|
||||
timeout: 50000,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
|
||||
// 添加请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 在发送请求之前做些什么 token
|
||||
if (Session.get('token')) {
|
||||
(<any>config.headers).common['Authorization'] = `${Session.get('token')}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 添加响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
// 对响应数据做点什么
|
||||
const res = response.data;
|
||||
if (res.code && res.code !== 0) {
|
||||
// `token` 过期或者账号已在别处登录
|
||||
if (res.code === 401 || res.code === 4001) {
|
||||
Session.clear(); // 清除浏览器全部临时缓存
|
||||
window.location.href = '/'; // 去登录页
|
||||
ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
}
|
||||
return Promise.reject(service.interceptors.response);
|
||||
} else {
|
||||
return response.data;
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
// 对响应错误做点什么
|
||||
if (error.message.indexOf('timeout') != -1) {
|
||||
ElMessage.error('网络超时');
|
||||
} else if (error.message == 'Network Error') {
|
||||
ElMessage.error('网络连接错误');
|
||||
} else {
|
||||
if (error.response.data) ElMessage.error(error.response.statusText);
|
||||
else ElMessage.error('接口路径找不到');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 导出 axios 实例
|
||||
export default service;
|
@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-form size="large" class="login-content-form">
|
||||
<el-form size="large" class="login-content-form" ref="ruleFormRef" :model="state.ruleForm" :rules="loginRules">
|
||||
<el-form-item class="login-animation1">
|
||||
<el-input text :placeholder="$t('message.account.accountPlaceholder1')" v-model="state.ruleForm.userName" clearable autocomplete="off">
|
||||
<el-input text :placeholder="$t('message.account.accountPlaceholder1')" v-model="state.ruleForm.UserID" clearable autocomplete="off">
|
||||
<template #prefix>
|
||||
<el-icon class="el-input__icon"><ele-User /></el-icon>
|
||||
</template>
|
||||
@ -11,7 +11,7 @@
|
||||
<el-input
|
||||
:type="state.isShowPassword ? 'text' : 'password'"
|
||||
:placeholder="$t('message.account.accountPlaceholder2')"
|
||||
v-model="state.ruleForm.password"
|
||||
v-model="state.ruleForm.Passwd"
|
||||
autocomplete="off"
|
||||
>
|
||||
<template #prefix>
|
||||
@ -27,7 +27,7 @@
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item class="login-animation3">
|
||||
<!-- <el-form-item class="login-animation3">
|
||||
<el-col :span="15">
|
||||
<el-input
|
||||
text
|
||||
@ -46,7 +46,7 @@
|
||||
<el-col :span="8">
|
||||
<el-button class="login-content-code" v-waves>1234</el-button>
|
||||
</el-col>
|
||||
</el-form-item>
|
||||
</el-form-item> -->
|
||||
<el-form-item class="login-animation4">
|
||||
<el-button type="primary" class="login-content-submit" round v-waves @click="onSignIn" :loading="state.loading.signIn">
|
||||
<span>{{ $t('message.account.accountBtnText') }}</span>
|
||||
@ -56,7 +56,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="loginAccount">
|
||||
import { reactive, computed } from 'vue';
|
||||
import { reactive, computed, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@ -68,24 +68,51 @@ import { initBackEndControlRoutes } from '/@/router/backEnd';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { formatAxis } from '/@/utils/formatTime';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
import { httpRequestApi } from '/@/api/linxyun/base';
|
||||
import type { FormInstance } from 'element-plus';
|
||||
|
||||
// 定义变量内容
|
||||
const { t } = useI18n();
|
||||
const http = httpRequestApi()
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const ruleFormRef = ref<FormInstance | null>(null);
|
||||
const userInfo = useUserInfo();
|
||||
const state = reactive({
|
||||
isShowPassword: false,
|
||||
ruleForm: {
|
||||
userName: 'admin',
|
||||
password: '123456',
|
||||
code: '1234',
|
||||
UserID: 'admin',
|
||||
Passwd: '123456',
|
||||
EntCode: 56,
|
||||
CustomerType: 1
|
||||
},
|
||||
loading: {
|
||||
signIn: false,
|
||||
},
|
||||
ifInvit: '0',
|
||||
invit: '',
|
||||
});
|
||||
const validateUsername = (rule: any, value: any, callback: any) => {
|
||||
if (!value) {
|
||||
callback(new Error(t('message.account.accountPlaceholder1')));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
const validatePassword = (rule: any, value: any, callback: any) => {
|
||||
if (value === undefined || value.length === 0) {
|
||||
callback(new Error(t('message.account.accountPlaceholder2')));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
const loginRules = {
|
||||
UserID: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
||||
Passwd: [{ required: true, trigger: 'blur', validator: validatePassword }],
|
||||
}
|
||||
|
||||
// 时间获取
|
||||
const currentTime = computed(() => {
|
||||
@ -93,48 +120,92 @@ const currentTime = computed(() => {
|
||||
});
|
||||
// 登录
|
||||
const onSignIn = async () => {
|
||||
state.loading.signIn = true;
|
||||
console.log('登录', ruleFormRef.value);
|
||||
|
||||
if (!ruleFormRef.value) return;
|
||||
ruleFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
state.loading.signIn = true;
|
||||
const loginUser = { UserID: state.ruleForm.UserID, Passwd: state.ruleForm.Passwd, CustomerType: state.ruleForm.CustomerType };
|
||||
userInfo
|
||||
// .getApiUserInfo(state.ruleForm)
|
||||
.getApiUserInfo(loginUser)
|
||||
.then(async () => {
|
||||
// LoginByUsername在store下面 备忘
|
||||
state.loading.signIn = false;
|
||||
localStorage.setItem('ObjectID', '1')
|
||||
// 存储 token 到浏览器缓存
|
||||
// Session.set('token', Math.random().toString(36).substr(0));
|
||||
// 模拟数据,对接接口时,记得删除多余代码及对应依赖的引入。用于 `/src/stores/userInfo.ts` 中不同用户登录判断(模拟数据)
|
||||
if (!themeConfig.value.isRequestRoutes) {
|
||||
// 前端控制路由,2、请注意执行顺序
|
||||
// Session.set('token', Math.random().toString(36).substr(0));
|
||||
// Cookies.set('UserID', state.ruleForm.UserID);
|
||||
await initFrontEndControlRoutes();
|
||||
state.loading.signIn = false;
|
||||
signInSuccess();
|
||||
} else {
|
||||
// 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
|
||||
// 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
||||
await initBackEndControlRoutes();
|
||||
// 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
||||
state.loading.signIn = false;
|
||||
signInSuccess();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
state.loading.signIn = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
// state.loading.signIn = true;
|
||||
// 存储 token 到浏览器缓存
|
||||
Session.set('token', Math.random().toString(36).substr(0));
|
||||
// Session.set('token', Math.random().toString(36).substr(0));
|
||||
// 模拟数据,对接接口时,记得删除多余代码及对应依赖的引入。用于 `/src/stores/userInfo.ts` 中不同用户登录判断(模拟数据)
|
||||
Cookies.set('userName', state.ruleForm.userName);
|
||||
if (!themeConfig.value.isRequestRoutes) {
|
||||
// 前端控制路由,2、请注意执行顺序
|
||||
const isNoPower = await initFrontEndControlRoutes();
|
||||
signInSuccess(isNoPower);
|
||||
} else {
|
||||
// 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
|
||||
// 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
||||
const isNoPower = await initBackEndControlRoutes();
|
||||
// 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
||||
signInSuccess(isNoPower);
|
||||
}
|
||||
// Cookies.set('userName', state.ruleForm.username);
|
||||
// if (!themeConfig.value.isRequestRoutes) {
|
||||
// // 前端控制路由,2、请注意执行顺序
|
||||
// const isNoPower = await initFrontEndControlRoutes();
|
||||
// signInSuccess(isNoPower);
|
||||
// } else {
|
||||
// // 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
|
||||
// // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
||||
// const isNoPower = await initBackEndControlRoutes();
|
||||
// // 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
||||
// signInSuccess(isNoPower);
|
||||
// }
|
||||
};
|
||||
// 登录成功后的跳转
|
||||
const signInSuccess = (isNoPower: boolean | undefined) => {
|
||||
if (isNoPower) {
|
||||
ElMessage.warning('抱歉,您没有登录权限');
|
||||
Session.clear();
|
||||
const signInSuccess = () => {
|
||||
// 初始化登录成功时间问候语`````
|
||||
let currentTimeInfo = currentTime.value;
|
||||
// 登录成功,跳到转首页
|
||||
// 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
|
||||
if (window.sessionStorage.getItem('becomeDeveloper')) {
|
||||
// 判断是否从成为开发者提示框登录
|
||||
window.sessionStorage.setItem('becomeDeveloper', '');
|
||||
router.push({ path: '/personal' }); // 是 跳转至成为开发者的页面
|
||||
} else {
|
||||
// 初始化登录成功时间问候语
|
||||
let currentTimeInfo = currentTime.value;
|
||||
// 登录成功,跳到转首页
|
||||
// 如果是复制粘贴的路径,非首页/登录页,那么登录成功后重定向到对应的路径中
|
||||
if (route.query?.redirect) {
|
||||
router.push({
|
||||
path: <string>route.query?.redirect,
|
||||
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
|
||||
});
|
||||
} else {
|
||||
router.push('/');
|
||||
let path = '/home';
|
||||
if (BASE_API.NEED_HOME) {
|
||||
path = BASE_API.HOME_ROUTER;
|
||||
}
|
||||
router.push({ path: path, query: { invit: state.invit, ifInvit: state.ifInvit } });
|
||||
}
|
||||
// 登录成功提示
|
||||
const signInText = t('message.signInText');
|
||||
ElMessage.success(`${currentTimeInfo},${signInText}`);
|
||||
// 添加 loading,防止第一次进入界面时出现短暂空白
|
||||
NextLoading.start();
|
||||
}
|
||||
state.loading.signIn = false;
|
||||
// 登录成功提示
|
||||
// 关闭 loading
|
||||
state.loading.signIn = true;
|
||||
const signInText = t('message.signInText');
|
||||
ElMessage.success(`${currentTimeInfo}, ${signInText}`);
|
||||
// 添加 loading,防止第一次进入界面时出现短暂空白
|
||||
// NextLoading.start();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
@ -89,7 +89,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { defineAsyncComponent, computed, ref, onBeforeMount, onMounted, onUnmounted, nextTick, reactive } from 'vue';
|
||||
import { ref, onMounted} from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import EventPopUp from '/@/components/eventPopUp/index.vue';
|
||||
import LampPopUp from '/@/components/lampPopUp/index.vue';
|
||||
|
@ -141,9 +141,11 @@ import * as echarts from 'echarts';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
import { CirclePlus, Remove } from '@element-plus/icons-vue'
|
||||
import { httpRequestApi } from '/@/api/linxyun/base/index';
|
||||
const Map = defineAsyncComponent(() => import('/@/components/map/index.vue'));
|
||||
const Total = defineAsyncComponent(() => import('/@/components/total/index.vue'));
|
||||
const router = useRouter();
|
||||
const http = new httpRequestApi()
|
||||
|
||||
const lampData = ref({
|
||||
total: 300,
|
||||
@ -372,7 +374,10 @@ onMounted(() => {
|
||||
console.log('浏览器窗口高度:', height);
|
||||
initOnlineRateChart();
|
||||
initLightingRateChart();
|
||||
NextLoading.done(0);
|
||||
http.Get('/smartroadlamp/query_tab_road_lamp_info.action').then(res => {
|
||||
console.log("request:", res)
|
||||
})
|
||||
NextLoading.done();
|
||||
})
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user