This commit is contained in:
神仙都没用 2023-10-30 18:34:30 +08:00
parent 42b406e028
commit 9f5ea9aff8
7 changed files with 85 additions and 74 deletions

View File

@ -39,7 +39,7 @@ async function getData(temps?: Eps.Entity[]) {
if (code === 1000) { if (code === 1000) {
if (!isEmpty(data) && data) { if (!isEmpty(data) && data) {
list = Object.values(data).flat() as Eps.Entity[]; merge(list, Object.values(data).flat() as Eps.Entity[]);
} }
} else { } else {
error(`[eps] ${message}`); error(`[eps] ${message}`);
@ -49,7 +49,7 @@ async function getData(temps?: Eps.Entity[]) {
error(`[eps] ${url} 服务未启动!!!`); error(`[eps] ${url} 服务未启动!!!`);
}); });
// 合并本地 service 数据 // 合并其他数据
if (isArray(temps)) { if (isArray(temps)) {
temps.forEach((e) => { temps.forEach((e) => {
const d = list.find((a) => e.prefix === a.prefix); const d = list.find((a) => e.prefix === a.prefix);
@ -65,21 +65,19 @@ async function getData(temps?: Eps.Entity[]) {
// 创建 json 文件 // 创建 json 文件
function createJson() { function createJson() {
const d = list const d = list.map((e) => {
.filter((e) => !e.isLocal) // 过滤本地的 service 数据 return {
.map((e) => { prefix: e.prefix,
return { name: e.name || "",
prefix: e.prefix, api: e.api.map((e) => {
name: e.name || "", return {
api: e.api.map((e) => { name: e.name,
return { method: e.method,
name: e.name, path: e.path
method: e.method, };
path: e.path })
}; };
}) });
};
});
createWriteStream(join(DistPath, "eps.json"), { createWriteStream(join(DistPath, "eps.json"), {
flags: "w" flags: "w"

View File

@ -1,7 +1,6 @@
export const proxy = { export const proxy = {
"/dev/": { "/dev/": {
// target: "http://127.0.0.1:8001", target: "http://127.0.0.1:8001",
target: "https://test-admin.cool-js.cloud",
changeOrigin: true, changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/dev/, "") rewrite: (path: string) => path.replace(/^\/dev/, "")
}, },

View File

@ -1,74 +1,75 @@
import { merge } from "lodash-es"; import { cloneDeep, merge } from "lodash-es";
import { BaseService, service } from "../service"; import { BaseService, service } from "../service";
import { Module } from "../types"; import { Module } from "../types";
import { path2Obj } from "../utils"; import { path2Obj } from "../utils";
import { config, isDev } from "/@/config"; import { config, isDev } from "/@/config";
import { eps } from "virtual:eps"; import { eps } from "virtual:eps";
import { hmr } from "../hook";
import { module } from "../module";
export function createEps(modules: Module[]) { // 更新事件
// 更新数据 function onUpdate() {
function update() { // 设置 request 方法
// 设置 request 方法 function set(d: any) {
function set(d: any) { if (d.namespace) {
if (d.namespace) { const a = new BaseService(d.namespace);
const a = new BaseService(d.namespace);
for (const i in d) { for (const i in d) {
const { path, method = "get" } = d[i]; const { path, method = "get" } = d[i];
if (path) { if (path) {
a.request = a.request; a.request = a.request;
a[i] = function (data?: any) { a[i] = function (data?: any) {
return this.request({ return this.request({
url: path, url: path,
method, method,
[method.toLocaleLowerCase() == "post" ? "data" : "params"]: data [method.toLocaleLowerCase() == "post" ? "data" : "params"]: data
}); });
}; };
}
}
for (const i in a) {
d[i] = a[i];
}
} else {
for (const i in d) {
set(d[i]);
} }
} }
for (const i in a) {
d[i] = a[i];
}
} else {
for (const i in d) {
set(d[i]);
}
} }
}
// 遍历每一个方法 // 遍历每一个方法
set(eps.service); set(eps.service);
// 合并[eps] // 合并[eps]
merge(service, eps.service); merge(service, eps.service);
// 合并[local] // 合并[local]
merge( merge(
service, service,
cloneDeep(
path2Obj( path2Obj(
modules.reduce((a, b) => { module.list.reduce((a, b) => {
return a.concat(...((b.services as any[]) || [])); return a.concat(...((b.services as any[]) || []));
}, []) }, [])
) )
); )
);
// 提示 // 热更新处理
if (isDev) { hmr.setData("service", service);
console.log("[eps] update", service);
} // 提示
if (isDev) {
console.log("[eps] update", service);
} }
}
update(); export function createEps(modules: Module[]) {
// 更新 eps
// 监听 vite 触发事件 onUpdate();
if (import.meta.hot) {
import.meta.hot.on("eps-update", () => {
update();
});
}
// 开发环境下,生成本地 service 的类型描述文件 // 开发环境下,生成本地 service 的类型描述文件
if (isDev && config.test.eps) { if (isDev && config.test.eps) {
@ -116,3 +117,10 @@ export function createEps(modules: Module[]) {
}); });
} }
} }
// 监听 vite 触发事件
if (import.meta.hot) {
import.meta.hot.on("eps-update", () => {
onUpdate();
});
}

View File

@ -1,9 +1,9 @@
import { hmr } from "../hook";
import { BaseService } from "./base"; import { BaseService } from "./base";
// service 数据集合 // service 数据集合
export const service: Eps.Service = { export const service: Eps.Service = hmr.getData("service", {
// @ts-ignore
request: new BaseService().request request: new BaseService().request
}; });
export * from "./base"; export * from "./base";

View File

@ -2,7 +2,9 @@
<div class="select-user__inner"> <div class="select-user__inner">
<div class="btns"> <div class="btns">
<el-button type="success" @click="open">添加</el-button> <el-button type="success" @click="open">添加</el-button>
<el-button type="danger" :disabled="list.length == 0" @click="remove">移除</el-button> <el-button type="danger" :disabled="refs.table?.selection.length == 0" @click="remove"
>移除</el-button
>
</div> </div>
<cl-table :data="list" :ref="setRefs('table')" :auto-height="false" /> <cl-table :data="list" :ref="setRefs('table')" :auto-height="false" />

View File

@ -177,6 +177,10 @@ const Upsert = useUpsert({
label: "基础", label: "基础",
value: "base" value: "base"
}, },
{
label: "选择",
value: "select"
},
{ {
label: "其他", label: "其他",
value: "other" value: "other"
@ -253,7 +257,7 @@ const Upsert = useUpsert({
{ {
label: "选择用户", label: "选择用户",
prop: "userIds", prop: "userIds",
group: "base", group: "select",
component: { component: {
name: "slot-userIds" name: "slot-userIds"
} }

View File

@ -86,7 +86,7 @@ export default defineComponent({
return []; return [];
}); });
} else { } else {
console.error("Crud 中未配置 service 参数"); console.error("useCrud 中未设置 service 参数");
return []; return [];
} }
} }