UNPKG

@javaguns/flow-ui

Version:

``` <template> <a-spin :spinning="loading"> <FlowDesigner ref="flowDesigner" top="50px"> </FlowDesigner> </a-spin> </template> <script lang="ts" setup> import { ref, provide, onMounted } from 'vue'; import { FlowDesigner, LoadingKey } from '@j

105 lines (104 loc) 4.67 kB
import { defineComponent as _, getCurrentInstance as x, toRefs as D, ref as I, watch as U, computed as O, onMounted as E, openBlock as n, createBlock as m, unref as p, withCtx as d, createElementBlock as i, Fragment as s, renderList as c, createTextVNode as N, toDisplayString as h } from "vue"; import { pluginManager as f, toUgroup as G } from "@javaguns/utils"; const L = /* @__PURE__ */ _({ __name: "flowSelect", props: { modelValue: {}, groupDatas: { default: () => [] }, datas: { default: () => [] }, labelName: { default: "name" }, valueName: { default: "value" }, codeName: { default: "code" }, mode: { default: "multiple" }, multiple: { type: Boolean, default: !1 }, totalValue: { type: Boolean, default: !1 }, toStr: { type: Boolean, default: !0 }, placeholder: { default: "请选择" } }, emits: ["update:modelValue", "update:label", "update:code", "change"], setup(V, { emit: S }) { const A = f.getComponent("Select"), v = f.getComponent("SelectOptionGroup"), g = f.getComponent("SelectOption"), { appContext: C } = x(), k = C.app.config.globalProperties.$flowUI, e = V, { modelValue: y } = D(e), r = I(y.value || void 0); U( () => e.modelValue, (l) => { b(l); } ), O(() => k == "element-plus" ? "el-option-group" : "a-select-opt-group"); const b = (l) => { if (l) if (e.mode == "simple") r.value = e.toStr ? l + "" : l; else if (e.mode == "multiple" && e.multiple == !1 && l.length > 0) r.value = e.toStr ? l[0] + "" : l; else if (e.mode == "multiple" && e.multiple == !0) { const a = e.totalValue ? G(Number(l)) : l; e.toStr && Array.isArray(a) ? (r.value = [], a.forEach((o) => { var t; (t = r.value) == null || t.push(o + ""); })) : e.toStr ? r.value = a + "" : r.value = a; } else r.value = null; }, u = S, w = (l) => { if (l) { if (e.mode == "simple" || e.mode == "multiple" && e.multiple == !0 && e.totalValue == !1) { const a = e.datas.filter((t) => t[e.valueName] == l).map((t) => t[e.labelName]), o = e.datas.filter((t) => t[e.valueName] == l).map((t) => t[e.codeName]); u("update:modelValue", l), e.mode == "simple" ? (u("update:label", Array.isArray(a) && a.length > 0 ? a[0] : a), u("update:code", Array.isArray(o) && o.length > 0 ? o[0] : o)) : (u("update:label", a), u("update:code", o)), u("change", l); } else if (e.mode == "multiple" && e.multiple == !1) { const a = e.datas.filter((t) => t[e.valueName] == l).map((t) => t[e.labelName]), o = e.datas.filter((t) => t[e.valueName] == l).map((t) => t[e.codeName]); u("update:modelValue", Array.isArray(l) ? l : [l]), u("update:label", Array.isArray(a) ? a : [a]), u("update:code", Array.isArray(o) ? a : [o]), u("change", Array.isArray(l) ? l : [l]); } else if (e.mode == "multiple" && e.multiple == !0 && e.totalValue == !0) { let a = null; l.length > 0 && (a = l.reduce((o, t) => parseInt(o) + parseInt(t))), u("update:modelValue", a), u("change", a); } } }; return E(() => { b(y.value); }), (l, a) => (n(), m(p(A), { modelValue: r.value, "onUpdate:modelValue": a[0] || (a[0] = (o) => r.value = o), value: r.value, "onUpdate:value": a[1] || (a[1] = (o) => r.value = o), multiple: e.multiple, mode: e.multiple ? "multiple" : "default", allowClear: "", placeholder: e.placeholder, class: "w-fill", onChange: w }, { default: d(() => [ e.groupDatas.length > 0 ? (n(!0), i(s, { key: 0 }, c(e.groupDatas, (o) => (n(), m(p(v), { label: o.name, key: o.value }, { default: d(() => [ (n(!0), i(s, null, c(o.children, (t, B) => (n(), m(p(g), { key: B, value: t[e.valueName].toString(), label: t[e.labelName] }, { default: d(() => [ N(h(t[e.labelName]), 1) ]), _: 2 }, 1032, ["value", "label"]))), 128)) ]), _: 2 }, 1032, ["label"]))), 128)) : (n(!0), i(s, { key: 1 }, c(e.datas, (o, t) => (n(), m(p(g), { key: t, value: o[e.valueName].toString(), label: o[e.labelName] }, { default: d(() => [ N(h(o[e.labelName]), 1) ]), _: 2 }, 1032, ["value", "label"]))), 128)) ]), _: 1 }, 8, ["modelValue", "value", "multiple", "mode", "placeholder"])); } }); export { L as default };