chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* project ide app 的生命周期
|
||||
* Project ide app life cycle
|
||||
*/
|
||||
import { injectable, inject } from 'inversify';
|
||||
import {
|
||||
@@ -45,15 +45,15 @@ export class AppContribution implements LifecycleContribution {
|
||||
onStartedEmitter = new Emitter<void>();
|
||||
onStarted = this.onStartedEmitter.event;
|
||||
|
||||
// ide 初始化完成,可执行业务逻辑的时机
|
||||
// When IDE initialization is complete and business logic can be executed
|
||||
onStart() {
|
||||
// 更新项目信息
|
||||
// Update project information
|
||||
this.projectInfoService.init();
|
||||
|
||||
// // 打开 url 上携带的资源
|
||||
// Open the resources carried on the URL
|
||||
this.openURIResourceService.open();
|
||||
this.openURIResourceService.listen();
|
||||
// 订阅变化事件
|
||||
// Subscribe to change events
|
||||
this.widgetEventService.listen();
|
||||
// listen layout store
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
@@ -63,7 +63,7 @@ export class AppContribution implements LifecycleContribution {
|
||||
}
|
||||
|
||||
onDispose() {
|
||||
// 销毁所有的订阅
|
||||
// Destroy all subscriptions
|
||||
this.widgetEventService.dispose();
|
||||
this.openURIResourceService.dispose();
|
||||
this.onStartedEmitter.dispose();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* 承载 project ide app 业务逻辑的插件
|
||||
* Plugin to host the business logic of the project ide app
|
||||
*/
|
||||
import { type NavigateFunction } from 'react-router-dom';
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* 业务层数据持久化
|
||||
* Business layer data persistence
|
||||
*/
|
||||
import { isPlainObject } from 'lodash-es';
|
||||
import { inject, injectable } from 'inversify';
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
import { saveLayoutData, readLayoutData } from './utils/layout-store';
|
||||
|
||||
/**
|
||||
* 被持久化的 widget 可能是普通的 widget 也可能是 project 特定的 widget
|
||||
* The persistent widget may be a normal widget or a project-specific widget.
|
||||
*/
|
||||
type LayoutWidget = ReactWidget | ProjectIDEWidget;
|
||||
|
||||
@@ -45,7 +45,7 @@ interface LayoutWidgetData {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是 ProjectIDEWidget
|
||||
* Determine if it is a ProjectIDEWidget
|
||||
*/
|
||||
const isProjectIDEWidget = (w: LayoutWidget): w is ProjectIDEWidget =>
|
||||
!!(w as ProjectIDEWidget).context;
|
||||
@@ -63,13 +63,13 @@ export class LayoutRestoreService {
|
||||
private optionsService: OptionsService;
|
||||
|
||||
/**
|
||||
* 本地数据是否生效
|
||||
* Is the local data valid?
|
||||
*/
|
||||
private _openFirstWorkflow = false;
|
||||
|
||||
/**
|
||||
* 是否启用持久化,暂时不可配置,若开发过程中出现问题,可以关闭
|
||||
* 此开关只会开关是否在初始化时恢复布局数据
|
||||
* Whether to enable persistence is temporarily unconfigurable. If there is a problem during development, it can be turned off.
|
||||
* This switch only switches whether to restore layout data during initialization
|
||||
*/
|
||||
private enabled = true;
|
||||
// private enabled = false;
|
||||
@@ -93,7 +93,7 @@ export class LayoutRestoreService {
|
||||
);
|
||||
}
|
||||
async restoreLayout() {
|
||||
// 无论是否需要持久化,这一步必须要做
|
||||
// This step must be done whether persistence is required or not
|
||||
await this.addSidebarWidget();
|
||||
if (this.enabled) {
|
||||
const data = await readLayoutData(
|
||||
@@ -111,15 +111,15 @@ export class LayoutRestoreService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成当前 ide 的布局数据
|
||||
* Generate layout data for the current IDE
|
||||
*/
|
||||
getLayoutData() {
|
||||
const data: Record<string, any> = {};
|
||||
const { primarySidebar, mainPanel } = this.applicationShell;
|
||||
|
||||
/**
|
||||
* primarySidebar 数据
|
||||
* 在当前特化业务下,primarySidebar 只可能打开特定的 widget,所以这里无需存储通用的 widgets 数据
|
||||
* Primary Sidebar Data
|
||||
* In the current specialized business, primarySidebar can only open specific widgets, so there is no need to store general widgets data here
|
||||
*/
|
||||
data.primarySidebar = {
|
||||
isHidden: !!primarySidebar?.isHidden,
|
||||
@@ -134,10 +134,10 @@ export class LayoutRestoreService {
|
||||
const { primarySidebar, mainPanel } = data || {};
|
||||
|
||||
/**
|
||||
* primarySidebar 面板初始化
|
||||
* 1. 数据不存在时,说明没有本地数据,需要默认打开
|
||||
* 2. 数据存在,且 hidden 为假,默认打开
|
||||
* 3. 其他情况不打开
|
||||
* PrimarySidebar panel initialization
|
||||
* 1. When the data does not exist, it means that there is no local data and needs to be opened by default.
|
||||
* 2. The data exists, and hidden is false, open by default
|
||||
* 3. Do not open in other cases
|
||||
*/
|
||||
if (!primarySidebar || !primarySidebar.isHidden) {
|
||||
this.applicationShell.primarySidebar.show();
|
||||
@@ -147,21 +147,21 @@ export class LayoutRestoreService {
|
||||
|
||||
if (mainPanel) {
|
||||
const mainPanelData = await this.widgetsParseBFS(mainPanel);
|
||||
// 如果初始化的时候没有 widget 打开,默认打开一个。
|
||||
// If no widget is opened when initializing, one is opened by default.
|
||||
// widget: tab
|
||||
// children: 分屏
|
||||
// Children: split screen
|
||||
const { main } = mainPanelData || {};
|
||||
if (!main?.widgets?.length && !main?.children?.length) {
|
||||
this._openFirstWorkflow = true;
|
||||
}
|
||||
this.applicationShell.mainPanel.restoreLayout(mainPanelData);
|
||||
// FlowDockPanel 需要挂载监听
|
||||
// FlowDockPanel requires a monitor to be mounted
|
||||
this.applicationShell.mainPanel.initWidgets();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂载默认的 sidebar widget
|
||||
* Mount the default sidebar widget
|
||||
*/
|
||||
async addSidebarWidget() {
|
||||
const widget = await this.widgetParse({
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* project ide app 初始化时打开 url 上携带的资源
|
||||
* Open resources carried on the url when the project ide app is initialized
|
||||
*/
|
||||
import { inject, injectable } from 'inversify';
|
||||
import {
|
||||
@@ -47,20 +47,20 @@ export class OpenURIResourceService {
|
||||
private disposable = new DisposableCollection();
|
||||
|
||||
/**
|
||||
* 针对 1.直接打开;2.外部系统跳转的场景,请勿在此添加其他副作用逻辑
|
||||
* For scenarios where 1. Open directly; 2. External system jumps, please do not add other side effect logic here.
|
||||
*/
|
||||
open() {
|
||||
const { resourceType } = getResourceByPathname(window.location.pathname);
|
||||
// ui-builder
|
||||
if (resourceType === UI_BUILDER_URI.displayName) {
|
||||
this.openDesign();
|
||||
// 展示默认页
|
||||
// Show default page
|
||||
this.tryOpenDefault();
|
||||
} else {
|
||||
const path = getURIPathByPathname(window.location.pathname);
|
||||
if (!path || path.startsWith(MAIN_PANEL_DEFAULT_URI.displayName)) {
|
||||
this.tryOpenDefault();
|
||||
// 路由不匹配时需要手动激活 currentWidget
|
||||
// When the routes do not match, you need to manually activate currentWidget.
|
||||
if (this.applicationShell.mainPanel.currentTitle?.owner) {
|
||||
this.applicationShell.setCurrentWidget(
|
||||
this.applicationShell.mainPanel?.currentTitle?.owner as ReactWidget,
|
||||
|
||||
@@ -66,7 +66,7 @@ export class ProjectInfoService {
|
||||
|
||||
init() {
|
||||
this.updateProjectInfo().catch(() => {
|
||||
// project 信息接口报错跳转到兜底页
|
||||
// Project information interface error Jump to default page
|
||||
this.errorService.toErrorPage();
|
||||
});
|
||||
if (!IS_OPEN_SOURCE) {
|
||||
@@ -80,12 +80,12 @@ export class ProjectInfoService {
|
||||
const res = await intelligenceApi.DraftProjectInnerTaskList({
|
||||
project_id: this.optionsService.projectId,
|
||||
});
|
||||
// 和后端确认,默认 task_list 长度为 1.
|
||||
// 如果有长度为 2 没有都住的场景,用户刷新后也可以获取到下一个。
|
||||
// And backend confirmation, the default task_list length is 1.
|
||||
// If there is a scene with a length of 2 that is not lived, the user can also get the next one after refreshing.
|
||||
const { task_list } = res.data || {};
|
||||
const taskId = task_list?.[0]?.task_id;
|
||||
if (taskId) {
|
||||
// 请求轮询接口获取基础信息
|
||||
// Request polling interface to obtain basic information
|
||||
const { task_detail } = await PluginDevelopApi.ResourceCopyDetail({
|
||||
task_id: taskId,
|
||||
});
|
||||
@@ -99,7 +99,7 @@ export class ProjectInfoService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开 project 页面需要上报,后端才能筛选出最近打开
|
||||
* To open the project page, you need to report it, and the backend can filter out the most recently opened.
|
||||
*/
|
||||
reportUserBehavior() {
|
||||
PlaygroundApi.ReportUserBehavior({
|
||||
@@ -111,8 +111,8 @@ export class ProjectInfoService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 单向请求接口
|
||||
* 提前唤醒 ide 插件,无需消费返回值
|
||||
* one-way request interface
|
||||
* Wake up the ide plugin in advance, no need to consume the return value
|
||||
*/
|
||||
wakeUpPlugin() {
|
||||
PluginDevelopApi.WakeupIdePlugin({
|
||||
|
||||
@@ -17,31 +17,31 @@
|
||||
import { Dexie, type EntityTable } from 'dexie';
|
||||
|
||||
/**
|
||||
* 布局数据
|
||||
* layout data
|
||||
*/
|
||||
interface DBLayoutRow {
|
||||
/**
|
||||
* 自增 id
|
||||
* autoincrement id
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* 空间 id
|
||||
* Space ID
|
||||
*/
|
||||
spaceId: string;
|
||||
/**
|
||||
* 项目 id
|
||||
* Project ID
|
||||
*/
|
||||
projectId: string;
|
||||
/**
|
||||
* 时间戳
|
||||
* timestamp
|
||||
*/
|
||||
timestamp: number;
|
||||
/**
|
||||
* 数据版本
|
||||
* data version
|
||||
*/
|
||||
version: number;
|
||||
/**
|
||||
* 数据
|
||||
* data
|
||||
*/
|
||||
data: string;
|
||||
}
|
||||
@@ -51,20 +51,20 @@ type DBLayout = Dexie & {
|
||||
};
|
||||
|
||||
/**
|
||||
* 持久化储存形式的版本号
|
||||
* Version number of persistent storage form
|
||||
*/
|
||||
const VERSION = 3;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
* database name
|
||||
*/
|
||||
const DB_NAME = 'CozProjectIDELayoutData';
|
||||
/**
|
||||
* 数据库版本
|
||||
* database version
|
||||
*/
|
||||
const DB_VERSION = 1;
|
||||
/**
|
||||
* 数据有效期
|
||||
* Data valid period
|
||||
*/
|
||||
const DB_EXPIRE = 1000 * 60 * 60 * 24 * 30;
|
||||
|
||||
@@ -74,7 +74,7 @@ const isExpired = (row: DBLayoutRow) =>
|
||||
row.timestamp < Date.now() - DB_EXPIRE || row.version !== VERSION;
|
||||
|
||||
/**
|
||||
* 获取数据库实例
|
||||
* Get the database instance
|
||||
*/
|
||||
const getDB = () => {
|
||||
if (!cache) {
|
||||
@@ -155,12 +155,12 @@ const deleteDataLS = (spaceId: string, projectId: string) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存布局数据
|
||||
* 注:调用时机为组件销毁或浏览器关闭时,故不可用异步函数
|
||||
* Save layout data
|
||||
* Note: The calling time is when the component is destroyed or the browser is closed, so asynchronous functions cannot be used
|
||||
*/
|
||||
const saveLayoutData = (spaceId: string, projectId: string, data: any) => {
|
||||
try {
|
||||
// 无论是什么值都需要序列化成字符串
|
||||
// No matter what the value is, it needs to be serialized into a string.
|
||||
const str = JSON.stringify(data);
|
||||
const row = {
|
||||
data: str,
|
||||
@@ -175,13 +175,13 @@ const saveLayoutData = (spaceId: string, projectId: string, data: any) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取布局数据
|
||||
* 会同时从 indexedDB 和 localStorage 中读取数据,会有以下几种情况:
|
||||
* 1. localStorage 无数据,返回 indexedDB 数据
|
||||
* 2. localStorage 有数据
|
||||
* 2.1. indexedDB 无数据,更新 indexedDB 数据,删除 localStorage 数据,返回 indexedDB 数据
|
||||
* 2.2. indexedDB 有数据,比较时间戳。返回最近的数据,删除 localStorage 数据
|
||||
* 2.2.1. 若 localStorage 数据较新,则更新到 indexedDB 中
|
||||
* Read layout data
|
||||
* Data will be read from indexedDB and localStorage simultaneously, in the following cases:
|
||||
* 1. localStorage no data, return indexedDB data
|
||||
* 2. localStorage has data
|
||||
* 2.1. indexedDB no data, update indexedDB data, delete localStorage data, return indexedDB data
|
||||
* 2.2. IndexedDB has data, compare timestamps. Return recent data, delete localStorage data
|
||||
* 2.2.1. If localStorage data is new, update to indexedDB
|
||||
*/
|
||||
const readLayoutData = async (spaceId: string, projectId: string) => {
|
||||
let str;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* 监听 widget 事件而需要执行的业务逻辑
|
||||
* Business logic that needs to be executed to listen for widget events
|
||||
*/
|
||||
import { inject, injectable } from 'inversify';
|
||||
import {
|
||||
@@ -58,14 +58,14 @@ export class WidgetEventService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 有 widget 打开时需要关闭默认页
|
||||
* 2. 关闭所有 widget 时需要打开默认页
|
||||
* 1. You need to close the default page when a widget is opened
|
||||
* 2. When closing all widgets, you need to open the default page
|
||||
*/
|
||||
toggleDefaultWidget(widget) {
|
||||
if ((widget as ReactWidget)?.uri) {
|
||||
const widgetUri = widget?.uri;
|
||||
if (widgetUri.displayName !== 'default') {
|
||||
// 关闭默认的 widget
|
||||
// Close the default widget
|
||||
const defaultWidget = this.widgetManager.getWidgetFromURI(
|
||||
MAIN_PANEL_DEFAULT_URI,
|
||||
);
|
||||
@@ -78,12 +78,12 @@ export class WidgetEventService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步切换资源 tab 时的 url 变化
|
||||
* Synchronize url changes when switching resource tabs
|
||||
*/
|
||||
syncURL(widget) {
|
||||
if (widget) {
|
||||
const widgetUri = widget?.uri;
|
||||
// 默认页无需同步 url
|
||||
// Default page does not need to synchronize URLs
|
||||
if (compareURI(widgetUri, MAIN_PANEL_DEFAULT_URI)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user