Spaces:
Runtime error
Runtime error
Trae Assistant commited on
Commit ·
159b89e
0
Parent(s):
Clean project init
Browse files- .gitattributes +37 -0
- .gitignore +12 -0
- Dockerfile +32 -0
- README.md +69 -0
- babel.config.js +3 -0
- config/dev.js +3 -0
- config/index.js +3 -0
- config/prod.js +3 -0
- package.json +82 -0
- pnpm-lock.yaml +0 -0
- project.config.json +25 -0
- project.private.config.json +14 -0
- src/app.config.js +3 -0
- src/app.scss +16 -0
- src/app.tsx +18 -0
- src/index.html +19 -0
- src/pages/index/index.config.js +3 -0
- src/pages/index/index.scss +75 -0
- src/pages/index/index.tsx +53 -0
- tsconfig.json +30 -0
.gitattributes
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.js filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.map filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
dist
|
| 3 |
+
.DS_Store
|
| 4 |
+
.idea
|
| 5 |
+
.vscode
|
| 6 |
+
*.log
|
| 7 |
+
npm-debug.log*
|
| 8 |
+
yarn-debug.log*
|
| 9 |
+
yarn-error.log*
|
| 10 |
+
pnpm-debug.log*
|
| 11 |
+
tmp_home
|
| 12 |
+
.swc
|
Dockerfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 第一阶段:构建
|
| 2 |
+
FROM node:18-alpine AS builder
|
| 3 |
+
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# 安装 pnpm
|
| 7 |
+
RUN npm install -g pnpm
|
| 8 |
+
|
| 9 |
+
COPY package.json pnpm-lock.yaml ./
|
| 10 |
+
|
| 11 |
+
# 安装依赖
|
| 12 |
+
RUN pnpm install --frozen-lockfile
|
| 13 |
+
|
| 14 |
+
COPY . .
|
| 15 |
+
|
| 16 |
+
# 构建 H5
|
| 17 |
+
RUN pnpm run build:h5
|
| 18 |
+
|
| 19 |
+
# 第二阶段:运行
|
| 20 |
+
FROM nginx:alpine
|
| 21 |
+
|
| 22 |
+
# 复制构建产物到 Nginx 目录
|
| 23 |
+
COPY --from=builder /app/dist /usr/share/nginx/html
|
| 24 |
+
|
| 25 |
+
# 暴露端口 (Hugging Face Spaces 需要 7860)
|
| 26 |
+
EXPOSE 7860
|
| 27 |
+
|
| 28 |
+
# 替换 Nginx 默认端口 80 为 7860,并修改 root 目录
|
| 29 |
+
RUN sed -i 's/listen 80;/listen 7860;/' /etc/nginx/conf.d/default.conf && \
|
| 30 |
+
sed -i 's/root \/usr\/share\/nginx\/html;/root \/usr\/share\/nginx\/html; try_files $uri $uri\/ \/index.html;/' /etc/nginx/conf.d/default.conf
|
| 31 |
+
|
| 32 |
+
CMD ["nginx", "-g", "daemon off;"]
|
README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Taro 多端开发示例
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
short_description: Taro 多端开发示例
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Taro 多端开发示例
|
| 12 |
+
|
| 13 |
+
这是一个基于 Taro 4 的多端开发项目,支持微信小程序、H5 等多端运行。
|
| 14 |
+
|
| 15 |
+
## 功能特性
|
| 16 |
+
|
| 17 |
+
- **多端支持**: 一套代码同时生成小程序和 H5 应用。
|
| 18 |
+
- **H5 适配**: H5 页面限制最大宽度并居中显示,适配桌面端浏览器。
|
| 19 |
+
- **中文支持**: 全中文注释和文档。
|
| 20 |
+
- **Docker 部署**: 提供 Dockerfile 用于容器化部署。
|
| 21 |
+
|
| 22 |
+
## 快速开始
|
| 23 |
+
|
| 24 |
+
### 安装依赖
|
| 25 |
+
|
| 26 |
+
```bash
|
| 27 |
+
npm install
|
| 28 |
+
# 或者
|
| 29 |
+
pnpm install
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
### 开发环境运行
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
# 微信小程序
|
| 36 |
+
npm run dev:weapp
|
| 37 |
+
|
| 38 |
+
# H5
|
| 39 |
+
npm run dev:h5
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### 构建生产版本
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
# 微信小程序
|
| 46 |
+
npm run build:weapp
|
| 47 |
+
|
| 48 |
+
# H5
|
| 49 |
+
npm run build:h5
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## 目录结构
|
| 53 |
+
|
| 54 |
+
```
|
| 55 |
+
├── config # 编译配置
|
| 56 |
+
├── src # 源码目录
|
| 57 |
+
│ ├── pages # 页面文件
|
| 58 |
+
│ ├── app.config.ts # 全局配置
|
| 59 |
+
│ ├── app.scss # 全局样式
|
| 60 |
+
│ ├── app.tsx # 入口组件
|
| 61 |
+
│ └── index.html # H5 入口模板
|
| 62 |
+
├── Dockerfile # Docker 构建文件
|
| 63 |
+
└── package.json # 项目依赖
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## 注意事项
|
| 67 |
+
|
| 68 |
+
- H5 端使用了条件编译样式,确保在大屏设备上居中显示。
|
| 69 |
+
- 小程序端请使用微信开发者工具打开 `dist` 目录预览。
|
babel.config.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ae8cb37589eee8e7089c19e24229fc7e56d25b53068e145ef9912b5f9ad4c088
|
| 3 |
+
size 231
|
config/dev.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52d62ddf3ada598dee5bd20e3d886bd73307d448700f66c51dc3329ca3a849b5
|
| 3 |
+
size 241
|
config/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:503271efb20c025d5bc9ed8f504a3260d131a601ea04726c090863e32f9630f2
|
| 3 |
+
size 1754
|
config/prod.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0cb3f6408073944bb32f78cc02f7240bd73a5489e5a56f6ba6ef12a736f67b13
|
| 3 |
+
size 369
|
package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "taro-miniprogram",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"description": "A taro project",
|
| 6 |
+
"templateInfo": {
|
| 7 |
+
"name": "default",
|
| 8 |
+
"typescript": true,
|
| 9 |
+
"css": "sass"
|
| 10 |
+
},
|
| 11 |
+
"scripts": {
|
| 12 |
+
"build:weapp": "taro build --type weapp",
|
| 13 |
+
"build:swan": "taro build --type swan",
|
| 14 |
+
"build:alipay": "taro build --type alipay",
|
| 15 |
+
"build:tt": "taro build --type tt",
|
| 16 |
+
"build:h5": "taro build --type h5",
|
| 17 |
+
"build:rn": "taro build --type rn",
|
| 18 |
+
"build:qq": "taro build --type qq",
|
| 19 |
+
"build:jd": "taro build --type jd",
|
| 20 |
+
"build:quickapp": "taro build --type quickapp",
|
| 21 |
+
"dev:weapp": "npm run build:weapp -- --watch",
|
| 22 |
+
"dev:swan": "npm run build:swan -- --watch",
|
| 23 |
+
"dev:alipay": "npm run build:alipay -- --watch",
|
| 24 |
+
"dev:tt": "npm run build:tt -- --watch",
|
| 25 |
+
"dev:h5": "npm run build:h5 -- --watch",
|
| 26 |
+
"dev:rn": "npm run build:rn -- --watch",
|
| 27 |
+
"dev:qq": "npm run build:qq -- --watch",
|
| 28 |
+
"dev:jd": "npm run build:jd -- --watch",
|
| 29 |
+
"dev:quickapp": "npm run build:quickapp -- --watch"
|
| 30 |
+
},
|
| 31 |
+
"browserslist": [
|
| 32 |
+
"last 3 versions",
|
| 33 |
+
"Android >= 4.1",
|
| 34 |
+
"ios >= 8"
|
| 35 |
+
],
|
| 36 |
+
"author": "",
|
| 37 |
+
"dependencies": {
|
| 38 |
+
"@babel/runtime": "^7.7.7",
|
| 39 |
+
"@tarojs/components": "3.6.38",
|
| 40 |
+
"@tarojs/helper": "3.6.38",
|
| 41 |
+
"@tarojs/plugin-framework-react": "3.6.38",
|
| 42 |
+
"@tarojs/plugin-platform-alipay": "3.6.38",
|
| 43 |
+
"@tarojs/plugin-platform-h5": "3.6.38",
|
| 44 |
+
"@tarojs/plugin-platform-jd": "3.6.38",
|
| 45 |
+
"@tarojs/plugin-platform-qq": "3.6.38",
|
| 46 |
+
"@tarojs/plugin-platform-swan": "3.6.38",
|
| 47 |
+
"@tarojs/plugin-platform-tt": "3.6.38",
|
| 48 |
+
"@tarojs/plugin-platform-weapp": "3.6.38",
|
| 49 |
+
"@tarojs/react": "3.6.38",
|
| 50 |
+
"@tarojs/router": "3.6.38",
|
| 51 |
+
"@tarojs/runtime": "3.6.38",
|
| 52 |
+
"@tarojs/shared": "3.6.38",
|
| 53 |
+
"@tarojs/taro": "3.6.38",
|
| 54 |
+
"react": "^18.0.0",
|
| 55 |
+
"react-dom": "^18.0.0"
|
| 56 |
+
},
|
| 57 |
+
"devDependencies": {
|
| 58 |
+
"@babel/core": "^7.8.0",
|
| 59 |
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
|
| 60 |
+
"@tarojs/cli": "3.6.38",
|
| 61 |
+
"@tarojs/mini-runner": "3.6.38",
|
| 62 |
+
"@tarojs/service": "3.6.38",
|
| 63 |
+
"@tarojs/webpack5-runner": "3.6.38",
|
| 64 |
+
"@types/react": "^18.0.0",
|
| 65 |
+
"@types/webpack-env": "^1.13.6",
|
| 66 |
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
| 67 |
+
"@typescript-eslint/parser": "^6.0.0",
|
| 68 |
+
"babel-preset-taro": "3.6.38",
|
| 69 |
+
"eslint": "^8.0.0",
|
| 70 |
+
"eslint-config-taro": "3.6.38",
|
| 71 |
+
"eslint-plugin-import": "^2.12.0",
|
| 72 |
+
"eslint-plugin-react": "^7.8.2",
|
| 73 |
+
"eslint-plugin-react-hooks": "^4.2.0",
|
| 74 |
+
"react-refresh": "^0.18.0",
|
| 75 |
+
"stylelint": "^14.4.0",
|
| 76 |
+
"typescript": "^5.1.0",
|
| 77 |
+
"webpack": "^5.78.0"
|
| 78 |
+
},
|
| 79 |
+
"engines": {
|
| 80 |
+
"node": ">=16.20.0"
|
| 81 |
+
}
|
| 82 |
+
}
|
pnpm-lock.yaml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
project.config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"setting": {
|
| 3 |
+
"es6": true,
|
| 4 |
+
"postcss": true,
|
| 5 |
+
"minified": true,
|
| 6 |
+
"uglifyFileName": false,
|
| 7 |
+
"enhance": true,
|
| 8 |
+
"packNpmRelationList": [],
|
| 9 |
+
"babelSetting": {
|
| 10 |
+
"ignore": [],
|
| 11 |
+
"disablePlugins": [],
|
| 12 |
+
"outputPath": ""
|
| 13 |
+
},
|
| 14 |
+
"useCompilerPlugins": false,
|
| 15 |
+
"minifyWXML": true
|
| 16 |
+
},
|
| 17 |
+
"compileType": "miniprogram",
|
| 18 |
+
"simulatorPluginLibVersion": {},
|
| 19 |
+
"packOptions": {
|
| 20 |
+
"ignore": [],
|
| 21 |
+
"include": []
|
| 22 |
+
},
|
| 23 |
+
"appid": "wx12d032ccae2e5976",
|
| 24 |
+
"editorSetting": {}
|
| 25 |
+
}
|
project.private.config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"libVersion": "3.14.3",
|
| 3 |
+
"projectname": "taro-miniprogram",
|
| 4 |
+
"setting": {
|
| 5 |
+
"urlCheck": true,
|
| 6 |
+
"coverView": true,
|
| 7 |
+
"lazyloadPlaceholderEnable": false,
|
| 8 |
+
"skylineRenderEnable": false,
|
| 9 |
+
"preloadBackgroundData": false,
|
| 10 |
+
"autoAudits": false,
|
| 11 |
+
"showShadowRootInWxmlPanel": true,
|
| 12 |
+
"compileHotReLoad": true
|
| 13 |
+
}
|
| 14 |
+
}
|
src/app.config.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:98f11c305e6841ada419d17926d74b17db437573dfe29439aca97c4300cdf061
|
| 3 |
+
size 227
|
src/app.scss
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* app.scss */
|
| 2 |
+
|
| 3 |
+
/* 只有在 H5 环境下生效的样式 */
|
| 4 |
+
/* #ifdef H5 */
|
| 5 |
+
body {
|
| 6 |
+
background-color: #f7f8fa;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
#app {
|
| 10 |
+
max-width: 480px; /* 限制最大宽度 */
|
| 11 |
+
margin: 0 auto; /* 居中显示 */
|
| 12 |
+
min-height: 100vh;
|
| 13 |
+
background-color: #fff;
|
| 14 |
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); /* 添加阴影增加立体感 */
|
| 15 |
+
}
|
| 16 |
+
/* #endif */
|
src/app.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { Component, PropsWithChildren } from 'react'
|
| 2 |
+
import './app.scss'
|
| 3 |
+
|
| 4 |
+
class App extends Component<PropsWithChildren> {
|
| 5 |
+
|
| 6 |
+
componentDidMount () {}
|
| 7 |
+
|
| 8 |
+
componentDidShow () {}
|
| 9 |
+
|
| 10 |
+
componentDidHide () {}
|
| 11 |
+
|
| 12 |
+
render () {
|
| 13 |
+
// this.props.children 是将要会渲染的页面
|
| 14 |
+
return this.props.children
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
export default App
|
src/index.html
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
| 5 |
+
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
|
| 6 |
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 7 |
+
<meta name="apple-touch-fullscreen" content="yes">
|
| 8 |
+
<meta name="format-detection" content="telephone=no,address=no">
|
| 9 |
+
<meta name="apple-mobile-web-app-status-bar-style" content="white">
|
| 10 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
|
| 11 |
+
<title>Taro Demo</title>
|
| 12 |
+
<script>
|
| 13 |
+
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.userAgent.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=480){r.style.fontSize="25.6px"}else{if(a<=320){r.style.fontSize="17.0666px"}else{r.style.fontSize=a/750*40+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
|
| 14 |
+
</script>
|
| 15 |
+
</head>
|
| 16 |
+
<body>
|
| 17 |
+
<div id="app"></div>
|
| 18 |
+
</body>
|
| 19 |
+
</html>
|
src/pages/index/index.config.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5bbe3e2bb536936f6380fcafb33cc512a795867a5d5e511d6e6208aa0a9fb5ac
|
| 3 |
+
size 56
|
src/pages/index/index.scss
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.index {
|
| 2 |
+
display: flex;
|
| 3 |
+
flex-direction: column;
|
| 4 |
+
min-height: 100vh;
|
| 5 |
+
padding: 30px;
|
| 6 |
+
background-color: #f7f8fa;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
.header {
|
| 10 |
+
padding: 40px 0;
|
| 11 |
+
text-align: center;
|
| 12 |
+
|
| 13 |
+
.title {
|
| 14 |
+
font-size: 48px;
|
| 15 |
+
font-weight: bold;
|
| 16 |
+
color: #333;
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.content {
|
| 21 |
+
flex: 1;
|
| 22 |
+
background-color: #fff;
|
| 23 |
+
padding: 40px;
|
| 24 |
+
border-radius: 16px;
|
| 25 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
| 26 |
+
|
| 27 |
+
.info-box {
|
| 28 |
+
margin-top: 30px;
|
| 29 |
+
padding: 20px;
|
| 30 |
+
background-color: #f0f2f5;
|
| 31 |
+
border-radius: 8px;
|
| 32 |
+
display: flex;
|
| 33 |
+
align-items: center;
|
| 34 |
+
|
| 35 |
+
.platform-tag {
|
| 36 |
+
margin-left: 10px;
|
| 37 |
+
padding: 4px 12px;
|
| 38 |
+
border-radius: 4px;
|
| 39 |
+
font-size: 24px;
|
| 40 |
+
color: #fff;
|
| 41 |
+
|
| 42 |
+
&.h5 { background-color: #108ee9; }
|
| 43 |
+
&.weapp { background-color: #07c160; }
|
| 44 |
+
&.other { background-color: #999; }
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.description {
|
| 49 |
+
margin-top: 30px;
|
| 50 |
+
color: #666;
|
| 51 |
+
font-size: 28px;
|
| 52 |
+
line-height: 1.6;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.h5-tip {
|
| 56 |
+
margin-top: 40px;
|
| 57 |
+
padding: 20px;
|
| 58 |
+
border: 2px dashed #108ee9;
|
| 59 |
+
color: #108ee9;
|
| 60 |
+
border-radius: 8px;
|
| 61 |
+
font-size: 24px;
|
| 62 |
+
|
| 63 |
+
/* 演示样式条件编译:仅在 H5 下加粗 */
|
| 64 |
+
/* #ifdef H5 */
|
| 65 |
+
font-weight: bold;
|
| 66 |
+
/* #endif */
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.footer {
|
| 71 |
+
padding: 40px 0;
|
| 72 |
+
text-align: center;
|
| 73 |
+
color: #999;
|
| 74 |
+
font-size: 24px;
|
| 75 |
+
}
|
src/pages/index/index.tsx
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import { View, Text } from '@tarojs/components'
|
| 3 |
+
import Taro, { useLoad } from '@tarojs/taro'
|
| 4 |
+
import './index.scss'
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* 首页组件
|
| 8 |
+
* 展示 Taro 的跨端能力,包括 H5 和各种小程序
|
| 9 |
+
*/
|
| 10 |
+
export default function Index() {
|
| 11 |
+
// 页面加载时的回调
|
| 12 |
+
useLoad(() => {
|
| 13 |
+
console.log('页面已加载。')
|
| 14 |
+
})
|
| 15 |
+
|
| 16 |
+
// 获取当前运行平台
|
| 17 |
+
const platform = Taro.getEnv()
|
| 18 |
+
|
| 19 |
+
return (
|
| 20 |
+
<View className='index'>
|
| 21 |
+
<View className='header'>
|
| 22 |
+
<Text className='title'>你好,世界!</Text>
|
| 23 |
+
</View>
|
| 24 |
+
|
| 25 |
+
<View className='content'>
|
| 26 |
+
<Text>这是 Taro 演示页面,支持多端打包。</Text>
|
| 27 |
+
|
| 28 |
+
<View className='info-box'>
|
| 29 |
+
<Text>当前运行环境: </Text>
|
| 30 |
+
{/* 使用 JS 条件编译展示平台信息 */}
|
| 31 |
+
{process.env.TARO_ENV === 'h5' && <Text className='platform-tag h5'>H5 网页</Text>}
|
| 32 |
+
{process.env.TARO_ENV === 'weapp' && <Text className='platform-tag weapp'>微信小程序</Text>}
|
| 33 |
+
{process.env.TARO_ENV !== 'h5' && process.env.TARO_ENV !== 'weapp' && <Text className='platform-tag other'>{process.env.TARO_ENV}</Text>}
|
| 34 |
+
</View>
|
| 35 |
+
|
| 36 |
+
<View className='description'>
|
| 37 |
+
<Text>这是一个在 H5 和小程序上都能完美运行的项目。</Text>
|
| 38 |
+
</View>
|
| 39 |
+
|
| 40 |
+
{/* 仅在 H5 环境下显示的特别提示 */}
|
| 41 |
+
{process.env.TARO_ENV === 'h5' && (
|
| 42 |
+
<View className='h5-tip'>
|
| 43 |
+
<Text>提示:在 H5 端,页面已自动限制最大宽度并居中显示。</Text>
|
| 44 |
+
</View>
|
| 45 |
+
)}
|
| 46 |
+
</View>
|
| 47 |
+
|
| 48 |
+
<View className='footer'>
|
| 49 |
+
<Text>© 2025 Taro 汉化项目演示</Text>
|
| 50 |
+
</View>
|
| 51 |
+
</View>
|
| 52 |
+
)
|
| 53 |
+
}
|
tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"target": "es2017",
|
| 4 |
+
"module": "commonjs",
|
| 5 |
+
"removeComments": false,
|
| 6 |
+
"preserveConstEnums": true,
|
| 7 |
+
"moduleResolution": "node",
|
| 8 |
+
"experimentalDecorators": true,
|
| 9 |
+
"noImplicitAny": false,
|
| 10 |
+
"allowSyntheticDefaultImports": true,
|
| 11 |
+
"outDir": "lib",
|
| 12 |
+
"noUnusedLocals": true,
|
| 13 |
+
"noUnusedParameters": true,
|
| 14 |
+
"strictNullChecks": true,
|
| 15 |
+
"sourceMap": true,
|
| 16 |
+
"baseUrl": ".",
|
| 17 |
+
"rootDir": ".",
|
| 18 |
+
"jsx": "react-jsx",
|
| 19 |
+
"allowJs": true,
|
| 20 |
+
"resolveJsonModule": true,
|
| 21 |
+
"typeRoots": [
|
| 22 |
+
"node_modules/@types"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"include": [
|
| 26 |
+
"./src",
|
| 27 |
+
"./types"
|
| 28 |
+
],
|
| 29 |
+
"compileOnSave": false
|
| 30 |
+
}
|