components.js 3.2 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
export function initComponents({ uni, Vue, weex, plus, BroadcastChannel, UniViewJSBridge, VueShared, UniShared }) {
fxy060608's avatar
fxy060608 已提交
2
  var components = function(vue, shared) {
fxy060608's avatar
fxy060608 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    "use strict";
    const OPEN_TYPES = [
      "navigate",
      "redirect",
      "switchTab",
      "reLaunch",
      "navigateBack"
    ];
    const navigatorProps = {
      hoverClass: {
        type: String,
        default: "navigator-hover"
      },
      url: {
        type: String,
        default: ""
      },
      openType: {
        type: String,
        default: "navigate",
        validator(value) {
          return Boolean(~OPEN_TYPES.indexOf(value));
        }
      },
      delta: {
        type: Number,
        default: 1
      },
      hoverStartTime: {
        type: [Number, String],
        default: 50
      },
      hoverStayTime: {
        type: [Number, String],
        default: 600
      },
      exists: {
        type: String,
        default: ""
      },
      hoverStopPropagation: {
        type: Boolean,
        default: false
      }
    };
    function createNavigatorOnClick(props) {
      return () => {
        if (props.openType !== "navigateBack" && !props.url) {
          console.error("<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab");
          return;
        }
        switch (props.openType) {
          case "navigate":
            uni.navigateTo({
              url: props.url
            });
            break;
          case "redirect":
            uni.redirectTo({
              url: props.url,
              exists: props.exists
            });
            break;
          case "switchTab":
            uni.switchTab({
              url: props.url
            });
            break;
          case "reLaunch":
            uni.reLaunch({
              url: props.url
            });
            break;
          case "navigateBack":
            uni.navigateBack({
              delta: props.delta
            });
            break;
        }
      };
    }
fxy060608's avatar
fxy060608 已提交
84 85 86
    function useHoverClass(props) {
      if (props.hoverClass && props.hoverClass !== "none") {
        const hoverAttrs = { hoverClass: props.hoverClass };
fxy060608's avatar
fxy060608 已提交
87
        if (shared.hasOwn(props, "hoverStartTime")) {
fxy060608's avatar
fxy060608 已提交
88 89
          hoverAttrs.hoverStartTime = props.hoverStartTime;
        }
fxy060608's avatar
fxy060608 已提交
90
        if (shared.hasOwn(props, "hoverStayTime")) {
fxy060608's avatar
fxy060608 已提交
91 92
          hoverAttrs.hoverStayTime = props.hoverStayTime;
        }
fxy060608's avatar
fxy060608 已提交
93
        if (shared.hasOwn(props, "hoverStopPropagation")) {
fxy060608's avatar
fxy060608 已提交
94 95 96
          hoverAttrs.hoverStopPropagation = props.hoverStopPropagation;
        }
        return hoverAttrs;
fxy060608's avatar
fxy060608 已提交
97
      }
fxy060608's avatar
fxy060608 已提交
98
      return {};
fxy060608's avatar
fxy060608 已提交
99
    }
fxy060608's avatar
fxy060608 已提交
100 101 102 103 104 105
    const navigatorStyles = [{
      "navigator-hover": {
        backgroundColor: "rgba(0,0,0,0.1)",
        opacity: 0.7
      }
    }];
fxy060608's avatar
fxy060608 已提交
106 107 108
    var Navigator = vue.defineComponent({
      name: "Navigator",
      props: navigatorProps,
fxy060608's avatar
fxy060608 已提交
109
      styles: navigatorStyles,
fxy060608's avatar
fxy060608 已提交
110 111 112 113
      setup(props, {
        slots
      }) {
        const onClick = createNavigatorOnClick(props);
fxy060608's avatar
fxy060608 已提交
114
        return () => {
fxy060608's avatar
fxy060608 已提交
115
          return vue.createVNode("view", vue.mergeProps(useHoverClass(props), {
fxy060608's avatar
fxy060608 已提交
116 117 118
            "onClick": onClick
          }), [slots.default && slots.default()]);
        };
fxy060608's avatar
fxy060608 已提交
119 120
      }
    });
fxy060608's avatar
fxy060608 已提交
121
    var components2 = {
fxy060608's avatar
fxy060608 已提交
122 123
      Navigator
    };
fxy060608's avatar
fxy060608 已提交
124
    return components2;
fxy060608's avatar
fxy060608 已提交
125
  }(Vue, VueShared);
fxy060608's avatar
fxy060608 已提交
126 127
  return components;
}