feat: 重构核心租住流程页面与交互体验
统一注册、看房、申请与入住等核心页面的视觉和流程衔接,补齐支付、签约与状态流转闭环,提升移动端操作连贯性。
This commit is contained in:
@@ -75,7 +75,7 @@
|
||||
|
||||
<script>
|
||||
import { getRegisteredUser, saveRegisteredUser, startAuthorizedLoginSession } from '../../utils/app-state'
|
||||
import { mergeBackendUserInfo, normalizeUser, resolveRegistrationApplicationCode } from '../../utils/flow'
|
||||
import { mergeBackendUserInfo, normalizeUser } from '../../utils/flow'
|
||||
import {
|
||||
extractLoginSession,
|
||||
matchRegisteredUser,
|
||||
@@ -83,8 +83,8 @@ import {
|
||||
resolveLoginPreparation
|
||||
} from '../../utils/login-helper'
|
||||
import { resolveBookingRedirectAfterLogin } from '../../utils/booking-entry'
|
||||
import { syncLoginStayState } from '../../utils/session-sync'
|
||||
import { registrationMyorder, userMe, usersLogin } from '@/api/index.js'
|
||||
import { parseReservationFlowResponse, getReservationCurrentNode, hasEffectiveReservationFlow } from '../../utils/reservation-flow'
|
||||
import { registrationMyorder, orderSearchedReservationFlow, userMe, usersLogin } from '@/api/index.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -235,14 +235,42 @@ export default {
|
||||
|
||||
return extractLoginSession(response, this.$getLanguage())
|
||||
},
|
||||
fetchUserInfoAfterLogin() {
|
||||
return userMe({}, this.$getLanguage())
|
||||
.then(userInfoRes => {
|
||||
return userInfoRes && userInfoRes.data ? userInfoRes.data : userInfoRes
|
||||
fetchReservationFlowAfterLogin(userCode = '') {
|
||||
const resolvedUserCode = String(userCode || '').trim()
|
||||
if (!resolvedUserCode) {
|
||||
return Promise.resolve({
|
||||
flowList: [],
|
||||
currentFlow: null,
|
||||
currentNode: null
|
||||
})
|
||||
}
|
||||
|
||||
return orderSearchedReservationFlow({
|
||||
userCode: resolvedUserCode
|
||||
}, this.$getLanguage())
|
||||
.then(response => {
|
||||
const flowList = parseReservationFlowResponse(response)
|
||||
const currentFlow = flowList.find(item => {
|
||||
const node = getReservationCurrentNode(item)
|
||||
return node && node.isCurrent
|
||||
}) || flowList[0] || null
|
||||
const currentNode = currentFlow ? getReservationCurrentNode(currentFlow) : null
|
||||
const hasActiveReservationFlow = flowList.some(item => hasEffectiveReservationFlow(item))
|
||||
return {
|
||||
flowList,
|
||||
currentFlow,
|
||||
currentNode,
|
||||
hasActiveReservationFlow
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('fetch userinfo failed', error)
|
||||
return null
|
||||
console.error('fetch reservation flow after login failed', error)
|
||||
return {
|
||||
flowList: [],
|
||||
currentFlow: null,
|
||||
currentNode: null,
|
||||
hasActiveReservationFlow: false
|
||||
}
|
||||
})
|
||||
},
|
||||
rejectHandledLogin(options = {}) {
|
||||
@@ -274,14 +302,15 @@ export default {
|
||||
async resolveLoginState() {
|
||||
const localRegisteredUser = normalizeUser(getRegisteredUser())
|
||||
const matchedLocalUser = matchRegisteredUser(localRegisteredUser, this.form.account)
|
||||
const { token, expires } = await this.loginByApi()
|
||||
const { token, expires, userCode } = await this.loginByApi()
|
||||
const latestRegistration = await this.fetchLatestRegistration()
|
||||
const loginPreparation = resolveLoginPreparation({
|
||||
language: this.$getLanguage(),
|
||||
matchedLocalUser,
|
||||
latestRegistration,
|
||||
account: this.form.account,
|
||||
password: this.form.password
|
||||
password: this.form.password,
|
||||
userCode
|
||||
})
|
||||
|
||||
if (!loginPreparation.ok) {
|
||||
@@ -301,21 +330,47 @@ export default {
|
||||
} = loginState
|
||||
|
||||
startAuthorizedLoginSession(sessionUser, token, expires)
|
||||
const backendUserInfo = await this.fetchUserInfoAfterLogin()
|
||||
const finalUser = mergeBackendUserInfo(sessionUser, backendUserInfo)
|
||||
|
||||
// 先获取用户信息(含 userCode),再获取流程
|
||||
let finalSessionUser = sessionUser
|
||||
try {
|
||||
const userInfoRes = await userMe({}, this.$getLanguage())
|
||||
finalSessionUser = mergeBackendUserInfo(sessionUser, userInfoRes)
|
||||
startAuthorizedLoginSession(finalSessionUser, token, expires)
|
||||
} catch (error) {
|
||||
console.error('fetch user info after login failed', error)
|
||||
}
|
||||
|
||||
const userCode = finalSessionUser.userCode || finalSessionUser.code || ''
|
||||
const reservationFlow = await this.fetchReservationFlowAfterLogin(userCode)
|
||||
const currentStep = reservationFlow.currentNode ? reservationFlow.currentNode.step : null
|
||||
|
||||
const finalUser = {
|
||||
...finalSessionUser,
|
||||
reservationFlowList: reservationFlow.flowList,
|
||||
currentReservationStep: currentStep,
|
||||
hasActiveReservationFlow: reservationFlow.hasActiveReservationFlow
|
||||
}
|
||||
|
||||
saveRegisteredUser(finalUser)
|
||||
startAuthorizedLoginSession(finalUser, token, expires)
|
||||
let nextRedirectUrl = this.redirectUrl
|
||||
|
||||
try {
|
||||
const stayState = await syncLoginStayState({
|
||||
language: this.$getLanguage(),
|
||||
force: true
|
||||
})
|
||||
const stayState = {
|
||||
hasCheckedIn: currentStep === 5,
|
||||
currentOrder: null,
|
||||
currentBooking: reservationFlow.hasActiveReservationFlow && reservationFlow.currentFlow
|
||||
? {
|
||||
orderNo: reservationFlow.currentFlow.orderNo || '',
|
||||
refNo: reservationFlow.currentNode ? String(reservationFlow.currentNode.refNo || '').trim() : '',
|
||||
step: currentStep
|
||||
}
|
||||
: null
|
||||
}
|
||||
nextRedirectUrl = resolveBookingRedirectAfterLogin(this.redirectUrl, stayState)
|
||||
} catch (error) {
|
||||
console.error('sync stay state after login failed', error)
|
||||
console.error('resolve booking redirect after login failed', error)
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user