You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
|
|
export const useUserStore = defineStore('user', () => {
|
|
const token = ref(uni.getStorageSync('token') || '')
|
|
const patientName = ref(uni.getStorageSync('patientName') || '')
|
|
const patientIdCardNo = ref(uni.getStorageSync('patientIdCardNo') || '')
|
|
const isLoggedIn = ref(!!token.value)
|
|
|
|
function setLogin(data) {
|
|
token.value = data.access_token
|
|
patientName.value = data.patient_name
|
|
patientIdCardNo.value = data.patient_id_card_no
|
|
isLoggedIn.value = true
|
|
uni.setStorageSync('token', data.access_token)
|
|
uni.setStorageSync('patientName', data.patient_name)
|
|
uni.setStorageSync('patientIdCardNo', data.patient_id_card_no)
|
|
}
|
|
|
|
function logout() {
|
|
token.value = ''
|
|
patientName.value = ''
|
|
patientIdCardNo.value = ''
|
|
isLoggedIn.value = false
|
|
uni.removeStorageSync('token')
|
|
uni.removeStorageSync('patientName')
|
|
uni.removeStorageSync('patientIdCardNo')
|
|
uni.reLaunch({ url: '/pages/login/login' })
|
|
}
|
|
|
|
return { token, patientName, patientIdCardNo, isLoggedIn, setLogin, logout }
|
|
})
|