From 45555455628ed60ed5b99106a91acfc8a2b9ccdf Mon Sep 17 00:00:00 2001
From: liweijie0812 <674416404@qq.com>
Date: Thu, 1 Jun 2023 14:12:23 +0800
Subject: [PATCH 01/14] feat: upgrade vite4 (#533)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* chore: 升级vite4
* docs: 项目简介 修改
* fix: 打包后预览提示TypeError
* chore: @vitejs/plugin-vue,@vitejs/plugin-vue-jsx升级
* docs: 项目简介 修改
---
README-zh_CN.md | 2 +-
README.md | 2 +-
package.json | 6 +++---
src/pages/dashboard/base/components/MiddleChart.vue | 2 --
src/pages/dashboard/base/components/OutputOverview.vue | 7 +------
5 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/README-zh_CN.md b/README-zh_CN.md
index 0a41c9c..63b71ae 100644
--- a/README-zh_CN.md
+++ b/README-zh_CN.md
@@ -19,7 +19,7 @@
### 项目简介
-TDesign Vue Next Starter 是一个基于 TDesign,使用 `Vue3`、`Vite2`、`Pinia`、`TypeScript` 开发,可进行个性化主题配置,旨在提供项目开箱即用的、配置式的中后台项目。
+TDesign Vue Next Starter 是一个基于 TDesign,使用 `Vue3`、`Vite`、`Pinia`、`TypeScript` 开发,可进行个性化主题配置,旨在提供项目开箱即用的、配置式的中后台项目。
在线预览
diff --git a/README.md b/README.md
index 75dedab..823d502 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@
English | [简体中文](./README-zh_CN.md)
### Introduction
-TDesign Vue Next Starter is a TDesign-based developed with `Vue 3`, `Vite 3+`, `Pinia`, `TypeScript`. It can be customized theme configuration, and aims to provide project out-of-the-box, configuration-style middle and background projects.
+TDesign Vue Next Starter is a TDesign-based developed with `Vue 3`, `Vite`, `Pinia`, `TypeScript`. It can be customized theme configuration, and aims to provide project out-of-the-box, configuration-style middle and background projects.
Live Preview
diff --git a/package.json b/package.json
index 04786a9..8c980e9 100644
--- a/package.json
+++ b/package.json
@@ -44,8 +44,8 @@
"@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"@typescript-eslint/parser": "^5.47.1",
- "@vitejs/plugin-vue": "^3.2.0",
- "@vitejs/plugin-vue-jsx": "^1.3.10",
+ "@vitejs/plugin-vue": "^4.2.3 ",
+ "@vitejs/plugin-vue-jsx": "^3.0.1 ",
"@vue/compiler-sfc": "^3.2.47",
"@vue/eslint-config-typescript": "^11.0.2",
"commitizen": "^4.2.4",
@@ -70,7 +70,7 @@
"stylelint-less": "1.0.6",
"stylelint-order": "~6.0.1",
"typescript": "~4.9.5",
- "vite": "^3.2.5",
+ "vite": "^4.3.9",
"vite-plugin-mock": "^2.9.6",
"vite-svg-loader": "^4.0.0",
"vue-tsc": "^1.2.0"
diff --git a/src/pages/dashboard/base/components/MiddleChart.vue b/src/pages/dashboard/base/components/MiddleChart.vue
index 32cbec9..26ec54f 100644
--- a/src/pages/dashboard/base/components/MiddleChart.vue
+++ b/src/pages/dashboard/base/components/MiddleChart.vue
@@ -15,7 +15,6 @@
@@ -25,7 +24,6 @@
diff --git a/src/pages/dashboard/base/components/OutputOverview.vue b/src/pages/dashboard/base/components/OutputOverview.vue
index a71dac0..3f045f7 100644
--- a/src/pages/dashboard/base/components/OutputOverview.vue
+++ b/src/pages/dashboard/base/components/OutputOverview.vue
@@ -17,12 +17,7 @@
@change="onStokeDataChange"
/>
-
+
From 83939b7517fe63bfc7d61d0053ec8717ecd3153f Mon Sep 17 00:00:00 2001
From: liweijie0812 <674416404@qq.com>
Date: Fri, 2 Jun 2023 16:03:02 +0800
Subject: [PATCH 02/14] =?UTF-8?q?fix:=20204=E6=97=A0=E5=86=85=E5=AE=B9?=
=?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E5=88=A4=E6=96=AD=20(#539)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/request/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts
index e2da3cc..386d67a 100644
--- a/src/utils/request/index.ts
+++ b/src/utils/request/index.ts
@@ -23,7 +23,7 @@ const transform: AxiosTransform = {
// 如果204无内容直接返回
const method = res.config.method?.toLowerCase();
- if (res.status === 204 || method === 'put' || method === 'patch') {
+ if (res.status === 204 && ['put', 'patch', 'delete'].includes(method)) {
return res;
}
From 9d8bf86059dfee689eb132c6f12e2bdb4dd4f93d Mon Sep 17 00:00:00 2001
From: ngyyuusora
Date: Mon, 19 Jun 2023 19:38:44 +0800
Subject: [PATCH 03/14] feat(axios util): support params stringify (#544)
---
src/utils/request/Axios.ts | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/utils/request/Axios.ts b/src/utils/request/Axios.ts
index fdb5c9c..5ad0b8e 100644
--- a/src/utils/request/Axios.ts
+++ b/src/utils/request/Axios.ts
@@ -118,6 +118,21 @@ export class VAxios {
};
}
+ // 支持params数组参数格式化
+ supportParamsStringify(config: AxiosRequestConfig) {
+ const headers = config.headers || this.options.headers;
+ const contentType = headers?.['Content-Type'] || headers?.['content-type'];
+
+ if (contentType === ContentTypeEnum.FormURLEncoded || !Reflect.has(config, 'params')) {
+ return config;
+ }
+
+ return {
+ ...config,
+ paramsSerializer: (params: any) => stringify(params, { arrayFormat: 'brackets' }),
+ };
+ }
+
get(config: AxiosRequestConfig, options?: RequestOptions): Promise {
return this.request({ ...config, method: 'GET' }, options);
}
@@ -154,6 +169,8 @@ export class VAxios {
conf.requestOptions = opt;
conf = this.supportFormData(conf);
+ // 支持params数组参数格式化,因axios默认的toFormData即为brackets方式,无需配置paramsSerializer为qs,有需要可解除注释,参数参考qs文档
+ // conf = this.supportParamsStringify(conf);
return new Promise((resolve, reject) => {
this.instance
From 8194b3d2533ec5e23d6115231a2331fb86ceb7be Mon Sep 17 00:00:00 2001
From: ngyyuusora
Date: Tue, 20 Jun 2023 23:33:11 +0800
Subject: [PATCH 04/14] fix(permission store): clear routes when logout (#545)
fix #541
---
src/store/modules/permission.ts | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts
index 94892f6..b0e81b3 100644
--- a/src/store/modules/permission.ts
+++ b/src/store/modules/permission.ts
@@ -37,9 +37,13 @@ export const usePermissionStore = defineStore('permission', {
}
},
async restoreRoutes() {
- this.removeRoutes.forEach((item: RouteRecordRaw) => {
- router.addRoute(item);
+ // 不需要在此额外调用initRoutes更新侧边导肮内容,在登录后asyncRoutes为空会调用
+ this.asyncRoutes.forEach((item: RouteRecordRaw) => {
+ if (item.name) {
+ router.removeRoute(item.name);
+ }
});
+ this.asyncRoutes = [];
},
},
});
From 5b1e9a4d77d889dd28eceb29b043dd32bf5dfe63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=82=A0=E9=9D=99=E8=90=9D=E8=8E=89?=
Date: Tue, 27 Jun 2023 11:03:07 +0800
Subject: [PATCH 05/14] chore: release 0.7.7 (#548)
* chore: release 0.7.7
* chore: dump tdesign version
---
package.json | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/package.json b/package.json
index 8c980e9..e2df45e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@tencent/tdesign-vue-next-starter",
- "version": "0.7.6",
+ "version": "0.7.7",
"scripts": {
"dev:mock": "vite --open --mode mock",
"dev": "vite --open --mode development",
@@ -19,8 +19,8 @@
"test:coverage": "echo \"no test:coverage specified,work in process\""
},
"dependencies": {
- "axios": "^1.3.4",
- "dayjs": "^1.11.7",
+ "axios": "^1.4.0",
+ "dayjs": "^1.11.8",
"echarts": "5.1.2",
"lodash": "^4.17.21",
"nprogress": "^0.2.0",
@@ -29,11 +29,11 @@
"qrcode.vue": "^3.3.4",
"qs": "^6.11.1",
"tdesign-icons-vue-next": "^0.1.11",
- "tdesign-vue-next": "^1.3.4",
+ "tdesign-vue-next": "^1.3.8",
"tvision-color": "^1.6.0",
- "vue": "^3.2.47",
+ "vue": "^3.3.4",
"vue-clipboard3": "^2.0.0",
- "vue-router": "~4.1.6"
+ "vue-router": "~4.2.2"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
@@ -73,7 +73,7 @@
"vite": "^4.3.9",
"vite-plugin-mock": "^2.9.6",
"vite-svg-loader": "^4.0.0",
- "vue-tsc": "^1.2.0"
+ "vue-tsc": "^1.8.2"
},
"config": {
"commitizen": {
From d4ffc9967e8560bfde08f6aa6159f043c85295d2 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 5 Jul 2023 15:24:26 +0800
Subject: [PATCH 06/14] build(deps-dev): bump typescript from 4.9.5 to 5.1.6
(#551)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.5 to 5.1.6.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/commits)
---
updated-dependencies:
- dependency-name: typescript
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot]
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index e2df45e..3d1b009 100644
--- a/package.json
+++ b/package.json
@@ -69,7 +69,7 @@
"stylelint-config-prettier": "~9.0.4",
"stylelint-less": "1.0.6",
"stylelint-order": "~6.0.1",
- "typescript": "~4.9.5",
+ "typescript": "~5.1.6",
"vite": "^4.3.9",
"vite-plugin-mock": "^2.9.6",
"vite-svg-loader": "^4.0.0",
From 78595657c687f95b19d9a3d68a221d3f70ac407e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=B2=A8=E9=B1=BC=E8=BE=A3=E6=A4=92?=
<82007768+tanhh326@users.noreply.github.com>
Date: Thu, 6 Jul 2023 12:00:37 +0800
Subject: [PATCH 07/14] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=91?=
=?UTF-8?q?=E7=B9=81=E5=88=87=E6=8D=A2=E8=B7=AF=E7=94=B1=E6=97=B6=E8=A1=A8?=
=?UTF-8?q?=E5=8D=95=E5=A4=B4=E6=BB=9E=E7=95=99=E7=9A=84=E9=97=AE=E9=A2=98?=
=?UTF-8?q?=20(#550)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: 🌩
---
src/layouts/components/Content.vue | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/layouts/components/Content.vue b/src/layouts/components/Content.vue
index 4d4780c..e7ef8a2 100644
--- a/src/layouts/components/Content.vue
+++ b/src/layouts/components/Content.vue
@@ -1,6 +1,6 @@
-
+
From 17eb3f0aa8a2357bbd3746f63092313d2b3958dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=82=A0=E9=9D=99=E8=90=9D=E8=8E=89?=
Date: Thu, 6 Jul 2023 12:01:08 +0800
Subject: [PATCH 08/14] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=89=80?=
=?UTF-8?q?=E6=9C=89=E4=BE=9D=E8=B5=96=20(#553)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat: 更新所有依赖
* feat: 移除无用依赖
* revert: 暂时回退echarts防止打包错误
---
package.json | 61 ++++++++++++++++++++++-----------------------
stylelint.config.js | 2 +-
vite.config.ts | 2 +-
3 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/package.json b/package.json
index 3d1b009..5637c58 100644
--- a/package.json
+++ b/package.json
@@ -20,60 +20,59 @@
},
"dependencies": {
"axios": "^1.4.0",
- "dayjs": "^1.11.8",
+ "dayjs": "^1.11.9",
"echarts": "5.1.2",
"lodash": "^4.17.21",
"nprogress": "^0.2.0",
- "pinia": "^2.0.33",
+ "pinia": "^2.1.4",
"pinia-plugin-persistedstate": "^3.1.0",
- "qrcode.vue": "^3.3.4",
- "qs": "^6.11.1",
+ "qrcode.vue": "^3.4.0",
+ "qs": "^6.11.2",
"tdesign-icons-vue-next": "^0.1.11",
- "tdesign-vue-next": "^1.3.8",
+ "tdesign-vue-next": "^1.3.10",
"tvision-color": "^1.6.0",
"vue": "^3.3.4",
"vue-clipboard3": "^2.0.0",
- "vue-router": "~4.2.2"
+ "vue-router": "~4.2.3"
},
"devDependencies": {
- "@commitlint/cli": "^17.3.0",
- "@commitlint/config-conventional": "^17.3.0",
- "@types/echarts": "^4.9.16",
- "@types/lodash": "^4.14.191",
+ "@commitlint/cli": "^17.6.6",
+ "@commitlint/config-conventional": "^17.6.6",
+ "@types/echarts": "^4.9.18",
+ "@types/lodash": "^4.14.195",
"@types/nprogress": "^0.2.0",
"@types/qs": "^6.9.7",
- "@typescript-eslint/eslint-plugin": "^5.47.1",
- "@typescript-eslint/parser": "^5.47.1",
- "@vitejs/plugin-vue": "^4.2.3 ",
- "@vitejs/plugin-vue-jsx": "^3.0.1 ",
- "@vue/compiler-sfc": "^3.2.47",
- "@vue/eslint-config-typescript": "^11.0.2",
- "commitizen": "^4.2.4",
+ "@typescript-eslint/eslint-plugin": "^5.61.0",
+ "@typescript-eslint/parser": "^5.61.0",
+ "@vitejs/plugin-vue": "^4.2.3",
+ "@vitejs/plugin-vue-jsx": "^3.0.1",
+ "@vue/compiler-sfc": "^3.3.4",
+ "@vue/eslint-config-typescript": "^11.0.3",
+ "commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
- "eslint": "^8.30.0",
+ "eslint": "^8.44.0",
"eslint-config-airbnb-base": "^15.0.0",
- "eslint-config-prettier": "^8.5.0",
- "eslint-plugin-import": "^2.26.0",
+ "eslint-config-prettier": "^8.8.0",
+ "eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
- "eslint-plugin-vue": "^9.8.0",
- "eslint-plugin-vue-scoped-css": "^2.2.0",
- "husky": "^8.0.2",
+ "eslint-plugin-vue": "^9.15.1",
+ "eslint-plugin-vue-scoped-css": "^2.5.0",
+ "husky": "^8.0.3",
"less": "^4.1.3",
- "lint-staged": "^13.1.0",
+ "lint-staged": "^13.2.3",
"mockjs": "^1.1.0",
"postcss-html": "^1.5.0",
"postcss-less": "^6.0.0",
- "prettier": "^2.8.1",
- "stylelint": "~14.9.1",
- "stylelint-config-prettier": "~9.0.4",
- "stylelint-less": "1.0.6",
- "stylelint-order": "~6.0.1",
+ "prettier": "^2.8.8",
+ "stylelint": "~15.10.0",
+ "stylelint-less": "1.0.7",
+ "stylelint-order": "~6.0.3",
"typescript": "~5.1.6",
"vite": "^4.3.9",
- "vite-plugin-mock": "^2.9.6",
+ "vite-plugin-mock": "^3.0.0",
"vite-svg-loader": "^4.0.0",
- "vue-tsc": "^1.8.2"
+ "vue-tsc": "^1.8.4"
},
"config": {
"commitizen": {
diff --git a/stylelint.config.js b/stylelint.config.js
index 6c8629b..4927ba7 100644
--- a/stylelint.config.js
+++ b/stylelint.config.js
@@ -1,6 +1,6 @@
module.exports = {
defaultSeverity: 'error',
- extends: ['stylelint-config-prettier'],
+ extends: ['stylelint-config-standard'],
plugins: ['stylelint-less'],
overrides: [
{
diff --git a/vite.config.ts b/vite.config.ts
index 557dccf..fb3c96d 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -35,7 +35,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {
vueJsx(),
viteMockServe({
mockPath: 'mock',
- localEnabled: true,
+ enable: true,
}),
svgLoader(),
],
From 12909e5d226c0bf5861ce8fadf7607c8ebdb3c4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=82=A0=E9=9D=99=E8=90=9D=E8=8E=89?=
Date: Sat, 8 Jul 2023 09:19:42 +0800
Subject: [PATCH 09/14] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84Axios?=
=?UTF-8?q?=E5=B7=A5=E5=85=B7=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?=
=?UTF-8?q?=E7=BA=A7=E9=98=B2=E6=8A=96=E8=8A=82=E6=B5=81=20(#556)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* refactor: 重构Axios工具,新增接口级防抖节流
* fix: 修复编译类型问题
* perf: 优化注释
---
src/types/axios.d.ts | 75 +++++++++++++-
src/utils/request/Axios.ts | 149 ++++++++++++++++++++++------
src/utils/request/AxiosCancel.ts | 24 ++++-
src/utils/request/AxiosTransform.ts | 58 ++++++++---
src/utils/request/index.ts | 10 +-
5 files changed, 262 insertions(+), 54 deletions(-)
diff --git a/src/types/axios.d.ts b/src/types/axios.d.ts
index 6f044c2..1c90329 100644
--- a/src/types/axios.d.ts
+++ b/src/types/axios.d.ts
@@ -1,18 +1,89 @@
-import { AxiosRequestConfig } from 'axios';
+import type { AxiosRequestConfig } from 'axios';
+/**
+ * Axios请求配置
+ */
export interface RequestOptions {
+ /**
+ * 接口地址
+ *
+ * 例: http://www.baidu.com/api
+ */
apiUrl?: string;
+ /**
+ * 是否自动添加接口前缀
+ *
+ * 例: http://www.baidu.com/api
+ * urlPrefix: 'api'
+ */
isJoinPrefix?: boolean;
+ /**
+ * 接口前缀
+ */
urlPrefix?: string;
+ /**
+ * POST请求的时候添加参数到Url中
+ */
joinParamsToUrl?: boolean;
+ /**
+ * 格式化提交参数时间
+ */
formatDate?: boolean;
+ /**
+ * 是否需要对响应数据进行处理
+ */
isTransformResponse?: boolean;
+ /**
+ * 是否返回原生响应头
+ *
+ * 例: 需要获取响应头时使用该属性
+ */
isReturnNativeResponse?: boolean;
- ignoreRepeatRequest?: boolean;
+ /**
+ * 是否忽略请求取消令牌
+ *
+ * 如果启用,则重复请求时不进行处理
+ *
+ * 如果禁用,则重复请求时会取消当前请求
+ */
+ ignoreCancelToken?: boolean;
+ /**
+ * 自动对请求添加时间戳参数
+ */
joinTime?: boolean;
+ /**
+ * 是否携带Token
+ */
withToken?: boolean;
+ /**
+ * 重试配置
+ */
retry?: {
+ /**
+ * 重试次数
+ */
count: number;
+ /**
+ * 隔多久重试
+ *
+ * 单位: 毫秒
+ */
+ delay: number;
+ };
+ /**
+ * 接口级节流
+ *
+ * 单位: 毫秒
+ */
+ throttle?: {
+ delay: number;
+ };
+ /**
+ * 接口级防抖
+ *
+ * 单位: 毫秒
+ */
+ debounce?: {
delay: number;
};
}
diff --git a/src/utils/request/Axios.ts b/src/utils/request/Axios.ts
index 5ad0b8e..fc52027 100644
--- a/src/utils/request/Axios.ts
+++ b/src/utils/request/Axios.ts
@@ -1,6 +1,15 @@
-import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
+import axios, {
+ AxiosError,
+ AxiosInstance,
+ AxiosRequestConfig,
+ AxiosRequestHeaders,
+ AxiosResponse,
+ InternalAxiosRequestConfig,
+} from 'axios';
import cloneDeep from 'lodash/cloneDeep';
+import debounce from 'lodash/debounce';
import isFunction from 'lodash/isFunction';
+import throttle from 'lodash/throttle';
import { stringify } from 'qs';
import { ContentTypeEnum } from '@/constants';
@@ -9,12 +18,20 @@ import { AxiosRequestConfigRetry, RequestOptions, Result } from '@/types/axios';
import { AxiosCanceler } from './AxiosCancel';
import { CreateAxiosOptions } from './AxiosTransform';
-// Axios模块
+/**
+ * Axios 模块
+ */
export class VAxios {
- // axios句柄
+ /**
+ * Axios实例句柄
+ * @private
+ */
private instance: AxiosInstance;
- // axios选项
+ /**
+ * Axios配置
+ * @private
+ */
private readonly options: CreateAxiosOptions;
constructor(options: CreateAxiosOptions) {
@@ -23,57 +40,71 @@ export class VAxios {
this.setupInterceptors();
}
- // 创建axios句柄
+ /**
+ * 创建Axios实例
+ * @param config
+ * @private
+ */
private createAxios(config: CreateAxiosOptions): void {
this.instance = axios.create(config);
}
- // 获取数据处理
+ /**
+ * 获取数据处理类
+ * @private
+ */
private getTransform() {
const { transform } = this.options;
return transform;
}
- // 获取句柄
+ /**
+ * 获取Axios实例
+ */
getAxios(): AxiosInstance {
return this.instance;
}
- // 配置 axios
+ /**
+ * 配置Axios
+ * @param config
+ */
configAxios(config: CreateAxiosOptions) {
- if (!this.instance) {
- return;
- }
+ if (!this.instance) return;
this.createAxios(config);
}
- // 设置通用头信息
+ /**
+ * 设置公共头部信息
+ * @param headers
+ */
setHeader(headers: Record): void {
- if (!this.instance) {
- return;
- }
+ if (!this.instance) return;
Object.assign(this.instance.defaults.headers, headers);
}
- // 设置拦截器
+ /**
+ * 设置拦截器
+ * @private
+ */
private setupInterceptors() {
const transform = this.getTransform();
- if (!transform) {
- return;
- }
+ if (!transform) return;
+
const { requestInterceptors, requestInterceptorsCatch, responseInterceptors, responseInterceptorsCatch } =
transform;
const axiosCanceler = new AxiosCanceler();
- // 请求配置处理
+ // 请求拦截器
this.instance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
+ // 如果忽略取消令牌,则不会取消重复的请求
// @ts-ignore
- const { ignoreRepeatRequest } = config.requestOptions;
- const ignoreRepeat = ignoreRepeatRequest ?? this.options.requestOptions?.ignoreRepeatRequest;
- if (!ignoreRepeat) axiosCanceler.addPending(config);
+ const { ignoreCancelToken } = config.requestOptions;
+ const ignoreCancel = ignoreCancelToken ?? this.options.requestOptions?.ignoreCancelToken;
+ if (!ignoreCancel) axiosCanceler.addPending(config);
if (requestInterceptors && isFunction(requestInterceptors)) {
- config = requestInterceptors(config, this.options);
+ config = requestInterceptors(config, this.options) as InternalAxiosRequestConfig;
}
return config;
@@ -99,9 +130,12 @@ export class VAxios {
}
}
- // 支持Form Data
+ /**
+ * 支持 FormData 请求格式
+ * @param config
+ */
supportFormData(config: AxiosRequestConfig) {
- const headers = config.headers || this.options.headers;
+ const headers = config.headers || (this.options.headers as AxiosRequestHeaders);
const contentType = headers?.['Content-Type'] || headers?.['content-type'];
if (
@@ -118,7 +152,10 @@ export class VAxios {
};
}
- // 支持params数组参数格式化
+ /**
+ * 支持 params 序列化
+ * @param config
+ */
supportParamsStringify(config: AxiosRequestConfig) {
const headers = config.headers || this.options.headers;
const contentType = headers?.['Content-Type'] || headers?.['content-type'];
@@ -153,8 +190,62 @@ export class VAxios {
return this.request({ ...config, method: 'PATCH' }, options);
}
- // 请求
- async request(config: AxiosRequestConfigRetry, options?: RequestOptions): Promise {
+ /**
+ * 上传文件封装
+ * @param key 文件所属的key
+ * @param file 文件
+ * @param config 请求配置
+ * @param options
+ */
+ upload(key: string, file: File, config: AxiosRequestConfig, options?: RequestOptions): Promise {
+ const params: FormData = config.params ?? new FormData();
+ params.append(key, file);
+
+ return this.request(
+ {
+ ...config,
+ method: 'POST',
+ headers: {
+ 'Content-Type': ContentTypeEnum.FormData,
+ },
+ params,
+ },
+ options,
+ );
+ }
+
+ /**
+ * 请求封装
+ * @param config
+ * @param options
+ */
+ request(config: AxiosRequestConfigRetry, options?: RequestOptions): Promise {
+ const { requestOptions } = this.options;
+
+ if (requestOptions.throttle !== undefined && requestOptions.debounce !== undefined) {
+ throw new Error('throttle and debounce cannot be set at the same time');
+ }
+
+ if (requestOptions.throttle && requestOptions.throttle.delay !== 0) {
+ return new Promise((resolve) => {
+ throttle(() => resolve(this.synthesisRequest(config, options)), requestOptions.throttle.delay);
+ });
+ }
+
+ if (requestOptions.debounce && requestOptions.debounce.delay !== 0) {
+ return new Promise((resolve) => {
+ debounce(() => resolve(this.synthesisRequest(config, options)), requestOptions.debounce.delay);
+ });
+ }
+
+ return this.synthesisRequest(config, options);
+ }
+
+ /**
+ * 请求方法
+ * @private
+ */
+ private async synthesisRequest(config: AxiosRequestConfigRetry, options?: RequestOptions): Promise {
let conf: CreateAxiosOptions = cloneDeep(config);
const transform = this.getTransform();
diff --git a/src/utils/request/AxiosCancel.ts b/src/utils/request/AxiosCancel.ts
index b50d279..010b0da 100644
--- a/src/utils/request/AxiosCancel.ts
+++ b/src/utils/request/AxiosCancel.ts
@@ -5,10 +5,20 @@ import isFunction from 'lodash/isFunction';
// 存储请求与取消令牌的键值对列表
let pendingMap = new Map();
+/**
+ * 获取请求Url
+ * @param config
+ */
export const getPendingUrl = (config: AxiosRequestConfig) => [config.method, config.url].join('&');
+/**
+ * @description 请求管理器
+ */
export class AxiosCanceler {
- // 添加请求到列表
+ /**
+ * 添加请求到列表中
+ * @param config
+ */
addPending(config: AxiosRequestConfig) {
this.removePending(config);
const url = getPendingUrl(config);
@@ -22,7 +32,9 @@ export class AxiosCanceler {
});
}
- // 清空所有请求
+ /**
+ * 移除现有的所有请求
+ */
removeAllPending() {
pendingMap.forEach((cancel) => {
if (cancel && isFunction(cancel)) cancel();
@@ -30,7 +42,10 @@ export class AxiosCanceler {
pendingMap.clear();
}
- // 移除某个请求
+ /**
+ * 移除指定请求
+ * @param config
+ */
removePending(config: AxiosRequestConfig) {
const url = getPendingUrl(config);
@@ -43,6 +58,9 @@ export class AxiosCanceler {
}
}
+ /**
+ * 重置
+ */
reset() {
pendingMap = new Map();
}
diff --git a/src/utils/request/AxiosTransform.ts b/src/utils/request/AxiosTransform.ts
index c3e9854..d05c64a 100644
--- a/src/utils/request/AxiosTransform.ts
+++ b/src/utils/request/AxiosTransform.ts
@@ -1,38 +1,64 @@
-import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
+import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { AxiosError } from 'axios';
import type { RequestOptions, Result } from '@/types/axios';
-// 创建Axios选项
+/**
+ * @description 创建Axios实例配置
+ */
export interface CreateAxiosOptions extends AxiosRequestConfig {
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes
+ /**
+ * 请求验证方案
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes
+ */
authenticationScheme?: string;
- // 数据处理
+ /**
+ * 请求数据处理
+ */
transform?: AxiosTransform;
- // 请求选项
+ /**
+ * 请求配置
+ */
requestOptions?: RequestOptions;
}
-// Axios 数据处理
+/**
+ * Axios请求数据处理 抽象类
+ */
export abstract class AxiosTransform {
- // 请求前Hook
+ /**
+ * 请求前钩子
+ */
beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
- // 转换前Hook
- transformRequestHook?: (res: AxiosResponse, options: RequestOptions) => any;
+ /**
+ * 数据处理前钩子
+ */
+ transformRequestHook?: (res: AxiosResponse, options: RequestOptions) => T;
- // 请求失败处理
- requestCatchHook?: (e: Error | AxiosError, options: RequestOptions) => Promise;
+ /**
+ * 请求失败钩子
+ */
+ requestCatchHook?: (e: Error | AxiosError, options: RequestOptions) => Promise;
- // 请求前的拦截器
- requestInterceptors?: (config: AxiosRequestConfig, options: CreateAxiosOptions) => InternalAxiosRequestConfig;
+ /**
+ * 请求拦截器
+ */
+ requestInterceptors?: (config: AxiosRequestConfig, options: CreateAxiosOptions) => AxiosRequestConfig;
- // 请求后的拦截器
+ /**
+ * 响应拦截器
+ */
responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
- // 请求前的拦截器错误处理
+ /**
+ * 请求拦截器错误处理
+ */
requestInterceptorsCatch?: (error: AxiosError) => void;
- // 请求后的拦截器错误处理
+ /**
+ * 响应拦截器错误处理
+ */
responseInterceptorsCatch?: (error: AxiosError, instance: AxiosInstance) => void;
}
diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts
index 386d67a..6dd0173 100644
--- a/src/utils/request/index.ts
+++ b/src/utils/request/index.ts
@@ -1,5 +1,5 @@
// axios配置 可自行根据项目进行更改,只需更改该文件即可,其他文件可以不动
-import type { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
+import type { AxiosInstance } from 'axios';
import isString from 'lodash/isString';
import merge from 'lodash/merge';
@@ -122,7 +122,7 @@ const transform: AxiosTransform = {
? `${options.authenticationScheme} ${token}`
: token;
}
- return config as InternalAxiosRequestConfig;
+ return config;
},
// 响应拦截器处理
@@ -186,8 +186,10 @@ function createAxios(opt?: Partial) {
formatDate: true,
// 是否加入时间戳
joinTime: true,
- // 忽略重复请求
- ignoreRepeatRequest: true,
+ // 是否忽略请求取消令牌
+ // 如果启用,则重复请求时不进行处理
+ // 如果禁用,则重复请求时会取消当前请求
+ ignoreCancelToken: true,
// 是否携带token
withToken: true,
// 重试
From 0358653f11c8fc142118b959cf925eb2eaf0add7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=82=A0=E9=9D=99=E8=90=9D=E8=8E=89?=
Date: Tue, 11 Jul 2023 14:59:22 +0800
Subject: [PATCH 10/14] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4Stylelint-less?=
=?UTF-8?q?=E4=BE=9D=E8=B5=96=20(#557)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 1 -
stylelint.config.js | 1 -
2 files changed, 2 deletions(-)
diff --git a/package.json b/package.json
index 5637c58..0ea6389 100644
--- a/package.json
+++ b/package.json
@@ -66,7 +66,6 @@
"postcss-less": "^6.0.0",
"prettier": "^2.8.8",
"stylelint": "~15.10.0",
- "stylelint-less": "1.0.7",
"stylelint-order": "~6.0.3",
"typescript": "~5.1.6",
"vite": "^4.3.9",
diff --git a/stylelint.config.js b/stylelint.config.js
index 4927ba7..f994912 100644
--- a/stylelint.config.js
+++ b/stylelint.config.js
@@ -1,7 +1,6 @@
module.exports = {
defaultSeverity: 'error',
extends: ['stylelint-config-standard'],
- plugins: ['stylelint-less'],
overrides: [
{
files: ['**/*.html', '**/*.vue'],
From 151151c354d0da787436f2d08484268e6276bd39 Mon Sep 17 00:00:00 2001
From: liweijie0812 <674416404@qq.com>
Date: Tue, 11 Jul 2023 16:38:05 +0800
Subject: [PATCH 11/14] fix: stylelint error (#558)
* fix: stylelint error
* fix(less): import eroor
---
package.json | 1 +
src/layouts/setting.vue | 7 ++++---
src/style/layout.less | 17 ++++++++++-------
src/style/reset.less | 2 +-
stylelint.config.js | 27 +++++++++++++++++++++++++++
5 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/package.json b/package.json
index 0ea6389..d4742b5 100644
--- a/package.json
+++ b/package.json
@@ -66,6 +66,7 @@
"postcss-less": "^6.0.0",
"prettier": "^2.8.8",
"stylelint": "~15.10.0",
+ "stylelint-config-standard": "^34.0.0",
"stylelint-order": "~6.0.3",
"typescript": "~5.1.6",
"vite": "^4.3.9",
diff --git a/src/layouts/setting.vue b/src/layouts/setting.vue
index fa0cea7..94a5ffd 100644
--- a/src/layouts/setting.vue
+++ b/src/layouts/setting.vue
@@ -206,7 +206,6 @@ watchEffect(() => {
position: fixed;
bottom: 200px;
right: 0;
- transition: transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1), visibility 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
height: 40px;
width: 40px;
border-radius: 20px 0 0 20px;
@@ -252,9 +251,9 @@ watchEffect(() => {
.setting-group-title {
font-size: 14px;
line-height: 22px;
- margin: 32px 0 24px 0;
+ margin: 32px 0 24px;
text-align: left;
- font-family: PingFang SC;
+ font-family: 'PingFang SC', var(--td-font-family);
font-style: normal;
font-weight: 500;
color: var(--td-text-color-primary);
@@ -283,6 +282,7 @@ watchEffect(() => {
.setting-container {
padding-bottom: 100px;
}
+
.t-radio-group.t-size-m {
min-height: 32px;
width: 100%;
@@ -306,6 +306,7 @@ watchEffect(() => {
padding: 8px;
border-radius: var(--td-radius-default);
border: 2px solid var(--td-component-border);
+
> .t-radio-button__label {
display: inline-flex;
}
diff --git a/src/style/layout.less b/src/style/layout.less
index f6c305f..e0e6e53 100644
--- a/src/style/layout.less
+++ b/src/style/layout.less
@@ -27,7 +27,7 @@
text-decoration: none;
margin-right: 24px;
cursor: pointer;
- transition: color 0.2s cubic-bezier(0.38, 0, 0.24, 1);
+ transition: color .2s cubic-bezier(.38, 0, .24, 1);
}
.left-operation-container,
@@ -45,7 +45,8 @@
}
.t-menu--dark .t-menu__operations .t-icon {
- color: rgba(255, 255, 255, 0.55);
+ color: rgba(255, 255, 255, 55%);
+
&:hover {
cursor: pointer;
}
@@ -81,6 +82,7 @@
&-layout {
height: calc(100vh - var(--td-comp-size-xxxl));
overflow-y: scroll;
+
&-tabs-nav {
max-width: 100%;
position: fixed;
@@ -127,7 +129,7 @@
top: 0;
bottom: 0;
z-index: 200;
- transition: all 0.3s;
+ transition: all .3s;
min-height: 100%;
&-mix {
@@ -153,6 +155,7 @@
align-items: center;
justify-content: center;
width: 100%;
+
&:hover {
cursor: pointer;
}
@@ -173,19 +176,19 @@
&-logo-normal {
color: var(--td-brand-color);
font: var(--td-font-body-large);
- transition: all 0.3s;
+ transition: all .3s;
}
}
&-side-nav-placeholder {
flex: 1 1 232px;
min-width: 232px;
- transition: all 0.3s;
+ transition: all .3s;
&-hidden {
flex: 1 1 72px;
min-width: 72px;
- transition: all 0.3s;
+ transition: all .3s;
}
}
}
@@ -204,7 +207,7 @@
.version-container {
color: var(--td-text-color-primary);
- opacity: 0.4;
+ opacity: .4;
}
.t-menu__popup {
diff --git a/src/style/reset.less b/src/style/reset.less
index 6bf61c3..6dcf8cd 100644
--- a/src/style/reset.less
+++ b/src/style/reset.less
@@ -1,8 +1,8 @@
// 对部分样式进行重置
body {
color: var(--td-text-color-secondary);
- font-family: -apple-system, BlinkMacSystemFont, var(--td-font-family);
font: var(--td-font-body-medium);
+ font-family: -apple-system, BlinkMacSystemFont, var(--td-font-family);
-webkit-font-smoothing: antialiased;
padding: 0;
margin: 0;
diff --git a/stylelint.config.js b/stylelint.config.js
index f994912..73e3952 100644
--- a/stylelint.config.js
+++ b/stylelint.config.js
@@ -1,6 +1,33 @@
module.exports = {
defaultSeverity: 'error',
extends: ['stylelint-config-standard'],
+ rules: {
+ 'no-duplicate-selectors': null,
+ 'number-leading-zero': 'never',
+ 'block-no-empty': null,
+ 'selector-class-pattern': null,
+ 'declaration-block-no-redundant-longhand-properties': [true, { ignoreShorthands: ['/flex/'] }],
+ 'custom-property-pattern': null,
+ 'keyframes-name-pattern': null,
+ 'no-empty-source': null,
+ 'font-family-no-missing-generic-family-keyword': [
+ true,
+ {
+ ignoreFontFamilies: ['PingFangSC-Regular', 'PingFangSC-Medium', 't'],
+ },
+ ],
+ 'unit-no-unknown': [true, { ignoreUnits: ['rpx'] }],
+ 'function-url-quotes': null,
+ 'max-line-length': null,
+ 'at-rule-empty-line-before': ['always', { ignore: ['after-comment'] }],
+ 'declaration-colon-newline-after': null,
+ 'no-descending-specificity': null,
+ 'selector-type-no-unknown': null,
+ 'color-function-notation': 'legacy',
+ 'value-keyword-case': null,
+ 'property-no-unknown': [true, { checkPrefixed: true }],
+ 'import-notation': 'string',
+ },
overrides: [
{
files: ['**/*.html', '**/*.vue'],
From e6192ef37ab2657c29b01f3649cac66aec118a78 Mon Sep 17 00:00:00 2001
From: liweijie0812 <674416404@qq.com>
Date: Tue, 11 Jul 2023 16:48:35 +0800
Subject: [PATCH 12/14] fix: list demo status defalut object (#559)
---
src/pages/list/components/CommonTable.vue | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/pages/list/components/CommonTable.vue b/src/pages/list/components/CommonTable.vue
index 8df81d0..9e65d2c 100644
--- a/src/pages/list/components/CommonTable.vue
+++ b/src/pages/list/components/CommonTable.vue
@@ -22,6 +22,7 @@
class="form-item-content"
:options="CONTRACT_STATUS_OPTIONS"
placeholder="请选择合同状态"
+ clearable
/>
@@ -43,6 +44,7 @@
class="form-item-content"
:options="CONTRACT_TYPE_OPTIONS"
placeholder="请选择合同类型"
+ clearable
/>
@@ -120,6 +122,13 @@ import {
} from '@/constants';
import { useSettingStore } from '@/store';
+interface FormData {
+ name: string;
+ no: string;
+ status?: number;
+ type: string;
+}
+
const store = useSettingStore();
const COLUMNS: PrimaryTableCol[] = [
@@ -168,11 +177,10 @@ const COLUMNS: PrimaryTableCol[] = [
const searchForm = {
name: '',
no: '',
- status: typeof CONTRACT_STATUS,
type: '',
};
-const formData = ref({ ...searchForm });
+const formData = ref({ ...searchForm });
const rowKey = 'index';
const verticalAlign = 'top' as const;
const hover = true;
@@ -242,6 +250,7 @@ const onReset = (val: unknown) => {
};
const onSubmit = (val: unknown) => {
console.log(val);
+ console.log(formData.value);
};
const rehandlePageChange = (pageInfo: PageInfo, newDataSource: TableRowData[]) => {
console.log('分页变化', pageInfo, newDataSource);
@@ -281,6 +290,7 @@ const headerAffixedTop = computed(
display: flex;
justify-content: flex-end;
align-items: center;
+
.expand {
.t-button__text {
display: flex;
From ebadc7b566225497c5383b644e02d65d3d85e5e6 Mon Sep 17 00:00:00 2001
From: liweijie0812 <674416404@qq.com>
Date: Tue, 11 Jul 2023 19:17:46 +0800
Subject: [PATCH 13/14] chore: fix typo (#560)
---
package.json | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/package.json b/package.json
index d4742b5..771ab18 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,7 @@
"lint": "eslint --ext .vue,.js,.jsx,.ts,.tsx ./ --max-warnings 0",
"lint:fix": "eslint --ext .vue,.js,jsx,.ts,.tsx ./ --max-warnings 0 --fix",
"stylelint": "stylelint src/**/*.{html,vue,sass,less}",
- "stylelint:fix": "stylelint --fix src/**/*.{html,vue,vss,sass,less}",
+ "stylelint:fix": "stylelint --fix src/**/*.{html,vue,css,sass,less}",
"prepare": "husky install",
"site:preview": "npm run build && cp -r dist _site",
"test": "echo \"no test specified,work in process\"",
@@ -84,7 +84,7 @@
"prettier --write",
"npm run lint:fix"
],
- "*.{html,vue,vss,sass,less}": [
+ "*.{html,vue,css,sass,less}": [
"npm run stylelint:fix"
]
}
From 109db6868e197ef8c417652db3550e2693cbc154 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=82=A0=E9=9D=99=E8=90=9D=E8=8E=89?=
Date: Wed, 12 Jul 2023 09:56:52 +0800
Subject: [PATCH 14/14] chore: release 0.8.0 (#561)
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 771ab18..1a0f564 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@tencent/tdesign-vue-next-starter",
- "version": "0.7.7",
+ "version": "0.8.0",
"scripts": {
"dev:mock": "vite --open --mode mock",
"dev": "vite --open --mode development",