From c89f434ce8ad2e476137943d059ee455a836d6c7 Mon Sep 17 00:00:00 2001 From: liweijie0812 <674416404@qq.com> Date: Thu, 11 May 2023 22:10:32 +0800 Subject: [PATCH 01/12] =?UTF-8?q?perf:=20=E8=B7=AF=E7=94=B1=E5=AE=88?= =?UTF-8?q?=E5=8D=AB=E8=8E=B7=E5=8F=96=E8=8F=9C=E5=8D=95=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=8C=E8=B7=B3=E8=BD=AC=E7=99=BB=E5=BD=95=E9=A1=B5=E5=B9=B6?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=8F=90=E7=A4=BA=20(#502)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.ts | 49 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/permission.ts b/src/permission.ts index cd82e62..5a9ea5e 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -25,38 +25,37 @@ router.beforeEach(async (to, from, next) => { } try { await userStore.getUserInfo(); + + const { asyncRoutes } = permissionStore; + + if (asyncRoutes && asyncRoutes.length === 0) { + const routeList = await permissionStore.buildAsyncRoutes(); + routeList.forEach((item: RouteRecordRaw) => { + router.addRoute(item); + }); + + if (to.name === PAGE_NOT_FOUND_ROUTE.name) { + // 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容 + next({ path: to.fullPath, replace: true, query: to.query }); + } else { + const redirect = decodeURIComponent((from.query.redirect || to.path) as string); + next(to.path === redirect ? { ...to, replace: true } : { path: redirect }); + return; + } + } + if (router.hasRoute(to.name)) { + next(); + } else { + next(`/`); + } } catch (error) { - MessagePlugin.error(error); + MessagePlugin.error(error.message); next({ path: '/login', query: { redirect: encodeURIComponent(to.fullPath) }, }); NProgress.done(); } - - const { asyncRoutes } = permissionStore; - - if (asyncRoutes && asyncRoutes.length === 0) { - const routeList = await permissionStore.buildAsyncRoutes(); - routeList.forEach((item: RouteRecordRaw) => { - router.addRoute(item); - }); - - if (to.name === PAGE_NOT_FOUND_ROUTE.name) { - // 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容 - next({ path: to.fullPath, replace: true, query: to.query }); - } else { - const redirect = decodeURIComponent((from.query.redirect || to.path) as string); - next(to.path === redirect ? { ...to, replace: true } : { path: redirect }); - return; - } - } - - if (router.hasRoute(to.name)) { - next(); - } else { - next(`/`); - } } else { /* white list router */ if (whiteListRouters.indexOf(to.path) !== -1) { From 4292bd2118326f770351ba00c3f613ea1b63f837 Mon Sep 17 00:00:00 2001 From: "Gui.H" Date: Fri, 12 May 2023 20:35:44 +0800 Subject: [PATCH 02/12] =?UTF-8?q?perf:=20=E8=A7=84=E8=8C=83=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=B3=BB=E7=BB=9F=E4=B8=AD=E7=9A=84=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E7=AC=A6=20(#505)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: eol * fix: 测试效果 * fix: 默认全部文件eol=lf * fix: 防止误判,仅对部分明确的文件设置 * fix: 新建文件eol格式错误进行互补 * Update settings.json --- .gitattributes | 6 ++++++ .vscode/settings.json | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..326caac --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +*.ts text eol=lf +*.vue text eol=lf +*.tsx text eol=lf +*.jsx text eol=lf +*.html text eol=lf +*.json text eol=lf \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 9f7e7d1..02a0913 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { + "files.eol":"\n", + "editor.tabSize": 2, "eslint.format.enable": true, "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"], "[vue]": { From 03adc83ba228ef0bc022d97e1fa1f776df2c51d0 Mon Sep 17 00:00:00 2001 From: You Date: Tue, 16 May 2023 22:00:36 +0800 Subject: [PATCH 03/12] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=B0=86=E9=80=9A=E7=9F=A5=E8=AE=BE=E4=B8=BA=E6=9C=AA?= =?UTF-8?q?=E8=AF=BB=20(#511)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/detail/secondary/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/detail/secondary/index.vue b/src/pages/detail/secondary/index.vue index 05e5455..cde49dc 100644 --- a/src/pages/detail/secondary/index.vue +++ b/src/pages/detail/secondary/index.vue @@ -104,7 +104,7 @@ const setReadStatus = (item: NotificationItem) => { const changeMsg = msgData.value; changeMsg.forEach((e: NotificationItem) => { if (e.id === item.id) { - if (e.status) e.status = false; + e.status = !e.status; } }); store.setMsgData(changeMsg); From 665e0dacec6d7401c295ca8d7a1897b50b1a74a9 Mon Sep 17 00:00:00 2001 From: "Gui.H" Date: Thu, 18 May 2023 11:29:01 +0800 Subject: [PATCH 04/12] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20store=20?= =?UTF-8?q?=E4=B8=AD=E5=B9=B6=E6=9C=AA=E5=AF=B9=20localStorage=20=E7=9A=84?= =?UTF-8?q?=20TOKEN=5FNAME=20=E9=94=AE=E8=BF=9B=E8=A1=8C=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7=20(#504)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 接口请求不携带token * fix: 优化token持久化策略 * fix: 删除多余的log --- src/permission.ts | 5 +++-- src/store/modules/user.ts | 16 ++++++++++------ src/utils/request/index.ts | 5 ++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/permission.ts b/src/permission.ts index 5a9ea5e..bde2890 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -4,6 +4,7 @@ import NProgress from 'nprogress'; // progress bar import { MessagePlugin } from 'tdesign-vue-next'; import { RouteRecordRaw } from 'vue-router'; +import { TOKEN_NAME } from '@/config/global'; import router from '@/router'; import { getPermissionStore, getUserStore } from '@/store'; import { PAGE_NOT_FOUND_ROUTE } from '@/utils/route/constant'; @@ -17,8 +18,8 @@ router.beforeEach(async (to, from, next) => { const { whiteListRouters } = permissionStore; const userStore = getUserStore(); - const { token } = userStore; - if (token) { + + if (userStore[TOKEN_NAME]) { if (to.path === '/login') { next(); return; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 7a5fbc1..57bed86 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -10,7 +10,7 @@ const InitUserInfo = { export const useUserStore = defineStore('user', { state: () => ({ - token: localStorage.getItem(TOKEN_NAME) || 'main_token', // 默认token不走权限 + [TOKEN_NAME]: 'main_token', // 默认token不走权限 userInfo: { ...InitUserInfo }, }), getters: { @@ -49,7 +49,7 @@ export const useUserStore = defineStore('user', { const res = await mockLogin(userInfo); if (res.code === 200) { - this.token = res.data; + this.setToken(res.data); } else { throw res; } @@ -67,17 +67,19 @@ export const useUserStore = defineStore('user', { roles: ['UserIndex', 'DashboardBase', 'login'], // 前端权限模型使用 如果使用请配置modules/permission-fe.ts使用 }; }; - const res = await mockRemoteUserInfo(this.token); + const res = await mockRemoteUserInfo(this[TOKEN_NAME]); this.userInfo = res; }, async logout() { - localStorage.removeItem(TOKEN_NAME); - this.token = ''; + this.removeToken(); this.userInfo = { ...InitUserInfo }; }, async removeToken() { - this.token = ''; + this.setToken(''); + }, + async setToken(token: string) { + this[TOKEN_NAME] = token; }, }, persist: { @@ -85,6 +87,8 @@ export const useUserStore = defineStore('user', { const permissionStore = usePermissionStore(); permissionStore.initRoutes(); }, + key: 'user', + paths: [TOKEN_NAME], }, }); diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts index 3dc7ed8..dfa538f 100644 --- a/src/utils/request/index.ts +++ b/src/utils/request/index.ts @@ -5,6 +5,7 @@ import merge from 'lodash/merge'; import { TOKEN_NAME } from '@/config/global'; import { ContentTypeEnum } from '@/constants'; +import { getUserStore } from '@/store'; import { VAxios } from './Axios'; import type { AxiosTransform, CreateAxiosOptions } from './AxiosTransform'; @@ -113,7 +114,9 @@ const transform: AxiosTransform = { // 请求拦截器处理 requestInterceptors: (config, options) => { // 请求之前处理config - const token = localStorage.getItem(TOKEN_NAME); + const userStore = getUserStore(); + const token = userStore[TOKEN_NAME]; + if (token && (config as Recordable)?.requestOptions?.withToken !== false) { // jwt token (config as Recordable).headers.Authorization = options.authenticationScheme From 7a7ee4ab7c9f51fa9a77e837a97e21579234f187 Mon Sep 17 00:00:00 2001 From: yuyang Date: Thu, 18 May 2023 17:58:02 +0800 Subject: [PATCH 05/12] chore: release 0.7.5 (#512) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d29b745..9952028 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tdesign-vue-next-starter", - "version": "0.7.4", + "version": "0.7.5", "scripts": { "dev:mock": "vite --open --mode mock", "dev": "vite --open --mode development", From e773936369bff192a576c231d378c2253ec7abb9 Mon Sep 17 00:00:00 2001 From: liweijie0812 <674416404@qq.com> Date: Fri, 19 May 2023 10:47:10 +0800 Subject: [PATCH 06/12] chore: lint-staged remove git add (#515) --- package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9952028..94b6ce9 100644 --- a/package.json +++ b/package.json @@ -83,12 +83,10 @@ "lint-staged": { "*.{js,jsx,vue,ts,tsx}": [ "prettier --write", - "npm run lint:fix", - "git add ." + "npm run lint:fix" ], "*.{html,vue,vss,sass,less}": [ - "npm run stylelint:fix", - "git add ." + "npm run stylelint:fix" ] } } From f84e348ad1a016f47903dbf1631157e08a7ef229 Mon Sep 17 00:00:00 2001 From: yuyang Date: Fri, 19 May 2023 11:39:50 +0800 Subject: [PATCH 07/12] chore: update package.json for security (#516) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94b6ce9..daa0924 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "tdesign-vue-next-starter", + "name": "@tencent/tdesign-vue-next-starter", "version": "0.7.5", "scripts": { "dev:mock": "vite --open --mode mock", From 09fdbb3465223ff7f443049479a400c1cbd64588 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, 23 May 2023 13:04:45 +0800 Subject: [PATCH 08/12] feat: upgrade tdesign set (#518) --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index daa0924..b258bc6 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "pinia-plugin-persistedstate": "^3.1.0", "qrcode.vue": "^3.3.4", "qs": "^6.11.1", - "tdesign-icons-vue-next": "^0.1.8", - "tdesign-vue-next": "^1.2.2", - "tvision-color": "^1.5.0", + "tdesign-icons-vue-next": "^0.1.11", + "tdesign-vue-next": "^1.3.4", + "tvision-color": "^1.6.0", "vue": "^3.2.47", "vue-clipboard3": "^2.0.0", "vue-router": "~4.1.6" From f9f9e9143822546e6cd129d361dcd63d76b0afab 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, 24 May 2023 10:40:06 +0800 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20=E5=B0=86=E7=8E=B0=E6=9C=89?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=BF=81=E7=A7=BB=E8=87=B3TS=E4=B8=A5?= =?UTF-8?q?=E6=A0=BC=E6=A8=A1=E5=BC=8F=20-=20=E7=A6=81=E6=AD=A2any?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20(#519)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 新增type enum类型 * feat: 开启禁止any类型规则 * types: 优化通知标签类型 * types: 补充标签页移除方法类型 * types: 补充请求工具类型 * types: 补充store相关类型 * types: 补充路由相关类型 * types: 补充钩子类型 * types: 补充页面组件类型 * types: 补充布局类型 * fix: 修复编译问题 --- commitlint.config.js | 11 ++++++++- src/constants/index.ts | 14 +++++++----- src/hooks/index.ts | 2 +- src/layouts/components/Header.vue | 2 +- src/layouts/components/LayoutContent.vue | 15 ++++++------ src/layouts/components/LayoutSideNav.vue | 3 ++- src/layouts/setting.vue | 2 +- src/pages/dashboard/base/index.ts | 3 ++- src/pages/detail/advanced/constants.ts | 8 +++---- src/pages/detail/advanced/index.vue | 6 ++--- src/pages/detail/deploy/constants.ts | 4 ++-- src/pages/detail/deploy/index.vue | 9 +++----- src/pages/detail/secondary/index.vue | 2 +- src/pages/form/base/constants.ts | 4 ++-- src/pages/form/base/index.vue | 13 ++++++----- src/pages/form/step/index.vue | 10 ++++---- src/pages/list/base/index.vue | 4 ++-- src/pages/list/card/index.vue | 28 +++++++++++++++++++---- src/pages/list/components/CommonTable.vue | 20 ++++++++-------- src/pages/list/tree/index.vue | 6 ++--- src/pages/login/components/Login.vue | 6 ++--- src/pages/login/components/Register.vue | 9 ++++---- src/pages/user/constants.ts | 8 ++++++- src/pages/user/index.vue | 14 ++++++++---- src/router/index.ts | 2 +- src/store/modules/permission-fe.ts | 8 +++---- src/store/modules/setting.ts | 5 ++-- src/store/modules/tabs-router.ts | 6 ++--- src/store/modules/user.ts | 3 ++- src/types/interface.d.ts | 12 ++++++++++ src/utils/request/utils.ts | 2 +- tsconfig.json | 3 ++- 32 files changed, 151 insertions(+), 93 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index 405e185..20116c9 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,2 +1,11 @@ // commit-lint config -module.exports = { extends: ['@commitlint/config-conventional'] }; +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'type-enum': [ + 2, + 'always', + ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test', 'types'], + ], + }, +}; diff --git a/src/constants/index.ts b/src/constants/index.ts index 7c822ce..4438b88 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -34,12 +34,14 @@ export const CONTRACT_PAYMENT_TYPES = { RECEIPT: 1, }; -// 通知的优先级对应的TAG类型 -export const NOTIFICATION_TYPES = { - low: 'primary', - middle: 'warning', - high: 'danger', -}; +// 标签类型 +type TagTheme = 'default' | 'success' | 'primary' | 'warning' | 'danger'; +// 通知的优先级对应的标签类型 +export const NOTIFICATION_TYPES: Map = new Map([ + ['low', 'primary'], + ['middle', 'warning'], + ['high', 'danger'], +]); // 通用请求头 export enum ContentTypeEnum { diff --git a/src/hooks/index.ts b/src/hooks/index.ts index fe47d70..3c26653 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -39,7 +39,7 @@ export const useChart = (domId: string): Ref => { * @returns */ export const useCounter = (duration = 60): [Ref, () => void] => { - let intervalTimer; + let intervalTimer: ReturnType; onUnmounted(() => { clearInterval(intervalTimer); }); diff --git a/src/layouts/components/Header.vue b/src/layouts/components/Header.vue index c74bce7..69bf443 100644 --- a/src/layouts/components/Header.vue +++ b/src/layouts/components/Header.vue @@ -141,7 +141,7 @@ const changeCollapsed = () => { }); }; -const handleNav = (url) => { +const handleNav = (url: string) => { router.push(url); }; diff --git a/src/layouts/components/LayoutContent.vue b/src/layouts/components/LayoutContent.vue index 32c1c57..c0bf5ad 100644 --- a/src/layouts/components/LayoutContent.vue +++ b/src/layouts/components/LayoutContent.vue @@ -24,7 +24,7 @@ :min-column-width="128" :popup-props="{ overlayClassName: 'route-tabs-dropdown', - onVisibleChange: (visible, ctx) => handleTabMenuClick(visible, ctx, routeItem.path), + onVisibleChange: (visible: boolean, ctx: PopupVisibleChangeContext) => handleTabMenuClick(visible, ctx, routeItem.path), visible: activeTabPath === routeItem.path, }" > @@ -70,12 +70,13 @@ diff --git a/src/pages/detail/secondary/index.vue b/src/pages/detail/secondary/index.vue index cde49dc..04b336f 100644 --- a/src/pages/detail/secondary/index.vue +++ b/src/pages/detail/secondary/index.vue @@ -6,7 +6,7 @@

- + {{ item.type }} {{ item.content }} diff --git a/src/pages/form/base/constants.ts b/src/pages/form/base/constants.ts index e321b9d..e8503a0 100644 --- a/src/pages/form/base/constants.ts +++ b/src/pages/form/base/constants.ts @@ -1,4 +1,4 @@ -import { FormRule } from 'tdesign-vue-next'; +import type { FormRule, UploadFile } from 'tdesign-vue-next'; export const FORM_RULES: Record = { name: [{ required: true, message: '请输入合同名称', type: 'error' }], @@ -23,7 +23,7 @@ export const INITIAL_DATA = { payment: '1', amount: 0, comment: '', - files: [], + files: [] as Array, }; export const TYPE_OPTIONS = [ diff --git a/src/pages/form/base/index.vue b/src/pages/form/base/index.vue index 267fdd2..514876d 100644 --- a/src/pages/form/base/index.vue +++ b/src/pages/form/base/index.vue @@ -164,6 +164,7 @@ export default { diff --git a/src/pages/form/step/index.vue b/src/pages/form/step/index.vue index 7d446be..0f0736a 100644 --- a/src/pages/form/step/index.vue +++ b/src/pages/form/step/index.vue @@ -29,7 +29,7 @@ :data="formData1" :rules="FORM_RULES" label-align="right" - @submit="(result) => onSubmit(result, 1)" + @submit="(result: SubmitContext) => onSubmit(result, 1)" > @@ -59,7 +59,7 @@ :rules="FORM_RULES" label-align="left" @reset="onReset(0)" - @submit="(result) => onSubmit(result, 2)" + @submit="(result: SubmitContext) => onSubmit(result, 2)" > @@ -96,7 +96,7 @@ :rules="FORM_RULES" label-align="left" @reset="onReset(1)" - @submit="(result) => onSubmit(result, 6)" + @submit="(result: SubmitContext) => onSubmit(result, 6)" > @@ -147,7 +147,7 @@ export default { diff --git a/src/pages/list/components/CommonTable.vue b/src/pages/list/components/CommonTable.vue index 0323863..8df81d0 100644 --- a/src/pages/list/components/CommonTable.vue +++ b/src/pages/list/components/CommonTable.vue @@ -122,7 +122,7 @@ import { useSettingStore } from '@/store'; const store = useSettingStore(); -const COLUMNS: PrimaryTableCol[] = [ +const COLUMNS: PrimaryTableCol[] = [ { title: '合同名称', fixed: 'left', @@ -167,8 +167,8 @@ const COLUMNS: PrimaryTableCol[] = [ const searchForm = { name: '', - no: undefined, - status: undefined, + no: '', + status: typeof CONTRACT_STATUS, type: '', }; @@ -233,24 +233,24 @@ onMounted(() => { fetchData(); }); -const handleClickDelete = ({ row }) => { - deleteIdx.value = row.rowIndex; +const handleClickDelete = (slot: { row: { rowIndex: number } }) => { + deleteIdx.value = slot.row.rowIndex; confirmVisible.value = true; }; -const onReset = (val) => { +const onReset = (val: unknown) => { console.log(val); }; -const onSubmit = (val) => { +const onSubmit = (val: unknown) => { console.log(val); }; const rehandlePageChange = (pageInfo: PageInfo, newDataSource: TableRowData[]) => { console.log('分页变化', pageInfo, newDataSource); }; -const rehandleChange = (changeParams, triggerAndData) => { +const rehandleChange = (changeParams: unknown, triggerAndData: unknown) => { console.log('统一Change', changeParams, triggerAndData); }; -const rehandleClickOp = ({ text, row }) => { - console.log(text, row); +const rehandleClickOp = (ctx: unknown) => { + console.log(ctx); }; const headerAffixedTop = computed( diff --git a/src/pages/list/tree/index.vue b/src/pages/list/tree/index.vue index 7101634..16b73c0 100644 --- a/src/pages/list/tree/index.vue +++ b/src/pages/list/tree/index.vue @@ -24,6 +24,7 @@ export default { diff --git a/src/pages/login/components/Login.vue b/src/pages/login/components/Login.vue index 24ba884..43339c7 100644 --- a/src/pages/login/components/Login.vue +++ b/src/pages/login/components/Login.vue @@ -80,7 +80,7 @@