1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-13 00:50: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,183 @@
# Easycom Configuration | Easycom 配置
## Instructions
This example demonstrates how to configure easycom in UniAppX for automatic uView Pro component import.
### Key Concepts
- Easycom automatic component import
- Component path configuration
- Autoscan configuration
- Custom component rules
- TypeScript type inference
### 基本配置
`pages.json` 中配置 easycom
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uview-pro/components/u-$1/u-$1.vue"
}
}
}
```
### 配置说明
- `autoscan: true`:开启自动扫描
- `custom`:自定义规则
- `^u-(.*)`:匹配以 `u-` 开头的组件名
- `uview-pro/components/u-$1/u-$1.vue`:组件路径,`$1` 是匹配的内容
### 使用示例
配置后,可以直接使用组件,无需引入:
```vue
<template>
<view>
<!-- 直接使用无需 import -->
<u-button type="primary">按钮</u-button>
<u-input v-model="value" placeholder="请输入"></u-input>
<u-form :model="form">
<u-form-item label="用户名">
<u-input v-model="form.username"></u-input>
</u-form-item>
</u-form>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
const form = ref({
username: ''
})
</script>
```
### 完整 pages.json 示例
```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 安装在不同位置,需要调整路径:
#### npm 安装
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "node_modules/uview-pro/components/u-$1/u-$1.vue"
}
}
}
```
#### uni_modules 安装
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uni_modules/uview-pro/components/u-$1/u-$1.vue"
}
}
}
```
### 禁用 easycom
如果不想使用 easycom,可以手动引入:
```vue
<template>
<view>
<u-button>按钮</u-button>
</view>
</template>
<script setup lang="ts">
import uButton from 'uview-pro/components/u-button/u-button.vue'
</script>
```
### TypeScript 类型支持
使用 easycom 时,TypeScript 类型会自动推断:
```vue
<template>
<view>
<u-button type="primary" @click="handleClick">按钮</u-button>
</view>
</template>
<script setup lang="ts">
const handleClick = () => {
console.log('按钮被点击')
}
</script>
```
### 验证配置
创建测试页面验证 easycom 是否生效:
```vue
<template>
<view class="container">
<u-button type="primary" @click="test">测试 Easycom</u-button>
</view>
</template>
<script setup lang="ts">
const test = () => {
console.log('Easycom 配置成功!')
}
</script>
```
如果按钮正常显示且无报错,说明 easycom 配置成功。
## 注意事项
1. **路径必须正确**:确保组件路径与实际安装位置一致
2. **组件名称**uView Pro 组件都以 `u-` 开头
3. **重启项目**:修改 easycom 配置后需要重启项目
4. **优先级**easycom 优先级高于手动引入
5. **性能**:easycom 不会影响性能,按需加载组件
6. **TypeScript**TypeScript 类型会自动推断,无需额外配置
@@ -0,0 +1,243 @@
# Installation | 安装
## Instructions
This example demonstrates how to install uView Pro in UniAppX projects via DCloud plugin marketplace (plugin ID: 24633).
### Key Concepts
- Installing uView Pro via DCloud plugin marketplace
- Installing via npm
- UniAppX project structure setup
- TypeScript (.uts) file configuration
- Composition API and setup syntax
- SCSS style configuration
### Example: Install via DCloud Plugin Marketplace (Recommended)
**Official Plugin**: https://ext.dcloud.net.cn/plugin?id=24633
```bash
# 1. Open HBuilderX
# 2. Open UniAppX project
# 3. Go to Tools -> Plugin Installation
# 4. Search for "uView Pro" or enter plugin ID: 24633
# 5. Click "Import Plugin"
# 6. Plugin will be installed to uni_modules/uview-pro directory
```
**Project Structure After Installation:**
```
project-root/
├── uni_modules/
│ └── uview-pro/
│ ├── components/
│ ├── index.scss
│ └── theme.scss
├── pages/
├── App.vue
├── main.uts
├── pages.json
└── manifest.json
```
### Example: Install via npm
```bash
# Install uView Pro package
npm install uview-pro
# Or using yarn
yarn add uview-pro
```
**Import in main.uts:**
```typescript
// main.uts
import { createSSRApp } from 'vue'
import App from './App.vue'
import uViewPro from 'uview-pro'
export function createApp() {
const app = createSSRApp(App)
app.use(uViewPro)
return {
app
}
}
```
### Example: Manual Installation
```bash
# 1. Download from DCloud plugin marketplace
# 2. Extract to project root
# 3. Ensure uni_modules/uview-pro/ exists
```
## UniAppX 项目配置
### 1. 在 main.uts 中引入
```typescript
// main.uts
import { createSSRApp } from 'vue'
import App from './App.vue'
import uViewPro from 'uview-pro'
export function createApp() {
const app = createSSRApp(App)
app.use(uViewPro)
return {
app
}
}
```
### 2. 在 App.vue 中引入样式
```vue
<!-- App.vue -->
<style lang="scss">
/* 引入 uView Pro 基础样式 */
@import "uview-pro/index.scss";
</style>
```
### 3. 在 uni.scss 中引入主题变量(可选)
```scss
/* uni.scss */
@import "uview-pro/theme.scss";
```
### 4. 配置 easycom(重要)
`pages.json` 中配置 easycom,实现组件自动引入:
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uview-pro/components/u-$1/u-$1.vue"
}
},
"pages": [
// ... 页面配置
]
}
```
### 5. 验证安装
创建测试页面 `pages/index/index.vue`
```vue
<template>
<view class="container">
<u-button type="primary">uView Pro 按钮</u-button>
</view>
</template>
<script setup lang="ts">
// UniAppX 使用 setup 语法
</script>
<style lang="scss" scoped>
.container {
padding: 20rpx;
}
</style>
```
如果按钮正常显示,说明安装成功。
## 目录结构
安装后的 UniAppX 项目结构:
```
uniappx-project/
├── uni_modules/
│ └── uview-pro/ # uView Pro 插件
│ ├── components/ # 组件目录
│ ├── index.scss # 基础样式
│ └── theme.scss # 主题变量
├── pages/ # 页面目录
├── static/ # 静态资源
├── App.vue # 应用入口
├── main.uts # 主入口文件(UniAppX 使用 .uts
├── pages.json # 页面配置
├── manifest.json # 应用配置
└── uni.scss # 全局样式变量
```
## UniAppX 特性
### TypeScript 支持
UniAppX 使用 TypeScript,需要类型定义:
```typescript
// main.uts
import { createSSRApp } from 'vue'
import App from './App.vue'
import uViewPro from 'uview-pro'
export function createApp() {
const app = createSSRApp(App)
app.use(uViewPro)
return {
app
}
}
```
### Setup 语法
UniAppX 推荐使用 Composition API 和 setup 语法:
```vue
<template>
<view>
<u-button type="primary" @click="handleClick">按钮</u-button>
</view>
</template>
<script setup lang="ts">
const handleClick = () => {
console.log('按钮被点击')
}
</script>
```
### Example: Verify Installation
```vue
<!-- pages/index/index.vue -->
<template>
<view>
<u-button type="primary">uView Pro Button</u-button>
</view>
</template>
<script setup lang="ts">
// UniAppX uses setup syntax
</script>
<style lang="scss" scoped>
// SCSS is required
</style>
```
### Key Points
- Install via DCloud plugin marketplace for easiest integration
- Plugin ID: 24633
- Component will be in `uni_modules/uview-pro/components/`
- Configure easycom in pages.json for automatic import
- Register uView Pro in main.uts (TypeScript)
- Import SCSS styles in App.vue
- Use setup syntax and Composition API (recommended for UniAppX)
- Test installation by using components in a page
@@ -0,0 +1,263 @@
# Project Setup | 项目设置
## Instructions
This example demonstrates how to set up a UniAppX project to work with uView Pro.
### Key Concepts
- UniAppX project structure
- TypeScript (.uts) file configuration
- Composition API and setup syntax
- SCSS style configuration
- Component directory organization
### 项目结构
标准的 UniAppX + uView Pro 项目结构:
```
uniappx-project/
├── uni_modules/
│ └── uview-pro/ # uView Pro 插件
├── pages/ # 页面目录
│ ├── index/
│ │ └── index.vue
│ └── ...
├── components/ # 自定义组件
├── static/ # 静态资源
├── utils/ # 工具函数
├── App.vue # 应用入口
├── main.uts # 主入口文件(UniAppX 使用 .uts
├── pages.json # 页面配置
├── manifest.json # 应用配置
└── uni.scss # 全局样式变量
```
### App.vue 配置
```vue
<template>
<view id="app">
<!-- 应用根组件 -->
</view>
</template>
<script setup lang="ts">
// UniAppX 使用 setup 语法
</script>
<style lang="scss">
/* 引入 uView Pro 基础样式 */
@import "uview-pro/index.scss";
/* 全局样式 */
page {
background-color: #f5f5f5;
}
</style>
```
### main.uts 配置
UniAppX 使用 TypeScript,主入口文件为 `main.uts`
```typescript
// main.uts
import { createSSRApp } from 'vue'
import App from './App.vue'
import uViewPro from 'uview-pro'
export function createApp() {
const app = createSSRApp(App)
app.use(uViewPro)
return {
app
}
}
```
### pages.json 配置
```json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uview-pro/components/u-$1/u-$1.vue"
}
},
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"navigationStyle": "default",
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "UniAppX",
"navigationBarBackgroundColor": "#ffffff",
"backgroundColor": "#f5f5f5"
},
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#3cc51f",
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "static/tab-home.png",
"selectedIconPath": "static/tab-home-current.png",
"text": "首页"
}
]
}
}
```
### uni.scss 配置
```scss
/* uni.scss */
/* 引入 uView Pro 主题变量 */
@import "uview-pro/theme.scss";
/* 自定义全局变量 */
$uni-color-primary: #409EFF;
$uni-bg-color: #f5f5f5;
```
### manifest.json 配置要点
```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
}
}
```
## 开发环境配置
### HBuilderX 配置
1. **启用 TypeScript 支持**
- 创建 UniAppX 项目时自动启用 TypeScript
- 确保 HBuilderX 版本支持 UniAppX
2. **启用 SCSS 支持**
- 创建项目时选择支持 SCSS
- 或在项目设置中启用 SCSS 编译
### TypeScript 配置
UniAppX 项目自动包含 TypeScript 配置,无需额外配置。
### 条件编译
使用条件编译处理平台差异:
```vue
<template>
<view>
<!-- #ifdef H5 -->
<view>H5 平台特有内容</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view>微信小程序特有内容</view>
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<view>App 平台特有内容</view>
<!-- #endif -->
</view>
</template>
<script setup lang="ts">
// #ifdef H5
// H5 平台特定代码
// #endif
// #ifdef MP-WEIXIN
// 微信小程序特定代码
// #endif
// #ifdef APP-PLUS
// App 平台特定代码
// #endif
</script>
```
## 验证配置
创建测试页面验证配置是否正确:
```vue
<template>
<view class="container">
<u-navbar title="测试页面"></u-navbar>
<view class="content">
<u-button type="primary" @click="test">测试按钮</u-button>
<u-toast ref="uToast"></u-toast>
</view>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const uToast = ref()
const test = () => {
uToast.value?.show({
message: '配置成功!'
})
}
</script>
<style lang="scss" scoped>
.container {
min-height: 100vh;
background-color: #f5f5f5;
}
.content {
padding: 20rpx;
}
</style>
```
## 注意事项
1. **TypeScript 支持**UniAppX 使用 TypeScript,确保类型正确
2. **Setup 语法**:推荐使用 Composition API 和 setup 语法
3. **easycom 必须配置**:否则需要手动引入每个组件
4. **SCSS 必须支持**uView Pro 依赖 SCSS
5. **路径正确性**:确保引入路径正确
6. **版本兼容**:确保 UniAppX 和 uView Pro 版本兼容
7. **平台测试**:在不同平台测试功能