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 @@