feat: 低代码文件编辑历史记录 crud 功能完成
This commit is contained in:
@@ -2,10 +2,14 @@
|
||||
import { onMounted, computed, watch } from 'vue';
|
||||
import { ElLoading } from 'element-plus';
|
||||
import Postmate from 'postmate';
|
||||
import { createRenderer } from '@vtj/renderer'
|
||||
import { getFile } from './io';
|
||||
import { createRenderer, createProvider } from '@vtj/renderer'
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
|
||||
import { LowCodeService } from './service'
|
||||
|
||||
import { getFile } from './io';
|
||||
|
||||
const lowCodeService = new LowCodeService();
|
||||
|
||||
onMounted(() => {
|
||||
const handshake = new Postmate.Model({});
|
||||
@@ -16,12 +20,10 @@ handshake.then(parent => {
|
||||
});
|
||||
|
||||
const { data: file, isFetching } = useQuery({
|
||||
queryKey: ['file', '45tncm34d'],
|
||||
queryKey: ['getFile'],
|
||||
queryFn: async () => {
|
||||
return getFile('45tncm34d');
|
||||
return getFile('45tnbgeme');
|
||||
},
|
||||
retry: 3,
|
||||
retryDelay: 2000,
|
||||
});
|
||||
|
||||
watch(isFetching, (newVal) => {
|
||||
@@ -34,6 +36,19 @@ watch(isFetching, (newVal) => {
|
||||
}
|
||||
});
|
||||
|
||||
const { provider, onReady } = createProvider({
|
||||
// runtime: 'web',
|
||||
service: lowCodeService,
|
||||
project: {
|
||||
id: '2'
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
onReady(() => {
|
||||
console.log('onReady');
|
||||
});
|
||||
|
||||
const renderer = computed(() => {
|
||||
console.log(file?.value?.dsl.id);
|
||||
if (file?.value?.dsl) {
|
||||
|
||||
@@ -2,7 +2,6 @@ import { createApp } from "vue";
|
||||
import "@sy/web-vitals";
|
||||
import { IconsPlugin } from "@vtj/icons";
|
||||
import { VueQueryPlugin } from "@tanstack/vue-query";
|
||||
// import "@sy/low-code-shared/styles/reset.css";
|
||||
|
||||
import App from "./App.vue";
|
||||
import ElementPlus from "element-plus";
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from "./file";
|
||||
export * from "./project";
|
||||
|
||||
6
apps/renderer/src/io/project.ts
Normal file
6
apps/renderer/src/io/project.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import instance from "./instance";
|
||||
|
||||
export const getProject = async (id: string) => {
|
||||
const response = await instance.get(`/api/v1/projects/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
40
apps/renderer/src/service/index.ts
Normal file
40
apps/renderer/src/service/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// @ts-nocheck
|
||||
import { type ProjectSchema, type BlockSchema, ProjectModel } from "@vtj/core";
|
||||
import { BaseService } from "@vtj/renderer";
|
||||
import { getProject, getFile as getLowCodeFile } from "@/io";
|
||||
|
||||
export class LowCodeService extends BaseService {
|
||||
public async init(project: ProjectSchema) {
|
||||
console.log("init", project);
|
||||
const remoteProject = await getProject("2");
|
||||
const model = new ProjectModel(remoteProject);
|
||||
const dsl = model.toDsl();
|
||||
return Promise.resolve(dsl);
|
||||
}
|
||||
|
||||
public saveProject(project: ProjectSchema): Promise<boolean> {
|
||||
const newProject = {
|
||||
...project,
|
||||
...Object.fromEntries(
|
||||
Object.entries(project)
|
||||
.filter(([key]) => stringifyFields.includes(key))
|
||||
.map(([key, value]) => [key, JSON.stringify(value)])
|
||||
),
|
||||
};
|
||||
updateProject("2", newProject);
|
||||
const model = new ProjectModel(project);
|
||||
storage.save(`project_${model.id}`, model.toDsl());
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
public async getFile(id: string): Promise<BlockSchema> {
|
||||
console.log("getFile", id);
|
||||
return getLowCodeFile(id).then((lowCodeFile) => {
|
||||
if (lowCodeFile.dsl) {
|
||||
return Promise.resolve(lowCodeFile.dsl as BlockSchema);
|
||||
} else {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user