init
This commit is contained in:
16
src/App.vue
Executable file
16
src/App.vue
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
<template>
|
||||||
|
<router-view />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
221
src/axios.js
Executable file
221
src/axios.js
Executable file
@@ -0,0 +1,221 @@
|
|||||||
|
/**
|
||||||
|
* 全站http配置
|
||||||
|
*
|
||||||
|
* axios参数说明
|
||||||
|
* isSerialize是否开启form表单提交
|
||||||
|
* isToken是否需要token
|
||||||
|
*/
|
||||||
|
import axios from 'axios';
|
||||||
|
import store from '@/store/';
|
||||||
|
import router from '@/router/';
|
||||||
|
import { serialize } from '@/utils/util';
|
||||||
|
import { getToken, removeToken, removeRefreshToken } from '@/utils/auth';
|
||||||
|
import { isURL, validatenull } from '@/utils/validate';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import website from '@/config/website';
|
||||||
|
import NProgress from 'nprogress'; // progress bar
|
||||||
|
import 'nprogress/nprogress.css'; // progress bar style
|
||||||
|
import { Base64 } from 'js-base64';
|
||||||
|
import { baseUrl } from '@/config/env';
|
||||||
|
import crypto from '@/utils/crypto';
|
||||||
|
|
||||||
|
// 全局未授权错误提示状态,只提示一次
|
||||||
|
let isErrorShown = false;
|
||||||
|
// 全局锁机制相关变量
|
||||||
|
let isRefreshing = false; // 标记当前是否正在刷新token
|
||||||
|
let refreshTokenPromise = null; // 刷新token的Promise,避免重复请求
|
||||||
|
|
||||||
|
axios.defaults.timeout = 10000;
|
||||||
|
//返回其他状态码
|
||||||
|
axios.defaults.validateStatus = function (status) {
|
||||||
|
return status >= 200 && status <= 500; // 默认的
|
||||||
|
};
|
||||||
|
//跨域请求,允许保存cookie
|
||||||
|
axios.defaults.withCredentials = true;
|
||||||
|
// NProgress Configuration
|
||||||
|
NProgress.configure({
|
||||||
|
showSpinner: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
//http request拦截
|
||||||
|
axios.interceptors.request.use(
|
||||||
|
config => {
|
||||||
|
// start progress bar
|
||||||
|
NProgress.start();
|
||||||
|
// 初始化错误提示状态
|
||||||
|
isErrorShown = false;
|
||||||
|
//地址为已经配置状态则不添加前缀
|
||||||
|
if (!isURL(config.url) && !config.url.startsWith(baseUrl)) {
|
||||||
|
config.url = baseUrl + config.url;
|
||||||
|
}
|
||||||
|
//安全请求header
|
||||||
|
config.headers['Blade-Requested-With'] = 'BladeHttpRequest';
|
||||||
|
//headers判断是否需要
|
||||||
|
const authorization = config.authorization === false;
|
||||||
|
if (!authorization) {
|
||||||
|
config.headers['Authorization'] = `Basic ${Base64.encode(
|
||||||
|
`${website.clientId}:${website.clientSecret}`
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
//headers判断请求是否携带token
|
||||||
|
const meta = config.meta || {};
|
||||||
|
const isToken = meta.isToken === false;
|
||||||
|
//headers传递token是否加密
|
||||||
|
const cryptoToken = config.cryptoToken === true;
|
||||||
|
//判断传递数据是否加密
|
||||||
|
const cryptoData = config.cryptoData === true;
|
||||||
|
const token = getToken();
|
||||||
|
if (token && !isToken) {
|
||||||
|
config.headers[website.tokenHeader] = cryptoToken
|
||||||
|
? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey)
|
||||||
|
: 'bearer ' + token;
|
||||||
|
}
|
||||||
|
// 开启报文加密
|
||||||
|
if (cryptoData) {
|
||||||
|
if (config.params) {
|
||||||
|
const data = crypto.encryptAES(JSON.stringify(config.params), crypto.aesKey);
|
||||||
|
config.params = { data };
|
||||||
|
}
|
||||||
|
if (config.data) {
|
||||||
|
config.text = true;
|
||||||
|
config.data = crypto.encryptAES(JSON.stringify(config.data), crypto.aesKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//headers中配置text请求
|
||||||
|
if (config.text === true) {
|
||||||
|
config.headers['Content-Type'] = 'text/plain';
|
||||||
|
}
|
||||||
|
//headers中配置serialize为true开启序列化
|
||||||
|
if (config.method === 'post' && meta.isSerialize === true) {
|
||||||
|
config.data = serialize(config.data);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
//http response拦截
|
||||||
|
axios.interceptors.response.use(
|
||||||
|
res => {
|
||||||
|
NProgress.done();
|
||||||
|
//获取配置信息
|
||||||
|
const config = res.config;
|
||||||
|
const cryptoData = config.cryptoData === true;
|
||||||
|
//解析加密报文
|
||||||
|
if (cryptoData) {
|
||||||
|
res.data = JSON.parse(crypto.decryptAES(res.data, crypto.aesKey));
|
||||||
|
}
|
||||||
|
//获取状态信息
|
||||||
|
const status = res.data.error_code || res.data.code || res.status;
|
||||||
|
const statusWhiteList = website.statusWhiteList || [];
|
||||||
|
const message = res.data.msg || res.data.error_description || '系统错误';
|
||||||
|
//如果在白名单里则自行catch逻辑处理
|
||||||
|
if (statusWhiteList.includes(status)) return Promise.reject(res);
|
||||||
|
|
||||||
|
// 如果是401并且没有重试过,尝试刷新token
|
||||||
|
if (status === 401 && !config._retry) {
|
||||||
|
config._retry = true;
|
||||||
|
|
||||||
|
// 如果当前已经在刷新token,等待刷新完成
|
||||||
|
if (isRefreshing) {
|
||||||
|
return refreshTokenPromise.then(() => {
|
||||||
|
const meta = config.meta || {};
|
||||||
|
const isToken = meta.isToken === false;
|
||||||
|
const cryptoToken = config.cryptoToken === true;
|
||||||
|
const token = getToken();
|
||||||
|
if (token && !isToken) {
|
||||||
|
config.headers[website.tokenHeader] = cryptoToken
|
||||||
|
? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey)
|
||||||
|
: 'bearer ' + token;
|
||||||
|
}
|
||||||
|
return axios(config);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始刷新token
|
||||||
|
isRefreshing = true;
|
||||||
|
|
||||||
|
// 调用RefreshToken action来刷新token
|
||||||
|
refreshTokenPromise = store
|
||||||
|
.dispatch('RefreshToken')
|
||||||
|
.then(() => {
|
||||||
|
isRefreshing = false; // 重置刷新标志
|
||||||
|
const meta = config.meta || {};
|
||||||
|
const isToken = meta.isToken === false;
|
||||||
|
const cryptoToken = config.cryptoToken === true;
|
||||||
|
// 获取刷新后的token
|
||||||
|
const token = getToken();
|
||||||
|
if (token && !isToken) {
|
||||||
|
config.headers[website.tokenHeader] = cryptoToken
|
||||||
|
? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey)
|
||||||
|
: 'bearer ' + token;
|
||||||
|
}
|
||||||
|
return axios(config);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
isRefreshing = false; // 重置刷新标志
|
||||||
|
// 首次报错时提示
|
||||||
|
if (!isErrorShown) {
|
||||||
|
isErrorShown = true;
|
||||||
|
ElMessage({
|
||||||
|
message: '用户令牌不可用,请重新登录',
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 清除token信息
|
||||||
|
removeToken();
|
||||||
|
removeRefreshToken();
|
||||||
|
// 重定向到登录页
|
||||||
|
store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }));
|
||||||
|
return Promise.reject(new Error(message));
|
||||||
|
});
|
||||||
|
|
||||||
|
return refreshTokenPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是401并且已经重试过,直接跳转到登录页面
|
||||||
|
if (status === 401 && config._retry) {
|
||||||
|
if (!isErrorShown) {
|
||||||
|
isErrorShown = true;
|
||||||
|
ElMessage({
|
||||||
|
message: '用户令牌不可用,请重新登录',
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
removeToken();
|
||||||
|
removeRefreshToken();
|
||||||
|
store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }));
|
||||||
|
return Promise.reject(new Error(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果请求为oauth2错误码则首次报错时提示
|
||||||
|
if (status > 2000 && !validatenull(res.data.error_description)) {
|
||||||
|
if (!isErrorShown) {
|
||||||
|
isErrorShown = true;
|
||||||
|
ElMessage({
|
||||||
|
message: message,
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果请求为非200则默认统一处理
|
||||||
|
if (status !== 200) {
|
||||||
|
ElMessage({
|
||||||
|
message: message,
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
return Promise.reject(new Error(message));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
NProgress.done();
|
||||||
|
return Promise.reject(new Error(error));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default axios;
|
||||||
50
src/debug.js
Normal file
50
src/debug.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import DisableDevtool from 'disable-devtool';
|
||||||
|
import { ElMessageBox } from 'element-plus';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全警告的HTML模板, 使用Tailwind CSS样式
|
||||||
|
*/
|
||||||
|
const SECURITY_WARNING_TEMPLATE = `
|
||||||
|
<div class='flex flex-col items-center gap-4 p-2'>
|
||||||
|
<div class='text-red-500 dark:text-red-400'>
|
||||||
|
<i class='el-icon-warning text-2xl'></i>
|
||||||
|
</div>
|
||||||
|
<div class='text-center'>
|
||||||
|
<p class='text-base font-medium text-gray-900 dark:text-gray-100'>
|
||||||
|
不合规操作,系统将在5秒后自动关闭退出!
|
||||||
|
</p>
|
||||||
|
<p class='mt-2 text-sm text-gray-600 dark:text-gray-400'>
|
||||||
|
如您频繁此类操作,系统将记录上报。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Element Plus 消息框配置选项
|
||||||
|
*/
|
||||||
|
const ALERT_OPTIONS = {
|
||||||
|
type: 'error',
|
||||||
|
showClose: false,
|
||||||
|
center: true,
|
||||||
|
closeOnClickModal: false,
|
||||||
|
closeOnPressEscape: false,
|
||||||
|
dangerouslyUseHTMLString: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
if (import.meta.env.VITE_APP_DEBUG_SWITCH === 'false') return;
|
||||||
|
|
||||||
|
const debugKey = import.meta.env.VITE_APP_DEBUG_KEY;
|
||||||
|
let flag = false;
|
||||||
|
DisableDevtool({
|
||||||
|
md5: DisableDevtool.md5(debugKey),
|
||||||
|
disableMenu: false,
|
||||||
|
ondevtoolopen: (type, next) => {
|
||||||
|
if (!flag) ElMessageBox.alert(SECURITY_WARNING_TEMPLATE, '安全警告', ALERT_OPTIONS);
|
||||||
|
flag = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
next();
|
||||||
|
}, 5000);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
25
src/error.js
Executable file
25
src/error.js
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
import store from './store';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
install: app => {
|
||||||
|
app.config.errorHandler = (err, vm, info) => {
|
||||||
|
store.commit('ADD_LOGS', {
|
||||||
|
type: 'error',
|
||||||
|
message: err.message,
|
||||||
|
stack: err.stack,
|
||||||
|
info,
|
||||||
|
});
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
console.group('>>>>>> 错误信息 >>>>>>');
|
||||||
|
console.log(info);
|
||||||
|
console.groupEnd();
|
||||||
|
console.group('>>>>>> Vue 实例 >>>>>>');
|
||||||
|
console.log(vm);
|
||||||
|
console.groupEnd();
|
||||||
|
console.group('>>>>>> Error >>>>>>');
|
||||||
|
console.log(err);
|
||||||
|
console.groupEnd();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
77
src/main.js
Executable file
77
src/main.js
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
import { createApp } from 'vue';
|
||||||
|
import website from './config/website';
|
||||||
|
import axios from './axios';
|
||||||
|
import router from './router/';
|
||||||
|
import store from './store';
|
||||||
|
import i18n from './lang/';
|
||||||
|
import { language, messages } from './lang/';
|
||||||
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
|
||||||
|
import ElementPlus from 'element-plus';
|
||||||
|
import 'element-plus/dist/index.css';
|
||||||
|
import Avue from '@smallwei/avue';
|
||||||
|
import '@smallwei/avue/lib/index.css';
|
||||||
|
import avueUeditor from 'avue-plugin-ueditor';
|
||||||
|
import crudCommon from '@/mixins/crud.js';
|
||||||
|
import { getScreen } from './utils/util';
|
||||||
|
import './permission';
|
||||||
|
import error from './error';
|
||||||
|
import App from './App.vue';
|
||||||
|
import 'animate.css';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import 'styles/common.scss';
|
||||||
|
// 系统组件
|
||||||
|
import debug from './debug';
|
||||||
|
import VueClipboard from 'vue3-clipboard';
|
||||||
|
import highlight from './components/highlight/main.vue';
|
||||||
|
import codeEditor from './components/code-editor/main.vue';
|
||||||
|
import basicBlock from './components/basic-block/main.vue';
|
||||||
|
import basicContainer from './components/basic-container/main.vue';
|
||||||
|
import thirdRegister from './components/third-register/main.vue';
|
||||||
|
import flowDesign from './components/flow-design/main.vue';
|
||||||
|
import flowDesignStep from './components/flow-design-step/main.vue';
|
||||||
|
// 业务组件
|
||||||
|
import codeSetting from './views/tool/codesetting.vue';
|
||||||
|
import formSetting from './views/tool/formsetting.vue';
|
||||||
|
import tenantPackage from './views/system/tenantpackage.vue';
|
||||||
|
import tenantDatasource from './views/system/tenantdatasource.vue';
|
||||||
|
|
||||||
|
window.$crudCommon = crudCommon;
|
||||||
|
debug();
|
||||||
|
window.axios = axios;
|
||||||
|
const app = createApp(App);
|
||||||
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||||
|
app.component(key, component);
|
||||||
|
}
|
||||||
|
app.component('basicContainer', basicContainer);
|
||||||
|
app.component('basicBlock', basicBlock);
|
||||||
|
app.component('highlight', highlight);
|
||||||
|
app.component('codeEditor', codeEditor);
|
||||||
|
app.component('thirdRegister', thirdRegister);
|
||||||
|
app.component('flowDesign', flowDesign);
|
||||||
|
app.component('flowDesignStep', flowDesignStep);
|
||||||
|
app.component('codeSetting', codeSetting);
|
||||||
|
app.component('formSetting', formSetting);
|
||||||
|
app.component('tenantPackage', tenantPackage);
|
||||||
|
app.component('tenantDatasource', tenantDatasource);
|
||||||
|
app.config.globalProperties.$app = app;
|
||||||
|
app.config.globalProperties.$dayjs = dayjs;
|
||||||
|
app.config.globalProperties.website = website;
|
||||||
|
app.config.globalProperties.getScreen = getScreen;
|
||||||
|
app.use(error);
|
||||||
|
app.use(i18n);
|
||||||
|
app.use(store);
|
||||||
|
app.use(router);
|
||||||
|
app.use(ElementPlus, {
|
||||||
|
locale: messages[language],
|
||||||
|
});
|
||||||
|
app.use(Avue, {
|
||||||
|
axios,
|
||||||
|
calcHeight: 10,
|
||||||
|
locale: messages[language],
|
||||||
|
});
|
||||||
|
app.use(avueUeditor, { axios });
|
||||||
|
app.use(VueClipboard, {
|
||||||
|
autoSetContainer: true,
|
||||||
|
appendToBody: true, // 这可以帮助解决一些更复杂的使用场景下的问题
|
||||||
|
});
|
||||||
|
app.mount('#app');
|
||||||
9
src/mockProdServer.js
Normal file
9
src/mockProdServer.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
|
||||||
|
|
||||||
|
import menuModule from '../mock/menu';
|
||||||
|
import userModule from '../mock/user';
|
||||||
|
import crudModule from '../mock/crud';
|
||||||
|
|
||||||
|
export const setupProdMockServer = () => {
|
||||||
|
createProdMockServer([...menuModule, ...userModule, ...crudModule]);
|
||||||
|
};
|
||||||
66
src/permission.js
Executable file
66
src/permission.js
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
import router from './router/';
|
||||||
|
import store from './store';
|
||||||
|
import { getToken } from '@/utils/auth';
|
||||||
|
import NProgress from 'nprogress'; // progress bar
|
||||||
|
import 'nprogress/nprogress.css'; // progress bar style
|
||||||
|
NProgress.configure({ showSpinner: false });
|
||||||
|
const lockPage = '/lock'; //锁屏页
|
||||||
|
router.beforeEach((to, from, next) => {
|
||||||
|
// 获取匹配的路由数组
|
||||||
|
const matchedRoutes = to.matched;
|
||||||
|
const component = matchedRoutes.length > 0 ? matchedRoutes[matchedRoutes.length - 1].components.default : null;
|
||||||
|
if (component && typeof (component) == 'function') {
|
||||||
|
component().then(mod => {
|
||||||
|
mod.default.name = to.fullPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const meta = to.meta || {};
|
||||||
|
const isMenu = meta.menu === undefined ? to.query.menu : meta.menu;
|
||||||
|
store.commit('SET_IS_MENU', isMenu === undefined);
|
||||||
|
if (getToken()) {
|
||||||
|
if (store.getters.isLock && to.path !== lockPage) {
|
||||||
|
//如果系统激活锁屏,全部跳转到锁屏页
|
||||||
|
next({ path: lockPage });
|
||||||
|
} else if (to.path === '/login') {
|
||||||
|
//如果登录成功访问登录页跳转到主页
|
||||||
|
next({ path: '/' });
|
||||||
|
} else {
|
||||||
|
if (store.getters.token.length === 0) {
|
||||||
|
store.dispatch('FedLogOut').then(() => {
|
||||||
|
next({ path: '/login' });
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const meta = to.meta || {};
|
||||||
|
const query = to.query || {};
|
||||||
|
if (meta.target) {
|
||||||
|
window.open(query.url.replace(/#/g, '&'));
|
||||||
|
return;
|
||||||
|
} else if (meta.isTab !== false) {
|
||||||
|
store.commit('ADD_TAG', {
|
||||||
|
name: query.name || to.name,
|
||||||
|
path: to.path,
|
||||||
|
fullPath: to.path,
|
||||||
|
params: to.params,
|
||||||
|
query: to.query,
|
||||||
|
meta: meta,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//判断是否需要认证,没有登录访问去登录页
|
||||||
|
if (meta.isAuth === false) {
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
next('/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.afterEach(to => {
|
||||||
|
NProgress.done();
|
||||||
|
let title = router.$avueRouter.generateTitle(to, { label: 'name' });
|
||||||
|
router.$avueRouter.setTitle(title);
|
||||||
|
store.commit('SET_IS_SEARCH', false);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user