fix: setup 迁移完成 v1

This commit is contained in:
Tim
2025-08-14 10:27:01 +08:00
parent 902fce5174
commit 655e8f2a65
33 changed files with 289 additions and 393 deletions
+12 -16
View File
@@ -2,24 +2,20 @@
<CallbackPage />
</template>
<script>
<script setup>
import CallbackPage from '~/components/CallbackPage.vue'
import { discordExchange } from '~/utils/discord'
export default {
name: 'DiscordCallbackPageView',
components: { CallbackPage },
async mounted() {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await discordExchange(code, state, '')
onMounted(async () => {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await discordExchange(code, state, '')
if (result.needReason) {
this.$router.push('/signup-reason?token=' + result.token)
} else {
this.$router.push('/')
}
},
}
if (result.needReason) {
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
} else {
navigateTo('/', { replace: true })
}
})
</script>
+1 -1
View File
@@ -106,7 +106,7 @@ const resetPassword = async () => {
const data = await res.json()
if (res.ok) {
toast.success('密码已重置')
router.push('/login')
navigateTo('/login', { replace: true })
} else if (data.field === 'password') {
passwordError.value = data.error
} else {
+12 -16
View File
@@ -2,24 +2,20 @@
<CallbackPage />
</template>
<script>
<script setup>
import CallbackPage from '~/components/CallbackPage.vue'
import { githubExchange } from '~/utils/github'
export default {
name: 'GithubCallbackPageView',
components: { CallbackPage },
async mounted() {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await githubExchange(code, state, '')
onMounted(async () => {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await githubExchange(code, state, '')
if (result.needReason) {
this.$router.push('/signup-reason?token=' + result.token)
} else {
this.$router.push('/')
}
},
}
if (result.needReason) {
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
} else {
navigateTo('/', { replace: true })
}
})
</script>
+18 -22
View File
@@ -2,29 +2,25 @@
<CallbackPage />
</template>
<script>
<script setup>
import CallbackPage from '~/components/CallbackPage.vue'
import { googleAuthWithToken } from '~/utils/google'
export default {
name: 'GoogleCallbackPageView',
components: { CallbackPage },
async mounted() {
const hash = new URLSearchParams(window.location.hash.substring(1))
const idToken = hash.get('id_token')
if (idToken) {
await googleAuthWithToken(
idToken,
() => {
this.$router.push('/')
},
(token) => {
this.$router.push('/signup-reason?token=' + token)
},
)
} else {
this.$router.push('/login')
}
},
}
onMounted(async () => {
const hash = new URLSearchParams(window.location.hash.substring(1))
const idToken = hash.get('id_token')
if (idToken) {
await googleAuthWithToken(
idToken,
() => {
navigateTo('/', { replace: true })
},
(token) => {
navigateTo(`/signup-reason?token=${token}`, { replace: true })
},
)
} else {
navigateTo('/login', { replace: true })
}
})
</script>
+7 -5
View File
@@ -62,7 +62,6 @@ import BaseInput from '~/components/BaseInput.vue'
import { registerPush } from '~/utils/push'
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const username = ref('')
const password = ref('')
const isWaitingForLogin = ref(false)
@@ -81,15 +80,18 @@ const submitLogin = async () => {
await loadCurrentUser()
toast.success('登录成功')
registerPush()
router.push('/')
await navigateTo('/', { replace: true })
} else if (data.reason_code === 'NOT_VERIFIED') {
toast.info('当前邮箱未验证,已经为您重新发送验证码')
router.push({ path: '/signup', query: { verify: 1, u: username.value } })
await navigateTo(
{ path: '/signup', query: { verify: '1', u: username.value } },
{ replace: true },
)
} else if (data.reason_code === 'IS_APPROVING') {
toast.info('您的注册正在审批中, 请留意邮件')
router.push('/')
await navigateTo('/', { replace: true })
} else if (data.reason_code === 'NOT_APPROVED') {
router.push('/signup-reason?token=' + data.token)
await navigateTo({ path: '/signup-reason', query: { token: data.token } }, { replace: true })
} else {
toast.error(data.error || '登录失败')
}
+10 -12
View File
@@ -480,7 +480,6 @@
<script setup>
import { ref, onMounted, computed } from 'vue'
import { useRouter } from 'vue-router'
import BaseTimeline from '~/components/BaseTimeline.vue'
import BasePlaceholder from '~/components/BasePlaceholder.vue'
import NotificationContainer from '~/components/NotificationContainer.vue'
@@ -492,7 +491,6 @@ import TimeManager from '~/utils/time'
import { reactionEmojiMap } from '~/utils/reactions'
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const router = useRouter()
const route = useRoute()
const notifications = ref([])
const isLoadingMessage = ref(false)
@@ -590,7 +588,7 @@ const fetchNotifications = async () => {
src: n.comment.author.avatar,
iconClick: () => {
markRead(n.id)
router.push(`/users/${n.comment.author.id}`)
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
},
})
} else if (n.type === 'REACTION') {
@@ -600,7 +598,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.fromUser) {
markRead(n.id)
router.push(`/users/${n.fromUser.id}`)
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
}
},
})
@@ -612,7 +610,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.fromUser) {
markRead(n.id)
router.push(`/users/${n.fromUser.id}`)
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
}
},
})
@@ -622,7 +620,7 @@ const fetchNotifications = async () => {
src: n.comment.author.avatar,
iconClick: () => {
markRead(n.id)
router.push(`/users/${n.comment.author.id}`)
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
},
})
} else if (n.type === 'USER_ACTIVITY') {
@@ -631,7 +629,7 @@ const fetchNotifications = async () => {
src: n.comment.author.avatar,
iconClick: () => {
markRead(n.id)
router.push(`/users/${n.comment.author.id}`)
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
},
})
} else if (n.type === 'MENTION') {
@@ -641,7 +639,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.fromUser) {
markRead(n.id)
router.push(`/users/${n.fromUser.id}`)
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
}
},
})
@@ -652,7 +650,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.fromUser) {
markRead(n.id)
router.push(`/users/${n.fromUser.id}`)
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
}
},
})
@@ -663,7 +661,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.post) {
markRead(n.id)
router.push(`/posts/${n.post.id}`)
navigateTo(`/posts/${n.post.id}`, { replace: true })
}
},
})
@@ -674,7 +672,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.post) {
markRead(n.id)
router.push(`/posts/${n.post.id}`)
navigateTo(`/posts/${n.post.id}`, { replace: true })
}
},
})
@@ -686,7 +684,7 @@ const fetchNotifications = async () => {
iconClick: () => {
if (n.post) {
markRead(n.id)
router.push(`/posts/${n.post.id}`)
navigateTo(`/posts/${n.post.id}`, { replace: true })
}
},
})
+2 -3
View File
@@ -37,7 +37,7 @@
<script setup>
import { ref, onMounted, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
import PostEditor from '~/components/PostEditor.vue'
import CategorySelect from '~/components/CategorySelect.vue'
import TagSelect from '~/components/TagSelect.vue'
@@ -56,7 +56,6 @@ const isAiLoading = ref(false)
const isLogin = computed(() => authState.loggedIn)
const route = useRoute()
const router = useRouter()
const postId = route.params.id
const loadPost = async () => {
@@ -197,7 +196,7 @@ const submitPost = async () => {
}
}
const cancelEdit = () => {
router.push(`/posts/${postId}`)
navigateTo(`/posts/${postId}`, { replace: true })
}
</script>
+5 -5
View File
@@ -343,7 +343,7 @@ const startCountdown = () => {
updateCountdown()
countdownTimer = setInterval(updateCountdown, 1000)
}
const gotoUser = (id) => router.push(`/users/${id}`)
const gotoUser = (id) => navigateTo(`/users/${id}`, { replace: true })
const articleMenuItems = computed(() => {
const items = []
if (isAuthor.value || isAdmin.value) {
@@ -394,7 +394,7 @@ const mapComment = (c, parentUserName = '', level = 0) => ({
reply: (c.replies || []).map((r) => mapComment(r, c.author.username, level + 1)),
openReplies: level === 0,
src: c.author.avatar,
iconClick: () => router.push(`/users/${c.author.id}`),
iconClick: () => navigateTo(`/users/${c.author.id}`, { replace: true }),
parentUserName: parentUserName,
})
@@ -641,7 +641,7 @@ const unpinPost = async () => {
}
const editPost = () => {
router.push(`/posts/${postId}/edit`)
navigateTo(`/posts/${postId}/edit`, { replace: true })
}
const deletePost = async () => {
@@ -656,7 +656,7 @@ const deletePost = async () => {
})
if (res.ok) {
toast.success('已删除')
router.push('/')
navigateTo('/', { replace: true })
} else {
toast.error('操作失败')
}
@@ -766,7 +766,7 @@ const jumpToHashComment = async () => {
}
const gotoProfile = () => {
router.push(`/users/${author.value.id}`)
navigateTo(`/users/${author.value.id}`, { replace: true })
}
onMounted(async () => {
+2 -2
View File
@@ -65,6 +65,7 @@
</template>
<script setup>
import { ref, onMounted } from 'vue'
import AvatarCropper from '~/components/AvatarCropper.vue'
import BaseInput from '~/components/BaseInput.vue'
import Dropdown from '~/components/Dropdown.vue'
@@ -72,7 +73,6 @@ import { toast } from '~/main'
import { fetchCurrentUser, getToken, setToken } from '~/utils/auth'
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const router = useRouter()
const username = ref('')
const introduction = ref('')
const usernameError = ref('')
@@ -102,7 +102,7 @@ onMounted(async () => {
}
} else {
toast.error('请先登录')
router.push('/login')
navigateTo('/login', { replace: true })
}
isLoadingPage.value = false
})
+4 -4
View File
@@ -29,10 +29,10 @@ const error = ref('')
const isWaitingForRegister = ref(false)
const token = ref('')
onMounted(() => {
onMounted(async () => {
token.value = route.query.token || ''
if (!token.value) {
router.push('/signup')
await navigateTo({ path: '/signup' }, { replace: true })
}
})
@@ -58,10 +58,10 @@ const submit = async () => {
const data = await res.json()
if (res.ok) {
toast.success('注册理由已提交,请等待审核')
router.push('/')
await navigateTo('/', { replace: true })
} else if (data.reason_code === 'INVALID_CREDENTIALS') {
toast.error('登录已过期,请重新登录')
router.push('/login')
await navigateTo('/login', { replace: true })
} else {
toast.error(data.error || '提交失败')
}
+2 -2
View File
@@ -189,10 +189,10 @@ const verifyCode = async () => {
const data = await res.json()
if (res.ok) {
if (registerMode.value === 'WHITELIST') {
router.push('/signup-reason?token=' + data.token)
navigateTo(`/signup-reason?token=${data.token}`, { replace: true })
} else {
toast.success('注册成功,请登录')
router.push('/login')
navigateTo('/login', { replace: true })
}
} else {
toast.error(data.error || '注册失败')
+12 -16
View File
@@ -2,24 +2,20 @@
<CallbackPage />
</template>
<script>
<script setup>
import CallbackPage from '~/components/CallbackPage.vue'
import { twitterExchange } from '~/utils/twitter'
export default {
name: 'TwitterCallbackPageView',
components: { CallbackPage },
async mounted() {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await twitterExchange(code, state, '')
onMounted(async () => {
const url = new URL(window.location.href)
const code = url.searchParams.get('code')
const state = url.searchParams.get('state')
const result = await twitterExchange(code, state, '')
if (result.needReason) {
this.$router.push('/signup-reason?token=' + result.token)
} else {
this.$router.push('/')
}
},
}
if (result.needReason) {
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
} else {
navigateTo('/', { replace: true })
}
})
</script>
+1 -1
View File
@@ -506,7 +506,7 @@ const unsubscribeUser = async () => {
const gotoTag = (tag) => {
const value = encodeURIComponent(tag.id ?? tag.name)
router.push({ path: '/', query: { tags: value } })
navigateTo({ path: '/', query: { tags: value } }, { replace: true })
}
const init = async () => {