UNPKG

snowy-designer

Version:

基于Epic-Designer-Pro版本的设计器,可视化开发页面表单

296 lines (295 loc) 6.94 kB
import { ref as I } from "vue"; import { loadAsyncComponent as G } from "../common/component.js"; import "lodash"; import "monaco-editor"; import "../request/index.js"; import "@vueuse/core"; import "../../../hooks/src/store/index.js"; import { useBuiltInRequests as pe } from "../../../hooks/src/plugin/useBuiltInRequests.js"; import { useDict as fe } from "../../../hooks/src/plugin/useDict.js"; import { useFormSchema as de } from "../../../hooks/src/plugin/useFormSchema.js"; import { usePanel as he } from "../../../hooks/src/plugin/usePanel.js"; import { useState as ge } from "../../../hooks/src/plugin/useState.js"; import { parseComponent as ye } from "../../../repl/src/useDynamicComponent.js"; function Se() { const y = I(!1), c = {}, A = [ { componentProps: { colon: !0, labelAlign: "right", labelCol: { span: 5 }, labelLayout: "fixed", labelPlacement: "left", labelWidth: 100, layout: "horizontal", name: "default", wrapperCol: { span: 19 } }, id: "root", label: "表单", type: "form", children: [] } ], i = { "epic-slot": { component: () => null, config: {}, defaultSchema: { type: "epic-slot" }, editConstraints: { locked: !0 }, icon: "" } }; let m = []; const h = I([]), { formSchema: N, setFormSchema: P } = de(); let a = [], p = {}, u = ["表单", "布局"]; const { getActivitybars: B, getRightSidebars: F, hideActivitybar: L, hideRightSidebar: R, registerActivitybar: k, registerRightSidebar: q, showActivitybar: w, showRightSidebar: D, viewsContainers: M } = he(), g = { // 示例数据 // publicTest: { // description: "测试函数", // name: "test", // handler: (e) => { // console.log(e) // // alert("测试函数弹出"); // }, // }, }, { removeProperty: j, setProperty: z, state: E } = ge({ // 请求服务基础地址 axiosConfig: { baseURL: "", headers: {}, params: {}, timeout: 1e4 }, // 上传文件地址 uploadFile: "https://examples.epicjs.cn/epic-mock/common/upload", // 上传图片地址 uploadImage: "https://examples.epicjs.cn/epic-mock/common/upload" }), { dictItems: O, dictList: T, loadDictItem: V, loadDictList: H, setFetchDictItemsFn: U, setFetchDictListFn: W } = fe(), f = pe(); function S(e, t) { if (typeof t == "function" && (t = G(t)), typeof t == "string") { const o = ye(t); t = G(() => o); } c[e] = t; } function J(e) { S(e.defaultSchema.type, e.component), e.defaultSchema.input && (e.config.action || (e.config.action = []), e.config.action.unshift( { // 参数配置 argsConfigs: [ { ...e.defaultSchema, field: "0", label: "设置数据" } ], description: "设置值", type: "setValue" }, { description: "获取值", type: "getValue" } )), i[e.defaultSchema.type] = e, r(); } function b(e) { delete i[e], delete c[e]; } function C(e) { m = e; } function K(e) { m.push(e); } function Q() { m.forEach((e) => { b(e); }), C([]), r(); } function X() { return c; } function Y(e) { return c[e]; } function Z(e) { var t; return ((t = d(e)) == null ? void 0 : t.defaultSchema.label) ?? ""; } function _(e) { var t; return ((t = d(e)) == null ? void 0 : t.icon) ?? ""; } function $(e) { var t, o; return (o = (t = d(e)) == null ? void 0 : t.editConstraints) == null ? void 0 : o.locked; } function ee() { return i; } function d(e) { return i[e]; } function r() { const e = []; Object.values(i).forEach((t) => { if (!a.includes(t.defaultSchema.type) && t.groupName) { const o = p[t.groupName] ?? t.groupName; let n = e.findIndex( (l) => l.title === o ); n === -1 && (e.push({ title: o, list: [] }), n = e.length - 1); const s = e[n].list.findIndex( (l) => l.type === t.defaultSchema.type ); s === -1 ? e[n].list.push(t.defaultSchema) : e[n].list[s] = t.defaultSchema; } }), e.sort((t, o) => { const n = u.indexOf(t.title), s = u.indexOf(o.title); return n === -1 ? 1 : s === -1 ? -1 : n - s; }), e.forEach((t) => { t.list.sort((o, n) => { var x, v; const s = ((x = i[o.type]) == null ? void 0 : x.sort) ?? 1e3, l = ((v = i[n.type]) == null ? void 0 : v.sort) ?? 1e3; return s - l; }); }), h.value = e; } function te() { return h; } function oe(e, t) { p[e] = t; } function ne() { p = {}; } function ie(e) { u = e, r(); } function re() { u = [], r(); } function se(e) { a.push(e), r(); } function ae(e) { a = a.filter((t) => t !== e), r(); } function ce(e) { a = e, r(); } function ue(e) { y.value = e; } function le(e) { const t = e.methodName ?? e.name, o = e.method ?? e.handler; g[t] = { ...e, handler: o, name: t }; } function me(e) { delete g[e]; } return { addBaseComponentType: K, addPublicMethod: le, baseComponentTypes: m, clearComponentGroupNameMap: ne, clearSortedGroups: re, component: S, componentConfigs: i, componentGroupNameMap: p, components: c, componentSchemaGroups: h, dictItems: O, dictList: T, formSchema: N, formSchemas: A, getActivitybars: B, getComponent: Y, getComponentConfingByType: d, getComponentConfings: ee, getComponents: X, getComponentSchemaGroups: te, getIcon: _, getLabel: Z, getLocked: $, getRightSidebars: F, global: E, hiddenComponents: a, hideActivitybar: L, hideComponent: se, hideRightSidebar: R, initialized: y, loadDictItem: V, loadDictList: H, publicMethods: g, registerActivitybar: k, registerComponent: J, registerRightSidebar: q, removeBaseComponents: Q, removeComponent: b, removeProperty: j, removePublicMethod: me, request: { clear: f.clear, execute: f.execute, register: f.register, requests: f.requests }, setBaseComponentTypes: C, setComponentGroupNameMap: oe, setFetchDictItemsFn: U, setFetchDictListFn: W, setFormSchema: P, setHideComponents: ce, setInitialized: ue, setProperty: z, setSortedGroups: ie, showActivitybar: w, showComponent: ae, showRightSidebar: D, sortedGroups: u, viewsContainers: M }; } const ke = Se(); export { ke as pluginManager, Se as usePluginManager };