前端封装添加签名计算,修改接口传输的数据类型

pull/236/head
13066656961 2024-07-25 14:32:04 +08:00
parent ce6b0634f5
commit 96a7465e12
5 changed files with 22 additions and 5 deletions

View File

@ -12,3 +12,5 @@ VITE_PORT = 81
# 开启设置抽屉 # 开启设置抽屉
VITE_SET_DRAWER = true VITE_SET_DRAWER = true
VITE_APP_ID = wxd504412d92c5ffe7
VITE_APP_KEY = 0c7bf34850bb54158d261e5914e807ee

View File

@ -12,3 +12,5 @@ VITE_PORT = 81
# 开启设置抽屉 # 开启设置抽屉
VITE_SET_DRAWER = false VITE_SET_DRAWER = false
VITE_APP_ID = wxd504412d92c5ffe7
VITE_APP_KEY = 0c7bf34850bb54158d261e5914e807ee

View File

@ -54,7 +54,8 @@
"vue-router": "4.3.0", "vue-router": "4.3.0",
"vue3-colorpicker": "2.3.0", "vue3-colorpicker": "2.3.0",
"vue3-tree-org": "4.2.2", "vue3-tree-org": "4.2.2",
"vuedraggable-es": "4.1.1" "vuedraggable-es": "4.1.1",
"crypto-js": "4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/eslint-parser": "7.19.1", "@babel/eslint-parser": "7.19.1",

View File

@ -14,7 +14,7 @@ import qs from 'qs'
import { Modal, message, notification } from 'ant-design-vue' import { Modal, message, notification } from 'ant-design-vue'
import sysConfig from '@/config/index' import sysConfig from '@/config/index'
import tool from '@/utils/tool' import tool from '@/utils/tool'
import CryptoUtil from './cryptoUtil'
// 以下这些code需要重新登录 // 以下这些code需要重新登录
const reloadCodes = [401, 1011007, 1011008] const reloadCodes = [401, 1011007, 1011008]
const errorCodeMap = { const errorCodeMap = {
@ -41,15 +41,27 @@ const service = axios.create({
// HTTP request 拦截器 // HTTP request 拦截器
service.interceptors.request.use( service.interceptors.request.use(
(config) => { (config) => {
Object.assign(config.headers, sysConfig.HEADERS)
const token = tool.data.get('TOKEN') const token = tool.data.get('TOKEN')
if (token) { if (token) {
config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token config.headers[sysConfig.TOKEN_NAME] = sysConfig.TOKEN_PREFIX + token
} }
const appTime = new Date().getTime()
if (!sysConfig.REQUEST_CACHE && config.method === 'get') { if (!sysConfig.REQUEST_CACHE && config.method === 'get') {
config.params = config.params || {} config.params = config.params || {}
config.params._ = new Date().getTime() config.params.appTime = appTime
config.params.appId = import.meta.env.VITE_APP_ID
} else {
config.data = config.data || {}
config.data.appTime = appTime
config.data.appId = import.meta.env.VITE_APP_ID
}
const bodyString = CryptoUtil.objectKeySort(Object.assign({}, config.params, config.data))
const sign = CryptoUtil.makeSign(import.meta.env.VITE_APP_ID, import.meta.env.VITE_APP_KEY, bodyString)
config.headers['appSign'] = sign
if (config.data) {
config.data = qs.stringify(config.data)
} }
Object.assign(config.headers, sysConfig.HEADERS)
return config return config
}, },
(error) => { (error) => {

View File

@ -78,7 +78,7 @@ public class AuthController {
**/ **/
@Operation(summary = "B端账号密码登录") @Operation(summary = "B端账号密码登录")
@PostMapping("/auth/b/doLogin") @PostMapping("/auth/b/doLogin")
public CommonResult<String> doLogin(@RequestBody @Valid AuthAccountPasswordLoginParam authAccountPasswordLoginParam) { public CommonResult<String> doLogin(@Valid AuthAccountPasswordLoginParam authAccountPasswordLoginParam) {
return CommonResult.data(authService.doLogin(authAccountPasswordLoginParam, SaClientTypeEnum.B.getValue())); return CommonResult.data(authService.doLogin(authAccountPasswordLoginParam, SaClientTypeEnum.B.getValue()));
} }