mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-12 13:42:50 +00:00
优化 eps 不刷新本地 service 问题
This commit is contained in:
parent
7bfd30373b
commit
2ccd1febdd
@ -33,6 +33,12 @@ export function virtual(): Plugin {
|
||||
// 代码保存时触发 eps 刷新
|
||||
if (!file.includes("build/cool/dist")) {
|
||||
buildEps(server);
|
||||
|
||||
// 通知客户端刷新
|
||||
server.ws.send({
|
||||
type: "custom",
|
||||
event: "eps-update"
|
||||
});
|
||||
}
|
||||
},
|
||||
resolveId(id) {
|
||||
|
||||
@ -43,7 +43,7 @@ export function createEps(modules: Module[]) {
|
||||
list.push({
|
||||
api,
|
||||
module: s.namespace.split("/")[0],
|
||||
name: s.constructor.name,
|
||||
name: s.constructor.name + "Entity",
|
||||
prefix: `/admin/${s.namespace}`
|
||||
});
|
||||
} else {
|
||||
|
||||
@ -3,11 +3,13 @@ import { hmr } from "../hook";
|
||||
import { eps } from "virtual:eps";
|
||||
import { merge } from "lodash-es";
|
||||
|
||||
// service 数据集合
|
||||
export const service: Eps.Service = hmr.getData("service", {
|
||||
request: new BaseService().request
|
||||
});
|
||||
|
||||
function main() {
|
||||
// 同步 service 数据
|
||||
function update() {
|
||||
function deep(d: any) {
|
||||
if (d.namespace) {
|
||||
const a = new BaseService(d.namespace);
|
||||
@ -46,8 +48,17 @@ function main() {
|
||||
|
||||
// 缓存
|
||||
hmr.setData("service", service);
|
||||
|
||||
// tips
|
||||
console.log("[eps] update");
|
||||
}
|
||||
|
||||
main();
|
||||
update();
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.on("eps-update", () => {
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
export * from "./base";
|
||||
|
||||
6
src/modules/demo/service/user/follow.ts
Normal file
6
src/modules/demo/service/user/follow.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { BaseService, Service } from "/@/cool";
|
||||
|
||||
@Service("demo/user/follow")
|
||||
class DemoUserFollow extends BaseService {}
|
||||
|
||||
export default DemoUserFollow;
|
||||
33
src/modules/demo/service/user/info.ts
Normal file
33
src/modules/demo/service/user/info.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import axios from "axios";
|
||||
import { BaseService, Service } from "/@/cool";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
@Service("demo/user/info")
|
||||
class DemoUserInfo extends BaseService {
|
||||
// 测试方法,使用 request 请求数据
|
||||
t1() {
|
||||
return this.request({
|
||||
url: "/t1" // 测试地址,实际项目中请更换为真实接口地址
|
||||
});
|
||||
}
|
||||
|
||||
// 自定义请求,通过 axios 返回数据
|
||||
t2() {
|
||||
return axios({
|
||||
url: "https://"
|
||||
});
|
||||
}
|
||||
|
||||
// 自定义请求,通过 Promise 返回数据
|
||||
t3() {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
date: dayjs().format("YYYY-MM-DD HH:mm:ss")
|
||||
});
|
||||
}, 1500);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default DemoUserInfo;
|
||||
Loading…
x
Reference in New Issue
Block a user