mt-ui-components-vue3
Version:
玛果添实UI组件库(Vue3)
162 lines • 6.79 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",
"multiple": "props",
"placement": "props",
"width": "props",
"inject": "setup-const",
"reactive": "setup-const",
"ref": "setup-const",
"watch": "setup-const",
"Form": "setup-maybe-ref",
"PopconfirmModal": "setup-maybe-ref",
"EnumItem": "setup-const",
"Icon": "setup-const",
"cloneDeep": "setup-maybe-ref",
"FULL_CODE": "setup-maybe-ref",
"props": "setup-reactive-const",
"emit": "setup-const",
"fullRef": "setup-maybe-ref",
"formRef": "setup-ref",
"tableRef": "setup-ref",
"formData": "setup-reactive-const",
"formItemContext": "setup-maybe-ref",
"source": "setup-ref",
"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 { inject, reactive, ref, watch } from 'vue';
import { Form, PopconfirmModal } from '../../../components';
import EnumItem from './EnumItem.js';
import Icon from '../Icon.js';
import { cloneDeep } from 'lodash-es';
import { FULL_CODE } from '../../index';
const __sfc_main__ = _defineComponent({
props: {
value: {
type: Object,
default: () => ({}),
},
multiple: {
type: Boolean,
default: false,
},
placement: {
type: String,
default: 'top',
},
width: {
type: String,
default: '480px',
},
},
emits: ['update:value', 'cancel', 'confirm'],
setup(__props, { emit }) {
const props = __props;
const fullRef = inject(FULL_CODE);
const formRef = ref();
const tableRef = ref();
const formData = reactive({
type: _optionalChain([props, 'access', _2 => _2.value, 'optionalAccess', _3 => _3.type]) || false,
elements: cloneDeep(_optionalChain([props, 'access', _4 => _4.value, 'optionalAccess', _5 => _5.elements])) || [],
});
const formItemContext = Form.useInjectFormItemContext();
const source = ref([]);
const cancel = () => {
_optionalChain([tableRef, 'access', _6 => _6.value, 'optionalAccess', _7 => _7.cancel, 'call', _8 => _8()]);
_optionalChain([formRef, 'access', _9 => _9.value, 'optionalAccess', _10 => _10.resetFields, 'call', _11 => _11()]);
formData.type = _optionalChain([props, 'access', _12 => _12.value, 'optionalAccess', _13 => _13.type]);
formData.elements = cloneDeep(_optionalChain([props, 'access', _14 => _14.value, 'optionalAccess', _15 => _15.elements])) || [];
emit('cancel');
};
const confirm = () => {
return new Promise(async (resolve, reject) => {
try {
const tableData = await tableRef.value.getData();
if (tableData) {
formRef.value
.validate()
.then(() => {
resolve(true);
const value = {
elements: tableData,
};
if (props.multiple) {
value.type = formData.type;
}
console.log('confirm', value);
emit('update:value', value);
emit('confirm', value);
formItemContext.onFieldChange();
})
.catch(() => reject(false));
}
}
catch (e) {
console.log(e);
reject(false);
}
});
};
watch(() => JSON.stringify(props.value), () => {
formData.type = _optionalChain([props, 'access', _16 => _16.value, 'optionalAccess', _17 => _17.type]);
formData.elements = cloneDeep(_optionalChain([props, 'access', _18 => _18.value, 'optionalAccess', _19 => _19.elements])) || [];
}, { immediate: true });
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_unref(PopconfirmModal), {
"destroy-on-close": "",
"body-style": { paddingTop: '4px', width: __props.width },
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(EnumItem, {
ref_key: "tableRef",
ref: tableRef,
value: formData.elements,
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => ((formData.elements) = $event)),
type: formData.type,
"onUpdate:type": _cache[1] || (_cache[1] = ($event) => ((formData.type) = $event)),
multiple: __props.multiple
}, null, 8 /* PROPS */, ["value", "type", "multiple"])
]),
_: 1 /* STABLE */
}, 8 /* PROPS */, ["model"])
]),
default: _withCtx(() => [
_renderSlot(_ctx.$slots, "default", {}, () => [
_createVNode(Icon)
])
]),
_: 3 /* FORWARDED */
}, 8 /* PROPS */, ["body-style", "placement", "get-popup-container"]));
};
}
});
export default __sfc_main__;