fix[Waves-Directive]: fixed v-waves does not support update (#1705)
This commit is contained in:
		| @@ -1,42 +1,72 @@ | |||||||
| import './waves.css' | import './waves.css' | ||||||
|  |  | ||||||
| export default { | const context = '@@wavesContext' | ||||||
|   bind(el, binding) { |  | ||||||
|     el.addEventListener('click', e => { | function handleClick(el, binding) { | ||||||
|       const customOpts = Object.assign({}, binding.value) |   function handle(e) { | ||||||
|       const opts = Object.assign({ |     const customOpts = Object.assign({}, binding.value) | ||||||
|  |     const opts = Object.assign({ | ||||||
|         ele: el, // 波纹作用元素 |         ele: el, // 波纹作用元素 | ||||||
|         type: 'hit', // hit 点击位置扩散 center中心点扩展 |         type: 'hit', // hit 点击位置扩散 center中心点扩展 | ||||||
|         color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色 |         color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色 | ||||||
|       }, customOpts) |       }, | ||||||
|       const target = opts.ele |       customOpts | ||||||
|       if (target) { |     ) | ||||||
|         target.style.position = 'relative' |     const target = opts.ele | ||||||
|         target.style.overflow = 'hidden' |     if (target) { | ||||||
|         const rect = target.getBoundingClientRect() |       target.style.position = 'relative' | ||||||
|         let ripple = target.querySelector('.waves-ripple') |       target.style.overflow = 'hidden' | ||||||
|         if (!ripple) { |       const rect = target.getBoundingClientRect() | ||||||
|           ripple = document.createElement('span') |       let ripple = target.querySelector('.waves-ripple') | ||||||
|           ripple.className = 'waves-ripple' |       if (!ripple) { | ||||||
|           ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px' |         ripple = document.createElement('span') | ||||||
|           target.appendChild(ripple) |         ripple.className = 'waves-ripple' | ||||||
|         } else { |         ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px' | ||||||
|           ripple.className = 'waves-ripple' |         target.appendChild(ripple) | ||||||
|         } |       } else { | ||||||
|         switch (opts.type) { |         ripple.className = 'waves-ripple' | ||||||
|           case 'center': |  | ||||||
|             ripple.style.top = (rect.height / 2 - ripple.offsetHeight / 2) + 'px' |  | ||||||
|             ripple.style.left = (rect.width / 2 - ripple.offsetWidth / 2) + 'px' |  | ||||||
|             break |  | ||||||
|           default: |  | ||||||
|             ripple.style.top = (e.pageY - rect.top - ripple.offsetHeight / 2 - document.documentElement.scrollTop || document.body.scrollTop) + 'px' |  | ||||||
|             ripple.style.left = (e.pageX - rect.left - ripple.offsetWidth / 2 - document.documentElement.scrollLeft || document.body.scrollLeft) + 'px' |  | ||||||
|         } |  | ||||||
|         ripple.style.backgroundColor = opts.color |  | ||||||
|         ripple.className = 'waves-ripple z-active' |  | ||||||
|         return false |  | ||||||
|       } |       } | ||||||
|     }, false) |       switch (opts.type) { | ||||||
|  |         case 'center': | ||||||
|  |           ripple.style.top = rect.height / 2 - ripple.offsetHeight / 2 + 'px' | ||||||
|  |           ripple.style.left = rect.width / 2 - ripple.offsetWidth / 2 + 'px' | ||||||
|  |           break | ||||||
|  |         default: | ||||||
|  |           ripple.style.top = | ||||||
|  |             (e.pageY - rect.top - ripple.offsetHeight / 2 - document.documentElement.scrollTop || | ||||||
|  |               document.body.scrollTop) + 'px' | ||||||
|  |           ripple.style.left = | ||||||
|  |             (e.pageX - rect.left - ripple.offsetWidth / 2 - document.documentElement.scrollLeft || | ||||||
|  |               document.body.scrollLeft) + 'px' | ||||||
|  |       } | ||||||
|  |       ripple.style.backgroundColor = opts.color | ||||||
|  |       ripple.className = 'waves-ripple z-active' | ||||||
|  |       return false | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   if (!el[context]) { | ||||||
|  |     el[context] = { | ||||||
|  |       removeHandle: handle | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     el[context].removeHandle = handle | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   return handle | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export default { | ||||||
|  |   bind(el, binding) { | ||||||
|  |     el.addEventListener('click', handleClick(el, binding), false) | ||||||
|  |   }, | ||||||
|  |   update(el, binding) { | ||||||
|  |     el.removeEventListener('click', el[context].removeHandle, false) | ||||||
|  |     el.addEventListener('click', handleClick(el, binding), false) | ||||||
|  |   }, | ||||||
|  |   unbind(el) { | ||||||
|  |     el.removeEventListener('click', el[context].removeHandle, false) | ||||||
|  |     el[context] = null | ||||||
|  |     delete el[context] | ||||||
|  |   } | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user