From 08c3874947189b1370fc23ddf5efee2eebf78189 Mon Sep 17 00:00:00 2001 From: bb_pan Date: Fri, 7 Feb 2025 16:27:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8A=A0=E5=AF=86=E4=B8=8E?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 14 +++++ package.json | 1 + src/http/index.ts | 25 +++++++- src/layout/header.vue | 33 +++++++---- src/utils/bonus.ts | 25 ++++++++ src/utils/configure.ts | 23 ++++++++ src/utils/sm.ts | 57 +++++++++++++++++++ src/views/user/index.vue | 8 ++- .../components/order-home.vue | 3 +- 9 files changed, 172 insertions(+), 17 deletions(-) create mode 100644 src/utils/bonus.ts create mode 100644 src/utils/configure.ts create mode 100644 src/utils/sm.ts diff --git a/package-lock.json b/package-lock.json index 059ae00..64d4b5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "pinia": "^2.1.7", "pinia-plugin-persist": "^1.0.0", "quill": "^2.0.3", + "sm-crypto": "^0.3.13", "tinymce": "^7.6.0", "vite-plugin-html": "^3.2.0", "vite-plugin-zip-file": "^2.2.0", @@ -4456,6 +4457,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sm-crypto": { + "version": "0.3.13", + "resolved": "https://registry.npmmirror.com/sm-crypto/-/sm-crypto-0.3.13.tgz", + "integrity": "sha512-ztNF+pZq6viCPMA1A6KKu3bgpkmYti5avykRHbcFIdSipFdkVmfUw2CnpM2kBJyppIalqvczLNM3wR8OQ0pT5w==", + "dependencies": { + "jsbn": "^1.1.0" + } + }, + "node_modules/sm-crypto/node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==" + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://repo.huaweicloud.com/repository/npm/source-map/-/source-map-0.6.1.tgz", diff --git a/package.json b/package.json index 72318e3..432011c 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "pinia": "^2.1.7", "pinia-plugin-persist": "^1.0.0", "quill": "^2.0.3", + "sm-crypto": "^0.3.13", "tinymce": "^7.6.0", "vite-plugin-html": "^3.2.0", "vite-plugin-zip-file": "^2.2.0", diff --git a/src/http/index.ts b/src/http/index.ts index 6152d9a..3b0a36b 100644 --- a/src/http/index.ts +++ b/src/http/index.ts @@ -6,6 +6,8 @@ import NProgress from 'nprogress' import { ElMessage } from 'element-plus' import { saveAs } from 'file-saver' import router from '@/router' +import { tansParams } from '@/utils/bonus' +import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm' // const store = mainStore() // const CancelToken = axios.CancelToken @@ -22,9 +24,28 @@ const service = axios.create({ timeout: 60000, }) +// 请求拦截 service.interceptors.request.use( (config) => { config.headers['Authorization'] = localStorage.getItem('tokenNew') + // 入参是否加密 + config.headers['encryptRequest'] = 'true' + // 数据完整性校验 + config.headers['checkIntegrity'] = 'true' + // 回参是否加密 + config.headers['encryptResponse'] = 'true' + + // 对请求数据进行加密 + if (config.method === 'get' && config.params) { + let url = config.url + '?' + tansParams(config.params) + url = url.slice(0, -1) + config.params = {} + config.url = url + } + if (config.data) { + let data = typeof config.data === 'object' ? JSON.stringify(config.data) : config.data + config.data = encryptWithSM4(data+"|"+hashWithSM3AndSalt(data)) + } return config }, (error) => { @@ -35,7 +56,9 @@ service.interceptors.request.use( service.interceptors.response.use( (res) => { ElMessage.closeAll() - const { data } = res + // const { data } = res + const data = JSON.parse(decryptWithSM4(res.data)) + // console.log('🚀 ~ data:', data) if (data.code == '200') { return data } else if (data.code == '403') { diff --git a/src/layout/header.vue b/src/layout/header.vue index c966208..2fada90 100644 --- a/src/layout/header.vue +++ b/src/layout/header.vue @@ -32,6 +32,7 @@ const activeLoginCompanyName = ref('') const searchCheckVisible = ref(false) import { storeToRefs } from 'pinia' const { userInfo, token }: any = storeToRefs(store) +const tokenNew = localStorage.getItem('tokenNew') if (roles?.length > 0) { isAdmin.value = roles.some((e: any) => e.roleKey == 'admin') } @@ -52,12 +53,13 @@ watch(userInfo, (newValue, oldCount) => { }) } }) -watch(token, (newValue, oldCount) => { - if (newValue) { - getUserListData() - getBookCarDetailsData() - } -}) +// watch(token, (newValue, oldCount) => { +// if (newValue) { +// getUserListData() +// getBookCarDetailsData() +// } +// }) +// 监听 tokenNew 有值时请求用户信息 const setActiveCompanyName = () => { // const companyList = userStore.companyList @@ -244,10 +246,14 @@ const onSelectRoles = (type: number) => { const getBookCarDetailsData = async () => { const res: any = await getBookCarDetailsApi() + console.log('🚀 ~ getBookCarDetailsData ~ res:', res) let amountNum = 0 - res.data.forEach((e: any) => { - amountNum = e.devInfoVoList.length + amountNum - }) + if (res.data && res.data.length > 0) { + res.data.forEach((e: any) => { + amountNum = e.devInfoVoList.length + amountNum + console.log('🚀 ~ res.data.forEach ~ amountNum:', amountNum) + }) + } cart.SET_CART_NUM(amountNum) } const cartNum = computed(() => { @@ -372,9 +378,12 @@ const resetPhone = async () => { }) } -// onMounted(() => { -// circleUrl.value = store.userInfo.avatar -// }) +onMounted(() => { + if (tokenNew) { + getUserListData() + getBookCarDetailsData() + } +})