From eef160a6bad0cc91686726c4492ec66a569fc19c Mon Sep 17 00:00:00 2001 From: icssoa <615206459@qq.com> Date: Thu, 4 Aug 2022 12:38:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=85=BC=E5=AE=B9=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- src/cool/router/index.ts | 76 ++++++++++--------- src/cool/service/request.ts | 2 + src/cool/types/index.d.ts | 1 + src/cool/utils/loading.ts | 2 +- src/modules/base/components/select/index.vue | 2 +- src/modules/base/pages/login/index.vue | 5 +- src/modules/chat/store/message.ts | 4 +- src/modules/chat/store/session.ts | 4 +- .../views/home/components/category-ratio.vue | 7 +- .../demo/views/home/components/count-paid.vue | 8 +- .../views/home/components/count-views.vue | 44 +++++------ .../demo/views/home/components/hot-search.vue | 44 +++++------ .../demo/views/home/components/tab-chart.vue | 8 +- src/modules/dict/store/dict.ts | 4 +- src/modules/dict/views/list.vue | 8 +- src/modules/upload/components/index.vue | 6 +- yarn.lock | 35 +++++++-- 18 files changed, 134 insertions(+), 130 deletions(-) diff --git a/package.json b/package.json index 9cb161e..9176d35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "front-next", - "version": "5.7.7", + "version": "5.7.8", "scripts": { "dev": "vite --host", "build": "vite build", @@ -11,7 +11,7 @@ "dependencies": { "@codemirror/lang-javascript": "^6.0.1", "@codemirror/theme-one-dark": "^6.0.0", - "@cool-vue/crud": "^5.3.2", + "@cool-vue/crud": "^5.3.5", "@element-plus/icons-vue": "^2.0.6", "@vueuse/core": "^8.9.4", "axios": "^0.27.2", diff --git a/src/cool/router/index.ts b/src/cool/router/index.ts index 9117168..fb5811a 100644 --- a/src/cool/router/index.ts +++ b/src/cool/router/index.ts @@ -48,9 +48,7 @@ router.href = function (path) { router.append = function (data) { const list = isArray(data) ? data : [data]; - list.forEach((e) => { - const d = { ...e }; - + list.forEach((d) => { if (!d.name) { d.name = d.path.substring(1); } @@ -73,7 +71,7 @@ router.append = function (data) { } } - if (e.isPage) { + if (d.isPage) { router.addRoute(d); } else { router.addRoute("index", d); @@ -81,6 +79,11 @@ router.append = function (data) { }); }; +// 找路由 +router.find = function (path: string) { + return router.getRoutes().find((e) => e.path == path); +}; + let lock = false; // 错误监听 @@ -100,9 +103,9 @@ router.onError((err: any) => { // 注册 async function register(path: string) { // 当前路由是否存在 - const d = router.getRoutes().find((e) => e.path == path); + const f = Boolean(router.find(path)); - if (!d) { + if (!f) { const { menu } = useBase(); // 等待加载 @@ -143,46 +146,49 @@ async function register(path: string) { if (r) { router.append(r); } - - return r?.path || "/404"; - } else { - return null; } + + return { route: router.find(path), isReg: !f }; } // 路由守卫 router.beforeEach(async (to, from, next) => { - // 注册路由 - const path = await register(to.path); + // 数据缓存 + const { user, process } = useBase(); - if (path) { - // 重定向 - next({ ...to, path }); + // 预先注册路由 + const { isReg, route } = await register(to.path); + + // 组件不存在、路由不存在 + if (!route?.components) { + next(user.token ? "/404" : "/login"); } else { - // 数据缓存 - const { user, process } = useBase(); - - // 登录成功 - if (user.token) { - // 在登录页 - if (to.path.includes("/login")) { - // Token 未过期 - if (!storage.isExpired("token")) { - // 回到首页 - return next("/"); + // 注册后重定向 + if (isReg) { + next({ ...to, path: route.path }); + } else { + // 登录成功 + if (user.token) { + // 在登录页 + if (to.path.includes("/login")) { + // Token 未过期 + if (!storage.isExpired("token")) { + // 回到首页 + return next("/"); + } + } else { + // 添加路由进程 + process.add(to); } } else { - // 添加路由进程 - process.add(to); + // 忽略部分 Token 验证 + if (!config.ignore.token.find((e) => to.path == e)) { + return next("/login"); + } } - } else { - // 忽略部分 Token 验证 - if (!config.ignore.token.find((e) => to.path == e)) { - return next("/login"); - } - } - next(); + next(); + } } }); diff --git a/src/cool/service/request.ts b/src/cool/service/request.ts index ec365d0..18cb388 100644 --- a/src/cool/service/request.ts +++ b/src/cool/service/request.ts @@ -124,6 +124,8 @@ request.interceptors.response.use( const { status, config } = error.response; const { user } = useBase(); + console.log(config); + if (status == 401) { user.logout(); } diff --git a/src/cool/types/index.d.ts b/src/cool/types/index.d.ts index 73a982e..b89c524 100644 --- a/src/cool/types/index.d.ts +++ b/src/cool/types/index.d.ts @@ -28,6 +28,7 @@ export declare interface Module extends ModuleConfig { export declare interface Router extends VueRouter { href(path: string): void; + find(path: string): RouteRecordRaw | undefined; append(data: any[] | any): void; [key: string]: any; } diff --git a/src/cool/utils/loading.ts b/src/cool/utils/loading.ts index 71f3c93..8d49363 100644 --- a/src/cool/utils/loading.ts +++ b/src/cool/utils/loading.ts @@ -9,7 +9,7 @@ export const Loading = { this.resolve(); }, - wait() { + async wait() { return this.next; }, diff --git a/src/modules/base/components/select/index.vue b/src/modules/base/components/select/index.vue index 7680b18..316adfd 100644 --- a/src/modules/base/components/select/index.vue +++ b/src/modules/base/components/select/index.vue @@ -19,7 +19,7 @@ export default defineComponent({ props: { modelValue: [String, Number], options: { - type: Array, + type: [Array, Object], default: () => [] }, prop: String diff --git a/src/modules/base/pages/login/index.vue b/src/modules/base/pages/login/index.vue index 4c9992d..e35ac47 100644 --- a/src/modules/base/pages/login/index.vue +++ b/src/modules/base/pages/login/index.vue @@ -13,7 +13,7 @@ v-model="form.username" placeholder="请输入用户名" maxlength="20" - auto-complete="off" + autocomplete="on" /> @@ -23,7 +23,7 @@ type="password" placeholder="请输入密码" maxlength="20" - auto-complete="off" + autocomplete="off" /> @@ -33,7 +33,6 @@ v-model="form.verifyCode" placeholder="图片验证码" maxlength="4" - auto-complete="off" @keyup.enter="toLogin" /> diff --git a/src/modules/chat/store/message.ts b/src/modules/chat/store/message.ts index 173c03a..e829928 100644 --- a/src/modules/chat/store/message.ts +++ b/src/modules/chat/store/message.ts @@ -1,10 +1,8 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import { useCool } from "/@/cool"; +import { service } from "/@/cool"; export const useMessageStore = defineStore("chat-message", () => { - const { service } = useCool(); - // 加载状态 const loading = ref(false); diff --git a/src/modules/chat/store/session.ts b/src/modules/chat/store/session.ts index b616039..a98ecb6 100644 --- a/src/modules/chat/store/session.ts +++ b/src/modules/chat/store/session.ts @@ -1,10 +1,8 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import { useCool } from "/@/cool"; +import { service } from "/@/cool"; export const useSessionStore = defineStore("chat-session", () => { - const { service } = useCool(); - // 加载状态 const loading = ref(false); diff --git a/src/modules/demo/views/home/components/category-ratio.vue b/src/modules/demo/views/home/components/category-ratio.vue index 9d855c3..469cceb 100644 --- a/src/modules/demo/views/home/components/category-ratio.vue +++ b/src/modules/demo/views/home/components/category-ratio.vue @@ -31,7 +31,6 @@ const chartOption = reactive({ radius: ["50%", "60%"], center: ["50%", "40%"], avoidLabelOverlap: false, - hoverAnimation: false, label: { show: false, position: "center" @@ -54,10 +53,8 @@ const chartOption = reactive({ { value: 500, name: "手表" } ], itemStyle: { - normal: { - borderColor: "#fff", - borderWidth: 4 - } + borderColor: "#fff", + borderWidth: 4 }, roundCap: 1 } diff --git a/src/modules/demo/views/home/components/count-paid.vue b/src/modules/demo/views/home/components/count-paid.vue index 5abaf48..1690889 100644 --- a/src/modules/demo/views/home/components/count-paid.vue +++ b/src/modules/demo/views/home/components/count-paid.vue @@ -55,9 +55,7 @@ const chartOption = reactive({ type: "bar", data: [81, 24, 77, 13, 87, 92, 68, 55], itemStyle: { - normal: { - color: "#4165d7" - } + color: "#4165d7" } }, { @@ -67,9 +65,7 @@ const chartOption = reactive({ barGap: "-100%", data: [100, 100, 100, 100, 100, 100, 100, 100], itemStyle: { - normal: { - color: "#f1f1f9" - } + color: "#f1f1f9" }, zlevel: -1 } diff --git a/src/modules/demo/views/home/components/count-views.vue b/src/modules/demo/views/home/components/count-views.vue index c4ce69f..58cb7e9 100644 --- a/src/modules/demo/views/home/components/count-views.vue +++ b/src/modules/demo/views/home/components/count-views.vue @@ -85,35 +85,29 @@ const chartOption = reactive({ "1322" ], areaStyle: { - normal: { - color: new echarts.graphic.LinearGradient( - 0, - 0, - 0, - 1, - [ - { - offset: 0, - color: "#D1E5FF" - }, - { - offset: 1, - color: "#FFFFFF" - } - ], - false - ) - } + color: new echarts.graphic.LinearGradient( + 0, + 0, + 0, + 1, + [ + { + offset: 0, + color: "#D1E5FF" + }, + { + offset: 1, + color: "#FFFFFF" + } + ], + false + ) }, itemStyle: { - normal: { - color: "#4165d7" - } + color: "#4165d7" }, lineStyle: { - normal: { - width: 2 - } + width: 2 } } ] diff --git a/src/modules/demo/views/home/components/hot-search.vue b/src/modules/demo/views/home/components/hot-search.vue index c8ecd47..3c63401 100644 --- a/src/modules/demo/views/home/components/hot-search.vue +++ b/src/modules/demo/views/home/components/hot-search.vue @@ -151,35 +151,29 @@ const chartOption = reactive({ "1322" ], areaStyle: { - normal: { - color: new echarts.graphic.LinearGradient( - 0, - 0, - 0, - 1, - [ - { - offset: 0, - color: "#D1E5FF" - }, - { - offset: 1, - color: "#FFFFFF" - } - ], - false - ) - } + color: new echarts.graphic.LinearGradient( + 0, + 0, + 0, + 1, + [ + { + offset: 0, + color: "#D1E5FF" + }, + { + offset: 1, + color: "#FFFFFF" + } + ], + false + ) }, itemStyle: { - normal: { - color: "#4165d7" - } + color: "#4165d7" }, lineStyle: { - normal: { - width: 2 - } + width: 2 } } ] diff --git a/src/modules/demo/views/home/components/tab-chart.vue b/src/modules/demo/views/home/components/tab-chart.vue index 8084b2c..b3641d9 100644 --- a/src/modules/demo/views/home/components/tab-chart.vue +++ b/src/modules/demo/views/home/components/tab-chart.vue @@ -76,9 +76,7 @@ const chartOption = reactive({ type: "bar", data: [], itemStyle: { - normal: { - color: "#4165d7" - } + color: "#4165d7" } }, { @@ -88,9 +86,7 @@ const chartOption = reactive({ barGap: "-100%", data: [], itemStyle: { - normal: { - color: "#f1f1f9" - } + color: "#f1f1f9" }, zlevel: -1 } diff --git a/src/modules/dict/store/dict.ts b/src/modules/dict/store/dict.ts index 9af011d..73f9a8a 100644 --- a/src/modules/dict/store/dict.ts +++ b/src/modules/dict/store/dict.ts @@ -1,14 +1,12 @@ import { defineStore } from "pinia"; import { computed, reactive } from "vue"; -import { isDev, useCool } from "/@/cool"; +import { isDev, service } from "/@/cool"; declare interface Data { [key: string]: Array<{ label: string; value: any }>; } export const useDictStore = defineStore("dict", () => { - const { service } = useCool(); - // 对象数据 const data = reactive({}); diff --git a/src/modules/dict/views/list.vue b/src/modules/dict/views/list.vue index 5d6dd46..d1f58e5 100644 --- a/src/modules/dict/views/list.vue +++ b/src/modules/dict/views/list.vue @@ -166,11 +166,11 @@ const Table = useTable({ "order-desc" ], columns: [ - { label: "名称", prop: "name", align: "left" }, + { label: "名称", prop: "name", align: "left", minWidth: 200 }, { label: "排序", prop: "orderNum", sortable: "custom", width: 100 }, - { label: "备注", prop: "remark", showOverflowTooltip: true }, - { label: "创建时间", prop: "createTime", sortable: "custom" }, - { label: "更新时间", prop: "updateTime", sortable: "custom" }, + { label: "备注", prop: "remark", showOverflowTooltip: true, minWidth: 150 }, + { label: "创建时间", prop: "createTime", sortable: "custom", minWidth: 160 }, + { label: "更新时间", prop: "updateTime", sortable: "custom", minWidth: 160 }, { type: "op", width: 250, diff --git a/src/modules/upload/components/index.vue b/src/modules/upload/components/index.vue index c705fe8..d3fd20d 100644 --- a/src/modules/upload/components/index.vue +++ b/src/modules/upload/components/index.vue @@ -171,7 +171,11 @@ const props = defineProps({ default: true }, drag: Boolean, - disabled: Boolean + disabled: Boolean, + + // 穿透值 + isEdit: null, + scope: null }); const emit = defineEmits(["update:modelValue", "upload", "success", "error", "progress"]); diff --git a/yarn.lock b/yarn.lock index e07040b..c4da194 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1052,17 +1052,17 @@ style-mod "^4.0.0" w3c-keyname "^2.2.4" -"@cool-vue/crud@^5.3.2": - version "5.3.2" - resolved "https://registry.npmjs.org/@cool-vue/crud/-/crud-5.3.2.tgz#61b01eb012688a0539e5939958cd9fb2bf60513a" - integrity sha512-tHmF6OGjGvoOCPTSzgFKv6x3UvFLDKq5NIneHx1jeoJwPE422lWHd/CeBr/tLq7pvFrRMsKWhlvD6moyfZDiQA== +"@cool-vue/crud@^5.3.5": + version "5.3.5" + resolved "https://registry.npmjs.org/@cool-vue/crud/-/crud-5.3.5.tgz#350d7b307ce1d0445b78f179ec2d0f16eb91b99c" + integrity sha512-xWwxv2zQCYGt4GqHg1vDEsiv2sGhJCKYKjxDW6hTo5O/oNuzm8uVcWGVGKyYn5y8//F8wcmod4Kk1L/OvdvS5w== dependencies: array.prototype.flat "^1.2.4" core-js "^3.21.1" - element-plus "^2.2.11" + element-plus "^2.2.12" merge "^2.1.1" mitt "^3.0.0" - vue "^3.2.31" + vue "^3.2.37" "@ctrl/tinycolor@^3.4.1": version "3.4.1" @@ -2467,6 +2467,27 @@ element-plus@^2.2.11: memoize-one "^6.0.0" normalize-wheel-es "^1.2.0" +element-plus@^2.2.12: + version "2.2.12" + resolved "https://registry.npmjs.org/element-plus/-/element-plus-2.2.12.tgz#b6c4e298e02ba9b904d70daa54def27b2de8c43c" + integrity sha512-g/hIHj3b+dND2R3YRvyvCJtJhQvR7lWvXqhJaoxaQmajjNWedoe4rttxG26fOSv9YCC2wN4iFDcJHs70YFNgrA== + dependencies: + "@ctrl/tinycolor" "^3.4.1" + "@element-plus/icons-vue" "^2.0.6" + "@floating-ui/dom" "^0.5.4" + "@popperjs/core" "npm:@sxzz/popperjs-es@^2.11.7" + "@types/lodash" "^4.14.182" + "@types/lodash-es" "^4.17.6" + "@vueuse/core" "^8.7.5" + async-validator "^4.2.5" + dayjs "^1.11.3" + escape-html "^1.0.3" + lodash "^4.17.21" + lodash-es "^4.17.21" + lodash-unified "^1.0.2" + memoize-one "^6.0.0" + normalize-wheel-es "^1.2.0" + emojis-list@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78" @@ -4718,7 +4739,7 @@ vue-router@^4.1.2: dependencies: "@vue/devtools-api" "^6.1.4" -vue@^3.2.31, vue@^3.2.37: +vue@^3.2.37: version "3.2.37" resolved "https://registry.npmjs.org/vue/-/vue-3.2.37.tgz#da220ccb618d78579d25b06c7c21498ca4e5452e" integrity sha512-bOKEZxrm8Eh+fveCqS1/NkG/n6aMidsI6hahas7pa0w/l7jkbssJVsRhVDs07IdDq7h9KHswZOgItnwJAgtVtQ==