diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..d2ff201 --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/app/AppScope/app.json5 b/app/AppScope/app.json5 new file mode 100644 index 0000000..e33fbf1 --- /dev/null +++ b/app/AppScope/app.json5 @@ -0,0 +1,11 @@ +{ + "app": { + "bundleName": "com.xiangsilian.app", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "buildVersion": "1", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/app/AppScope/resources/base/element/string.json b/app/AppScope/resources/base/element/string.json new file mode 100644 index 0000000..198f1e7 --- /dev/null +++ b/app/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "app" + } + ] +} diff --git a/app/AppScope/resources/base/media/background.png b/app/AppScope/resources/base/media/background.png new file mode 100644 index 0000000..923f2b3 Binary files /dev/null and b/app/AppScope/resources/base/media/background.png differ diff --git a/app/AppScope/resources/base/media/foreground.png b/app/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000..eb94275 Binary files /dev/null and b/app/AppScope/resources/base/media/foreground.png differ diff --git a/app/AppScope/resources/base/media/layered_image.json b/app/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000..fb49920 --- /dev/null +++ b/app/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/app/README.md b/app/README.md new file mode 100644 index 0000000..cedf615 --- /dev/null +++ b/app/README.md @@ -0,0 +1,26 @@ +# 美搭 HarmonyOS App(ArkTS) + +- 模板:DevEco Studio 6.1 空 Ability 工程;API `6.1.1(24)`,`runtimeOS: HarmonyOS`,`bundleName: com.xiangsilian.app` +- 后端:`meida_backend`(WSL)。本地开发默认 `http://127.0.0.1:8000`(模拟器可用;**真机连开发机要在登录页改成局域网 IP**) +- 登录通道(V1 骨架):dev-token(后端 `DEV_AUTH_ENABLED=true` 本地可用);华为账号/短信为后续任务 + +## 命令行构建(Agent/CI 用的门禁) + +```bash +cd G:/meida/app +export DEVECO_SDK_HOME="C:/Program Files/Huawei/DevEco Studio/sdk" +"C:/Program Files/Huawei/DevEco Studio/tools/node/node.exe" \ + "C:/Program Files/Huawei/DevEco Studio/tools/hvigor/bin/hvigorw.js" \ + --mode module -p module=entry@default assembleHap --analyze=false --daemon=false +``` + +`BUILD SUCCESSFUL` 即门禁通过(未签名 HAP 正常——签名等 AGC 证书)。运行/调试用 DevEco Studio 打开本工程点 Run(模拟器或真机,真机需先配签名)。 + +## 代码约定 + +- `ets/core/`:网络与会话地基(ApiClient/AuthStore/ContextHolder/ApiTypes)——**共享层,改动需全量构建验证** +- `ets/pages/`:页面。**页面间跳转一律 `router.pushUrl({url: 'pages/Xxx'})` 路径方式,禁止 import 其它页面**(并行开发的冲突隔离约定) +- 组件级复用放 `ets/components/`(各自任务目录内自建子目录) +- 文案:骨架期中文硬编码即可(i18n 后置);错误提示只 catch `ApiError`,用其 `message/hint`(后端文案已保证无价格字样) +- 状态管理:页面内 `@State`;跨页少量状态走 `AppStorage` +- 不引第三方 ohpm 包(保持零依赖,后续按需评估) diff --git a/app/build-profile.json5 b/app/build-profile.json5 new file mode 100644 index 0000000..0cb46cc --- /dev/null +++ b/app/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.1.1(24)", + "compatibleSdkVersion": "6.1.1(24)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/app/code-linter.json5 b/app/code-linter.json5 new file mode 100644 index 0000000..073990f --- /dev/null +++ b/app/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/app/entry/.gitignore b/app/entry/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/app/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/app/entry/build-profile.json5 b/app/entry/build-profile.json5 new file mode 100644 index 0000000..6bd6457 --- /dev/null +++ b/app/entry/build-profile.json5 @@ -0,0 +1,33 @@ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/app/entry/hvigorfile.ts b/app/entry/hvigorfile.ts new file mode 100644 index 0000000..b0e3a1a --- /dev/null +++ b/app/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/app/entry/obfuscation-rules.txt b/app/entry/obfuscation-rules.txt new file mode 100644 index 0000000..1e7e54e --- /dev/null +++ b/app/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/source-obfuscation + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/app/entry/oh-package.json5 b/app/entry/oh-package.json5 new file mode 100644 index 0000000..248c3b7 --- /dev/null +++ b/app/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/app/entry/src/main/ets/core/ApiClient.ets b/app/entry/src/main/ets/core/ApiClient.ets new file mode 100644 index 0000000..e8a9ccd --- /dev/null +++ b/app/entry/src/main/ets/core/ApiClient.ets @@ -0,0 +1,100 @@ +/** + * 极简 HTTP 客户端:统一信封解包 + 401 自动刷新重试一次。 + * + * ArkTS 严格模式约束(本文件全部遵守,FE 任务照此风格): + * - 请求体一律 Record(具名字面量),不用内联对象类型 + * - throw 只抛 ApiError(Error 子类),未知异常先包装 + * - code!=0 一律抛 ApiError;UI 层只 catch ApiError + */ + +import http from '@ohos.net.http' +import { ApiEnvelope, ApiError } from './ApiTypes' +import { AuthStore } from './AuthStore' + +const AUTH_EXPIRED_CODES: number[] = [40100, 40101, 40102] + +export class ApiClient { + static async get(path: string): Promise { + return ApiClient.request(http.RequestMethod.GET, path, undefined) + } + + static async post(path: string, body?: Record): Promise { + return ApiClient.request(http.RequestMethod.POST, path, body) + } + + /** 不带 token、不触发自动刷新(AuthStore.refreshOnce 内部使用,防递归)。 */ + static async postWithoutAuth(path: string, body: Record): Promise { + return ApiClient.doRequest(path, http.RequestMethod.POST, body, undefined, false) + } + + private static async request( + method: http.RequestMethod, + path: string, + body: Record | undefined + ): Promise { + const token = AuthStore.getAccessToken() + if (token === undefined) { + // 未登录直接短路,省一次必然 401 的往返 + throw new ApiError(40100, '请先登录', '登录后即可继续') + } + try { + return await ApiClient.doRequest(path, method, body, token, true) + } catch (e) { + const wrapped = ApiClient.wrapUnknown(e) + if (wrapped instanceof ApiError && AUTH_EXPIRED_CODES.includes(wrapped.code)) { + const refreshed = await AuthStore.refreshOnce() + if (refreshed) { + return await ApiClient.doRequest(path, method, body, AuthStore.getAccessToken(), true) + } + } + throw wrapped + } + } + + private static async doRequest( + path: string, + method: http.RequestMethod, + body: Record | undefined, + token: string | undefined, + withAuth: boolean + ): Promise { + const base = await AuthStore.getBaseUrl() + const url = `${base}${path}` + const client = http.createHttp() + try { + const header: Record = { + 'Content-Type': 'application/json' + } + if (withAuth && token !== undefined) { + header['Authorization'] = `Bearer ${token}` + } + const resp = await client.request(url, { + method: method, + header: header, + extraData: body !== undefined ? JSON.stringify(body) : undefined, + expectDataType: http.HttpDataType.OBJECT, + connectTimeout: 10000, + readTimeout: 30000 + }) + if (resp.responseCode !== 200 || resp.result === null || resp.result === undefined) { + // 网关/代理层错误:没有信封可用,给统一话术(NFR-UX-02) + throw new ApiError(50000, '服务开小差了', '请稍后重试', resp.responseCode) + } + const env = resp.result as ApiEnvelope + if (env.code !== 0) { + throw new ApiError(env.code, env.message, env.hint, resp.responseCode) + } + return env.data + } finally { + client.destroy() + } + } + + /** ArkTS 禁止 throw 任意类型:未知异常统一包装成 ApiError。 */ + private static wrapUnknown(e: Object): ApiError { + if (e instanceof ApiError) { + return e + } + return new ApiError(50000, '请求失败,请检查网络', '请稍后重试') + } +} diff --git a/app/entry/src/main/ets/core/ApiTypes.ets b/app/entry/src/main/ets/core/ApiTypes.ets new file mode 100644 index 0000000..5a3ea65 --- /dev/null +++ b/app/entry/src/main/ets/core/ApiTypes.ets @@ -0,0 +1,29 @@ +/** + * 后端统一响应信封与错误类型(对齐 packages/shared/response.py)。 + * + * 信封形状:{code, message, data, hint?, request_id?} + * - code=0 成功;4xxxx 客户端错;5xxxx 服务端错;6xxxx 外部依赖错 + * - 所有非 0 code 都必须走 ApiError 抛出,UI 层只 catch ApiError + */ + +export interface ApiEnvelope { + code: number + message: string + data: T + hint?: string + request_id?: string +} + +export class ApiError extends Error { + readonly code: number + readonly hint: string | undefined + readonly httpStatus: number + + constructor(code: number, message: string, hint?: string, httpStatus = 200) { + super(message) + this.name = 'ApiError' + this.code = code + this.hint = hint + this.httpStatus = httpStatus + } +} diff --git a/app/entry/src/main/ets/core/AuthStore.ets b/app/entry/src/main/ets/core/AuthStore.ets new file mode 100644 index 0000000..63b296c --- /dev/null +++ b/app/entry/src/main/ets/core/AuthStore.ets @@ -0,0 +1,155 @@ +/** + * 会话状态与令牌持久化(对齐后端 FR-ACC-05 双令牌)。 + * + * - access 短令牌放内存 + preferences(local 明文可接受:V1 骨架,无支付; + * 正式版应迁 @ohos.security.asset,注释留迁移点) + * - refresh 一次性轮换:每次 refresh 换新对 + * - dev-token 登录:POST /auth/dev-token(后端 DEV_AUTH_ENABLED 本地可用; + * 华为账号/短信登录是后续通道,接口按多通道预留) + * - ArkTS 约束:所有请求/响应都是具名 interface;字面量先声明类型再传 + */ + +import preferences from '@ohos.data.preferences' +import { ApiClient } from './ApiClient' +import { ContextHolder } from './ContextHolder' + +export interface TokenPair { + accessToken: string + refreshToken: string + expiresIn: number + refreshExpiresIn: number + userId: string +} + +interface AuthWireResp { + access_token: string + refresh_token: string + expires_in: number + refresh_expires_in: number + user_id: string +} + +const PREF_NAME = 'meida_auth' +const KEY_TOKENS = 'tokens' +const KEY_BASE_URL = 'base_url' +export const DEFAULT_BASE_URL = 'http://127.0.0.1:8000' + +export class AuthStore { + private static tokens: TokenPair | undefined + private static prefs: preferences.Preferences | undefined + private static refreshing: Promise | undefined + + static async init(): Promise { + AuthStore.prefs = await preferences.getPreferences(ContextHolder.get(), { name: PREF_NAME }) + const raw = await AuthStore.prefs.get(KEY_TOKENS, '') as string + if (raw !== '') { + try { + AuthStore.tokens = JSON.parse(raw) as TokenPair + } catch (_e) { + AuthStore.tokens = undefined + } + } + } + + static isLoggedIn(): boolean { + return AuthStore.tokens !== undefined && AuthStore.tokens.accessToken !== '' + } + + static getAccessToken(): string | undefined { + return AuthStore.tokens?.accessToken + } + + static getUserId(): string | undefined { + return AuthStore.tokens?.userId + } + + static async setBaseUrl(url: string): Promise { + await AuthStore.ensurePrefs() + await AuthStore.prefs!.put(KEY_BASE_URL, url) + await AuthStore.prefs!.flush() + } + + static async getBaseUrl(): Promise { + await AuthStore.ensurePrefs() + return await AuthStore.prefs!.get(KEY_BASE_URL, DEFAULT_BASE_URL) as string + } + + /** dev-token 登录(本地后端开发通道)。失败由 ApiClient 抛 ApiError。 */ + static async loginByDevToken(deviceKey: string): Promise { + const req: Record = { 'device_key': deviceKey } + const data = await ApiClient.post('/api/v1/auth/dev-token', req) + await AuthStore.saveTokens(AuthStore.fromWire(data)) + } + + /** 用 refresh 换新对。返回 false 表示会话已失效(应回登录页)。 */ + static async refreshOnce(): Promise { + if (AuthStore.refreshing !== undefined) { + return AuthStore.refreshing + } + const t = AuthStore.tokens + if (!t || t.refreshToken === '') { + return false + } + AuthStore.refreshing = AuthStore.doRefresh(t) + return AuthStore.refreshing + } + + static async logout(): Promise { + const t = AuthStore.tokens + if (t && t.refreshToken !== '') { + // 尽力通知服务端撤销;失败不阻塞本地登出 + try { + const req: Record = { 'refresh_token': t.refreshToken } + await ApiClient.post('/api/v1/auth/logout', req) + } catch (_e) { + // 忽略:服务端不可达也必须能本地登出 + } + } + await AuthStore.clear() + } + + static async clear(): Promise { + AuthStore.tokens = undefined + await AuthStore.ensurePrefs() + await AuthStore.prefs!.delete(KEY_TOKENS) + await AuthStore.prefs!.flush() + } + + private static async doRefresh(t: TokenPair): Promise { + try { + // 刻意走 postWithoutAuth:绕过 ApiClient 的自动刷新(否则递归) + const req: Record = { 'refresh_token': t.refreshToken } + const data = await ApiClient.postWithoutAuth('/api/v1/auth/refresh', req) + await AuthStore.saveTokens(AuthStore.fromWire(data)) + return true + } catch (_e) { + await AuthStore.clear() + return false + } finally { + AuthStore.refreshing = undefined + } + } + + private static fromWire(w: AuthWireResp): TokenPair { + return { + accessToken: w.access_token, + refreshToken: w.refresh_token, + expiresIn: w.expires_in, + refreshExpiresIn: w.refresh_expires_in, + userId: w.user_id + } + } + + private static async saveTokens(t: TokenPair): Promise { + AuthStore.tokens = t + await AuthStore.ensurePrefs() + await AuthStore.prefs!.put(KEY_TOKENS, JSON.stringify(t)) + await AuthStore.prefs!.flush() + } + + private static async ensurePrefs(): Promise { + if (AuthStore.prefs === undefined) { + AuthStore.prefs = await preferences.getPreferences(ContextHolder.get(), { name: PREF_NAME }) + } + } +} diff --git a/app/entry/src/main/ets/core/ContextHolder.ets b/app/entry/src/main/ets/core/ContextHolder.ets new file mode 100644 index 0000000..aaf02aa --- /dev/null +++ b/app/entry/src/main/ets/core/ContextHolder.ets @@ -0,0 +1,22 @@ +/** + * ContextHolder:UI 上下文的全局挂点。 + * + * preferences / http 等系统能力需要 Context;ArkUI 里合法取法是 + * getUIContext().getHostContext(),但网络层与页面解耦后统一从 EntryAbility + * 注入一次最简单(EntryAbility.onCreate 里 set)。 + */ + +export class ContextHolder { + private static context: Context | undefined + + static set(context: Context): void { + ContextHolder.context = context + } + + static get(): Context { + if (!ContextHolder.context) { + throw new Error('ContextHolder 未初始化:EntryAbility.onCreate 应先调用 set()') + } + return ContextHolder.context + } +} diff --git a/app/entry/src/main/ets/entryability/EntryAbility.ets b/app/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000..daf2b92 --- /dev/null +++ b/app/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,53 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { ContextHolder } from '../core/ContextHolder'; +import { AuthStore } from '../core/AuthStore'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 全局 Context 挂点:core 层(preferences/http)从这里取,UI 不传参 + ContextHolder.set(this.context) + AuthStore.init() + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/app/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/app/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000..8e4de99 --- /dev/null +++ b/app/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/app/entry/src/main/ets/pages/ChatPage.ets b/app/entry/src/main/ets/pages/ChatPage.ets new file mode 100644 index 0000000..c420a72 --- /dev/null +++ b/app/entry/src/main/ets/pages/ChatPage.ets @@ -0,0 +1,17 @@ +/** + * ChatPage —— 占位桩(FE 批次对应任务填充实现)。 + * 已注册进 main_pages.json,其它页面可按路径跳转。 + */ + +@Entry +@Component +struct ChatPage { + build() { + Column() { + Text('ChatPage(建设中)').fontSize(16).fontColor('#666666') + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/ets/pages/HomePage.ets b/app/entry/src/main/ets/pages/HomePage.ets new file mode 100644 index 0000000..7c655fa --- /dev/null +++ b/app/entry/src/main/ets/pages/HomePage.ets @@ -0,0 +1,17 @@ +/** + * HomePage —— 占位桩(FE 批次对应任务填充实现)。 + * 已注册进 main_pages.json,其它页面可按路径跳转。 + */ + +@Entry +@Component +struct HomePage { + build() { + Column() { + Text('HomePage(建设中)').fontSize(16).fontColor('#666666') + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/ets/pages/Index.ets b/app/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..99398c4 --- /dev/null +++ b/app/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,29 @@ +/** + * 应用入口:按登录态分流到登录页或主页。 + * 页面间一律 router 路径跳转(页面已全部注册 main_pages),跨任务零 import。 + */ + +import { router } from '@kit.ArkUI' +import { AuthStore } from '../core/AuthStore' + +@Entry +@Component +struct Index { + aboutToAppear(): void { + const target = AuthStore.isLoggedIn() ? 'pages/HomePage' : 'pages/LoginPage' + router.replaceUrl({ url: target }) + } + + build() { + Column() { + LoadingProgress().width(48).height(48) + Text('美搭') + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ top: 12 }) + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/ets/pages/LoginPage.ets b/app/entry/src/main/ets/pages/LoginPage.ets new file mode 100644 index 0000000..6b9ce76 --- /dev/null +++ b/app/entry/src/main/ets/pages/LoginPage.ets @@ -0,0 +1,17 @@ +/** + * LoginPage —— 占位桩(FE 批次对应任务填充实现)。 + * 已注册进 main_pages.json,其它页面可按路径跳转。 + */ + +@Entry +@Component +struct LoginPage { + build() { + Column() { + Text('LoginPage(建设中)').fontSize(16).fontColor('#666666') + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/ets/pages/ProfilePage.ets b/app/entry/src/main/ets/pages/ProfilePage.ets new file mode 100644 index 0000000..d6e7673 --- /dev/null +++ b/app/entry/src/main/ets/pages/ProfilePage.ets @@ -0,0 +1,17 @@ +/** + * ProfilePage —— 占位桩(FE 批次对应任务填充实现)。 + * 已注册进 main_pages.json,其它页面可按路径跳转。 + */ + +@Entry +@Component +struct ProfilePage { + build() { + Column() { + Text('ProfilePage(建设中)').fontSize(16).fontColor('#666666') + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/ets/pages/ReportCreatePage.ets b/app/entry/src/main/ets/pages/ReportCreatePage.ets new file mode 100644 index 0000000..9905f86 --- /dev/null +++ b/app/entry/src/main/ets/pages/ReportCreatePage.ets @@ -0,0 +1,17 @@ +/** + * ReportCreatePage —— 占位桩(FE 批次对应任务填充实现)。 + * 已注册进 main_pages.json,其它页面可按路径跳转。 + */ + +@Entry +@Component +struct ReportCreatePage { + build() { + Column() { + Text('ReportCreatePage(建设中)').fontSize(16).fontColor('#666666') + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/ets/pages/ReportResultPage.ets b/app/entry/src/main/ets/pages/ReportResultPage.ets new file mode 100644 index 0000000..bc28924 --- /dev/null +++ b/app/entry/src/main/ets/pages/ReportResultPage.ets @@ -0,0 +1,17 @@ +/** + * ReportResultPage —— 占位桩(FE 批次对应任务填充实现)。 + * 已注册进 main_pages.json,其它页面可按路径跳转。 + */ + +@Entry +@Component +struct ReportResultPage { + build() { + Column() { + Text('ReportResultPage(建设中)').fontSize(16).fontColor('#666666') + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} diff --git a/app/entry/src/main/module.json5 b/app/entry/src/main/module.json5 new file mode 100644 index 0000000..f658a45 --- /dev/null +++ b/app/entry/src/main/module.json5 @@ -0,0 +1,53 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "requestPermissions": [ + { "name": "ohos.permission.INTERNET" } + ], + "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" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/app/entry/src/main/resources/base/element/color.json b/app/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000..3c71296 --- /dev/null +++ b/app/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/app/entry/src/main/resources/base/element/float.json b/app/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000..33ea223 --- /dev/null +++ b/app/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/app/entry/src/main/resources/base/element/string.json b/app/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000..f945955 --- /dev/null +++ b/app/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/app/entry/src/main/resources/base/media/background.png b/app/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000..923f2b3 Binary files /dev/null and b/app/entry/src/main/resources/base/media/background.png differ diff --git a/app/entry/src/main/resources/base/media/foreground.png b/app/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000..97014d3 Binary files /dev/null and b/app/entry/src/main/resources/base/media/foreground.png differ diff --git a/app/entry/src/main/resources/base/media/layered_image.json b/app/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000..fb49920 --- /dev/null +++ b/app/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/app/entry/src/main/resources/base/media/startIcon.png b/app/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000..205ad8b Binary files /dev/null and b/app/entry/src/main/resources/base/media/startIcon.png differ diff --git a/app/entry/src/main/resources/base/profile/backup_config.json b/app/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000..78f40ae --- /dev/null +++ b/app/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/app/entry/src/main/resources/base/profile/main_pages.json b/app/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..f59e15a --- /dev/null +++ b/app/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,11 @@ +{ + "src": [ + "pages/Index", + "pages/LoginPage", + "pages/HomePage", + "pages/ReportCreatePage", + "pages/ReportResultPage", + "pages/ChatPage", + "pages/ProfilePage" + ] +} diff --git a/app/entry/src/main/resources/dark/element/color.json b/app/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000..79b11c2 --- /dev/null +++ b/app/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/app/entry/src/mock/mock-config.json5 b/app/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/app/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/app/entry/src/ohosTest/ets/test/Ability.test.ets b/app/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000..85c78f6 --- /dev/null +++ b/app/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/app/entry/src/ohosTest/ets/test/List.test.ets b/app/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000..794c7dc --- /dev/null +++ b/app/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/app/entry/src/ohosTest/module.json5 b/app/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000..509a3a2 --- /dev/null +++ b/app/entry/src/ohosTest/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/app/entry/src/test/List.test.ets b/app/entry/src/test/List.test.ets new file mode 100644 index 0000000..bb5b5c3 --- /dev/null +++ b/app/entry/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/app/entry/src/test/LocalUnit.test.ets b/app/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000..165fc16 --- /dev/null +++ b/app/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/app/hvigor/hvigor-config.json5 b/app/hvigor/hvigor-config.json5 new file mode 100644 index 0000000..4481d31 --- /dev/null +++ b/app/hvigor/hvigor-config.json5 @@ -0,0 +1,23 @@ +{ + "modelVersion": "6.1.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/app/hvigorfile.ts b/app/hvigorfile.ts new file mode 100644 index 0000000..47113e2 --- /dev/null +++ b/app/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/app/oh-package-lock.json5 b/app/oh-package-lock.json5 new file mode 100644 index 0000000..c5a91ec --- /dev/null +++ b/app/oh-package-lock.json5 @@ -0,0 +1,28 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.25": "@ohos/hypium@1.0.25" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.25": { + "name": "@ohos/hypium", + "version": "1.0.25", + "integrity": "sha512-l6uO2pjl8HyEKdekLqQt7tUpWbDqX/42zoAzkagtUVZAW9jT6lMvbe54MVjoLxq/RwQGygRvi6j4GpypSMFSHw==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.25.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/app/oh-package.json5 b/app/oh-package.json5 new file mode 100644 index 0000000..01177cc --- /dev/null +++ b/app/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "6.1.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.25", + "@ohos/hamock": "1.0.0" + } +}