Files
gmTouringMiniApp/README.md
T
admin 7deba0dd37
AI Code Review / review (pull_request) Successful in 1s
更新 README.md
2026-07-31 08:37:16 +08:00

197 lines
12 KiB
Markdown
Raw 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.
# 光明文旅地图 POC
基于 uni-app、Vue 3、TypeScript 和 Pinia 开发的微信小程序 POC,用于验证深圳市光明区文旅资源地图探索、POI 数字化展示、文旅问答式偏好收集和行程规划。
当前范围包括地图拖动缩放、POI 分类、marker 与摘要联动、用户主动授权后的前台实时定位、POI 详情、AI 文旅助手交互和推荐行程展示。路线规划支持基于当前位置的快速规划,以及用户自选 2–8 个 POI、2–10 小时时长的自定义规划;本地规划器按时间预算动态排程,配置服务端后可由受控 AI 在审核白名单内推荐点位与顺序。当前不是道路级实时导航,也不包含打卡、登录或个人中心。
## 微信开发者工具
本仓库是 uni-app 源码工程,微信开发者工具不能直接编译 `src/**/*.vue`。正确流程是由 Vite/uni-app 持续编译,再由微信开发者工具加载编译产物:
```sh
corepack pnpm install --frozen-lockfile
corepack pnpm dev:mp-weixin
```
保持最后一条命令运行,然后在微信开发者工具中选择“导入项目”,目录选择本仓库根目录。根目录的 `project.config.json` 已设置:
```text
miniprogramRoot = dist/dev/mp-weixin/
```
因此 IDE 会识别 `dist/dev/mp-weixin/app.json` 及页面产物。第一次导入前必须等终端显示编译完成;真正生成 `app.json`、WXML 和 WXSS 的是持续运行的 `dev:mp-weixin``prepare:mp-weixin` 仅供需要预先创建空目录的工具使用,不能替代编译。
微信构建脚本已内置 macOS 文件监听兼容处理;如系统会话的监听句柄上限较低,不需要额外手动设置即可避免 `EMFILE` 编译失败。
macOS 已安装微信开发者工具时,也可在另一个终端执行 `corepack pnpm ide:mp-weixin` 打开根目录项目。
正式构建使用:
```sh
corepack pnpm build:mp-weixin
```
开发编译后可运行 `corepack pnpm verify:mp-weixin`,检查微信工程配置、启动页、五个业务页面、三个 tabBar 入口、六个图标和页面四件套是否完整。
生产产物位于 `dist/build/mp-weixin`。微信 AppID 通过未提交的 `.env.local``UNI_MP_WEIXIN_APPID` 配置;根目录 IDE 配置暂用 `touristappid`,避免误用模板中的其他项目身份。游客身份只能本地编译,真机预览或上传前必须同时把 `project.config.json``appid` 换成项目方确认的真实 AppID。详细说明见 [微信小程序构建与验收说明](./docs/微信小程序构建与验收说明.md)。
生产验收时可直接导入 `dist/build/mp-weixin`macOS 也可运行 `corepack pnpm ide:mp-weixin:build`。根目录始终用于开发模式,不会因执行生产构建而自动切换到 `dist/build/mp-weixin`
## 业务目录
```text
src/
├── pages/map/index.vue # 小程序首页:全域地图
├── pages/assistant/index.vue # AI 文旅助手:偏好快捷入口
├── pages/planner/index.vue # 行程偏好表单
├── pages/itinerary/index.vue # 推荐路线与地图展示
├── pages/poi/detail.vue # POI 详情
├── components/map/ # 地图筛选和摘要组件
├── components/poi/ # POI 图片、标签、状态和图集组件
├── components/travel/ # 行程点位展示组件
├── data/poi/ # POC 数据包与仓储
├── domain/poi/ # POI 类型、校验和选择器
├── domain/travel/ # 偏好、行程模型与本地规划规则
├── services/map/ # marker 数字 ID 适配
├── services/travel-assistant/ # 本地会话存储与可选远程服务适配
├── stores/modules/map.ts # 地图会话状态
└── static/ # 随包静态资源
```
不配置 `VITE_TRAVEL_ASSISTANT_API_BASE_URL` 时,小程序使用本地确定性 POC 规划器。配置受控后端地址后,服务端 AI 只接收偏好和不含坐标的 POI 白名单,返回推荐 ID、理由和顺序;当前位置、交通估算、时长适配及最终路线仍由小程序本机计算。服务端默认 `LLM_MODE=mock`,只有部署时设置 `LLM_MODE=real` 及模型凭据才会标记为真实 AI。微信公众平台还需配置 HTTPS 合法请求域名;API Key、模型凭证和高德 Web Service Key 均不得进入客户端环境变量或构建产物。
实时位置仅由用户主动触发,并只在地图页处于前台时持续更新。精确坐标保留在当前内存会话中,不写入匿名偏好或路线缓存,也不会发送给远程 AI 服务。iOS 真机使用前,需通过真实 AppID 在微信公众平台开通定位接口并完善《用户隐私保护指引》。
路由来自页面 SFC 的 `<route>`,由 UniPages 在编译时生成 `src/pages.json`;应用清单由 `manifest.config.ts` 生成 `src/manifest.json`。不要直接修改这两个生成文件,也不要让微信开发者工具读取 `src`IDE 只读取 `dist/dev/mp-weixin`
## POC 数据声明
当前随包 POI 是从 2026-07-30 高德 Web Service 离线候选快照中精选的 30 个 POC 点位,覆盖文化场馆、公园湿地、田园休闲、人文地标和绿道户外。高德只参与开发期数据发现,微信客户端读取本地冻结数据,不携带或实时调用 Web Service Key。
这些点位仍不代表光明区全域权威清单。简介和推荐指数为明确标注的 POC 待审核内容,开放时间统一待确认,封面为开发占位素材,均不满足正式内容或图片验收。
如需重新采集候选,请在本机临时注入 Web Service Key,输出默认写入系统临时目录:
```sh
AMAP_WEB_SERVICE_KEY=... corepack pnpm fetch:amap-pois
corepack pnpm test:amap-fetch
```
Key 不得写入源码、环境模板、文档、构建产物或日志;采集结果必须经过光明区过滤、去重和人工内容审核后才能固化。采集统计、字段映射与发布门槛见 [高德 POI 离线采集与数据快照说明](./docs/高德POI离线采集与数据快照说明.md)。
---
以下保留原模板的技术说明。
## 衍生项目
由于这个模板的业务场景非常的局限,下面提供了一个精心策划的列表。当然也欢迎你 PR 提供自己的项目!
###### 官方
- [unisave-lite](https://github.com/sunpm/unisave-lite) - unisave 的 js 版本
## 平台兼容性
在技术考量上,优先同时支持下列的平台,为兼容多个平台而舍弃一些实用的依赖插件。如发现下列平台环境开发编译出现问题,欢迎提 [issue](https://github.com/sunpm/unisave/issues/new) or [pr](https://github.com/sunpm/unisave/pulls)
| H5 | IOS | 安卓 | 微信小程序 | 字节小程序 | 快手小程序 | 支付宝小程序 | 百度小程序 |
|:--:| :--: | :--: | :--------: | :--------: | :--------: | :----------: | :----------: |
| √ | √ | √ | √ | √ | √ | √ | √ |
## 特性
- 🗂 [基于文件的路由](./src/pages)
- 📦 [组件自动化加载](./src/components)
- 🍍 [使用 Pinia 的状态管理](https://github.com/vuejs/pinia)
- 📑 [布局系统](./src/layouts)
- 🔥 使用 [新的 `<script setup>` 语法](https://github.com/vuejs/rfcs/pull/227)
- 📥 [API 自动加载](https://github.com/unplugin/unplugin-auto-import) - 直接使用 Composition API 无需引入
- 🎨 [UnoCSS](https://github.com/unocss/unocss) - 高性能且极具灵活性的即时原子化 CSS 引擎
- 🦾 TypeScript, 为什么不呢
- ⚙️ 使用 [Vitest](https://github.com/vitest-dev/vitest) 进行单元测试
## 预配置
### UI 框架
- [uview-plus](https://github.com/ijry/uview-plus) uview-plus3.0是基于uView2.x修改的vue3版本
- [UnoCSS](https://github.com/unocss/unocss) 高性能且极具灵活性的即时原子化 CSS 引擎
- [unocss-preset-uni](https://github.com/uni-helper/unocss-preset-uni) 专为 uni-app 打造的 UnoCSS 预设
### 插件
- [Pinia](https://github.com/vuejs/pinia) - 直接的, 类型安全的, 使用 Composition API 的轻便灵活的 Vue 状态管理
- [`pinia-plugin-persist-uni`](https://github.com/Allen-1998/pinia-plugin-persist-uni) - pinia 在 uniapp 中数据持久化插件
- Router
- [`@uni-helper/vite-plugin-uni-pages`](https://github.com/uni-helper/vite-plugin-uni-pages) - 在 Vite 驱动的 uni-app 上使用基于文件的路由系统
- [`vite-plugin-vue-layouts`](https://github.com/uni-helper/vite-plugin-uni-layouts) - 页面布局系统
- [`@uni-helper/uni-use`](https://github.com/uni-helper/uni-use) - 使用 `useRouter` 封装路由方法 -> `src/composables/useNavigation.ts`
- 请求
- [`@uni-helper/uni-network`](https://github.com/uni-helper/uni-network) - 为 uni-app 打造的基于 Promise 的 HTTP 客户端
- `services` 目录封装通用请求
- [`unplugin-vue-components`](https://github.com/antfu/unplugin-vue-components) - 自动加载组件
- [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) - 直接使用 Composition API 等,无需导入
- [`@uni-helper/vite-plugin-uni-manifest`](https://github.com/uni-helper/vite-plugin-uni-manifest) - 使用 TypeScript 编写 `uni-app``manifest.json`
### 编码风格
- 使用 Composition API 地 [`<script setup>` SFC 语法](https://cn.vuejs.org/api/sfc-script-setup.html)
- [ESLint](https://github.com/eslint/eslint) 配置为 [@antfu/eslint-config](https://github.com/antfu/eslint-config) - 单引号, 无分号...
- [@unocss/eslint-config](https://unocss.dev/integrations/eslint) - 用于UnoCSS的ESLint配置
- [@uni-helper/eslint-config](https://github.com/uni-helper/eslint-config) - 适用于 uni-app 的 Anthony's ESLint 配置预设
### 各平台类型定义文件
- [x] [uni-app 组件](https://www.npmjs.com/package/@uni-helper/uni-app-types)
- [x] [微信小程序](https://www.npmjs.com/package/miniprogram-api-typings)
- [x] [支付宝小程序](https://www.npmjs.com/package/@mini-types/alipay)
- [x] [字节小程序](https://www.npmjs.com/package/@douyin-microapp/typings)
- [x] [快手小程序](https://www.npmjs.com/package/ks-miniprogram-types/global)
- [x] [百度小程序](https://www.npmjs.com/package/@types/baidu-app)
## 环境建议
**Node >= 18**
**pnpm >= 8**
## 使用该模版
```sh
npx degit sunpm/unisave#main my-unisave
cd my-unisave
pnpm install
```
如果你没装过 pnpm, 可以先运行: `npm install -g pnpm`
## 清单
使用此模板时,请尝试按照清单正确更新您自己的信息
- [ ]`LICENSE` 中改变作者名或删除
- [ ]`manifest.config.ts` 中修改项目名称,描述,`appid`
- [ ]`.env.*` 更改环境变量
- [ ] 不需要部署到 netlify 请移除 `.netlify.toml` 文件
- [ ] 整理 README 并删除演示页面和组件
紧接着, 享受吧 :)
## 问题
怎么修改了 `pages.json` 没效果?
> 模版使用了 [`@uni-helper/vite-plugin-uni-pages`](https://github.com/uni-helper/vite-plugin-uni-pages)插件依赖,需要在`pages.config.ts`配置,编译会生成至`pages.json`,详细[点我看文档](https://github.com/uni-helper/vite-plugin-uni-pages)
怎么修改了 `manifest.json` 没效果?
> 模版使用了[`@uni-helper/vite-plugin-uni-manifest`](https://github.com/uni-helper/vite-plugin-uni-manifest)插件依赖,需要在`manifest.config.ts`配置,编译会生成至`manifest.json`,新增了自动生成项目配置信息的方法,详细[点击查看代码](./manifest.config.ts)
报错:`Uncaught SyntaxError: The requested module '/node_modules/vue-demi/lib/index.mjs?v=701bef9f' does not provide an export named 'hasInjectionContext'`
> pinia v2.1.X 版本要求 vue 3.3 或者 vue-demi latest ,如果 uniapp 的 vue 版本是 ^3.2.45,通过 pinia 降级到 2.0.X 可以运行和使用。
## 感谢
- [vitesse](https://github.com/antfu/vitesse)
- [uni-helper](https://github.com/uni-helper)
- [uni-vitesse](https://github.com/Ares-Chang/uni-vitesse)