mt-ui-components-vue3
Version:
玛果添实UI组件库(Vue3)
120 lines • 4.37 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",
"inject": "setup-const",
"reactive": "setup-const",
"ref": "setup-const",
"watch": "setup-const",
"Form": "setup-maybe-ref",
"PopconfirmModal": "setup-maybe-ref",
"FileType": "setup-const",
"Icon": "setup-const",
"FULL_CODE": "setup-maybe-ref",
"emit": "setup-const",
"props": "setup-reactive-const",
"fullRef": "setup-maybe-ref",
"rules": "setup-const",
"formRef": "setup-ref",
"formData": "setup-reactive-const",
"confirm": "setup-const",
"cancel": "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 FileType from './FileType.js';
import Icon from '../Icon.js';
import { FULL_CODE } from '../../index';
const __sfc_main__ = _defineComponent({
props: {
value: {
type: String,
default: undefined,
},
placement: {
type: String,
default: 'top',
},
},
emits: ['update:value', 'confirm', 'cancel'],
setup(__props, { emit }) {
const props = __props;
const fullRef = inject(FULL_CODE);
const rules = [
{
validator: (_, value) => {
if (!value) {
return Promise.reject('请选择文件类型');
}
return Promise.resolve();
},
},
];
const formRef = ref();
const formData = reactive({
file: props.value,
});
const confirm = () => {
emit('update:value', formData.file);
emit('confirm', formData.file);
};
const cancel = () => {
_optionalChain([formRef, 'access', _2 => _2.value, 'optionalAccess', _3 => _3.resetFields, 'call', _4 => _4()]);
formData.file = props.value;
emit('cancel');
};
watch(() => props.value, () => {
formData.file = props.value;
});
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(FileType, {
value: formData.file,
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => ((formData.file) = $event))
}, 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__;