qcp QCP pad
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

67 lines
1.7 KiB

import type { ICarPerson, IListItem, IOutCheckArea, IPicArea } from '@/types/service'
import { defineStore } from 'pinia'
import { store } from '@/store'
export interface IPatient {
name: string
gender?: number
idCard?: string
status?: string
age?: number
sex?: string
time?: string
}
export interface ServiceState {
currentPatient: null | IPatient
device: null | { deviceNo: string; host: string }
}
export const useServiceStore = defineStore({
id: 'service',
state: (): ServiceState => ({
currentPatient: null, // 当前病友的信息
device: null, // 当前设备的信息
}),
getters: {
deviceNo: ({ device }) => device?.deviceNo || '',
host: ({ device }) => device?.host || '',
},
actions: {
setCurrentPatient(patient: IPatient) {
this.currentPatient = patient
},
// 设置设备信息
setDevice(device: null | { deviceNo: string; host: string }) {
this.device = device
if (device?.deviceNo) {
uni.setStorageSync(uni.$u.LOCAL_KEY.DEVICE_NO, device.deviceNo)
}
if (device?.host) {
uni.setStorageSync(uni.$u.LOCAL_KEY.HOST, device.host)
}
},
// sync local device info 2 store
// 应用启动的时候调用一次 loading页调用了
syncDevice() {
const localDeviceNo = uni.getStorageSync(uni.$u.LOCAL_KEY.DEVICE_NO)
const localDeviceHost = uni.getStorageSync(uni.$u.LOCAL_KEY.HOST)
if (localDeviceNo && localDeviceHost) {
this.device = { deviceNo: localDeviceNo, host: localDeviceHost }
} else {
this.device = null
}
},
},
})
// Need to be used outside the setup
export function useServiceStoreWidthOut() {
return useServiceStore(store)
}