提交图
144 次代码提交
作者 SHA1 备注 提交日期
Guoguo fcbae016ed debug: add console.log to getPhoneNumber callback 2026-05-06 06:35:50 -07:00
Guoguo c065d3fdce fix: make phone authorization skippable in registration
getPhoneNumber requires verified enterprise miniprogram account.
Allow users to skip phone auth and complete registration without it.
2026-05-06 06:29:03 -07:00
Guoguo 52456d850e fix: audit fixes for registration flow
- loadProfile() now returns Promise (was missing return)
- Avatar upload via COS instead of storing WeChat temp path
- Add POST /user/avatar endpoint with multer + COS SDK
- Incomplete registration detection: redirect to register if phone is empty
2026-05-06 06:18:21 -07:00
Guoguo 2f6ab74eab fix: admin console support non-root path deployment
- Set vite base to /admin/ (configurable via PUBLIC_PATH env var)
- Add h5 router base in manifest.json for subdirectory deployment
2026-05-06 06:12:39 -07:00
Guoguo 563e515bce feat: add registration page for new miniprogram users
- New register page with chooseAvatar, nickname input (random default),
  and required phone number authorization via getPhoneNumber
- Login simplified: removed deprecated wx.getUserProfile, checks
  is_new_user flag to redirect new users to registration
- Server login response now includes is_new_user field
2026-05-06 06:12:34 -07:00
Guoguo 5cc41f0f10 chore: update API domain deployment config 2026-05-06 21:07:44 +08:00
Guoguo ff4590767d docs: update AGENTS.md with current architecture and security measures 2026-05-05 02:35:36 -07:00
Guoguo 2eb38195f1 fix: address critical security and data integrity issues from cross-audit
- Add expire_time > NOW() filter to findActive() preventing stale subscriptions
- Add express-rate-limit on login endpoints (user: 10/15min, admin: 5/15min)
- Add production guard for default admin credentials
- Fix BLE bindDevice userId encoding (uint32 instead of hexToBytes on numeric)
- Wrap adminCreate in transaction to prevent race condition
- Add settings cache invalidation after admin saves
- Read trial_days from settings instead of hardcoding 7
- Fix double JSON.stringify in commandDao.finish call
- Cancel stale pending bindings before creating new ones
- Reduce token refresh grace period from 3 days to 1 day
- Fix subscribe-success to fetch expiry from server (correct for renewals)
- Add keep-alive name property to DashboardView and SettingsView
- Fix BLE disconnect() to preserve listener registrations across reconnects
2026-05-05 02:33:25 -07:00
Guoguo 031678c03f feat: complete feature gaps across all modules
Server:
- Add settings-cache with 60s TTL for feature toggle checks
- Enforce maintenance_mode on login, enable_binding on device bind

Admin console:
- Remove dead "发送通知" button from user detail
- Firmware check calls real API and compares versions

Miniprogram:
- Wear-check: dynamic battery/connected from BLE state
- Login: hide non-functional phone auth button
- Treating: show actual selected regions instead of hardcoded "全脸"
- Index: display subscription status with tap to manage
- Auto-scan: show "待检测" instead of "--" for PD data
- Agreements: tap shows "内容建设中" modal
2026-05-02 08:48:26 -07:00
Guoguo 1017fb5dae fix: subscription extend instead of overwrite, improve placeholder pages
- Subscription purchase now extends expire_time when user has active
  subscription, instead of cancelling and replacing
- Admin subscription creation uses same extend logic
- Subscribe page shows "续费" button and extend message for renewals
- Help and contact pages: add pink header, centered icon + text
2026-04-29 08:35:58 -07:00
Guoguo 9bdccdcec8 chore: remove duplicate logDao require in subscription route 2026-04-29 08:24:15 -07:00
Guoguo 66cc846da1 fix: mock purchase now actually activates subscription
POST /api/v1/subscription/purchase only creates an order without
activating. Add POST /api/v1/subscription/mock-purchase that does
purchase + verify in one step (non-production only). Miniprogram
subscribe page now calls mock-purchase so subscriptions take effect.
2026-04-29 08:22:08 -07:00
Guoguo 17f5366c23 feat: show trial plan with used/disabled state on subscribe page
- Add GET /api/v1/subscription/plans public endpoint for pricing
- Subscription API now returns trial_used field
- Subscribe-plans page shows trial card, greyed out with "已使用" tag
  when trial has been used
