From d5e2d88c4c800c27ef0dac7a78875f166050b19a Mon Sep 17 00:00:00 2001 From: AndyChen1024 Date: Fri, 11 Sep 2026 16:22:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(uikit):=20=E6=96=B0=E5=A2=9E=E9=80=9A?= =?UTF-8?q?=E7=94=A8=20UI=20=E7=BB=84=E4=BB=B6=E5=BA=93=E4=B8=8E=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uikit/BuildProfile.ets | 17 ++++++++++ uikit/Index.ets | 1 + uikit/build-profile.json5 | 10 ++++++ uikit/hvigorfile.ts | 6 ++++ uikit/oh-package.json5 | 9 +++++ uikit/src/main/ets/Index.ets | 4 +++ uikit/src/main/ets/components/AppButton.ets | 33 +++++++++++++++++++ uikit/src/main/ets/components/EmptyView.ets | 20 +++++++++++ uikit/src/main/ets/components/LoadingView.ets | 21 ++++++++++++ uikit/src/main/ets/theme/Theme.ets | 29 ++++++++++++++++ uikit/src/main/module.json5 | 10 ++++++ .../main/resources/base/element/string.json | 8 +++++ 12 files changed, 168 insertions(+) create mode 100644 uikit/BuildProfile.ets create mode 100644 uikit/Index.ets create mode 100644 uikit/build-profile.json5 create mode 100644 uikit/hvigorfile.ts create mode 100644 uikit/oh-package.json5 create mode 100644 uikit/src/main/ets/Index.ets create mode 100644 uikit/src/main/ets/components/AppButton.ets create mode 100644 uikit/src/main/ets/components/EmptyView.ets create mode 100644 uikit/src/main/ets/components/LoadingView.ets create mode 100644 uikit/src/main/ets/theme/Theme.ets create mode 100644 uikit/src/main/module.json5 create mode 100644 uikit/src/main/resources/base/element/string.json diff --git a/uikit/BuildProfile.ets b/uikit/BuildProfile.ets new file mode 100644 index 0000000..3a501e5 --- /dev/null +++ b/uikit/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/uikit/Index.ets b/uikit/Index.ets new file mode 100644 index 0000000..64530f6 --- /dev/null +++ b/uikit/Index.ets @@ -0,0 +1 @@ +export * from './src/main/ets/Index.ets'; diff --git a/uikit/build-profile.json5 b/uikit/build-profile.json5 new file mode 100644 index 0000000..79961f9 --- /dev/null +++ b/uikit/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/uikit/hvigorfile.ts b/uikit/hvigorfile.ts new file mode 100644 index 0000000..08f99a1 --- /dev/null +++ b/uikit/hvigorfile.ts @@ -0,0 +1,6 @@ +import { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/uikit/oh-package.json5 b/uikit/oh-package.json5 new file mode 100644 index 0000000..dfc7789 --- /dev/null +++ b/uikit/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "uikit", + "version": "1.0.0", + "description": "通用 UI 组件库与主题", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/uikit/src/main/ets/Index.ets b/uikit/src/main/ets/Index.ets new file mode 100644 index 0000000..881651c --- /dev/null +++ b/uikit/src/main/ets/Index.ets @@ -0,0 +1,4 @@ +export { AppColor, AppSpacing, AppFontSize } from './theme/Theme'; +export { AppButton, ButtonVariant } from './components/AppButton'; +export { LoadingView } from './components/LoadingView'; +export { EmptyView } from './components/EmptyView'; diff --git a/uikit/src/main/ets/components/AppButton.ets b/uikit/src/main/ets/components/AppButton.ets new file mode 100644 index 0000000..78ad60b --- /dev/null +++ b/uikit/src/main/ets/components/AppButton.ets @@ -0,0 +1,33 @@ +import { AppColor } from '../theme/Theme'; + +export enum ButtonVariant { + Primary = 'primary', + Secondary = 'secondary' +} + +/** + * 通用按钮:@ComponentV2 + @Param 输入 + @Event 输出回调。 + */ +@ComponentV2 +export struct AppButton { + @Param text: string = ''; + @Param variant: ButtonVariant = ButtonVariant.Primary; + @Param disabled: boolean = false; + @Event onTap: () => void; + + build() { + Button(this.text) + .width('100%') + .height(48) + .fontSize(16) + .fontColor(this.variant === ButtonVariant.Primary ? AppColor.white : AppColor.primary) + .backgroundColor(this.variant === ButtonVariant.Primary ? AppColor.primary : AppColor.white) + .borderRadius(8) + .enabled(!this.disabled) + .onClick(() => { + if (!this.disabled) { + this.onTap(); + } + }) + } +} diff --git a/uikit/src/main/ets/components/EmptyView.ets b/uikit/src/main/ets/components/EmptyView.ets new file mode 100644 index 0000000..eca7e45 --- /dev/null +++ b/uikit/src/main/ets/components/EmptyView.ets @@ -0,0 +1,20 @@ +import { AppColor, AppFontSize } from '../theme/Theme'; + +/** + * 通用空态组件。 + */ +@ComponentV2 +export struct EmptyView { + @Param text: string = '暂无数据'; + + build() { + Column({ space: 8 }) { + Text('暂无内容') + .fontSize(AppFontSize.headline) + .fontColor(AppColor.textSecondary) + Text(this.text) + .fontSize(AppFontSize.body) + .fontColor(AppColor.textSecondary) + } + } +} diff --git a/uikit/src/main/ets/components/LoadingView.ets b/uikit/src/main/ets/components/LoadingView.ets new file mode 100644 index 0000000..072184b --- /dev/null +++ b/uikit/src/main/ets/components/LoadingView.ets @@ -0,0 +1,21 @@ +import { AppColor, AppFontSize } from '../theme/Theme'; + +/** + * 通用加载态组件。 + */ +@ComponentV2 +export struct LoadingView { + @Param text: string = '加载中...'; + + build() { + Column({ space: 8 }) { + LoadingProgress() + .width(32) + .height(32) + .color(AppColor.primary) + Text(this.text) + .fontSize(AppFontSize.body) + .fontColor(AppColor.textSecondary) + } + } +} diff --git a/uikit/src/main/ets/theme/Theme.ets b/uikit/src/main/ets/theme/Theme.ets new file mode 100644 index 0000000..4733035 --- /dev/null +++ b/uikit/src/main/ets/theme/Theme.ets @@ -0,0 +1,29 @@ +/** + * 主题 token:颜色 / 间距 / 字号。 + * 全 App 统一从这里取值,避免散落魔法值。 + */ +export class AppColor { + static readonly primary: string = '#0A59F7'; + static readonly primaryPressed: string = '#094CCB'; + static readonly textPrimary: string = '#182431'; + static readonly textSecondary: string = '#66182431'; + static readonly background: string = '#F1F3F5'; + static readonly white: string = '#FFFFFF'; + static readonly divider: string = '#0D182431'; + static readonly danger: string = '#E84026'; +} + +export class AppSpacing { + static readonly xs: number = 4; + static readonly sm: number = 8; + static readonly md: number = 16; + static readonly lg: number = 24; + static readonly xl: number = 32; +} + +export class AppFontSize { + static readonly caption: number = 12; + static readonly body: number = 14; + static readonly title: number = 16; + static readonly headline: number = 20; +} diff --git a/uikit/src/main/module.json5 b/uikit/src/main/module.json5 new file mode 100644 index 0000000..f3a79dd --- /dev/null +++ b/uikit/src/main/module.json5 @@ -0,0 +1,10 @@ +{ + "module": { + "name": "uikit", + "type": "har", + "description": "$string:module_desc", + "deviceTypes": [ + "phone" + ] + } +} diff --git a/uikit/src/main/resources/base/element/string.json b/uikit/src/main/resources/base/element/string.json new file mode 100644 index 0000000..6620c63 --- /dev/null +++ b/uikit/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "uikit module" + } + ] +}