|
@@ -6,6 +6,7 @@ import 'element-ui/lib/theme-chalk/index.css'
|
|
|
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
|
|
|
import 'font-awesome/scss/font-awesome.scss'
|
|
|
import '@/styles/index.scss' // global css
|
|
|
+import 'xe-utils'
|
|
|
import moment from 'moment'
|
|
|
import plugins from './plugins' // plugins
|
|
|
import App from './App'
|
|
@@ -15,17 +16,16 @@ import router, {resetRouter} from './router'
|
|
|
import echarts from 'echarts'
|
|
|
import '@/icons' // icon
|
|
|
import '@/permission' // permission control
|
|
|
-import axios from 'axios'
|
|
|
-import 'xe-utils'
|
|
|
+// import axios from 'axios'
|
|
|
import VXETable from 'vxe-table'
|
|
|
import 'vxe-table/lib/index.css'
|
|
|
-
|
|
|
+import service from './utils/request'
|
|
|
import {removeToken} from './utils/auth'
|
|
|
// import { resetForm} from "@/utils/index"
|
|
|
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi"
|
|
|
-import {sm2 as sm5, sm2 as sm4, sm2 as sm3, sm2} from "sm-crypto"
|
|
|
Vue.prototype.$moment = moment
|
|
|
Vue.prototype.$echarts = echarts
|
|
|
+Vue.prototype.$axios = service
|
|
|
Vue.use(VXETable)
|
|
|
Vue.use(plugins)
|
|
|
Vue.prototype.handleTree = handleTree
|
|
@@ -48,217 +48,13 @@ Vue.use(ElementUI, {locale})
|
|
|
// Vue.use(ElementUI)
|
|
|
Vue.prototype.$fpath = require('path')
|
|
|
Vue.config.productionTip = false
|
|
|
-Vue.prototype.$axios = axios.create({
|
|
|
- baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
|
|
- // withCredentials: true, // send cookies when cross-domain requests
|
|
|
- timeout: 1000 * 60 * 10 // request timeout
|
|
|
-})
|
|
|
+
|
|
|
VXETable.setup({
|
|
|
validArgs: 'obsolete' // 将自定义校验参数还原为 Function(rule, cellValue, callback)
|
|
|
})
|
|
|
|
|
|
Vue.prototype.resetForm = resetForm
|
|
|
Vue.prototype.parseTime = parseTime
|
|
|
-// 公钥Q
|
|
|
-let publicKey2 = '041967638ca43d4577d8dba166bff4437fde944270101f398a95b846ec2f8177d09f8abc5d62b6cd2c7216274d7abe0c8e04b0bb691207a32dd2e12d6bd2798672'
|
|
|
-// 私钥D
|
|
|
-let privateKey1 = '27ce6eec39dbf3b564a77c4da1e129fe1ba01a92f6d61055a33ed14ffcbc949e'
|
|
|
-
|
|
|
-Vue.prototype.$axios.interceptors.request.use(
|
|
|
- config => {
|
|
|
- const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
|
|
|
- // get请求映射params参数
|
|
|
- if (config.method === 'get' && config.params) {
|
|
|
- // 参数加密
|
|
|
- let encryptParam = doEncrypt(JSON.stringify(config.params))
|
|
|
- // 参数签名
|
|
|
- let paramSign = doSign(JSON.stringify(config.params))
|
|
|
- let result = 'secretData=' + encryptParam + '¶mSign=' + paramSign
|
|
|
- config.params = result
|
|
|
- }
|
|
|
-
|
|
|
- if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put' || config.method === 'delete')) {
|
|
|
- if (config.url != '/getMailCode') {
|
|
|
- if (config.data !== undefined) {
|
|
|
- // 参数加密
|
|
|
- let encryptParam = doEncrypt(JSON.stringify(config.data))
|
|
|
- // 参数签名
|
|
|
- let paramSign = doSign(JSON.stringify(config.data))
|
|
|
- const param = {
|
|
|
- secretData: encryptParam,
|
|
|
- paramSign: paramSign
|
|
|
- }
|
|
|
- config.data = param
|
|
|
- if (config.url!='/user/login'){
|
|
|
- config.headers.post['Content-Type'] = 'application/json';
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- Message({
|
|
|
- message: '请求拦截器检测出config.data是undefined不能提交!',
|
|
|
- type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (sessionStorage.getItem("token")!=="undefined" && sessionStorage.getItem("token")!==undefined && sessionStorage.getItem("token")!=null) { // 判断是否存在token,如果存在的话,则每个http header都加上token
|
|
|
- let tokenStr = doEncrypt(sessionStorage.getItem("token"))
|
|
|
- config.headers['Authorization'] = tokenStr
|
|
|
- config.headers['TokenSign'] = doSign(sessionStorage.getItem("token"))
|
|
|
- }
|
|
|
- return config
|
|
|
- },
|
|
|
- error => {
|
|
|
- // do something with request error
|
|
|
- // console.log(error) // for debug
|
|
|
- return Promise.reject(error)
|
|
|
- }
|
|
|
-)
|
|
|
-
|
|
|
-// 是否正在刷新的标记
|
|
|
-let isRefreshing = false
|
|
|
-//重试队列
|
|
|
-let requests = []
|
|
|
-
|
|
|
-// response interceptor
|
|
|
-Vue.prototype.$axios.interceptors.response.use(
|
|
|
- /**
|
|
|
- * Determine the request status by custom code
|
|
|
- * Here is just an example
|
|
|
- * You can also judge the status by HTTP Status Code
|
|
|
- */
|
|
|
- response => {
|
|
|
- const res = response.data
|
|
|
- let returnStr = res.split("&")
|
|
|
- let returnData = returnStr[0].split("=")[1]
|
|
|
- let returnSign = returnStr[1].split("=")[1]
|
|
|
- // 解密
|
|
|
- let decData = doDecryptStr(returnData)
|
|
|
- // 验签
|
|
|
- let verifyResult = doVerifySignature(decData, returnSign)
|
|
|
- if (!verifyResult) {
|
|
|
- return Promise.reject(new Error('返回数据验签失败' || 'Error'))
|
|
|
- }
|
|
|
- let data = JSON.parse(decData)
|
|
|
- // if the custom code is not 20000, it is judged as an error.
|
|
|
- //console.log(res.code)
|
|
|
- if (data.code > 1) {
|
|
|
- // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
|
- if (data.code === 50008 || data.code === 50012 || data.code === 50014) {
|
|
|
- // to re-login
|
|
|
- MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
|
|
|
- confirmButtonText: 'Re-Login',
|
|
|
- cancelButtonText: 'Cancel',
|
|
|
- type: 'warning'
|
|
|
- }).then(() => {
|
|
|
- store.dispatch('user/resetToken').then(() => {
|
|
|
- location.reload()
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- return Promise.reject(new Error(data.message || 'Error'))
|
|
|
- } else {
|
|
|
- return data
|
|
|
- }
|
|
|
- },
|
|
|
- async error => {
|
|
|
- if (error.response) {
|
|
|
- switch (error.response.status) {
|
|
|
- case 401:
|
|
|
- console.log('用户验证失败!')
|
|
|
- // 返回 401 清除token信息并跳转到登录页面
|
|
|
- removeToken()
|
|
|
- resetRouter()
|
|
|
- Message({
|
|
|
- message: error.response.data,
|
|
|
- type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
- })
|
|
|
- break
|
|
|
- case 403:
|
|
|
- console.log('登录超时!')
|
|
|
- // 返回 401 清除token信息并跳转到登录页面
|
|
|
- removeToken()
|
|
|
- resetRouter()
|
|
|
- router.push('/login')
|
|
|
- Message({
|
|
|
- message: error.response.data,
|
|
|
- type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
- })
|
|
|
- return
|
|
|
- break
|
|
|
- case 500:
|
|
|
- Message({
|
|
|
- message: '服务器关闭了!请联系相关工作人员',
|
|
|
- type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
- })
|
|
|
- removeToken()
|
|
|
- resetRouter()
|
|
|
- router.push('/login')
|
|
|
- break
|
|
|
- case 504:
|
|
|
- console.log('服务器关闭了!')
|
|
|
- resetRouter()
|
|
|
- break
|
|
|
- case 410:
|
|
|
- Message({
|
|
|
- message: error.response.data,
|
|
|
- type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
- })
|
|
|
- break
|
|
|
- case 409:
|
|
|
- if (!isRefreshing) {
|
|
|
- isRefreshing = true
|
|
|
- //调用刷新token的接口
|
|
|
- return await Vue.prototype.$axios.post(
|
|
|
- '/refreshToken'
|
|
|
- ).then((res) => {
|
|
|
- // const { token } = res.data
|
|
|
- // 替换token
|
|
|
- sessionStorage.setItem('token', res.data)
|
|
|
- // Vue.prototype.$axios(error.response.config)
|
|
|
- // 重新请求接口 前过期的接口
|
|
|
- error.config.headers.Authorization = res.data;
|
|
|
- requests.length > 0 && requests.map((cb) => {
|
|
|
- cb();
|
|
|
- });
|
|
|
- requests = []; //注意要清空
|
|
|
- return Vue.prototype.$axios.request(error.config);
|
|
|
- // return error.response.config
|
|
|
- }).catch(err => {
|
|
|
- console.log(err)
|
|
|
- //跳到登录页
|
|
|
- removeToken()
|
|
|
- router.push('/login')
|
|
|
- // return Promise.reject(err)
|
|
|
- }).finally(() => {
|
|
|
- isRefreshing = false
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
- // 正在刷新token ,把后来的接口缓冲起来
|
|
|
- return new Promise((resolve) => {
|
|
|
- requests.push(() => {
|
|
|
- error.config.headers.Authorization = sessionStorage.getItem('token');
|
|
|
- resolve(Vue.prototype.$axios.request(error.config));
|
|
|
- });
|
|
|
- })
|
|
|
- }
|
|
|
- break
|
|
|
- // return Promise.reject(error.response.data)
|
|
|
- }
|
|
|
- }
|
|
|
- else{
|
|
|
- return Promise.reject(error)
|
|
|
- }
|
|
|
- }
|
|
|
-)
|
|
|
|
|
|
new Vue({
|
|
|
el: '#app',
|
|
@@ -267,82 +63,4 @@ new Vue({
|
|
|
render: h => h(App)
|
|
|
})
|
|
|
|
|
|
-// 加密:
|
|
|
-export function doEncrypt(msgString) {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- // 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
|
- let cipherMode = 1
|
|
|
-
|
|
|
- // 加密结果
|
|
|
- let encryptData = sm2.doEncrypt(msgString, publicKey2, cipherMode);
|
|
|
- // 加密后的密文前需要添加04,后端才能正常解密
|
|
|
- // let encrypt = '04' + encryptData;
|
|
|
- return encryptData;
|
|
|
-}
|
|
|
-
|
|
|
-// 解密
|
|
|
-export function doDecryptStr(enStr) {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- // 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
|
- let cipherMode = 1
|
|
|
- // 解密结果
|
|
|
- let doDecrypt = sm2.doDecrypt(enStr, privateKey1, cipherMode);
|
|
|
- // 解密后类型转换
|
|
|
- // let objData = JSON.parse(doDecrypt)
|
|
|
- return doDecrypt;
|
|
|
-}
|
|
|
-
|
|
|
-// 签名
|
|
|
-export function doSign(msgString) {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- // 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
|
- let cipherMode = 1
|
|
|
- // 签名
|
|
|
- let sign = sm2.doSignature(msgString, privateKey1, {hash: true, der: true})
|
|
|
- return sign;
|
|
|
-}
|
|
|
-
|
|
|
-// 验签
|
|
|
-export function doVerifySignature(msgString, sigValueHex) {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- // 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
|
- let cipherMode = 1
|
|
|
- // 签名
|
|
|
- let verifyResult = sm2.doVerifySignature(msgString, sigValueHex, publicKey2, {hash: true, der: true}) // 验签结果
|
|
|
- return verifyResult;
|
|
|
-}
|
|
|
-
|
|
|
-// 前端user信息加密
|
|
|
-export function userinfoEncrypt(str) {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- let cipherMode = 1
|
|
|
- // 加密
|
|
|
- let encryptData = sm2.doEncrypt(str, '0460ff8c8c306fe62f6f9d11c5c82c30d10bbbc703da094e423072cac7dc663c97fad52eccb34f311f47a07f280de157ba4f2aa659cabe749121384b9376ea2ed2', cipherMode);
|
|
|
- return encryptData
|
|
|
-}
|
|
|
-// 前端user信息解密
|
|
|
-export function userinfoDecrypt(str) {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- let cipherMode = 1
|
|
|
- // 加密
|
|
|
- let decryptData = sm2.doDecrypt(str, "27ce6eec39dbf3b564a77c4da1e129fe1ba01a92f6d61055a33ed14ffcbc949e", cipherMode);
|
|
|
- return decryptData
|
|
|
-}
|
|
|
|
|
|
-export function test() {
|
|
|
- let sm2 = require('sm-crypto').sm2;
|
|
|
- let cipherMode = 1
|
|
|
- // 加密
|
|
|
- let encryptData = sm2.doEncrypt('1122加密', '0460ff8c8c306fe62f6f9d11c5c82c30d10bbbc703da094e423072cac7dc663c97fad52eccb34f311f47a07f280de157ba4f2aa659cabe749121384b9376ea2ed2', cipherMode);
|
|
|
- let sm3 = require('sm-crypto').sm2;
|
|
|
- // 签名
|
|
|
- let sign = sm3.doSignature('1122加密', '6155d63ee27cbeca07f3e40c4f8856f1be8119fcbda1aadc7e0e595e52bad7bd')
|
|
|
- // 解密
|
|
|
- let sm4 = require('sm-crypto').sm2;
|
|
|
- let doDecrypt = sm4.doDecrypt(encryptData, privateKey1, cipherMode);
|
|
|
- alert('解密:' + doDecrypt)
|
|
|
- // 验签
|
|
|
- let sm5 = require('sm-crypto').sm2;
|
|
|
- let verifyResult = sm5.doVerifySignature(doDecrypt, sign, publicKey2) // 验签结果
|
|
|
- alert('验签:' + verifyResult)
|
|
|
-}
|