antd-mini
Version:
antd-mini 是支付宝小程序 UI 组件库,遵循 Ant Design 规范。
78 lines (77 loc) • 2.77 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import { isOldSDKVersion } from '../_util/platform';
import { Component, getValueFromProps, triggerEventOnly, } from '../_util/simply';
import { PopupDefaultProps } from './props';
var isOldVersion = isOldSDKVersion();
Component({
props: PopupDefaultProps,
data: {
closing: false,
isOldVersion: isOldVersion,
},
methods: {
onClickCloseIcon: function () {
var closing = this.data.closing;
if (closing) {
return;
}
triggerEventOnly(this, 'close');
},
onClickBack: function () {
triggerEventOnly(this, 'clickBack');
},
onTapMask: function () {
var closing = this.data.closing;
if (closing) {
return;
}
triggerEventOnly(this, 'close');
},
onAnimationEnd: function () {
var closing = this.data.closing;
if (closing) {
this.setData({ closing: false });
}
var _a = getValueFromProps(this, [
'visible',
'duration',
'animation',
]), visible = _a[0], duration = _a[1], animation = _a[2];
var enableAnimation = animation && duration > 0;
if (enableAnimation) {
triggerEventOnly(this, visible ? 'afterShow' : 'afterClose');
}
},
},
deriveDataFromProps: function (nextProps) {
return __awaiter(this, void 0, void 0, function () {
var _a, visible, duration, animation, enableAnimation;
return __generator(this, function (_b) {
_a = getValueFromProps(this, [
'visible',
'duration',
'animation',
]), visible = _a[0], duration = _a[1], animation = _a[2];
enableAnimation = animation && duration > 0;
if (Boolean(nextProps.visible) !== Boolean(visible) &&
enableAnimation &&
!nextProps.visible &&
!this.data.closing) {
this.setData({ closing: true });
}
return [2 /*return*/];
});
});
},
didUpdate: function (prevProps) {
var _a = getValueFromProps(this, [
'visible',
'duration',
'animation',
]), visible = _a[0], duration = _a[1], animation = _a[2];
var enableAnimation = animation && duration > 0;
if (prevProps.visible !== visible && !enableAnimation) {
triggerEventOnly(this, visible ? 'afterShow' : 'afterClose');
}
},
});