su-tabbar-item.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. "use strict";
  2. const sheep_helper_index = require("../../helper/index.js");
  3. const common_vendor = require("../../../common/vendor.js");
  4. require("../../helper/test.js");
  5. require("../../helper/digit.js");
  6. const _sfc_main = {
  7. name: "su-tabbar-item",
  8. props: {
  9. customStyle: {
  10. type: [Object, String],
  11. default: () => ({})
  12. },
  13. customClass: {
  14. type: String,
  15. default: ""
  16. },
  17. // 跳转的页面路径
  18. url: {
  19. type: String,
  20. default: ""
  21. },
  22. // 页面跳转的类型
  23. linkType: {
  24. type: String,
  25. default: "navigateTo"
  26. },
  27. // item标签的名称,作为与u-tabbar的value参数匹配的标识符
  28. name: {
  29. type: [String, Number, null],
  30. default: ""
  31. },
  32. // uView内置图标或者绝对路径的图片
  33. icon: {
  34. icon: String,
  35. default: ""
  36. },
  37. // 右上角的角标提示信息
  38. badge: {
  39. type: [String, Number, null],
  40. default: ""
  41. },
  42. // 是否显示圆点,将会覆盖badge参数
  43. dot: {
  44. type: Boolean,
  45. default: false
  46. },
  47. // 描述文本
  48. text: {
  49. type: String,
  50. default: ""
  51. },
  52. // 控制徽标的位置,对象或者字符串形式,可以设置top和right属性
  53. badgeStyle: {
  54. type: [Object, String],
  55. default: ""
  56. },
  57. isCenter: {
  58. type: Boolean,
  59. default: false
  60. },
  61. centerImage: {
  62. type: String,
  63. default: ""
  64. }
  65. },
  66. data() {
  67. return {
  68. isActive: false,
  69. // 是否处于激活状态
  70. addStyle: sheep_helper_index.addStyle,
  71. parentData: {
  72. value: null,
  73. activeColor: "",
  74. color: ""
  75. },
  76. parent: {}
  77. };
  78. },
  79. created() {
  80. this.init();
  81. },
  82. methods: {
  83. getParentData(parentName = "") {
  84. if (!this.parent)
  85. this.parent = {};
  86. this.parent = sheep_helper_index.$parent.call(this, parentName);
  87. if (this.parent.children) {
  88. this.parent.children.indexOf(this) === -1 && this.parent.children.push(this);
  89. }
  90. if (this.parent && this.parentData) {
  91. Object.keys(this.parentData).map((key) => {
  92. this.parentData[key] = this.parent[key];
  93. });
  94. }
  95. },
  96. init() {
  97. this.updateParentData();
  98. if (!this.parent) {
  99. console.log("u-tabbar-item必须搭配u-tabbar组件使用");
  100. }
  101. const index = this.parent.children.indexOf(this);
  102. this.isActive = (this.name.split("?")[0] || index) === this.parentData.value;
  103. },
  104. updateParentData() {
  105. this.getParentData("su-tabbar");
  106. },
  107. // 此方法将会被父组件u-tabbar调用
  108. updateFromParent() {
  109. this.init();
  110. },
  111. clickHandler() {
  112. this.$nextTick(() => {
  113. const index = this.parent.children.indexOf(this);
  114. const name = this.name || index;
  115. if (name !== this.parent.value) {
  116. this.parent.$emit("change", name);
  117. }
  118. this.$emit("click", name);
  119. });
  120. }
  121. }
  122. };
  123. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  124. return common_vendor.e({
  125. a: $props.isCenter
  126. }, $props.isCenter ? {
  127. b: $props.centerImage
  128. } : common_vendor.e({
  129. c: $props.icon
  130. }, $props.icon ? {
  131. d: $props.icon,
  132. e: $data.isActive ? $data.parentData.activeColor : $data.parentData.color
  133. } : common_vendor.e({
  134. f: $data.isActive
  135. }, $data.isActive ? {} : {}), {
  136. g: common_vendor.t($props.text),
  137. h: $data.isActive ? $data.parentData.activeColor : $data.parentData.color
  138. }), {
  139. i: common_vendor.s($data.addStyle($props.customStyle))
  140. });
  141. }
  142. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a62e13d6"], ["__file", "D:/zx/mall-front-app/sheep/ui/su-tabbar-item/su-tabbar-item.vue"]]);
  143. wx.createComponent(Component);