chore: 更新低代码引擎依赖,file 增删改查完成

This commit is contained in:
wangxuefeng 2025-03-01 10:06:57 +08:00
parent 9e012947fb
commit 384ea1f547
6 changed files with 529 additions and 399 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
低代码相关接口文档: https://developer.shiyuegame.com/showdoc/web/#/231?page_id=15660

View File

@ -16,22 +16,22 @@
"clean": "rimraf node_modules" "clean": "rimraf node_modules"
}, },
"dependencies": { "dependencies": {
"@vtj/core": "^0.10.5", "@vtj/core": "^0.10.6",
"@vtj/designer": "0.10.5", "@vtj/designer": "0.10.6",
"@vtj/icons": "0.10.5", "@vtj/icons": "0.10.6",
"@vtj/local": "^0.10.5", "@vtj/local": "^0.10.6",
"@vtj/materials": "^0.10.5", "@vtj/materials": "^0.10.6",
"@vtj/node": "0.10.1", "@vtj/node": "0.10.1",
"@vtj/pro": "^0.10.5", "@vtj/pro": "^0.10.6",
"@vtj/renderer": "^0.10.5", "@vtj/renderer": "^0.10.6",
"@vtj/ui": "^0.10.5", "@vtj/ui": "^0.10.6",
"@vtj/utils": "0.10.5", "@vtj/utils": "0.10.6",
"@vtj/web": "^0.10.5", "@vtj/web": "^0.10.6",
"axios": "^1.8.1",
"element-plus": "^2.9.4", "element-plus": "^2.9.4",
"licia-es": "^1.46.0", "licia-es": "^1.46.0",
"vue": "~3.5.13", "vue": "~3.5.13",
"vue-router": "~4.5.0", "vue-router": "~4.5.0"
"axios": "^1.8.1"
}, },
"devDependencies": { "devDependencies": {
"@sy/vite-plugin-http2-proxy": "workspace:*", "@sy/vite-plugin-http2-proxy": "workspace:*",

View File

@ -1,21 +1,49 @@
import { type BlockSchema } from '@vtj/core';
import instance from './instance'; import instance from './instance';
export type LowCodeFileSchema = {
project_id: number;
publish: boolean;
active: boolean;
dsl: BlockSchema;
file_path?: string;
};
function transformFile(file: LowCodeFileSchema): LowCodeFileSchema {
return {
project_id: file.project_id,
publish: file.publish,
active: file.active,
// @ts-ignore
dsl: JSON.stringify(file.dsl),
file_path: file.file_path
};
}
export const getFileList = async () => { export const getFileList = async () => {
const response = await instance.get('/api/v1/file'); const response = await instance.get('/api/v1/files');
return response.data; return response.data;
}; };
export const createFile = async (data: any) => { export const getFile = async (id: string) => {
const response = await instance.post('/api/v1/file', data); const response = await instance.get(`/api/v1/files/${id}`);
return {
...response.data,
dsl: JSON.parse(response.data.dsl)
};
};
export const createFile = async (data: LowCodeFileSchema) => {
const response = await instance.post('/api/v1/files', transformFile(data));
return response.data; return response.data;
}; };
export const updateFile = async (id: string, data: any) => { export const updateFile = async (id: string, data: LowCodeFileSchema) => {
const response = await instance.put(`/api/v1/file/${id}`, data); const response = await instance.put(`/api/v1/files/${id}`, data);
return response.data; return response.data;
}; };
export const deleteFile = async (id: string) => { export const deleteFile = async (id: string) => {
const response = await instance.delete(`/api/v1/file/${id}`); const response = await instance.delete(`/api/v1/files/${id}`);
return response.data; return response.data;
}; };

View File

@ -12,7 +12,15 @@ import {
} from '@vtj/core'; } from '@vtj/core';
import { Storage, mapToObject } from '@vtj/utils'; import { Storage, mapToObject } from '@vtj/utils';
import { BaseService } from '@vtj/renderer'; import { BaseService } from '@vtj/renderer';
import { getProject, updateProject } from '@/io'; import {
getProject,
updateProject,
createFile,
updateFile as updateLowCodeFile,
getFile as getLowCodeFile,
type LowCodeFileSchema
} from '@/io';
import { isNumeric } from 'licia-es';
const storage = new Storage({ const storage = new Storage({
type: 'local', type: 'local',
expired: 0 expired: 0
@ -80,17 +88,55 @@ export class StorageService extends BaseService {
return Promise.resolve(true); return Promise.resolve(true);
} }
public saveFile(file: BlockSchema): Promise<boolean> { public async saveFile(file: BlockSchema): Promise<boolean> {
storage.save(`file_${file.id}`, file); // console.log('file', file);
console.log('saveFile', file); // const ACTION = {
// CREATE: 'create',
// UPDATE: 'update'
// };
// const action = isNumeric(file.id) ? ACTION.UPDATE : ACTION.CREATE;
// console.log('action', action);
// console.log('saveFile', file);
// if (action === ACTION.CREATE) {
// const newFile: LowCodeFileSchema = {
// project_id: 2,
// publish: false,
// active: true,
// dsl: file
// };
// Reflect.deleteProperty(newFile, 'id');
// const res = await createFile(newFile);
// console.log('saveFile-res', res);
// }
if (file.id) {
const existFile = await getLowCodeFile(file.id);
console.log('existFile', existFile);
if (existFile) {
await updateLowCodeFile(file.id, {
...existFile,
dsl: file
});
} else {
await createFile({
project_id: 2,
publish: false,
active: true,
dsl: file
});
}
}
// storage.save(`file_${file.id}`, file);
return Promise.resolve(true); return Promise.resolve(true);
} }
public getFile(id: string): Promise<BlockSchema> { public async getFile(id: string): Promise<BlockSchema> {
const dsl = storage.get(`file_${id}`); const dsl = storage.get(`file_${id}`);
console.log('getFile', id, dsl); console.log('getFile', id, dsl);
if (dsl) { const lowCodeFile = await getLowCodeFile(id);
return Promise.resolve(dsl as BlockSchema); console.log('lowCodeFile', lowCodeFile);
if (lowCodeFile.dsl) {
return Promise.resolve(lowCodeFile.dsl as BlockSchema);
} else { } else {
return Promise.reject(null); return Promise.reject(null);
} }

View File

@ -16,17 +16,17 @@
"@iframe-resizer/child": "^5.3.3", "@iframe-resizer/child": "^5.3.3",
"@sy/low-code-shared": "workspace:*", "@sy/low-code-shared": "workspace:*",
"@sy/web-vitals": "workspace:*", "@sy/web-vitals": "workspace:*",
"@vtj/core": "^0.10.5", "@vtj/core": "^0.10.6",
"@vtj/icons": "0.10.5", "@vtj/icons": "0.10.6",
"@vtj/materials": "^0.10.5", "@vtj/materials": "^0.10.6",
"@vtj/renderer": "^0.10.5", "@vtj/renderer": "^0.10.6",
"axios": "^1.8.1",
"core-js": "^3.40.0", "core-js": "^3.40.0",
"element-plus": "^2.9.4", "element-plus": "^2.9.4",
"licia-es": "^1.46.0", "licia-es": "^1.46.0",
"postmate": "^1.5.2", "postmate": "^1.5.2",
"rrweb": "2.0.0-alpha.4", "rrweb": "2.0.0-alpha.4",
"vue": "^3.5.13", "vue": "^3.5.13"
"axios": "^1.8.1"
}, },
"devDependencies": { "devDependencies": {
"@farmfe/cli": "^1.0.4", "@farmfe/cli": "^1.0.4",

791
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff