first commit
This commit is contained in:
+256
@@ -0,0 +1,256 @@
|
||||
"use strict";
|
||||
var common_vendor = require("../../../../common/vendor.js");
|
||||
var uni_modules_wotDesignUni_components_wdMessageBox_types = require("./types.js");
|
||||
var uni_modules_wotDesignUni_components_wdMessageBox_index = require("./index.js");
|
||||
var uni_modules_wotDesignUni_components_common_util = require("../common/util.js");
|
||||
var uni_modules_wotDesignUni_components_composables_useTranslate = require("../composables/useTranslate.js");
|
||||
require("../common/props.js");
|
||||
require("../common/AbortablePromise.js");
|
||||
require("../../locale/index.js");
|
||||
require("../../locale/lang/zh-CN.js");
|
||||
if (!Math) {
|
||||
(wdInput + wdButton + wdPopup)();
|
||||
}
|
||||
const wdPopup = () => "../wd-popup/wd-popup.js";
|
||||
const wdButton = () => "../wd-button/wd-button.js";
|
||||
const wdInput = () => "../wd-input/wd-input.js";
|
||||
const __default__ = {
|
||||
name: "wd-message-box",
|
||||
options: {
|
||||
virtualHost: true,
|
||||
addGlobalClass: true,
|
||||
styleIsolation: "shared"
|
||||
}
|
||||
};
|
||||
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
...__default__,
|
||||
props: uni_modules_wotDesignUni_components_wdMessageBox_types.messageBoxProps,
|
||||
setup(__props) {
|
||||
const props = __props;
|
||||
const { translate } = uni_modules_wotDesignUni_components_composables_useTranslate.useTranslate("message-box");
|
||||
const rootClass = common_vendor.computed$1(() => {
|
||||
return `wd-message-box__container ${props.customClass}`;
|
||||
});
|
||||
const bodyClass = common_vendor.computed$1(() => {
|
||||
return `wd-message-box__body ${!messageState.title ? "is-no-title" : ""} ${messageState.type === "prompt" ? "is-prompt" : ""}`;
|
||||
});
|
||||
const messageOptionKey = uni_modules_wotDesignUni_components_wdMessageBox_index.getMessageDefaultOptionKey(props.selector);
|
||||
const messageOption = common_vendor.inject(messageOptionKey, common_vendor.ref(uni_modules_wotDesignUni_components_wdMessageBox_index.defaultOptions));
|
||||
const messageState = common_vendor.reactive({
|
||||
msg: "",
|
||||
show: false,
|
||||
title: "",
|
||||
showCancelButton: false,
|
||||
closeOnClickModal: true,
|
||||
confirmButtonText: "",
|
||||
cancelButtonText: "",
|
||||
type: "alert",
|
||||
inputType: "text",
|
||||
inputValue: "",
|
||||
inputPlaceholder: "",
|
||||
inputError: "",
|
||||
showErr: false,
|
||||
zIndex: 99,
|
||||
lazyRender: true
|
||||
});
|
||||
const customConfirmProps = common_vendor.computed$1(() => {
|
||||
const buttonProps = uni_modules_wotDesignUni_components_common_util.deepAssign(
|
||||
{
|
||||
block: true
|
||||
},
|
||||
uni_modules_wotDesignUni_components_common_util.isDef(messageState.confirmButtonProps) ? uni_modules_wotDesignUni_components_common_util.omitBy(messageState.confirmButtonProps, uni_modules_wotDesignUni_components_common_util.isUndefined) : {}
|
||||
);
|
||||
buttonProps.customClass = `${buttonProps.customClass || ""} wd-message-box__actions-btn`;
|
||||
return buttonProps;
|
||||
});
|
||||
const customCancelProps = common_vendor.computed$1(() => {
|
||||
const buttonProps = uni_modules_wotDesignUni_components_common_util.deepAssign(
|
||||
{
|
||||
block: true,
|
||||
type: "info"
|
||||
},
|
||||
uni_modules_wotDesignUni_components_common_util.isDef(messageState.cancelButtonProps) ? uni_modules_wotDesignUni_components_common_util.omitBy(messageState.cancelButtonProps, uni_modules_wotDesignUni_components_common_util.isUndefined) : {}
|
||||
);
|
||||
buttonProps.customClass = `${buttonProps.customClass || ""} wd-message-box__actions-btn`;
|
||||
return buttonProps;
|
||||
});
|
||||
common_vendor.watch(
|
||||
() => messageOption.value,
|
||||
(newVal) => {
|
||||
reset(newVal);
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
common_vendor.watch(
|
||||
() => messageState.show,
|
||||
(newValue) => {
|
||||
resetErr(!!newValue);
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
function toggleModal(action) {
|
||||
if (action === "modal" && !messageState.closeOnClickModal) {
|
||||
return;
|
||||
}
|
||||
if (messageState.type === "prompt" && action === "confirm" && !validate()) {
|
||||
return;
|
||||
}
|
||||
switch (action) {
|
||||
case "confirm":
|
||||
if (messageState.beforeConfirm) {
|
||||
messageState.beforeConfirm({
|
||||
resolve: (isPass) => {
|
||||
if (isPass) {
|
||||
handleConfirm({
|
||||
action,
|
||||
value: messageState.inputValue
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handleConfirm({
|
||||
action,
|
||||
value: messageState.inputValue
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "cancel":
|
||||
handleCancel({
|
||||
action
|
||||
});
|
||||
break;
|
||||
default:
|
||||
handleCancel({
|
||||
action: "modal"
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
function handleConfirm(result) {
|
||||
messageState.show = false;
|
||||
if (uni_modules_wotDesignUni_components_common_util.isFunction(messageState.success)) {
|
||||
messageState.success(result);
|
||||
}
|
||||
}
|
||||
function handleCancel(result) {
|
||||
messageState.show = false;
|
||||
if (uni_modules_wotDesignUni_components_common_util.isFunction(messageState.fail)) {
|
||||
messageState.fail(result);
|
||||
}
|
||||
}
|
||||
function validate() {
|
||||
if (messageState.inputPattern && !messageState.inputPattern.test(String(messageState.inputValue))) {
|
||||
messageState.showErr = true;
|
||||
return false;
|
||||
}
|
||||
if (typeof messageState.inputValidate === "function") {
|
||||
const validateResult = messageState.inputValidate(messageState.inputValue);
|
||||
if (!validateResult) {
|
||||
messageState.showErr = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
messageState.showErr = false;
|
||||
return true;
|
||||
}
|
||||
function resetErr(val) {
|
||||
if (val === false) {
|
||||
messageState.showErr = false;
|
||||
}
|
||||
}
|
||||
function inputValChange({ value }) {
|
||||
if (value === "") {
|
||||
messageState.showErr = false;
|
||||
return;
|
||||
}
|
||||
messageState.inputValue = value;
|
||||
}
|
||||
function reset(option) {
|
||||
if (option) {
|
||||
messageState.title = uni_modules_wotDesignUni_components_common_util.isDef(option.title) ? option.title : "";
|
||||
messageState.showCancelButton = uni_modules_wotDesignUni_components_common_util.isDef(option.showCancelButton) ? option.showCancelButton : false;
|
||||
messageState.show = option.show;
|
||||
messageState.closeOnClickModal = option.closeOnClickModal;
|
||||
messageState.confirmButtonText = option.confirmButtonText;
|
||||
messageState.cancelButtonText = option.cancelButtonText;
|
||||
messageState.msg = option.msg;
|
||||
messageState.type = option.type;
|
||||
messageState.inputType = option.inputType;
|
||||
messageState.inputSize = option.inputSize;
|
||||
messageState.inputValue = option.inputValue;
|
||||
messageState.inputPlaceholder = option.inputPlaceholder;
|
||||
messageState.inputPattern = option.inputPattern;
|
||||
messageState.inputValidate = option.inputValidate;
|
||||
messageState.success = option.success;
|
||||
messageState.fail = option.fail;
|
||||
messageState.beforeConfirm = option.beforeConfirm;
|
||||
messageState.inputError = option.inputError;
|
||||
messageState.showErr = option.showErr;
|
||||
messageState.zIndex = option.zIndex;
|
||||
messageState.lazyRender = option.lazyRender;
|
||||
messageState.confirmButtonProps = option.confirmButtonProps;
|
||||
messageState.cancelButtonProps = option.cancelButtonProps;
|
||||
}
|
||||
}
|
||||
return (_ctx, _cache) => {
|
||||
return common_vendor.e({
|
||||
a: messageState.title
|
||||
}, messageState.title ? {
|
||||
b: common_vendor.t(messageState.title)
|
||||
} : {}, {
|
||||
c: messageState.type === "prompt"
|
||||
}, messageState.type === "prompt" ? common_vendor.e({
|
||||
d: common_vendor.o(inputValChange),
|
||||
e: common_vendor.o(($event) => messageState.inputValue = $event),
|
||||
f: common_vendor.p({
|
||||
type: messageState.inputType,
|
||||
size: messageState.inputSize,
|
||||
placeholder: messageState.inputPlaceholder,
|
||||
modelValue: messageState.inputValue
|
||||
}),
|
||||
g: messageState.showErr
|
||||
}, messageState.showErr ? {
|
||||
h: common_vendor.t(messageState.inputError || common_vendor.unref(translate)("inputNoValidate"))
|
||||
} : {}) : {}, {
|
||||
i: common_vendor.t(messageState.msg),
|
||||
j: common_vendor.n(common_vendor.unref(bodyClass)),
|
||||
k: messageState.showCancelButton
|
||||
}, messageState.showCancelButton ? {
|
||||
l: common_vendor.t(messageState.cancelButtonText || common_vendor.unref(translate)("cancel")),
|
||||
m: common_vendor.o(($event) => toggleModal("cancel")),
|
||||
n: common_vendor.p({
|
||||
...common_vendor.unref(customCancelProps)
|
||||
})
|
||||
} : {}, {
|
||||
o: common_vendor.t(messageState.confirmButtonText || common_vendor.unref(translate)("confirm")),
|
||||
p: common_vendor.o(($event) => toggleModal("confirm")),
|
||||
q: common_vendor.p({
|
||||
...common_vendor.unref(customConfirmProps)
|
||||
}),
|
||||
r: common_vendor.n(`wd-message-box__actions ${messageState.showCancelButton ? "wd-message-box__flex" : "wd-message-box__block"}`),
|
||||
s: common_vendor.n(common_vendor.unref(rootClass)),
|
||||
t: common_vendor.o(($event) => toggleModal("modal")),
|
||||
v: common_vendor.o(($event) => messageState.show = $event),
|
||||
w: common_vendor.p({
|
||||
transition: "zoom-in",
|
||||
["close-on-click-modal"]: messageState.closeOnClickModal,
|
||||
["lazy-render"]: messageState.lazyRender,
|
||||
["custom-class"]: "wd-message-box",
|
||||
["z-index"]: messageState.zIndex,
|
||||
duration: 200,
|
||||
["root-portal"]: _ctx.rootPortal,
|
||||
modelValue: messageState.show
|
||||
})
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-12024933"], ["__file", "D:/\u7F51\u6291\u4E91Time/\u79C1\u6D3B/2000\u7B97\u5366/src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue"]]);
|
||||
wx.createComponent(Component);
|
||||
Reference in New Issue
Block a user