mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-10-15 12:15:32 +00:00
refactor: 按 sample_in_harmonyos 多层模块化架构重构工程结构
- 新增 common/ 公共模块:模型、服务、组件、常量 - 新增 features/ 功能模块:graph(星图)、chat(聊天)、settings(设置)、commonbusiness - 新增 products/phone 产品入口层:EntryAbility + Index + MainPage - Index.ets 简化为纯路由入口,TabNavigation 移至 MainPage 统一管理 - 更新 build-profile.json5 注册所有新模块 - 迁移原始 entry/ 代码到分层架构,保持功能完整
This commit is contained in:
8
products/phone/build-profile.json5
Normal file
8
products/phone/build-profile.json5
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
}
|
||||
]
|
||||
}
|
||||
14
products/phone/oh-package.json5
Normal file
14
products/phone/oh-package.json5
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@ohos/phone",
|
||||
"version": "1.0.0",
|
||||
"description": "TrulyMEM phone product entry",
|
||||
"main": "Index.ets",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"@ohos/common": "file:../../common",
|
||||
"@ohos/graph": "file:../../features/graph",
|
||||
"@ohos/chat": "file:../../features/chat",
|
||||
"@ohos/settings": "file:../../features/settings"
|
||||
}
|
||||
}
|
||||
35
products/phone/src/main/ets/entryability/EntryAbility.ets
Normal file
35
products/phone/src/main/ets/entryability/EntryAbility.ets
Normal file
@ -0,0 +1,35 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import window from '@ohos.window';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
console.info('EntryAbility onCreate');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.info('EntryAbility onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
console.info('EntryAbility onWindowStageCreate');
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
console.info('EntryAbility onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
console.info('EntryAbility onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
console.info('EntryAbility onBackground');
|
||||
}
|
||||
}
|
||||
125
products/phone/src/main/ets/pages/Index.ets
Normal file
125
products/phone/src/main/ets/pages/Index.ets
Normal file
@ -0,0 +1,125 @@
|
||||
import { GraphDatabase } from '@ohos/common';
|
||||
import { GraphPage } from '@ohos/graph';
|
||||
import { ChatPage } from '@ohos/chat';
|
||||
import { SettingsPage } from '@ohos/settings';
|
||||
import { ImmersiveTabNavigation } from '@ohos/common';
|
||||
import display from '@ohos.display';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State currentIndex: number = 0;
|
||||
private db: GraphDatabase = new GraphDatabase();
|
||||
private displayCallback?: Callback<number>;
|
||||
|
||||
aboutToAppear() {
|
||||
this.db.init(getContext(this));
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
if (this.displayCallback) {
|
||||
display.off('change', this.displayCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
tabContentBuilder() {
|
||||
Column() {
|
||||
if (this.currentIndex === 0) {
|
||||
MainPage({ db: this.db })
|
||||
} else {
|
||||
SettingsPage()
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
|
||||
build() {
|
||||
Stack() {
|
||||
ImmersiveTabNavigation({
|
||||
currentIndex: this.currentIndex,
|
||||
onTabChange: (index: number): void => { this.currentIndex = index; },
|
||||
contentBuilder: (): void => { this.tabContentBuilder(); }
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct MainPage {
|
||||
@Prop db: GraphDatabase;
|
||||
@State isWide: boolean = false;
|
||||
|
||||
aboutToAppear() {
|
||||
this.updateBreakpoint();
|
||||
try {
|
||||
display.on('change', () => {
|
||||
this.updateBreakpoint();
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('display.on error: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
private updateBreakpoint(): void {
|
||||
try {
|
||||
const defaultWindow = display.getDefaultDisplaySync();
|
||||
this.isWide = defaultWindow.width > 520;
|
||||
} catch (e) {
|
||||
console.error('updateBreakpoint error: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
if (this.isWide) {
|
||||
Row() {
|
||||
GraphPage({ db: this.db })
|
||||
.layoutWeight(1)
|
||||
.height('100%')
|
||||
.clip(true)
|
||||
.borderRadius(12)
|
||||
.margin({ left: 4, right: 2 })
|
||||
|
||||
ChatPage({ db: this.db })
|
||||
.width(380)
|
||||
.height('100%')
|
||||
.clip(true)
|
||||
.borderRadius(12)
|
||||
.margin({ left: 2, right: 4 })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.padding(4)
|
||||
.backgroundColor('#1A1B2E')
|
||||
.backgroundBlurStyle(BlurStyle.Regular)
|
||||
} else {
|
||||
Column() {
|
||||
Stack() {
|
||||
GraphPage({ db: this.db })
|
||||
}
|
||||
.height('55%')
|
||||
.width('100%')
|
||||
.clip(true)
|
||||
.borderRadius(12)
|
||||
.margin({ top: 2, left: 4, right: 4, bottom: 2 })
|
||||
|
||||
Stack() {
|
||||
ChatPage({ db: this.db })
|
||||
}
|
||||
.height('45%')
|
||||
.width('100%')
|
||||
.clip(true)
|
||||
.borderRadius(12)
|
||||
.margin({ top: 2, left: 4, right: 4, bottom: 2 })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.padding(2)
|
||||
.backgroundColor('#1A1B2E')
|
||||
.backgroundBlurStyle(BlurStyle.Regular)
|
||||
}
|
||||
}
|
||||
}
|
||||
46
products/phone/src/main/module.json5
Normal file
46
products/phone/src/main/module.json5
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "phone",
|
||||
"type": "entry",
|
||||
"description": "TrulyMEM phone entry module",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:layered_image",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"ohos.want.action.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.INTERNET"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_NETWORK_INFO"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user