@univa/core 0.0.2 → 0.0.3
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 +238 -1
- package/package.json +3 -1
- package/src/client.d.ts +2 -0
package/README.md
CHANGED
|
@@ -61,7 +61,244 @@ export default defineConfig({
|
|
|
61
61
|
|
|
62
62
|
## 功能详解
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
### 自动导入
|
|
65
|
+
|
|
66
|
+
自动导入 Vue、Pinia、uni-app 等 API,无需手动 import:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// 无需 import,直接使用
|
|
70
|
+
const count = ref(0)
|
|
71
|
+
const router = useRouter()
|
|
72
|
+
const store = useStore()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**自动扫描目录**:
|
|
76
|
+
- `src/hooks/**` - 自动导入 hooks
|
|
77
|
+
- `src/store/**` - 自动导入 store
|
|
78
|
+
- `src/constants/**` - 自动导入常量
|
|
79
|
+
|
|
80
|
+
### 组件自动注册
|
|
81
|
+
|
|
82
|
+
自动注册 `components` 目录下的组件,无需手动 import:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
src/
|
|
86
|
+
├── components/
|
|
87
|
+
│ ├── MyButton.vue
|
|
88
|
+
│ └── common/
|
|
89
|
+
│ └── Icon.vue
|
|
90
|
+
└── components-biz/
|
|
91
|
+
└── Card.vue
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
在页面中直接使用:
|
|
95
|
+
|
|
96
|
+
```vue
|
|
97
|
+
<template>
|
|
98
|
+
<MyButton />
|
|
99
|
+
<Icon />
|
|
100
|
+
<BizCard />
|
|
101
|
+
</template>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**特性**:
|
|
105
|
+
- `components/` 和 `common/` 是全局命名空间,不添加前缀
|
|
106
|
+
- `components-biz/` 会自动添加 `Biz` 命名空间前缀
|
|
107
|
+
- 自动生成类型声明文件
|
|
108
|
+
|
|
109
|
+
### 页面管理
|
|
110
|
+
|
|
111
|
+
#### 定义页面配置
|
|
112
|
+
|
|
113
|
+
**方式 1:在 pages.config.ts 中定义**
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// pages.config.ts
|
|
117
|
+
import { definePagesConfig } from '@univa/core'
|
|
118
|
+
|
|
119
|
+
export default definePagesConfig({
|
|
120
|
+
tabBarMode: 'CUSTOM', // 'NONE' | 'NATIVE' | 'CUSTOM'
|
|
121
|
+
tabBar: {
|
|
122
|
+
list: [
|
|
123
|
+
{
|
|
124
|
+
pagePath: 'pages/index',
|
|
125
|
+
text: '首页',
|
|
126
|
+
iconPath: 'images/tabbar/home.png',
|
|
127
|
+
selectedIconPath: 'images/tabbar/home_selected.png',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**方式 2:在 vite.config.ts 中直接定义**
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// vite.config.ts
|
|
138
|
+
import { Univa } from '@univa/core'
|
|
139
|
+
import { defineConfig } from 'vite'
|
|
140
|
+
|
|
141
|
+
export default defineConfig({
|
|
142
|
+
plugins: [
|
|
143
|
+
Univa({
|
|
144
|
+
pages: {
|
|
145
|
+
config: {
|
|
146
|
+
tabBarMode: 'CUSTOM',
|
|
147
|
+
tabBar: {
|
|
148
|
+
list: [...],
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
],
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### 获取 TabBar 配置
|
|
158
|
+
|
|
159
|
+
在组件中获取 tabBar 配置:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import tabBar from 'virtual:univa-tabbar'
|
|
163
|
+
|
|
164
|
+
if (tabBar) {
|
|
165
|
+
console.log(tabBar.list) // TabBar 列表
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### UnoCSS 预设
|
|
170
|
+
|
|
171
|
+
内置 UnoCSS 预设,提供开箱即用的原子化 CSS:
|
|
172
|
+
|
|
173
|
+
**内置预设**:
|
|
174
|
+
- `presetUni()` - uni-app 专属预设
|
|
175
|
+
- `presetIcons()` - 图标预设(scale: 1.2)
|
|
176
|
+
- `presetLegacyCompat()` - 兼容性预设(处理低端安卓机)
|
|
177
|
+
|
|
178
|
+
**内置快捷方式**:
|
|
179
|
+
```typescript
|
|
180
|
+
'border-s' // border border-solid
|
|
181
|
+
'wh-full' // w-full h-full
|
|
182
|
+
'f-c-c' // flex justify-center items-center
|
|
183
|
+
'f-col-c' // flex-col justify-center items-center
|
|
184
|
+
'flex-items' // flex items-center
|
|
185
|
+
'flex-justify' // flex justify-center
|
|
186
|
+
'flex-col' // flex flex-col
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**安全区域规则**:
|
|
190
|
+
```html
|
|
191
|
+
<div class="p-safe">安全区域内边距</div>
|
|
192
|
+
<div class="pt-safe">顶部安全区域</div>
|
|
193
|
+
<div class="pb-safe">底部安全区域</div>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 根组件
|
|
197
|
+
|
|
198
|
+
自动创建和管理 `App.univa.vue` 根组件:
|
|
199
|
+
|
|
200
|
+
```vue
|
|
201
|
+
<script setup lang="ts">
|
|
202
|
+
</script>
|
|
203
|
+
|
|
204
|
+
<template>
|
|
205
|
+
<UnivaPageMeta background-color="#ff0000" page-style="color: green" />
|
|
206
|
+
<view class="container">
|
|
207
|
+
<UnivaRootView />
|
|
208
|
+
</view>
|
|
209
|
+
</template>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**特性**:
|
|
213
|
+
- 自动创建根组件文件
|
|
214
|
+
- 支持虚拟节点(`virtualHost`)
|
|
215
|
+
- 支持全局 ref
|
|
216
|
+
- 支持 `<UnivaPageMeta>` 组件配置页面元信息
|
|
217
|
+
- 支持 `<UnivaRootView />` 组件作为根视图
|
|
218
|
+
|
|
219
|
+
### Manifest 配置
|
|
220
|
+
|
|
221
|
+
在 `vite.config.ts` 中直接配置 manifest:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { Univa } from '@univa/core'
|
|
225
|
+
import { defineConfig } from 'vite'
|
|
226
|
+
|
|
227
|
+
export default defineConfig({
|
|
228
|
+
plugins: [
|
|
229
|
+
Univa({
|
|
230
|
+
manifest: {
|
|
231
|
+
name: 'my-app',
|
|
232
|
+
appid: '__UNI__XXXXXX',
|
|
233
|
+
description: 'My Application',
|
|
234
|
+
versionName: '1.0.0',
|
|
235
|
+
versionCode: '100',
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
],
|
|
239
|
+
})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## 配置选项
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import type { UnivaUserConfig } from '@univa/core'
|
|
246
|
+
|
|
247
|
+
const config: UnivaUserConfig = {
|
|
248
|
+
// 自动导入配置(默认 true)
|
|
249
|
+
autoImport: true,
|
|
250
|
+
|
|
251
|
+
// 组件自动注册配置(默认 true)
|
|
252
|
+
components: true,
|
|
253
|
+
|
|
254
|
+
// 页面配置
|
|
255
|
+
pages: {
|
|
256
|
+
config: {
|
|
257
|
+
// TabBar 模式:'NONE' | 'NATIVE' | 'CUSTOM'
|
|
258
|
+
tabBarMode: 'NATIVE',
|
|
259
|
+
tabBar: {
|
|
260
|
+
color: '#A6A6A6',
|
|
261
|
+
selectedColor: '#003594',
|
|
262
|
+
list: [
|
|
263
|
+
{
|
|
264
|
+
pagePath: 'pages/index',
|
|
265
|
+
text: '首页',
|
|
266
|
+
iconPath: 'images/tabbar/home.png',
|
|
267
|
+
selectedIconPath: 'images/tabbar/home_selected.png',
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
// 全局样式配置
|
|
272
|
+
globalStyle: {
|
|
273
|
+
navigationBarBackgroundColor: '#000000',
|
|
274
|
+
navigationBarTextStyle: 'black',
|
|
275
|
+
navigationBarTitleText: 'My App',
|
|
276
|
+
navigationStyle: 'custom',
|
|
277
|
+
enablePullDownRefresh: false,
|
|
278
|
+
onReachBottomDistance: 50,
|
|
279
|
+
animationType: 'pop-in',
|
|
280
|
+
animationDuration: 300,
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
// 排除的页面
|
|
284
|
+
exclude: ['pages/exclude/**'],
|
|
285
|
+
// 分包配置
|
|
286
|
+
subPackages: ['pages-sub'],
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
// 根组件配置(默认 true)
|
|
290
|
+
appRoot: true,
|
|
291
|
+
|
|
292
|
+
// Manifest 配置
|
|
293
|
+
manifest: {
|
|
294
|
+
name: 'my-app',
|
|
295
|
+
appid: '__UNI__XXXXXX',
|
|
296
|
+
description: 'My Application',
|
|
297
|
+
versionName: '1.0.0',
|
|
298
|
+
versionCode: '100',
|
|
299
|
+
},
|
|
300
|
+
}
|
|
301
|
+
```
|
|
65
302
|
|
|
66
303
|
## 依赖
|
|
67
304
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univa/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@uni-helper/eslint-config": "0.7.3",
|
|
43
43
|
"@uni-helper/plugin-uni": "0.1.0",
|
|
44
|
+
"@uni-helper/uni-types": "1.0.0-alpha.8",
|
|
44
45
|
"@uni-helper/unocss-preset-uni": "0.2.11",
|
|
45
46
|
"@uni-helper/vite-plugin-uni-components": "0.2.10",
|
|
46
47
|
"@uni-helper/vite-plugin-uni-layouts": "0.1.11",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"@uni-ku/bundle-optimizer": "2.1.2",
|
|
49
50
|
"@univa/manifest": "^0.0.1",
|
|
50
51
|
"@univa/root": "^0.0.1",
|
|
52
|
+
"@univa/tsconfig": "^0.0.1",
|
|
51
53
|
"@unocss/eslint-plugin": "66.6.7",
|
|
52
54
|
"@unocss/preset-legacy-compat": "66.0.0",
|
|
53
55
|
"eslint": "10.3.0",
|
package/src/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference path="./global.d.ts" />
|
|
2
2
|
/// <reference types="@uni-helper/vite-plugin-uni-pages/client" />
|
|
3
3
|
/// <reference types="vite/client" />
|
|
4
|
+
/// <reference types="@uni-ku/bundle-optimizer/client" />
|
|
5
|
+
/// <reference types="@uni-helper/uni-types" />
|
|
4
6
|
|
|
5
7
|
declare module 'virtual:univa-tabbar' {
|
|
6
8
|
import type { TabBar } from '@uni-helper/vite-plugin-uni-pages'
|