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) + } + } + } +}