tdesign-mobile-vue
Version:
tdesign-mobile-vue
159 lines (155 loc) • 5.09 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import { ref, computed, watch, setBlockTracking, h, nextTick } from 'vue';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import { renderTNode } from '../shared/render.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
function useSureConfirm(instance, initData) {
var sureRightRef = ref();
var sureLeftRef = ref();
var showSureRight = ref(false);
var showSureLeft = ref(false);
var sureMarginRight = ref(0);
var sureMarginLeft = ref(0);
var closedSure = ref(false);
var sureRightContent = ref();
var sureLeftContent = ref();
var handleSureClick = ref();
var sureRightBgStyle = computed(function () {
var style = {
display: "inline-block",
position: "absolute",
width: "100%",
height: "100%",
backgroundColor: "rgba(0,0,0,0)",
transition: closedSure.value ? "none" : "background-color .6s cubic-bezier(0.18, 0.89, 0.32, 1)",
transform: "translate3d(".concat(initData.rightWidth, "px, 0, 0)"),
pointerEvents: "none"
};
if (showSureRight.value) {
style.backgroundColor = "rgba(0,0,0,.5)";
} else {
style.backgroundColor = "rgba(0,0,0,0)";
}
return style;
});
var sureLeftBgStyle = computed(function () {
var style = {
display: "inline-block",
position: "absolute",
width: "100%",
height: "100%",
backgroundColor: "rgba(0,0,0,0)",
transition: closedSure.value ? "none" : "background-color .6s cubic-bezier(0.18, 0.89, 0.32, 1)",
transform: "translate3d(0, 0, 0)",
pointerEvents: "none"
};
if (showSureLeft.value) {
style.backgroundColor = "rgba(0,0,0,.5)";
} else {
style.backgroundColor = "rgba(0,0,0,0)";
}
return style;
});
var sureRightStyle = computed(function () {
var style = {
display: "inline-block",
position: "absolute",
height: "100%",
top: 0,
minWidth: "100%",
transition: closedSure.value ? "none" : "transform .6s cubic-bezier(0.18, 0.89, 0.32, 1)",
transform: "translate3d(0, 0, 0)"
};
if (showSureRight.value) {
style.transform = "translate3d(0, 0, 0)";
} else {
style.transform = "translate3d(".concat(initData.rightWidth, "px, 0, 0)");
}
return style;
});
var sureLeftStyle = computed(function () {
var style = {
display: "inline-block",
position: "absolute",
height: "100%",
top: 0,
minWidth: "100%",
transition: closedSure.value ? "none" : "transform .6s cubic-bezier(0.18, 0.89, 0.32, 1)",
transform: "translate3d(0, 0, 0)"
};
if (showSureLeft.value) {
style.transform = "translate3d(0, 0, 0)";
} else {
style.transform = "translate3d(".concat(-initData.leftWidth, "px, 0, 0)");
}
return style;
});
watch(showSureRight, function () {
if (initData.pos < 0) {
if (showSureRight.value) {
var _sureRightRef$value;
var sureRightWidth = (_sureRightRef$value = sureRightRef.value) === null || _sureRightRef$value === void 0 ? void 0 : _sureRightRef$value.clientWidth;
sureMarginRight.value = Math.max(initData.rightWidth, sureRightWidth) - initData.rightWidth;
} else {
sureMarginRight.value = 0;
}
}
});
watch(showSureLeft, function () {
if (initData.pos > 0) {
if (showSureLeft.value) {
var _sureLeftRef$value;
var sureLeftWidth = (_sureLeftRef$value = sureLeftRef.value) === null || _sureLeftRef$value === void 0 ? void 0 : _sureLeftRef$value.clientWidth;
sureMarginLeft.value = Math.max(initData.leftWidth, sureLeftWidth) - initData.leftWidth;
} else {
sureMarginLeft.value = 0;
}
}
});
var showSure = function showSure(sure, onClick) {
handleSureClick.value = onClick;
var sureContent = sureRightContent;
var sureVisible = showSureRight;
if (initData.pos > 0) {
sureContent = sureLeftContent;
sureVisible = showSureLeft;
}
if (isString(sure) && instance !== null && instance !== void 0 && instance.slots[sure]) {
sureContent.value = renderTNode(instance, sure);
} else if (isFunction(sure)) {
setBlockTracking(-1);
sureContent.value = sure(h);
setBlockTracking(1);
} else {
sureContent.value = sure;
}
nextTick(function () {
sureVisible.value = true;
});
};
return {
sureRightRef: sureRightRef,
sureLeftRef: sureLeftRef,
showSureRight: showSureRight,
showSureLeft: showSureLeft,
sureMarginRight: sureMarginRight,
sureMarginLeft: sureMarginLeft,
closedSure: closedSure,
sureRightContent: sureRightContent,
sureLeftContent: sureLeftContent,
sureLeftBgStyle: sureLeftBgStyle,
sureRightBgStyle: sureRightBgStyle,
sureRightStyle: sureRightStyle,
sureLeftStyle: sureLeftStyle,
showSure: showSure,
handleSureClick: handleSureClick
};
}
export { useSureConfirm };
//# sourceMappingURL=useSureConfirm.js.map