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

View File

@ -1,7 +1,6 @@
export const proxy = {
"/dev/": {
// target: "http://127.0.0.1:8001",
target: "https://test-admin.cool-js.cloud",
target: "http://127.0.0.1:8001",
changeOrigin: true,
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 { Module } from "../types";
import { path2Obj } from "../utils";
import { config, isDev } from "/@/config";
import { eps } from "virtual:eps";
import { hmr } from "../hook";
import { module } from "../module";
export function createEps(modules: Module[]) {
// 更新数据
function update() {
// 设置 request 方法
function set(d: any) {
if (d.namespace) {
const a = new BaseService(d.namespace);
// 更新事件
function onUpdate() {
// 设置 request 方法
function set(d: any) {
if (d.namespace) {
const a = new BaseService(d.namespace);
for (const i in d) {
const { path, method = "get" } = d[i];
for (const i in d) {
const { path, method = "get" } = d[i];
if (path) {
a.request = a.request;
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]);
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);
// 遍历每一个方法
set(eps.service);
// 合并[eps]
merge(service, eps.service);
// 合并[eps]
merge(service, eps.service);
// 合并[local]
merge(
service,
// 合并[local]
merge(
service,
cloneDeep(
path2Obj(
modules.reduce((a, b) => {
module.list.reduce((a, b) => {
return a.concat(...((b.services as any[]) || []));
}, [])
)
);
)
);
// 提示
if (isDev) {
console.log("[eps] update", service);
}
// 热更新处理
hmr.setData("service", service);
// 提示
if (isDev) {
console.log("[eps] update", service);
}
}
update();
// 监听 vite 触发事件
if (import.meta.hot) {
import.meta.hot.on("eps-update", () => {
update();
});
}
export function createEps(modules: Module[]) {
// 更新 eps
onUpdate();
// 开发环境下,生成本地 service 的类型描述文件
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";
// service 数据集合
export const service: Eps.Service = {
// @ts-ignore
export const service: Eps.Service = hmr.getData("service", {
request: new BaseService().request
};
});
export * from "./base";

View File

@ -2,7 +2,9 @@
<div class="select-user__inner">
<div class="btns">
<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>
<cl-table :data="list" :ref="setRefs('table')" :auto-height="false" />

View File

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

View File

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