Implement login functionality and UI updates across the application. Added silent login process in App.vue, updated styles for various components, and integrated smoke record dialog. Enhanced onboarding and profile pages with improved layouts and user experience. Updated manifest and configuration files for deployment. Added easycom configuration for component auto-import.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { ref } from 'vue'
|
||||
import { login, isLoggedIn } from '@/api/auth'
|
||||
|
||||
const loginReady = ref(false)
|
||||
let loginPromise = null
|
||||
|
||||
export function useLogin() {
|
||||
async function waitForLogin() {
|
||||
if (loginReady.value) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (loginPromise) {
|
||||
return loginPromise
|
||||
}
|
||||
|
||||
const app = getApp()
|
||||
if (app && app.globalData && app.globalData.loginPromise) {
|
||||
loginPromise = app.globalData.loginPromise
|
||||
const result = await loginPromise
|
||||
loginReady.value = true
|
||||
return result
|
||||
}
|
||||
|
||||
loginPromise = doLogin()
|
||||
return loginPromise
|
||||
}
|
||||
|
||||
async function doLogin() {
|
||||
try {
|
||||
if (!isLoggedIn()) {
|
||||
await login()
|
||||
}
|
||||
loginReady.value = true
|
||||
return true
|
||||
} catch (e) {
|
||||
console.error('登录失败:', e)
|
||||
loginReady.value = true
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureLogin() {
|
||||
if (isLoggedIn()) {
|
||||
loginReady.value = true
|
||||
return true
|
||||
}
|
||||
return waitForLogin()
|
||||
}
|
||||
|
||||
return {
|
||||
loginReady,
|
||||
waitForLogin,
|
||||
ensureLogin
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user