From b98be31d55cb5c473cc7687912bcce608609f727 Mon Sep 17 00:00:00 2001 From: lbw Date: Thu, 9 Feb 2023 18:17:31 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Introducing=20new=20features.=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=94=AF=E6=8C=81=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/gen/table.ts | 7 ++ src/components/verifition/utils/axios.js | 30 ------ src/hooks/table.ts | 27 +++-- src/utils/other.ts | 12 +++ src/utils/request.ts | 28 +++-- src/views/admin/log/index.vue | 15 +-- src/views/gen/table/edit.vue | 127 +++++++++++++++-------- 7 files changed, 143 insertions(+), 103 deletions(-) delete mode 100644 src/components/verifition/utils/axios.js diff --git a/src/api/gen/table.ts b/src/api/gen/table.ts index d9d93b92..7db9199d 100644 --- a/src/api/gen/table.ts +++ b/src/api/gen/table.ts @@ -59,3 +59,10 @@ export const useGeneratorPreviewApi = (tableId: any) => { params: { tableId: tableId } }) } + +export function fetchDictList() { + return request({ + url: '/admin/dict/list', + method: 'get' + }) +} diff --git a/src/components/verifition/utils/axios.js b/src/components/verifition/utils/axios.js deleted file mode 100644 index 9d58857d..00000000 --- a/src/components/verifition/utils/axios.js +++ /dev/null @@ -1,30 +0,0 @@ -import axios from 'axios'; - -axios.defaults.baseURL = 'https://captcha.anji-plus.com/captcha-api'; - -const service = axios.create({ - timeout: 40000, - headers: { - 'X-Requested-With': 'XMLHttpRequest', - 'Content-Type': 'application/json; charset=UTF-8' - }, -}) -service.interceptors.request.use( - config => { - return config - }, - error => { - Promise.reject(error) - } -) - -// response interceptor -service.interceptors.response.use( - response => { - const res = response.data; - return res - }, - error => { - } -) -export default service diff --git a/src/hooks/table.ts b/src/hooks/table.ts index 346b7c59..7daaf9d3 100644 --- a/src/hooks/table.ts +++ b/src/hooks/table.ts @@ -21,11 +21,7 @@ export interface BasicTableProps { // loading loading?: Boolean - selectObjs?: any[], - - descs?: string - - ascs?: string + selectObjs?: any[] } export interface Pagination { @@ -58,9 +54,7 @@ export function useTable(options?: BasicTableProps) { } as Pagination, dataListSelections: [], loading: false, - selectObjs: [], - descs: '', - ascs: '' + selectObjs: [] } const mergeDefaultOptions = (options: any, props: any): BasicTableProps => { @@ -83,8 +77,6 @@ export function useTable(options?: BasicTableProps) { ...state.queryForm, current: state.pagination?.current, size: state.pagination?.size, - descs: state.descs, - ascs: state.ascs }).then(res => { state.dataList = state.isPage ? res.data.records : res.data state.pagination!.total = state.isPage ? res.data.total : 0 @@ -114,6 +106,20 @@ export function useTable(options?: BasicTableProps) { query(); }; + // 排序触发事件 + const sortChangeHandle = (column: any) => { + const prop = other.toUnderline(column.prop); + if (column.order === 'descending') { + state.queryForm!.descs.push(prop) + state.queryForm!.ascs.splice(state.queryForm!.ascs.indexOf(prop), 1) + } + if (column.order === 'ascending') { + state.queryForm!.ascs.push(prop) + state.queryForm!.descs.splice(state.queryForm!.descs.indexOf(prop), 1) + } + query(); + } + const getDataList = () => { state.pagination!.current = 1 query() @@ -129,6 +135,7 @@ export function useTable(options?: BasicTableProps) { getDataList, sizeChangeHandle, currentChangeHandle, + sortChangeHandle, downBlobFile } diff --git a/src/utils/other.ts b/src/utils/other.ts index 0b8c56f5..fd5dcbf2 100644 --- a/src/utils/other.ts +++ b/src/utils/other.ts @@ -286,6 +286,9 @@ const other = { }, downBlobFile: (url: any, query: any, fileName: string) => { return downBlobFile(url, query, fileName) + }, + toUnderline: (str: string) => { + return toUnderline(str) } }; @@ -321,5 +324,14 @@ export function handleTree(data, id, parentId, children, rootId) { return treeData !== '' ? treeData : data } +/** + * + * @param str 驼峰转下划线 + * @returns 下划线 + */ +export function toUnderline(str: string) { + return str.replace(/([A-Z])/g, "_$1").toLowerCase() +} + // 统一批量导出 export default other; diff --git a/src/utils/request.ts b/src/utils/request.ts index e0c9b15c..baeb3ba5 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,29 +1,35 @@ -import axios, {AxiosInstance, InternalAxiosRequestConfig} from 'axios'; +import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios'; import errorCode from './errorCode' -import {ElMessage, ElMessageBox} from 'element-plus'; -import {Session} from '/@/utils/storage'; +import { ElMessage, ElMessageBox } from 'element-plus'; +import { Session } from '/@/utils/storage'; import qs from 'qs'; // 配置新建一个 axios 实例 const service: AxiosInstance = axios.create({ baseURL: import.meta.env.VITE_API_URL, timeout: 50000, - headers: {'Content-Type': 'application/json'}, + headers: { 'Content-Type': 'application/json' }, paramsSerializer: { serialize(params) { - return qs.stringify(params, {allowDots: true}); + return qs.stringify(params, { allowDots: true }); }, }, }); // 添加请求拦截器 service.interceptors.request.use((config: InternalAxiosRequestConfig) => { - // 在发送请求之前做些什么 token - if (Session.get('token')) { - config.headers!['Authorization'] = `Bearer ${Session.get('token')}`; + // get查询参数序列化 + if (config.method === 'get') { + config.paramsSerializer = (params: any) => { + return qs.stringify(params, { arrayFormat: 'repeat' }) } - return config; - }, + } + // 在发送请求之前做些什么 token + if (Session.get('token')) { + config.headers!['Authorization'] = `Bearer ${Session.get('token')}`; + } + return config; +}, (error) => { // 对请求错误做些什么 return Promise.reject(error); @@ -32,7 +38,7 @@ service.interceptors.request.use((config: InternalAxiosRequestConfig) => { // 添加响应拦截器 service.interceptors.response.use((res: any) => { - if(res.data.code === 1){ + if (res.data.code === 1) { throw res.data } return res.data; diff --git a/src/views/admin/log/index.vue b/src/views/admin/log/index.vue index bec1964f..b0890213 100644 --- a/src/views/admin/log/index.vue +++ b/src/views/admin/log/index.vue @@ -36,7 +36,7 @@ + @selection-change="handleSelectionChange" @sort-change="sortChangeHandle"> @@ -46,11 +46,11 @@ - - + - + - - - - - - - + - - - - - - - - - + - + - + - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + +