chore: 移除已弃用的 miniprogram(uni-app 微信小程序)
- 删除 miniprogram/ 整个工程(28 个跟踪文件:uni-app 页面、接口封装、构建配置) - README 去掉小程序目录、7304 端口、进度条目与用法链接 - cors 中间件与 CORS_ORIGINS 示例注释不再以「小程序 H5 预览」举例 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
a4a0b18440
commit
4586fe5217
@ -1,12 +1,11 @@
|
||||
# 云仓视频溯源系统
|
||||
|
||||
前后端分离 + 一个浏览器扩展 + 一个 Windows 本机软件(WPF)+ 一个微信小程序 + 一个 Android 设备端,六个目录:
|
||||
前后端分离 + 一个浏览器扩展 + 一个 Windows 本机软件(WPF)+ 一个 Android 设备端,五个目录:
|
||||
|
||||
```
|
||||
packService/
|
||||
├── backend/ # Egg.js 3(纯 API;MySQL + Redis)
|
||||
├── frontend/ # Vite + Vue3 + TypeScript(用户端 SPA)
|
||||
├── miniprogram/ # uni-app + Vue3 + TypeScript(微信小程序:抽屉登录(个人中心为整页登录)/ 协议弹窗 / 首页统计 / 扫码记录 / 我的)
|
||||
├── extension/ # Chrome MV3 扩展:注入第三方 WMS 页面,把运单号加工成溯源入口
|
||||
├── desktop/ # WPF 本机软件:HTTP 17300(查询/唤起/下载)+ WS 17301(拉通道/预览/云台)+ yuncang:// 启动协议
|
||||
└── AndroidStation/ # Android 设备端:UDP 48899 被桌面端发现 + TCP 8087 推送 USB 扫码结果
|
||||
@ -19,7 +18,6 @@ packService/
|
||||
| 前端 dev(Vite) | **7301** | `cd frontend && npm run dev` |
|
||||
| 前端 preview(dist) | **7302** | `cd frontend && npm run preview` |
|
||||
| 后端 dev | **7300** | `cd backend && npm run dev` |
|
||||
| 小程序 H5 预览(可选) | **7304** | `cd miniprogram && npm run dev:h5` |
|
||||
| 本机软件(WPF,只监听 loopback) | **17300**(HTTP)/ **17301**(WebSocket) | `cd desktop && dotnet run`(详见 [`desktop/README.md`](desktop/README.md)) |
|
||||
| 扩展自测页(可选) | **7310** | `npx --yes http-server extension/test -p 7310` |
|
||||
|
||||
@ -52,7 +50,6 @@ packService/
|
||||
|
||||
- [x] 目录拆分为 `backend/` + `frontend/`
|
||||
- [x] 前端脚手架(Vite + Vue3 + TS)跑通,登录页走通 `/api/web/auth/*`
|
||||
- [x] 小程序脚手架 `miniprogram/`(uni-app + Vue3 + TS):账号密码登录 / 首页统计 / 扫码记录 / 个人中心;登录前需阅读并同意协议(版本落库);不强制登录(启动不弹窗,点功能或 401 才提示,符合小程序审核)
|
||||
- [x] 浏览器扩展 `extension/`(MV3,零构建):注入第三方 WMS 页面,在运单号**旁边**渲染「查看打包视频」按钮 → 点按钮打开溯源页
|
||||
- [x] **后端去掉服务端渲染**:删除 `app/controller/page/`、`app/view/`、`app/lib/page.js`、nunjucks / session / CSRF 配置与依赖,后端只剩 JSON 接口
|
||||
- [x] 页面全部迁移到前端:登录 / 注册 / 找回密码 / 扫码 / 扫码确认 / 首页统计 / 设备管理 / 扫码记录 / 个人中心 / 测试页(仅开发构建,生产不打包)
|
||||
@ -73,7 +70,7 @@ packService/
|
||||
- 配置见 `WX_GATEWAY_APP_KEY` / `WX_GATEWAY_APP_SECRET`(不配则扫码入口提示「未开通」),
|
||||
网关管理台的「服务端通知地址」要配成 `https://<域名>/api/wechat-gateway/notify`
|
||||
- [x] **移除自建的微信授权表(2026-10-29)**:微信侧接入收敛到登录网关后,删除 `wechat_oauth`(公众号网页授权)与
|
||||
`wechat_mp_accounts`(小程序一键登录)两张表及其代码/接口/环境变量;小程序改为账号密码登录
|
||||
`wechat_mp_accounts`(小程序一键登录)两张表及其代码/接口/环境变量
|
||||
(详见 [`backend/README.md`](backend/README.md) 的「已下线:小程序微信一键登录」)
|
||||
- [x] **平台管理员 + 平台管理台(2026-10-29)**:新表 `admin_members`(平台管理员名单,`INTERNAL_ADMIN_IDS` 为内置/救急入口);
|
||||
平台管理员登录后左侧菜单多出「平台管理」:**主体管理**(所有主体 + 直接改授权到期时间:选时间或顺延)、
|
||||
@ -85,7 +82,7 @@ packService/
|
||||
版本号读 `/download/version.json` 与 `/download/android_client/version.json`,没发布过安装包时按钮置灰
|
||||
- [ ] 扩展:目标地址换成真实打包视频页(现在指向百度占位)—— 在扩展「设置」里改「目标地址模板」即可,需要真实地址
|
||||
|
||||
后端接口细节见 [`backend/README.md`](backend/README.md),扩展用法见 [`extension/README.md`](extension/README.md),小程序用法见 [`miniprogram/README.md`](miniprogram/README.md)。
|
||||
后端接口细节见 [`backend/README.md`](backend/README.md),扩展用法见 [`extension/README.md`](extension/README.md)。
|
||||
|
||||
## 前端页面风格约定(`frontend/`)
|
||||
|
||||
|
||||
@ -3,9 +3,8 @@
|
||||
/**
|
||||
* 跨域(CORS)
|
||||
*
|
||||
* 为什么需要:小程序 H5 预览(7304)与前端 SPA 一样用浏览器发起请求,
|
||||
* 但接口现在**统一走后端绝对地址**(不再经 Vite 同源代理),所以后端必须回 CORS 头。
|
||||
* 小程序真机 / 桌面端 / 扩展走的是原生请求,不受同源策略限制,这段对它们没有影响。
|
||||
* 为什么需要:前端 SPA 用浏览器发起请求,接口走后端绝对地址(不经 Vite 同源代理)时需要 CORS;
|
||||
* 桌面端 / 安卓端 / 扩展走的是原生请求,不受同源策略限制,这段对它们没有影响。
|
||||
*
|
||||
* 配置(`config.cors`):
|
||||
* - `origins`: `'*'`(默认)或逗号分隔白名单(env `CORS_ORIGINS`),白名单外返回不带 CORS 头;
|
||||
|
||||
@ -29,7 +29,7 @@ module.exports = (appInfo) => {
|
||||
config.middleware = [ 'cors', 'errorHandler', 'frontend' ];
|
||||
|
||||
// ==================== 跨域 ====================
|
||||
// `'*'` = 回显任意 Origin;需要收紧就设 CORS_ORIGINS=http://127.0.0.1:7304,https://trace.example.com
|
||||
// `'*'` = 回显任意 Origin;需要收紧就设 CORS_ORIGINS=http://127.0.0.1:7301,https://trace.example.com
|
||||
config.cors = {
|
||||
enable: !/^(0|false|no|off)$/i.test(String(env.CORS_ENABLE === undefined ? 'true' : env.CORS_ENABLE)),
|
||||
origins: String(env.CORS_ORIGINS || '*')
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# 后端接口地址(小程序没有同源代理,必须是完整地址)
|
||||
# 本地联调:复制成 .env.development(已被根 .gitignore 忽略)
|
||||
# 真机/发布:必须是 https 域名,并在小程序后台「开发设置 → 服务器域名」里配好 request 合法域名
|
||||
VITE_API_BASE=http://127.0.0.1:7300
|
||||
@ -1,115 +0,0 @@
|
||||
# 云仓视频溯源 · 微信小程序
|
||||
|
||||
uni-app + Vue3 + TypeScript + Vite 的微信小程序,复用后端 `backend/` 的用户端接口(`/api/web/*`)。
|
||||
当前是基础脚手架:底部抽屉登录、首页统计、扫码记录、个人中心。
|
||||
|
||||
## 运行
|
||||
|
||||
```bash
|
||||
cd miniprogram
|
||||
npm install
|
||||
npm run dev:mp-weixin # 产物在 dist/dev/mp-weixin,watch 模式
|
||||
```
|
||||
|
||||
微信开发者工具 → 导入项目 → 选 `miniprogram/dist/dev/mp-weixin`,AppID 用你自己的(或测试号)。
|
||||
本地联调时在「详情 → 本地设置」勾选 **不校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书**。
|
||||
|
||||
发布:
|
||||
|
||||
```bash
|
||||
npm run build:mp-weixin # 产物在 dist/build/mp-weixin
|
||||
```
|
||||
|
||||
小程序 AppID 填在 [`src/manifest.json`](src/manifest.json) 的 `mp-weixin.appid`(`appid` 留空时开发者工具会让你选测试号)。
|
||||
|
||||
## 后端地址
|
||||
|
||||
小程序没有 Vite 同源代理,必须请求完整地址。`src/api/client.ts` 的规则:
|
||||
|
||||
- 配了 `VITE_API_BASE` → 用它;
|
||||
- 没配 → 默认 `http://127.0.0.1:7300`(本机后端)。
|
||||
|
||||
本地需要改地址时,复制 [`.env.example`](.env.example) 为 `.env.development`(已被根 `.gitignore` 忽略):
|
||||
|
||||
```ini
|
||||
VITE_API_BASE=http://127.0.0.1:7300
|
||||
```
|
||||
|
||||
发布时用 `.env.production` 指向 **https** 域名,并在小程序后台「开发设置 → 服务器域名」把它加入 `request` 合法域名
|
||||
(微信要求域名已备案,且不能带端口/路径)。
|
||||
|
||||
## 登录时机(小程序审核要求)
|
||||
|
||||
**不允许一打开就强制登录**,登录只在「用户点了需要登录的功能」或「接口真的返回 401」时出现。
|
||||
策略集中在 [`src/config/auth.ts`](src/config/auth.ts):
|
||||
|
||||
| 配置 | 默认 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `pageGuards` | `['pages/records/index']` | 必须登录才能使用的页面 |
|
||||
| `autoPromptOnEnter` | `true` | 进入 `pageGuards` 页面时弹一次登录(同一次进入不重复弹) |
|
||||
| `apiRequireAuth` | `true` | 业务接口是否必须登录 |
|
||||
| `promptOnUnauthorized` | `true` | 请求拿到 401 时是否自动弹登录 |
|
||||
|
||||
配套行为:
|
||||
|
||||
- `App.vue` 启动时**不做任何拦截**;首页对游客展示功能介绍 + 「登录 / 注册」按钮;
|
||||
- 个人中心游客态展示欢迎卡片,点「登录 / 注册」跳整页登录(不自动跳转);
|
||||
- 扫码记录属于 `pageGuards`:切到该 tab 才弹抽屉(关掉后本页不再自动弹,可点「登录查看」);
|
||||
- 游客页面不会发需要登录的业务请求,所以不会出现「一进来就 401 → 弹窗」;
|
||||
- 令牌过期(401)会清登录态并按 `promptOnUnauthorized` 弹登录。
|
||||
|
||||
## 页面与接口
|
||||
|
||||
| 页面 | 路径 | 游客可用 | 登录后接口 |
|
||||
| --- | --- | --- | --- |
|
||||
| 首页(统计) | `pages/index/index` | 是(功能介绍) | `GET /api/web/subjects`、`GET /api/web/stats` |
|
||||
| 扫码记录 | `pages/records/index` | 否(`pageGuards`) | `GET /api/web/records`、`GET /api/web/devices` |
|
||||
| 个人中心 | `pages/profile/index` | 是(欢迎卡片) | `GET /api/web/me`、`PUT /api/web/me`、`GET /api/web/subjects` |
|
||||
| 登录(整页兜底) | `pages/login/index` | 是 | `GET /api/agreements/current`、`POST /api/web/auth/login` |
|
||||
| 登录抽屉 | `components/LoginDrawer.vue` | 是 | 同上(与整页登录共用 `LoginPanel`) |
|
||||
|
||||
登录没有独立页面:它是一张从底部弹出的抽屉卡片([`src/components/LoginDrawer.vue`](src/components/LoginDrawer.vue)),
|
||||
在首页 / 记录两个 tab 页各引入一次,状态由 [`src/composables/useLoginDrawer.ts`](src/composables/useLoginDrawer.ts) 共享。
|
||||
**不会一进入小程序就弹出**:只有点页面里的「登录」按钮、进入需要登录的页面、或接口返回 401 时才弹(见上面「登录时机」)。
|
||||
打开时隐藏原生 tabBar,登录成功后关闭并留在当前页。
|
||||
|
||||
登录面板([`src/components/LoginPanel.vue`](src/components/LoginPanel.vue))只有一种登录方式:
|
||||
|
||||
- **账号登录**:用户名 / 手机号 / 邮箱 + 密码。
|
||||
- 小程序的「微信一键登录」(`uni.login()` → `POST /api/web/auth/wechat/login`)已下线:后端移除了
|
||||
`wechat_mp_accounts` 表与整套小程序 code2Session 逻辑,微信侧接入统一走 Web 端的「微信登录网关」(扫码登录 / 绑定微信)。
|
||||
|
||||
H5 预览时接口走 Vite 的 `/api` 反代(`vite.config.ts` 的 `server.proxy`),不需要后端开 CORS。
|
||||
|
||||
**个人中心例外**:那里的「登录」跳整页登录 [`src/pages/login/index.vue`](src/pages/login/index.vue)(`navigateTo`),
|
||||
用于抽屉在某些真机 / 低版本基础库上弹不出来的兜底;登录成功 `navigateBack` 回到个人中心并自动刷新。
|
||||
个人中心页没有挂 `LoginDrawer`,401 也统一跳到整页登录(`useLoginDrawer` 里按当前路由判断)。
|
||||
|
||||
表单逻辑只有一份:[`src/components/LoginPanel.vue`](src/components/LoginPanel.vue)(抽屉与整页登录共用)。
|
||||
|
||||
登录前必须同意协议:
|
||||
|
||||
- 面板只显示一行「我已阅读并同意《用户协议》v1.0.0」,点协议名弹出**独立的协议弹窗**
|
||||
[`src/components/AgreementDialog.vue`](src/components/AgreementDialog.vue)(不占登录面板高度);
|
||||
- 弹窗正文是 `scroll-view`,**「我已阅读并同意」按钮在正文末尾**,不滑到最后点不到;
|
||||
- 点完才打勾,勾选前登录按钮不可用;每次打开登录面都会清空勾选,需要重新阅读同意;
|
||||
- 登录请求带 `client: 'mini_program'` + `agreements: [{ code, versionId }]`,后端校验版本并写入 `user_agreements`;
|
||||
- 服务端返回 428 `agreement_required`(协议版本更新)时,面板会自动拉新正文并要求重新勾选。
|
||||
|
||||
## 约定
|
||||
|
||||
- 令牌与用户存在本地:`packs_token` / `packs_user`;当前主体 id 存在 `packs_subject_id`。
|
||||
- 业务接口都会带 `Authorization: Bearer <user JWT>` 和 `X-Subject-Id`(见 `src/api/client.ts`)。
|
||||
- 401 清令牌,并按 `AUTH_POLICY.promptOnUnauthorized` 弹登录(不跳页);`400 subject_required` / `403 subject_expired` 由页面自己提示。
|
||||
- 登录 / 退出后 `authVersion` 自增,页面 `watch` 它刷新或清空数据。
|
||||
- 主体(租户)是设备与扫码记录的归属单位:小程序里只做切换,创建主体仍在 Web 端。
|
||||
- 微信扫码登录 / 绑定微信走 Web 端的登录网关(`/api/web/auth/wechat-gateway/*`),小程序里没有扫码入口;视频回放仍未接入。
|
||||
|
||||
## H5 预览(可选,方便不装开发者工具时看页面)
|
||||
|
||||
```bash
|
||||
npm run dev:h5 # http://127.0.0.1:7304
|
||||
npm run build:h5
|
||||
```
|
||||
|
||||
H5 页面同样直连 `VITE_API_BASE`(后端未开 CORS,浏览器跨域会被拦;仅用于看静态样式)。
|
||||
@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<script>
|
||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||
CSS.supports('top: constant(a)'))
|
||||
document.write(
|
||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
<title>云仓视频溯源</title>
|
||||
<!--preload-links-->
|
||||
<!--app-context-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"><!--app-html--></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
7981
miniprogram/package-lock.json
generated
7981
miniprogram/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,29 +0,0 @@
|
||||
{
|
||||
"name": "pack-service-miniprogram",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "云仓视频溯源 · 微信小程序(uni-app + Vue3 + TypeScript)",
|
||||
"scripts": {
|
||||
"dev:mp-weixin": "uni -p mp-weixin",
|
||||
"build:mp-weixin": "uni build -p mp-weixin",
|
||||
"dev:h5": "uni",
|
||||
"build:h5": "uni build",
|
||||
"type-check": "vue-tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-app": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-components": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-h5": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
|
||||
"vue": "^3.4.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dcloudio/types": "^3.4.8",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-5020420260813003",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-5020420260813003",
|
||||
"@vue/runtime-core": "^3.4.21",
|
||||
"typescript": "^6.0.3",
|
||||
"vite": "5.2.8",
|
||||
"vue-tsc": "^3.3.13"
|
||||
}
|
||||
}
|
||||
@ -1,127 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 应用入口
|
||||
*
|
||||
* ⚠️ 启动时**不做任何登录拦截 / 弹窗**:微信审核要求用户能先浏览小程序,
|
||||
* 登录只在「点了需要登录的功能」或「接口返回 401」时才唤起(见 `config/auth.ts`)。
|
||||
*/
|
||||
</script>
|
||||
|
||||
<style>
|
||||
page {
|
||||
--brand: #2563eb;
|
||||
--brand-dark: #1d4ed8;
|
||||
--text: #1f2430;
|
||||
--text-muted: #6b7280;
|
||||
--border: #e5e7eb;
|
||||
--bg: #f6f7fb;
|
||||
--card: #ffffff;
|
||||
--danger: #dc2626;
|
||||
--ok: #16a34a;
|
||||
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
|
||||
}
|
||||
|
||||
.page {
|
||||
padding: 24rpx;
|
||||
/* navigationStyle=custom:没有内置标题栏,自己让出状态栏高度(H5 下为 0,小程序里是真实高度) */
|
||||
padding-top: calc(24rpx + var(--status-bar-height, 0px));
|
||||
padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--card);
|
||||
border-radius: 16rpx;
|
||||
padding: 28rpx;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(31, 36, 48, 0.04);
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 88rpx;
|
||||
border-radius: 12rpx;
|
||||
background: var(--brand);
|
||||
color: #fff;
|
||||
font-size: 30rpx;
|
||||
border: none;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.btn[disabled] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
background: #eef2ff;
|
||||
color: var(--brand);
|
||||
}
|
||||
|
||||
.btn::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.field {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: block;
|
||||
margin-bottom: 10rpx;
|
||||
color: var(--text-muted);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
height: 84rpx;
|
||||
padding: 0 24rpx;
|
||||
border: 1rpx solid var(--border);
|
||||
border-radius: 12rpx;
|
||||
background: #fff;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: var(--text-muted);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 18rpx 24rpx;
|
||||
border-radius: 12rpx;
|
||||
margin-bottom: 24rpx;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background: #fef2f2;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.alert-ok {
|
||||
background: #f0fdf4;
|
||||
color: var(--ok);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.row-between {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
</style>
|
||||
@ -1,105 +0,0 @@
|
||||
/**
|
||||
* 接口客户端:统一带上 `Authorization: Bearer <JWT>` + `X-Subject-Id`,
|
||||
* 统一处理 `{ ok, data, message }` 结构。
|
||||
*
|
||||
* 后端约定(见 backend/README):
|
||||
* - 成功 `{ ok: true, data }`;失败 `{ ok: false, message, status? }`
|
||||
* - 401 = 令牌缺失/过期/无效 → 清掉本地令牌并回登录页
|
||||
* - 400 `status='subject_required'` = 没选主体;403 `status='subject_expired'` = 主体到期
|
||||
*/
|
||||
import { clearSession, getToken } from '@/composables/useAuth';
|
||||
import { openLoginDrawer } from '@/composables/useLoginDrawer';
|
||||
import { getStoredSubjectId } from '@/composables/subjectStorage';
|
||||
import { AUTH_POLICY } from '@/config/auth';
|
||||
|
||||
/**
|
||||
* 地址规则:**统一用绝对地址**(H5 预览与小程序一致,不再依赖 Vite 的同源代理)
|
||||
* - 默认本机后端;本地联调 / 发布前用 `VITE_API_BASE` 换成正式域名(如 `https://trace.example.com`)
|
||||
* - 后端已开 CORS(`config.cors`),H5 直接跨域调用即可
|
||||
*/
|
||||
const BASE = (import.meta.env.VITE_API_BASE || 'http://127.0.0.1:7300').replace(/\/+$/, '');
|
||||
|
||||
export interface ApiResult<T> {
|
||||
ok: boolean;
|
||||
data?: T;
|
||||
message?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
code?: string;
|
||||
|
||||
constructor(message: string, status: number, code?: string) {
|
||||
super(message);
|
||||
this.name = 'ApiError';
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
interface RequestOptions {
|
||||
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||
body?: unknown;
|
||||
/** 带上令牌(默认带;登录等公开接口可传 false) */
|
||||
auth?: boolean;
|
||||
}
|
||||
|
||||
/** 401 = 令牌失效:清掉本地登录态;是否弹登录由 `config/auth.ts` 决定(游客浏览时不打扰) */
|
||||
function handleUnauthorized(): void {
|
||||
clearSession();
|
||||
if (AUTH_POLICY.apiRequireAuth && AUTH_POLICY.promptOnUnauthorized) openLoginDrawer();
|
||||
}
|
||||
|
||||
function request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
||||
const { method = 'GET', body, auth = true } = options;
|
||||
const header: Record<string, string> = {};
|
||||
if (body !== undefined) header['Content-Type'] = 'application/json';
|
||||
|
||||
if (auth) {
|
||||
const token = getToken();
|
||||
if (token) header.Authorization = `Bearer ${token}`;
|
||||
// 业务接口都靠这个 header 限定操作范围(没有主体时不带,后端回 subject_required)
|
||||
const subjectId = getStoredSubjectId();
|
||||
if (subjectId) header['X-Subject-Id'] = String(subjectId);
|
||||
}
|
||||
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${BASE}${path}`,
|
||||
method,
|
||||
header,
|
||||
data: body === undefined ? undefined : (body as Record<string, unknown>),
|
||||
timeout: 15000,
|
||||
success: (res) => {
|
||||
const payload = (res.data || null) as ApiResult<T> | null;
|
||||
|
||||
if (res.statusCode === 401 && auth) {
|
||||
handleUnauthorized();
|
||||
reject(new ApiError(payload?.message || '登录已过期,请重新登录', 401, payload?.status));
|
||||
return;
|
||||
}
|
||||
if (res.statusCode < 200 || res.statusCode >= 300 || !payload || payload.ok === false) {
|
||||
reject(new ApiError(payload?.message || `请求失败(${res.statusCode})`, res.statusCode, payload?.status));
|
||||
return;
|
||||
}
|
||||
resolve(payload.data as T);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(new ApiError(`网络异常:${err.errMsg || '无法连接服务器'}`, 0));
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const api = {
|
||||
baseUrl: BASE,
|
||||
get: <T>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>) =>
|
||||
request<T>(path, { ...options, method: 'GET' }),
|
||||
post: <T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>) =>
|
||||
request<T>(path, { ...options, method: 'POST', body }),
|
||||
put: <T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>) =>
|
||||
request<T>(path, { ...options, method: 'PUT', body }),
|
||||
del: <T>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method' | 'body'>) =>
|
||||
request<T>(path, { ...options, method: 'DELETE', body }),
|
||||
};
|
||||
@ -1,122 +0,0 @@
|
||||
/**
|
||||
* 接口数据模型(与后端 `backend/app/controller/web/*` 的返回一一对应)
|
||||
*
|
||||
* 时间字段后端返回 ISO 字符串,展示时用 `utils/format.ts` 格式化。
|
||||
*/
|
||||
|
||||
/** 分页返回 */
|
||||
export interface Paged<T> {
|
||||
list: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
/** 当前用户 */
|
||||
export interface CurrentUser {
|
||||
id: number;
|
||||
username?: string | null;
|
||||
nickname?: string | null;
|
||||
email?: string | null;
|
||||
phone?: string | null;
|
||||
avatar?: string | null;
|
||||
}
|
||||
|
||||
/** 主体(租户) */
|
||||
export interface SubjectItem {
|
||||
id: number;
|
||||
name: string;
|
||||
adminUserId: number;
|
||||
expireAt: string;
|
||||
status: number;
|
||||
remark?: string | null;
|
||||
/** 1 管理员 2 成员 */
|
||||
role: number;
|
||||
memberName?: string | null;
|
||||
memberCount?: number;
|
||||
expired: boolean;
|
||||
}
|
||||
|
||||
/** 设备(中控) */
|
||||
export interface Device {
|
||||
id: number;
|
||||
sn: string;
|
||||
name?: string | null;
|
||||
vendor?: string | null;
|
||||
model?: string | null;
|
||||
status: number;
|
||||
lastSeenAt?: string | null;
|
||||
}
|
||||
|
||||
/** 扫码记录 */
|
||||
export interface ScanRecord {
|
||||
id: number;
|
||||
scannerId: number;
|
||||
channelId: string;
|
||||
barcode: string;
|
||||
scanTime: string;
|
||||
reportedAt?: string | null;
|
||||
deviceSn?: string | null;
|
||||
deviceName?: string | null;
|
||||
}
|
||||
|
||||
/** 首页统计 */
|
||||
export interface Stats {
|
||||
deviceCount: number;
|
||||
channelCount: number;
|
||||
recordCount: number;
|
||||
latestRecord: {
|
||||
id: number;
|
||||
barcode: string;
|
||||
channelId: string;
|
||||
deviceSn?: string | null;
|
||||
scanTime: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
/** 登录 / 注册接口返回 */
|
||||
export interface LoginResult {
|
||||
token: string;
|
||||
tokenType: string;
|
||||
expiresIn?: number | string;
|
||||
user: CurrentUser;
|
||||
subjects?: SubjectItem[];
|
||||
/** 登录时落库的协议同意记录(只有校验/记录过才有) */
|
||||
agreements?: AgreementConsentRecord[];
|
||||
}
|
||||
|
||||
/** 协议当前版本 */export interface AgreementVersion {
|
||||
id: number;
|
||||
version: string;
|
||||
title: string;
|
||||
summary?: string;
|
||||
content: string;
|
||||
contentType?: 'text' | 'html' | string;
|
||||
publishedAt?: string | null;
|
||||
effectiveAt?: string | null;
|
||||
}
|
||||
|
||||
/** 协议(含当前版本正文) */
|
||||
export interface AgreementItem {
|
||||
id: number;
|
||||
code: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
required: boolean;
|
||||
sortNo?: number;
|
||||
version: AgreementVersion;
|
||||
}
|
||||
|
||||
/** 提交给登录接口的同意项 */
|
||||
export interface AgreementAcceptance {
|
||||
code: string;
|
||||
versionId: number;
|
||||
}
|
||||
|
||||
/** 登录接口返回的同意记录 */
|
||||
export interface AgreementConsentRecord {
|
||||
code: string;
|
||||
versionId: number;
|
||||
version: string;
|
||||
agreedAt: string;
|
||||
}
|
||||
@ -1,109 +0,0 @@
|
||||
/**
|
||||
* web 用户端接口(`/api/web/*`)—— 只碰「自己的」数据,令牌由 `api/client.ts` 统一带上
|
||||
*
|
||||
* 后端返回 `{ ok:true, data }`,失败会抛 `ApiError`(401 会自动清令牌并回登录页)。
|
||||
*/
|
||||
import { api } from '@/api/client';
|
||||
import type {
|
||||
AgreementAcceptance,
|
||||
AgreementItem,
|
||||
CurrentUser,
|
||||
Device,
|
||||
LoginResult,
|
||||
Paged,
|
||||
ScanRecord,
|
||||
Stats,
|
||||
SubjectItem,
|
||||
} from '@/api/types';
|
||||
|
||||
/** 拼查询串(小程序环境不一定有 URLSearchParams) */
|
||||
function buildQuery(params: Record<string, string | number | undefined>): string {
|
||||
const parts: string[] = [];
|
||||
for (const key of Object.keys(params)) {
|
||||
const value = params[key];
|
||||
if (value === undefined || value === '') continue;
|
||||
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
||||
}
|
||||
return parts.length ? `?${parts.join('&')}` : '';
|
||||
}
|
||||
|
||||
/** 当前有效的协议 + 已发布版本(公开接口,登录前读) */
|
||||
export function fetchAgreements(): Promise<{ agreements: AgreementItem[] }> {
|
||||
return api.get<{ agreements: AgreementItem[] }>('/api/agreements/current', { auth: false });
|
||||
}
|
||||
|
||||
/** 账号密码登录(小程序登录必须带上已同意的协议版本) */
|
||||
export function login(
|
||||
account: string,
|
||||
password: string,
|
||||
agreements: AgreementAcceptance[] = [],
|
||||
client = 'mini_program',
|
||||
): Promise<LoginResult> {
|
||||
return api.post<LoginResult>(
|
||||
'/api/web/auth/login',
|
||||
{ account, password, agreements, client },
|
||||
{ auth: false },
|
||||
);
|
||||
}
|
||||
|
||||
/** 当前登录用户 */
|
||||
export function fetchMe(): Promise<CurrentUser> {
|
||||
return api.get<CurrentUser>('/api/web/me');
|
||||
}
|
||||
|
||||
/** 改自己的资料 */
|
||||
export function updateMe(body: {
|
||||
nickname?: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
}): Promise<CurrentUser> {
|
||||
return api.put<CurrentUser>('/api/web/me', body);
|
||||
}
|
||||
|
||||
/** 可进入的主体(租户)列表 */
|
||||
export function fetchSubjects(): Promise<{ list: SubjectItem[]; trialDays: number }> {
|
||||
return api.get<{ list: SubjectItem[]; trialDays: number }>('/api/web/subjects');
|
||||
}
|
||||
|
||||
/** 首页统计(当前主体) */
|
||||
export function fetchStats(): Promise<Stats> {
|
||||
return api.get<Stats>('/api/web/stats');
|
||||
}
|
||||
|
||||
/** 我的设备列表 */
|
||||
export function fetchDevices(params: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
keyword?: string;
|
||||
status?: number | '';
|
||||
} = {}): Promise<Paged<Device>> {
|
||||
const query = buildQuery({
|
||||
page: params.page,
|
||||
pageSize: params.pageSize,
|
||||
keyword: params.keyword?.trim(),
|
||||
status: params.status,
|
||||
});
|
||||
return api.get<Paged<Device>>(`/api/web/devices${query}`);
|
||||
}
|
||||
|
||||
/** 我的扫码记录 */
|
||||
export function fetchRecords(params: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
deviceId?: number | '';
|
||||
channelId?: string;
|
||||
barcode?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
} = {}): Promise<Paged<ScanRecord>> {
|
||||
const query = buildQuery({
|
||||
page: params.page,
|
||||
pageSize: params.pageSize,
|
||||
deviceId: params.deviceId,
|
||||
channelId: params.channelId,
|
||||
barcode: params.barcode,
|
||||
startTime: params.startTime,
|
||||
endTime: params.endTime,
|
||||
});
|
||||
return api.get<Paged<ScanRecord>>(`/api/web/records${query}`);
|
||||
}
|
||||
@ -1,163 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 协议弹窗:独立的居中弹窗(不占登录面板高度)
|
||||
*
|
||||
* 「我已阅读并同意」按钮放在正文**末尾**,必须滑到正文最后才点得到。
|
||||
* 弹窗自带遮罩,层级高于登录抽屉(抽屉 z-index 999 → 这里 1000)。
|
||||
*/
|
||||
import type { AgreementItem } from '@/api/types';
|
||||
|
||||
defineProps<{
|
||||
/** 是否显示 */
|
||||
show: boolean;
|
||||
/** 要阅读的协议(为空时不渲染面板) */
|
||||
agreement: AgreementItem | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:show', value: boolean): void;
|
||||
(e: 'agree'): void;
|
||||
}>();
|
||||
|
||||
function close() {
|
||||
emit('update:show', false);
|
||||
}
|
||||
|
||||
function agree() {
|
||||
emit('agree');
|
||||
emit('update:show', false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="agreement-root" :class="{ 'is-open': show && agreement }">
|
||||
<view class="agreement-mask" @click="close" />
|
||||
|
||||
<view v-if="agreement" class="agreement-panel">
|
||||
<view class="agreement-head">
|
||||
<view class="agreement-titles">
|
||||
<view class="agreement-title">{{ agreement.name }}</view>
|
||||
<view class="agreement-sub">版本 {{ agreement.version.version }}</view>
|
||||
</view>
|
||||
<view class="agreement-close" @click="close">×</view>
|
||||
</view>
|
||||
|
||||
<scroll-view scroll-y class="agreement-body">
|
||||
<rich-text
|
||||
v-if="agreement.version.contentType === 'html'"
|
||||
class="agreement-text"
|
||||
:nodes="agreement.version.content"
|
||||
/>
|
||||
<text v-else class="agreement-text">{{ agreement.version.content }}</text>
|
||||
|
||||
<button class="btn agreement-agree" @click="agree">我已阅读并同意</button>
|
||||
<view class="agreement-tip">请滑动阅读至正文末尾后点击上方按钮</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agreement-root {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.agreement-root.is-open {
|
||||
visibility: visible;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.agreement-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background: rgba(15, 23, 42, 0.5);
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.agreement-root.is-open .agreement-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.agreement-panel {
|
||||
position: absolute;
|
||||
left: 48rpx;
|
||||
right: 48rpx;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: 76vh;
|
||||
background: #fff;
|
||||
border-radius: 24rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 24rpx 64rpx rgba(15, 23, 42, 0.28);
|
||||
}
|
||||
|
||||
.agreement-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 28rpx 28rpx 20rpx;
|
||||
border-bottom: 1rpx solid #eef0f4;
|
||||
}
|
||||
|
||||
.agreement-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.agreement-sub {
|
||||
margin-top: 4rpx;
|
||||
color: var(--text-muted);
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.agreement-close {
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
margin: -10rpx -10rpx 0 0;
|
||||
border-radius: 50%;
|
||||
color: #9ca3af;
|
||||
font-size: 40rpx;
|
||||
line-height: 52rpx;
|
||||
text-align: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.agreement-body {
|
||||
height: 52vh;
|
||||
padding: 24rpx 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.agreement-text {
|
||||
display: block;
|
||||
color: #4b5563;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.agreement-agree {
|
||||
margin-top: 32rpx;
|
||||
}
|
||||
|
||||
.agreement-tip {
|
||||
margin: 16rpx 0 8rpx;
|
||||
color: var(--text-muted);
|
||||
font-size: 22rpx;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@ -1,119 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 登录底部抽屉:需要登录时就地弹出,登录完留在当前页
|
||||
*
|
||||
* 用法:tab 页面引一次 `<login-drawer />`,状态由 `composables/useLoginDrawer.ts` 共享。
|
||||
* 打开时隐藏原生 tabBar(否则遮罩盖不住底部 tab),关闭时再显示。
|
||||
* 表单与协议逻辑都在 `LoginPanel`(与页面版登录共用)。
|
||||
*/
|
||||
import { watch } from 'vue';
|
||||
import LoginPanel from '@/components/LoginPanel.vue';
|
||||
import {
|
||||
closeLoginDrawer,
|
||||
loginDrawerVisible,
|
||||
} from '@/composables/useLoginDrawer';
|
||||
|
||||
function syncTabBar(open: boolean) {
|
||||
if (open) uni.hideTabBar({ animation: false, fail: () => {} });
|
||||
else uni.showTabBar({ animation: false, fail: () => {} });
|
||||
}
|
||||
|
||||
watch(loginDrawerVisible, syncTabBar, { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="login-drawer-root" :class="{ 'is-open': loginDrawerVisible }">
|
||||
<view class="login-drawer-mask" @click="closeLoginDrawer" />
|
||||
|
||||
<view class="login-drawer">
|
||||
<view class="login-drawer__handle" />
|
||||
|
||||
<view class="login-drawer__head">
|
||||
<view>
|
||||
<view class="login-drawer__title">登录</view>
|
||||
<view class="login-drawer__sub">登录后查看设备与扫码记录</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<login-panel
|
||||
:active="loginDrawerVisible"
|
||||
show-cancel
|
||||
@success="closeLoginDrawer"
|
||||
@cancel="closeLoginDrawer"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.login-drawer-root {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
visibility: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.login-drawer-root.is-open {
|
||||
visibility: visible;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.login-drawer-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background: rgba(15, 23, 42, 0.45);
|
||||
opacity: 0;
|
||||
transition: opacity 0.22s ease;
|
||||
}
|
||||
|
||||
.login-drawer-root.is-open .login-drawer-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.login-drawer {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: #fff;
|
||||
border-radius: 28rpx 28rpx 0 0;
|
||||
padding: 16rpx 40rpx calc(32rpx + env(safe-area-inset-bottom));
|
||||
box-shadow: 0 -8rpx 40rpx rgba(15, 23, 42, 0.12);
|
||||
transform: translateY(100%);
|
||||
transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
|
||||
}
|
||||
|
||||
.login-drawer-root.is-open .login-drawer {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.login-drawer__handle {
|
||||
width: 72rpx;
|
||||
height: 8rpx;
|
||||
margin: 0 auto 24rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #e2e6ee;
|
||||
}
|
||||
|
||||
.login-drawer__head {
|
||||
margin-bottom: 28rpx;
|
||||
}
|
||||
|
||||
.login-drawer__title {
|
||||
font-size: 38rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.login-drawer__sub {
|
||||
margin-top: 4rpx;
|
||||
color: var(--text-muted);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
</style>
|
||||
@ -1,341 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 登录表单面板:抽屉(`LoginDrawer`)与页面版登录(`pages/login`)共用
|
||||
*
|
||||
* - 只有账号密码登录(微信一键登录已下线:微信侧接入统一走 Web 端的扫码登录网关);
|
||||
* - 协议正文单独弹窗(`AgreementDialog`),面板里只留「我已阅读并同意《xx》」一行;
|
||||
* - 登录必须先同意当前协议版本;
|
||||
* - 每次 `active` 变成 true 都清空勾选并重拉协议(同意记录按「登录」这一动作落库);
|
||||
* - 登录成功只抛 `success`,关抽屉 / 返回上一页交给使用方。
|
||||
*/
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
import { ApiError } from '@/api/client';
|
||||
import { fetchAgreements, login } from '@/api/web';
|
||||
import type { AgreementItem, LoginResult } from '@/api/types';
|
||||
import AgreementDialog from '@/components/AgreementDialog.vue';
|
||||
import { setSession } from '@/composables/useAuth';
|
||||
import { applySubjects } from '@/composables/useSubject';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
/** 面板是否处于打开状态(true 时重置勾选并加载协议) */
|
||||
active?: boolean;
|
||||
/** 是否显示右上角关闭按钮 */
|
||||
showCancel?: boolean;
|
||||
}>(), {
|
||||
active: true,
|
||||
showCancel: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'success'): void;
|
||||
(e: 'cancel'): void;
|
||||
}>();
|
||||
|
||||
const form = reactive({ account: '', password: '' });
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
const tip = ref('');
|
||||
|
||||
/** 协议:当前版本 + 是否已阅读同意(按 code 记录) */
|
||||
const agreements = ref<AgreementItem[]>([]);
|
||||
const agreementsLoading = ref(false);
|
||||
const agreementsError = ref('');
|
||||
const accepted = ref<Record<string, boolean>>({});
|
||||
|
||||
/** 正在阅读的协议(null = 弹窗关闭) */
|
||||
const reading = ref<AgreementItem | null>(null);
|
||||
const readerVisible = ref(false);
|
||||
|
||||
const requiredAgreements = computed(() => agreements.value.filter(item => item.required));
|
||||
const allAgreed = computed(() => requiredAgreements.value.every(item => accepted.value[item.code]));
|
||||
const agreementsReady = computed(
|
||||
() => !agreementsLoading.value && !agreementsError.value && allAgreed.value,
|
||||
);
|
||||
|
||||
const canSubmit = computed(
|
||||
() => Boolean(form.account.trim() && form.password) && agreementsReady.value,
|
||||
);
|
||||
|
||||
async function loadAgreements() {
|
||||
agreementsLoading.value = true;
|
||||
agreementsError.value = '';
|
||||
try {
|
||||
const data = await fetchAgreements();
|
||||
agreements.value = (data.agreements || []).filter(item => item && item.version);
|
||||
} catch (err) {
|
||||
agreements.value = [];
|
||||
agreementsError.value = err instanceof ApiError ? err.message : '协议加载失败';
|
||||
} finally {
|
||||
agreementsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开协议弹窗(已同意时再点一次=重新阅读,不会取消勾选) */
|
||||
function openAgreement(item: AgreementItem) {
|
||||
error.value = '';
|
||||
reading.value = item;
|
||||
readerVisible.value = true;
|
||||
}
|
||||
|
||||
/** 弹窗里点过「我已阅读并同意」→ 打勾 */
|
||||
function onAgreed() {
|
||||
const item = reading.value;
|
||||
if (!item) return;
|
||||
accepted.value = { ...accepted.value, [item.code]: true };
|
||||
error.value = '';
|
||||
uni.showToast({ title: `已同意《${item.name}》`, icon: 'none' });
|
||||
}
|
||||
|
||||
/** 点圆圈:取消勾选(重新阅读后再勾) */
|
||||
function revoke(item: AgreementItem) {
|
||||
if (!accepted.value[item.code]) {
|
||||
openAgreement(item);
|
||||
return;
|
||||
}
|
||||
accepted.value = { ...accepted.value, [item.code]: false };
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.active,
|
||||
(active) => {
|
||||
if (!active) return;
|
||||
error.value = '';
|
||||
tip.value = '';
|
||||
accepted.value = {};
|
||||
readerVisible.value = false;
|
||||
reading.value = null;
|
||||
loadAgreements();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/** 登录成功后统一收尾:落地令牌 + 主体列表,抛事件给使用方 */
|
||||
function finish(data: LoginResult, message: string) {
|
||||
setSession(data.token, data.user);
|
||||
// 登录接口直接下发主体列表,落地后页面就不用再请求一次
|
||||
if (Array.isArray(data.subjects)) applySubjects(data.subjects);
|
||||
form.password = '';
|
||||
accepted.value = {};
|
||||
error.value = '';
|
||||
tip.value = '';
|
||||
uni.showToast({ title: message, icon: 'none' });
|
||||
emit('success');
|
||||
}
|
||||
|
||||
/** 428:协议版本变了 → 清勾选、拉最新正文 */
|
||||
async function handleAgreementRequired(err: ApiError, fallback: string) {
|
||||
error.value = err.message || fallback;
|
||||
accepted.value = {};
|
||||
await loadAgreements();
|
||||
}
|
||||
|
||||
async function doLogin() {
|
||||
if (busy.value) return;
|
||||
error.value = '';
|
||||
tip.value = '';
|
||||
if (!form.account.trim() || !form.password) {
|
||||
error.value = '请填写账号和密码';
|
||||
return;
|
||||
}
|
||||
if (!allAgreed.value) {
|
||||
error.value = '请先阅读并同意协议';
|
||||
return;
|
||||
}
|
||||
|
||||
busy.value = true;
|
||||
try {
|
||||
const payload = requiredAgreements.value.map(item => ({
|
||||
code: item.code,
|
||||
versionId: item.version.id,
|
||||
}));
|
||||
const data = await login(form.account.trim(), form.password, payload, 'mini_program');
|
||||
finish(data, '登录成功');
|
||||
} catch (err) {
|
||||
if (err instanceof ApiError && err.code === 'agreement_required') {
|
||||
await handleAgreementRequired(err, '协议已更新,请重新阅读并同意');
|
||||
} else {
|
||||
error.value = err instanceof ApiError ? err.message : '登录失败,请稍后再试';
|
||||
}
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="login-panel">
|
||||
<view v-if="showCancel" class="login-panel__close" @click="emit('cancel')">×</view>
|
||||
|
||||
<view v-if="error" class="alert alert-error">{{ error }}</view>
|
||||
<view v-if="tip" class="alert alert-ok">{{ tip }}</view>
|
||||
|
||||
<view class="field">
|
||||
<input
|
||||
v-model="form.account"
|
||||
class="input"
|
||||
placeholder="用户名 / 手机号 / 邮箱"
|
||||
placeholder-class="login-panel__placeholder"
|
||||
:disabled="busy"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<input
|
||||
v-model="form.password"
|
||||
class="input"
|
||||
password
|
||||
placeholder="请输入密码"
|
||||
placeholder-class="login-panel__placeholder"
|
||||
confirm-type="done"
|
||||
:disabled="busy"
|
||||
@confirm="doLogin"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="agree-block">
|
||||
<view class="agree-head">
|
||||
<text class="agree-title">阅读并同意协议</text>
|
||||
<text v-if="agreementsLoading" class="hint">加载中…</text>
|
||||
</view>
|
||||
|
||||
<view v-if="agreementsError" class="agree-error">
|
||||
<text class="hint">{{ agreementsError }}</text>
|
||||
<text class="agree-link agree-retry" @click="loadAgreements">重试</text>
|
||||
</view>
|
||||
|
||||
<view v-for="item in agreements" :key="item.code" class="agree-row">
|
||||
<view
|
||||
class="agree-check"
|
||||
:class="{ 'is-checked': accepted[item.code] }"
|
||||
@click="revoke(item)"
|
||||
>
|
||||
<text v-if="accepted[item.code]" class="agree-tick">✓</text>
|
||||
</view>
|
||||
<text class="agree-text">我已阅读并同意</text>
|
||||
<text class="agree-link" @click="openAgreement(item)">《{{ item.name }}》</text>
|
||||
<text class="agree-version">v{{ item.version.version }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button
|
||||
class="btn login-panel__submit"
|
||||
:disabled="busy || !canSubmit"
|
||||
@click="doLogin"
|
||||
>
|
||||
{{ busy ? '登录中…' : '登录' }}
|
||||
</button>
|
||||
|
||||
<view class="login-panel__tip hint">账号注册、找回密码请在电脑浏览器打开 Web 端操作。</view>
|
||||
|
||||
<agreement-dialog
|
||||
v-model:show="readerVisible"
|
||||
:agreement="reading"
|
||||
@agree="onAgreed"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.login-panel {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.login-panel__close {
|
||||
position: absolute;
|
||||
top: -8rpx;
|
||||
right: -12rpx;
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 50%;
|
||||
color: #9ca3af;
|
||||
font-size: 40rpx;
|
||||
line-height: 52rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login-panel__submit {
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.login-panel__tip {
|
||||
margin-top: 20rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login-panel__placeholder {
|
||||
color: #b6bcc8;
|
||||
}
|
||||
|
||||
.agree-block {
|
||||
margin: 2rpx 0 20rpx;
|
||||
}
|
||||
|
||||
.agree-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4rpx;
|
||||
}
|
||||
|
||||
.agree-title {
|
||||
color: var(--text-muted);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.agree-error {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
|
||||
.agree-retry {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.agree-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.agree-check {
|
||||
width: 34rpx;
|
||||
height: 34rpx;
|
||||
margin-right: 10rpx;
|
||||
border: 2rpx solid #c7ccd6;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.agree-check.is-checked {
|
||||
border-color: var(--brand);
|
||||
background: var(--brand);
|
||||
}
|
||||
|
||||
.agree-tick {
|
||||
color: #fff;
|
||||
font-size: 22rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.agree-text {
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
.agree-link {
|
||||
color: var(--brand);
|
||||
}
|
||||
|
||||
.agree-version {
|
||||
margin-left: 8rpx;
|
||||
color: #9ca3af;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
</style>
|
||||
@ -1,22 +0,0 @@
|
||||
/** 主体选择的本地存储(只做存储,不引接口,避免和 api/client.ts 形成循环依赖) */
|
||||
const SUBJECT_KEY = 'packs_subject_id';
|
||||
|
||||
/** 上次使用的主体 id(没有/非法返回 null) */
|
||||
export function getStoredSubjectId(): number | null {
|
||||
try {
|
||||
const raw = Number(uni.getStorageSync(SUBJECT_KEY));
|
||||
return Number.isInteger(raw) && raw > 0 ? raw : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 记住/清除当前主体 */
|
||||
export function setStoredSubjectId(id: number | null): void {
|
||||
try {
|
||||
if (id) uni.setStorageSync(SUBJECT_KEY, String(id));
|
||||
else uni.removeStorageSync(SUBJECT_KEY);
|
||||
} catch {
|
||||
/* 存储不可用时忽略 */
|
||||
}
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
import { ref } from 'vue';
|
||||
import { setStoredSubjectId } from '@/composables/subjectStorage';
|
||||
import type { CurrentUser } from '@/api/types';
|
||||
|
||||
/** 令牌与当前用户的本地存放(接口用 header 令牌,不依赖 cookie/session) */
|
||||
const TOKEN_KEY = 'packs_token';
|
||||
const USER_KEY = 'packs_user';
|
||||
|
||||
/** 当前用户(响应式,个人中心用) */
|
||||
export const currentUser = ref<CurrentUser | null>(readUser());
|
||||
|
||||
/** 登录状态版本号:登录 / 退出 / 令牌失效时 +1,页面 watch 它来刷新数据 */
|
||||
export const authVersion = ref(0);
|
||||
|
||||
function readUser(): CurrentUser | null {
|
||||
try {
|
||||
const raw = uni.getStorageSync(USER_KEY);
|
||||
if (!raw) return null;
|
||||
return typeof raw === 'string' ? (JSON.parse(raw) as CurrentUser) : (raw as CurrentUser);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getToken(): string {
|
||||
try {
|
||||
return String(uni.getStorageSync(TOKEN_KEY) || '');
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function setSession(token: string, user: CurrentUser): void {
|
||||
uni.setStorageSync(TOKEN_KEY, token);
|
||||
uni.setStorageSync(USER_KEY, user);
|
||||
currentUser.value = user;
|
||||
authVersion.value += 1;
|
||||
}
|
||||
|
||||
export function setUser(user: CurrentUser): void {
|
||||
uni.setStorageSync(USER_KEY, user);
|
||||
currentUser.value = user;
|
||||
}
|
||||
|
||||
export function clearSession(): void {
|
||||
uni.removeStorageSync(TOKEN_KEY);
|
||||
uni.removeStorageSync(USER_KEY);
|
||||
// 换账号后不能带着上一个账号的主体 id
|
||||
setStoredSubjectId(null);
|
||||
currentUser.value = null;
|
||||
authVersion.value += 1;
|
||||
}
|
||||
|
||||
export function isLoggedIn(): boolean {
|
||||
return Boolean(getToken());
|
||||
}
|
||||
|
||||
/** 显示名 */
|
||||
export function displayName(user: CurrentUser | null = currentUser.value): string {
|
||||
if (!user) return '';
|
||||
return user.nickname || user.username || `#${user.id}`;
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* 登录入口:默认弹底部抽屉;个别页面用「页面版登录页」兜底
|
||||
*
|
||||
* 为什么保留两种:抽屉是 Vue 层 fixed 定位,个别真机/低版本基础库上可能弹不出来,
|
||||
* 所以个人中心额外提供一个整页登录(`pages/login/index`),从那里点「登录」就跳页。
|
||||
*
|
||||
* ⚠️ **不要在启动 / 进入游客页时自动调用**:小程序审核要求不能强制登录,
|
||||
* 只允许在「用户点了需要登录的功能」或「请求真的拿到 401」时唤起。
|
||||
* 策略见 `config/auth.ts`。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
|
||||
/** 抽屉开关(tab 页面各挂一个 `<login-drawer />`,共享这个状态) */
|
||||
export const loginDrawerVisible = ref(false);
|
||||
|
||||
/** 页面版登录页路径 */
|
||||
export const LOGIN_PAGE = '/pages/login/index';
|
||||
|
||||
/** 这些页面唤起登录时走整页登录(不弹抽屉) */
|
||||
const PAGE_MODE_ROUTES = [ 'pages/profile/index' ];
|
||||
|
||||
/** 当前页面路由(`getCurrentPages()` 栈顶) */
|
||||
export function currentRoute(): string {
|
||||
try {
|
||||
const pages = getCurrentPages();
|
||||
const page = pages[pages.length - 1] as { route?: string } | undefined;
|
||||
return (page && page.route) || '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/** 跳转到页面版登录(个人中心点「登录」用) */
|
||||
export function openLoginPage(): void {
|
||||
if (currentRoute() === 'pages/login/index') return;
|
||||
uni.navigateTo({
|
||||
url: LOGIN_PAGE,
|
||||
// 页面栈满(10 层)时退回重定向
|
||||
fail: () => uni.redirectTo({ url: LOGIN_PAGE }),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 唤起登录:默认弹抽屉;在 `PAGE_MODE_ROUTES` 里的页面自动改用整页登录。
|
||||
* 只在「用户主动要登录」或「401」时调用,不要在 onLaunch / onShow 里无条件调用。
|
||||
*/
|
||||
export function openLoginDrawer(): void {
|
||||
if (PAGE_MODE_ROUTES.includes(currentRoute())) {
|
||||
openLoginPage();
|
||||
return;
|
||||
}
|
||||
loginDrawerVisible.value = true;
|
||||
}
|
||||
|
||||
export function closeLoginDrawer(): void {
|
||||
loginDrawerVisible.value = false;
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
/**
|
||||
* 主体(租户)状态:当前主体 + 主体列表
|
||||
*
|
||||
* - 上次使用的主体存在本地,登录后如果还在列表里就继续用它
|
||||
* - 所有业务接口都要带 `X-Subject-Id`(见 `api/client.ts`)
|
||||
* - 没有可用主体时,业务页面只提示「先在 Web 端创建主体」
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { fetchSubjects } from '@/api/web';
|
||||
import { getToken } from '@/composables/useAuth';
|
||||
import { getStoredSubjectId, setStoredSubjectId } from '@/composables/subjectStorage';
|
||||
import type { SubjectItem } from '@/api/types';
|
||||
|
||||
/** 主体列表(响应式) */
|
||||
export const subjects = ref<SubjectItem[]>([]);
|
||||
/** 新建主体默认赠送天数(后端下发) */
|
||||
export const trialDays = ref(7);
|
||||
/** 当前主体 id(响应式) */
|
||||
export const currentSubjectId = ref<number | null>(getStoredSubjectId());
|
||||
/** 是否已经拉过主体列表 */
|
||||
export const subjectsLoaded = ref(false);
|
||||
/** 这份列表是用哪个令牌拉下来的(换账号后自动重拉) */
|
||||
let loadedForToken = '';
|
||||
|
||||
/** 当前主体对象 */
|
||||
export const currentSubject = computed<SubjectItem | null>(
|
||||
() => subjects.value.find(item => item.id === currentSubjectId.value) || null,
|
||||
);
|
||||
|
||||
/** 是否有可用主体(存在且在有效期内) */
|
||||
export const hasSubject = computed(() => Boolean(currentSubject.value && !currentSubject.value.expired));
|
||||
|
||||
/** 当前账号是不是当前主体的管理员 */
|
||||
export const isSubjectAdmin = computed(() => Number(currentSubject.value?.role) === 1);
|
||||
|
||||
/** 切换主体(只改本地;接口靠 header 带上) */
|
||||
export function setSubjectId(id: number | null): void {
|
||||
setStoredSubjectId(id);
|
||||
currentSubjectId.value = id;
|
||||
}
|
||||
|
||||
/** 清掉主体选择(退出登录 / 换账号时) */
|
||||
export function clearSubjectCache(): void {
|
||||
subjects.value = [];
|
||||
subjectsLoaded.value = false;
|
||||
loadedForToken = '';
|
||||
currentSubjectId.value = null;
|
||||
setStoredSubjectId(null);
|
||||
}
|
||||
|
||||
/** 用后端下发的列表刷新(登录接口里也带了一份) */
|
||||
export function applySubjects(list: SubjectItem[], days?: number): void {
|
||||
subjects.value = Array.isArray(list) ? list : [];
|
||||
subjectsLoaded.value = true;
|
||||
loadedForToken = getToken();
|
||||
if (typeof days === 'number' && days > 0) trialDays.value = days;
|
||||
|
||||
// 上次用的主体还在 → 继续用;否则挑第一个可用的,都没有就选第一个
|
||||
const stored = getStoredSubjectId();
|
||||
const keep = stored && subjects.value.some(item => item.id === stored) ? stored : null;
|
||||
if (keep) {
|
||||
currentSubjectId.value = keep;
|
||||
return;
|
||||
}
|
||||
const usable = subjects.value.find(item => !item.expired && Number(item.status) === 1) || subjects.value[0];
|
||||
setSubjectId(usable ? usable.id : null);
|
||||
}
|
||||
|
||||
/** 拉取主体列表(`GET /api/web/subjects`) */
|
||||
export async function loadSubjects(): Promise<SubjectItem[]> {
|
||||
const data = await fetchSubjects();
|
||||
applySubjects(data.list, data.trialDays);
|
||||
return subjects.value;
|
||||
}
|
||||
|
||||
/** 没拉过(或换了账号)就拉一次(页面 onShow 里用) */
|
||||
export async function ensureSubjects(): Promise<void> {
|
||||
if (subjectsLoaded.value && loadedForToken === getToken() && getToken()) return;
|
||||
await loadSubjects();
|
||||
}
|
||||
|
||||
/** 使用期限是否已过 */
|
||||
export function isExpired(item: SubjectItem): boolean {
|
||||
return Boolean(item.expired) || new Date(item.expireAt).getTime() <= Date.now();
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* 登录策略:集中控制「页面 / 接口是否必须登录」
|
||||
*
|
||||
* 微信小程序审核要求:**不能一打开就强制登录**,要让用户先能浏览;
|
||||
* 所以默认策略是「游客可浏览,只有真正需要使用功能时才提示登录」:
|
||||
*
|
||||
* - 首页 / 我的:游客可进,点页面里的「登录」才进登录流程;
|
||||
* - 扫码记录:属于 `pageGuards`,**进入页面时**才提示登录(`autoPromptOnEnter`);
|
||||
* - 接口:只有页面真的发请求拿到 401 才弹登录(`promptOnUnauthorized`)。
|
||||
*
|
||||
* 需要收紧/放宽时只改这里,页面与 `api/client.ts` 都读它。
|
||||
*/
|
||||
export const AUTH_POLICY = {
|
||||
/**
|
||||
* 必须登录才能使用的页面。
|
||||
* 现在只有「首页 / 我的」两个 tab,且都能游客浏览(首页给功能介绍、我的给欢迎卡片),
|
||||
* 所以这里是空的;将来加「仅登录可见」的页面时把 route 加进来即可。
|
||||
*/
|
||||
pageGuards: [] as string[],
|
||||
|
||||
/** 进入 pageGuards 页面时是否自动弹出登录(false → 页面内只给「登录」按钮) */
|
||||
autoPromptOnEnter: true,
|
||||
|
||||
/** 业务接口是否必须登录(false → 游客也允许请求,401 不弹登录,页面按空数据处理) */
|
||||
apiRequireAuth: true,
|
||||
|
||||
/** 收到 401 时是否自动弹出登录 */
|
||||
promptOnUnauthorized: true,
|
||||
};
|
||||
|
||||
/** 页面是否需要登录 */
|
||||
export function isGuardedPage(route: string): boolean {
|
||||
return AUTH_POLICY.pageGuards.includes(route);
|
||||
}
|
||||
17
miniprogram/src/env.d.ts
vendored
17
miniprogram/src/env.d.ts
vendored
@ -1,17 +0,0 @@
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="@dcloudio/types" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
/** 后端接口地址(小程序没有同源代理,必须是完整地址) */
|
||||
readonly VITE_API_BASE?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue';
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { createSSRApp } from 'vue';
|
||||
import App from './App.vue';
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App);
|
||||
return { app };
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
{
|
||||
"name": "云仓视频溯源",
|
||||
"appid": "",
|
||||
"description": "云仓视频溯源小程序:登录后查看自己的设备、扫码记录与打包视频入口",
|
||||
"versionName": "0.1.0",
|
||||
"versionCode": "10",
|
||||
"transformPx": false,
|
||||
"mp-weixin": {
|
||||
"appid": "",
|
||||
"setting": {
|
||||
"urlCheck": false,
|
||||
"es6": true,
|
||||
"minified": true
|
||||
},
|
||||
"usingComponents": true
|
||||
},
|
||||
"h5": {
|
||||
"title": "云仓视频溯源",
|
||||
"router": {
|
||||
"mode": "hash"
|
||||
}
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "3"
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "云仓溯源",
|
||||
"enablePullDownRefresh": true,
|
||||
"onReachBottomDistance": 80
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/profile/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "我的"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/info/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "个人信息"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/login/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "登录"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "云仓视频溯源",
|
||||
"navigationBarBackgroundColor": "#F8F8F8",
|
||||
"backgroundColor": "#F6F7FB"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#6B7280",
|
||||
"selectedColor": "#2563EB",
|
||||
"backgroundColor": "#FFFFFF",
|
||||
"borderStyle": "black",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/index/index",
|
||||
"text": "首页"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/profile/index",
|
||||
"text": "我的"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -1,374 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 首页:当前主体的统计 + 扫码记录(只保留「首页 / 我的」两个 tab)
|
||||
*
|
||||
* 游客:只展示功能介绍与登录入口(不强制登录);
|
||||
* 登录后:设备 / 通道 / 记录数量 + 扫码记录列表(按条码筛选、上拉加载更多)。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { onPullDownRefresh, onReachBottom, onShow } from '@dcloudio/uni-app';
|
||||
import { ApiError } from '@/api/client';
|
||||
import { fetchRecords, fetchStats } from '@/api/web';
|
||||
import type { ScanRecord, Stats } from '@/api/types';
|
||||
import LoginDrawer from '@/components/LoginDrawer.vue';
|
||||
import { authVersion, currentUser, displayName, isLoggedIn } from '@/composables/useAuth';
|
||||
import { openLoginDrawer } from '@/composables/useLoginDrawer';
|
||||
import {
|
||||
currentSubject,
|
||||
currentSubjectId,
|
||||
ensureSubjects,
|
||||
hasSubject,
|
||||
loadSubjects,
|
||||
setSubjectId,
|
||||
subjects,
|
||||
} from '@/composables/useSubject';
|
||||
import { formatTime, fromNow } from '@/utils/format';
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
const stats = ref<Stats | null>(null);
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
|
||||
const records = ref<ScanRecord[]>([]);
|
||||
const total = ref(0);
|
||||
const nextPage = ref(1);
|
||||
const listLoading = ref(false);
|
||||
const finished = ref(false);
|
||||
const barcode = ref('');
|
||||
const listError = ref('');
|
||||
|
||||
const loggedIn = computed(() => Boolean(currentUser.value));
|
||||
const subjectNames = computed(() => subjects.value.map(item => item.name));
|
||||
const subjectIndex = computed(() => {
|
||||
const index = subjects.value.findIndex(item => item.id === currentSubjectId.value);
|
||||
return index >= 0 ? index : 0;
|
||||
});
|
||||
|
||||
async function loadStats() {
|
||||
stats.value = hasSubject.value ? await fetchStats() : null;
|
||||
}
|
||||
|
||||
async function loadRecords(reset = false) {
|
||||
if (!hasSubject.value || listLoading.value) return;
|
||||
|
||||
if (reset) {
|
||||
nextPage.value = 1;
|
||||
finished.value = false;
|
||||
}
|
||||
|
||||
listLoading.value = true;
|
||||
listError.value = '';
|
||||
try {
|
||||
const data = await fetchRecords({
|
||||
page: nextPage.value,
|
||||
pageSize: PAGE_SIZE,
|
||||
barcode: barcode.value.trim(),
|
||||
});
|
||||
records.value = reset ? data.list : [...records.value, ...data.list];
|
||||
total.value = data.total;
|
||||
nextPage.value = data.page + 1;
|
||||
finished.value = records.value.length >= data.total;
|
||||
} catch (err) {
|
||||
listError.value = err instanceof ApiError ? err.message : '加载失败';
|
||||
} finally {
|
||||
listLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (!isLoggedIn()) {
|
||||
stats.value = null;
|
||||
records.value = [];
|
||||
total.value = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
await ensureSubjects();
|
||||
await loadStats();
|
||||
await loadRecords(true);
|
||||
} catch (err) {
|
||||
error.value = err instanceof ApiError ? err.message : '加载失败';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadSubjects() {
|
||||
try {
|
||||
await loadSubjects();
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = err instanceof ApiError ? err.message : '主体列表加载失败';
|
||||
}
|
||||
}
|
||||
|
||||
function onSubjectChange(event: { detail: { value: string | number } }) {
|
||||
const target = subjects.value[Number(event.detail.value)];
|
||||
if (!target || target.id === currentSubjectId.value) return;
|
||||
setSubjectId(target.id);
|
||||
load();
|
||||
}
|
||||
|
||||
function search() {
|
||||
loadRecords(true);
|
||||
}
|
||||
|
||||
onShow(load);
|
||||
watch(authVersion, () => load());
|
||||
onPullDownRefresh(async () => {
|
||||
await load();
|
||||
uni.stopPullDownRefresh();
|
||||
});
|
||||
onReachBottom(() => {
|
||||
if (!finished.value) loadRecords();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="row-between hero">
|
||||
<view>
|
||||
<view class="hello">{{ loggedIn ? `你好,${displayName(currentUser)}` : '欢迎使用云仓溯源' }}</view>
|
||||
<view v-if="loggedIn" class="hint">当前仓库:{{ currentSubject ? currentSubject.name : '未选择' }}</view>
|
||||
<view v-else class="hint">仓储打包视频溯源 · 扫码即录像</view>
|
||||
</view>
|
||||
<picker v-if="loggedIn && subjects.length > 1" :range="subjectNames" :value="subjectIndex" @change="onSubjectChange">
|
||||
<view class="subject-chip">切换仓库</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view v-if="error" class="alert alert-error">{{ error }}</view>
|
||||
|
||||
<!-- 游客:先介绍能做什么(不强制登录),要用功能时再点登录 -->
|
||||
<view v-if="!loggedIn" class="card">
|
||||
<view class="card-title">你可以用它做什么</view>
|
||||
<view class="feature">
|
||||
<text class="feature-dot" />
|
||||
<text>扫码记录:查看每件包裹的打包时间与操作流水</text>
|
||||
</view>
|
||||
<view class="feature">
|
||||
<text class="feature-dot" />
|
||||
<text>视频溯源:按运单号回看对应的打包录像</text>
|
||||
</view>
|
||||
<view class="feature">
|
||||
<text class="feature-dot" />
|
||||
<text>设备管理:统一管理扫码中控与摄像头通道</text>
|
||||
</view>
|
||||
<button class="btn guest-btn" @click="openLoginDrawer">登录 / 注册</button>
|
||||
<view class="hint guest-tip">不登录也可以先浏览;登录后才可查看你自己的数据。</view>
|
||||
</view>
|
||||
|
||||
<view v-else-if="!hasSubject && !loading" class="card">
|
||||
<view class="card-title">还没有可用仓库</view>
|
||||
<view class="hint">仓库(主体)是设备与扫码记录的归属单位,请先在 Web 端创建,再回来查看。</view>
|
||||
<button class="btn" style="margin-top: 24rpx" @click="reloadSubjects">重新获取</button>
|
||||
</view>
|
||||
|
||||
<template v-else>
|
||||
<view class="stat-grid">
|
||||
<view class="card stat">
|
||||
<text class="stat-label">我的设备</text>
|
||||
<text class="stat-value">{{ stats ? stats.deviceCount : '—' }}</text>
|
||||
<text class="stat-foot">台(中控)</text>
|
||||
</view>
|
||||
<view class="card stat">
|
||||
<text class="stat-label">已登记通道</text>
|
||||
<text class="stat-value">{{ stats ? stats.channelCount : '—' }}</text>
|
||||
<text class="stat-foot">个</text>
|
||||
</view>
|
||||
<view class="card stat">
|
||||
<text class="stat-label">扫码记录</text>
|
||||
<text class="stat-value">{{ stats ? stats.recordCount : '—' }}</text>
|
||||
<text class="stat-foot">条</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
<view class="row-between card-title-row">
|
||||
<text class="card-title">扫码记录</text>
|
||||
<text class="hint">共 {{ total }} 条</text>
|
||||
</view>
|
||||
|
||||
<view class="search-row">
|
||||
<input
|
||||
v-model="barcode"
|
||||
class="input search-input"
|
||||
placeholder="输入条码(支持模糊)"
|
||||
confirm-type="search"
|
||||
@confirm="search"
|
||||
/>
|
||||
<button class="btn btn-ghost search-btn" :disabled="listLoading" @click="search">查询</button>
|
||||
</view>
|
||||
|
||||
<view v-if="listError" class="alert alert-error">{{ listError }}</view>
|
||||
|
||||
<view v-for="row in records" :key="row.id" class="record">
|
||||
<view class="row-between">
|
||||
<text class="barcode">{{ row.barcode }}</text>
|
||||
<text class="channel">通道 {{ row.channelId }}</text>
|
||||
</view>
|
||||
<view class="record-meta">
|
||||
<text>{{ row.deviceSn || row.scannerId }}{{ row.deviceName ? ` · ${row.deviceName}` : '' }}</text>
|
||||
<text class="muted">{{ formatTime(row.scanTime) }}</text>
|
||||
</view>
|
||||
<view class="record-meta muted">
|
||||
<text>上报 {{ formatTime(row.reportedAt) }}</text>
|
||||
<text>{{ fromNow(row.scanTime) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="!records.length" class="hint list-empty">{{ listLoading ? '加载中…' : '还没有扫码记录。' }}</view>
|
||||
<view v-else-if="listLoading" class="hint list-foot">加载中…</view>
|
||||
<view v-else-if="finished" class="hint list-foot">没有更多了</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<login-drawer />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.hero {
|
||||
padding: 8rpx 4rpx 32rpx;
|
||||
}
|
||||
|
||||
.hello {
|
||||
font-size: 38rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.subject-chip {
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #eef2ff;
|
||||
color: var(--brand);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.guest-btn {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.guest-tip {
|
||||
margin-top: 16rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.feature {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
margin-top: 14rpx;
|
||||
color: #4b5563;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.feature-dot {
|
||||
width: 10rpx;
|
||||
height: 10rpx;
|
||||
margin: 14rpx 14rpx 0 0;
|
||||
border-radius: 50%;
|
||||
background: var(--brand);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stat-grid {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.stat {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 24rpx 20rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: var(--text-muted);
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
margin-top: 8rpx;
|
||||
font-size: 44rpx;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.stat-foot {
|
||||
color: var(--text-muted);
|
||||
font-size: 20rpx;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.card-title-row {
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.search-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
flex-shrink: 0;
|
||||
width: 140rpx;
|
||||
height: 84rpx;
|
||||
}
|
||||
|
||||
.record {
|
||||
padding: 20rpx 0;
|
||||
border-top: 1rpx solid #f1f3f7;
|
||||
}
|
||||
|
||||
.barcode {
|
||||
font-family: Menlo, Consolas, monospace;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.channel {
|
||||
flex-shrink: 0;
|
||||
margin-left: 16rpx;
|
||||
padding: 2rpx 14rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #eef2ff;
|
||||
color: var(--brand);
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.record-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.list-empty {
|
||||
padding: 24rpx 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.list-foot {
|
||||
padding: 16rpx 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@ -1,332 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 个人信息:进入本页才拉取用户资料(`GET /api/web/me`),退出登录也在这里。
|
||||
*
|
||||
* 样式对齐参考项目(`wms_mp_weixin/src/pages/mine/user-info.vue`):
|
||||
* 白卡片 + 卡内蓝色「我是谁」横条 + cell 行;全局 `navigationStyle: custom`,本页自带返回。
|
||||
*/
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
import { ApiError, api } from '@/api/client';
|
||||
import { fetchMe, updateMe } from '@/api/web';
|
||||
import type { CurrentUser } from '@/api/types';
|
||||
import { clearSession, currentUser, displayName, isLoggedIn, setUser } from '@/composables/useAuth';
|
||||
import { clearSubjectCache } from '@/composables/useSubject';
|
||||
|
||||
const form = reactive({ nickname: '', email: '', phone: '' });
|
||||
const loading = ref(true);
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
const ok = ref('');
|
||||
|
||||
const loggedIn = computed(() => Boolean(currentUser.value));
|
||||
const avatarUrl = computed(() => String(currentUser.value?.avatar || '').trim());
|
||||
const avatarText = computed(() => displayName(currentUser.value).slice(0, 1) || '云');
|
||||
const name = computed(() => displayName(currentUser.value));
|
||||
const account = computed(() => currentUser.value?.username || '');
|
||||
|
||||
function fill(user: CurrentUser | null) {
|
||||
form.nickname = user?.nickname || '';
|
||||
form.email = user?.email || '';
|
||||
form.phone = user?.phone || '';
|
||||
}
|
||||
|
||||
/** 只在本页拉资料(进页面 / 返回页面时各拉一次) */
|
||||
async function load() {
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
if (!isLoggedIn()) {
|
||||
loading.value = false;
|
||||
fill(null);
|
||||
return;
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const me = await fetchMe();
|
||||
setUser(me);
|
||||
fill(me);
|
||||
} catch (err) {
|
||||
error.value = err instanceof ApiError ? err.message : '资料加载失败';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (busy.value) return;
|
||||
error.value = '';
|
||||
ok.value = '';
|
||||
if (!form.nickname.trim()) {
|
||||
error.value = '昵称不能为空';
|
||||
return;
|
||||
}
|
||||
|
||||
busy.value = true;
|
||||
try {
|
||||
const me = await updateMe({
|
||||
nickname: form.nickname.trim(),
|
||||
email: form.email.trim(),
|
||||
phone: form.phone.trim(),
|
||||
});
|
||||
setUser(me);
|
||||
fill(me);
|
||||
ok.value = '资料已更新';
|
||||
uni.showToast({ title: '资料已更新', icon: 'success' });
|
||||
} catch (err) {
|
||||
error.value = err instanceof ApiError ? err.message : '保存失败';
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
uni.showModal({
|
||||
title: '退出登录',
|
||||
content: '确认退出当前账号?',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
clearSession();
|
||||
clearSubjectCache();
|
||||
fill(null);
|
||||
uni.showToast({ title: '已退出登录', icon: 'none' });
|
||||
uni.switchTab({ url: '/pages/index/index' });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
fail: () => uni.switchTab({ url: '/pages/profile/index' }),
|
||||
});
|
||||
}
|
||||
|
||||
onShow(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="navbar">
|
||||
<text class="navbar-back" @click="goBack">‹</text>
|
||||
<text class="navbar-title">个人信息</text>
|
||||
</view>
|
||||
|
||||
<view v-if="error" class="alert alert-error">{{ error }}</view>
|
||||
<view v-if="ok" class="alert alert-ok">{{ ok }}</view>
|
||||
|
||||
<template v-if="loggedIn">
|
||||
<view class="card">
|
||||
<view class="card-title">{{ loading ? '正在加载…' : '用户信息' }}</view>
|
||||
|
||||
<view class="me">
|
||||
<view class="me-avatar">
|
||||
<image v-if="avatarUrl" class="me-avatar-img" :src="avatarUrl" mode="aspectFill" />
|
||||
<text v-else class="me-avatar-text">{{ avatarText }}</text>
|
||||
</view>
|
||||
<view class="me-info">
|
||||
<view class="me-name">{{ name }}</view>
|
||||
<view class="me-desc">{{ account ? `账号 ${account}` : '已登录' }}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="cell">
|
||||
<text class="cell-title">昵称</text>
|
||||
<input v-model="form.nickname" class="cell-input" placeholder="昵称" />
|
||||
</view>
|
||||
<view class="cell">
|
||||
<text class="cell-title">邮箱</text>
|
||||
<input v-model="form.email" class="cell-input" type="text" placeholder="未设置" />
|
||||
</view>
|
||||
<view class="cell cell-last">
|
||||
<text class="cell-title">手机号</text>
|
||||
<input v-model="form.phone" class="cell-input" type="number" placeholder="未设置" />
|
||||
</view>
|
||||
|
||||
<view class="card-action">
|
||||
<button class="btn-save" :disabled="busy" @click="save">{{ busy ? '保存中…' : '保存' }}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
<view class="cell cell-last cell-link" @click="logout">
|
||||
<text class="cell-title cell-title-danger">退出登录</text>
|
||||
<text class="cell-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<view v-else class="card">
|
||||
<view class="card-title">未登录</view>
|
||||
<view class="card-note">请先在「我的」页登录后查看个人信息。</view>
|
||||
</view>
|
||||
|
||||
<view class="footer">{{ loading ? '正在加载资料…' : `接口地址:${api.baseUrl}` }}</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 0;
|
||||
background: #f5f6fa;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: calc(16rpx + var(--status-bar-height, 0px)) 24rpx 16rpx;
|
||||
background: #fff;
|
||||
border-bottom: 1rpx solid #ebedf0;
|
||||
}
|
||||
|
||||
.navbar-back {
|
||||
width: 64rpx;
|
||||
font-size: 44rpx;
|
||||
line-height: 1;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.navbar-title {
|
||||
flex: 1;
|
||||
margin-right: 64rpx;
|
||||
text-align: center;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.card {
|
||||
margin: 24rpx;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
padding: 24rpx 32rpx 8rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.card-note {
|
||||
padding: 0 32rpx 32rpx;
|
||||
font-size: 24rpx;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.card-action {
|
||||
padding: 8rpx 32rpx 32rpx;
|
||||
}
|
||||
|
||||
/* 卡内「我是谁」横条:与「我的」页头部同款蓝底 */
|
||||
.me {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 16rpx 24rpx 8rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: 12rpx;
|
||||
background: linear-gradient(135deg, #2563eb 0%, #4f8bff 62%, #6aa6ff 100%);
|
||||
}
|
||||
|
||||
.me-avatar {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.me-avatar-img {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.me-avatar-text {
|
||||
color: #fff;
|
||||
font-size: 40rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.me-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
|
||||
.me-name {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.me-desc {
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 96rpx;
|
||||
margin: 0 32rpx;
|
||||
border-bottom: 1rpx solid #ebedf0;
|
||||
}
|
||||
|
||||
.cell-last {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.cell-title {
|
||||
width: 140rpx;
|
||||
font-size: 28rpx;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.cell-title-danger {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.cell-input {
|
||||
flex: 1;
|
||||
height: 96rpx;
|
||||
font-size: 28rpx;
|
||||
color: #303133;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.cell-arrow {
|
||||
margin-left: 8rpx;
|
||||
color: #c0c4cc;
|
||||
font-size: 36rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.btn-save {
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
border: none;
|
||||
border-radius: 12rpx;
|
||||
background: var(--brand);
|
||||
color: #fff;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.btn-save[disabled] {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 8rpx 32rpx 48rpx;
|
||||
text-align: center;
|
||||
font-size: 22rpx;
|
||||
color: #c0c4cc;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
@ -1,72 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 页面版登录:给「抽屉在某些设备上打不开」兜底
|
||||
*
|
||||
* 只在个人中心点「登录」时 `navigateTo` 进来;其它页面仍然用 `LoginDrawer`。
|
||||
* 登录成功 → 返回上一页(个人中心 watch authVersion 自动刷新)。
|
||||
*/
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import LoginPanel from '@/components/LoginPanel.vue';
|
||||
import { isLoggedIn } from '@/composables/useAuth';
|
||||
|
||||
function back() {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
uni.navigateBack();
|
||||
return;
|
||||
}
|
||||
uni.switchTab({ url: '/pages/index/index' });
|
||||
}
|
||||
|
||||
function onSuccess() {
|
||||
// 稍等一下让 toast 出来,避免返回动画盖掉提示
|
||||
setTimeout(back, 200);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
// 已经登录(例如返回键回退到本页)就直接退出去
|
||||
if (isLoggedIn()) back();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="login-page">
|
||||
<view class="card login-card">
|
||||
<view class="login-card__head">
|
||||
<view class="login-card__title">登录</view>
|
||||
<view class="login-card__sub">登录后查看设备与扫码记录</view>
|
||||
</view>
|
||||
|
||||
<login-panel active @success="onSuccess" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.login-page {
|
||||
min-height: 100vh;
|
||||
padding: 40rpx 32rpx calc(40rpx + env(safe-area-inset-bottom));
|
||||
background: linear-gradient(180deg, #eef3ff 0%, #f6f7fb 38%);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
padding: 36rpx 32rpx;
|
||||
border-radius: 24rpx;
|
||||
}
|
||||
|
||||
.login-card__head {
|
||||
margin-bottom: 28rpx;
|
||||
}
|
||||
|
||||
.login-card__title {
|
||||
font-size: 38rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.login-card__sub {
|
||||
margin-top: 4rpx;
|
||||
color: var(--text-muted);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
</style>
|
||||
@ -1,116 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 我的:只显示头像和名称
|
||||
*
|
||||
* 样式对齐参考项目(`wms_mp_weixin/src/pages/mine/mine.vue`):整条蓝色头部通栏 + 白卡片列表。
|
||||
* - 本页不请求接口(只读本地登录态),进 tab 立刻有内容;
|
||||
* - 点头像或名称 → 「个人信息」页,资料拉取与退出登录都在那一页;
|
||||
* - 未登录时点它去登录页。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { currentUser, displayName } from '@/composables/useAuth';
|
||||
import { openLoginPage } from '@/composables/useLoginDrawer';
|
||||
|
||||
const loggedIn = computed(() => Boolean(currentUser.value));
|
||||
const avatarUrl = computed(() => String(currentUser.value?.avatar || '').trim());
|
||||
const avatarText = computed(() => displayName(currentUser.value).slice(0, 1) || '云');
|
||||
const name = computed(() => (loggedIn.value ? displayName(currentUser.value) : '未登录'));
|
||||
const desc = computed(() => (loggedIn.value ? '查看个人信息' : '点击登录后使用完整功能'));
|
||||
|
||||
function openInfo() {
|
||||
if (!loggedIn.value) {
|
||||
openLoginPage();
|
||||
return;
|
||||
}
|
||||
uni.navigateTo({ url: '/pages/info/index' });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="profile" @click="openInfo">
|
||||
<view class="profile-avatar">
|
||||
<image v-if="avatarUrl" class="profile-avatar-img" :src="avatarUrl" mode="aspectFill" />
|
||||
<text v-else class="profile-avatar-text">{{ avatarText }}</text>
|
||||
</view>
|
||||
|
||||
<view class="profile-info">
|
||||
<view class="profile-name">{{ name }}</view>
|
||||
<view class="profile-desc">{{ desc }}</view>
|
||||
</view>
|
||||
|
||||
<text class="profile-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 0;
|
||||
background: #f5f6fa;
|
||||
}
|
||||
|
||||
.profile {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: calc(40rpx + var(--status-bar-height, 0px)) 32rpx 40rpx;
|
||||
background: linear-gradient(135deg, #2563eb 0%, #4f8bff 62%, #6aa6ff 100%);
|
||||
}
|
||||
|
||||
.profile:active {
|
||||
opacity: 0.92;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
width: 108rpx;
|
||||
height: 108rpx;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.profile-avatar-img {
|
||||
width: 108rpx;
|
||||
height: 108rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.profile-avatar-text {
|
||||
color: #fff;
|
||||
font-size: 44rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.profile-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
|
||||
.profile-name {
|
||||
font-size: 36rpx;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.profile-desc {
|
||||
margin-top: 8rpx;
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.profile-arrow {
|
||||
flex-shrink: 0;
|
||||
margin-left: 12rpx;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
font-size: 40rpx;
|
||||
line-height: 1;
|
||||
}
|
||||
</style>
|
||||
@ -1,26 +0,0 @@
|
||||
/** 展示用的格式化小工具 */
|
||||
|
||||
/** ISO 字符串 / 时间戳 / Date → `2026-10-17 09:30:00`(空值显示占位符) */
|
||||
export function formatTime(value?: string | number | Date | null, fallback = '—'): string {
|
||||
if (value === undefined || value === null || value === '') return fallback;
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return fallback;
|
||||
|
||||
const pad = (num: number) => String(num).padStart(2, '0');
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
||||
+ ` ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
||||
}
|
||||
|
||||
/** 相对时间:`刚刚` / `3 分钟前` / ……(超过 30 天直接给日期) */
|
||||
export function fromNow(value?: string | null, fallback = '—'): string {
|
||||
if (!value) return fallback;
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return fallback;
|
||||
|
||||
const diff = Date.now() - date.getTime();
|
||||
if (diff < 60_000) return '刚刚';
|
||||
if (diff < 3_600_000) return `${Math.floor(diff / 60_000)} 分钟前`;
|
||||
if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)} 小时前`;
|
||||
if (diff < 2_592_000_000) return `${Math.floor(diff / 86_400_000)} 天前`;
|
||||
return formatTime(date, fallback);
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"jsx": "preserve",
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"types": ["@dcloudio/types"],
|
||||
"strict": true,
|
||||
"noImplicitThis": true,
|
||||
"isolatedModules": true,
|
||||
"useDefineForClassFields": true,
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"sourceMap": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import uni from '@dcloudio/vite-plugin-uni';
|
||||
|
||||
/**
|
||||
* 小程序 H5 预览(7304):**不代理 /api**,接口直连后端绝对地址(见 `src/api/client.ts`,
|
||||
* 后端已开 CORS)。`VITE_BACKEND` 只在需要时用来对齐默认地址,不再参与转发。
|
||||
*/
|
||||
export default defineConfig({
|
||||
plugins: [uni()],
|
||||
server: {
|
||||
// 本项目端口约定:前端 7301/7302、后端 7300,小程序 H5 预览用 7304
|
||||
host: '127.0.0.1',
|
||||
port: 7304,
|
||||
strictPort: true,
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user