update
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
---
|
||||
import { getI18n } from "@/i18n/utils"
|
||||
import { getI18n } from "@/lib/i18n"
|
||||
|
||||
// 全站统一登录门禁,两种语义属性(按使用场景二选一,不要混用):
|
||||
// - login-required:需要登录的「动作」(收藏/翻页/看完整图…)。点击时若未登录 →
|
||||
@ -69,9 +69,25 @@ const fullLoginLabel = t('go to full login')
|
||||
import { getUser } from "@/lib/auth"
|
||||
import { login } from "@/lib/api"
|
||||
|
||||
// 全局登录 store 的数据形状。
|
||||
// 必须显式声明并注解:@types/alpinejs 的 Stores 是 `[key: string | symbol]: unknown`,
|
||||
// 内联字面量会失去上下文类型,导致各方法内 this 退化成 {}(原先 16 处报错)。
|
||||
interface AuthStore {
|
||||
isOpen: boolean
|
||||
pending: HTMLElement | null
|
||||
account: string
|
||||
password: string
|
||||
error: string
|
||||
loading: boolean
|
||||
request(el: HTMLElement): boolean
|
||||
close(): void
|
||||
submit(): Promise<void>
|
||||
goFullLogin(): void
|
||||
}
|
||||
|
||||
document.addEventListener("alpine:init", () => {
|
||||
// 全局登录 store:request(el) 返回是否放行;未登录记录 pending 并开层
|
||||
Alpine.store("auth", {
|
||||
const authStore: AuthStore = {
|
||||
isOpen: false,
|
||||
pending: null as HTMLElement | null,
|
||||
account: "",
|
||||
@ -126,7 +142,9 @@ const fullLoginLabel = t('go to full login')
|
||||
this.close()
|
||||
window.location.assign(`/${loc}/login?redirect=${encodeURIComponent(p)}`)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Alpine.store("auth", authStore)
|
||||
|
||||
// 全站统一登录门禁:两种语义属性(capture 阶段,先于元素自身 @click 处理)
|
||||
// login-required → 就地弹窗(登录后自动重放原点击)
|
||||
|
||||
Reference in New Issue
Block a user