123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- const _f = function () {};
- module.exports = {
- showZanDialog(options = {}) {
- const {
-
-
- buttons = [],
-
- title = '',
-
- content = ' ',
-
- buttonsShowVertical = false,
-
- showConfirm = true,
-
- confirmText = '确定',
-
- confirmColor = '#3CC51F',
-
- showCancel = false,
-
- cancelText = '取消',
-
- cancelColor = '#333'
- } = options;
-
-
- let showCustomBtns = false;
- if (buttons.length === 0) {
- if (showConfirm) {
- buttons.push({
- type: 'confirm',
- text: confirmText,
- color: confirmColor
- });
- }
- if (showCancel) {
- const cancelButton = {
- type: 'cancel',
- text: cancelText,
- color: cancelColor
- };
- if (buttonsShowVertical) {
- buttons.push(cancelButton);
- } else {
- buttons.unshift(cancelButton);
- }
- }
- } else {
- showCustomBtns = true;
- }
- return new Promise((resolve, reject) => {
- this.setData({
- zanDialog: {
- show: true,
- showCustomBtns,
- buttons,
- title,
- content,
- buttonsShowVertical,
- showConfirm,
- confirmText,
- confirmColor,
- showCancel,
- cancelText,
- cancelColor,
-
- resolve,
- reject
- }
- });
- });
- },
- _handleZanDialogButtonClick(e) {
- const { currentTarget = {} } = e;
- const { dataset = {} } = currentTarget;
-
- const zanDialogData = this.data.zanDialog || {};
- const { resolve = _f, reject = _f } = zanDialogData;
-
- this.setData({
- zanDialog: { show: false }
- });
-
- if (zanDialogData.showCustomBtns) {
- resolve({
- type: dataset.type
- });
- return;
- }
-
- if (dataset.type === 'confirm') {
- resolve({
- type: 'confirm'
- });
- } else {
- reject({
- type: 'cancel'
- });
- }
- }
- };
|