From 1661d7951e4b1e4da695e8677d93016986f77daf Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Thu, 22 Jan 2026 15:54:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/DesignForm/requestapi.ts | 2 +- src/utils/axiosRequest/request.ts | 102 ++++++++++++++++++ src/utils/encryptionAndDecryption/sm4Utils.ts | 5 - src/utils/loadSvgFile.ts | 14 +++ src/utils/request.ts | 19 ++-- src/utils/request123.ts | 1 + src/utils/validate.ts | 32 ++++++ src/views/hr/company/orgPeopleNew.vue | 8 +- 8 files changed, 166 insertions(+), 17 deletions(-) create mode 100644 src/utils/axiosRequest/request.ts create mode 100644 src/utils/loadSvgFile.ts create mode 100644 src/utils/validate.ts diff --git a/src/api/DesignForm/requestapi.ts b/src/api/DesignForm/requestapi.ts index dcd1fd3..8d45bac 100644 --- a/src/api/DesignForm/requestapi.ts +++ b/src/api/DesignForm/requestapi.ts @@ -654,4 +654,4 @@ export function savePrintTemplate(data: any) { method: 'post', data: data }); -} \ No newline at end of file +} diff --git a/src/utils/axiosRequest/request.ts b/src/utils/axiosRequest/request.ts new file mode 100644 index 0000000..8933393 --- /dev/null +++ b/src/utils/axiosRequest/request.ts @@ -0,0 +1,102 @@ +/** +@ 作者: 秦东 +@ 时间: 2025-12-09 10:57:37 +@ 功能: 封装axios请求 +*/ +import axios, { AxiosError, type InternalAxiosRequestConfig } from 'axios' +import { ElMessage, ElMessageBox } from 'element-plus' +import { generateRandomString } from '@/utils/encryptionAndDecryption/randNumber' +import { sm4DecryptMethod, sm4EncryptMethod } from '@/utils/encryptionAndDecryption/sm4Utils' +import { useUserStore } from '@/stores/user' +/** +@ 作者: 秦东 +@ 时间: 2025-12-09 10:58:34 +@ 功能: 创建axios实例 +*/ +const service = axios.create({ + baseURL: import.meta.env.VITE_APP_BASE_API, + timeout: 5000 +}) + +/** +@ 作者: 秦东 +@ 时间: 2025-12-09 11:00:05 +@ 功能: 请求拦截 +*/ +service.interceptors.request.use( + (config: InternalAxiosRequestConfig) => { + const userStore = useUserStore() + // if (config.headers['content-type'] === 'application/json') { + let { data, headers } = config + console.log('请求拦截----data---1--->', data) + if (userStore.authToken) { + config.headers['Auth-token'] = userStore.authToken + } + //获取16位随机数 + let randomString = generateRandomString(16) + config.headers['Auth-key'] = randomString + if (data) { + // 加密请求数据 + config.data = { + encryptedFile: sm4EncryptMethod(JSON.stringify(data), randomString) + } + } + console.log('请求拦截---------->', randomString) + console.log('请求拦截----headers------>', headers) + console.log('请求拦截----data------>', config.data) + console.log('请求拦截----config------>', config) + // } + + // console.log('请求拦截----content-type------>', config.headers['Content-Type']) + // console.log('请求拦截----config------>', config.headers) + return config + }, + (error: AxiosError) => { + return Promise.reject(error) + } +) +/** +@ 作者: 秦东 +@ 时间: 2025-12-09 21:00:20 +@ 备注: 响应拦截 +*/ +service.interceptors.response.use( + response => { + console.log('行营结果---------->', response) + let { data, headers } = response + // console.log('行营结果----data------>', data.data) + let authKey = headers['auth-key'] + console.log('行营结果----authKey------>', authKey) + // 解密响应数据 + if (authKey) { + let jsonData = sm4DecryptMethod(data.data, authKey) + response.data.data = JSON.parse(jsonData) + } + console.log('行营结果----解密结构------>', headers['auth-key'], response) + return response.data + }, + (error: AxiosError) => { + if (error.response) { + const status = error.response.status + switch (status) { + case 401: + // 处理401错误,例如跳转到登录页 + break + case 403: + // 处理403错误,例如提示无权限 + break + case 404: + // 处理404错误,例如提示资源不存在 + break + case 500: + // 处理500错误,例如提示服务器错误 + break + default: + // 处理其他错误 + break + } + } + return Promise.reject(error) + } +) +export default service diff --git a/src/utils/encryptionAndDecryption/sm4Utils.ts b/src/utils/encryptionAndDecryption/sm4Utils.ts index 6ea8840..4a764e6 100644 --- a/src/utils/encryptionAndDecryption/sm4Utils.ts +++ b/src/utils/encryptionAndDecryption/sm4Utils.ts @@ -63,11 +63,6 @@ const sm4DecryptMethod = (data: string, customKey: string): string => { console.log('SM4解密方法----解密结构--ivSetup---->', ivSetup) console.log('SM4解密方法----解密结构---sm4TokenKey--->', sm4TokenKey) console.log('SM4解密方法----解密结构---appSystemKey--->', appSystemKey) - - console.log('SM4解密方法----解密结构---appSystemKey.length--->', appSystemKey.length) - console.log('SM4解密方法----解密结构---ivSetup.length--->', ivSetup.length) - - return sm4.decrypt(data, appSystemKey, { iv: ivSetup, mode: sm4.constants.CBC, diff --git a/src/utils/loadSvgFile.ts b/src/utils/loadSvgFile.ts new file mode 100644 index 0000000..83f4e46 --- /dev/null +++ b/src/utils/loadSvgFile.ts @@ -0,0 +1,14 @@ +/** +@ 作者: 秦东 +@ 时间: 2026-01-09 15:57:48 +@ 功能: 加载svg文件 +*/ +export const loadSvgFiles = (): string[] => { + const icons = import.meta.glob('../assets/icons/*.svg') + const svgIcons: string[] = [] + for (const icon in icons) { + const iconName = icon.split('assets/icons/')[1].split('.svg')[0] + svgIcons.push(iconName) + } + return svgIcons +} diff --git a/src/utils/request.ts b/src/utils/request.ts index 73dc9da..eba1ce4 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -40,7 +40,10 @@ service.interceptors.request.use( if (userStore.userToken) { config.headers["user-token"] = userStore.userToken; } - + console.error('<---------------请求拦截---------->') + console.error('请求拦截----config------>', config.url) + console.error('请求拦截----data------>', config.data) + console.error('<---------------请求拦截---------->') // if (config.headers['content-type'] === 'application/json') { let { data, headers } = config //获取16位随机数 @@ -52,10 +55,10 @@ service.interceptors.request.use( data: sm4EncryptMethod(JSON.stringify(data), randomString) } } - console.log('请求拦截---------->', randomString) - console.log('请求拦截----headers------>', headers) - console.log('请求拦截----data------>', config.data) - console.log('请求拦截----config------>', config) + // console.log('请求拦截---------->', randomString) + // console.log('请求拦截----headers------>', headers) + // console.log('请求拦截----data------>', config.data) + // console.log('请求拦截----config------>', config) // } // console.log('请求拦截----content-type------>', config.headers['Content-Type']) @@ -76,13 +79,15 @@ service.interceptors.response.use( let { data, headers } = response let authKey = headers['auth-key'] - console.log('行营结果----authKey------>', authKey) + // console.log('行营结果----authKey------>', authKey) // 解密响应数据 if (authKey) { let jsonData = sm4DecryptMethod(data.data, authKey) response.data.data = JSON.parse(jsonData) } - console.log('行营结果----解密结构------>', headers['auth-key'], response) + console.error('行营结果----解密结构------>', response.config.url) + console.error('行营结果----解密结构------>', response.data) + // console.log('行营结果----解密结构------>', headers['auth-key'], response) const { code, msg } = response.data; if (code === 0 || code === 200 || code === 10001) { return response.data; diff --git a/src/utils/request123.ts b/src/utils/request123.ts index 9e950b0..22ae507 100644 --- a/src/utils/request123.ts +++ b/src/utils/request123.ts @@ -4,6 +4,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'; import router from '@/router'; import { useRouter } from 'vue-router' import { generateRandomString } from '@/utils/encryptionAndDecryption/randNumber' +import { sm4DecryptMethod, sm4EncryptMethod } from './encryptionAndDecryption/sm4Utils'; const routerPinia = useRouter() diff --git a/src/utils/validate.ts b/src/utils/validate.ts new file mode 100644 index 0000000..9277d7e --- /dev/null +++ b/src/utils/validate.ts @@ -0,0 +1,32 @@ +/** +@ 作者: 秦东 +@ 时间: 2025-12-29 16:00:55 +@ 功能: 路径匹配器 + * @param {string} pattern + * @param {string} path + * @returns {Boolean} +*/ +export const isPathMatch = (pattern: string, path: string): boolean => { + const regexPattern = pattern + .replace(/\//g, '\\/') + .replace(/\*\*/g, '.*') + .replace(/\*/g, '[^\\/]*') + const regex = new RegExp(`^${regexPattern}$`) + return regex.test(path) +} +/** +@ 作者: 秦东 +@ 时间: 2025-12-29 16:02:21 +@ 功能: 判断字符串是否为空 +*/ +export const isEmptyString = (str: string): boolean => { + return str.trim().length === 0 +} +/** +@ 作者: 秦东 +@ 时间: 2025-12-29 16:03:14 +@ 功能: 判断url是否是http或https +*/ +export const isHttpOrHttpsUrl = (url: string): boolean => { + return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1 +} diff --git a/src/views/hr/company/orgPeopleNew.vue b/src/views/hr/company/orgPeopleNew.vue index 6682d6f..b2e8cb8 100644 --- a/src/views/hr/company/orgPeopleNew.vue +++ b/src/views/hr/company/orgPeopleNew.vue @@ -41,14 +41,14 @@ const props = defineProps({ }, }); //已选择的数据 -const pickUserAry = ref(props.orgInfo ? props.orgInfo : []); -const pickUserKeyAry = ref(props.orgKey ? props.orgKey : []); +const pickUserAry = ref(props.orgInfo ? props.orgInfo : []); +const pickUserKeyAry = ref(props.orgKey ? props.orgKey : []); const loading = ref(false); const emits = defineEmits([ "update:isOpen", "update:orgKey", "update:orgInfo", - "subitRefresh", + "subitRefresh", 'update:isShow', ]); const openPage = computed({ get() { @@ -63,7 +63,7 @@ const openPage = computed({ const currOrgManList = ref([]); const loadTable = ref(false); const totalCount = ref(0); //一共多少数据 -const peopleAry = ref([]); //人员列表 +const peopleAry = ref([]); //人员列表 //获取行政组织 const getOrgTreeSub = () => { currOrgManList.value = [];