mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor: 重构偏好设置与恋爱模块,对齐插件端字段结构
1. 重构布局偏好字段映射,移除嵌套layout结构,直接使用插件端同名字段 2. 新增恋爱模块token管理与密码解锁功能,支持恋爱故事/相册/清单的密码保护 3. 重构首页快捷导航,支持插件端直接配置导航项 4. 清理废弃配置字段,统一站点默认值与插件端结构 5. 修复文章卡片布局读取逻辑,适配新的偏好字段结构
This commit is contained in:
@@ -23,7 +23,7 @@ const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
|
||||
const settingStore = useSettingStore()
|
||||
|
||||
/** 归档页列表布局(偏好设置驱动:single=单列 / double=双列) */
|
||||
const archivesListLayout = computed(() => settingStore.settings.layout.archives.listLayout)
|
||||
const archivesListLayout = computed(() => settingStore.settings.archivesListLayout)
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
||||
|
||||
@@ -24,7 +24,7 @@ const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
|
||||
const settingStore = useSettingStore()
|
||||
|
||||
/** 文章列表页列表布局(偏好设置驱动:single=单列 / double=双列) */
|
||||
const articlesListLayout = computed(() => settingStore.settings.layout.articles.listLayout)
|
||||
const articlesListLayout = computed(() => settingStore.settings.articlesListLayout)
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getLoveAlbumByName, getLoveAlbums } from '@/api/uni-halo'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { checkImageUrl } from '@/utils/url'
|
||||
import { getCache, setCache } from '@/utils/storage'
|
||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||
import type { ILoveAlbum, ILovePhoto } from '@/api/types/uni-halo'
|
||||
|
||||
@@ -111,6 +112,8 @@ async function handleGetData() {
|
||||
}
|
||||
catch (e) {
|
||||
console.error('获取相册失败', e)
|
||||
// 模块锁 401:清除 token 并提示
|
||||
handleLoveModuleLocked('lovePhoto', e)
|
||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||
}
|
||||
finally {
|
||||
@@ -138,6 +141,7 @@ async function handleLoadUnlockedAlbumPhotos() {
|
||||
}
|
||||
catch (e) {
|
||||
console.error('加载相册照片失败', e)
|
||||
handleLoveModuleLocked('lovePhoto', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
|
||||
import { getLoveDailyItems } from '@/api/uni-halo'
|
||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||
import { checkImageUrl } from '@/utils/url'
|
||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||
import type { ILoveDailyItem } from '@/api/types/uni-halo'
|
||||
@@ -172,6 +173,8 @@
|
||||
}
|
||||
catch (e) {
|
||||
console.error('获取清单失败', e)
|
||||
// 模块锁 401:清除 token 并提示
|
||||
handleLoveModuleLocked('loveDaily', e)
|
||||
updateLoadingStatus(DataLoadingStatusEnum.Error)
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { checkAvatarUrl, checkImageUrl } from '@/utils/url'
|
||||
import { unlockLoveModule } from '@/api/uni-halo'
|
||||
import { getLoveModuleToken, setLoveModuleToken, type LoveModuleKey } from '@/utils/loveModuleToken'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
@@ -29,9 +31,9 @@
|
||||
waveImageUrl : string
|
||||
heartImageUrl : string
|
||||
}
|
||||
ourStory : { enabled : boolean, iconUrl : string }
|
||||
lovePhoto : { enabled : boolean, iconUrl : string }
|
||||
loveDaily : { enabled : boolean, iconUrl : string }
|
||||
ourStory : { enabled : boolean, passwordEnabled ?: boolean }
|
||||
lovePhoto : { enabled : boolean, passwordEnabled ?: boolean }
|
||||
loveDaily : { enabled : boolean, passwordEnabled ?: boolean }
|
||||
[key : string] : unknown
|
||||
}
|
||||
|
||||
@@ -50,9 +52,9 @@
|
||||
waveImageUrl: '',
|
||||
heartImageUrl: '',
|
||||
},
|
||||
ourStory: { enabled: false, iconUrl: '' },
|
||||
lovePhoto: { enabled: false, iconUrl: '' },
|
||||
loveDaily: { enabled: false, iconUrl: '' },
|
||||
ourStory: { enabled: false, passwordEnabled: false },
|
||||
lovePhoto: { enabled: false, passwordEnabled: false },
|
||||
loveDaily: { enabled: false, passwordEnabled: false },
|
||||
})
|
||||
|
||||
const loveDayCount = ref({ d: 0, h: 0, m: 0, s: 0 })
|
||||
@@ -151,13 +153,66 @@
|
||||
countDownFn()
|
||||
}
|
||||
|
||||
/* ---------------- 跳转 ---------------- */
|
||||
/* ---------------- 跳转(模块密码拦截) ---------------- */
|
||||
/** 页面名 → 恋爱模块 scope 映射(stories→ourStory、album→lovePhoto、list→loveDaily) */
|
||||
const MODULE_KEY_MAP: Record<string, LoveModuleKey> = {
|
||||
stories: 'ourStory',
|
||||
album: 'lovePhoto',
|
||||
list: 'loveDaily',
|
||||
}
|
||||
|
||||
/** 模块密码弹窗状态 */
|
||||
const passwordModalVisible = ref(false)
|
||||
const pendingPage = ref('')
|
||||
const pendingModule = ref<LoveModuleKey>('ourStory')
|
||||
const modulePassword = ref('')
|
||||
const unlocking = ref(false)
|
||||
|
||||
function handleToPage(pageName : string) {
|
||||
const module = MODULE_KEY_MAP[pageName]
|
||||
const moduleCfg = module
|
||||
? (loveConfig.value[module] as { enabled ?: boolean, passwordEnabled ?: boolean })
|
||||
: undefined
|
||||
// 模块设了密码且本地无有效 token → 先弹密码框验证
|
||||
if (moduleCfg?.passwordEnabled && !getLoveModuleToken(module)) {
|
||||
pendingPage.value = pageName
|
||||
pendingModule.value = module
|
||||
modulePassword.value = ''
|
||||
passwordModalVisible.value = true
|
||||
return
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/love/${pageName}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 密码确认:unlock 签发 token 后进入模块 */
|
||||
async function handleConfirmPassword() {
|
||||
if (!modulePassword.value.trim()) {
|
||||
uni.showToast({ icon: 'none', title: '请输入密码' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
unlocking.value = true
|
||||
const res = await unlockLoveModule(pendingModule.value, modulePassword.value)
|
||||
const token = res.data?.token
|
||||
if (token) {
|
||||
setLoveModuleToken(pendingModule.value, token)
|
||||
passwordModalVisible.value = false
|
||||
uni.navigateTo({ url: `/pages-blog/love/${pendingPage.value}` })
|
||||
}
|
||||
else {
|
||||
uni.showToast({ icon: 'none', title: '解锁失败,请重试' })
|
||||
}
|
||||
}
|
||||
catch {
|
||||
uni.showToast({ icon: 'none', title: '密码不正确' })
|
||||
}
|
||||
finally {
|
||||
unlocking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------- 生命周期 ---------------- */
|
||||
onLoad(() => {
|
||||
syncLoveConfigFromStore()
|
||||
@@ -256,6 +311,28 @@
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 模块密码验证弹窗 -->
|
||||
<view v-if="passwordModalVisible" class="fixed inset-0 z-50 flex items-center justify-center bg-black/40"
|
||||
@click="passwordModalVisible = false">
|
||||
<view class="box-border w-4/5 rounded-2xl bg-white p-6" @click.stop>
|
||||
<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>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
|
||||
import dayjs from 'dayjs'
|
||||
import { getLoveStories } from '@/api/uni-halo'
|
||||
import { handleLoveModuleLocked } from '@/utils/loveModuleToken'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { checkImageUrl } from '@/utils/url'
|
||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||
@@ -116,7 +117,10 @@
|
||||
}
|
||||
catch (e) {
|
||||
console.error('获取故事失败', e)
|
||||
handleLoadFromLegacy()
|
||||
// 模块锁 401:清除 token 并提示;命中 locked 时不做旧配置降级(需回入口重新解锁)
|
||||
if (!handleLoveModuleLocked('ourStory', e)) {
|
||||
handleLoadFromLegacy()
|
||||
}
|
||||
}
|
||||
finally {
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -168,37 +168,37 @@
|
||||
</uh-section-title>
|
||||
<view class="setting-sheet uh-global-card-glass overflow-hidden rounded-2xl">
|
||||
<template v-for="(row, index) in featureRows" :key="row.key">
|
||||
<!-- 布尔项:内联分段器(默认 / 开 / 关) -->
|
||||
<view v-if="row.kind === 'bool'" class="box-border p-3"
|
||||
:class="index < featureRows.length - 1 ? 'border-b border-black/5' : ''">
|
||||
<view class="flex items-center justify-between">
|
||||
<text class="row-label text-[28rpx] text-gray-900 font-bold">{{ row.label }}</text>
|
||||
<view class="flex items-center gap-2">
|
||||
<text v-if="row.following" class="row-sub text-2xs text-gray-400">默认</text>
|
||||
<view v-else
|
||||
class="rounded-full bg-secondary px-2 py-1 text-xs text-gray-900 leading-none">
|
||||
已自定义
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mt-3 flex flex-wrap gap-2">
|
||||
<view class="rounded-full px-3 py-1 text-xs uh-global-card-glass shadow-none border"
|
||||
:class="row.following ? 'bg-secondary font-bold' : 'text-gray-500'"
|
||||
@click="handleRevert(row.path)">
|
||||
默认
|
||||
</view>
|
||||
<view class="rounded-full px-3 py-1 text-xs uh-global-card-glass shadow-none border"
|
||||
:class="!row.following && row.boolValue ? 'bg-secondary font-bold' : 'text-gray-500'"
|
||||
@click="handleBoolChange(row.path, true)">
|
||||
开
|
||||
</view>
|
||||
<view class="rounded-full px-3 py-1 text-xs uh-global-card-glass shadow-none border"
|
||||
:class="!row.following && !row.boolValue ? 'bg-secondary font-bold' : 'text-gray-500'"
|
||||
@click="handleBoolChange(row.path, false)">
|
||||
关
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 布尔项:内联分段器(默认 / 开 / 关) -->
|
||||
<view v-if="row.kind === 'bool'" class="box-border p-3"
|
||||
:class="index < featureRows.length - 1 ? 'border-b border-black/5' : ''">
|
||||
<view class="flex items-center justify-between">
|
||||
<text class="row-label text-[28rpx] text-gray-900 font-bold">{{ row.label }}</text>
|
||||
<view class="flex items-center gap-2">
|
||||
<text v-if="row.following" class="row-sub text-2xs text-gray-400">默认</text>
|
||||
<view v-else
|
||||
class="rounded-full bg-secondary px-2 py-1 text-xs text-gray-900 leading-none">
|
||||
已自定义
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mt-3 flex flex-wrap gap-2">
|
||||
<view class="rounded-full px-3 py-1 text-xs uh-global-card-glass shadow-none border"
|
||||
:class="row.following ? 'bg-secondary font-bold' : 'text-gray-500'"
|
||||
@click="handleRevert(row.path)">
|
||||
默认
|
||||
</view>
|
||||
<view class="rounded-full px-3 py-1 text-xs uh-global-card-glass shadow-none border"
|
||||
:class="!row.following && row.boolValue ? 'bg-secondary font-bold' : 'text-gray-500'"
|
||||
@click="handleBoolChange(row.path, true)">
|
||||
开
|
||||
</view>
|
||||
<view class="rounded-full px-3 py-1 text-xs uh-global-card-glass shadow-none border"
|
||||
:class="!row.following && !row.boolValue ? 'bg-secondary font-bold' : 'text-gray-500'"
|
||||
@click="handleBoolChange(row.path, false)">
|
||||
关
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 枚举选择 -->
|
||||
<view v-else class="pick-row flex items-center justify-between px-4 py-4"
|
||||
:class="index < featureRows.length - 1 ? 'border-b border-black/5' : ''"
|
||||
@@ -245,7 +245,8 @@
|
||||
</view>
|
||||
<!-- 选择器 -->
|
||||
<wd-picker-view :columns="enumColumns" v-model="pickerValue"
|
||||
custom-class="!p-0 !bg-transparent !rounded-xl overflow-hidden" @change="handlePickerChange" />
|
||||
custom-class="uh-picker-view !p-0 !bg-transparent !rounded-xl overflow-hidden"
|
||||
@change="handlePickerChange" />
|
||||
<!-- 底部操作:取消 / 确认 -->
|
||||
<view class="mt-4 flex items-center justify-center gap-x-3">
|
||||
<uh-button custom-class="flex-1 py-2 uh-global-card-glass border !rounded-xl bg-white/90"
|
||||
@@ -261,4 +262,15 @@
|
||||
</view>
|
||||
</uh-glass-popup>
|
||||
</view>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
:deep(.uh-picker-view) {
|
||||
.wd-picker-view__mask {
|
||||
background: transparent !important;
|
||||
}
|
||||
.wd-picker-view__roller{
|
||||
border-radius: 16rpx !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user