管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2024-02-26 3f7ec892d68f71e996489d14d9918dc332281b1e
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
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import props from './props';
import { getInstance } from '../common/utils';
const defaultOptions = {
    actions: [],
    buttonLayout: props.buttonLayout.value,
    cancelBtn: props.cancelBtn.value,
    closeOnOverlayClick: props.closeOnOverlayClick.value,
    confirmBtn: props.confirmBtn.value,
    content: '',
    preventScrollThrough: props.preventScrollThrough.value,
    showOverlay: props.showOverlay.value,
    title: '',
    visible: props.visible.value,
};
export default {
    alert(options) {
        const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog' } = _a, otherOptions = __rest(_a, ["context", "selector"]);
        const instance = getInstance(context, selector);
        if (!instance)
            return Promise.reject();
        return new Promise((resolve) => {
            instance.setData(Object.assign(Object.assign({ cancelBtn: '' }, otherOptions), { visible: true }));
            instance._onConfirm = resolve;
        });
    },
    confirm(options) {
        const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog' } = _a, otherOptions = __rest(_a, ["context", "selector"]);
        const instance = getInstance(context, selector);
        if (!instance)
            return Promise.reject();
        return new Promise((resolve, reject) => {
            instance.setData(Object.assign(Object.assign({}, otherOptions), { visible: true }));
            instance._onConfirm = resolve;
            instance._onCancel = reject;
        });
    },
    close(options) {
        const { context, selector = '#t-dialog' } = Object.assign({}, options);
        const instance = getInstance(context, selector);
        if (instance) {
            instance.close();
            return Promise.resolve();
        }
        return Promise.reject();
    },
    action(options) {
        const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog', actions } = _a, otherOptions = __rest(_a, ["context", "selector", "actions"]);
        const instance = getInstance(context, selector);
        if (!instance)
            return Promise.reject();
        const { buttonLayout = 'vertical' } = options;
        const maxLengthSuggestion = buttonLayout === 'vertical' ? 7 : 3;
        if (!actions || (typeof actions === 'object' && (actions.length === 0 || actions.length > maxLengthSuggestion))) {
            console.warn(`action 数量建议控制在1至${maxLengthSuggestion}个`);
        }
        return new Promise((resolve) => {
            instance.setData(Object.assign(Object.assign({ actions }, otherOptions), { buttonLayout, visible: true }));
            instance._onAction = resolve;
        });
    },
};