mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
feat(love): 恋爱解锁弹窗通用化,接入 token 失效存储与模块配置
This commit is contained in:
@@ -112,6 +112,13 @@ export interface IPageConfig {
|
|||||||
categoryConfig?: { type?: string }
|
categoryConfig?: { type?: string }
|
||||||
momentConfig?: { useTagRandomColor?: boolean }
|
momentConfig?: { useTagRandomColor?: boolean }
|
||||||
galleryConfig?: { pageTitle?: string }
|
galleryConfig?: { pageTitle?: string }
|
||||||
|
/** 恋爱日记页(插件端「通用配置 → 页面设置 → 恋爱日记」配置;
|
||||||
|
* 2026-09-11 起恋爱页背景图由 loveConfig.pageImages 迁入此处) */
|
||||||
|
loveDiaryConfig?: {
|
||||||
|
pageTitle?: string
|
||||||
|
/** 恋爱页背景图(留空客户端内置回退) */
|
||||||
|
bgImageUrl?: string
|
||||||
|
}
|
||||||
aboutConfig?: {
|
aboutConfig?: {
|
||||||
bgImageUrl?: string
|
bgImageUrl?: string
|
||||||
waveImageUrl?: string
|
waveImageUrl?: string
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { getPluginCaptcha } from '@/api/uni-halo'
|
||||||
|
import type { ICaptchaQuery, IPluginCaptcha } from '@/api/uni-halo'
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
show : boolean
|
||||||
|
/** 弹窗标题(如"解锁相册"/"请输入访问密码") */
|
||||||
|
title ?: string
|
||||||
|
/** 提示文案(如"此相册已加密,请输入密码查看") */
|
||||||
|
tip ?: string
|
||||||
|
/** 密码输入占位符 */
|
||||||
|
placeholder ?: string
|
||||||
|
/** 确认按钮文案 */
|
||||||
|
confirmText ?: string
|
||||||
|
/** 是否启用防刷验证码(受保护写接口 403 附新码时展示) */
|
||||||
|
captchaEnabled ?: boolean
|
||||||
|
/** 解锁请求函数(父组件注入具体接口;返回含 token 的对象表示成功) */
|
||||||
|
request ?: (password : string, captcha ?: ICaptchaQuery | null) => Promise<{ token ?: string, [key : string] : unknown } | null | undefined>
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<IProps>(), {
|
||||||
|
title: '解锁',
|
||||||
|
tip: '',
|
||||||
|
placeholder: '请输入密码',
|
||||||
|
confirmText: '解锁',
|
||||||
|
captchaEnabled: false,
|
||||||
|
request: undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e : 'update:show', show : boolean) : void
|
||||||
|
(e : 'success', data : { token ?: string, [key : string] : unknown }) : void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const isShow = ref(false)
|
||||||
|
const password = ref('')
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
// 防刷验证码(服务端 403 附新码 / 主动刷新;captchaEnabled 时启用)
|
||||||
|
const captchaImage = ref('')
|
||||||
|
const captchaId = ref('')
|
||||||
|
const captchaCode = ref('')
|
||||||
|
const captchaLoading = ref(false)
|
||||||
|
|
||||||
|
const captchaSrc = computed(() => {
|
||||||
|
if (!captchaImage.value)
|
||||||
|
return ''
|
||||||
|
return captchaImage.value.startsWith('data:')
|
||||||
|
? captchaImage.value
|
||||||
|
: `data:image/png;base64,${captchaImage.value}`
|
||||||
|
})
|
||||||
|
|
||||||
|
function resetCaptcha() {
|
||||||
|
captchaImage.value = ''
|
||||||
|
captchaId.value = ''
|
||||||
|
captchaCode.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 用服务端返回的验证码(403 响应体附新码)填充展示 */
|
||||||
|
function applyCaptcha(captcha : IPluginCaptcha) {
|
||||||
|
captchaImage.value = captcha.imageBase64
|
||||||
|
captchaId.value = captcha.id
|
||||||
|
captchaCode.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 点击验证码图刷新 */
|
||||||
|
async function handleRefreshCaptcha() {
|
||||||
|
if (captchaLoading.value) { return }
|
||||||
|
captchaLoading.value = true
|
||||||
|
try {
|
||||||
|
const res = await getPluginCaptcha()
|
||||||
|
if (res.data) { applyCaptcha(res.data) }
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('获取验证码失败', e)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
captchaLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.show, (val) => {
|
||||||
|
isShow.value = val
|
||||||
|
if (val) {
|
||||||
|
password.value = ''
|
||||||
|
resetCaptcha()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 弹窗开关同步(遮罩/关闭按钮/取消):关闭时复位输入并通知父组件 */
|
||||||
|
function handleOnPopupClose(val : boolean) {
|
||||||
|
isShow.value = val
|
||||||
|
if (!val) {
|
||||||
|
password.value = ''
|
||||||
|
resetCaptcha()
|
||||||
|
}
|
||||||
|
emit('update:show', val)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOnCancel() {
|
||||||
|
handleOnPopupClose(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleOnConfirm() {
|
||||||
|
if (loading.value)
|
||||||
|
return
|
||||||
|
if (!password.value.trim()) {
|
||||||
|
uni.showToast({ title: '请输入密码', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!props.request) {
|
||||||
|
uni.showToast({ title: '未配置解锁请求', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const captchaQuery : ICaptchaQuery | undefined = props.captchaEnabled && captchaImage.value
|
||||||
|
? { captchaId: captchaId.value, captchaCode: captchaCode.value }
|
||||||
|
: undefined
|
||||||
|
const res = await props.request(password.value, captchaQuery)
|
||||||
|
if (res && res.token) {
|
||||||
|
password.value = ''
|
||||||
|
resetCaptcha()
|
||||||
|
isShow.value = false
|
||||||
|
emit('update:show', false)
|
||||||
|
emit('success', res)
|
||||||
|
uni.showToast({ title: '解锁成功', icon: 'success' })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uni.showToast({ title: '解锁失败,请重试', icon: 'none' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('解锁失败', e)
|
||||||
|
const err = e as { code ?: number, data ?: { message ?: string, captcha ?: IPluginCaptcha } }
|
||||||
|
if (err.code === 403 && err.data?.captcha) {
|
||||||
|
// 需要/校验失败:服务端附新验证码(一次性,旧码已作废),展示并要求重试
|
||||||
|
applyCaptcha(err.data.captcha)
|
||||||
|
uni.showToast({ title: '请完成验证码后重新解锁', icon: 'none' })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 密码错误等业务失败:清空密码并复位验证码(一次性,需重新获取)
|
||||||
|
password.value = ''
|
||||||
|
resetCaptcha()
|
||||||
|
uni.showToast({ title: '密码错误,请重试', icon: 'none' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<uh-glass-popup :model-value="isShow" position="bottom" :z-index="100" custom-class="!border rounded-2xl"
|
||||||
|
safe-area-inset-bottom @update:model-value="handleOnPopupClose">
|
||||||
|
<view class="box-border p-4 w-full">
|
||||||
|
<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>
|
||||||
|
<view
|
||||||
|
class="w-6 h-6 uh-global-card-glass border uh-shadow-xs flex items-center justify-center rounded-lg"
|
||||||
|
@click="handleOnCancel">
|
||||||
|
<wd-icon name="close" size="32rpx"></wd-icon>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="mt-6 flex flex-col items-center">
|
||||||
|
<view class="tip-text text-sm text-gray-600">
|
||||||
|
{{ tip }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<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" />
|
||||||
|
|
||||||
|
<view v-if="captchaEnabled && captchaSrc" class="mt-5 flex items-center justify-center gap-4">
|
||||||
|
<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" />
|
||||||
|
<image :src="captchaSrc" class="shrink-0 h-10 w-26 rounded-xl" mode="widthFix"
|
||||||
|
@click="handleRefreshCaptcha" />
|
||||||
|
</view>
|
||||||
|
<view v-if="captchaEnabled && captchaSrc" class="mt-4 text-center text-xs text-gray-500">
|
||||||
|
点击图片刷新验证码
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 操作按钮:取消 + 解锁 -->
|
||||||
|
<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"
|
||||||
|
@click="handleOnCancel">
|
||||||
|
取消
|
||||||
|
</uh-button>
|
||||||
|
<uh-button custom-class="py-2 flex-1 uh-global-card-glass rounded-xl !bg-love/90 text-white border"
|
||||||
|
@click="handleOnConfirm">
|
||||||
|
{{ loading ? '解锁中...' : confirmText }}
|
||||||
|
</uh-button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</uh-glass-popup>
|
||||||
|
</template>
|
||||||
@@ -20,6 +20,7 @@ export const DefaultAppConfigs: IAppConfig = {
|
|||||||
momentConfig: {
|
momentConfig: {
|
||||||
useTagRandomColor: true,
|
useTagRandomColor: true,
|
||||||
},
|
},
|
||||||
|
loveDiaryConfig: {},
|
||||||
},
|
},
|
||||||
auditConfig: {
|
auditConfig: {
|
||||||
auditModeEnabled: false,
|
auditModeEnabled: false,
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
|
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { getLoveAlbumByName, getLoveAlbums } from '@/api/uni-halo'
|
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 { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||||
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
import type { ILoveAlbum, ILovePhoto } from '@/api/types/uni-halo'
|
import type { ILoveAlbum, ILovePhoto } from '@/api/types/uni-halo'
|
||||||
|
|
||||||
@@ -57,7 +58,8 @@ function mapAlbumCard(item: ILoveAlbum): ILoveAlbumCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
|
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>>({})
|
||||||
|
|
||||||
@@ -101,12 +103,24 @@ function handleSaveUnlockedAlbums() {
|
|||||||
|
|
||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetData() {
|
async function handleGetData() {
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = await getLoveAlbums({})
|
const res = await getLoveAlbums({ ...queryParams.value })
|
||||||
const items = res.data?.items || []
|
const items = (res.data?.items || []).map(mapAlbumCard)
|
||||||
dataList.value = items.map(mapAlbumCard)
|
dataList.value = loadMoreStatus.value.active
|
||||||
|
? dataList.value.concat(items)
|
||||||
|
: items
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
|
await sleep(600)
|
||||||
updateLoadingStatus(dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
updateLoadingStatus(dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
||||||
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data?.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: !!res.data?.hasNext,
|
||||||
|
})
|
||||||
if (dataList.value.length > 0)
|
if (dataList.value.length > 0)
|
||||||
handleLoadUnlockedAlbumPhotos()
|
handleLoadUnlockedAlbumPhotos()
|
||||||
}
|
}
|
||||||
@@ -114,12 +128,18 @@ async function handleGetData() {
|
|||||||
console.error('获取相册失败', e)
|
console.error('获取相册失败', e)
|
||||||
// 模块锁 401:清除 token 并提示
|
// 模块锁 401:清除 token 并提示
|
||||||
handleLoveModuleLocked('lovePhoto', e)
|
handleLoveModuleLocked('lovePhoto', e)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally {
|
finally {
|
||||||
setTimeout(() => {
|
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}, 200)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,8 +215,26 @@ onLoad(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
|
resetLoadMoreStatus()
|
||||||
|
queryParams.value.page = 1
|
||||||
handleGetData()
|
handleGetData()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
// 正在加载时阻止重复请求
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 有更多数据时继续加载
|
||||||
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetData()
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -242,6 +280,7 @@ onPullDownRefresh(() => {
|
|||||||
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
<!-- 密码解锁弹窗 -->
|
<!-- 密码解锁弹窗 -->
|
||||||
<uh-album-unlock-popup
|
<uh-album-unlock-popup
|
||||||
v-if="currentUnlockAlbum" v-model="showUnlockModal" :show="showUnlockModal" :album-name="unlockAlbumName"
|
v-if="currentUnlockAlbum" v-model="showUnlockModal" :show="showUnlockModal" :album-name="unlockAlbumName"
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
/**
|
|
||||||
* 恋爱清单页
|
|
||||||
* 恋爱清单卡片列表(未开始/进行中/已完成),展开查看详情与回忆图片
|
|
||||||
*/
|
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
|
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||||
import { getLoveDailyItems } from '@/api/uni-halo'
|
import { getLoveDailyItems } from '@/api/uni-halo'
|
||||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||||
import { checkImageUrl } from '@/utils/url'
|
import { checkImageUrl } from '@/utils/url'
|
||||||
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
import type { ILoveDailyItem } from '@/api/types/uni-halo'
|
import type { ILoveDailyItem } from '@/api/types/uni-halo'
|
||||||
|
|
||||||
@@ -53,7 +50,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
|
const queryParams = ref({ page: 1, size: 10 })
|
||||||
const list = ref<ILoveItemCard[]>([])
|
const list = ref<ILoveItemCard[]>([])
|
||||||
|
|
||||||
/* ---------------- 筛选与排序 ---------------- */
|
/* ---------------- 筛选与排序 ---------------- */
|
||||||
@@ -164,23 +162,41 @@
|
|||||||
|
|
||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetList() {
|
async function handleGetList() {
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = await getLoveDailyItems({})
|
const res = await getLoveDailyItems({ ...queryParams.value })
|
||||||
const items = res.data?.items || []
|
const items = (res.data?.items || []).map(mapItemCard)
|
||||||
list.value = items.map(mapItemCard)
|
list.value = loadMoreStatus.value.active
|
||||||
|
? list.value.concat(items)
|
||||||
|
: items
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
|
await sleep(600)
|
||||||
updateLoadingStatus(list.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
updateLoadingStatus(list.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
|
||||||
}
|
}
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data?.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: !!res.data?.hasNext,
|
||||||
|
})
|
||||||
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error('获取清单失败', e)
|
console.error('获取清单失败', e)
|
||||||
// 模块锁 401:清除 token 并提示
|
// 模块锁 401:清除 token 并提示
|
||||||
handleLoveModuleLocked('loveDaily', e)
|
handleLoveModuleLocked('loveDaily', e)
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally {
|
finally {
|
||||||
setTimeout(() => {
|
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}, 200)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,8 +254,26 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
|
resetLoadMoreStatus()
|
||||||
|
queryParams.value.page = 1
|
||||||
handleGetList()
|
handleGetList()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
// 正在加载时阻止重复请求
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 有更多数据时继续加载
|
||||||
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetList()
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -341,9 +375,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
<view class="box-border py-10 text-center text-xs text-gray-500">
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
|
|
||||||
</view>
|
|
||||||
<uh-data-loading v-if="showList.length === 0" :loading-status="DataLoadingStatusEnum.Empty"
|
<uh-data-loading v-if="showList.length === 0" :loading-status="DataLoadingStatusEnum.Empty"
|
||||||
min-height="42vh" empty-text="该筛选条件下暂无清单~" :use-refresh-button="false" />
|
min-height="42vh" empty-text="该筛选条件下暂无清单~" :use-refresh-button="false" />
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
import { onLoad, 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 { unlockLoveModule } from '@/api/uni-halo'
|
import { getPluginCaptcha, unlockLoveModule, type ICaptchaQuery, type IPluginCaptcha } from '@/api/uni-halo'
|
||||||
import { getLoveModuleToken, setLoveModuleToken, type LoveModuleKey } from '@/utils/loveModuleToken'
|
import { getLoveModuleToken, setLoveModuleToken, type LoveModuleKey } from '@/utils/loveModuleToken'
|
||||||
|
|
||||||
definePage({
|
definePage({
|
||||||
@@ -31,24 +31,19 @@
|
|||||||
waveImageUrl : string
|
waveImageUrl : string
|
||||||
heartImageUrl : string
|
heartImageUrl : string
|
||||||
}
|
}
|
||||||
|
loveDiary : { enabled : boolean, passwordEnabled ?: boolean }
|
||||||
ourStory : { enabled : boolean, passwordEnabled ?: boolean }
|
ourStory : { enabled : boolean, passwordEnabled ?: boolean }
|
||||||
lovePhoto : { enabled : boolean, passwordEnabled ?: boolean }
|
lovePhoto : { enabled : boolean, passwordEnabled ?: boolean }
|
||||||
loveDaily : { enabled : boolean, passwordEnabled ?: boolean }
|
loveDaily : { enabled : boolean, passwordEnabled ?: boolean }
|
||||||
/** 恋爱页入口列表(插件端 spec.love.navList 经 getConfigs 下发,additive;
|
|
||||||
* 字段 key/title/subTitle/priority/visible,desc 已改名 subTitle) */
|
|
||||||
navList ?: ILoveNavItem[]
|
navList ?: ILoveNavItem[]
|
||||||
[key : string] : unknown
|
[key : string] : unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 恋爱页入口项(对齐插件端 GeneralConfig.LoveNavItem;key 固定 stories/album/list) */
|
|
||||||
interface ILoveNavItem {
|
interface ILoveNavItem {
|
||||||
key : string
|
key : string
|
||||||
title ?: string
|
title ?: string
|
||||||
/** 副标题(原 app 端 desc 文案改名 subTitle) */
|
|
||||||
subTitle ?: string
|
subTitle ?: string
|
||||||
/** 排序(越大越靠前) */
|
|
||||||
priority ?: number
|
priority ?: number
|
||||||
/** 是否展示(不可删除,仅禁用/启用) */
|
|
||||||
visible ?: boolean
|
visible ?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +62,7 @@
|
|||||||
waveImageUrl: '',
|
waveImageUrl: '',
|
||||||
heartImageUrl: '',
|
heartImageUrl: '',
|
||||||
},
|
},
|
||||||
|
loveDiary: { enabled: false, passwordEnabled: false },
|
||||||
ourStory: { enabled: false, passwordEnabled: false },
|
ourStory: { enabled: false, passwordEnabled: false },
|
||||||
lovePhoto: { enabled: false, passwordEnabled: false },
|
lovePhoto: { enabled: false, passwordEnabled: false },
|
||||||
loveDaily: { enabled: false, passwordEnabled: false },
|
loveDaily: { enabled: false, passwordEnabled: false },
|
||||||
@@ -75,27 +71,24 @@
|
|||||||
const loveDayCount = ref({ d: 0, h: 0, m: 0, s: 0 })
|
const loveDayCount = ref({ d: 0, h: 0, m: 0, s: 0 })
|
||||||
let loveDayTimer : ReturnType<typeof setTimeout> | null = null
|
let loveDayTimer : ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
/** 恋爱页入口渲染项(字段由 initList 从插件端 loveConfig.navList 合成:key 映射图标/路径、desc→subTitle) */
|
|
||||||
interface ILoveNavRenderItem {
|
interface ILoveNavRenderItem {
|
||||||
key : string
|
key : string
|
||||||
use : boolean
|
use : boolean
|
||||||
|
locked: boolean
|
||||||
iconPrefix : string
|
iconPrefix : string
|
||||||
icon : string
|
icon : string
|
||||||
title : string
|
title : string
|
||||||
subTitle : string
|
subTitle : string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否使用本地的恋爱页入口数据(本地的可以任意修改图标/路径/文案,插件端的仅可配置 title/subTitle/排序/显隐)
|
|
||||||
const useLocalNav = false
|
const useLocalNav = false
|
||||||
|
|
||||||
/** 内置默认入口项(未配置时回退;字段命名与插件端 loveConfig.navList 一致,desc 文案改名 subTitle) */
|
|
||||||
const DEFAULT_NAV_LIST : ILoveNavItem[] = [
|
const DEFAULT_NAV_LIST : ILoveNavItem[] = [
|
||||||
{ key: 'stories', title: '恋爱故事', subTitle: '我们一起度过的那些经历', priority: 1, visible: true },
|
{ key: 'stories', title: '恋爱故事', subTitle: '我们一起度过的那些经历', priority: 1, visible: true },
|
||||||
{ key: 'album', title: '恋爱相册', subTitle: '定格了我们的那些小美好', priority: 2, visible: true },
|
{ key: 'album', title: '恋爱相册', subTitle: '定格了我们的那些小美好', priority: 2, visible: true },
|
||||||
{ key: 'list', title: '恋爱清单', subTitle: '你我之间的约定我们都在努力实现', priority: 3, visible: true },
|
{ key: 'list', title: '恋爱清单', subTitle: '你我之间的约定我们都在努力实现', priority: 3, visible: true },
|
||||||
]
|
]
|
||||||
|
|
||||||
/** 入口 key → 图标与跳转页映射(固定:key=stories/album/list,对应恋爱三模块) */
|
|
||||||
const NAV_META: Record<string, { iconPrefix: string, icon: string, page: string }> = {
|
const NAV_META: Record<string, { iconPrefix: string, icon: string, page: string }> = {
|
||||||
stories: { iconPrefix: 'uhlove-icon', icon: 'gushi', page: 'stories' },
|
stories: { iconPrefix: 'uhlove-icon', icon: 'gushi', page: 'stories' },
|
||||||
album: { iconPrefix: 'uhlove-icon', icon: 'xiangce', page: 'album' },
|
album: { iconPrefix: 'uhlove-icon', icon: 'xiangce', page: 'album' },
|
||||||
@@ -120,28 +113,36 @@
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 getConfigs.loveConfig 取模块开关与页面图片(缺省保留默认)
|
|
||||||
const loveModuleConfig = appConfigs.loveConfig as Partial<ILoveConfigPage> | undefined
|
const loveModuleConfig = appConfigs.loveConfig as Partial<ILoveConfigPage> | undefined
|
||||||
if (loveModuleConfig) {
|
// 恋爱页背景图:2026-09-11 起插件端由 loveConfig.pageImages 迁至
|
||||||
|
// pageConfig.loveDiaryConfig.bgImageUrl,优先读新位置、兼容回退旧值
|
||||||
|
const loveDiaryPageConfig = appConfigs.pageConfig?.loveDiaryConfig as
|
||||||
|
{ bgImageUrl ?: string } | undefined
|
||||||
|
const pageImagesBg =
|
||||||
|
loveDiaryPageConfig?.bgImageUrl
|
||||||
|
|| loveModuleConfig?.pageImages?.bgImageUrl
|
||||||
|
|| loveConfig.value.pageImages.bgImageUrl
|
||||||
|
if (loveModuleConfig || loveDiaryPageConfig) {
|
||||||
loveConfig.value = {
|
loveConfig.value = {
|
||||||
...loveConfig.value,
|
...loveConfig.value,
|
||||||
pageImages: loveModuleConfig.pageImages || loveConfig.value.pageImages,
|
pageImages: {
|
||||||
ourStory: loveModuleConfig.ourStory || loveConfig.value.ourStory,
|
...loveConfig.value.pageImages,
|
||||||
lovePhoto: loveModuleConfig.lovePhoto || loveConfig.value.lovePhoto,
|
bgImageUrl: pageImagesBg,
|
||||||
loveDaily: loveModuleConfig.loveDaily || loveConfig.value.loveDaily,
|
},
|
||||||
navList: loveModuleConfig.navList || loveConfig.value.navList,
|
loveDiary: loveModuleConfig?.loveDiary || loveConfig.value.loveDiary,
|
||||||
|
ourStory: loveModuleConfig?.ourStory || loveConfig.value.ourStory,
|
||||||
|
lovePhoto: loveModuleConfig?.lovePhoto || loveConfig.value.lovePhoto,
|
||||||
|
loveDaily: loveModuleConfig?.loveDaily || loveConfig.value.loveDaily,
|
||||||
|
navList: loveModuleConfig?.navList || loveConfig.value.navList,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initList()
|
initList()
|
||||||
// 未配置纪念日(loveDate 为空)不启动倒计时,避免 NaN
|
|
||||||
if (loveConfig.value.loveDate) {
|
if (loveConfig.value.loveDate) {
|
||||||
handleInitLoveDayCount()
|
handleInitLoveDayCount()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 恋爱页入口:优先读插件端 loveConfig.navList(visible 过滤 + priority 排序,desc→subTitle,
|
|
||||||
* key 映射图标/路径,模块开关 enabled 与条目 visible 均 true 才展示);未配置/为空回退内置默认 */
|
|
||||||
function initList() {
|
function initList() {
|
||||||
const configs = loveConfig.value
|
const configs = loveConfig.value
|
||||||
const configured = configs.navList
|
const configured = configs.navList
|
||||||
@@ -151,7 +152,6 @@
|
|||||||
} else {
|
} else {
|
||||||
source = DEFAULT_NAV_LIST;
|
source = DEFAULT_NAV_LIST;
|
||||||
}
|
}
|
||||||
// priority 排序(越大越靠前;缺失按默认顺序兜底)
|
|
||||||
const sorted = [...source].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
const sorted = [...source].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
|
||||||
navList.value = sorted.map((item) => {
|
navList.value = sorted.map((item) => {
|
||||||
const meta = NAV_META[item.key]
|
const meta = NAV_META[item.key]
|
||||||
@@ -160,13 +160,14 @@
|
|||||||
}
|
}
|
||||||
const moduleKey = MODULE_KEY_MAP[item.key]
|
const moduleKey = MODULE_KEY_MAP[item.key]
|
||||||
const moduleCfg = moduleKey
|
const moduleCfg = moduleKey
|
||||||
? (configs[moduleKey] as { enabled ?: boolean } | undefined)
|
? (configs[moduleKey] as { enabled ?: boolean, passwordEnabled ?: boolean } | undefined)
|
||||||
: undefined
|
: undefined
|
||||||
const fallback = DEFAULT_NAV_LIST.find((d) => d.key === item.key)
|
const fallback = DEFAULT_NAV_LIST.find((d) => d.key === item.key)
|
||||||
return {
|
return {
|
||||||
key: item.key,
|
key: item.key,
|
||||||
// 模块开关与条目显示开关均开启才展示(与插件端语义一致)
|
|
||||||
use: !!moduleCfg?.enabled && item.visible !== false,
|
use: !!moduleCfg?.enabled && item.visible !== false,
|
||||||
|
// 模块设了密码且本地无有效 token → 显示 lock;解锁后恢复箭头
|
||||||
|
locked: !!moduleCfg?.passwordEnabled && !(moduleKey && getLoveModuleToken(moduleKey)),
|
||||||
iconPrefix: meta.iconPrefix,
|
iconPrefix: meta.iconPrefix,
|
||||||
icon: meta.icon,
|
icon: meta.icon,
|
||||||
title: item.title || fallback?.title || '',
|
title: item.title || fallback?.title || '',
|
||||||
@@ -201,7 +202,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- 跳转(模块密码拦截) ---------------- */
|
/* ---------------- 跳转(模块密码拦截) ---------------- */
|
||||||
/** 页面名 → 恋爱模块 scope 映射(stories→ourStory、album→lovePhoto、list→loveDaily) */
|
|
||||||
const MODULE_KEY_MAP: Record<string, LoveModuleKey> = {
|
const MODULE_KEY_MAP: Record<string, LoveModuleKey> = {
|
||||||
stories: 'ourStory',
|
stories: 'ourStory',
|
||||||
album: 'lovePhoto',
|
album: 'lovePhoto',
|
||||||
@@ -209,11 +209,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 模块密码弹窗状态 */
|
/** 模块密码弹窗状态 */
|
||||||
const passwordModalVisible = ref(false)
|
const unlockModalVisible = ref(false)
|
||||||
const pendingPage = ref('')
|
const pendingPage = ref('')
|
||||||
const pendingModule = ref<LoveModuleKey>('ourStory')
|
const pendingModule = ref<LoveModuleKey>('ourStory')
|
||||||
const modulePassword = ref('')
|
|
||||||
const unlocking = ref(false)
|
/** 恋爱日记入口(love 页本身)是否锁定:设了密码且本地无有效 token */
|
||||||
|
const loveDiaryLocked = computed(() =>
|
||||||
|
!!loveConfig.value.loveDiary?.passwordEnabled && !getLoveModuleToken('loveDiary'))
|
||||||
|
|
||||||
function handleToPage(pageName : string) {
|
function handleToPage(pageName : string) {
|
||||||
const module = MODULE_KEY_MAP[pageName]
|
const module = MODULE_KEY_MAP[pageName]
|
||||||
@@ -224,8 +226,7 @@
|
|||||||
if (moduleCfg?.passwordEnabled && !getLoveModuleToken(module)) {
|
if (moduleCfg?.passwordEnabled && !getLoveModuleToken(module)) {
|
||||||
pendingPage.value = pageName
|
pendingPage.value = pageName
|
||||||
pendingModule.value = module
|
pendingModule.value = module
|
||||||
modulePassword.value = ''
|
unlockModalVisible.value = true
|
||||||
passwordModalVisible.value = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
@@ -233,32 +234,28 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 密码确认:unlock 签发 token 后进入模块 */
|
/** 通用解锁弹窗请求:unlock 签发 token(插件端要求验证码,403 附新码由弹窗展示重试) */
|
||||||
async function handleConfirmPassword() {
|
async function handleUnlockRequest(password : string, captcha ?: ICaptchaQuery | null) {
|
||||||
if (!modulePassword.value.trim()) {
|
const res = await unlockLoveModule(pendingModule.value, password, captcha)
|
||||||
uni.showToast({ icon: 'none', title: '请输入密码' })
|
return res.data as { token ?: string, [key : string] : unknown } | null | undefined
|
||||||
return
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
unlocking.value = true
|
/** 解锁成功:存 token;恋爱日记入口(loveDiary)重新拉取恋爱信息,其余进入模块 */
|
||||||
const res = await unlockLoveModule(pendingModule.value, modulePassword.value)
|
function handleUnlockSuccess(data : { token ?: string }) {
|
||||||
const token = res.data?.token
|
if (data.token) {
|
||||||
if (token) {
|
setLoveModuleToken(pendingModule.value, data.token)
|
||||||
setLoveModuleToken(pendingModule.value, token)
|
if (pendingModule.value === 'loveDiary') {
|
||||||
passwordModalVisible.value = false
|
// 恋爱日记入口解锁:重新拉取 /love-config 并刷新页面状态
|
||||||
|
appConfigStore.fetchLoveConfig().then(() => syncLoveConfigFromStore())
|
||||||
|
}
|
||||||
|
else {
|
||||||
uni.navigateTo({ url: `/pages-blog/love/${pendingPage.value}` })
|
uni.navigateTo({ url: `/pages-blog/love/${pendingPage.value}` })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
uni.showToast({ icon: 'none', title: '解锁失败,请重试' })
|
uni.showToast({ icon: 'none', title: '解锁失败,请重试' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
|
||||||
uni.showToast({ icon: 'none', title: '密码不正确' })
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
unlocking.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------- 生命周期 ---------------- */
|
/* ---------------- 生命周期 ---------------- */
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
@@ -268,6 +265,12 @@
|
|||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
await appConfigStore.bootstrap()
|
await appConfigStore.bootstrap()
|
||||||
syncLoveConfigFromStore()
|
syncLoveConfigFromStore()
|
||||||
|
// 恋爱日记入口(love 页本身)设了密码且本地无 token → 先弹密码框验证
|
||||||
|
if (loveDiaryLocked.value) {
|
||||||
|
pendingPage.value = ''
|
||||||
|
pendingModule.value = 'loveDiary'
|
||||||
|
unlockModalVisible.value = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
@@ -278,12 +281,12 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="bg-pink-100 min-h-screen w-screen">
|
<view class="bg-pink-50 min-h-screen w-screen">
|
||||||
<uh-navbar default-title="恋爱日记" :need-placeholder="false" back-class="text-love"
|
<uh-navbar default-title="恋爱日记" :need-placeholder="false" back-class="text-love"
|
||||||
title-color="!text-love"></uh-navbar>
|
title-color="!text-love"></uh-navbar>
|
||||||
|
|
||||||
<!-- 情侣信息 -->
|
<!-- 情侣信息 -->
|
||||||
<view class="relative z-10 h-92 w-screen flex flex-col items-center justify-center">
|
<view class="box-border pt-12 relative z-10 h-92 w-screen flex flex-col items-center justify-center">
|
||||||
<view class="relative z-10 w-full h-full flex items-center justify-center rounded-xl">
|
<view class="relative z-10 w-full h-full flex items-center justify-center rounded-xl">
|
||||||
<view class="boy flex flex-col items-center justify-center translate-x-0.5">
|
<view class="boy flex flex-col items-center justify-center translate-x-0.5">
|
||||||
<image class="uh-global-card-glass border-3 box-border border-blue-400 h-26 w-26 rounded-full"
|
<image class="uh-global-card-glass border-3 box-border border-blue-400 h-26 w-26 rounded-full"
|
||||||
@@ -304,7 +307,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<image :src="checkImageUrl(loveConfig.pageImages.bgImageUrl)" class="absolute z-0 inset-0 w-full h-full"
|
<image :src="checkImageUrl(loveConfig.pageImages.bgImageUrl)" class="absolute z-0 inset-0 w-full h-full"
|
||||||
mode="aspectFill" />
|
mode="aspectFill" />
|
||||||
<view class="absolute z-2 left-0 bottom-0 w-full h-12 bg-gradient-to-b from-white/0 to-pink-100" />
|
<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" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 恋爱记时 -->
|
<!-- 恋爱记时 -->
|
||||||
@@ -351,7 +354,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="shrink-0">
|
<view class="shrink-0">
|
||||||
<wd-icon name="arrow-right" :class="[index%2===0?'text-love':'text-blue-400']"
|
<wd-icon :name="nav.locked ? 'lock' : 'arrow-right'" :class="[index%2===0?'text-love':'text-blue-400']"
|
||||||
size="32rpx"></wd-icon>
|
size="32rpx"></wd-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -359,27 +362,10 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 模块密码验证弹窗 -->
|
<!-- 模块密码验证弹窗(通用解锁弹窗;恋爱日记入口与模块共用;插件端要求验证码,403 附新码) -->
|
||||||
<view v-if="passwordModalVisible" class="fixed inset-0 z-50 flex items-center justify-center bg-black/40"
|
<uh-unlock-popup v-model:show="unlockModalVisible" title="请输入访问密码" captcha-enabled
|
||||||
@click="passwordModalVisible = false">
|
:tip="`${pendingModule === 'loveDiary' ? '恋爱日记' : pendingModule === 'ourStory' ? '恋爱故事' : pendingModule === 'lovePhoto' ? '恋爱相册' : '恋爱清单'}已设置访问密码,输入后进入`"
|
||||||
<view class="box-border w-4/5 rounded-2xl bg-white p-6" @click.stop>
|
placeholder="请输入密码" confirm-text="进入" :request="handleUnlockRequest" @success="handleUnlockSuccess" />
|
||||||
<view class="text-center text-lg font-bold text-love">请输入访问密码</view>
|
|
||||||
<view class="mt-2 text-center text-xs text-gray-500">
|
|
||||||
{{ pendingModule === 'ourStory' ? '恋爱故事' : pendingModule === 'lovePhoto' ? '恋爱相册' : '恋爱清单' }}已设置访问密码,输入后进入
|
|
||||||
</view>
|
|
||||||
<input v-model="modulePassword" password
|
|
||||||
class="mt-4 h-11 w-full rounded-xl border border-gray-200 bg-gray-50 px-4 text-sm outline-none"
|
|
||||||
placeholder="请输入密码" />
|
|
||||||
<view class="mt-5 flex items-center gap-3">
|
|
||||||
<view class="flex-1 rounded-xl bg-gray-100 py-2.5 text-center text-sm text-gray-600"
|
|
||||||
@click="passwordModalVisible = false">取消</view>
|
|
||||||
<view class="flex-1 rounded-xl bg-love py-2.5 text-center text-sm text-white"
|
|
||||||
:class="unlocking ? 'opacity-60' : ''" @click="handleConfirmPassword">
|
|
||||||
{{ unlocking ? '验证中…' : '进入' }}
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
|
import { onLoad, 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 { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import { checkImageUrl } from '@/utils/url'
|
import { checkImageUrl } from '@/utils/url'
|
||||||
|
import { sleep } from '@/utils/common'
|
||||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||||
import type { ILoveStory } from '@/api/types/uni-halo'
|
import type { ILoveStory } from '@/api/types/uni-halo'
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@
|
|||||||
images : string[]
|
images : string[]
|
||||||
/** 时间轴封面图(最多 3 张,已预处理 URL) */
|
/** 时间轴封面图(最多 3 张,已预处理 URL) */
|
||||||
coverImages : string[]
|
coverImages : string[]
|
||||||
|
/** 排序优先级(仅脚本跨页排序用,模板不展示) */
|
||||||
|
priority : number
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 空故事占位(弹窗未打开时) */
|
/** 空故事占位(弹窗未打开时) */
|
||||||
@@ -56,6 +59,7 @@
|
|||||||
content: '',
|
content: '',
|
||||||
images: [],
|
images: [],
|
||||||
coverImages: [],
|
coverImages: [],
|
||||||
|
priority: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 中文星期(dayjs day():0=周日) */
|
/** 中文星期(dayjs day():0=周日) */
|
||||||
@@ -88,11 +92,18 @@
|
|||||||
content: spec.content || '',
|
content: spec.content || '',
|
||||||
images,
|
images,
|
||||||
coverImages: images.slice(0, 3),
|
coverImages: images.slice(0, 3),
|
||||||
|
priority: spec.priority || 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 故事列表排序(priority 越大越靠前;跨页 concat 后整体重排) */
|
||||||
|
function sortStories(list : IStoryCard[]) : IStoryCard[] {
|
||||||
|
return [...list].sort((a, b) => (b.priority || 0) - (a.priority || 0))
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------------- 状态 ---------------- */
|
/* ---------------- 状态 ---------------- */
|
||||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
|
||||||
|
const queryParams = ref({ page: 1, size: 10 })
|
||||||
const stories = ref<IStoryCard[]>([])
|
const stories = ref<IStoryCard[]>([])
|
||||||
const showDetail = ref(false)
|
const showDetail = ref(false)
|
||||||
const currentStory = ref<IStoryCard>(EMPTY_STORY)
|
const currentStory = ref<IStoryCard>(EMPTY_STORY)
|
||||||
@@ -100,15 +111,31 @@
|
|||||||
|
|
||||||
/* ---------------- 数据加载 ---------------- */
|
/* ---------------- 数据加载 ---------------- */
|
||||||
async function handleGetStories() {
|
async function handleGetStories() {
|
||||||
|
if (!loadMoreStatus.value.active) {
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
updateLoadingStatus(DataLoadingStatusEnum.Loading)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const res = await getLoveStories({})
|
const res = await getLoveStories({ ...queryParams.value })
|
||||||
const items = res.data?.items || []
|
const items = res.data?.items || []
|
||||||
if (items.length > 0) {
|
if (loadMoreStatus.value.active) {
|
||||||
// 按 priority 排序(越大越靠前)
|
// 分页加载:追加并按 priority 整体重排(跨页保持全局有序)
|
||||||
const sorted = [...items].sort((a, b) => (b.spec?.priority || 0) - (a.spec?.priority || 0))
|
stories.value = sortStories([...stories.value, ...items.map(mapStoryCard)])
|
||||||
stories.value = sorted.map(mapStoryCard)
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data?.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: !!res.data?.hasNext,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (items.length > 0) {
|
||||||
|
// 首屏:按 priority 排序(越大越靠前)
|
||||||
|
stories.value = sortStories(items.map(mapStoryCard))
|
||||||
|
await sleep(600)
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Success)
|
updateLoadingStatus(DataLoadingStatusEnum.Success)
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: res.data?.hasNext ? 'loadMore' : 'noMore',
|
||||||
|
hasNext: !!res.data?.hasNext,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 降级:从旧配置读取单条故事
|
// 降级:从旧配置读取单条故事
|
||||||
@@ -121,11 +148,18 @@
|
|||||||
if (!handleLoveModuleLocked('ourStory', e)) {
|
if (!handleLoveModuleLocked('ourStory', e)) {
|
||||||
handleLoadFromLegacy()
|
handleLoadFromLegacy()
|
||||||
}
|
}
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: false,
|
||||||
|
status: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
setTimeout(() => {
|
|
||||||
uni.stopPullDownRefresh()
|
uni.stopPullDownRefresh()
|
||||||
}, 200)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +178,7 @@
|
|||||||
content: loveModuleConfig.ourStory.content,
|
content: loveModuleConfig.ourStory.content,
|
||||||
images: [],
|
images: [],
|
||||||
coverImages: [],
|
coverImages: [],
|
||||||
|
priority: 0,
|
||||||
}]
|
}]
|
||||||
updateLoadingStatus(DataLoadingStatusEnum.Success)
|
updateLoadingStatus(DataLoadingStatusEnum.Success)
|
||||||
return
|
return
|
||||||
@@ -194,8 +229,26 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
onPullDownRefresh(() => {
|
onPullDownRefresh(() => {
|
||||||
|
resetLoadMoreStatus()
|
||||||
|
queryParams.value.page = 1
|
||||||
handleGetStories()
|
handleGetStories()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
// 正在加载时阻止重复请求
|
||||||
|
if (loadMoreStatus.value.active) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 有更多数据时继续加载
|
||||||
|
if (loadMoreStatus.value.hasNext) {
|
||||||
|
queryParams.value.page += 1
|
||||||
|
updateLoadMoreStatus({
|
||||||
|
active: true,
|
||||||
|
status: 'loading',
|
||||||
|
})
|
||||||
|
handleGetStories()
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -252,6 +305,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 故事详情弹窗 -->
|
<!-- 故事详情弹窗 -->
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { getAppConfigs, getAuditData, getLoveConfig } from '@/api/uni-halo'
|
|||||||
import { DefaultAppConfigs } from '@/config/appConfig'
|
import { DefaultAppConfigs } from '@/config/appConfig'
|
||||||
import { deepMerge } from '@/utils/merge'
|
import { deepMerge } from '@/utils/merge'
|
||||||
import { setCache } from '@/utils/storage'
|
import { setCache } from '@/utils/storage'
|
||||||
|
import { clearLoveModuleToken } from '@/utils/loveModuleToken'
|
||||||
import type { IAppConfig, IAuditDataResult } from '@/api/types/uni-halo'
|
import type { IAppConfig, IAuditDataResult } from '@/api/types/uni-halo'
|
||||||
|
|
||||||
/** 合并后配置缓存 key(与 utils/url.ts / api/uni-halo.ts 的 APP_GLOBAL_CONFIGS 读取保持一致) */
|
/** 合并后配置缓存 key(与 utils/url.ts / api/uni-halo.ts 的 APP_GLOBAL_CONFIGS 读取保持一致) */
|
||||||
@@ -87,7 +88,9 @@ export const useAppConfigStore = defineStore(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取恋爱配置内容(公开 /love-config) */
|
/** 获取恋爱配置内容(公开 /love-config;恋爱日记入口 loveDiary 设密码时
|
||||||
|
* 需携带模块解锁 token;401 locked 表示 token 缺失/失效,清除本地 token
|
||||||
|
* 交由 love.vue 重新弹密码框解锁) */
|
||||||
const fetchLoveConfig = async () => {
|
const fetchLoveConfig = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getLoveConfig()
|
const res = await getLoveConfig()
|
||||||
@@ -99,6 +102,11 @@ export const useAppConfigStore = defineStore(
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error('获取恋爱配置失败', err)
|
console.error('获取恋爱配置失败', err)
|
||||||
|
// 401 locked:恋爱日记锁定且本地 token 失效/缺失,清除后由 love.vue 引导解锁
|
||||||
|
const status = (err as { cause?: { response?: { status?: number } } })?.cause?.response?.status
|
||||||
|
if (status === 401) {
|
||||||
|
clearLoveModuleToken('loveDiary')
|
||||||
|
}
|
||||||
loveConfig.value = { enabled: false }
|
loveConfig.value = { enabled: false }
|
||||||
return loveConfig.value
|
return loveConfig.value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* 恋爱模块入口解锁 token 管理(插件端 POST /love-modules/unlock 签发,HMAC 30 分钟有效)
|
* 恋爱模块入口解锁 token 管理(插件端 POST /love-modules/unlock 签发,HMAC 30 分钟有效)
|
||||||
* 模块 scope:ourStory(恋爱故事) / lovePhoto(恋爱相册) / loveDaily(恋爱清单)
|
* 模块 scope:loveDiary(恋爱日记入口/恋爱页本身) / ourStory(恋爱故事) /
|
||||||
|
* lovePhoto(恋爱相册) / loveDaily(恋爱清单)
|
||||||
*/
|
*/
|
||||||
import { delCache, getCache, setCache } from '@/utils/storage'
|
import { delCache, getCache, setCache } from '@/utils/storage'
|
||||||
|
|
||||||
/** 恋爱模块解锁 token 存储键(module → token) */
|
/** 恋爱模块解锁 token 存储键(module → token) */
|
||||||
const LOVE_MODULE_TOKEN_KEY = 'uh_love_module_token_v1'
|
const LOVE_MODULE_TOKEN_KEY = 'uh_love_module_token_v1'
|
||||||
|
/** 解锁 token 有效期(与后端约定一致:HMAC 30 分钟,过期由 getCache 自动清除,服务端 401 兜底) */
|
||||||
|
const LOVE_MODULE_TOKEN_TTL_SECONDS = 30 * 60
|
||||||
|
|
||||||
export type LoveModuleKey = 'ourStory' | 'lovePhoto' | 'loveDaily'
|
export type LoveModuleKey = 'loveDiary' | 'ourStory' | 'lovePhoto' | 'loveDaily'
|
||||||
|
|
||||||
/** 读取指定模块的解锁 token(未解锁则 undefined) */
|
/** 读取指定模块的解锁 token(未解锁或已过期则 undefined) */
|
||||||
export function getLoveModuleToken(module: LoveModuleKey): string | undefined {
|
export function getLoveModuleToken(module: LoveModuleKey): string | undefined {
|
||||||
const cache = getCache<Record<string, string>>(LOVE_MODULE_TOKEN_KEY)
|
const cache = getCache<Record<string, string>>(LOVE_MODULE_TOKEN_KEY)
|
||||||
return cache?.[module]
|
return cache?.[module]
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 保存指定模块的解锁 token(插件端 30 分钟有效,过期由服务端 401 兜底重新解锁) */
|
/** 保存指定模块的解锁 token(30 分钟失效存储;过期由 getCache 自动清除,服务端 401 兜底重新解锁) */
|
||||||
export function setLoveModuleToken(module: LoveModuleKey, token: string): void {
|
export function setLoveModuleToken(module: LoveModuleKey, token: string): void {
|
||||||
const cache = getCache<Record<string, string>>(LOVE_MODULE_TOKEN_KEY) || {}
|
const cache = getCache<Record<string, string>>(LOVE_MODULE_TOKEN_KEY) || {}
|
||||||
cache[module] = token
|
cache[module] = token
|
||||||
setCache(LOVE_MODULE_TOKEN_KEY, cache)
|
setCache(LOVE_MODULE_TOKEN_KEY, cache, LOVE_MODULE_TOKEN_TTL_SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 清除指定模块的解锁 token(401 locked 时调用,回到未解锁状态) */
|
/** 清除指定模块的解锁 token(401 locked 时调用,回到未解锁状态) */
|
||||||
|
|||||||
Reference in New Issue
Block a user