|
|
@ -2,10 +2,15 @@ |
|
|
|
<div class="login-container"> |
|
|
|
<aside class="sidebar"> |
|
|
|
<ul> |
|
|
|
<li v-for="user in userList" :key="user.id" :class="[ |
|
|
|
'user', |
|
|
|
{ selected: user.account === selectedUser?.account }, |
|
|
|
]" @click="selectUser(user)"> |
|
|
|
<li |
|
|
|
v-for="user in userList" |
|
|
|
:key="user.id" |
|
|
|
:class="[ |
|
|
|
'user', |
|
|
|
{ selected: user.account === selectedUser?.account }, |
|
|
|
]" |
|
|
|
@click="selectUser(user)" |
|
|
|
> |
|
|
|
{{ user.account }} |
|
|
|
</li> |
|
|
|
</ul> |
|
|
@ -14,10 +19,19 @@ |
|
|
|
<div class="pin-container"> |
|
|
|
<p :class="['pin-prompt', { shake: isShaking }]">{{ loginStatus }}</p> |
|
|
|
<div class="pin-indicators"> |
|
|
|
<span v-for="n in maxPinLength" :key="n" :class="['pin-dot', { filled: n <= pin.length }]"></span> |
|
|
|
<span |
|
|
|
v-for="n in maxPinLength" |
|
|
|
:key="n" |
|
|
|
:class="['pin-dot', { filled: n <= pin.length }]" |
|
|
|
></span> |
|
|
|
</div> |
|
|
|
<div class="pin-keypad"> |
|
|
|
<div v-for="n in 9" :key="n" class="key" @click="inputPin(n.toString())"> |
|
|
|
<div |
|
|
|
v-for="n in 9" |
|
|
|
:key="n" |
|
|
|
class="key" |
|
|
|
@click="inputPin(n.toString())" |
|
|
|
> |
|
|
|
{{ n }} |
|
|
|
</div> |
|
|
|
<div class="key" @click="clearPin">重输</div> |
|
|
@ -30,11 +44,17 @@ |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup lang="ts"> |
|
|
|
import { onMounted, ref, watch } from 'vue' |
|
|
|
import { onMounted, onUnmounted, ref, watch } from 'vue' |
|
|
|
import { login, getUserList } from '../../services/index' |
|
|
|
import type { User } from '../../types/Index' |
|
|
|
import { useRouter } from 'vue-router' |
|
|
|
import { getServerInfo } from '@/utils/getServerInfo' |
|
|
|
import { createWebSocket, DeviceContextStateMessage } from '@/websocket/socket' |
|
|
|
const router = useRouter() |
|
|
|
|
|
|
|
const stateUrl = getServerInfo('/api/v1/app/ws/state') |
|
|
|
const wsState = createWebSocket(stateUrl.wsUrl) |
|
|
|
|
|
|
|
// 用户角色 |
|
|
|
// const roles = ref(['护士', '管理员', '测试人员']) |
|
|
|
// const selectedRole = ref('护士') |
|
|
@ -45,11 +65,29 @@ const getUserListData = async () => { |
|
|
|
const res = await getUserList() |
|
|
|
userList.value = res.data |
|
|
|
} |
|
|
|
const handleDeviceContextState = (data: DeviceContextStateMessage['data']) => { |
|
|
|
if (data.loginFlag) { |
|
|
|
sessionStorage.setItem('token', JSON.stringify(data.loginUser)) |
|
|
|
router.push('/index') |
|
|
|
} |
|
|
|
} |
|
|
|
onMounted(() => { |
|
|
|
wsState.subscribe<DeviceContextStateMessage>( |
|
|
|
'DeviceContext', |
|
|
|
handleDeviceContextState, |
|
|
|
) |
|
|
|
wsState.connect() |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
getUserListData() |
|
|
|
}, 500) |
|
|
|
}) |
|
|
|
onUnmounted(() => { |
|
|
|
wsState.unsubscribe<DeviceContextStateMessage>( |
|
|
|
'DeviceContext', |
|
|
|
handleDeviceContextState, |
|
|
|
) |
|
|
|
}) |
|
|
|
//选中的用户 |
|
|
|
const selectedUser = ref<User | null>(null) |
|
|
|
// PIN 相关 |
|
|
@ -101,13 +139,12 @@ const submitPin = async () => { |
|
|
|
password: pin.value, |
|
|
|
} |
|
|
|
const res = await login(params) |
|
|
|
console.log(res); |
|
|
|
console.log(res) |
|
|
|
if (res.success) { |
|
|
|
loginStatus.value = '登录成功' |
|
|
|
sessionStorage.setItem('token', JSON.stringify(res.data)) |
|
|
|
router.push('/index') |
|
|
|
} else { |
|
|
|
|
|
|
|
loginStatus.value = `${res.info}` |
|
|
|
pin.value = '' |
|
|
|
} |
|
|
|