From 812e085795ad429e55297bf86b0b1964960b228f Mon Sep 17 00:00:00 2001 From: aixianling Date: Mon, 13 Mar 2023 15:42:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A3=85=E9=A5=B0=E5=99=A8?= =?UTF-8?q?=E7=B1=BB=20=E7=A1=AE=E8=AE=A4=E5=BC=B9=E7=AA=97,loading,?= =?UTF-8?q?=E8=8A=82=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/lib/js/decorator.js | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ui/lib/js/decorator.js diff --git a/ui/lib/js/decorator.js b/ui/lib/js/decorator.js new file mode 100644 index 00000000..54b29c5e --- /dev/null +++ b/ui/lib/js/decorator.js @@ -0,0 +1,61 @@ +import {Loading, MessageBox} from "element-ui"; + +/** + * 确认按钮 + * @param content 提示信息 + * @returns {(function(*, *, *): void)|*} + */ +export function confirm(content) { + return function (target, name, descriptor) { + const origin = descriptor.value + descriptor.value = function (...args) { + MessageBox.confirm(content, { + type: 'warning', + confirmButtonText: '确认', + center: true, + title: '提示', + dangerouslyUseHTMLString: true, + customClass: "AiConfirm", + }).then(origin.bind(this, ...args)).catch(() => 0) + } + } +} + +/** + * 锁屏loading + * @returns {(function(*, *, *): void)|*} + */ +export function loading() { + return function (target, name, descriptor) { + const origin = descriptor.value + descriptor.value = async function (...args) { + const loading = Loading.service({fullscreen: true}) + try { + await origin.apply(this, args) + } finally { + loading.close() + } + } + } +} + +/** + * 节流装饰器 + * @param wait 等待时间 + * @returns {(function(*, *, *): void)|*} + */ +export function throttle(wait) { + return function (target, name, descriptor) { + const origin = descriptor.value + let lock = false + descriptor.value = function () { + if (!lock) { + lock = true + origin.apply(this, arguments) + setTimeout(() => { + lock = false + }, wait) + } + } + } +}