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