fix(mobile): 登录页匹配PC端逻辑 - 输入用户名后加载租户列表
This commit is contained in:
@@ -7,16 +7,16 @@
|
||||
</div>
|
||||
<div class="login-form">
|
||||
<div class="form-item">
|
||||
<label>用户名</label>
|
||||
<input v-model="form.username" type="text" placeholder="请输入用户名" class="input" @blur="loadTenants" />
|
||||
</div>
|
||||
<div class="form-item" v-if="tenantOptions.length > 0">
|
||||
<label>医院/租户</label>
|
||||
<select v-model="form.tenantId" class="input" @change="onTenantChange">
|
||||
<option value="">请选择医院</option>
|
||||
<option v-for="t in tenantOptions" :key="t.value" :value="t.value">{{ t.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label>用户名</label>
|
||||
<input v-model="form.username" type="text" placeholder="请输入用户名" class="input" />
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label>密码</label>
|
||||
<input v-model="form.password" type="password" placeholder="请输入密码" class="input" @keyup.enter="handleLogin" />
|
||||
@@ -41,16 +41,12 @@ const currentTenantName = ref('')
|
||||
const form = ref({ username: '', password: '', tenantId: '' })
|
||||
|
||||
const loadTenants = async () => {
|
||||
if (!form.value.username) return
|
||||
try {
|
||||
const res = await authApi.getTenants()
|
||||
const res = await authApi.getUserTenants(form.value.username)
|
||||
if (res.code === 200 && res.data) {
|
||||
tenantOptions.value = res.data.map(item => ({ label: item.tenantName, value: item.tenantId || item.id }))
|
||||
const savedTenantId = localStorage.getItem('selectedTenantId')
|
||||
const savedTenantName = localStorage.getItem('selectedTenantName')
|
||||
if (savedTenantId && tenantOptions.value.some(t => t.value == savedTenantId)) {
|
||||
form.value.tenantId = savedTenantId
|
||||
currentTenantName.value = savedTenantName || ''
|
||||
} else if (tenantOptions.value.length === 1) {
|
||||
tenantOptions.value = res.data.map(item => ({ label: item.tenantName, value: item.id }))
|
||||
if (tenantOptions.value.length === 1) {
|
||||
form.value.tenantId = tenantOptions.value[0].value
|
||||
currentTenantName.value = tenantOptions.value[0].label
|
||||
}
|
||||
@@ -61,13 +57,11 @@ const loadTenants = async () => {
|
||||
const onTenantChange = () => {
|
||||
const selected = tenantOptions.value.find(t => t.value === form.value.tenantId)
|
||||
currentTenantName.value = selected ? selected.label : ''
|
||||
if (selected) {
|
||||
localStorage.setItem('selectedTenantId', selected.value)
|
||||
localStorage.setItem('selectedTenantName', selected.label)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadTenants)
|
||||
onMounted(() => {
|
||||
if (form.value.username) loadTenants()
|
||||
})
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (!form.value.username) { errorMsg.value = '请输入用户名'; return }
|
||||
@@ -81,14 +75,9 @@ const handleLogin = async () => {
|
||||
if (infoRes.code === 200) {
|
||||
const user = infoRes.user || {}
|
||||
localStorage.setItem('userInfo', JSON.stringify({
|
||||
userId: user.userId,
|
||||
userName: user.userName,
|
||||
nickName: user.nickName,
|
||||
practitionerId: user.practitionerId,
|
||||
orgId: user.orgId,
|
||||
orgName: user.orgName,
|
||||
roles: user.roles,
|
||||
permissions: user.permissions
|
||||
userId: user.userId, userName: user.userName, nickName: user.nickName,
|
||||
practitionerId: user.practitionerId, orgId: user.orgId, orgName: user.orgName,
|
||||
roles: user.roles, permissions: user.permissions
|
||||
}))
|
||||
}
|
||||
ElMessage.success('登录成功')
|
||||
@@ -98,9 +87,7 @@ const handleLogin = async () => {
|
||||
}
|
||||
} catch (e) {
|
||||
errorMsg.value = e.response?.data?.msg || '登录失败,请检查网络'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
} finally { loading.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user