UNPKG

mt-ui-components-vue3

Version:

玛果添实UI组件库(Vue3)

97 lines 3.55 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": "setup-ref", "size": "props", "UnitProps": "setup-maybe-ref", "inject": "setup-const", "ref": "setup-const", "watch": "setup-const", "isArray": "setup-maybe-ref", "isFunction": "setup-maybe-ref", "Form": "setup-maybe-ref", "JSelect": "setup-maybe-ref", "FULL_CODE": "setup-maybe-ref", "emit": "setup-const", "props": "setup-reactive-const", "fullRef": "setup-maybe-ref", "unitOptions": "setup-ref", "formItemContext": "setup-maybe-ref", "change": "setup-const", "initOptions": "setup-const" } */ import { defineComponent as _defineComponent } from 'vue'; import { unref as _unref, openBlock as _openBlock, createBlock as _createBlock } from "vue"; import { UnitProps } from './defaultSetting'; import { inject, ref, watch } from 'vue'; import { isArray, isFunction } from 'lodash-es'; import { Form, Select as JSelect } from '../../../components'; import { FULL_CODE } from '../../index'; const __sfc_main__ = _defineComponent({ props: { ...UnitProps, value: { type: [String, Number], default: undefined, }, size: { type: String, default: undefined, }, }, emits: ["update:value", "change"], setup(__props, { emit }) { const props = __props; const fullRef = inject(FULL_CODE); const value = ref(props.value ? [props.value] : []); const unitOptions = ref([]); const formItemContext = Form.useInjectFormItemContext(); const change = (v) => { const newValue = v.length > 1 ? v.pop() : _optionalChain([v, 'optionalAccess', _ => _[0]]); value.value = [newValue]; emit('update:value', newValue); emit('change', newValue); formItemContext.onFieldChange(); }; const initOptions = async () => { if (isArray(props.options)) { unitOptions.value = props.options; } else if (isFunction(props.options)) { unitOptions.value = await props.options(); } }; initOptions(); watch(() => props.value, (newV) => { value.value = newV ? [newV] : undefined; }, { immediate: true }); return (_ctx, _cache) => { return (_openBlock(), _createBlock(_unref(JSelect), { value: value.value, "onUpdate:value": _cache[0] || (_cache[0] = ($event) => ((value).value = $event)), mode: "tags", options: unitOptions.value, size: __props.size, placeholder: "请选择单位", style: { "width": "100%" }, "get-popup-container": (node) => _unref(fullRef) || node, onChange: change }, null, 8 /* PROPS */, ["value", "options", "size", "get-popup-container"])); }; } }); export default __sfc_main__;