- Trial activation calls dedicated trial API, not purchase
- Prices fetched from server settings, fallback to defaults
2026-04-29 08:15:27 -07:00
Guoguo e8f076c914 feat: fetch subscription prices from server settings
- Add GET /api/v1/subscription/plans public endpoint (no auth needed)
  that reads prices from system_settings table
- Subscribe-plans page now loads prices from server on show
- Falls back to hardcoded defaults if API fails
- Add api.getPlans() to miniprogram API module
2026-04-29 08:07:47 -07:00
Guoguo 71e4a487a5 fix: resolve subscription UX issues and add placeholder pages
- Profile: show "未订阅" card when subscription inactive/0 days
- Profile: subscription management navigates to page instead of modal
- Subscribe-plans: data-driven plan cards with mock payment flow
- Subscribe-plans: show current subscription status at top
- Subscribe-prompt: "先使用普通模式" goes to wear-check directly
- Add help and contact placeholder pages
- Fix unbindDevice to work without explicit deviceId
2026-04-29 07:00:36 -07:00
Guoguo 453f3854bd refactor: convert admin console to SPA with dynamic component switching
- Create shell page (pages/admin/index.vue) with AdminLayout + keep-alive
- Convert 9 pages to view components (views/*.vue)
- AdminLayout emits navigate events instead of uni.redirectTo
- Sidebar navigation no longer causes full page reload
- List views cached with keep-alive, detail views re-mount fresh
- Fix: add name property to 5 cached views for keep-alive matching
- Fix: add navigationStyle custom to prevent double nav bar
- Fix: remove duplicate mounted() in RecordView/LogView
2026-04-29 06:24:46 -07:00
Guoguo 52fb7799a3 fix: default NODE_ENV to development for testing phase 2026-04-29 06:11:43 -07:00
Guoguo 563af5dbe1 fix: add ble.js proxy for WeChat miniprogram module resolution
WeChat's require() does not support directory imports — require('./ble')
looks for ble.js, not ble/index.js. Add a proxy file that re-exports
from ble/index.js so all existing imports continue to work.
2026-04-29 06:08:37 -07:00
Guoguo 62a63f9c9b fix: resolve final audit issues
- firmware route: extract insertId from ResultSetHeader correctly
- admin device detail: add null check and flatten response to match
  frontend's expected field structure
- device command result: add ownership verification before finishing
  command (security fix)
2026-04-29 06:02:18 -07:00
Guoguo bb4b80f867 refactor: restructure entire project for human maintainability
Server:
- Add Express framework, replace custom router/request parser
- Create DAO layer (12 files) centralizing all 73 SQL queries
- Rewrite 7 route files as thin Express controllers calling DAOs
- Add SCF-to-Express adapter (lib/serverless.js)
- Add auth middleware (middleware/auth.js)
- Remove dead code from lib/auth.js

Admin console:
- Extract DataTable component (table + pagination)
- Extract ConfirmModal component (modal + form styles)
- Create listMixin for paginated list pages
- Move form styles to common.css for slot compatibility
- Refactor device + subscription pages as examples

Miniprogram:
- Split 734-line BLE monolith into 4 focused modules
  (protocol, connection, commands, barrel index)
- Create API module (utils/api.js) with named functions
- Create page utilities (utils/page.js)
- Refactor index + profile pages to use API module
2026-04-29 05:58:20 -07:00
Guoguo 9f0e629c82 fix: resolve quality audit issues
- utils.js: force UTC+8 output to match MySQL timezone on SCF
- admin subscriptions: return stats (plan counts + revenue) in response
- admin devices: implement keyword search filter
- device-detail: fix binding history field names (bind_time/unbind_time/bind_status)
- user-detail: fix treatment time field (start_time not started_at)
- dashboard: show actual mode per treatment, use sub_stats from dashboard API
2026-04-29 05:37:36 -07:00
Guoguo 8d1cde8636 fix: resolve 8 bugs and add admin features
Miniprogram:
- Profile "我的设备": show unbind option when device bound, scan when not
- Add device status indicator (已绑定/未绑定) to profile menu

Admin console:
- Login: add @confirm to inputs so Enter key submits the form
- Record detail: wire up 详情 link with modal showing full record info
- Dashboard: add subscription stats row (月卡/年卡/试用/收入)
- Subscription: add 取消 action for active subscriptions
- Format: fix -8h timezone display for UTC ISO date strings

Server:
- POST /api/v1/admin/subscriptions/cancel: cancel active subscriptions
- Dashboard API: include sub_stats (plan counts + monthly revenue)
- IP extraction: add X-Forwarded-For fallback for logging
2026-04-29 05:33:12 -07:00
Guoguo 775112130d feat: add mock-bind endpoint to bypass token flow for testing
The bind + confirm two-step flow has timezone issues between Node.js
(UTC on SCF) and MySQL (timezone +08:00) that cause bind_token to
fail validation. Add POST /api/v1/device/mock-bind that does bind +
confirm in one atomic step, skipping the token entirely. Only
available when NODE_ENV != production.

Update ble-connect and index page mock buttons to use mock-bind.
2026-04-29 05:10:12 -07:00
Guoguo 3e8cd8764a fix: use MySQL DATE_ADD instead of JS dates for bind token expiry
SCF runs in UTC but MySQL connection uses timezone +08:00, causing
bind_expires computed in JS to mismatch NOW() in SQL queries.
Use DATE_ADD(NOW(), INTERVAL ...) directly in SQL to guarantee
consistent timezone for both storage and comparison.
2026-04-29 04:57:31 -07:00
Guoguo 2578c06a74 fix: back button alignment, mock bind flow, and timezone bug
- nav-back: add text-align:left to override page-header's center
- ble-connect mock: call bind API first to get fresh token before
  confirm, instead of relying on potentially stale URL params
- utils.js: use local time instead of UTC for toMysqlDate, fixing
  timezone mismatch with MySQL NOW() that caused bind tokens to
  appear immediately expired
2026-04-29 04:54:42 -07:00
Guoguo 1f55e430c8 feat: add password change, trial subscription, batch import, UX improvements
Server:
- POST /api/v1/admin/password: admin password change with bcrypt migration
- POST /api/v1/subscription/trial: user trial activation, one per user
- POST /api/v1/admin/devices/batch: bulk device import (up to 500)
- Add trial plan (7 days, free) to PLANS constant

Admin console:
- Settings page: add password change form with validation
- Device page: add batch import modal with textarea input

Miniprogram:
- Treating page: add back button with stop-treatment confirmation
- Index page: add mock device bind button (dev mode only)
2026-04-28 19:42:23 -07:00
Guoguo 4ec42e7816 fix: resolve password migration crash and schema constraints
- Login bcrypt migration: write password_salt = '' instead of NULL,
  which violated the NOT NULL constraint and caused 500 errors
- Schema: widen password_hash from CHAR(64) to VARCHAR(100) for bcrypt
  compatibility, add DEFAULT '' to password_salt
- init-db: add ALTER TABLE migrations for existing databases
- app.js: enrich error logging with method, path, SQL error details
2026-04-28 19:14:13 -07:00
Guoguo 4b6e577dfb fix: correct init-db hashPassword call for bcrypt migration
hashPassword now uses bcrypt (single arg), not SHA-256 (password+salt).
The old call silently ignored the salt param but was misleading.
2026-04-28 19:06:11 -07:00
Guoguo b754926937 fix: clear stale token expiry on auth failure, correct doc inaccuracies
- request.js: also remove admin_token_expiry when clearing auth on
  1001/1002 response, preventing stale expiry value in storage
- 01-服务端架构.md: fix table count from 10 to 11
- 03-管理后台架构.md: add /api/v1 prefix to all API endpoint paths
2026-04-28 18:49:00 -07:00
Guoguo 6201b97fcd fix: resolve critical audit issues across all modules
Server: add filter/search/pagination to admin list endpoints, enrich
user/device queries with JOINs and subqueries, prevent duplicate active
subscriptions on creation.

Admin console: fix record page TypeError on numeric record_id, correct
mode comparison (integer vs string), fix device detail field names and
command opcode, remove hardcoded login credentials, wire up dead buttons
(unbind, view logs, export), fix user/subscription field mappings.

Miniprogram: fix subscription status string/number mismatches across
index/treatment-setup/profile pages, fix device name field reference,
fix treatment-done null device_id by capturing at onLoad.
2026-04-28 18:46:03 -07:00
Guoguo c5f6033ccf fix: improve UX and fix admin console display issues
Miniprogram:
- Add back buttons to all custom-nav pages
- Add debug/mock buttons (BLE connect, wear check, treatment)
  controlled by __DEV__ flag (hidden in prod)

Admin console:
- Fix log page using nonexistent fields (operator_type, target_type)
  now correctly reads admin_id/user_id/action/detail from API
- Fix subscription date fields (started_at→start_time, expired_at→expire_time)
- Wire up subscription detail/extend/renew action buttons
- Wire up device detail "查看完整日志" button
- Add "创建订阅" button to subscription toolbar
- Fix subscription status mapping (2=expired, 3=cancelled)

Docs:
- Add detailed architecture docs for server, miniprogram, admin console
2026-04-28 18:32:26 -07:00
Guoguo 91d5937d8e feat: implement P0 security and reliability improvements
- bcrypt password hashing with auto-migration from SHA-256
- BLE command retry (3 attempts, 500ms delay, skip on disconnect)
- BLE auto-reconnect with service re-discovery on disconnect
- Treatment page disconnect/reconnect event handling
- Token refresh endpoint with 3-day grace period
- Client-side token auto-refresh when <24h remaining
- Single treatment record detail API with ownership check
2026-04-28 18:12:30 -07:00
Guoguo 88adee7743 docs: add audit report and prioritized action items
- docs/reviews/代码质量审计报告-20260428.md: full audit results and fix summary
- docs/planning/12-待办事项决策分类.md: action items split by decision owner
  (hardware team / product team / ops / independent)
2026-04-28 09:01:18 -07:00
Guoguo b80e872600 fix: comprehensive security, quality and consistency fixes
Server:
- Block startup with default JWT secrets in production
- Make subscription verify admin-only (no payment integration yet)
- Add device ownership validation on command/result, event, treatment/sync
- Remove admin token from request body fallback
- Add pageParams boundary protection (pageSize capped at 100)
- Fix COS getObjectUrl to use callback-based Promise
- Add settings key whitelist matching frontend fields
- Add user existence check before subscription creation
- Fix firmware always returning has_update:true
- Replace hardcoded trial subscription with actual DB query
- Extract shared utilities (limitClause, toMysqlDate, formatDate)

Miniprogram:
- Replace fake PD random data with placeholder
- Mark client-timer treatment completions with source field
- Disable mock.js
- Fix BLE listener leaks (save refs, cleanup in onUnload)
- Fix ble.off clearing all listeners (pass specific callback)
- Add BLE disconnect detection via onBLEConnectionStateChange
- Fix subscription status type consistency (number not string)
- Fix scan callback accumulation in ble.js
- Fix history stats accumulation across pages
- Fix subscribe-success/treatment-done hardcoded values
- Fix profile subscription view logic
- Replace purchase flow with admin-contact modal
- Add error logging in command-sync report

Admin console:
- Fix AdminLayout logout (require->import, logout->clearToken)
- Remove all mock data from production request.js
- Replace dashboard fake data with real API calls
- Replace monthly_revenue with subscription_count
- Fix subscription stats fallback (|| -> ??)
- Add token expiry tracking (7 days)
- Unify device status map and subscription status text
- Fix user page record link navigation
- Fix subscription createForm.user_id type handling
- Add error feedback in all empty catch blocks
- Remove unused remember checkbox and uview-plus dependency
- Extract common CSS to shared stylesheet (-900 lines)
- Extract formatDate to shared utils/format.js
- Show real admin name in layout header
2026-04-28 08:46:59 -07:00
Guoguo 543808b76e docs: align documentation with Tencent Cloud architecture 2026-04-28 23:16:26 +08:00
Guoguo a1b189483f fix: use WeChat profile authorization login 2026-04-28 23:00:13 +08:00
Guoguo 444c91c0b0 refactor: migrate to Tencent Cloud backend 2026-04-28 22:56:47 +08:00
GuoguoClaude Opus 4.6 267c75718b fix: resolve multiple miniprogram bugs and extend admin console
- fix manual bind stuck at BLE scan, redirect to bind-success
- add 15s timeout and stopScan to ble-connect
- add stopScan method to ble.js
- add back-to-home button on bind-success page
- fix field name in subscribe-plans (plan -> plan_type)
- fix history.js to handle created_at field
- fix index.js to handle device name field
- add subscription route alias in request.js
- extend admin cloud function from 1 to 9 actions
- add mock mode to admin-console request.js
- remove unused discover page and legacy record function

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-24 23:28:53 +08:00
Guoguo 52cb1f72dc fix: resolve header overlap on Dynamic Island iPhones
- app.js 通过 wx.getSystemInfoSync 获取 statusBarHeight 存入 globalData
- 所有12个自定义导航页面的 JS 读取 statusBarHeight
- WXML 通过 style="padding-top: {{statusBarHeight + 24}}px" 动态适配
- 普通手机和灵动岛手机都能正确显示
2026-04-24 22:20:10 +08:00
Guoguo 36e80d503a refactor: migrate to WeChat cloud development
- 新增 cloud-functions/ 目录(6个云函数:auth/device/subscription/treatment/user/admin)
- 云函数使用 wx-server-sdk + 云数据库(不再依赖 MySQL)
- auth 云函数通过 cloud.getWXContext() 自动获取 openid,无需手动 wx.login
- request.js 改为通过 wx.cloud.callFunction() 调用云函数
- 登录流程简化:点击授权 → 直接调 auth 云函数 → 获取用户信息
- 保留 HTTP 模式切换能力(USE_CLOUD 变量控制)
2026-04-24 22:03:16 +08:00
Guoguo 5064cf119d fix(ui): polish miniprogram and admin console details
小程序修复:
- 首页/我的/记录页移除自定义头部,使用原生导航栏
- tabBar '护理记录' 改为 '记录'
- 智能模式跳转auto-scan页面(不再跳过)
- 扫码区域尺寸 300→360rpx,图标 100→120rpx
- 护理中倒计时 120→144rpx
- 完成页图标 120→140rpx
- 完成页时长格式 '10分0秒' → '10分钟'
- 蓝牙连接 '连接中' → '点击连接'
- 订阅套餐默认选中年卡
- 订阅成功页改为动态数据(非硬编码)
- 我的页增加退出登录按钮
- 护理记录日期支持'今天/昨天'相对格式
- 扫描进度居中
- 锁定模式图标加灰度滤镜

管理后台修复:
- 所有页面移除重复页面标题
- 仪表盘统计卡片改为垂直布局
- 快捷操作图标统一粉色+箭头
- 设备管理搜索placeholder和库存badge修正
- 用户管理头像、次后缀、月卡/试用badge颜色修正
- 订阅管理stat背景改白色、过期改红色、tab切换修复
- 护理记录模式badge修正
- 操作日志改为平铺列表
- 系统设置开关改绿色、表单改水平布局
- 全局背景色 #f5f5f5 → #f0f2f5
2026-04-23 01:18:50 +08:00
Guoguo 7fc17b958a feat(ui): redesign all admin console pages
- 新增 AdminLayout 侧边栏布局组件(深色#001529侧边栏+粉色#E6508C高亮)
- 登录页:深蓝渐变背景+🌸标识+粉色登录按钮
- 仪表盘:4个统计卡片+实时护理数据表+快捷操作
- 设备管理:搜索栏+设备列表表格+状态标签+分页
- 设备详情:返回链接+信息网格+护理记录表
- 用户管理:用户列表+头像+订阅状态标签+分页
- 用户详情:用户卡片+统计数据+基本信息+护理记录
- 订阅管理:统计行+标签页筛选+订阅列表表格
- 护理记录:日期范围+搜索+模式标签+记录表格
- 操作日志:时间线列表+彩色操作者+类型标签
- 系统设置:基础配置+订阅配置+功能开关+保存按钮
2026-04-22 22:06:11 +08:00
Guoguo aa4b215c8b feat(ui): redesign all miniprogram pages
- 全局样式改为粉色(#E6508C)/金色(#DCB982)/绿色(#52c41a)配色
- 所有非tab页使用自定义导航栏,带彩色头部+标题+副标题
- login页: 粉色头部+🌸图标+微信授权登录
- scan页: 粉色头部+虚线扫码框+手动输入按钮
- ble-connect页: 蓝牙提示+搜索中/已发现设备卡片
- bind-success页: 绿色头部+成功图标+7天试用提示卡
- wear-check页: 设备信息行+佩戴指引卡片
- index首页: 粉色设备卡片+开始护理/设备管理按钮
- treatment-setup页: 模式选择+面部地图选区域
- auto-scan页: 面部轮廓+扫描线动画+检测标签
- treating页: 蓝色头部+大倒计时+渐变进度条+放松提示
- treatment-done页: 绿色头部+统计卡片+已记录提示
- subscribe-prompt页: 普通/智能模式对比+试用提示+金色订阅按钮
- subscribe-plans页: 金色头部+服务卡片+月卡/年卡选择
- subscribe-success页: 绿色头部+订阅详情卡+金色按钮
- profile页: 渐变头部+用户行+订阅卡+菜单列表
- history页: 粉色统计行+模式标签记录列表
2026-04-22 21:40:55 +08:00
Guoguo a84e37a6e2 feat: init project with miniprogram, cloud functions and admin console 2026-04-22 21:24:20 +08:00