Merge branch 'build' of http://git.sinoecare.com/sinoecare/digital_village_v2/dvcp_v2_webapp into build
This commit is contained in:
@@ -45,17 +45,58 @@ export function loading() {
|
|||||||
* @returns {(function(*, *, *): void)|*}
|
* @returns {(function(*, *, *): void)|*}
|
||||||
*/
|
*/
|
||||||
export function throttle(wait) {
|
export function throttle(wait) {
|
||||||
return function (target, name, descriptor) {
|
let timer;
|
||||||
|
return function (t, n, descriptor) {
|
||||||
const origin = descriptor.value
|
const origin = descriptor.value
|
||||||
let lock = false
|
|
||||||
descriptor.value = function () {
|
descriptor.value = function () {
|
||||||
if (!lock) {
|
if (!timer) {
|
||||||
lock = true
|
|
||||||
origin.apply(this, arguments)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
lock = false
|
origin.apply(this, arguments)
|
||||||
|
timer = null
|
||||||
}, wait)
|
}, wait)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载第三方sdk
|
||||||
|
* @param sdk
|
||||||
|
* @param interval
|
||||||
|
* @param name
|
||||||
|
* @returns {(function(*, *, *): void)|*}
|
||||||
|
*/
|
||||||
|
export function load(sdk, interval = 200, name = "") {
|
||||||
|
return function (target, n, descriptor) {
|
||||||
|
const origin = descriptor.value
|
||||||
|
let c = 0
|
||||||
|
const loop = (that, args) => {
|
||||||
|
if (!!sdk) {
|
||||||
|
origin.apply(that, args)
|
||||||
|
} else if (c < 10) {
|
||||||
|
setTimeout(() => ++c && loop(that, args), interval)
|
||||||
|
} else throw new Error("无法加载" + name)
|
||||||
|
}
|
||||||
|
descriptor.value = function () {
|
||||||
|
loop(this, arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 防抖装饰器
|
||||||
|
* @param delay 防抖时间
|
||||||
|
* @returns {(function(*, *, *): void)|*}
|
||||||
|
*/
|
||||||
|
export function debounce(delay) {
|
||||||
|
let timer = null;
|
||||||
|
return function (t, n, descriptor) {
|
||||||
|
const origin = descriptor.value
|
||||||
|
descriptor.value = function () {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
origin.apply(this, arguments)
|
||||||
|
}, delay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
37
ui/lib/js/directives.js
Normal file
37
ui/lib/js/directives.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
const map = {
|
||||||
|
throttle: {
|
||||||
|
bind: function (el, obj) {
|
||||||
|
let timerId = null
|
||||||
|
let flag = true
|
||||||
|
|
||||||
|
el.addEventListener('input', function () {
|
||||||
|
if (!flag) return
|
||||||
|
|
||||||
|
flag = false
|
||||||
|
timerId && clearTimeout(timerId)
|
||||||
|
timerId = setTimeout(function () {
|
||||||
|
flag = true
|
||||||
|
obj.value()
|
||||||
|
}, 800)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
permit: {
|
||||||
|
bind(el, binding) {
|
||||||
|
const code = binding.value
|
||||||
|
const permits = JSON.parse(localStorage.getItem('vuex') || null)?.user?.info?.buttons || []
|
||||||
|
if (!permits.find(e => e.id == code || e.permission == code)) {
|
||||||
|
el.parentNode.removeChild(el)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
install(Vue) {
|
||||||
|
for (const key in map) {
|
||||||
|
Vue.directive(key, map[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +1,15 @@
|
|||||||
//本地仓库外部组件
|
//本地仓库外部组件
|
||||||
|
|
||||||
// 存储组件列表
|
// 存储组件列表
|
||||||
|
import directives from "../lib/js/directives";
|
||||||
|
|
||||||
let components = [];
|
let components = [];
|
||||||
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
|
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
|
||||||
const install = function (Vue) {
|
const install = function (Vue) {
|
||||||
if (install.installed) return;
|
if (install.installed) return;
|
||||||
// 遍历注册全局组件
|
// 遍历注册全局组件
|
||||||
let contexts = require.context('.', true, /[\\\/]Ai([^\\\/]+)\.vue$/);
|
let contexts = require.context('.', true, /[\\\/]Ai([^\\\/]+)\.vue$/);
|
||||||
Vue.directive('throttle', {
|
Vue.use(directives)
|
||||||
bind: function (el, obj) {
|
|
||||||
let timerId = null
|
|
||||||
let flag = true
|
|
||||||
|
|
||||||
el.addEventListener('input', function () {
|
|
||||||
if (!flag) return
|
|
||||||
|
|
||||||
flag = false
|
|
||||||
timerId && clearTimeout(timerId)
|
|
||||||
timerId = setTimeout(function () {
|
|
||||||
flag = true
|
|
||||||
obj.value()
|
|
||||||
}, 800)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (contexts) {
|
if (contexts) {
|
||||||
contexts.keys().map((e) => {
|
contexts.keys().map((e) => {
|
||||||
components.push(contexts(e).default);
|
components.push(contexts(e).default);
|
||||||
|
|||||||
Reference in New Issue
Block a user