From 3670ae3ae759ce2291a547a04843bcdffe987bc9 Mon Sep 17 00:00:00 2001
From: mxf <547087214@qq.com>
Date: Thu, 31 Aug 2023 16:14:28 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8B=A6=E6=88=AA=E5=99=A8?=
=?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8apifox=E6=A8=A1=E6=8B=9F=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 3 +-
src/components/my-table.vue | 11 +-
src/demo/index.vue | 39 ++++
src/demo/my-table-demo.vue | 184 ++++++++++--------
src/demo/my-table.d.ts | 12 ++
src/service/api.ts | 6 +
src/service/axios.ts | 10 -
src/service/interceptors.ts | 35 +++-
src/service/request.ts | 32 +++
.../auto-import/auto-import-components.d.ts | 1 +
src/types/auto-import/auto-import.d.ts | 1 +
src/types/my-table.d.ts | 24 +--
tsconfig.app.json | 1 +
vite.config.ts | 3 +
14 files changed, 256 insertions(+), 106 deletions(-)
create mode 100644 src/demo/my-table.d.ts
create mode 100644 src/service/api.ts
delete mode 100644 src/service/axios.ts
create mode 100644 src/service/request.ts
diff --git a/package.json b/package.json
index dbb564a..8dc65ac 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,8 @@
"dev": "vite",
"preview": "vite preview",
"build": "vite build",
- "deploy": "push-dir --dir=dist --branch=gh-pages --cleanup"
+ "deploy": "push-dir --dir=dist --branch=gh-pages --cleanup",
+ "test": "rm -rf dist && echo 'del success' "
},
"dependencies": {
"@types/lodash": "^4.14.195",
diff --git a/src/components/my-table.vue b/src/components/my-table.vue
index 121adc6..67e2e4f 100644
--- a/src/components/my-table.vue
+++ b/src/components/my-table.vue
@@ -27,7 +27,7 @@ import type {isShowType} from '../types/my-table.d'
})
console.log(props,'props');
- const emits = defineEmits(['selectChange','pagination'])
+ const emits = defineEmits(['selectChange','paginationFn'])
// const pageSize = ref(props.limit)
// const currentPage = ref(props.pageNum)
@@ -58,11 +58,11 @@ import type {isShowType} from '../types/my-table.d'
}
const currentChange = (val:number) => {
// currentPage.value = val
- emits('pagination',{pageNum:val,pageSize:pageSize.value})
+ emits('paginationFn',{pageNum:val,pageSize:pageSize.value})
}
const sizeChange = (val:number) => {
// pageSize.value = val
- emits('pagination',{pageSize:val,pageNum:currentPage.value})
+ emits('paginationFn',{pageSize:val,pageNum:currentPage.value})
}
@@ -99,7 +99,12 @@ import type {isShowType} from '../types/my-table.d'
+
+
+
+
+
@@ -31,6 +65,11 @@ import router from '@/router';
width: 100vw;
padding-top: 20px;
+ .my-log {
+ width: 200px;
+ height: 200px;
+ margin: 20px 0;
+ }
}
}
diff --git a/src/demo/my-table-demo.vue b/src/demo/my-table-demo.vue
index efd266f..d6eddb9 100644
--- a/src/demo/my-table-demo.vue
+++ b/src/demo/my-table-demo.vue
@@ -1,75 +1,95 @@
@@ -84,15 +104,12 @@
:pageNum="currentPage"
:limit="limit"
:pageSizes="[1,2,3,4]"
- :dataTotal="tableData.length"
+ :dataTotal="total"
@selectChange="selectChange"
- @pagination="getList"
+ @paginationFn="getListFn"
>
-
- {{scope.row[scope.column.property]}}
-
+
+ {{scope.row[scope.column.property]}}
+
+
{{ scope.row[scope.column.property] === '1' ? '男' : '女' }}
@@ -110,8 +131,8 @@
- 详情
- 删除
+ 详情
+ 删除
@@ -131,6 +152,13 @@
width: 1000px;
border: 1px solid red;
padding-bottom: 50px;
+ .column-text {
+ margin-left: 20px;
+ }
+ .opreate {
+ font-size: 12px;
+ padding-right: 20px;
+ }
}
diff --git a/src/demo/my-table.d.ts b/src/demo/my-table.d.ts
new file mode 100644
index 0000000..abd2a23
--- /dev/null
+++ b/src/demo/my-table.d.ts
@@ -0,0 +1,12 @@
+export interface tableDataType {
+ id:number,
+ name:string,
+ description:string,
+ is_use:number,
+ sex: number
+ }
+
+export interface pagenationType {
+ pageSize: number,
+ pageNum: number,
+}
diff --git a/src/service/api.ts b/src/service/api.ts
new file mode 100644
index 0000000..6953809
--- /dev/null
+++ b/src/service/api.ts
@@ -0,0 +1,6 @@
+import { httpReq } from "@/service/request";
+
+const commonApi = {
+ getList:(params?: any) => httpReq.get("/list", {params})
+}
+export default commonApi;
diff --git a/src/service/axios.ts b/src/service/axios.ts
deleted file mode 100644
index f7edc24..0000000
--- a/src/service/axios.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import axios from 'axios'
-import type { AxiosInstance } from 'axios'
-
-const service:AxiosInstance = axios.create({
- baseURL: 'http://localhost:4523',
- timeout: 5000
-})
-
-
-export default service
\ No newline at end of file
diff --git a/src/service/interceptors.ts b/src/service/interceptors.ts
index e382745..48f7afc 100644
--- a/src/service/interceptors.ts
+++ b/src/service/interceptors.ts
@@ -1,3 +1,34 @@
-import service from "@/service/axios";
-import type { AxiosError,AxiosRequestConfig,AxiosResponse } from "axios";
+import axios from 'axios';
+import type { AxiosError,AxiosResponse,InternalAxiosRequestConfig,AxiosInstance } from "axios";
+
+const service:AxiosInstance = axios.create({
+ // baseURL: 'http://localhost:4523',
+ baseURL: 'http://127.0.0.1:4523/m1/2897880-0-default',
+ timeout: 5000
+});
+
+var loadingInstance:any = null;
+
+service.interceptors.request.use((config:InternalAxiosRequestConfig) => {
+ loadingInstance = ElLoading.service({ fullscreen: true });
+ return config;
+},(error:AxiosError) => {
+ return Promise.reject(error);
+});
+
+service.interceptors.response.use((response:AxiosResponse) => {
+ loadingInstance.close();
+ const {data,message,code} = response.data;
+ if(code === 0){
+ return data
+ } else {
+ ElMessage.error(message);
+ return Promise.reject(message);
+ }
+},(error:any) => {
+ loadingInstance.close();
+ return Promise.reject(error);
+});
+
+export default service;
\ No newline at end of file
diff --git a/src/service/request.ts b/src/service/request.ts
new file mode 100644
index 0000000..4d4b86d
--- /dev/null
+++ b/src/service/request.ts
@@ -0,0 +1,32 @@
+import service from '@/service/interceptors'
+
+export interface apiResult {
+ code: number,
+ message: string,
+ data: T
+}
+
+export const httpReq = {
+ get: (url:string,config?:any):Promise => {
+ return service.get(url,config)
+ }
+}
+
+export async function get(url: string, params?: any): Promise> {
+ const response = await service.get>(url, { params });
+ return response.data;
+}
+export async function post(url: string, data?: any): Promise> {
+ const response = await service.post>(url, data);
+ return response.data;
+ }
+
+export async function put(url: string, data?: any): Promise> {
+ const response = await service.put>(url, data);
+ return response.data;
+}
+
+export async function del(url: string, params?: any): Promise> {
+ const response = await service.delete>(url, { params });
+ return response.data;
+}
diff --git a/src/types/auto-import/auto-import-components.d.ts b/src/types/auto-import/auto-import-components.d.ts
index 671e176..f741a6b 100644
--- a/src/types/auto-import/auto-import-components.d.ts
+++ b/src/types/auto-import/auto-import-components.d.ts
@@ -10,6 +10,7 @@ export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
ElButton: typeof import('element-plus/es')['ElButton']
+ ElEmpty: typeof import('element-plus/es')['ElEmpty']
ElLink: typeof import('element-plus/es')['ElLink']
ElPagination: typeof import('element-plus/es')['ElPagination']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
diff --git a/src/types/auto-import/auto-import.d.ts b/src/types/auto-import/auto-import.d.ts
index 7b8b1ab..b480186 100644
--- a/src/types/auto-import/auto-import.d.ts
+++ b/src/types/auto-import/auto-import.d.ts
@@ -5,6 +5,7 @@
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope']
+ const ElLoading: typeof import('element-plus/es')['ElLoading']
const ElMessage: typeof import('element-plus/es')['ElMessage']
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const computed: typeof import('vue')['computed']
diff --git a/src/types/my-table.d.ts b/src/types/my-table.d.ts
index c240dc1..3bbf715 100644
--- a/src/types/my-table.d.ts
+++ b/src/types/my-table.d.ts
@@ -1,18 +1,18 @@
-// my-table.ts
-
export interface isShowType {
sortShow: boolean
selectionShow: boolean
detailShow: boolean
}
-// interface Props {
-// tableData: Array
-// tableHeader: Array
-// isShow: isShowType
-// limit: number
-// pageNum: number
-// pagination: string
-// pageSizes: Array
-// dataTotal: number
-// }
\ No newline at end of file
+export interface tableDataType {
+ id:number,
+ name:string,
+ description:string,
+ is_use:number,
+ sex: number
+}
+
+export interface pagenationType {
+ pageSize: number,
+ pageNum: number,
+}
diff --git a/tsconfig.app.json b/tsconfig.app.json
index 6809f92..c38a681 100644
--- a/tsconfig.app.json
+++ b/tsconfig.app.json
@@ -4,6 +4,7 @@
"env.d.ts",
"src/**/*",
"src/**/*.vue",
+ "src/**/*.ts",
"types/**/*.d.ts",
"types/**/*.ts",
"components.d.ts",
diff --git a/vite.config.ts b/vite.config.ts
index f5eef69..71e35b8 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -31,5 +31,8 @@ export default defineConfig({
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
+ },
+ build:{
+
}
})