jiaqingjiayi-xiaochengxu/甲情_甲意/miniprogram/node_modules/antd-mini/less/Toast/index.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-12-01 11:56:54 +00:00
import { Component, triggerEventOnly, getValueFromProps, } from '../_util/simply';
import { ToastDefaultProps } from './props';
Component(ToastDefaultProps, {
closeMask: function () {
if (this.timer) {
clearTimeout(this.timer);
}
this.setData({ show: false });
this.timer = null;
triggerEventOnly(this, 'close');
},
handleShowToast: function () {
var _this = this;
this.setData({ show: true });
var duration = getValueFromProps(this, 'duration');
if (duration > 0) {
var timer = setTimeout(function () {
_this.closeMask();
}, duration);
this.timer = timer;
}
2024-11-10 07:01:22 +00:00
},
2024-12-01 11:56:54 +00:00
handleClickMask: function () {
var _a = getValueFromProps(this, [
'showMask',
'maskCloseable',
]), showMask = _a[0], maskCloseable = _a[1];
if (showMask && maskCloseable) {
this.closeMask();
}
},
}, {
show: false,
}, undefined, {
timer: null,
2024-11-10 07:01:22 +00:00
didUpdate: function (prev) {
2024-12-01 11:56:54 +00:00
var visible = getValueFromProps(this, 'visible');
if (!prev.visible && visible) {
2024-11-10 07:01:22 +00:00
this.handleShowToast();
}
2024-12-01 11:56:54 +00:00
else if (!visible && this.data.show) {
2024-11-10 07:01:22 +00:00
this.closeMask();
}
},
didMount: function () {
2024-12-01 11:56:54 +00:00
var visible = getValueFromProps(this, 'visible');
if (visible) {
2024-11-10 07:01:22 +00:00
this.handleShowToast();
}
},
2024-12-01 11:56:54 +00:00
});