mixin.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var common_vendor = require("../../../../common/vendor.js");
  3. var uni_modules_uviewPlus_libs_function_index = require("../function/index.js");
  4. var uni_modules_uviewPlus_libs_function_test = require("../function/test.js");
  5. var uni_modules_uviewPlus_libs_util_route = require("../util/route.js");
  6. var mixin = {
  7. props: {
  8. customStyle: {
  9. type: [Object, String],
  10. default: () => ({})
  11. },
  12. customClass: {
  13. type: String,
  14. default: ""
  15. },
  16. url: {
  17. type: String,
  18. default: ""
  19. },
  20. linkType: {
  21. type: String,
  22. default: "navigateTo"
  23. }
  24. },
  25. data() {
  26. return {};
  27. },
  28. onLoad() {
  29. this.$u.getRect = this.$uGetRect;
  30. },
  31. created() {
  32. this.$u.getRect = this.$uGetRect;
  33. },
  34. computed: {
  35. $u() {
  36. return uni_modules_uviewPlus_libs_function_index.deepMerge(common_vendor.index.$u, {
  37. props: void 0,
  38. http: void 0,
  39. mixin: void 0
  40. });
  41. },
  42. bem() {
  43. return function(name, fixed, change) {
  44. const prefix = `u-${name}--`;
  45. const classes = {};
  46. if (fixed) {
  47. fixed.map((item) => {
  48. classes[prefix + this[item]] = true;
  49. });
  50. }
  51. if (change) {
  52. change.map((item) => {
  53. this[item] ? classes[prefix + item] = this[item] : delete classes[prefix + item];
  54. });
  55. }
  56. return Object.keys(classes);
  57. };
  58. }
  59. },
  60. methods: {
  61. openPage(urlKey = "url") {
  62. const url = this[urlKey];
  63. if (url) {
  64. uni_modules_uviewPlus_libs_util_route.route({ type: this.linkType, url });
  65. }
  66. },
  67. $uGetRect(selector, all) {
  68. return new Promise((resolve) => {
  69. common_vendor.index.createSelectorQuery().in(this)[all ? "selectAll" : "select"](selector).boundingClientRect((rect) => {
  70. if (all && Array.isArray(rect) && rect.length) {
  71. resolve(rect);
  72. }
  73. if (!all && rect) {
  74. resolve(rect);
  75. }
  76. }).exec();
  77. });
  78. },
  79. getParentData(parentName = "") {
  80. if (!this.parent)
  81. this.parent = {};
  82. this.parent = uni_modules_uviewPlus_libs_function_index.$parent.call(this, parentName);
  83. if (this.parent.children) {
  84. this.parent.children.indexOf(this) === -1 && this.parent.children.push(this);
  85. }
  86. if (this.parent && this.parentData) {
  87. Object.keys(this.parentData).map((key) => {
  88. this.parentData[key] = this.parent[key];
  89. });
  90. }
  91. },
  92. preventEvent(e) {
  93. e && typeof e.stopPropagation === "function" && e.stopPropagation();
  94. },
  95. noop(e) {
  96. this.preventEvent(e);
  97. }
  98. },
  99. onReachBottom() {
  100. common_vendor.index.$emit("uOnReachBottom");
  101. },
  102. beforeUnmount() {
  103. if (this.parent && uni_modules_uviewPlus_libs_function_test.test.array(this.parent.children)) {
  104. const childrenList = this.parent.children;
  105. childrenList.map((child, index) => {
  106. if (child === this) {
  107. childrenList.splice(index, 1);
  108. }
  109. });
  110. }
  111. }
  112. };
  113. exports.mixin = mixin;