From bc54630d0af8f7965118490fe1c28da544e9d71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Thu, 28 Apr 2022 17:36:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=A1=A8=E5=8D=95=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/extra.code-snippets | 6 ++++++ src/plugins/global-api.js | 20 ++++++++++++++++++++ src/views/global/login.vue | 4 ++-- src/views/operation/limit/index.vue | 2 +- src/views/sales/category/form.vue | 2 +- src/views/sales/category/index.vue | 3 ++- src/views/sales/order/address.vue | 4 ++-- src/views/sales/order/cancel.vue | 4 ++-- src/views/sales/order/close.vue | 4 ++-- src/views/sales/order/fees.vue | 4 ++-- src/views/sales/product/form/step1.vue | 3 ++- src/views/sales/product/picker.vue | 1 + src/views/sales/service/detail.vue | 9 +++++---- src/views/system/employee/form.vue | 3 ++- src/views/system/notify/index.vue | 3 ++- vite.config.js | 4 ++-- 16 files changed, 54 insertions(+), 22 deletions(-) diff --git a/.vscode/extra.code-snippets b/.vscode/extra.code-snippets index 7eb1558..0d27d62 100644 --- a/.vscode/extra.code-snippets +++ b/.vscode/extra.code-snippets @@ -46,5 +46,11 @@ "prefix": "trycatch", "body": ["try {", "\t$0", "} catch (e) {", "\tconsole.info('取消$1', e);", "}"], "description": "TryCatch代码块" + }, + "proxy": { + "scope": "javascript,typescript", + "prefix": "proxy", + "body": ["const { proxy } = getCurrentInstance();"], + "description": "proxy对象" } } diff --git a/src/plugins/global-api.js b/src/plugins/global-api.js index dcbeffe..f82a9fa 100644 --- a/src/plugins/global-api.js +++ b/src/plugins/global-api.js @@ -95,10 +95,30 @@ export const name = (nickname, realname) => { return realname ? `${nickname}(${realname})` : nickname; }; +/** + * 表单校验 + * @param {*} refsForm 表单组件 + */ +export const validate = (refsForm) => { + return new Promise((resolve, reject) => { + (async () => { + try { + await unref(refsForm).validate(); + resolve(); + } catch (e) { + console.info('校验失败', e); + unref(refsForm).scrollToField(Object.keys(e)[0]); + reject(e); + } + })(); + }); +}; + export default (app) => { app.config.globalProperties.$copy = copy; app.config.globalProperties.$download = download; app.config.globalProperties.$excel = excel; app.config.globalProperties.$dict = dict; app.config.globalProperties.$name = name; + app.config.globalProperties.$validate = validate; }; diff --git a/src/views/global/login.vue b/src/views/global/login.vue index 83cfd3b..b5d5d37 100644 --- a/src/views/global/login.vue +++ b/src/views/global/login.vue @@ -42,7 +42,7 @@