chore: 渲染端只渲染发布后的 dsl
This commit is contained in:
parent
26c08e0974
commit
f63b39b818
@ -9,6 +9,9 @@ import Postmate from 'postmate';
|
||||
|
||||
import { LowCodeService } from './service';
|
||||
|
||||
// 文件加载时,清空一次 sessionStorage
|
||||
sessionStorage.clear();
|
||||
|
||||
// 响应式状态
|
||||
const renderer = ref();
|
||||
const lowCodeService = new LowCodeService();
|
||||
@ -42,7 +45,7 @@ const initPostmateHandshake = async () => {
|
||||
return model.then((parent) => {
|
||||
// 只获取 accessToken
|
||||
accessToken.value = parent.model.accessToken || '';
|
||||
localStorage.setItem('y-code-access-token', accessToken.value);
|
||||
sessionStorage.setItem('y-code-access-token', accessToken.value);
|
||||
parent.emit('renderer-ready', 'y-code-renderer is ready');
|
||||
|
||||
// 更新请求配置
|
||||
@ -69,7 +72,7 @@ const initLowCodeEngine = async () => {
|
||||
if (provider.value) return provider.value;
|
||||
|
||||
const token =
|
||||
accessToken.value || localStorage.getItem('y-code-access-token') || '';
|
||||
accessToken.value || sessionStorage.getItem('y-code-access-token') || '';
|
||||
if (token) {
|
||||
initRequestConfig(token);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ export type LowCodeFileSchema = {
|
||||
file_path?: string;
|
||||
project_id: number;
|
||||
publish: boolean;
|
||||
published_dsl: BlockSchema;
|
||||
};
|
||||
|
||||
export const getFile = async (id: string): Promise<LowCodeFileSchema> => {
|
||||
|
@ -4,22 +4,16 @@ import { getFile as getLowCodeFile, getProject } from '@/io';
|
||||
import { ProjectModel } from '@vtj/core';
|
||||
import { BaseService } from '@vtj/renderer';
|
||||
|
||||
// let initProject: ProjectModel = {};
|
||||
|
||||
export class LowCodeService extends BaseService {
|
||||
public async getFile(id: string): Promise<BlockSchema> {
|
||||
console.log('service getFile', id);
|
||||
return getLowCodeFile(id).then((lowCodeFile) => {
|
||||
return lowCodeFile.dsl
|
||||
? Promise.resolve(lowCodeFile.dsl as BlockSchema)
|
||||
return lowCodeFile.published_dsl
|
||||
? Promise.resolve(lowCodeFile.published_dsl as BlockSchema)
|
||||
: Promise.reject(new Error(`dsl 不存在, id: ${id}`));
|
||||
});
|
||||
}
|
||||
|
||||
public async init(project: ProjectSchema) {
|
||||
console.log('init', project);
|
||||
// @ts-ignore 忽略错误
|
||||
// initProject = project;
|
||||
// @ts-ignore 忽略错误
|
||||
const remoteProject = await getProject(project.id);
|
||||
console.log('remoteProject', remoteProject);
|
||||
@ -27,18 +21,4 @@ export class LowCodeService extends BaseService {
|
||||
const dsl = model.toDsl();
|
||||
return 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)]),
|
||||
// ),
|
||||
// };
|
||||
// const model = new ProjectModel(newProject);
|
||||
// // storage.save(`project_${model.id}`, model.toDsl());
|
||||
// return Promise.resolve(true);
|
||||
// }
|
||||
}
|
||||
|
@ -19,10 +19,34 @@ const initPostmate = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建包含除 accessToken 外所有参数的 URL
|
||||
const buildUrl = () => {
|
||||
const baseUrl = props.url || '';
|
||||
const urlObj = new URL(
|
||||
baseUrl.includes('://') ? baseUrl : `http://dummy${baseUrl}`,
|
||||
);
|
||||
|
||||
// 添加其他参数到 URL
|
||||
if (props.applicationId)
|
||||
urlObj.searchParams.set('applicationId', props.applicationId);
|
||||
if (props.fileId) urlObj.searchParams.set('fileId', props.fileId);
|
||||
if (props.name) urlObj.searchParams.set('name', props.name);
|
||||
if (props.projectId) urlObj.searchParams.set('projectId', props.projectId);
|
||||
|
||||
// 返回构建好的 URL,如果使用了 dummy 前缀则去掉
|
||||
return baseUrl.includes('://')
|
||||
? urlObj.toString()
|
||||
: urlObj.toString().replace('http://dummy', '');
|
||||
};
|
||||
|
||||
const finalUrl = buildUrl();
|
||||
console.log('finalUrl', finalUrl);
|
||||
|
||||
const connection = new Postmate({
|
||||
container,
|
||||
model: {
|
||||
accessToken: props.accessToken,
|
||||
// 其他参数仍然保留在 model 中,以保持兼容性
|
||||
applicationId: props.applicationId,
|
||||
fileId: props.fileId,
|
||||
name: props.name,
|
||||
@ -30,7 +54,7 @@ const initPostmate = async () => {
|
||||
url: props.url,
|
||||
},
|
||||
name: 'y-code-renderer',
|
||||
url: props.url,
|
||||
url: finalUrl,
|
||||
});
|
||||
|
||||
connection.then((child) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user