储能智慧云小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

action-sheet.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { chunk } from '../common/utils';
  8. import { SuperComponent, wxComponent } from '../common/src/index';
  9. import config from '../common/config';
  10. import { ActionSheetTheme, show } from './show';
  11. import props from './props';
  12. import useCustomNavbar from '../mixins/using-custom-navbar';
  13. const { prefix } = config;
  14. const name = `${prefix}-action-sheet`;
  15. let ActionSheet = class ActionSheet extends SuperComponent {
  16. constructor() {
  17. super(...arguments);
  18. this.behaviors = [useCustomNavbar];
  19. this.externalClasses = [`${prefix}-class`, `${prefix}-class-content`, `${prefix}-class-cancel`];
  20. this.properties = Object.assign({}, props);
  21. this.data = {
  22. prefix,
  23. classPrefix: name,
  24. gridThemeItems: [],
  25. currentSwiperIndex: 0,
  26. defaultPopUpProps: {},
  27. defaultPopUpzIndex: 11500,
  28. };
  29. this.controlledProps = [
  30. {
  31. key: 'visible',
  32. event: 'visible-change',
  33. },
  34. ];
  35. this.methods = {
  36. onSwiperChange(e) {
  37. const { detail: { current }, } = e;
  38. this.setData({
  39. currentSwiperIndex: current,
  40. });
  41. },
  42. splitGridThemeActions() {
  43. if (this.data.theme !== ActionSheetTheme.Grid)
  44. return;
  45. this.setData({
  46. gridThemeItems: chunk(this.data.items, this.data.count),
  47. });
  48. },
  49. show(options) {
  50. this.setData(Object.assign(Object.assign(Object.assign({}, this.initialData), options), { visible: true }));
  51. this.splitGridThemeActions();
  52. this.autoClose = true;
  53. this._trigger('visible-change', { visible: true });
  54. },
  55. memoInitialData() {
  56. this.initialData = Object.assign(Object.assign({}, this.properties), this.data);
  57. },
  58. close() {
  59. this.triggerEvent('close', { trigger: 'command' });
  60. this._trigger('visible-change', { visible: false });
  61. },
  62. onPopupVisibleChange({ detail }) {
  63. if (!detail.visible) {
  64. this.triggerEvent('close', { trigger: 'overlay' });
  65. this._trigger('visible-change', { visible: false });
  66. }
  67. if (this.autoClose) {
  68. this.setData({ visible: false });
  69. this.autoClose = false;
  70. }
  71. },
  72. onSelect(event) {
  73. const { currentSwiperIndex, items, gridThemeItems, count, theme } = this.data;
  74. const { index } = event.currentTarget.dataset;
  75. const isSwiperMode = theme === ActionSheetTheme.Grid;
  76. const item = isSwiperMode ? gridThemeItems[currentSwiperIndex][index] : items[index];
  77. const realIndex = isSwiperMode ? index + currentSwiperIndex * count : index;
  78. if (item) {
  79. this.triggerEvent('selected', { selected: item, index: realIndex });
  80. if (!item.disabled) {
  81. this.triggerEvent('close', { trigger: 'select' });
  82. this._trigger('visible-change', { visible: false });
  83. }
  84. }
  85. },
  86. onCancel() {
  87. this.triggerEvent('cancel');
  88. if (this.autoClose) {
  89. this.setData({ visible: false });
  90. this.autoClose = false;
  91. }
  92. },
  93. };
  94. }
  95. ready() {
  96. this.memoInitialData();
  97. this.splitGridThemeActions();
  98. }
  99. };
  100. ActionSheet.show = show;
  101. ActionSheet = __decorate([
  102. wxComponent()
  103. ], ActionSheet);
  104. export default ActionSheet;