diff --git a/src/api/login.js b/src/api/login.js index 40a6b89c..899b1311 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -13,6 +13,18 @@ export function login(data) { }) } +export function isLogin(data) { + return request({ + url: '/auth/isLogin', + headers: { + isToken: false, + repeatSubmit: false + }, + method: 'post', + data: data + }) +} + export function getPhoneCode(payload) { return request({ url: '/auth/getPhoneCode', diff --git a/src/store/modules/user.js b/src/store/modules/user.js index bf062950..fdede50d 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -1,4 +1,4 @@ -import { login, logout, getInfo, refreshToken, getPhoneCode } from '@/api/login' +import { login, logout, getInfo, refreshToken, getPhoneCode, isLogin } from '@/api/login' import { getToken, setToken, setExpiresIn, removeToken } from '@/utils/auth' const user = { @@ -36,6 +36,34 @@ const user = { }, actions: { + IsLogin({ commit }, userInfo) { + let payload = {} + const loginType = userInfo.loginType + if (loginType === 'password') { + payload = { + username: userInfo.username.trim(), + password: userInfo.password, + uuid: userInfo.uuid, + code: userInfo.code, + loginType: loginType + } + } else if (loginType === 'mobile') { + payload = { + mobile: userInfo.mobile.trim(), + verificationCode: userInfo.verificationCode, + uuid: userInfo.uuid, + code: userInfo.code, + loginType: loginType + } + } + return new Promise((resolve, reject) => { + isLogin(payload).then(res => { + resolve(res); + }).catch(error => { + reject(error) + }) + }) + }, // 登录 Login({ commit }, userInfo) { let payload = {} @@ -78,7 +106,6 @@ const user = { code: userInfo.code, mobileCodeType: userInfo.mobileCodeType } - console.log(payload) return new Promise((resolve, reject) => { getPhoneCode(payload).then(res => { resolve() diff --git a/src/utils/request.js b/src/utils/request.js index 2e81233f..7a847ce2 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -7,7 +7,8 @@ import { blobValidate, tansParams } from '@/utils/bonus' import cache from '@/plugins/cache' import { saveAs } from 'file-saver' import { decryptCBC, encryptCBC } from '@/utils/aescbc' -import { hashWithSM3AndSalt } from '@/utils/sm' // 导入SM3哈希函数 +import { hashWithSM3AndSalt } from '@/utils/sm' +import data from '@/views/system/dict/data.vue' // 导入SM3哈希函数 let downloadLoadingInstance export let isRelogin = { show: false } @@ -37,7 +38,7 @@ service.interceptors.request.use( if (param) { param = param.slice(0, -1) param = encryptCBC(param) - /* config.headers['Params-Hash'] = hashWithSM3AndSalt(param) */ + /* config.headers['Params-Hash'] = hashWithSM3AndSalt(param) */ } config.url = `${config.url}?${param}` config.params = {} @@ -91,11 +92,11 @@ service.interceptors.request.use( formData = formData.slice(0, -1) config.data = encryptCBC(formData) console.log(config.data) - /* config.headers['Params-Hash'] = hashWithSM3AndSalt(config.data) */ // 添加参数哈希到请求头 + /* config.headers['Params-Hash'] = hashWithSM3AndSalt(config.data) */ // 添加参数哈希到请求头 } } else { config.data = encryptCBC('formData=' + JSON.stringify(config.data)) - /* config.headers['Params-Hash'] = hashWithSM3AndSalt(config.data) */ // 添加参数哈希到请求头 + /* config.headers['Params-Hash'] = hashWithSM3AndSalt(config.data) */ // 添加参数哈希到请求头 } } @@ -117,12 +118,12 @@ service.interceptors.request.use( service.interceptors.response.use( (res) => { // 自动解密响应数据 - if (res.data.decrypt) { + /* if (res.data.decrypt) { res.data = JSON.parse(decryptCBC(res.data.data)) } else if (typeof res.data.code === 'undefined') { res.data = res.data.data - } - + } */ + console.log(res.data.code) // 获取状态码 const code = res.data.code || 200 const msg = errorCode[code] || res.data.msg || errorCode['default'] @@ -150,6 +151,7 @@ service.interceptors.response.use( } return Promise.reject('无效的会话,或者会话已过期,请重新登录。') } else if (code === 500) { + console.log(data) Message({ message: msg, type: 'error' }) return Promise.reject(new Error(msg)) } else if (code === 601) { @@ -191,7 +193,7 @@ export function download(url, params, filename, config) { transformRequest: [(params) => params], headers: { 'Content-Type': 'application/x-www-form-urlencoded' - /* 'Params-Hash': hashWithSM3AndSalt(params) */ + /* 'Params-Hash': hashWithSM3AndSalt(params) */ }, responseType: 'blob', ...config diff --git a/src/views/login1.vue b/src/views/login1.vue index 46cf73c7..d9e6fe27 100644 --- a/src/views/login1.vue +++ b/src/views/login1.vue @@ -67,7 +67,7 @@ - +