1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-12 16:40:40 +08:00

refactor: 架构升级

This commit is contained in:
小莫唐尼
2026-08-31 07:58:23 +08:00
commit ba5b77568b
693 changed files with 118430 additions and 0 deletions
@@ -0,0 +1,227 @@
# Manifest Configuration | Manifest 配置
## Instructions
This example demonstrates how to configure manifest.json for uView Pro in UniAppX projects across different platforms.
### Key Concepts
- Platform-specific manifest configuration
- H5 configuration
- Mini-program configuration
- App configuration
- Component support configuration
### 基本配置
```json
{
"name": "uniappx-uview-pro-project",
"appid": "",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
"app-plus": {
"usingComponents": true
},
"h5": {
"router": {
"mode": "hash"
}
},
"mp-weixin": {
"appid": "",
"setting": {
"urlCheck": false
},
"usingComponents": true
}
}
```
### H5 平台配置
```json
{
"h5": {
"router": {
"mode": "hash",
"base": "/"
},
"devServer": {
"https": false,
"port": 8080
},
"publicPath": "/",
"template": "index.html"
}
}
```
### 微信小程序配置
```json
{
"mp-weixin": {
"appid": "your-appid",
"setting": {
"urlCheck": false,
"es6": true,
"enhance": true,
"postcss": true,
"minified": true
},
"usingComponents": true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
}
}
```
### App 平台配置
```json
{
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
"modules": {},
"distribute": {
"android": {
"permissions": [
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
]
},
"ios": {},
"sdkConfigs": {}
}
}
}
```
### 支付宝小程序配置
```json
{
"mp-alipay": {
"usingComponents": true
}
}
```
### 百度小程序配置
```json
{
"mp-baidu": {
"usingComponents": true
}
}
```
### 字节跳动小程序配置
```json
{
"mp-toutiao": {
"usingComponents": true
}
}
```
### QQ 小程序配置
```json
{
"mp-qq": {
"usingComponents": true
}
}
```
### 完整配置示例
```json
{
"name": "uniappx-uview-pro-project",
"appid": "",
"description": "UniAppX + uView Pro 项目",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app"
},
"h5": {
"router": {
"mode": "hash"
},
"devServer": {
"port": 8080
}
},
"mp-weixin": {
"appid": "",
"setting": {
"urlCheck": false,
"es6": true,
"enhance": true,
"postcss": true,
"minified": true
},
"usingComponents": true
},
"mp-alipay": {
"usingComponents": true
},
"mp-baidu": {
"usingComponents": true
},
"mp-toutiao": {
"usingComponents": true
},
"mp-qq": {
"usingComponents": true
},
"quickapp": {},
"vueVersion": "3"
}
```
## 关键配置说明
### usingComponents
所有平台都需要设置 `"usingComponents": true`,以支持组件使用。
### transformPx
建议设置为 `false`,使用 rpx 单位进行响应式布局。
### vueVersion
UniAppX 使用 Vue 3,设置为 `"3"`
### TypeScript 支持
UniAppX 原生支持 TypeScript,无需额外配置。
## 注意事项
1. **usingComponents**:必须设置为 true
2. **平台差异**:不同平台有不同的配置项
3. **AppID**:小程序平台需要配置对应的 AppID
4. **权限配置**:根据功能需求配置相应权限
5. **版本号**:正确配置版本号和版本名称
6. **Vue 版本**UniAppX 使用 Vue 3
@@ -0,0 +1,292 @@
# Navigation | 导航
## Instructions
This example demonstrates how to handle navigation and routing with uView Pro in UniAppX.
### Key Concepts
- Page navigation with uView Pro components
- URL parameters passing
- Navigation lifecycle
- Custom navigation bar with uView Pro
- Tab bar navigation
### 使用 UniAppX 导航 API
#### 页面跳转
```typescript
// 保留当前页面,跳转到应用内的某个页面
uni.navigateTo({
url: '/pages/detail/detail?id=1'
})
// 关闭当前页面,跳转到应用内的某个页面
uni.redirectTo({
url: '/pages/login/login'
})
// 跳转到 tabBar 页面
uni.switchTab({
url: '/pages/index/index'
})
// 返回上一页面
uni.navigateBack({
delta: 1
})
```
#### 使用 uView Pro 按钮进行跳转
```vue
<template>
<view>
<u-button
type="primary"
@click="goToDetail"
>
跳转到详情页
</u-button>
</view>
</template>
<script setup lang="ts">
const goToDetail = () => {
uni.navigateTo({
url: '/pages/detail/detail?id=1'
})
}
</script>
```
### 使用 uView Pro 导航栏
#### 自定义导航栏
```json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationStyle": "custom"
}
}
]
}
```
页面中使用 uView Pro 导航栏:
```vue
<template>
<view>
<u-navbar
title="首页"
:border="true"
:back-icon-color="'#ffffff'"
:background="{
background: 'linear-gradient(45deg, #409EFF, #67C23A)'
}"
>
<template #right>
<u-icon name="more-dot-fill" color="#ffffff" @click="handleRight"></u-icon>
</template>
</u-navbar>
<!-- 页面内容 -->
</view>
</template>
<script setup lang="ts">
const handleRight = () => {
// 右侧按钮点击事件
}
</script>
```
### 使用 uView Pro 返回顶部
```vue
<template>
<view class="container">
<!-- 长列表内容 -->
<u-back-top :scroll-top="scrollTop"></u-back-top>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const scrollTop = ref(0)
const onPageScroll = (e: PageScrollOption) => {
scrollTop.value = e.scrollTop
}
</script>
```
### TabBar 导航
#### 使用原生 TabBar
```json
{
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#409EFF",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/user/user",
"text": "我的"
}
]
}
}
```
#### 使用 uView Pro TabBar 组件
```vue
<template>
<view>
<u-tabbar
:list="tabbarList"
:mid-button="true"
@change="tabbarChange"
></u-tabbar>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const tabbarList = ref([
{
iconPath: "static/tab-home.png",
selectedIconPath: "static/tab-home-current.png",
text: "首页",
pagePath: "/pages/index/index"
},
{
iconPath: "static/tab-user.png",
selectedIconPath: "static/tab-user-current.png",
text: "我的",
pagePath: "/pages/user/user"
}
])
const tabbarChange = (index: number) => {
const pagePath = tabbarList.value[index].pagePath
uni.switchTab({
url: pagePath
})
}
</script>
```
### 页面传参
#### 传递参数
```typescript
// 跳转并传递参数
uni.navigateTo({
url: '/pages/detail/detail?id=1&name=test'
})
```
#### 接收参数
```vue
<template>
<view>
<text>ID: {{ id }}</text>
<text>Name: {{ name }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
const id = ref('')
const name = ref('')
onLoad((options) => {
id.value = options.id as string
name.value = options.name as string
})
</script>
```
### 使用 uView Pro 搜索框导航
```vue
<template>
<view>
<u-search
placeholder="搜索内容"
v-model="keyword"
@search="handleSearch"
@custom="handleCustom"
></u-search>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const keyword = ref('')
const handleSearch = () => {
uni.navigateTo({
url: `/pages/search/search?keyword=${keyword.value}`
})
}
const handleCustom = () => {
// 自定义操作
}
</script>
```
### 导航栏返回按钮自定义
```vue
<template>
<view>
<u-navbar
title="详情页"
:back-icon-name="'arrow-left'"
@leftClick="handleBack"
></u-navbar>
</view>
</template>
<script setup lang="ts">
const handleBack = () => {
// 自定义返回逻辑
uni.navigateBack({
delta: 1
})
}
</script>
```
## 注意事项
1. **路径格式**:路径必须以 `/` 开头
2. **TabBar 跳转**:使用 `uni.switchTab` 跳转到 tabBar 页面
3. **参数传递**URL 参数需要编码
4. **页面栈**:注意页面栈限制(最多 10 层)
5. **返回按钮**:自定义导航栏需要自己处理返回逻辑
6. **TypeScript**:使用 TypeScript 类型定义,确保类型安全
@@ -0,0 +1,273 @@
# Pages Configuration | Pages 配置
## Instructions
This example demonstrates how to configure pages.json for uView Pro in UniAppX projects.
### Key Concepts
- Pages routing configuration
- Easycom component configuration
- Navigation bar configuration
- Tab bar configuration with uView Pro
- Custom navigation with uView Pro components
### 基本配置
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uview-pro/components/u-$1/u-$1.vue"
}
},
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "UniAppX",
"navigationBarBackgroundColor": "#ffffff",
"backgroundColor": "#f5f5f5"
}
}
```
### 使用 uView Pro 导航栏
#### 方式一:使用 uView Pro 导航栏组件
```json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "首页"
}
}
]
}
```
页面中使用 uView Pro 导航栏:
```vue
<template>
<view>
<u-navbar title="首页" :border="true"></u-navbar>
<!-- 页面内容 -->
</view>
</template>
<script setup lang="ts">
// UniAppX 使用 setup 语法
</script>
```
#### 方式二:使用原生导航栏
```json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"navigationBarBackgroundColor": "#409EFF",
"navigationBarTextStyle": "white"
}
}
]
}
```
### TabBar 配置
```json
{
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#409EFF",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "static/tab-home.png",
"selectedIconPath": "static/tab-home-current.png",
"text": "首页"
},
{
"pagePath": "pages/user/user",
"iconPath": "static/tab-user.png",
"selectedIconPath": "static/tab-user-current.png",
"text": "我的"
}
]
}
}
```
### 使用 uView Pro TabBar 组件
如果使用 uView Pro 的 TabBar 组件,可以禁用原生 TabBar:
```json
{
"tabBar": {
"custom": true,
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
}
]
}
}
```
### 页面样式配置
```json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"navigationBarBackgroundColor": "#409EFF",
"navigationBarTextStyle": "white",
"backgroundColor": "#f5f5f5",
"enablePullDownRefresh": true,
"onReachBottomDistance": 50
}
}
]
}
```
### 下拉刷新配置
```json
{
"pages": [
{
"path": "pages/list/list",
"style": {
"navigationBarTitleText": "列表",
"enablePullDownRefresh": true
}
}
]
}
```
页面中使用 uView Pro 下拉刷新:
```vue
<template>
<view>
<u-list @refresh="onRefresh" @loadmore="onLoadMore">
<!-- 列表内容 -->
</u-list>
</view>
</template>
<script setup lang="ts">
const onRefresh = () => {
// 刷新逻辑
}
const onLoadMore = () => {
// 加载更多逻辑
}
</script>
```
### 条件编译配置
不同平台可以有不同的配置:
```json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"// #ifdef H5": {
"navigationStyle": "custom"
},
"// #ifdef MP-WEIXIN": {
"navigationBarTitleText": "微信首页"
}
}
}
]
}
```
### 完整示例
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uview-pro/components/u-$1/u-$1.vue"
}
},
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"navigationBarBackgroundColor": "#409EFF",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/list/list",
"style": {
"navigationBarTitleText": "列表",
"enablePullDownRefresh": true
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "UniAppX",
"navigationBarBackgroundColor": "#ffffff",
"backgroundColor": "#f5f5f5"
},
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#409EFF",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
}
]
}
}
```
## 注意事项
1. **easycom 配置**:必须在 pages.json 中配置 easycom
2. **路径正确性**:确保组件路径正确
3. **样式配置**:合理配置页面样式,与 uView Pro 主题协调
4. **平台差异**:注意不同平台的配置差异
5. **性能优化**:合理配置下拉刷新和上拉加载
6. **TypeScript**UniAppX 使用 TypeScript,注意类型定义
@@ -0,0 +1,233 @@
# UniAppX API Integration | UniAppX API 集成
## Instructions
This example demonstrates how to use UniAppX APIs with uView Pro components.
### Key Concepts
- Using UniAppX APIs with uView Pro components
- Network requests for component data
- Storage API for component state
- System information for responsive components
- Lifecycle hooks with uView Pro components
- TypeScript type definitions
### Example: Network Request with uView Pro Components
```vue
<!-- pages/index/index.vue -->
<template>
<view>
<u-button type="primary" :loading="loading" @click="loadData">
加载数据
</u-button>
<u-list v-if="dataList.length > 0">
<u-list-item v-for="item in dataList" :key="item.id">
{{ item.name }}
</u-list-item>
</u-list>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref(false)
const dataList = ref([])
const loadData = () => {
loading.value = true
uni.request({
url: 'https://api.example.com/data',
method: 'GET',
success: (res) => {
dataList.value = res.data
},
fail: (err) => {
uni.showToast({
title: '加载失败',
icon: 'none'
})
},
complete: () => {
loading.value = false
}
})
}
</script>
```
### Example: Storage API with uView Pro Components
```vue
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const userInfo = ref({})
onMounted(() => {
// Load from cache first
uni.getStorage({
key: 'userInfo',
success: (res) => {
userInfo.value = res.data
},
fail: () => {
// Load from network
loadUserInfo()
}
})
})
const loadUserInfo = () => {
uni.request({
url: 'https://api.example.com/user',
success: (res) => {
userInfo.value = res.data
// Cache the data
uni.setStorage({
key: 'userInfo',
data: res.data
})
}
})
}
</script>
```
### Example: System Information for Responsive Components
```vue
<template>
<view>
<u-grid :col="gridCol">
<u-grid-item v-for="item in gridData" :key="item.id">
{{ item.name }}
</u-grid-item>
</u-grid>
</view>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const gridCol = ref(3)
const gridData = ref([])
onMounted(() => {
uni.getSystemInfo({
success: (res) => {
// Adjust grid columns based on screen width
if (res.windowWidth > 750) {
gridCol.value = 4
} else if (res.windowWidth > 500) {
gridCol.value = 3
} else {
gridCol.value = 2
}
}
})
})
</script>
```
### Example: Show Loading with uView Pro
```vue
<template>
<view>
<u-loading-page :loading="loading" />
<u-button @click="loadData">加载数据</u-button>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const loading = ref(false)
const loadData = () => {
loading.value = true
uni.request({
url: 'https://api.example.com/data',
success: (res) => {
// Handle data
},
complete: () => {
loading.value = false
}
})
}
</script>
```
### Example: Pull to Refresh with uView Pro
```json
// pages.json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"enablePullDownRefresh": true
}
}
]
}
```
```vue
<!-- pages/index/index.vue -->
<script setup lang="ts">
import { ref } from 'vue'
const dataList = ref([])
const onPullDownRefresh = () => {
loadData()
}
const loadData = () => {
uni.request({
url: 'https://api.example.com/data',
success: (res) => {
dataList.value = res.data
},
complete: () => {
uni.stopPullDownRefresh()
}
})
}
</script>
```
### Example: Navigation with uView Pro Components
```vue
<template>
<view>
<u-button type="primary" @click="goToDetail">查看详情</u-button>
</view>
</template>
<script setup lang="ts">
const goToDetail = () => {
uni.navigateTo({
url: '/pages/detail/detail?id=123'
})
}
</script>
```
### Key Points
- Use `uni.request()` for loading data with uView Pro components
- Use `uni.getStorage()` and `uni.setStorage()` for caching component state
- Use `uni.getSystemInfo()` for responsive component sizing
- Use `u-loading-page` component for loading states
- Handle pull-to-refresh for component data updates
- Use TypeScript types for better type safety
- Use Composition API and setup syntax (recommended for UniAppX)