Files
java-10561/docs/MOBILE_GENERATOR_EXAMPLE.md
2025-09-06 11:58:18 +08:00

124 lines
3.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 移动端页面文件生成器使用示例
## 快速开始
### 1. 配置生成器
`ShopGenerator` 为例,编辑 `src/test/java/com/gxwebsoft/generator/ShopGenerator.java`
```java
// 需要生成的表
private static final String[] TABLE_NAMES = new String[]{
"shop_goods", // 商品表
"shop_category", // 分类表
"shop_user_address" // 用户地址表
};
```
### 2. 运行生成器
```bash
# 在 IDE 中运行 ShopGenerator.main() 方法
# 或者使用命令行
cd /Users/gxwebsoft/JAVA/cms-java-code
mvn test-compile exec:java -Dexec.mainClass="com.gxwebsoft.generator.ShopGenerator"
```
### 3. 生成的文件结构
运行后会在 `/Users/gxwebsoft/VUE/template-10550/src/` 目录下生成:
```
src/
├── shop/
│ ├── goods/
│ │ ├── index.config.ts # 商品列表页面配置
│ │ ├── index.tsx # 商品列表页面组件
│ │ ├── add.config.ts # 商品新增/编辑页面配置
│ │ └── add.tsx # 商品新增/编辑页面组件
│ ├── category/
│ │ ├── index.config.ts
│ │ ├── index.tsx
│ │ ├── add.config.ts
│ │ └── add.tsx
│ └── userAddress/
│ ├── index.config.ts
│ ├── index.tsx
│ ├── add.config.ts
│ └── add.tsx
```
## 生成的文件内容示例
### index.config.ts
```typescript
export default definePageConfig({
navigationBarTitleText: '商品管理',
navigationBarTextStyle: 'black'
})
```
### index.tsx (列表页面)
```typescript
import {useState} from "react";
import Taro, {useDidShow} from '@tarojs/taro'
import {Button, Cell, CellGroup, Space, Empty, ConfigProvider, Divider} from '@nutui/nutui-react-taro'
import {Dongdong, ArrowRight, CheckNormal, Checked} from '@nutui/icons-react-taro'
import {View} from '@tarojs/components'
import {ShopGoods} from "@/api/shop/goods/model";
import {listShopGoods, removeShopGoods, updateShopGoods} from "@/api/shop/goods";
const ShopGoodsList = () => {
const [list, setList] = useState<ShopGoods[]>([])
// ... 其他逻辑
};
export default ShopGoodsList;
```
### add.config.ts
```typescript
export default definePageConfig({
navigationBarTitleText: '新增商品',
navigationBarTextStyle: 'black'
})
```
### add.tsx (新增/编辑页面)
```typescript
import {useEffect, useState, useRef} from "react";
import {useRouter} from '@tarojs/taro'
import {Button, Loading, CellGroup, Input, TextArea, Form} from '@nutui/nutui-react-taro'
import Taro from '@tarojs/taro'
import {View} from '@tarojs/components'
import {ShopGoods} from "@/api/shop/goods/model";
import {getShopGoods, updateShopGoods, addShopGoods} from "@/api/shop/goods";
const AddShopGoods = () => {
// ... 表单逻辑
};
export default AddShopGoods;
```
## 支持的模块
- **ShopGenerator**: 输出到 `/Users/gxwebsoft/VUE/template-10550/src/shop/`
- **CmsGenerator**: 输出到 `/Users/gxwebsoft/VUE/template-10550/src/cms/`
## 自定义配置
如需修改输出路径,可以编辑生成器中的常量:
```java
// UniApp文件输出目录
private static final String OUTPUT_LOCATION_UNIAPP = "/Users/gxwebsoft/VUE/template-10550";
```
## 注意事项
1. 生成前请确保目标目录存在
2. 建议先备份现有文件
3. 生成的代码可能需要根据具体业务调整
4. 确保对应的 API 文件已经生成