From eb036b6488f42afca9c150e42f298e448416a723 Mon Sep 17 00:00:00 2001 From: yuntian001 Date: Tue, 20 Dec 2022 16:33:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20loginApi=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E8=BF=94=E5=9B=9Eaxios=E8=A7=84=E9=81=BFvue-request=E9=9D=9Ese?= =?UTF-8?q?tup=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 16 ++++++++++------ src/store/modules/user.ts | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index 99a937b2..52101176 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -14,12 +14,16 @@ export class LoginParams { export interface LoginResult { token: string; } -export function loginApi() { - return request((params) => ({ - url: Api.LOGIN, - method: 'post', - data: params, - })); +export function loginApi(returnAxios: T = true as T) { + return request( + (params) => ({ + url: Api.LOGIN, + method: 'post', + data: params, + }), + {}, + returnAxios, + ); } // 获取用户详细信息 diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 3f1bfd6b..a40d01f5 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -60,7 +60,7 @@ export default defineStore({ // 登录 login: async function (params: LoginParams) { mitter.emit(event.BEFORE_LOGIN); - const res = await loginApi().runAsync(params); + const res = await loginApi()(params); await this.init(res.token); mitter.emit(event.AFTER_LOGIN); }, From 8a9e731ad8c0708f7e7fe53270ad50503c531a8c Mon Sep 17 00:00:00 2001 From: yuntian001 Date: Tue, 20 Dec 2022 16:42:15 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=83=AD=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=90=8E=E5=81=B6=E7=8E=B0=E9=A1=B5=E9=9D=A2loading?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit layout lodaing直接根据api调用和pinia脱离关联 --- src/layout/index.vue | 2 +- src/store/modules/global.ts | 14 -------------- src/utils/loading.ts | 18 ++++++++++-------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/layout/index.vue b/src/layout/index.vue index fec3e15f..05981340 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -10,7 +10,7 @@ -
+
diff --git a/src/store/modules/global.ts b/src/store/modules/global.ts index fc1af3f1..b3809cbe 100644 --- a/src/store/modules/global.ts +++ b/src/store/modules/global.ts @@ -27,21 +27,7 @@ export default defineStore('global', { }; }), isMobile, - loadingOptions: undefined as undefined | LoadingOptions, layoutLoaded: false, }; }, - getters: { - layoutLoading: (state) => Boolean(state.loadingOptions), - layoutLoadingOptions() { - if (!this.loadingOptions) { - return {}; - } - const options = {} as { [key in keyof LoadingOptions as `element-loading-${key}`]: LoadingOptions[key] }; - forOwn(this.loadingOptions, function (value, key) { - options[('element-loading-' + key) as keyof typeof options] = value as any; - }); - return options; - }, - }, }); diff --git a/src/utils/loading.ts b/src/utils/loading.ts index 4d265882..3d6ebfbf 100644 --- a/src/utils/loading.ts +++ b/src/utils/loading.ts @@ -1,13 +1,12 @@ -import { useGlobalStore } from '@/store'; import { LoadingOptions } from 'element-plus'; import { throttle } from 'lodash-es'; -let loadingInstance: ReturnType; +const loadingInstance: Record> = {}; class Loading { constructor(private execLoading: (options?: LoadingOptions) => void, private execClose: () => void) { this.execLoading = execLoading; this.execClose = execClose; } - private number = 0; + public number = 0; public loading(options?: LoadingOptions, number = 1) { this.number += number; this.execLoading(options); @@ -26,23 +25,26 @@ class Loading { if (this.number > 0) { this.number -= Math.min(this.number, number); this.throttleClose(); + } else { + this.forceClose(); } } public forceClose() { this.number = 0; - loadingInstance.close(); + this.execClose(); this.throttleClose.cancel(); } } export const loadingObject = { global: new Loading( - (options?: LoadingOptions) => (loadingInstance = ElLoading.service(options)), - () => loadingInstance.close(), + (options?: LoadingOptions) => (loadingInstance.global = ElLoading.service(options)), + () => loadingInstance.global?.close(), ), layout: new Loading( - (options?: LoadingOptions) => (useGlobalStore().loadingOptions = options ? reactive(options) : {}), - () => (useGlobalStore().loadingOptions = undefined), + (options?: LoadingOptions) => + (loadingInstance.layout = ElLoading.service(Object.assign({ target: '#me-main' }, options))), + () => loadingInstance.layout?.close(), ), }; From 67fd3c40b0df4693378a138582da8206192f47ec Mon Sep 17 00:00:00 2001 From: yuntian001 Date: Tue, 20 Dec 2022 16:48:57 +0800 Subject: [PATCH 3/4] =?UTF-8?q?docs:=20=E7=89=B9=E6=80=A7=E4=BB=8B?= =?UTF-8?q?=E7=BB=8D=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d988aef9..0c99072c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ Me-admin template是一个免费开源的中后台模板,基于vue3、vite3、 p - **Mock 数据** 内置mock数据方案便于测试 - **组件自动引入** 自动按需引入components下的组件定义,可以自定义引入模式和模板,真正的按需引入 - **便捷的类型自动生成** 自动生成ts type 最大程度减少工作量 - + - **友好的request封装** 基于vue-request+axios的request api封装和vue3响应式语法糖深度耦合。 + ## 预览 - 完整版国外访问:[https://meadmin-cn.github.io/meadmin-template](https://meadmin-cn.github.io/meadmin-template) - 完整版国内访问:[https://meadmin-cn.gitee.io/meadmin-template](https://meadmin-cn.gitee.io/meadmin-template) From 4b0a3fcfced7d2f6e051e8b2ecd45e8b1ed0adb0 Mon Sep 17 00:00:00 2001 From: yuntian001 Date: Tue, 20 Dec 2022 16:51:09 +0800 Subject: [PATCH 4/4] chore: template-release v1.1.6 --- TEMPLATE-CHANGELOG.md | 17 +++++++++++++++++ package.json | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/TEMPLATE-CHANGELOG.md b/TEMPLATE-CHANGELOG.md index 1211a14b..f50e739b 100644 --- a/TEMPLATE-CHANGELOG.md +++ b/TEMPLATE-CHANGELOG.md @@ -1,5 +1,22 @@ +## [1.1.6](https://github.com/meadmin-cn/meadmin-template/compare/template-1.1.4...template-1.1.6) (2022-12-20) + + +### 重构[refactor] + +* loginApi直接返回axios规避vue-request非setup警告 ([eb036b6](https://github.com/meadmin-cn/meadmin-template/commit/eb036b6488f42afca9c150e42f298e448416a723)) + + +### Bug 修复[fix] + +* 修复热更新后偶现页面loading无法关闭的bug ([8a9e731](https://github.com/meadmin-cn/meadmin-template/commit/8a9e731ad8c0708f7e7fe53270ad50503c531a8c)) + + +### 文档更改[docs] + +* 特性介绍添加 ([67fd3c4](https://github.com/meadmin-cn/meadmin-template/commit/67fd3c40b0df4693378a138582da8206192f47ec)) + ## [1.1.4](https://github.com/meadmin-cn/meadmin-template/compare/template-1.1.3...template-1.1.4) (2022-12-19) diff --git a/package.json b/package.json index 6d08209d..9c4405a1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "meadmin-template", "private": true, - "version": "1.1.4", + "version": "1.1.6", "type": "module", "author": { "name": "meadmin-cn",