mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
feat: 恋爱模块入口校验与强制解锁弹窗
- 首页快捷导航/我的页跳转恋爱日记前拦截:设密码且无有效 token 先弹解锁弹窗 - love 页初始化与清单/相册/故事三模块页防分享直达:不可关闭密码弹窗,解锁后才加载数据 - 模块数据接口 401 locked 时自动弹解锁弹窗 - 解锁弹窗开启验证码时打开即拉取显示 - 抽取 useLoveModuleUnlock 共享 hook 统一解锁流程
This commit is contained in:
@@ -73,6 +73,8 @@
|
|||||||
if (val) {
|
if (val) {
|
||||||
password.value = ''
|
password.value = ''
|
||||||
resetCaptcha()
|
resetCaptcha()
|
||||||
|
// 插件端开启验证码时打开即拉取显示,避免首次提交 403 后才出现
|
||||||
|
handleRefreshCaptcha()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
|
import { useLoveModuleUnlock } from '@/hooks/useLoveModuleUnlock'
|
||||||
|
|
||||||
const appConfigStore = useAppConfigStore()
|
const appConfigStore = useAppConfigStore()
|
||||||
|
|
||||||
@@ -13,8 +14,19 @@
|
|||||||
return configured.filter(item => item.visible !== false)
|
return configured.filter(item => item.visible !== false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* 恋爱模块解锁拦截(目前仅恋爱日记设密码,命中锁定则先解锁再跳转;样式不变) */
|
||||||
|
const {
|
||||||
|
unlockModalVisible,
|
||||||
|
unlockTip,
|
||||||
|
handleUnlockRequest,
|
||||||
|
handleUnlockSuccess,
|
||||||
|
interceptNavigateByPath,
|
||||||
|
} = useLoveModuleUnlock()
|
||||||
|
|
||||||
function handleClickNav(item : { path ?: string }) {
|
function handleClickNav(item : { path ?: string }) {
|
||||||
if (!item.path) { return }
|
if (!item.path) { return }
|
||||||
|
// 命中恋爱模块且锁定 → 弹解锁弹窗,解锁成功后由 hook 自动跳转
|
||||||
|
if (interceptNavigateByPath(item.path)) { return }
|
||||||
uni.navigateTo({ url: item.path })
|
uni.navigateTo({ url: item.path })
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -41,4 +53,9 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 恋爱模块解锁弹窗(解锁成功自动跳转) -->
|
||||||
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请解锁" captcha-enabled
|
||||||
|
:tip="unlockTip" placeholder="请输入密码" confirm-text="进入" :request="handleUnlockRequest"
|
||||||
|
@success="handleUnlockSuccess" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
placeholder ?: string
|
placeholder ?: string
|
||||||
/** 确认按钮文案 */
|
/** 确认按钮文案 */
|
||||||
confirmText ?: string
|
confirmText ?: string
|
||||||
|
/** 是否可关闭(强制解锁场景传 false:隐藏关闭按钮/取消按钮,点遮罩不关) */
|
||||||
|
closeable ?: boolean
|
||||||
/** 是否启用防刷验证码(受保护写接口 403 附新码时展示) */
|
/** 是否启用防刷验证码(受保护写接口 403 附新码时展示) */
|
||||||
captchaEnabled ?: boolean
|
captchaEnabled ?: boolean
|
||||||
/** 解锁请求函数(父组件注入具体接口;返回含 token 的对象表示成功) */
|
/** 解锁请求函数(父组件注入具体接口;返回含 token 的对象表示成功) */
|
||||||
@@ -24,6 +26,7 @@
|
|||||||
tip: '',
|
tip: '',
|
||||||
placeholder: '请输入密码',
|
placeholder: '请输入密码',
|
||||||
confirmText: '解锁',
|
confirmText: '解锁',
|
||||||
|
closeable: true,
|
||||||
captchaEnabled: false,
|
captchaEnabled: false,
|
||||||
request: undefined,
|
request: undefined,
|
||||||
})
|
})
|
||||||
@@ -85,6 +88,10 @@
|
|||||||
if (val) {
|
if (val) {
|
||||||
password.value = ''
|
password.value = ''
|
||||||
resetCaptcha()
|
resetCaptcha()
|
||||||
|
// 插件端开启验证码时打开即拉取显示,避免首次提交 403 后才出现
|
||||||
|
if (props.captchaEnabled) {
|
||||||
|
handleRefreshCaptcha()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -155,46 +162,49 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<uh-glass-popup :model-value="isShow" position="bottom" :z-index="100" custom-class="!border rounded-2xl"
|
<uh-glass-popup :model-value="isShow" position="bottom" :z-index="100" custom-class="!border rounded-2xl"
|
||||||
safe-area-inset-bottom @update:model-value="handleOnPopupClose">
|
:close-on-click-modal="closeable" safe-area-inset-bottom @update:model-value="handleOnPopupClose">
|
||||||
<view class="box-border p-4 w-full">
|
<view class="box-border p-4 w-full">
|
||||||
<view class="w-full flex items-center justify-between">
|
<view class="w-full flex items-center justify-between">
|
||||||
<view class="font-bold flex items-center gap-x-1"> <wd-icon name="lock" size="42rpx"></wd-icon> {{ title }}
|
<view class="font-bold flex items-center gap-x-1 text-love">
|
||||||
|
<wd-icon name="lock" size="42rpx"></wd-icon> {{ title }}
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view v-if="closeable"
|
||||||
class="w-6 h-6 uh-global-card-glass border uh-shadow-xs flex items-center justify-center rounded-lg"
|
class="w-6 h-6 uh-global-card-glass border uh-shadow-xs flex items-center justify-center rounded-lg"
|
||||||
@click="handleOnCancel">
|
@click="handleOnCancel">
|
||||||
<wd-icon name="close" size="32rpx"></wd-icon>
|
<wd-icon name="close" size="28rpx"></wd-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="mt-6 flex flex-col items-center">
|
<view class="mt-6 flex flex-col items-center">
|
||||||
<view class="tip-text text-sm text-gray-600">
|
<view class="tip-text text-xs text-gray-600">
|
||||||
{{ tip }}
|
{{ tip }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<input v-model="password" :password="true" :placeholder="placeholder"
|
<input v-model="password" :password="true" :placeholder="placeholder"
|
||||||
class="box-border mt-6 h-10 px-3 rounded-xl text-sm uh-global-card-glass uh-shadow-xs border" />
|
class="box-border mt-6 h-9 px-3 rounded-xl text-xs uh-global-card-glass uh-shadow-xs border" />
|
||||||
|
|
||||||
<view v-if="captchaEnabled && captchaSrc" class="mt-5 flex items-center justify-center gap-4">
|
<view v-if="captchaEnabled && captchaSrc" class="mt-5 flex items-center justify-center gap-4">
|
||||||
<input v-model="captchaCode" placeholder="验证码"
|
<input v-model="captchaCode" placeholder="验证码"
|
||||||
class="box-border flex-1 h-10 px-3 rounded-xl text-sm uh-global-card-glass uh-shadow-xs border" />
|
class="box-border flex-1 h-9 px-3 rounded-xl text-xs uh-global-card-glass uh-shadow-xs border" />
|
||||||
<image :src="captchaSrc" class="shrink-0 h-10 w-26 rounded-xl" mode="widthFix"
|
<image :src="captchaSrc" class="shrink-0 h-9 w-24 rounded-xl" mode="widthFix"
|
||||||
@click="handleRefreshCaptcha" />
|
@click="handleRefreshCaptcha" />
|
||||||
</view>
|
</view>
|
||||||
<view v-if="captchaEnabled && captchaSrc" class="mt-4 text-center text-xs text-gray-500">
|
<view v-if="captchaEnabled && captchaSrc" class="mt-4 text-center text-xs text-gray-500">
|
||||||
点击图片刷新验证码
|
点击图片刷新验证码
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 操作按钮:取消 + 解锁 -->
|
<!-- 操作按钮:取消 + 解锁(强制解锁场景隐藏取消) -->
|
||||||
<view class="mt-6 box-border flex gap-4">
|
<view class="mt-6 box-border flex gap-4">
|
||||||
<uh-button custom-class="py-2 flex-1 uh-global-card-glass rounded-xl bg-white/90"
|
<uh-button v-if="closeable" class="flex-1"
|
||||||
|
custom-class="py-2 flex-1 uh-global-card-glass text-xs rounded-xl bg-white/90"
|
||||||
@click="handleOnCancel">
|
@click="handleOnCancel">
|
||||||
取消
|
取消
|
||||||
</uh-button>
|
</uh-button>
|
||||||
<uh-button custom-class="py-2 flex-1 uh-global-card-glass rounded-xl !bg-love/90 text-white border"
|
<uh-button class="flex-1"
|
||||||
|
custom-class="py-2 flex-1 uh-global-card-glass rounded-xl text-xs !bg-love/90 text-white border"
|
||||||
@click="handleOnConfirm">
|
@click="handleOnConfirm">
|
||||||
{{ loading ? '解锁中...' : confirmText }}
|
{{ loading ? '解锁中...' : confirmText }}
|
||||||
</uh-button>
|
</uh-button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</uh-glass-popup>
|
</uh-glass-popup>
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* 恋爱模块解锁流程(供 love 页 / 首页快捷导航 / 我的页 / 三模块页共用):
|
||||||
|
* - path → moduleKey 判定(插件端下发 path 前缀匹配,兼容带 query)
|
||||||
|
* - 锁定判定(passwordEnabled && 本地无有效 token)
|
||||||
|
* - 解锁弹窗状态 + 解锁请求 + 成功回调(存 token,可配置跳转)
|
||||||
|
*/
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { unlockLoveModule, type ICaptchaQuery } from '@/api/uni-halo'
|
||||||
|
import { getLoveModuleToken, setLoveModuleToken, type LoveModuleKey } from '@/utils/loveModuleToken'
|
||||||
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
|
import type { ILoveModuleConfig } from '@/api/types/uni-halo'
|
||||||
|
|
||||||
|
/** 恋爱模块 path 前缀 → moduleKey(与插件端下发 path 约定一致) */
|
||||||
|
const LOVE_MODULE_PATH_MAP: Array<{ key: LoveModuleKey; pathPrefix: string }> = [
|
||||||
|
{ key: 'loveDiary', pathPrefix: '/pages-blog/love/love' },
|
||||||
|
{ key: 'ourStory', pathPrefix: '/pages-blog/love/stories' },
|
||||||
|
{ key: 'lovePhoto', pathPrefix: '/pages-blog/love/album' },
|
||||||
|
{ key: 'loveDaily', pathPrefix: '/pages-blog/love/list' },
|
||||||
|
]
|
||||||
|
|
||||||
|
/** 由跳转 path 反查恋爱模块 key(非恋爱模块路径返回 undefined) */
|
||||||
|
export function getLoveModuleKeyByPath(path: string): LoveModuleKey | undefined {
|
||||||
|
return LOVE_MODULE_PATH_MAP.find(item => path.startsWith(item.pathPrefix))?.key
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useLoveModuleUnlock(options?: {
|
||||||
|
/** 解锁成功(已存 token)后的回调,如刷新配置/恢复数据加载 */
|
||||||
|
onUnlocked?: (moduleKey: LoveModuleKey) => void
|
||||||
|
}) {
|
||||||
|
const appConfigStore = useAppConfigStore()
|
||||||
|
const loveConfig = computed(() => appConfigStore.configs.loveConfig)
|
||||||
|
|
||||||
|
/* ---------------- 弹窗状态 ---------------- */
|
||||||
|
const unlockModalVisible = ref(false)
|
||||||
|
/** 待解锁模块 */
|
||||||
|
const pendingModule = ref<LoveModuleKey>('loveDiary')
|
||||||
|
/** 解锁成功后跳转路径(空则不跳转) */
|
||||||
|
const pendingPath = ref('')
|
||||||
|
|
||||||
|
const unlockTip = computed(() => {
|
||||||
|
const moduleCfg = getModuleConfig(pendingModule.value)
|
||||||
|
const tip = moduleCfg?.title || ''
|
||||||
|
return `${tip}已设置访问密码,输入后进入`
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 恋爱模块配置读取(入口与三模块共用字段;loveDiary 仅密码状态) */
|
||||||
|
function getModuleConfig(moduleKey: LoveModuleKey): ILoveModuleConfig | undefined {
|
||||||
|
return (loveConfig.value as unknown as Record<string, ILoveModuleConfig | undefined>)[moduleKey]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 模块是否锁定:设了密码且本地无有效 token */
|
||||||
|
function isModuleLocked(moduleKey: LoveModuleKey): boolean {
|
||||||
|
return !!getModuleConfig(moduleKey)?.passwordEnabled && !getLoveModuleToken(moduleKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开解锁弹窗(path 用于解锁成功后跳转,空则不跳) */
|
||||||
|
function openUnlock(moduleKey: LoveModuleKey, path = '') {
|
||||||
|
pendingModule.value = moduleKey
|
||||||
|
pendingPath.value = path
|
||||||
|
unlockModalVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 通用解锁请求:unlock 签发 token(插件端要求验证码,403 附新码由弹窗展示重试) */
|
||||||
|
async function handleUnlockRequest(password: string, captcha?: ICaptchaQuery | null) {
|
||||||
|
const res = await unlockLoveModule(pendingModule.value, password, captcha)
|
||||||
|
return res.data as { token?: string, [key: string]: unknown } | null | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解锁成功:存 token → 回调 → 按配置跳转 */
|
||||||
|
function handleUnlockSuccess(data: { token?: string }) {
|
||||||
|
if (!data.token) {
|
||||||
|
uni.showToast({ icon: 'none', title: '解锁失败,请重试' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setLoveModuleToken(pendingModule.value, data.token)
|
||||||
|
options?.onUnlocked?.(pendingModule.value)
|
||||||
|
if (pendingPath.value) {
|
||||||
|
uni.navigateTo({ url: pendingPath.value })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 跳转拦截:命中恋爱模块且锁定 → 弹窗并返回 true(调用方不再跳转) */
|
||||||
|
function interceptNavigateByPath(path: string): boolean {
|
||||||
|
const moduleKey = getLoveModuleKeyByPath(path)
|
||||||
|
if (moduleKey && isModuleLocked(moduleKey)) {
|
||||||
|
openUnlock(moduleKey, path)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
unlockModalVisible,
|
||||||
|
pendingModule,
|
||||||
|
unlockTip,
|
||||||
|
isModuleLocked,
|
||||||
|
openUnlock,
|
||||||
|
handleUnlockRequest,
|
||||||
|
handleUnlockSuccess,
|
||||||
|
interceptNavigateByPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@ import { getLoveAlbumByName, getLoveAlbums } from '@/api/uni-halo'
|
|||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import { checkImageUrl } from '@/utils/url'
|
import { checkImageUrl } from '@/utils/url'
|
||||||
import { getCache, setCache } from '@/utils/storage'
|
import { getCache, setCache } from '@/utils/storage'
|
||||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
import { getLoveModuleToken, handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||||
|
import { useLoveModuleUnlock } from '@/hooks/useLoveModuleUnlock'
|
||||||
import { sleep } from '@/utils/common'
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
import { usePageScroll } from '@/hooks/usePageScroll'
|
import { usePageScroll } from '@/hooks/usePageScroll'
|
||||||
@@ -65,6 +66,37 @@ const queryParams = ref({ page: 1, size: 10 })
|
|||||||
const dataList = ref<ILoveAlbumCard[]>([])
|
const dataList = ref<ILoveAlbumCard[]>([])
|
||||||
const unlockedAlbums = ref<Record<string, string>>({})
|
const unlockedAlbums = ref<Record<string, string>>({})
|
||||||
|
|
||||||
|
/* ---------------- 恋爱模块解锁(防分享直达:锁定未解锁时不加载数据) ---------------- */
|
||||||
|
const {
|
||||||
|
unlockModalVisible,
|
||||||
|
unlockTip,
|
||||||
|
isModuleLocked,
|
||||||
|
openUnlock,
|
||||||
|
handleUnlockRequest,
|
||||||
|
handleUnlockSuccess,
|
||||||
|
} = useLoveModuleUnlock()
|
||||||
|
|
||||||
|
/** 是否放行数据加载(锁定未解锁时为 false,解锁成功置 true) */
|
||||||
|
const canLoad = ref(false)
|
||||||
|
|
||||||
|
/** 锁定则弹不可关闭解锁弹窗,返回是否放行 */
|
||||||
|
function ensureUnlocked(): boolean {
|
||||||
|
if (isModuleLocked('lovePhoto')) {
|
||||||
|
openUnlock('lovePhoto')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解锁成功:存 token 后恢复数据加载 */
|
||||||
|
function handlePageUnlockSuccess(data: { token?: string }) {
|
||||||
|
handleUnlockSuccess(data)
|
||||||
|
if (getLoveModuleToken('lovePhoto')) {
|
||||||
|
canLoad.value = true
|
||||||
|
handleGetData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 密码解锁弹窗 */
|
/** 密码解锁弹窗 */
|
||||||
const showUnlockModal = ref(false)
|
const showUnlockModal = ref(false)
|
||||||
const currentUnlockAlbum = ref<ILoveAlbumCard | null>(null)
|
const currentUnlockAlbum = ref<ILoveAlbumCard | null>(null)
|
||||||
@@ -128,8 +160,10 @@ async function handleGetData() {
|
|||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error('获取相册失败', e)
|
console.error('获取相册失败', e)
|
||||||
// 模块锁 401:清除 token 并提示
|
// 模块锁 401:清除 token 并弹不可关闭解锁弹窗(解锁后恢复加载)
|
||||||
handleLoveModuleLocked('lovePhoto', e)
|
if (handleLoveModuleLocked('lovePhoto', e)) {
|
||||||
|
openUnlock('lovePhoto')
|
||||||
|
}
|
||||||
if (loadMoreStatus.value.active) {
|
if (loadMoreStatus.value.active) {
|
||||||
updateLoadMoreStatus({
|
updateLoadMoreStatus({
|
||||||
active: false,
|
active: false,
|
||||||
@@ -216,10 +250,18 @@ onPageScroll((option: Page.PageScrollOption) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
handleRestoreUnlockedAlbums()
|
handlePageInit()
|
||||||
handleGetData()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 页面初始化:先判定模块锁定(防分享直达),解锁或未设密码才加载数据 */
|
||||||
|
async function handlePageInit() {
|
||||||
|
handleRestoreUnlockedAlbums()
|
||||||
|
await appConfigStore.bootstrap()
|
||||||
|
if (!ensureUnlocked()) { return }
|
||||||
|
canLoad.value = true
|
||||||
|
handleGetData()
|
||||||
|
}
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
resetLoadMoreStatus()
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
@@ -299,6 +341,11 @@ onReachBottom(() => {
|
|||||||
:album-name="viewerAlbumName" :album-key="viewerAlbumKey" :token="viewerAlbumToken"
|
:album-name="viewerAlbumName" :album-key="viewerAlbumKey" :token="viewerAlbumToken"
|
||||||
@update:show="showPhotoViewer = $event"
|
@update:show="showPhotoViewer = $event"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- 模块级密码解锁弹窗(强制不可关闭,防分享直达) -->
|
||||||
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请解锁" captcha-enabled
|
||||||
|
:tip="unlockTip" placeholder="请输入密码" confirm-text="进入" :closeable="false"
|
||||||
|
:request="handleUnlockRequest" @success="handlePageUnlockSuccess" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { onLoad, onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
import { onLoad, onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import { getLoveDailyItems } from '@/api/uni-halo'
|
import { getLoveDailyItems } from '@/api/uni-halo'
|
||||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
import { getLoveModuleToken, handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||||
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
|
import { useLoveModuleUnlock } from '@/hooks/useLoveModuleUnlock'
|
||||||
import { checkImageUrl } from '@/utils/url'
|
import { checkImageUrl } from '@/utils/url'
|
||||||
import { sleep } from '@/utils/common'
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
@@ -57,6 +59,38 @@
|
|||||||
const queryParams = ref({ page: 1, size: 10 })
|
const queryParams = ref({ page: 1, size: 10 })
|
||||||
const list = ref<ILoveItemCard[]>([])
|
const list = ref<ILoveItemCard[]>([])
|
||||||
|
|
||||||
|
/* ---------------- 恋爱模块解锁(防分享直达:锁定未解锁时不加载数据) ---------------- */
|
||||||
|
const appConfigStore = useAppConfigStore()
|
||||||
|
const {
|
||||||
|
unlockModalVisible,
|
||||||
|
unlockTip,
|
||||||
|
isModuleLocked,
|
||||||
|
openUnlock,
|
||||||
|
handleUnlockRequest,
|
||||||
|
handleUnlockSuccess,
|
||||||
|
} = useLoveModuleUnlock()
|
||||||
|
|
||||||
|
/** 是否放行数据加载(锁定未解锁时为 false,解锁成功置 true) */
|
||||||
|
const canLoad = ref(false)
|
||||||
|
|
||||||
|
/** 锁定则弹不可关闭解锁弹窗,返回是否放行 */
|
||||||
|
function ensureUnlocked() : boolean {
|
||||||
|
if (isModuleLocked('loveDaily')) {
|
||||||
|
openUnlock('loveDaily')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解锁成功:存 token 后恢复数据加载 */
|
||||||
|
function handlePageUnlockSuccess(data : { token ?: string }) {
|
||||||
|
handleUnlockSuccess(data)
|
||||||
|
if (getLoveModuleToken('loveDaily')) {
|
||||||
|
canLoad.value = true
|
||||||
|
handleGetList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------- 筛选与排序 ---------------- */
|
/* ---------------- 筛选与排序 ---------------- */
|
||||||
interface IFilterOption {
|
interface IFilterOption {
|
||||||
label : string
|
label : string
|
||||||
@@ -186,8 +220,10 @@
|
|||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error('获取清单失败', e)
|
console.error('获取清单失败', e)
|
||||||
// 模块锁 401:清除 token 并提示
|
// 模块锁 401:清除 token 并弹不可关闭解锁弹窗(解锁后恢复加载)
|
||||||
handleLoveModuleLocked('loveDaily', e)
|
if (handleLoveModuleLocked('loveDaily', e)) {
|
||||||
|
openUnlock('loveDaily')
|
||||||
|
}
|
||||||
if (loadMoreStatus.value.active) {
|
if (loadMoreStatus.value.active) {
|
||||||
updateLoadMoreStatus({
|
updateLoadMoreStatus({
|
||||||
active: false,
|
active: false,
|
||||||
@@ -257,9 +293,17 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
handleGetList()
|
handlePageInit()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 页面初始化:先判定模块锁定(防分享直达),解锁或未设密码才加载数据 */
|
||||||
|
async function handlePageInit() {
|
||||||
|
await appConfigStore.bootstrap()
|
||||||
|
if (!ensureUnlocked()) { return }
|
||||||
|
canLoad.value = true
|
||||||
|
handleGetList()
|
||||||
|
}
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
resetLoadMoreStatus()
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
@@ -417,5 +461,10 @@
|
|||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
</uh-glass-popup>
|
</uh-glass-popup>
|
||||||
|
|
||||||
|
<!-- 模块级密码解锁弹窗(强制不可关闭,防分享直达) -->
|
||||||
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请解锁" captcha-enabled
|
||||||
|
:tip="unlockTip" placeholder="请输入密码" confirm-text="进入" :closeable="false"
|
||||||
|
:request="handleUnlockRequest" @success="handlePageUnlockSuccess" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, onBeforeUnmount, ref } from 'vue'
|
import { onBeforeUnmount, ref } from 'vue'
|
||||||
import { onLoad, onPageScroll, onShow } from '@dcloudio/uni-app'
|
import { onLoad, onPageScroll, onShow } from '@dcloudio/uni-app'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import { checkAvatarUrl, checkImageUrl } from '@/utils/url'
|
import { checkAvatarUrl, checkImageUrl } from '@/utils/url'
|
||||||
import { getPluginCaptcha, unlockLoveModule, type ICaptchaQuery, type IPluginCaptcha } from '@/api/uni-halo'
|
import { getLoveModuleToken, type LoveModuleKey } from '@/utils/loveModuleToken'
|
||||||
import { getLoveModuleToken, setLoveModuleToken, type LoveModuleKey } from '@/utils/loveModuleToken'
|
import { useLoveModuleUnlock } from '@/hooks/useLoveModuleUnlock'
|
||||||
import { usePageScroll } from '@/hooks/usePageScroll'
|
import { usePageScroll } from '@/hooks/usePageScroll'
|
||||||
import type { ILoveConfigGroup, ILoveModuleConfig } from '@/api/types/uni-halo'
|
import type { ILoveConfigGroup, ILoveModuleConfig } from '@/api/types/uni-halo'
|
||||||
|
|
||||||
@@ -148,29 +148,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 跳转(模块密码拦截) ---------------- */
|
/* ---------------- 跳转(模块密码拦截) ---------------- */
|
||||||
/** 模块密码弹窗状态 */
|
/** 恋爱模块解锁流程(弹窗状态/请求/成功回调统一由 hook 管理) */
|
||||||
const unlockModalVisible = ref(false)
|
const {
|
||||||
/** 待跳转路径(模块下发的完整 path,解锁成功后 navigateTo) */
|
unlockModalVisible,
|
||||||
const pendingPath = ref('')
|
pendingModule,
|
||||||
const pendingModule = ref<LoveModuleKey>('ourStory')
|
unlockTip,
|
||||||
|
isModuleLocked,
|
||||||
/** 恋爱日记入口(love 页本身)是否锁定:设了密码且本地无有效 token */
|
openUnlock,
|
||||||
const loveDiaryLocked = computed(() =>
|
handleUnlockRequest,
|
||||||
!!loveConfig.value.loveDiary?.passwordEnabled && !getLoveModuleToken('loveDiary'))
|
handleUnlockSuccess,
|
||||||
|
} = useLoveModuleUnlock({
|
||||||
const unlockTip = computed(() => {
|
onUnlocked: (moduleKey) => {
|
||||||
const moduleCfg = loveConfig.value[pendingModule.value] as ILoveModuleConfig | undefined
|
// 恋爱日记入口解锁:恋爱配置已并入 getConfigs loveConfig 组,刷新后重读
|
||||||
const tip = moduleCfg?.title || ''
|
if (moduleKey === 'loveDiary') {
|
||||||
return `${tip}已设置访问密码,输入后进入`
|
appConfigStore.refreshStatic().then(() => syncLoveConfigFromStore())
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function handleToPage(moduleKey : LoveModuleKey) {
|
function handleToPage(moduleKey : LoveModuleKey) {
|
||||||
const moduleCfg = loveConfig.value[moduleKey] as ILoveModuleConfig | undefined
|
const moduleCfg = loveConfig.value[moduleKey] as ILoveModuleConfig | undefined
|
||||||
// 模块设了密码且本地无有效 token → 先弹密码框验证
|
// 模块设了密码且本地无有效 token → 先弹密码框验证
|
||||||
if (moduleCfg?.passwordEnabled && !getLoveModuleToken(moduleKey)) {
|
if (isModuleLocked(moduleKey)) {
|
||||||
pendingPath.value = moduleCfg.path || ''
|
openUnlock(moduleKey, moduleCfg?.path || '')
|
||||||
pendingModule.value = moduleKey
|
|
||||||
unlockModalVisible.value = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 跳转直接使用插件下发的 path
|
// 跳转直接使用插件下发的 path
|
||||||
@@ -181,29 +181,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 通用解锁弹窗请求:unlock 签发 token(插件端要求验证码,403 附新码由弹窗展示重试) */
|
|
||||||
async function handleUnlockRequest(password : string, captcha ?: ICaptchaQuery | null) {
|
|
||||||
const res = await unlockLoveModule(pendingModule.value, password, captcha)
|
|
||||||
return res.data as { token ?: string, [key : string] : unknown } | null | undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 解锁成功:存 token;恋爱日记入口(loveDiary)重新拉取配置,其余进入模块 */
|
|
||||||
function handleUnlockSuccess(data : { token ?: string }) {
|
|
||||||
if (data.token) {
|
|
||||||
setLoveModuleToken(pendingModule.value, data.token)
|
|
||||||
if (pendingModule.value === 'loveDiary') {
|
|
||||||
// 恋爱日记入口解锁:恋爱配置已并入 getConfigs loveConfig 组,刷新后重读
|
|
||||||
appConfigStore.refreshStatic().then(() => syncLoveConfigFromStore())
|
|
||||||
}
|
|
||||||
else if (pendingPath.value) {
|
|
||||||
uni.navigateTo({ url: pendingPath.value })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uni.showToast({ icon: 'none', title: '解锁失败,请重试' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------- 生命周期 ---------------- */
|
/* ---------------- 生命周期 ---------------- */
|
||||||
onPageScroll((option : Page.PageScrollOption) => {
|
onPageScroll((option : Page.PageScrollOption) => {
|
||||||
updatePageScrollValue(option.scrollTop)
|
updatePageScrollValue(option.scrollTop)
|
||||||
@@ -216,11 +193,9 @@
|
|||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
await appConfigStore.bootstrap()
|
await appConfigStore.bootstrap()
|
||||||
syncLoveConfigFromStore()
|
syncLoveConfigFromStore()
|
||||||
// 恋爱日记入口(love 页本身)设了密码且本地无 token → 先弹密码框验证
|
// 恋爱日记入口(love 页本身)设了密码且本地无 token → 弹不可关闭密码框,解锁后才能查看
|
||||||
if (loveDiaryLocked.value) {
|
if (isModuleLocked('loveDiary')) {
|
||||||
pendingPath.value = ''
|
openUnlock('loveDiary')
|
||||||
pendingModule.value = 'loveDiary'
|
|
||||||
unlockModalVisible.value = true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -261,7 +236,6 @@
|
|||||||
<view
|
<view
|
||||||
class="absolute z-2 left-0 bottom-0 w-full h-36 bg-gradient-to-b from-white/0 via-pink-50/50 to-pink-50" />
|
class="absolute z-2 left-0 bottom-0 w-full h-36 bg-gradient-to-b from-white/0 via-pink-50/50 to-pink-50" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 恋爱记时 -->
|
<!-- 恋爱记时 -->
|
||||||
<view class="love-time-wrap mt-8 w-screen flex flex-col items-center justify-center">
|
<view class="love-time-wrap mt-8 w-screen flex flex-col items-center justify-center">
|
||||||
<view class="title text-xl text-love font-bold">
|
<view class="title text-xl text-love font-bold">
|
||||||
@@ -315,9 +289,9 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 模块密码验证弹窗-->
|
<!-- 模块密码验证弹窗(恋爱日记入口强制解锁不可关闭;模块入口点击可取消) -->
|
||||||
<uh-unlock-popup v-model:show="unlockModalVisible" title="请输入访问密码" captcha-enabled
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请解锁" captcha-enabled
|
||||||
:tip="unlockTip"
|
:tip="unlockTip" :closeable="pendingModule !== 'loveDiary'"
|
||||||
placeholder="请输入密码" confirm-text="进入" :request="handleUnlockRequest" @success="handleUnlockSuccess" />
|
placeholder="请输入密码" confirm-text="进入" :request="handleUnlockRequest" @success="handleUnlockSuccess" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
import { onLoad, onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
import { onLoad, onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { getLoveStories } from '@/api/uni-halo'
|
import { getLoveStories } from '@/api/uni-halo'
|
||||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
import { getLoveModuleToken, handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
|
import { useLoveModuleUnlock } from '@/hooks/useLoveModuleUnlock'
|
||||||
import { checkImageUrl } from '@/utils/url'
|
import { checkImageUrl } from '@/utils/url'
|
||||||
import { sleep } from '@/utils/common'
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
@@ -111,6 +112,37 @@
|
|||||||
const currentStory = ref<IStoryCard>(EMPTY_STORY)
|
const currentStory = ref<IStoryCard>(EMPTY_STORY)
|
||||||
const storyImageIndex = ref(0)
|
const storyImageIndex = ref(0)
|
||||||
|
|
||||||
|
/* ---------------- 恋爱模块解锁(防分享直达:锁定未解锁时不加载数据) ---------------- */
|
||||||
|
const {
|
||||||
|
unlockModalVisible,
|
||||||
|
unlockTip,
|
||||||
|
isModuleLocked,
|
||||||
|
openUnlock,
|
||||||
|
handleUnlockRequest,
|
||||||
|
handleUnlockSuccess,
|
||||||
|
} = useLoveModuleUnlock()
|
||||||
|
|
||||||
|
/** 是否放行数据加载(锁定未解锁时为 false,解锁成功置 true) */
|
||||||
|
const canLoad = ref(false)
|
||||||
|
|
||||||
|
/** 锁定则弹不可关闭解锁弹窗,返回是否放行 */
|
||||||
|
function ensureUnlocked() : boolean {
|
||||||
|
if (isModuleLocked('ourStory')) {
|
||||||
|
openUnlock('ourStory')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解锁成功:存 token 后恢复数据加载 */
|
||||||
|
function handlePageUnlockSuccess(data : { token ?: string }) {
|
||||||
|
handleUnlockSuccess(data)
|
||||||
|
if (getLoveModuleToken('ourStory')) {
|
||||||
|
canLoad.value = true
|
||||||
|
handleGetStories()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetStories() {
|
async function handleGetStories() {
|
||||||
if (!loadMoreStatus.value.active) {
|
if (!loadMoreStatus.value.active) {
|
||||||
@@ -146,8 +178,11 @@
|
|||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error('获取故事失败', e)
|
console.error('获取故事失败', e)
|
||||||
// 模块锁 401:清除 token 并提示;命中 locked 时不做旧配置降级(需回入口重新解锁)
|
// 模块锁 401:清除 token 并弹不可关闭解锁弹窗(解锁后恢复加载);命中 locked 不做旧配置降级
|
||||||
if (!handleLoveModuleLocked('ourStory', e)) {
|
if (handleLoveModuleLocked('ourStory', e)) {
|
||||||
|
openUnlock('ourStory')
|
||||||
|
}
|
||||||
|
else {
|
||||||
handleLoadFromLegacy()
|
handleLoadFromLegacy()
|
||||||
}
|
}
|
||||||
if (loadMoreStatus.value.active) {
|
if (loadMoreStatus.value.active) {
|
||||||
@@ -231,9 +266,17 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
handleGetStories()
|
handlePageInit()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 页面初始化:先判定模块锁定(防分享直达),解锁或未设密码才加载数据 */
|
||||||
|
async function handlePageInit() {
|
||||||
|
await appConfigStore.bootstrap()
|
||||||
|
if (!ensureUnlocked()) { return }
|
||||||
|
canLoad.value = true
|
||||||
|
handleGetStories()
|
||||||
|
}
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
resetLoadMoreStatus()
|
resetLoadMoreStatus()
|
||||||
queryParams.value.page = 1
|
queryParams.value.page = 1
|
||||||
@@ -353,6 +396,11 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</uh-glass-popup>
|
</uh-glass-popup>
|
||||||
|
|
||||||
|
<!-- 模块级密码解锁弹窗(强制不可关闭,防分享直达) -->
|
||||||
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请解锁" captcha-enabled
|
||||||
|
:tip="unlockTip" placeholder="请输入密码" confirm-text="进入" :closeable="false"
|
||||||
|
:request="handleUnlockRequest" @success="handlePageUnlockSuccess" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import { getBlogStatistics } from '@/api/halo'
|
import { getBlogStatistics } from '@/api/halo'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import { useFavoritesStore } from '@/store/favorites'
|
import { useFavoritesStore } from '@/store/favorites'
|
||||||
|
import { useLoveModuleUnlock } from '@/hooks/useLoveModuleUnlock'
|
||||||
import { checkAvatarUrl, checkImageUrl } from '@/utils/url'
|
import { checkAvatarUrl, checkImageUrl } from '@/utils/url'
|
||||||
import { t } from '@/locale'
|
import { t } from '@/locale'
|
||||||
import type { IBlogStats } from '@/api/types/halo'
|
import type { IBlogStats } from '@/api/types/halo'
|
||||||
@@ -158,10 +159,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 交互 ---------------- */
|
/* ---------------- 交互 ---------------- */
|
||||||
|
/* 恋爱模块解锁拦截(目前仅恋爱日记设密码,命中锁定则先解锁再跳转;样式不变) */
|
||||||
|
const {
|
||||||
|
unlockModalVisible,
|
||||||
|
unlockTip,
|
||||||
|
handleUnlockRequest,
|
||||||
|
handleUnlockSuccess,
|
||||||
|
interceptNavigateByPath,
|
||||||
|
} = useLoveModuleUnlock()
|
||||||
|
|
||||||
function handleNavGoTo(data : { path : string }) {
|
function handleNavGoTo(data : { path : string }) {
|
||||||
const { path } = data
|
const { path } = data
|
||||||
if (!path) { return }
|
if (!path) { return }
|
||||||
|
|
||||||
|
// 命中恋爱模块且锁定 → 弹解锁弹窗,解锁成功后由 hook 自动跳转
|
||||||
|
if (interceptNavigateByPath(path)) { return }
|
||||||
|
|
||||||
uni.navigateTo({ url: path })
|
uni.navigateTo({ url: path })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,5 +307,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<uh-page-copyright />
|
<uh-page-copyright />
|
||||||
|
|
||||||
|
<!-- 恋爱模块解锁弹窗(解锁成功自动跳转) -->
|
||||||
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请解锁" captcha-enabled
|
||||||
|
:tip="unlockTip" placeholder="请输入密码" confirm-text="进入" :request="handleUnlockRequest"
|
||||||
|
@success="handleUnlockSuccess" />
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user