fix(mp): T40 UI 审查全量修复 + 设计体系一致性优化
Phase 0 基础设施:
- statusTag.ts: getStatusInlineStyle() 移除内联 borderRadius/padding/fontSize,仅返回 {background, color}
- 新增 SEVERITY_COLORS + getSeverityStyle() + getSeverityLabel() 统一告警严重程度样式
- variables.scss: 新增 9 个语义颜色别名 ($success/$danger/$warning/$info 等)
- mixins.scss: 新增 status-inline mixin 统一状态标签样式
- 7 个消费者页面添加 @include status-inline CSS 补偿
Phase 1 HIGH 修复 (4 页面):
- P46 随访管理: 移除 getTypeStyle() 硬编码 fontSize,替换文字 Loading 为组件
- P45 咨询详情医护: 添加 Loading/ErrorState 三态模板 + error ref
- P02 健康数据: 添加 loading ref + Loading 组件 + 错误 toast 提示
- P48 告警中心: 替换本地 SEVERITY_COLORS/SEVERITY_LABELS 为 statusTag.ts 导出
Phase 2 全局一致性:
- 2.1 触控补全: 17 页面为可点击元素添加 min-height: $touch-min
- 2.2 字号替换: 19 文件 31 处硬编码 px → Design Token CSS 变量
- 2.3 颜色替换: 18 文件 ~50 处硬编码十六进制 → SCSS 语义变量
- 2.4 elder-mode.scss: 新增 9 个选择器到触控放大清单
Phase 3 LOW 修复:
- 3.1 统一 Loading: 21 页面旧式文字加载 → <Loading> 组件
- 3.2 useElderClass: 8 页面补全长者模式 class 绑定
- 3.3 零散修复: 按钮 44px→48px,诊断记录添加 scroll-view 无限加载
同时新增 UniApp (Vue 3 + Vite) 小程序完整代码库 (146 文件)
This commit is contained in:
139
apps/miniprogram-uniapp/src/stores/auth.ts
Normal file
139
apps/miniprogram-uniapp/src/stores/auth.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import * as authApi from '@/services/auth'
|
||||
import { clearRequestCache, markLoggingOut, clearLoggingOut } from '@/services/request'
|
||||
|
||||
function safeGet(key: string): string {
|
||||
try { return uni.getStorageSync(key) || '' } catch { return '' }
|
||||
}
|
||||
function safeSet(key: string, value: string): void {
|
||||
try { uni.setStorageSync(key, value) } catch { /* ignore */ }
|
||||
}
|
||||
function safeRemove(key: string): void {
|
||||
try { uni.removeStorageSync(key) } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const user = ref<{ id: string; username: string; display_name?: string; phone?: string; tenant_id?: string } | null>(null)
|
||||
const roles = ref<string[]>([])
|
||||
const currentPatient = ref<authApi.PatientInfo | null>(null)
|
||||
const patients = ref<authApi.PatientInfo[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const isMedicalStaff = computed(() => roles.value.some(r => ['doctor', 'nurse', 'admin', 'health_manager'].includes(r)))
|
||||
const isDoctor = computed(() => roles.value.some(r => ['doctor', 'admin'].includes(r)))
|
||||
const hasPatientProfile = computed(() => !!currentPatient.value)
|
||||
|
||||
function hasRole(code: string): boolean {
|
||||
return roles.value.some(r => r === code || r === 'admin')
|
||||
}
|
||||
|
||||
function restore() {
|
||||
try {
|
||||
const userData = safeGet('user_data')
|
||||
if (userData) user.value = JSON.parse(userData)
|
||||
const rolesData = safeGet('user_roles')
|
||||
if (rolesData) roles.value = JSON.parse(rolesData)
|
||||
} catch { /* ignore */ }
|
||||
const patient = uni.getStorageSync('current_patient')
|
||||
if (patient) currentPatient.value = patient
|
||||
}
|
||||
|
||||
async function login(code: string): Promise<boolean> {
|
||||
if (loading.value) return false
|
||||
loading.value = true
|
||||
try {
|
||||
const resp = await authApi.wechatLogin(code)
|
||||
if (resp.bound && resp.token) {
|
||||
const { access_token, refresh_token, user: u } = resp.token
|
||||
const r = (resp as any).roles instanceof Array
|
||||
? (resp as any).roles.map((r: any) => r.code || r.name || String(r))
|
||||
: []
|
||||
safeSet('access_token', access_token)
|
||||
safeSet('refresh_token', refresh_token)
|
||||
safeSet('user_data', JSON.stringify(u))
|
||||
safeSet('user_roles', JSON.stringify(r))
|
||||
safeSet('tenant_id', u.tenant_id || '')
|
||||
user.value = u
|
||||
roles.value = r
|
||||
loading.value = false
|
||||
clearLoggingOut()
|
||||
return true
|
||||
}
|
||||
safeSet('wechat_openid', resp.openid)
|
||||
loading.value = false
|
||||
return false
|
||||
} catch {
|
||||
loading.value = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function bindPhone(encryptedData: string, iv: string): Promise<boolean> {
|
||||
if (loading.value) return false
|
||||
loading.value = true
|
||||
try {
|
||||
const openid = safeGet('wechat_openid')
|
||||
if (!openid) { loading.value = false; throw new Error('登录态丢失') }
|
||||
const resp = await authApi.wechatBindPhone(openid, encryptedData, iv) as any
|
||||
const r = resp.roles instanceof Array
|
||||
? resp.roles.map((role: any) => role.code || role.name || String(role))
|
||||
: []
|
||||
safeSet('access_token', resp.access_token)
|
||||
safeSet('refresh_token', resp.refresh_token)
|
||||
safeSet('user_data', JSON.stringify(resp.user))
|
||||
safeSet('user_roles', JSON.stringify(r))
|
||||
safeSet('tenant_id', resp.user?.tenant_id || '')
|
||||
safeRemove('wechat_openid')
|
||||
user.value = resp.user
|
||||
roles.value = r
|
||||
loading.value = false
|
||||
clearLoggingOut()
|
||||
return true
|
||||
} catch (err) {
|
||||
safeRemove('wechat_openid')
|
||||
loading.value = false
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
function setCurrentPatient(patient: authApi.PatientInfo) {
|
||||
uni.setStorageSync('current_patient_id', patient.id)
|
||||
uni.setStorageSync('current_patient', patient)
|
||||
currentPatient.value = patient
|
||||
}
|
||||
|
||||
async function loadPatients() {
|
||||
try {
|
||||
patients.value = await authApi.getPatients()
|
||||
if (patients.value.length > 0 && !currentPatient.value) {
|
||||
setCurrentPatient(patients.value[0])
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function logout() {
|
||||
markLoggingOut()
|
||||
clearRequestCache()
|
||||
safeRemove('access_token')
|
||||
safeRemove('refresh_token')
|
||||
safeRemove('user_data')
|
||||
safeRemove('user_roles')
|
||||
safeRemove('tenant_id')
|
||||
safeRemove('wechat_openid')
|
||||
uni.removeStorageSync('current_patient')
|
||||
uni.removeStorageSync('current_patient_id')
|
||||
user.value = null
|
||||
roles.value = []
|
||||
currentPatient.value = null
|
||||
patients.value = []
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}
|
||||
|
||||
return {
|
||||
user, roles, currentPatient, patients, loading,
|
||||
isMedicalStaff, isDoctor, hasPatientProfile,
|
||||
hasRole, restore, login, bindPhone,
|
||||
setCurrentPatient, loadPatients, logout,
|
||||
}
|
||||
})
|
||||
112
apps/miniprogram-uniapp/src/stores/health.ts
Normal file
112
apps/miniprogram-uniapp/src/stores/health.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { api } from '@/services/request'
|
||||
import { getTodaySummary, getTrend } from '@/services/health'
|
||||
|
||||
interface CachedTrend {
|
||||
data: { date: string; value: number }[]
|
||||
cachedAt: number
|
||||
}
|
||||
|
||||
interface TodaySummary {
|
||||
blood_pressure?: { systolic: number; diastolic: number; status: string; reference_range?: string }
|
||||
heart_rate?: { value: number; status: string; reference_range?: string }
|
||||
blood_sugar?: { value: number; status: string; reference_range?: string }
|
||||
weight?: { value: number; status: string; reference_range?: string }
|
||||
}
|
||||
|
||||
interface HealthThreshold {
|
||||
id: string
|
||||
indicator: string
|
||||
direction: string
|
||||
threshold_value: number
|
||||
level: string
|
||||
is_active: boolean
|
||||
}
|
||||
|
||||
export const DEFAULT_THRESHOLDS: HealthThreshold[] = [
|
||||
{ id: '_bp_sys_high', indicator: 'systolic_bp', direction: 'high', threshold_value: 140, level: 'warning', is_active: true },
|
||||
{ id: '_bp_dia_high', indicator: 'diastolic_bp', direction: 'high', threshold_value: 90, level: 'warning', is_active: true },
|
||||
{ id: '_hr_high', indicator: 'heart_rate', direction: 'high', threshold_value: 100, level: 'warning', is_active: true },
|
||||
{ id: '_hr_low', indicator: 'heart_rate', direction: 'low', threshold_value: 60, level: 'warning', is_active: true },
|
||||
{ id: '_bs_fasting_high', indicator: 'blood_sugar_fasting', direction: 'high', threshold_value: 6.1, level: 'warning', is_active: true },
|
||||
{ id: '_bs_pp_high', indicator: 'blood_sugar_postprandial', direction: 'high', threshold_value: 7.8, level: 'warning', is_active: true },
|
||||
]
|
||||
|
||||
const CACHE_TTL = 5 * 60 * 1000
|
||||
const TODAY_SUMMARY_TTL = 60_000
|
||||
const THRESHOLD_CACHE_KEY = 'health_thresholds'
|
||||
const THRESHOLD_TTL = 24 * 60 * 60 * 1000
|
||||
|
||||
export const useHealthStore = defineStore('health', () => {
|
||||
const vitals = ref<any[]>([])
|
||||
const todaySummary = ref<TodaySummary | null>(null)
|
||||
const todaySummaryFetchedAt = ref(0)
|
||||
const trendData = ref<Record<string, CachedTrend>>({})
|
||||
const thresholds = ref<HealthThreshold[]>(DEFAULT_THRESHOLDS)
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchVitals() {
|
||||
loading.value = true
|
||||
try {
|
||||
const summary = await getTodaySummary()
|
||||
vitals.value = summary ? [summary] : []
|
||||
} catch { /* ignore */ }
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
async function refreshToday(force = false) {
|
||||
if (!force && todaySummary.value && Date.now() - todaySummaryFetchedAt.value < TODAY_SUMMARY_TTL) return
|
||||
loading.value = true
|
||||
try {
|
||||
const patientId = uni.getStorageSync('current_patient_id') || undefined
|
||||
const params: Record<string, string> = {}
|
||||
if (patientId) params.patient_id = patientId
|
||||
todaySummary.value = await api.get<TodaySummary>('/health/vital-signs/today', params)
|
||||
todaySummaryFetchedAt.value = Date.now()
|
||||
} catch { /* ignore */ }
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
async function getTrend(indicator: string, range: string): Promise<{ date: string; value: number }[]> {
|
||||
const cacheKey = `${indicator}_${range}`
|
||||
const cached = trendData.value[cacheKey]
|
||||
if (cached && Date.now() - cached.cachedAt < CACHE_TTL) return cached.data
|
||||
|
||||
try {
|
||||
const resp = await api.get<{ data_points: { date: string; value: number }[] }>(
|
||||
'/health/vital-signs/trend', { indicator, range },
|
||||
)
|
||||
const points = resp.data_points || []
|
||||
trendData.value = { ...trendData.value, [cacheKey]: { data: points, cachedAt: Date.now() } }
|
||||
return points
|
||||
} catch { return [] }
|
||||
}
|
||||
|
||||
async function fetchThresholds() {
|
||||
try {
|
||||
const cached = uni.getStorageSync(THRESHOLD_CACHE_KEY) as { data: HealthThreshold[]; ts: number } | undefined
|
||||
if (cached && Date.now() - cached.ts < THRESHOLD_TTL) {
|
||||
thresholds.value = cached.data
|
||||
return
|
||||
}
|
||||
} catch { /* cache miss */ }
|
||||
|
||||
try {
|
||||
const data = await api.get<HealthThreshold[]>('/health/critical-value-thresholds/public')
|
||||
uni.setStorageSync(THRESHOLD_CACHE_KEY, { data, ts: Date.now() })
|
||||
thresholds.value = data
|
||||
} catch { /* keep defaults */ }
|
||||
}
|
||||
|
||||
function clearCache() {
|
||||
trendData.value = {}
|
||||
todaySummary.value = null
|
||||
todaySummaryFetchedAt.value = 0
|
||||
}
|
||||
|
||||
return {
|
||||
vitals, todaySummary, trendData, thresholds, loading,
|
||||
fetchVitals, refreshToday, getTrend, fetchThresholds, clearCache,
|
||||
}
|
||||
})
|
||||
41
apps/miniprogram-uniapp/src/stores/points.ts
Normal file
41
apps/miniprogram-uniapp/src/stores/points.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import * as pointsApi from '@/services/points'
|
||||
|
||||
export const usePointsStore = defineStore('points', () => {
|
||||
const account = ref<pointsApi.PointsAccount | null>(null)
|
||||
const checkinStatus = ref<pointsApi.CheckinStatus | null>(null)
|
||||
const loading = ref(false)
|
||||
const lastFetched = ref(0)
|
||||
|
||||
const CACHE_TTL = 2 * 60 * 1000
|
||||
|
||||
async function refresh() {
|
||||
if (Date.now() - lastFetched.value < CACHE_TTL && account.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const [acct, checkin] = await Promise.all([
|
||||
pointsApi.getAccount(),
|
||||
pointsApi.getCheckinStatus(),
|
||||
])
|
||||
account.value = acct
|
||||
checkinStatus.value = checkin
|
||||
lastFetched.value = Date.now()
|
||||
} catch { /* ignore */ }
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
function invalidate() { lastFetched.value = 0 }
|
||||
|
||||
async function doCheckin(): Promise<boolean> {
|
||||
try {
|
||||
const result = await pointsApi.dailyCheckin()
|
||||
checkinStatus.value = result
|
||||
lastFetched.value = 0
|
||||
account.value = await pointsApi.getAccount()
|
||||
return true
|
||||
} catch { return false }
|
||||
}
|
||||
|
||||
return { account, checkinStatus, loading, lastFetched, refresh, invalidate, doCheckin }
|
||||
})
|
||||
20
apps/miniprogram-uniapp/src/stores/ui.ts
Normal file
20
apps/miniprogram-uniapp/src/stores/ui.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useUIStore = defineStore('ui', () => {
|
||||
const elderMode = ref(false)
|
||||
|
||||
function restore() {
|
||||
try {
|
||||
const val = uni.getStorageSync('elder_mode')
|
||||
if (val !== '' && val !== undefined) elderMode.value = !!val
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
function toggleElderMode() {
|
||||
elderMode.value = !elderMode.value
|
||||
uni.setStorageSync('elder_mode', elderMode.value)
|
||||
}
|
||||
|
||||
return { elderMode, restore, toggleElderMode }
|
||||
})
|
||||
Reference in New Issue
Block a user