mt-ui-components-vue3
Version:
玛果添实UI组件库(Vue3)
139 lines • 6.2 kB
JavaScript
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) {
const op = ops[i];
const fn = ops[i + 1];
i += 2;
if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
return undefined;
}
if (op === 'access' || op === 'optionalAccess') {
lastAccessLHS = value;
value = fn(value);
}
else if (op === 'call' || op === 'optionalCall') {
value = fn((...args) => value.call(lastAccessLHS, ...args));
lastAccessLHS = undefined;
}
} return value; }
/* Analyzed bindings: {
"value": "props",
"placement": "props",
"Form": "setup-maybe-ref",
"PopconfirmModal": "setup-maybe-ref",
"BooleanItem": "setup-const",
"Icon": "setup-const",
"inject": "setup-const",
"reactive": "setup-const",
"ref": "setup-const",
"watch": "setup-const",
"cloneDeep": "setup-maybe-ref",
"FULL_CODE": "setup-maybe-ref",
"emit": "setup-const",
"props": "setup-reactive-const",
"formRef": "setup-ref",
"fullRef": "setup-maybe-ref",
"formData": "setup-reactive-const",
"change": "setup-const",
"cancel": "setup-const",
"confirm": "setup-const"
} */
import { defineComponent as _defineComponent } from 'vue';
import { unref as _unref, createVNode as _createVNode, withCtx as _withCtx, renderSlot as _renderSlot, openBlock as _openBlock, createBlock as _createBlock } from "vue";
import { Form, PopconfirmModal } from '../../../components';
import BooleanItem from './BooleanItem.js';
import Icon from '../Icon.js';
import { inject, reactive, ref, watch } from 'vue';
import { cloneDeep } from 'lodash-es';
import { FULL_CODE } from '../../index';
const __sfc_main__ = _defineComponent({
props: {
value: {
type: Object,
default: () => ({}),
},
placement: {
type: String,
default: 'top',
},
},
emits: ['update:value', 'cancel', 'confirm'],
setup(__props, { emit }) {
const props = __props;
const formRef = ref();
const fullRef = inject(FULL_CODE);
const formData = reactive({
value: {
trueText: _optionalChain([props, 'access', _2 => _2.value, 'optionalAccess', _3 => _3.trueText]) || '是',
trueValue: _optionalChain([props, 'access', _4 => _4.value, 'optionalAccess', _5 => _5.trueValue]) || 'true',
falseText: _optionalChain([props, 'access', _6 => _6.value, 'optionalAccess', _7 => _7.falseText]) || '否',
falseValue: _optionalChain([props, 'access', _8 => _8.value, 'optionalAccess', _9 => _9.falseValue]) || 'false',
},
});
const change = () => {
formRef.value.validateFields('value');
};
const cancel = () => {
_optionalChain([formRef, 'access', _10 => _10.value, 'optionalAccess', _11 => _11.resetFields, 'call', _12 => _12()]);
formData.value = {
trueText: _optionalChain([props, 'access', _13 => _13.value, 'optionalAccess', _14 => _14.trueText]) || '是',
trueValue: _optionalChain([props, 'access', _15 => _15.value, 'optionalAccess', _16 => _16.trueValue]) || 'true',
falseText: _optionalChain([props, 'access', _17 => _17.value, 'optionalAccess', _18 => _18.falseText]) || '否',
falseValue: _optionalChain([props, 'access', _19 => _19.value, 'optionalAccess', _20 => _20.falseValue]) || 'false',
};
emit('cancel');
};
const confirm = () => {
return new Promise(async (resolve, reject) => {
const data = await formRef.value.validate().catch(() => {
reject();
});
if (data) {
emit('update:value', cloneDeep(formData.value));
emit('confirm', cloneDeep(formData.value));
resolve(true);
}
});
};
watch(() => JSON.stringify(props.value), () => {
formData.value = {
trueText: _optionalChain([props, 'access', _21 => _21.value, 'optionalAccess', _22 => _22.trueText]) || '是',
trueValue: _optionalChain([props, 'access', _23 => _23.value, 'optionalAccess', _24 => _24.trueValue]) || 'true',
falseText: _optionalChain([props, 'access', _25 => _25.value, 'optionalAccess', _26 => _26.falseText]) || '否',
falseValue: _optionalChain([props, 'access', _27 => _27.value, 'optionalAccess', _28 => _28.falseValue]) || 'false',
};
});
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_unref(PopconfirmModal), {
"body-style": "padding-top:4px;width: 260px;",
placement: __props.placement,
"get-popup-container": (node) => _unref(fullRef) || node,
onConfirm: confirm,
onCancel: cancel
}, {
content: _withCtx(() => [
_createVNode(_unref(Form), {
ref_key: "formRef",
ref: formRef,
model: formData,
layout: "vertical"
}, {
default: _withCtx(() => [
_createVNode(BooleanItem, {
value: formData.value,
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => ((formData.value) = $event)),
onChange: change
}, null, 8 /* PROPS */, ["value"])
]),
_: 1 /* STABLE */
}, 8 /* PROPS */, ["model"])
]),
default: _withCtx(() => [
_renderSlot(_ctx.$slots, "default", {}, () => [
_createVNode(Icon)
])
]),
_: 3 /* FORWARDED */
}, 8 /* PROPS */, ["placement", "get-popup-container"]));
};
}
});
export default __sfc_main__;