115 lines
2.8 KiB
Vue
115 lines
2.8 KiB
Vue
<script setup lang="ts">
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
import {
|
|
RESULT_PAGE_CONFIG,
|
|
RESULT_REDIRECT_DELAY,
|
|
type ResultPageType,
|
|
} from '@/types/result-page'
|
|
|
|
const pageType = ref<ResultPageType>('register')
|
|
const projectId = ref('')
|
|
const countdown = ref(RESULT_REDIRECT_DELAY / 1000)
|
|
let timer: ReturnType<typeof setInterval> | null = null
|
|
|
|
const pageConfig = computed(() => RESULT_PAGE_CONFIG[pageType.value])
|
|
|
|
const redirectUrl = computed(() => {
|
|
if (pageType.value === 'afterSalesSuccess' && projectId.value) {
|
|
return `${pageConfig.value.redirectUrl}?id=${encodeURIComponent(projectId.value)}&tab=aftersales`
|
|
}
|
|
return pageConfig.value.redirectUrl
|
|
})
|
|
|
|
const title = computed(() => pageConfig.value.title)
|
|
|
|
const subtitle = computed(() => {
|
|
if (pageType.value === 'modifySuccess')
|
|
return `${countdown.value}秒后自动返回`
|
|
|
|
return `${countdown.value}秒后自动跳转至${pageConfig.value.subtitleTarget}`
|
|
})
|
|
|
|
onLoad((options) => {
|
|
const type = options?.type
|
|
if (type === 'resetPassword' || type === 'reset-password') {
|
|
pageType.value = 'resetPassword'
|
|
return
|
|
}
|
|
if (type === 'passwordChanged') {
|
|
pageType.value = 'passwordChanged'
|
|
return
|
|
}
|
|
if (type === 'loginFailed') {
|
|
pageType.value = 'loginFailed'
|
|
return
|
|
}
|
|
if (type === 'submitSuccess') {
|
|
pageType.value = 'submitSuccess'
|
|
return
|
|
}
|
|
if (type === 'afterSalesSuccess') {
|
|
pageType.value = 'afterSalesSuccess'
|
|
const id = options?.id
|
|
if (id)
|
|
projectId.value = decodeURIComponent(String(id))
|
|
return
|
|
}
|
|
if (type === 'modifySuccess')
|
|
pageType.value = 'modifySuccess'
|
|
})
|
|
|
|
onMounted(() => {
|
|
timer = setInterval(() => {
|
|
countdown.value -= 1
|
|
if (countdown.value <= 0) {
|
|
if (timer) {
|
|
clearInterval(timer)
|
|
timer = null
|
|
}
|
|
const url = redirectUrl.value
|
|
// 改密 / 找回密码 / 注册等需回登录页:用 reLaunch 清空页面栈,避免返回继续操作
|
|
if (
|
|
pageType.value === 'passwordChanged'
|
|
|| pageType.value === 'resetPassword'
|
|
|| pageType.value === 'register'
|
|
) {
|
|
uni.reLaunch({ url })
|
|
return
|
|
}
|
|
|
|
uni.redirectTo({ url })
|
|
}
|
|
}, 1000)
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
if (timer) {
|
|
clearInterval(timer)
|
|
timer = null
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<view class="result-page">
|
|
<view class="result-page__content">
|
|
<image
|
|
class="result-page__icon"
|
|
:src="pageConfig.icon"
|
|
mode="aspectFit"
|
|
/>
|
|
<text class="result-page__title">
|
|
{{ title }}
|
|
</text>
|
|
<text class="result-page__subtitle">
|
|
{{ subtitle }}
|
|
</text>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
@import './index.scss';
|
|
</style>
|