自定义命令统一管理,装饰器统一管理
This commit is contained in:
		| @@ -59,3 +59,27 @@ export function throttle(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) | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										28
									
								
								ui/lib/js/directives.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								ui/lib/js/directives.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| 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) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| export default { | ||||
|   install(Vue) { | ||||
|     for (const key in map) { | ||||
|       Vue.directive(key, map[key]) | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user