|
@@ -46,9 +46,9 @@ Vue.use(ElementUI, {locale})
|
|
Vue.prototype.$fpath = require('path')
|
|
Vue.prototype.$fpath = require('path')
|
|
Vue.config.productionTip = false
|
|
Vue.config.productionTip = false
|
|
Vue.prototype.$axios = axios.create({
|
|
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
|
|
|
|
|
|
+ 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({
|
|
VXETable.setup({
|
|
validArgs: 'obsolete' // 将自定义校验参数还原为 Function(rule, cellValue, callback)
|
|
validArgs: 'obsolete' // 将自定义校验参数还原为 Function(rule, cellValue, callback)
|
|
@@ -60,210 +60,184 @@ let publicKey2 = '041967638ca43d4577d8dba166bff4437fde944270101f398a95b846ec2f81
|
|
let privateKey1 = '27ce6eec39dbf3b564a77c4da1e129fe1ba01a92f6d61055a33ed14ffcbc949e'
|
|
let privateKey1 = '27ce6eec39dbf3b564a77c4da1e129fe1ba01a92f6d61055a33ed14ffcbc949e'
|
|
|
|
|
|
Vue.prototype.$axios.interceptors.request.use(
|
|
Vue.prototype.$axios.interceptors.request.use(
|
|
- config => {
|
|
|
|
- // 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
|
|
|
|
- }
|
|
|
|
|
|
+ config => {
|
|
|
|
+ // 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 (config.method === 'post' || config.method === 'put') {
|
|
|
|
- if (config.url!='/getMailCode'){
|
|
|
|
- if (config.data!==undefined){
|
|
|
|
- // 参数加密
|
|
|
|
- let encryptParam = doEncrypt(config.data.toString())
|
|
|
|
- // 参数签名
|
|
|
|
- let paramSign = doSign(config.data.toString())
|
|
|
|
- let result = 'secretData='+encryptParam+'¶mSign='+paramSign
|
|
|
|
- config.data = result
|
|
|
|
- }
|
|
|
|
|
|
+ if (config.method === 'post' || config.method === 'put') {
|
|
|
|
+ if (config.url != '/getMailCode') {
|
|
|
|
+ if (config.data !== undefined) {
|
|
|
|
+ // 参数加密
|
|
|
|
+ let encryptParam = doEncrypt(config.data.toString())
|
|
|
|
+ // 参数签名
|
|
|
|
+ let paramSign = doSign(config.data.toString())
|
|
|
|
+ let result = 'secretData=' + encryptParam + '¶mSign=' + paramSign
|
|
|
|
+ config.data = result
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- if (getBrowserToken()) { // 判断是否存在token,如果存在的话,则每个http header都加上token
|
|
|
|
- let tokenStr = doEncrypt(getBrowserToken())
|
|
|
|
- config.headers['Authorization']= tokenStr
|
|
|
|
- config.headers['TokenSign']= doSign(getBrowserToken())
|
|
|
|
- }
|
|
|
|
- return config
|
|
|
|
- },
|
|
|
|
- error => {
|
|
|
|
- // do something with request error
|
|
|
|
- console.log(error) // for debug
|
|
|
|
- return Promise.reject(error)
|
|
|
|
|
|
+ if (sessionStorage.getItem("token")!=="undefined" && sessionStorage.getItem("token")!==undefined && sessionStorage.getItem("token")!=null) { // 判断是否存在token,如果存在的话,则每个http header都加上token
|
|
|
|
+ alert('存在')
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
)
|
|
)
|
|
|
|
|
|
function getBrowserUser() {
|
|
function getBrowserUser() {
|
|
- var user = "";
|
|
|
|
- var ca = document.cookie.split(';');
|
|
|
|
- for (var i = 0; i < ca.length; i++) {
|
|
|
|
- var c = ca[i].trim();
|
|
|
|
- if (c.indexOf("user=") == 0){
|
|
|
|
- user = c.substring("user=".length, c.length);
|
|
|
|
- }
|
|
|
|
|
|
+ var user = "";
|
|
|
|
+ var ca = document.cookie.split(';');
|
|
|
|
+ for (var i = 0; i < ca.length; i++) {
|
|
|
|
+ var c = ca[i].trim();
|
|
|
|
+ if (c.indexOf("user=") == 0) {
|
|
|
|
+ user = c.substring("user=".length, c.length);
|
|
}
|
|
}
|
|
- return user
|
|
|
|
|
|
+ }
|
|
|
|
+ return user
|
|
}
|
|
}
|
|
|
|
|
|
// response interceptor
|
|
// response interceptor
|
|
Vue.prototype.$axios.interceptors.response.use(
|
|
Vue.prototype.$axios.interceptors.response.use(
|
|
- /**
|
|
|
|
- * If you want to get http information such as headers or status
|
|
|
|
- * Please return response => response
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Determine the request status by custom code
|
|
|
|
- * Here is just an example
|
|
|
|
- * You can also judge the status by HTTP Status Code
|
|
|
|
- */
|
|
|
|
- response => {
|
|
|
|
- // 处理下载文件
|
|
|
|
- if (response.headers && response.headers['content-type'] && (response.headers['content-type'].indexOf('application/x-msdownload') != -1)) {
|
|
|
|
- // 创建一个blob对象,file的一种
|
|
|
|
- const blob = new Blob([response.data], {type: response.headers['content-type']})
|
|
|
|
- const fileName = decodeURI(response.headers['content-disposition'].split('=')[1])
|
|
|
|
- if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
- // 兼容IE10
|
|
|
|
- navigator.msSaveBlob(blob, fileName)
|
|
|
|
- } else {
|
|
|
|
- // 非IE下载
|
|
|
|
- const elink = document.createElement('a')
|
|
|
|
- elink.download = fileName
|
|
|
|
- elink.style.display = 'none'
|
|
|
|
- elink.href = URL.createObjectURL(blob)
|
|
|
|
- document.body.appendChild(elink)
|
|
|
|
- elink.click()
|
|
|
|
- URL.revokeObjectURL(elink.href) // 释放URL 对象
|
|
|
|
- document.body.removeChild(elink)
|
|
|
|
- }
|
|
|
|
- response.data = ''
|
|
|
|
- response.headers['content-type'] = 'text/json'
|
|
|
|
- return response
|
|
|
|
- } else {
|
|
|
|
- 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)
|
|
|
|
- alert(data)
|
|
|
|
- // if the custom code is not 20000, it is judged as an error.
|
|
|
|
- //console.log(res.code)
|
|
|
|
- if (data.code !== 0) {
|
|
|
|
- Message({
|
|
|
|
- message: data.message || 'Error',
|
|
|
|
- type: 'error',
|
|
|
|
- duration: 5 * 1000
|
|
|
|
- })
|
|
|
|
|
|
+ /**
|
|
|
|
+ * If you want to get http information such as headers or status
|
|
|
|
+ * Please return response => response
|
|
|
|
+ */
|
|
|
|
|
|
- // 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
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- 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: '登录超时',
|
|
|
|
- type: 'error',
|
|
|
|
- duration: 5 * 1000
|
|
|
|
- })
|
|
|
|
- break
|
|
|
|
- case 500:
|
|
|
|
- Message({
|
|
|
|
- message: '服务器关闭了!请联系相关工作人员',
|
|
|
|
- type: 'error',
|
|
|
|
- duration: 5 * 1000
|
|
|
|
- })
|
|
|
|
- removeToken()
|
|
|
|
- resetRouter()
|
|
|
|
- router.push('/login')
|
|
|
|
- break
|
|
|
|
- case 504:
|
|
|
|
- console.log('服务器关闭了!')
|
|
|
|
- resetRouter()
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /* console.log('err' + error) // for debug
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 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 !== 0) {
|
|
Message({
|
|
Message({
|
|
- message: error.message,
|
|
|
|
|
|
+ message: data.message || 'Error',
|
|
type: 'error',
|
|
type: 'error',
|
|
duration: 5 * 1000
|
|
duration: 5 * 1000
|
|
- })*/
|
|
|
|
- return Promise.reject(error)
|
|
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ // 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
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ 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: '登录超时',
|
|
|
|
+ type: 'error',
|
|
|
|
+ duration: 5 * 1000
|
|
|
|
+ })
|
|
|
|
+ break
|
|
|
|
+ case 500:
|
|
|
|
+ Message({
|
|
|
|
+ message: '服务器关闭了!请联系相关工作人员',
|
|
|
|
+ type: 'error',
|
|
|
|
+ duration: 5 * 1000
|
|
|
|
+ })
|
|
|
|
+ removeToken()
|
|
|
|
+ resetRouter()
|
|
|
|
+ router.push('/login')
|
|
|
|
+ break
|
|
|
|
+ case 504:
|
|
|
|
+ console.log('服务器关闭了!')
|
|
|
|
+ resetRouter()
|
|
|
|
+ break
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ /* console.log('err' + error) // for debug
|
|
|
|
+ Message({
|
|
|
|
+ message: error.message,
|
|
|
|
+ type: 'error',
|
|
|
|
+ duration: 5 * 1000
|
|
|
|
+ })*/
|
|
|
|
+ return Promise.reject(error)
|
|
|
|
+ }
|
|
)
|
|
)
|
|
|
|
|
|
new Vue({
|
|
new Vue({
|
|
- el: '#app',
|
|
|
|
- router,
|
|
|
|
- store,
|
|
|
|
- render: h => h(App)
|
|
|
|
|
|
+ el: '#app',
|
|
|
|
+ router,
|
|
|
|
+ store,
|
|
|
|
+ render: h => h(App)
|
|
})
|
|
})
|
|
|
|
|
|
-export function test(){
|
|
|
|
|
|
+export function test() {
|
|
let sm2 = require('sm-crypto').sm2;
|
|
let sm2 = require('sm-crypto').sm2;
|
|
let cipherMode = 1
|
|
let cipherMode = 1
|
|
// 加密
|
|
// 加密
|
|
let encryptData = sm2.doEncrypt('1122加密', '0460ff8c8c306fe62f6f9d11c5c82c30d10bbbc703da094e423072cac7dc663c97fad52eccb34f311f47a07f280de157ba4f2aa659cabe749121384b9376ea2ed2', cipherMode);
|
|
let encryptData = sm2.doEncrypt('1122加密', '0460ff8c8c306fe62f6f9d11c5c82c30d10bbbc703da094e423072cac7dc663c97fad52eccb34f311f47a07f280de157ba4f2aa659cabe749121384b9376ea2ed2', cipherMode);
|
|
let sm3 = require('sm-crypto').sm2;
|
|
let sm3 = require('sm-crypto').sm2;
|
|
// 签名
|
|
// 签名
|
|
- let sign = sm3.doSignature('1122加密','6155d63ee27cbeca07f3e40c4f8856f1be8119fcbda1aadc7e0e595e52bad7bd')
|
|
|
|
|
|
+ let sign = sm3.doSignature('1122加密', '6155d63ee27cbeca07f3e40c4f8856f1be8119fcbda1aadc7e0e595e52bad7bd')
|
|
// 解密
|
|
// 解密
|
|
let sm4 = require('sm-crypto').sm2;
|
|
let sm4 = require('sm-crypto').sm2;
|
|
let doDecrypt = sm4.doDecrypt(encryptData, privateKey1, cipherMode);
|
|
let doDecrypt = sm4.doDecrypt(encryptData, privateKey1, cipherMode);
|
|
- alert('解密:'+doDecrypt)
|
|
|
|
|
|
+ alert('解密:' + doDecrypt)
|
|
// 验签
|
|
// 验签
|
|
let sm5 = require('sm-crypto').sm2;
|
|
let sm5 = require('sm-crypto').sm2;
|
|
let verifyResult = sm5.doVerifySignature(doDecrypt, sign, publicKey2) // 验签结果
|
|
let verifyResult = sm5.doVerifySignature(doDecrypt, sign, publicKey2) // 验签结果
|
|
- alert('验签:'+verifyResult)
|
|
|
|
|
|
+ alert('验签:' + verifyResult)
|
|
}
|
|
}
|
|
|
|
|
|
// 加密:
|
|
// 加密:
|
|
@@ -309,16 +283,16 @@ export function doSign(msgString) {
|
|
// 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
// 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
let cipherMode = 1
|
|
let cipherMode = 1
|
|
// 签名
|
|
// 签名
|
|
- let sign = sm2.doSignature(msgString,privateKey1, { hash:true, der:true })
|
|
|
|
|
|
+ let sign = sm2.doSignature(msgString, privateKey1, {hash: true, der: true})
|
|
return sign;
|
|
return sign;
|
|
}
|
|
}
|
|
|
|
|
|
// 验签
|
|
// 验签
|
|
-export function doVerifySignature(msgString,sigValueHex) {
|
|
|
|
|
|
+export function doVerifySignature(msgString, sigValueHex) {
|
|
let sm2 = require('sm-crypto').sm2;
|
|
let sm2 = require('sm-crypto').sm2;
|
|
// 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
// 1 - C1C3C2; 0 - C1C2C3; 默认为1
|
|
let cipherMode = 1
|
|
let cipherMode = 1
|
|
// 签名
|
|
// 签名
|
|
- let verifyResult = sm2.doVerifySignature(msgString, sigValueHex, publicKey2,{ hash:true, der:true }) // 验签结果
|
|
|
|
|
|
+ let verifyResult = sm2.doVerifySignature(msgString, sigValueHex, publicKey2, {hash: true, der: true}) // 验签结果
|
|
return verifyResult;
|
|
return verifyResult;
|
|
}
|
|
}
|