mt-ui-components-vue3
Version:
玛果添实UI组件库(Vue3)
153 lines • 6.55 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",
"showUnit": "props",
"placement": "props",
"UnitSelect": "setup-maybe-ref",
"UnitProps": "setup-maybe-ref",
"inject": "setup-const",
"reactive": "setup-const",
"ref": "setup-const",
"watch": "setup-const",
"Form": "setup-maybe-ref",
"FormItem": "setup-maybe-ref",
"PopconfirmModal": "setup-maybe-ref",
"ScaleItem": "setup-const",
"Icon": "setup-const",
"FULL_CODE": "setup-maybe-ref",
"emit": "setup-const",
"props": "setup-reactive-const",
"formRef": "setup-ref",
"fullRef": "setup-maybe-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, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, renderSlot as _renderSlot } from "vue";
import UnitSelect, { UnitProps } from '../UnitSelect';
import { inject, reactive, ref, watch } from 'vue';
import { Form, FormItem, PopconfirmModal } from '../../../components';
import ScaleItem from './ScaleItem.js';
import Icon from '../Icon.js';
import { FULL_CODE } from '../../index';
const __sfc_main__ = _defineComponent({
props: {
...UnitProps,
value: {
type: Object,
default: () => ({}),
},
showUnit: {
type: Boolean,
default: true,
},
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({
unit: _optionalChain([props, 'access', _2 => _2.value, 'optionalAccess', _3 => _3.unit]),
scale: _optionalChain([props, 'access', _4 => _4.value, 'optionalAccess', _5 => _5.scale]) || 0, // 精度
});
const confirm = () => {
return new Promise(async (resolve, reject) => {
formRef.value
.validate()
.then(() => {
resolve(true);
const obj = { ...formData };
if (!props.showUnit) {
delete obj.unit;
}
emit('update:value', formData);
emit('confirm', formData);
})
.catch((e) => {
reject(false);
});
});
};
const cancel = () => {
_optionalChain([formRef, 'access', _6 => _6.value, 'optionalAccess', _7 => _7.resetFields, 'call', _8 => _8()]);
formData.unit = _optionalChain([props, 'access', _9 => _9.value, 'optionalAccess', _10 => _10.unit]);
formData.scale = _optionalChain([props, 'access', _11 => _11.value, 'optionalAccess', _12 => _12.scale]);
emit('cancel');
};
watch(() => props.value, () => {
formData.unit = _optionalChain([props, 'access', _13 => _13.value, 'optionalAccess', _14 => _14.unit]);
formData.scale = _optionalChain([props, 'access', _15 => _15.value, 'optionalAccess', _16 => _16.scale]);
}, { deep: true });
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(() => [
(__props.showUnit)
? (_openBlock(), _createBlock(_unref(FormItem), {
key: 0,
name: "unit",
label: "单位",
rules: [{ max: 64, message: '最多可输入64个字符' }]
}, {
default: _withCtx(() => [
_createVNode(_unref(UnitSelect), {
value: formData.unit,
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => ((formData.unit) = $event)),
options: _ctx.options
}, null, 8 /* PROPS */, ["value", "options"])
]),
_: 1 /* STABLE */
}))
: _createCommentVNode("v-if", true),
_createVNode(ScaleItem, {
value: formData.scale,
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => ((formData.scale) = $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__;