index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "use strict";
  2. var _link = require("../mixins/link");
  3. var _component = require("../common/component");
  4. var _utils = require("../common/utils");
  5. var _my = require("../../__antmove/api/index.js")(my);
  6. var wx = _my;
  7. (0, _component.VantComponent)({
  8. relation: {
  9. name: "grid",
  10. type: "ancestor",
  11. current: "grid-item"
  12. },
  13. classes: ["content-class", "icon-class", "text-class"],
  14. mixins: [_link.link],
  15. props: {
  16. icon: String,
  17. iconColor: String,
  18. dot: Boolean,
  19. info: null,
  20. badge: null,
  21. text: String,
  22. useSlot: Boolean
  23. },
  24. data: {
  25. viewStyle: ""
  26. },
  27. mounted: function mounted() {
  28. var _this = this;
  29. wx.nextTick(function () {
  30. _this.updateStyle();
  31. });
  32. },
  33. methods: {
  34. updateStyle: function updateStyle() {
  35. if (!this.parent) {
  36. return;
  37. }
  38. var _this$parent = this.parent,
  39. data = _this$parent.data,
  40. children = _this$parent.children;
  41. var columnNum = data.columnNum,
  42. border = data.border,
  43. square = data.square,
  44. gutter = data.gutter,
  45. clickable = data.clickable,
  46. center = data.center,
  47. direction = data.direction,
  48. iconSize = data.iconSize;
  49. var width = "".concat(100 / columnNum, "%");
  50. var styleWrapper = [];
  51. styleWrapper.push("width: ".concat(width));
  52. if (square) {
  53. styleWrapper.push("padding-top: ".concat(width));
  54. }
  55. if (gutter) {
  56. var gutterValue = (0, _utils.addUnit)(gutter);
  57. styleWrapper.push("padding-right: ".concat(gutterValue));
  58. var index = children.indexOf(this);
  59. if (index >= columnNum && !square) {
  60. styleWrapper.push("margin-top: ".concat(gutterValue));
  61. }
  62. }
  63. var contentStyle = "";
  64. if (square && gutter) {
  65. var _gutterValue = (0, _utils.addUnit)(gutter);
  66. contentStyle = "\n right: ".concat(_gutterValue, ";\n bottom: ").concat(_gutterValue, ";\n height: auto;\n ");
  67. }
  68. this.setData({
  69. viewStyle: styleWrapper.join("; "),
  70. contentStyle: contentStyle,
  71. center: center,
  72. border: border,
  73. square: square,
  74. gutter: gutter,
  75. clickable: clickable,
  76. direction: direction,
  77. iconSize: iconSize
  78. });
  79. },
  80. onClick: function onClick() {
  81. this.$emit("click");
  82. this.jumpLink();
  83. }
  84. }
  85. });