From 42b406e0287af682fec3f8102b0502962a1fb49f Mon Sep 17 00:00:00 2001 From: icssoa <615206459@qq.com> Date: Mon, 30 Oct 2023 00:56:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/cool/eps/index.ts | 28 +-- build/cool/types/index.d.ts | 1 + index.html | 7 +- src/config/proxy.ts | 3 +- src/cool/bootstrap/eps.ts | 98 ++++++--- src/cool/service/index.ts | 61 +----- src/modules/base/components/select/index.tsx | 2 +- src/modules/base/static/css/index.scss | 7 - src/modules/demo/components/form-btn.vue | 3 +- src/modules/demo/components/select-user.vue | 216 +++++++++++++++++++ src/modules/demo/views/crud.vue | 23 +- 11 files changed, 337 insertions(+), 112 deletions(-) create mode 100644 src/modules/demo/components/select-user.vue diff --git a/build/cool/eps/index.ts b/build/cool/eps/index.ts index 1b75b32..7294882 100644 --- a/build/cool/eps/index.ts +++ b/build/cool/eps/index.ts @@ -65,19 +65,21 @@ async function getData(temps?: Eps.Entity[]) { // 创建 json 文件 function createJson() { - const d = list.map((e) => { - return { - prefix: e.prefix, - name: e.name || "", - api: e.api.map((e) => { - return { - name: e.name, - method: e.method, - path: e.path - }; - }) - }; - }); + const d = list + .filter((e) => !e.isLocal) // 过滤本地的 service 数据 + .map((e) => { + return { + prefix: e.prefix, + name: e.name || "", + api: e.api.map((e) => { + return { + name: e.name, + method: e.method, + path: e.path + }; + }) + }; + }); createWriteStream(join(DistPath, "eps.json"), { flags: "w" diff --git a/build/cool/types/index.d.ts b/build/cool/types/index.d.ts index 2b6f3bd..4a778a5 100644 --- a/build/cool/types/index.d.ts +++ b/build/cool/types/index.d.ts @@ -28,5 +28,6 @@ export namespace Eps { module: string; name: string; prefix: string; + [key: string]: any; } } diff --git a/index.html b/index.html index bbec739..392df9c 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ - + @@ -22,7 +22,7 @@ margin: 0; padding: 0; font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", - "Microsoft YaHei", Arial, sans-serif; + "Microsoft YaHei", "微软雅黑", Arial, sans-serif; } .preload__wrap { @@ -93,8 +93,7 @@ border: 7px solid currentColor; border-bottom-color: #2f3447 !important; position: relative; - animation: - r 1s infinite cubic-bezier(0.17, 0.67, 0.83, 0.67), + animation: r 1s infinite cubic-bezier(0.17, 0.67, 0.83, 0.67), bc 2s infinite ease-in; transform: rotate(0deg); } diff --git a/src/config/proxy.ts b/src/config/proxy.ts index 9d6c263..af860ef 100644 --- a/src/config/proxy.ts +++ b/src/config/proxy.ts @@ -1,6 +1,7 @@ export const proxy = { "/dev/": { - target: "http://127.0.0.1:8001", + // target: "http://127.0.0.1:8001", + target: "https://test-admin.cool-js.cloud", changeOrigin: true, rewrite: (path: string) => path.replace(/^\/dev/, "") }, diff --git a/src/cool/bootstrap/eps.ts b/src/cool/bootstrap/eps.ts index 6e99157..2b523df 100644 --- a/src/cool/bootstrap/eps.ts +++ b/src/cool/bootstrap/eps.ts @@ -1,30 +1,85 @@ import { merge } from "lodash-es"; -import { service } from "../service"; +import { BaseService, service } from "../service"; import { Module } from "../types"; import { path2Obj } from "../utils"; import { config, isDev } from "/@/config"; +import { eps } from "virtual:eps"; export function createEps(modules: Module[]) { - // 本地模块的数据 - const s = path2Obj( - modules.reduce((a, b) => { - return a.concat(...((b.services as any[]) || [])); - }, []) - ); + // 更新数据 + function update() { + // 设置 request 方法 + function set(d: any) { + if (d.namespace) { + const a = new BaseService(d.namespace); - // 合并数据 - merge(service, s); + for (const i in d) { + const { path, method = "get" } = d[i]; - // 开发环境下,生成本地 service 的类型文件 + if (path) { + a.request = a.request; + + a[i] = function (data?: any) { + return this.request({ + url: path, + method, + [method.toLocaleLowerCase() == "post" ? "data" : "params"]: data + }); + }; + } + } + + for (const i in a) { + d[i] = a[i]; + } + } else { + for (const i in d) { + set(d[i]); + } + } + } + + // 遍历每一个方法 + set(eps.service); + + // 合并[eps] + merge(service, eps.service); + + // 合并[local] + merge( + service, + path2Obj( + modules.reduce((a, b) => { + return a.concat(...((b.services as any[]) || [])); + }, []) + ) + ); + + // 提示 + if (isDev) { + console.log("[eps] update", service); + } + } + + update(); + + // 监听 vite 触发事件 + if (import.meta.hot) { + import.meta.hot.on("eps-update", () => { + update(); + }); + } + + // 开发环境下,生成本地 service 的类型描述文件 if (isDev && config.test.eps) { const list: any[] = []; // 模拟 eps 数据 - function deep(s: any) { - if (s.namespace) { + modules.forEach((m) => { + m.services?.forEach((s) => { const api = Array.from( new Set([ - ...Object.getOwnPropertyNames(s.constructor.prototype), + ...Object.getOwnPropertyNames(s.value.constructor.prototype), "page", "list", "info", @@ -42,18 +97,13 @@ export function createEps(modules: Module[]) { list.push({ api, - module: s.namespace.split("/")[0], - name: s.constructor.name + "Entity", - prefix: `/admin/${s.namespace}` + module: m.name, + name: s.value.constructor.name + "Entity", + prefix: `/admin/${s.path}`, + isLocal: true }); - } else { - for (const i in s) { - deep(s[i]); - } - } - } - - deep(s); + }); + }); // 生成文件 service.request({ diff --git a/src/cool/service/index.ts b/src/cool/service/index.ts index 60ce26e..bb5a768 100644 --- a/src/cool/service/index.ts +++ b/src/cool/service/index.ts @@ -1,64 +1,9 @@ import { BaseService } from "./base"; -import { hmr } from "../hook"; -import { eps } from "virtual:eps"; -import { merge } from "lodash-es"; // service 数据集合 -export const service: Eps.Service = hmr.getData("service", { +export const service: Eps.Service = { + // @ts-ignore request: new BaseService().request -}); - -// 同步 service 数据 -function update() { - function deep(d: any) { - if (d.namespace) { - const a = new BaseService(d.namespace); - - for (const i in d) { - const { path, method = "get" } = d[i]; - - if (path) { - a.request = a.request; - - a[i] = function (data?: any) { - return this.request({ - url: path, - method, - [method.toLocaleLowerCase() == "post" ? "data" : "params"]: data - }); - }; - } - } - - for (const i in a) { - d[i] = a[i]; - } - } else { - for (const i in d) { - deep(d[i]); - } - } - } - - // 遍历 - deep(eps.service); - - // 合并 - merge(service, eps.service); - - // 缓存 - hmr.setData("service", service); - - // tips - console.log("[eps] update"); -} - -update(); - -if (import.meta.hot) { - import.meta.hot.on("eps-update", () => { - update(); - }); -} +}; export * from "./base"; diff --git a/src/modules/base/components/select/index.tsx b/src/modules/base/components/select/index.tsx index f1fc5d6..aba20f3 100644 --- a/src/modules/base/components/select/index.tsx +++ b/src/modules/base/components/select/index.tsx @@ -1,5 +1,5 @@ import { useCrud } from "@cool-vue/crud"; -import { isObject, isString } from "lodash-es"; +import { isString } from "lodash-es"; import { computed, defineComponent, isRef, PropType, Ref, ref, watch } from "vue"; import { parsePx } from "/@/cool/utils"; diff --git a/src/modules/base/static/css/index.scss b/src/modules/base/static/css/index.scss index 6b9c870..6830b75 100644 --- a/src/modules/base/static/css/index.scss +++ b/src/modules/base/static/css/index.scss @@ -1,10 +1,3 @@ -* { - padding: 0; - margin: 0; - font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", - "微软雅黑", Arial, sans-serif; -} - *::-webkit-scrollbar { width: 10px; height: 10px; diff --git a/src/modules/demo/components/form-btn.vue b/src/modules/demo/components/form-btn.vue index 4f1556a..ff54b52 100644 --- a/src/modules/demo/components/form-btn.vue +++ b/src/modules/demo/components/form-btn.vue @@ -104,7 +104,8 @@ function open() { labelPosition: "top" }, dialog: { - height: "500px" + height: "500px", + width: "1000px" }, items: [ { diff --git a/src/modules/demo/components/select-user.vue b/src/modules/demo/components/select-user.vue new file mode 100644 index 0000000..4faeb79 --- /dev/null +++ b/src/modules/demo/components/select-user.vue @@ -0,0 +1,216 @@ + + + + + diff --git a/src/modules/demo/views/crud.vue b/src/modules/demo/views/crud.vue index 2cfa878..8a6b971 100644 --- a/src/modules/demo/views/crud.vue +++ b/src/modules/demo/views/crud.vue @@ -45,7 +45,7 @@ }, { label: '手机号', value: 'phone' } ]" - :width="200" + :width="250" /> @@ -88,7 +88,11 @@ - + + + @@ -102,6 +106,7 @@ import { reactive } from "vue"; import { ElMessage, ElMessageBox } from "element-plus"; import { useCool } from "/@/cool"; import FormBtn from "../components/form-btn.vue"; +import SelectUser from "../components/select-user.vue"; // 基础 const { service, refs, setRefs } = useCool(); @@ -156,6 +161,11 @@ function refresh(params?: any) { // 新增、编辑 const Upsert = useUpsert({ + dialog: { + height: "600px", // 固定高 + width: "1000px" // 固定宽 + }, + items: [ // 分组 { @@ -232,7 +242,6 @@ const Upsert = useUpsert({ } ] }, - { label: "省市区", prop: "pca", @@ -241,6 +250,14 @@ const Upsert = useUpsert({ name: "cl-distpicker" } }, + { + label: "选择用户", + prop: "userIds", + group: "base", + component: { + name: "slot-userIds" + } + }, { label: "工作",