增加装饰器类 确认弹窗,loading,节流
This commit is contained in:
61
ui/lib/js/decorator.js
Normal file
61
ui/lib/js/decorator.js
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user