管灌系统农户端微信小程序(嘉峪关应用)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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 { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
import { isObject, toCamel } from '../common/utils';
const { prefix } = config;
const name = `${prefix}-dialog`;
let Dialog = class Dialog extends SuperComponent {
    constructor() {
        super(...arguments);
        this.options = {
            multipleSlots: true,
            addGlobalClass: true,
        };
        this.externalClasses = [
            `${prefix}-class`,
            `${prefix}-class-content`,
            `${prefix}-class-confirm`,
            `${prefix}-class-cancel`,
            `${prefix}-class-action`,
        ];
        this.properties = props;
        this.data = {
            prefix,
            classPrefix: name,
            buttonVariant: 'text',
        };
        this.observers = {
            'confirmBtn, cancelBtn'(confirm, cancel) {
                const { prefix, classPrefix, buttonLayout } = this.data;
                const rect = { buttonVariant: 'text' };
                const useBaseVariant = [confirm, cancel].some((item) => isObject(item) && item.variant && item.variant !== 'text');
                const buttonMap = { confirm, cancel };
                const cls = [`${classPrefix}__button`];
                const externalCls = [];
                if (useBaseVariant) {
                    rect.buttonVariant = 'base';
                    cls.push(`${classPrefix}__button--${buttonLayout}`);
                }
                else {
                    cls.push(`${classPrefix}__button--text`);
                    externalCls.push(`${classPrefix}-button`);
                }
                Object.keys(buttonMap).forEach((key) => {
                    const btn = buttonMap[key];
                    const base = {
                        block: true,
                        class: [...cls, `${classPrefix}__button--${key}`],
                        externalClass: [...externalCls, `${prefix}-class-${key}`],
                        variant: rect.buttonVariant,
                    };
                    if (key === 'cancel' && rect.buttonVariant === 'base') {
                        base.theme = 'light';
                    }
                    if (typeof btn === 'string') {
                        rect[`_${key}`] = Object.assign(Object.assign({}, base), { content: btn });
                    }
                    else if (btn && typeof btn === 'object') {
                        rect[`_${key}`] = Object.assign(Object.assign({}, base), btn);
                    }
                    else {
                        rect[`_${key}`] = null;
                    }
                });
                this.setData(Object.assign({}, rect));
            },
        };
        this.methods = {
            onTplButtonTap(e) {
                var _a, _b, _c;
                const evtType = e.type;
                const { type, extra } = e.target.dataset;
                const button = this.data[`_${type}`];
                const cbName = `bind${evtType}`;
                if (type === 'action') {
                    this.onActionTap(extra);
                    return;
                }
                if (typeof button[cbName] === 'function') {
                    const closeFlag = button[cbName](e);
                    if (closeFlag) {
                        this.close();
                    }
                }
                const hasOpenType = 'openType' in button;
                if (!hasOpenType && ['confirm', 'cancel'].includes(type)) {
                    (_a = this[toCamel(`on-${type}`)]) === null || _a === void 0 ? void 0 : _a.call(this, type);
                }
                if (evtType !== 'tap') {
                    const success = ((_c = (_b = e.detail) === null || _b === void 0 ? void 0 : _b.errMsg) === null || _c === void 0 ? void 0 : _c.indexOf('ok')) > -1;
                    this.triggerEvent(success ? 'open-type-event' : 'open-type-error-event', e.detail);
                }
            },
            onConfirm() {
                this.triggerEvent('confirm');
                if (this._onConfirm) {
                    this._onConfirm();
                    this.close();
                }
            },
            onCancel() {
                this.triggerEvent('close', { trigger: 'cancel' });
                this.triggerEvent('cancel');
                if (this._onCancel) {
                    this._onCancel();
                    this.close();
                }
            },
            onClose() {
                this.triggerEvent('close', { trigger: 'close-btn' });
                this.close();
            },
            close() {
                this.setData({ visible: false });
            },
            overlayClick() {
                if (this.properties.closeOnOverlayClick) {
                    this.triggerEvent('close', { trigger: 'overlay' });
                }
                this.triggerEvent('overlay-click');
            },
            onActionTap(index) {
                this.triggerEvent('action', { index });
                if (this._onAction) {
                    this._onAction({ index });
                    this.close();
                }
            },
            openValueCBHandle(e) {
                this.triggerEvent('open-type-event', e.detail);
            },
            openValueErrCBHandle(e) {
                this.triggerEvent('open-type-error-event', e.detail);
            },
        };
    }
};
Dialog = __decorate([
    wxComponent()
], Dialog);
export default Dialog;