@hlw-uni/mp-vue 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +211 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# @hlw-uni/mp-vue
|
|
2
|
+
|
|
3
|
+
> hlw-uni Vue 组件库 — 供 uni-app 小程序业务方使用的 UI 组件集合
|
|
4
|
+
|
|
5
|
+
基于 Vue 3 + TypeScript 构建,面向 uni-app 多端小程序(微信、抖音等)场景,由 uni-app 编译器适配各平台原生组件。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- 基于 Vue 3 Composition API + `<script setup>`
|
|
10
|
+
- 完整的 TypeScript 类型定义
|
|
11
|
+
- 多端兼容(微信小程序 / 抖音小程序等)
|
|
12
|
+
- Tree-shaking 友好,按需引入
|
|
13
|
+
- 轻量、零样式侵入
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @hlw-uni/mp-vue
|
|
19
|
+
# 或
|
|
20
|
+
pnpm add @hlw-uni/mp-vue
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Peer Dependencies
|
|
24
|
+
|
|
25
|
+
- `vue >= 3.4.0`
|
|
26
|
+
|
|
27
|
+
### 依赖
|
|
28
|
+
|
|
29
|
+
- `@hlw-uni/mp-core` — 共享核心工具
|
|
30
|
+
|
|
31
|
+
## 使用
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { HlwAd, HlwAvatar, HlwEmpty, HlwLoading, HlwMenuList } from '@hlw-uni/mp-vue';
|
|
35
|
+
import type { MenuItem } from '@hlw-uni/mp-vue';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
可在页面或组件中直接注册并使用:
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
import { HlwEmpty, HlwLoading } from '@hlw-uni/mp-vue';
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<HlwLoading text="加载中..." />
|
|
47
|
+
<HlwEmpty text="暂无数据" />
|
|
48
|
+
</template>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 组件
|
|
52
|
+
|
|
53
|
+
### HlwAd — 广告组件
|
|
54
|
+
|
|
55
|
+
对小程序原生 `<ad>` 的封装,支持信息流 / Banner 广告。
|
|
56
|
+
|
|
57
|
+
**Props**
|
|
58
|
+
|
|
59
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
60
|
+
| --- | --- | --- | --- |
|
|
61
|
+
| `unitId` | `string` | 是 | 广告单元 ID(在各平台广告后台申请) |
|
|
62
|
+
|
|
63
|
+
**Events**
|
|
64
|
+
|
|
65
|
+
| 事件 | 说明 |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `load` | 广告加载成功 |
|
|
68
|
+
| `close` | 用户关闭广告 |
|
|
69
|
+
| `error` | 加载/展示失败,携带 `{ errCode, errMsg }` |
|
|
70
|
+
|
|
71
|
+
```vue
|
|
72
|
+
<HlwAd unit-id="adunit-xxx" @load="onLoad" @error="onError" />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### HlwAvatar — 头像
|
|
78
|
+
|
|
79
|
+
支持图片头像,加载失败或未传 `src` 时降级显示首字母占位。
|
|
80
|
+
|
|
81
|
+
**Props**
|
|
82
|
+
|
|
83
|
+
| 属性 | 类型 | 默认 | 说明 |
|
|
84
|
+
| --- | --- | --- | --- |
|
|
85
|
+
| `src` | `string` | — | 头像图片地址 |
|
|
86
|
+
| `name` | `string` | — | 用户名(首字母占位) |
|
|
87
|
+
| `size` | `'small' \| 'medium' \| 'large'` | `'medium'` | 尺寸 |
|
|
88
|
+
|
|
89
|
+
```vue
|
|
90
|
+
<HlwAvatar :src="user.avatar" :name="user.name" size="large" />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### HlwEmpty — 空状态
|
|
96
|
+
|
|
97
|
+
**Props**
|
|
98
|
+
|
|
99
|
+
| 属性 | 类型 | 默认 | 说明 |
|
|
100
|
+
| --- | --- | --- | --- |
|
|
101
|
+
| `text` | `string` | `'暂无数据'` | 提示文案 |
|
|
102
|
+
| `image` | `string` | — | 自定义占位图,未传时显示默认图标 |
|
|
103
|
+
|
|
104
|
+
**Slots**
|
|
105
|
+
|
|
106
|
+
- `default` — 自定义底部内容(如操作按钮)
|
|
107
|
+
|
|
108
|
+
```vue
|
|
109
|
+
<HlwEmpty text="还没有任何记录">
|
|
110
|
+
<button @click="refresh">刷新</button>
|
|
111
|
+
</HlwEmpty>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### HlwLoading — 加载中
|
|
117
|
+
|
|
118
|
+
**Props**
|
|
119
|
+
|
|
120
|
+
| 属性 | 类型 | 说明 |
|
|
121
|
+
| --- | --- | --- |
|
|
122
|
+
| `text` | `string` | 加载文案,可选 |
|
|
123
|
+
|
|
124
|
+
```vue
|
|
125
|
+
<HlwLoading text="加载中..." />
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### HlwMenuList — 菜单列表
|
|
131
|
+
|
|
132
|
+
常用于"我的"页面的设置菜单。
|
|
133
|
+
|
|
134
|
+
**Props**
|
|
135
|
+
|
|
136
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
137
|
+
| --- | --- | --- | --- |
|
|
138
|
+
| `items` | `MenuItem[]` | 是 | 菜单项数组 |
|
|
139
|
+
|
|
140
|
+
**MenuItem 类型**
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
interface MenuItem {
|
|
144
|
+
key: string; // 唯一标识
|
|
145
|
+
label: string; // 显示文案
|
|
146
|
+
icon?: string; // 图标(emoji 或字体)
|
|
147
|
+
value?: string; // 右侧附加信息
|
|
148
|
+
url?: string; // 点击跳转的页面路径
|
|
149
|
+
action?: () => void; // 点击执行的函数
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Events**
|
|
154
|
+
|
|
155
|
+
| 事件 | 参数 | 说明 |
|
|
156
|
+
| --- | --- | --- |
|
|
157
|
+
| `click` | `item: MenuItem` | 点击菜单项时触发 |
|
|
158
|
+
|
|
159
|
+
```vue
|
|
160
|
+
<script setup lang="ts">
|
|
161
|
+
import { HlwMenuList, type MenuItem } from '@hlw-uni/mp-vue';
|
|
162
|
+
|
|
163
|
+
const items: MenuItem[] = [
|
|
164
|
+
{ key: 'profile', label: '个人资料', icon: '👤', url: '/pages/profile/index' },
|
|
165
|
+
{ key: 'settings', label: '设置', icon: '⚙️', value: '已开启' },
|
|
166
|
+
{ key: 'logout', label: '退出登录', icon: '🚪', action: () => uni.showToast({ title: '已退出' }) },
|
|
167
|
+
];
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<template>
|
|
171
|
+
<HlwMenuList :items="items" @click="onMenuClick" />
|
|
172
|
+
</template>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 开发
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# 构建
|
|
179
|
+
npm run build
|
|
180
|
+
|
|
181
|
+
# 监听构建(开发模式)
|
|
182
|
+
npm run dev
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
构建产物输出到 `dist/`:
|
|
186
|
+
|
|
187
|
+
- `dist/index.mjs` — ES Module
|
|
188
|
+
- `dist/index.js` — CommonJS
|
|
189
|
+
- `dist/index.d.ts` — TypeScript 类型定义
|
|
190
|
+
|
|
191
|
+
## 项目结构
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
mp-vue/
|
|
195
|
+
├── src/
|
|
196
|
+
│ ├── components/
|
|
197
|
+
│ │ ├── hlw-ad/
|
|
198
|
+
│ │ ├── hlw-avatar/
|
|
199
|
+
│ │ ├── hlw-empty/
|
|
200
|
+
│ │ ├── hlw-loading/
|
|
201
|
+
│ │ └── hlw-menu-list/
|
|
202
|
+
│ └── index.ts # 统一导出入口
|
|
203
|
+
├── dist/ # 构建产物
|
|
204
|
+
├── package.json
|
|
205
|
+
├── tsconfig.json
|
|
206
|
+
└── vite.config.ts
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
内部组件库,仅供 hlw-uni 项目使用。
|