mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-10-15 12:15:32 +00:00
refactor: 工程标准化 — 组件提取、废弃API清理、console清零
- ChatPage/GraphPage/SettingsPage 拆分为独立子组件 - MainPage 接入 ImmersiveTabNavigation 玻璃拟态导航 - EntryAbility console.* 全替换为 defaultLogger - SplashPage replaceUrl 废弃 API 迁移到 UIContext Router - common/Index.ets 双通道导出 Logger/defaultLogger - 删除 dead code (entry/, commonbusiness/, trulymem-core/) - 全工程 0 console.*,BUILD SUCCESSFUL
This commit is contained in:
@ -1,5 +1,17 @@
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
"arkOptions": {
|
||||
"runtimeOnly": {
|
||||
"packages": [
|
||||
"@ohos/common",
|
||||
"@ohos/graph",
|
||||
"@ohos/chat",
|
||||
"@ohos/settings"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
|
||||
6
products/phone/hvigorfile.ts
Normal file
6
products/phone/hvigorfile.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks,
|
||||
plugins: []
|
||||
};
|
||||
49
products/phone/oh-package-lock.json5
Normal file
49
products/phone/oh-package-lock.json5
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"meta": {
|
||||
"stableOrder": true,
|
||||
"enableUnifiedLockfile": false
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@ohos/chat@../../features/chat": "@ohos/chat@../../features/chat",
|
||||
"@ohos/common@../../common": "@ohos/common@../../common",
|
||||
"@ohos/graph@../../features/graph": "@ohos/graph@../../features/graph",
|
||||
"@ohos/settings@../../features/settings": "@ohos/settings@../../features/settings"
|
||||
},
|
||||
"packages": {
|
||||
"@ohos/chat@../../features/chat": {
|
||||
"name": "@ohos/chat",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../../features/chat",
|
||||
"registryType": "local",
|
||||
"dependencies": {
|
||||
"@ohos/common": "file:../../common"
|
||||
}
|
||||
},
|
||||
"@ohos/common@../../common": {
|
||||
"name": "@ohos/common",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../../common",
|
||||
"registryType": "local"
|
||||
},
|
||||
"@ohos/graph@../../features/graph": {
|
||||
"name": "@ohos/graph",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../../features/graph",
|
||||
"registryType": "local",
|
||||
"dependencies": {
|
||||
"@ohos/common": "file:../../common"
|
||||
}
|
||||
},
|
||||
"@ohos/settings@../../features/settings": {
|
||||
"name": "@ohos/settings",
|
||||
"version": "1.0.0",
|
||||
"resolved": "../../features/settings",
|
||||
"registryType": "local",
|
||||
"dependencies": {
|
||||
"@ohos/common": "file:../../common"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
products/phone/oh_modules/@ohos/chat
Symbolic link
1
products/phone/oh_modules/@ohos/chat
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../features/chat
|
||||
1
products/phone/oh_modules/@ohos/common
Symbolic link
1
products/phone/oh_modules/@ohos/common
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../common
|
||||
1
products/phone/oh_modules/@ohos/graph
Symbolic link
1
products/phone/oh_modules/@ohos/graph
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../features/graph
|
||||
1
products/phone/oh_modules/@ohos/settings
Symbolic link
1
products/phone/oh_modules/@ohos/settings
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../features/settings
|
||||
@ -1,14 +1,15 @@
|
||||
import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { defaultLogger } from '@ohos/common';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want: Want, param: AbilityConstant.LaunchParam): void {
|
||||
console.info('EntryAbility onCreate');
|
||||
defaultLogger.info('EntryAbility onCreate');
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
console.info('EntryAbility onDestroy');
|
||||
defaultLogger.info('EntryAbility onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
@ -16,7 +17,7 @@ export default class EntryAbility extends UIAbility {
|
||||
try {
|
||||
windowClass.setWindowBackgroundColor('#00000000');
|
||||
} catch (e) {
|
||||
console.error('Failed to set background color: ' + (e as BusinessError).message);
|
||||
defaultLogger.error('Failed to set background color: ' + (e as BusinessError).message);
|
||||
}
|
||||
try {
|
||||
windowClass.setWindowSystemBarProperties({
|
||||
@ -24,28 +25,28 @@ export default class EntryAbility extends UIAbility {
|
||||
navigationBarColor: '#00000000'
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to set system bar properties: ' + (e as BusinessError).message);
|
||||
defaultLogger.error('Failed to set system bar properties: ' + (e as BusinessError).message);
|
||||
}
|
||||
|
||||
console.info('EntryAbility onWindowStageCreate');
|
||||
defaultLogger.info('EntryAbility onWindowStageCreate');
|
||||
windowStage.loadContent('pages/SplashPage', (err, data) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to load the content. Cause: ' + JSON.stringify(err));
|
||||
defaultLogger.error('Failed to load the content. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
|
||||
defaultLogger.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
console.info('EntryAbility onWindowStageDestroy');
|
||||
defaultLogger.info('EntryAbility onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
console.info('EntryAbility onForeground');
|
||||
defaultLogger.info('EntryAbility onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
console.info('EntryAbility onBackground');
|
||||
defaultLogger.info('EntryAbility onBackground');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import { GraphDatabase } from '@ohos/common';
|
||||
import { GraphDatabase, Logger } from '@ohos/common';
|
||||
import { MainPage } from './MainPage';
|
||||
import display from '@ohos.display';
|
||||
|
||||
@ -9,14 +9,18 @@ struct Index {
|
||||
private displayCallback?: Callback<number>;
|
||||
|
||||
aboutToAppear() {
|
||||
this.db.init(getContext(this));
|
||||
try {
|
||||
this.displayCallback = (size: number): void => {
|
||||
};
|
||||
display.on('change', this.displayCallback);
|
||||
} catch (e) {
|
||||
console.error('display.on error: ' + JSON.stringify(e));
|
||||
const ctx = this.getUIContext()?.getHostContext();
|
||||
if (ctx) {
|
||||
this.db.init(ctx);
|
||||
}
|
||||
// TODO: display.on('change') API 在 API 23 中已废弃,应替换为窗口尺寸监听
|
||||
// 当前保留以兼容旧代码,后续应使用 window.on('windowSizeChange') 或断点系统替代
|
||||
// try {
|
||||
// this.displayCallback = (size: number): void => { };
|
||||
// display.on('change', this.displayCallback);
|
||||
// } catch (e) {
|
||||
// Logger.error('display.on error: ' + JSON.stringify(e));
|
||||
// }
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
@ -26,6 +30,12 @@ struct Index {
|
||||
}
|
||||
|
||||
build() {
|
||||
MainPage({ db: this.db }).width('100%').height('100%');
|
||||
Column() {
|
||||
MainPage({ db: this.db })
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,22 +1,26 @@
|
||||
import { GraphDatabase } from '@ohos/common';
|
||||
import { GraphDatabase, Logger, ImmersiveTabNavigation } from '@ohos/common';
|
||||
import { GraphPage } from '@ohos/graph';
|
||||
import { ChatPage } from '@ohos/chat';
|
||||
import { SettingsPage } from '@ohos/settings';
|
||||
import display from '@ohos.display';
|
||||
|
||||
@Builder
|
||||
export function MainPageBuilder() {
|
||||
MainPage({ db: new GraphDatabase() })
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct MainPage {
|
||||
@Prop db: GraphDatabase;
|
||||
@State isWide: boolean = false;
|
||||
@State currentIndex: number = 0;
|
||||
private tabController: TabsController = new TabsController();
|
||||
|
||||
aboutToAppear() {
|
||||
this.updateBreakpoint();
|
||||
try {
|
||||
display.on('change', () => { this.updateBreakpoint(); });
|
||||
} catch (e) {
|
||||
console.error('display.on error: ' + JSON.stringify(e));
|
||||
Logger.error('display.on error: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,82 +29,77 @@ export struct MainPage {
|
||||
const defaultWindow = display.getDefaultDisplaySync();
|
||||
this.isWide = defaultWindow.width > 520;
|
||||
} catch (e) {
|
||||
console.error('updateBreakpoint error: ' + JSON.stringify(e));
|
||||
Logger.error('updateBreakpoint error: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Builder
|
||||
TabContentsBuilder() {
|
||||
TabContent() {
|
||||
if (this.isWide) {
|
||||
Row() {
|
||||
GraphPage({ db: this.db })
|
||||
.layoutWeight(1)
|
||||
.height('100%')
|
||||
.clip(true)
|
||||
.borderRadius(12)
|
||||
.margin({ left: 4, right: 2 })
|
||||
@Builder
|
||||
TrulyMEMContent() {
|
||||
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')
|
||||
} else {
|
||||
Column() {
|
||||
Stack() { GraphPage({ db: this.db }) }
|
||||
.height('55%')
|
||||
.width('100%')
|
||||
.clip(true)
|
||||
.borderRadius(12)
|
||||
.margin({ top: 2, left: 4, right: 4, bottom: 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')
|
||||
} 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')
|
||||
}
|
||||
}
|
||||
.tabBar(this.bottomTabBarStyle('TrulyMEM', '\ue8b6'))
|
||||
|
||||
TabContent() {
|
||||
SettingsPage()
|
||||
}
|
||||
.tabBar(this.bottomTabBarStyle('设置', '\ue8b8'))
|
||||
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')
|
||||
}
|
||||
}
|
||||
|
||||
private bottomTabBarStyle(title: string, icon: string): BottomTabBarStyle {
|
||||
return new BottomTabBarStyle({
|
||||
normal: new SymbolGlyphModifier(icon)
|
||||
}, title)
|
||||
.padding({ bottom: 4 });
|
||||
}
|
||||
@Builder
|
||||
SettingsContent() {
|
||||
SettingsPage()
|
||||
}
|
||||
|
||||
build() {
|
||||
Tabs({ controller: this.tabController, index: this.currentIndex }) {
|
||||
this.TabContentsBuilder()
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('#0A0A1A')
|
||||
.barPosition(BarPosition.End)
|
||||
.scrollable(false)
|
||||
.animationMode(AnimationMode.NO_ANIMATION)
|
||||
.onChange((index: number) => {
|
||||
this.currentIndex = index;
|
||||
})
|
||||
@Builder
|
||||
TabContentBuilder() {
|
||||
if (this.currentIndex === 0) {
|
||||
this.TrulyMEMContent()
|
||||
} else {
|
||||
this.SettingsContent()
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
ImmersiveTabNavigation({
|
||||
contentBuilder: this.TabContentBuilder,
|
||||
onTabChange: (index: number) => {
|
||||
this.currentIndex = index;
|
||||
}
|
||||
})
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,15 @@
|
||||
import router from '@ohos.router';
|
||||
import { PromptAction } from '@kit.ArkUI';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct SplashPage {
|
||||
aboutToAppear() {
|
||||
setTimeout(() => {
|
||||
router.replaceUrl({ url: 'pages/Index' });
|
||||
const uiContext = this.getUIContext();
|
||||
if (uiContext) {
|
||||
const router = uiContext.getRouter();
|
||||
router.replaceUrl({ url: 'pages/Index' });
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
||||
@ -12,12 +12,12 @@
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"routerMap": "$profile:router_map",
|
||||
"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",
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#0A0A1A"
|
||||
}
|
||||
]
|
||||
}
|
||||
28
products/phone/src/main/resources/base/element/string.json
Normal file
28
products/phone/src/main/resources/base/element/string.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "TrulyMEM"
|
||||
},
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "TrulyMEM Phone Module"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "TrulyMEM"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "TrulyMEM Entry Ability"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_label",
|
||||
"value": "TrulyMEM"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_desc",
|
||||
"value": "TrulyMEM Main Ability"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
{"layered": true, "background": ":startIcon", "foreground": ":startIcon"}
|
||||
BIN
products/phone/src/main/resources/base/media/startIcon.png
Normal file
BIN
products/phone/src/main/resources/base/media/startIcon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 B |
@ -1,7 +1,6 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/SplashPage",
|
||||
"pages/MainPage",
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
{
|
||||
"routerMap": [
|
||||
{
|
||||
"name": "MainPage",
|
||||
"pageSourceFile": "src/main/ets/pages/MainPage.ets",
|
||||
"buildFunction": "MainPageBuilder"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user