UNPKG

mt-ui-components-vue3

Version:

玛果添实UI组件库(Vue3)

170 lines 8.08 kB
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", "name": "props", "FormItem": "setup-maybe-ref", "Input": "setup-maybe-ref", "reactive": "setup-const", "watch": "setup-const", "props": "setup-reactive-const", "emit": "setup-const", "formData": "setup-reactive-const", "rules": "setup-const", "change": "setup-const" } */ import { defineComponent as _defineComponent } from 'vue'; import { unref as _unref, createVNode as _createVNode, withCtx as _withCtx, createElementVNode as _createElementVNode, openBlock as _openBlock, createBlock as _createBlock } from "vue"; const _hoisted_1 = { class: "data-table-boolean-item", style: { "margin-bottom": "12px" } }; const _hoisted_2 = { class: "data-table-boolean-item--value" }; const _hoisted_3 = /*#__PURE__*/ _createElementVNode("div", null, "-", -1 /* HOISTED */); const _hoisted_4 = { class: "data-table-boolean-item--value" }; const _hoisted_5 = { class: "data-table-boolean-item" }; const _hoisted_6 = { class: "data-table-boolean-item--value" }; const _hoisted_7 = /*#__PURE__*/ _createElementVNode("div", null, "-", -1 /* HOISTED */); const _hoisted_8 = { class: "data-table-boolean-item--value" }; import { FormItem, Input } from '../../../components'; import { reactive, watch } from 'vue'; const __sfc_main__ = _defineComponent({ props: { value: { type: Object, default: () => ({}), }, name: { type: String, default: 'value', }, }, emits: ['update:value', 'change'], setup(__props, { emit }) { const props = __props; const formData = reactive({ 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 rules = [ { validator(_, v) { const isMax = Object.values(v).some((item) => item.length > 64); const isNull = Object.values(v).some((item) => !item); if (isMax) { return Promise.reject('最多可输入64个字符'); } if (isNull) { return Promise.reject('请输入布尔值'); } return Promise.resolve(); }, }, ]; const change = () => { emit('update:value', formData); emit('change', formData); }; watch(() => JSON.stringify(props.value), () => { formData.trueText = _optionalChain([props, 'access', _10 => _10.value, 'optionalAccess', _11 => _11.trueText]); formData.trueValue = _optionalChain([props, 'access', _12 => _12.value, 'optionalAccess', _13 => _13.trueValue]); formData.falseText = _optionalChain([props, 'access', _14 => _14.value, 'optionalAccess', _15 => _15.falseText]); formData.falseValue = _optionalChain([props, 'access', _16 => _16.value, 'optionalAccess', _17 => _17.falseValue]); }); return (_ctx, _cache) => { return (_openBlock(), _createBlock(_unref(FormItem), { label: "布尔值", required: "", name: __props.name, rules: rules }, { default: _withCtx(() => [ _createElementVNode("div", _hoisted_1, [ _createElementVNode("div", _hoisted_2, [ _createVNode(_unref(FormItem), { "no-style": "", name: "trueText" }, { default: _withCtx(() => [ _createVNode(_unref(Input), { value: formData.trueText, "onUpdate:value": _cache[0] || (_cache[0] = ($event) => ((formData.trueText) = $event)), onChange: change }, null, 8 /* PROPS */, ["value"]) ]), _: 1 /* STABLE */ }) ]), _hoisted_3, _createElementVNode("div", _hoisted_4, [ _createVNode(_unref(FormItem), { "no-style": "", name: "trueValue" }, { default: _withCtx(() => [ _createVNode(_unref(Input), { value: formData.trueValue, "onUpdate:value": _cache[1] || (_cache[1] = ($event) => ((formData.trueValue) = $event)), onChange: change }, null, 8 /* PROPS */, ["value"]) ]), _: 1 /* STABLE */ }) ]) ]), _createElementVNode("div", _hoisted_5, [ _createElementVNode("div", _hoisted_6, [ _createVNode(_unref(FormItem), { "no-style": "", name: "falseText" }, { default: _withCtx(() => [ _createVNode(_unref(Input), { value: formData.falseText, "onUpdate:value": _cache[2] || (_cache[2] = ($event) => ((formData.falseText) = $event)), onChange: change }, null, 8 /* PROPS */, ["value"]) ]), _: 1 /* STABLE */ }) ]), _hoisted_7, _createElementVNode("div", _hoisted_8, [ _createVNode(_unref(FormItem), { "no-style": "", name: "falseValue" }, { default: _withCtx(() => [ _createVNode(_unref(Input), { value: formData.falseValue, "onUpdate:value": _cache[3] || (_cache[3] = ($event) => ((formData.falseValue) = $event)), onChange: change }, null, 8 /* PROPS */, ["value"]) ]), _: 1 /* STABLE */ }) ]) ]) ]), _: 1 /* STABLE */ }, 8 /* PROPS */, ["name"])); }; } }); export default __sfc_main__;