fix(miniprogram): 审计修复 — P0/P1 共 16 个问题
P0 功能阻断: - 修复 login→bindPhone openid 状态传递断裂 - 首页健康卡片对接 useHealthStore 真实数据 - 血压录入改为收缩压/舒张压双输入 - 快捷服务路径修正(报告→/pages/report、随访→/pages/followup) P1 类型安全 + 组件: - 替换所有 <input>/<image>/<textarea> 为 Taro 组件 - service 层 any 类型全部替换(Doctor/DoctorSchedule/IndicatorDetail/FollowUpContent/PatientUpdateInput) - 预约详情数据传递简化为纯 Storage 缓存 - Article 接口添加 author 字段
This commit is contained in:
@@ -2,6 +2,12 @@ import { create } from 'zustand';
|
||||
import Taro from '@tarojs/taro';
|
||||
import * as authApi from '../services/auth';
|
||||
|
||||
interface BindPhoneResp {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
user: { id: string; username: string; display_name?: string; phone?: string; tenant_id?: string };
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
token: string | null;
|
||||
refreshToken: string | null;
|
||||
@@ -11,7 +17,7 @@ interface AuthState {
|
||||
loading: boolean;
|
||||
|
||||
login: (code: string) => Promise<boolean>;
|
||||
bindPhone: (openid: string, encryptedData: string, iv: string) => Promise<boolean>;
|
||||
bindPhone: (encryptedData: string, iv: string) => Promise<boolean>;
|
||||
setCurrentPatient: (patient: authApi.PatientInfo) => void;
|
||||
loadPatients: () => Promise<void>;
|
||||
logout: () => void;
|
||||
@@ -47,6 +53,8 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
set({ token: access_token, refreshToken: refresh_token, user, loading: false });
|
||||
return true;
|
||||
}
|
||||
// 未绑定手机号,缓存 openid 供后续 bindPhone 使用
|
||||
Taro.setStorageSync('wechat_openid', resp.openid);
|
||||
set({ loading: false });
|
||||
return false;
|
||||
} catch {
|
||||
@@ -55,14 +63,21 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
}
|
||||
},
|
||||
|
||||
bindPhone: async (openid: string, encryptedData: string, iv: string) => {
|
||||
bindPhone: async (encryptedData: string, iv: string) => {
|
||||
set({ loading: true });
|
||||
try {
|
||||
const resp: any = await authApi.wechatBindPhone(openid, encryptedData, iv);
|
||||
const openid = Taro.getStorageSync('wechat_openid') || '';
|
||||
if (!openid) {
|
||||
set({ loading: false });
|
||||
return false;
|
||||
}
|
||||
const resp = await authApi.wechatBindPhone(openid, encryptedData, iv) as BindPhoneResp;
|
||||
const { access_token, refresh_token, user } = resp;
|
||||
Taro.setStorageSync('access_token', access_token);
|
||||
Taro.setStorageSync('refresh_token', refresh_token);
|
||||
Taro.setStorageSync('user', user);
|
||||
Taro.setStorageSync('tenant_id', user.tenant_id || '');
|
||||
Taro.removeStorageSync('wechat_openid');
|
||||
set({ token: access_token, refreshToken: refresh_token, user, loading: false });
|
||||
return true;
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user