UNPKG

quick-admin-vue3-core

Version:

以快(计算机执行效率、开发效率)为核心的后台管理系统开发模板

79 lines (78 loc) 2.04 kB
import { ref as m, computed as b, nextTick as S } from "vue"; import { L as c } from "./index-C0qRtkRj.js"; import q from "./BaseOption-CnQJDi8m.js"; const d = { school: { reqNameKey: "name", resValKey: "id", //跟下方的handleItem中的value对应的键名保持一致 fetchApi: c, defaultField: { prop: "xx", label: "学校" }, extraParams: { type: "school" }, handleItem(a) { const { name: e, id: r } = a; return { label: e, value: r }; } }, company: { reqNameKey: "name", resValKey: "id", fetchApi: c, defaultField: { prop: "gs", label: "公司" }, extraParams: { type: "company" }, handleItem(a) { const { full_name: e, short_name: r, id: o } = a; return { label: e, value: o, short_name: r, slots: [q, { rightKey: "short_name" }] }; } } }, M = () => { function a(e, r, o, p) { if (!d[e]) throw new Error(`不存在type为${e}的类型`); let l = []; const { fetchApi: h, defaultField: y, handleItem: g, reqNameKey: x = "name", resValKey: K = "id", extraParams: O } = d[e], i = m(!1), n = m([]), v = b(() => n.value.map(g)); o && u(o); function u(t = "", f = !1) { if (!t) { if (l.length) return n.value = l; if (!f) return; } i.value = !!t, h({ [x]: t, ...O }).then((s) => { !l.length && !t && (l = s || []), n.value = s || []; }).finally(() => { i.value = !1; }); } function F(t) { const f = n.value.find((s) => s[K] === t); S(() => p(t, f)); } return { ...y, ...r, type: "select", attrs: { options: v, filterable: !0, placeholder: "支持输入名称/id进行搜索", remote: !0, remoteShowSuffix: !0, defaultFirstOption: !0, onFocus: () => u("", !0), remoteMethod: u, onChange: p ? F : void 0, loading: i } }; } return { getSearchOpts: a }; }; export { M as u };