足力健前端,vue版本

ui.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Vue from 'vue'
  2. // 使用白名单过滤(前期有一批自定义组件使用了 uni-)
  3. import tags from 'uni-helpers/tags'
  4. import 'uni-core/view/index.css'
  5. import uni from './ui-api.js'
  6. import {
  7. processEvent
  8. } from 'uni-core/view/plugins/events'
  9. const oldIsReservedTag = Vue.config.isReservedTag
  10. global.uni = uni
  11. Vue.config.isReservedTag = function (tag) {
  12. return tags.indexOf(tag) !== -1 || oldIsReservedTag(tag)
  13. }
  14. Vue.config.ignoredElements = tags
  15. const oldGetTagNamespace = Vue.config.getTagNamespace
  16. const conflictTags = ['switch', 'image', 'text', 'view']
  17. Vue.config.getTagNamespace = function (tag) {
  18. if (~conflictTags.indexOf(tag)) { // svg 部分标签名称与 uni 标签冲突
  19. return false
  20. }
  21. return oldGetTagNamespace(tag) || false
  22. }
  23. const findUniTarget = function ($event, $el) {
  24. let target = $event.target
  25. for (; target && target !== $el; target = target.parentNode) {
  26. if (target.tagName && target.tagName.indexOf('UNI-') === 0) {
  27. break
  28. }
  29. }
  30. return target
  31. }
  32. Vue.prototype.$handleEvent = function ($event) {
  33. if ($event instanceof Event) { // 未处理的 event 对象 需要对 target 校正及包装
  34. // 查找 uniTarget
  35. const target = findUniTarget($event, this.$el)
  36. $event = processEvent.call(this, $event.type, $event, {}, target || $event.target, $event.currentTarget)
  37. }
  38. return $event
  39. }
  40. require('uni-components')