index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _utils = require("../utils");
  7. var _popup = require("../mixins/popup");
  8. var _popup2 = _interopRequireDefault(require("../popup"));
  9. // Utils
  10. // Mixins
  11. // Components
  12. var PRESET_ICONS = ['qq', 'link', 'weibo', 'wechat', 'poster', 'qrcode', 'weapp-qrcode', 'wechat-moments'];
  13. var _createNamespace = (0, _utils.createNamespace)('share-sheet'),
  14. createComponent = _createNamespace[0],
  15. bem = _createNamespace[1],
  16. t = _createNamespace[2];
  17. var _default2 = createComponent({
  18. props: (0, _extends2.default)({}, _popup.popupMixinProps, {
  19. title: String,
  20. duration: String,
  21. cancelText: String,
  22. description: String,
  23. getContainer: [String, Function],
  24. options: {
  25. type: Array,
  26. default: function _default() {
  27. return [];
  28. }
  29. },
  30. overlay: {
  31. type: Boolean,
  32. default: true
  33. },
  34. closeOnPopstate: {
  35. type: Boolean,
  36. default: true
  37. },
  38. safeAreaInsetBottom: {
  39. type: Boolean,
  40. default: true
  41. },
  42. closeOnClickOverlay: {
  43. type: Boolean,
  44. default: true
  45. }
  46. }),
  47. methods: {
  48. onCancel: function onCancel() {
  49. this.toggle(false);
  50. this.$emit('cancel');
  51. },
  52. onSelect: function onSelect(option, index) {
  53. this.$emit('select', option, index);
  54. },
  55. toggle: function toggle(val) {
  56. this.$emit('input', val);
  57. },
  58. getIconURL: function getIconURL(icon) {
  59. if (PRESET_ICONS.indexOf(icon) !== -1) {
  60. return "https://img01.yzcdn.cn/vant/share-sheet-" + icon + ".png";
  61. }
  62. return icon;
  63. },
  64. genHeader: function genHeader() {
  65. var h = this.$createElement;
  66. var title = this.slots('title') || this.title;
  67. var description = this.slots('description') || this.description;
  68. if (!title && !description) {
  69. return;
  70. }
  71. return h("div", {
  72. "class": bem('header')
  73. }, [title && h("h2", {
  74. "class": bem('title')
  75. }, [title]), description && h("span", {
  76. "class": bem('description')
  77. }, [description])]);
  78. },
  79. genOptions: function genOptions(options, showBorder) {
  80. var _this = this;
  81. var h = this.$createElement;
  82. return h("div", {
  83. "class": bem('options', {
  84. border: showBorder
  85. })
  86. }, [options.map(function (option, index) {
  87. return h("div", {
  88. "attrs": {
  89. "role": "button",
  90. "tabindex": "0"
  91. },
  92. "class": [bem('option'), option.className],
  93. "on": {
  94. "click": function click() {
  95. _this.onSelect(option, index);
  96. }
  97. }
  98. }, [h("img", {
  99. "attrs": {
  100. "src": _this.getIconURL(option.icon)
  101. },
  102. "class": bem('icon')
  103. }), option.name && h("span", {
  104. "class": bem('name')
  105. }, [option.name]), option.description && h("span", {
  106. "class": bem('option-description')
  107. }, [option.description])]);
  108. })]);
  109. },
  110. genRows: function genRows() {
  111. var _this2 = this;
  112. var options = this.options;
  113. if (Array.isArray(options[0])) {
  114. return options.map(function (item, index) {
  115. return _this2.genOptions(item, index !== 0);
  116. });
  117. }
  118. return this.genOptions(options);
  119. },
  120. genCancelText: function genCancelText() {
  121. var _this$cancelText;
  122. var h = this.$createElement;
  123. var cancelText = (_this$cancelText = this.cancelText) != null ? _this$cancelText : t('cancel');
  124. if (cancelText) {
  125. return h("button", {
  126. "attrs": {
  127. "type": "button"
  128. },
  129. "class": bem('cancel'),
  130. "on": {
  131. "click": this.onCancel
  132. }
  133. }, [cancelText]);
  134. }
  135. },
  136. onClickOverlay: function onClickOverlay() {
  137. this.$emit('click-overlay');
  138. }
  139. },
  140. render: function render() {
  141. var h = arguments[0];
  142. return h(_popup2.default, {
  143. "attrs": {
  144. "round": true,
  145. "value": this.value,
  146. "position": "bottom",
  147. "overlay": this.overlay,
  148. "duration": this.duration,
  149. "lazyRender": this.lazyRender,
  150. "lockScroll": this.lockScroll,
  151. "getContainer": this.getContainer,
  152. "closeOnPopstate": this.closeOnPopstate,
  153. "closeOnClickOverlay": this.closeOnClickOverlay,
  154. "safeAreaInsetBottom": this.safeAreaInsetBottom
  155. },
  156. "class": bem(),
  157. "on": {
  158. "input": this.toggle,
  159. "click-overlay": this.onClickOverlay
  160. }
  161. }, [this.genHeader(), this.genRows(), this.genCancelText()]);
  162. }
  163. });
  164. exports.default = _default2;