mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor(love-module): 重构恋爱模块页面与组件
1. 统一主题色小写格式,新增恋爱页面渐变背景类 2. 替换旧版相册解锁弹窗为新版弹窗组件 3. 重构相册查看器样式与布局,适配新的玻璃态弹窗 4. 优化恋爱相册与故事页面的UI布局、样式与交互 5. 新增回顶按钮的样式适配,统一使用love主题色
This commit is contained in:
@@ -1,156 +1,159 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 相册图片查看弹窗(源自旧项目 components/album-photo-viewer,新建复刻)
|
||||
* 双列瀑布流展示相册照片,支持大图预览
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { checkImageUrl } from '@/utils/url'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { checkImageUrl } from '@/utils/url'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
show: boolean
|
||||
albumName?: string
|
||||
photos?: IAlbumPhoto[]
|
||||
loading?: boolean
|
||||
}>(), {
|
||||
albumName: '',
|
||||
photos: () => [],
|
||||
loading: false,
|
||||
})
|
||||
const props = withDefaults(defineProps<{
|
||||
show : boolean
|
||||
albumName ?: string
|
||||
photos ?: IAlbumPhoto[]
|
||||
loading ?: boolean
|
||||
}>(), {
|
||||
albumName: '',
|
||||
photos: () => [],
|
||||
loading: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:show', show: boolean): void
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
(e : 'update:show', show : boolean) : void
|
||||
}>()
|
||||
|
||||
export interface IAlbumPhoto {
|
||||
name?: string
|
||||
url?: string
|
||||
title?: string
|
||||
takenDate?: string
|
||||
location?: string
|
||||
description?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
export interface IAlbumPhoto {
|
||||
name ?: string
|
||||
url ?: string
|
||||
title ?: string
|
||||
takenDate ?: string
|
||||
location ?: string
|
||||
description ?: string
|
||||
[key : string] : unknown
|
||||
}
|
||||
|
||||
const isShow = ref(false)
|
||||
const isShow = ref(false)
|
||||
|
||||
watch(() => props.show, (val) => {
|
||||
isShow.value = val
|
||||
})
|
||||
watch(() => props.show, (val) => {
|
||||
isShow.value = val
|
||||
})
|
||||
|
||||
/** 预处理图片路径(相对路径拼接 BASE_API) */
|
||||
const photoList = computed<IAlbumPhoto[]>(() =>
|
||||
(props.photos || []).map(photo => ({
|
||||
...photo,
|
||||
url: checkImageUrl(photo.url || ''),
|
||||
})),
|
||||
)
|
||||
/** 预处理图片路径(相对路径拼接 BASE_API) */
|
||||
const photoList = computed<IAlbumPhoto[]>(() =>
|
||||
(props.photos || []).map(photo => ({
|
||||
...photo,
|
||||
url: checkImageUrl(photo.url || ''),
|
||||
})),
|
||||
)
|
||||
|
||||
/** 左列(偶数位照片,瀑布流错落) */
|
||||
const leftPhotos = computed(() => photoList.value.filter((_, index) => index % 2 === 0))
|
||||
/** 左列(偶数位照片,瀑布流错落) */
|
||||
const leftPhotos = computed(() => photoList.value.filter((_, index) => index % 2 === 0))
|
||||
|
||||
/** 右列(奇数位照片) */
|
||||
const rightPhotos = computed(() => photoList.value.filter((_, index) => index % 2 === 1))
|
||||
/** 右列(奇数位照片) */
|
||||
const rightPhotos = computed(() => photoList.value.filter((_, index) => index % 2 === 1))
|
||||
|
||||
function handleClose() {
|
||||
isShow.value = false
|
||||
emit('update:show', false)
|
||||
}
|
||||
function handleClose() {
|
||||
isShow.value = false
|
||||
emit('update:show', false)
|
||||
}
|
||||
|
||||
/** 预览大图 */
|
||||
function handlePreview(url?: string) {
|
||||
const urls = photoList.value.map(photo => photo.url || '')
|
||||
if (urls.length === 0) {
|
||||
uni.showToast({ title: '相册暂无照片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.previewImage({
|
||||
current: url || urls[0],
|
||||
urls,
|
||||
})
|
||||
}
|
||||
/** 预览大图 */
|
||||
function handlePreview(url ?: string) {
|
||||
const urls = photoList.value.map(photo => photo.url || '')
|
||||
if (urls.length === 0) {
|
||||
uni.showToast({ title: '相册暂无照片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.previewImage({
|
||||
current: url || urls[0],
|
||||
urls,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<wd-popup v-model="isShow" position="center" custom-style="width:94vw;height:82vh;border-radius:12rpx;" @close="handleClose">
|
||||
<view class="album-photo-viewer h-full w-full flex flex-col overflow-hidden rounded-xl bg-white">
|
||||
<!-- 头部 -->
|
||||
<view class="viewer-header box-border flex shrink-0 items-center justify-between border-b border-black/5 px-7 py-6">
|
||||
<text class="viewer-title flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-[32rpx] text-[#333] font-bold">{{ albumName }}</text>
|
||||
<view class="viewer-close h-14 w-14 flex shrink-0 items-center justify-center rounded-full bg-black/5" @click="handleClose">
|
||||
<wd-icon name="close" size="16px" color="#666" />
|
||||
</view>
|
||||
</view>
|
||||
<uh-glass-popup v-model="isShow" position="bottom" :z-index="100" custom-class="!border rounded-2xl"
|
||||
safe-area-inset-bottom @close="handleClose">
|
||||
<view class="box-border h-full w-full flex flex-col gap-y-3 p-4">
|
||||
<!-- 头部 -->
|
||||
<view class="w-full shrink-0 flex items-center justify-between">
|
||||
<view class="font-bold flex items-center gap-x-1">
|
||||
{{ albumName }}
|
||||
</view>
|
||||
<view
|
||||
class="w-6 h-6 uh-global-card-glass border uh-shadow-xs flex items-center justify-center rounded-lg"
|
||||
@click="handleClose">
|
||||
<wd-icon name="close" size="32rpx"></wd-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 照片列表 -->
|
||||
<scroll-view class="viewer-body box-border min-h-0 flex-1" scroll-y :show-scrollbar="false">
|
||||
<view v-if="loading" class="viewer-empty box-border h-full flex items-center justify-center p-10">
|
||||
<view class="viewer-loading flex flex-col items-center">
|
||||
<view class="loading-text mt-7 text-[28rpx] text-[#56bbf9]">
|
||||
照片正在努力加载中啦~
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else-if="photoList.length === 0" class="viewer-empty box-border h-full flex items-center justify-center p-10">
|
||||
<wd-empty description="这个相册暂时还没有照片~" />
|
||||
</view>
|
||||
<view v-else class="photo-list box-border flex items-start p-5">
|
||||
<!-- 左列 -->
|
||||
<view class="photo-column box-border min-w-0 flex-1 mr-[20rpx]">
|
||||
<view v-for="photo in leftPhotos" :key="photo.name" class="photo-card mb-6 box-border overflow-hidden rounded-xl bg-white shadow-sm">
|
||||
<image
|
||||
class="photo-image w-full"
|
||||
:src="photo.url"
|
||||
mode="widthFix"
|
||||
lazy-load
|
||||
@click="handlePreview(photo.url)"
|
||||
/>
|
||||
<view class="photo-info box-border px-6 py-5">
|
||||
<view v-if="photo.title" class="photo-title mb-3 text-[30rpx] text-[#333] font-bold">
|
||||
{{ photo.title }}
|
||||
</view>
|
||||
<view v-if="photo.takenDate || photo.location" class="photo-meta mb-3 flex flex-wrap items-center">
|
||||
<text v-if="photo.takenDate" class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.takenDate }}</text>
|
||||
<text v-if="photo.location" class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.location }}</text>
|
||||
</view>
|
||||
<view v-if="photo.description" class="photo-desc text-[26rpx] text-[#666] leading-[1.6]">
|
||||
{{ photo.description }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 右列 -->
|
||||
<view class="photo-column box-border min-w-0 flex-1">
|
||||
<view v-for="photo in rightPhotos" :key="photo.name" class="photo-card mb-6 box-border overflow-hidden rounded-xl bg-white shadow-sm">
|
||||
<image
|
||||
class="photo-image w-full"
|
||||
:src="photo.url"
|
||||
mode="widthFix"
|
||||
lazy-load
|
||||
@click="handlePreview(photo.url)"
|
||||
/>
|
||||
<view class="photo-info box-border px-6 py-5">
|
||||
<view v-if="photo.title" class="photo-title mb-3 text-[30rpx] text-[#333] font-bold">
|
||||
{{ photo.title }}
|
||||
</view>
|
||||
<view v-if="photo.takenDate || photo.location" class="photo-meta mb-3 flex flex-wrap items-center">
|
||||
<text v-if="photo.takenDate" class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.takenDate }}</text>
|
||||
<text v-if="photo.location" class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.location }}</text>
|
||||
</view>
|
||||
<view v-if="photo.description" class="photo-desc text-[26rpx] text-[#666] leading-[1.6]">
|
||||
{{ photo.description }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<!-- 照片列表 -->
|
||||
<scroll-view class="box-border max-h-[50vh] flex-1" scroll-y :show-scrollbar="false">
|
||||
<view v-if="loading" class="viewer-empty box-border h-full flex items-center justify-center p-10">
|
||||
<view class="viewer-loading flex flex-col items-center">
|
||||
<view class="loading-text mt-7 text-[28rpx] text-[#56bbf9]">
|
||||
照片正在努力加载中啦~
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else-if="photoList.length === 0"
|
||||
class="viewer-empty box-border h-full flex items-center justify-center p-10">
|
||||
<wd-empty description="这个相册暂时还没有照片~" />
|
||||
</view>
|
||||
<view v-else class="photo-list box-border flex items-start p-5">
|
||||
<!-- 左列 -->
|
||||
<view class="photo-column box-border min-w-0 flex-1 mr-[20rpx]">
|
||||
<view v-for="photo in leftPhotos" :key="photo.name"
|
||||
class="photo-card mb-6 box-border overflow-hidden rounded-xl bg-white shadow-sm">
|
||||
<image class="photo-image w-full" :src="photo.url" mode="widthFix" lazy-load
|
||||
@click="handlePreview(photo.url)" />
|
||||
<view class="photo-info box-border px-6 py-5">
|
||||
<view v-if="photo.title" class="photo-title mb-3 text-[30rpx] text-[#333] font-bold">
|
||||
{{ photo.title }}
|
||||
</view>
|
||||
<view v-if="photo.takenDate || photo.location"
|
||||
class="photo-meta mb-3 flex flex-wrap items-center">
|
||||
<text v-if="photo.takenDate"
|
||||
class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.takenDate }}</text>
|
||||
<text v-if="photo.location"
|
||||
class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.location }}</text>
|
||||
</view>
|
||||
<view v-if="photo.description"
|
||||
class="photo-desc text-[26rpx] text-[#666] leading-[1.6]">
|
||||
{{ photo.description }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 右列 -->
|
||||
<view class="photo-column box-border min-w-0 flex-1">
|
||||
<view v-for="photo in rightPhotos" :key="photo.name"
|
||||
class="photo-card mb-6 box-border overflow-hidden rounded-xl bg-white shadow-sm">
|
||||
<image class="photo-image w-full" :src="photo.url" mode="widthFix" lazy-load
|
||||
@click="handlePreview(photo.url)" />
|
||||
<view class="photo-info box-border px-6 py-5">
|
||||
<view v-if="photo.title" class="photo-title mb-3 text-[30rpx] text-[#333] font-bold">
|
||||
{{ photo.title }}
|
||||
</view>
|
||||
<view v-if="photo.takenDate || photo.location"
|
||||
class="photo-meta mb-3 flex flex-wrap items-center">
|
||||
<text v-if="photo.takenDate"
|
||||
class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.takenDate }}</text>
|
||||
<text v-if="photo.location"
|
||||
class="meta-item mr-8 text-[24rpx] text-[#999]">{{ photo.location }}</text>
|
||||
</view>
|
||||
<view v-if="photo.description"
|
||||
class="photo-desc text-[26rpx] text-[#666] leading-[1.6]">
|
||||
{{ photo.description }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部关闭 -->
|
||||
<view class="viewer-footer box-border shrink-0 border-t border-black/5 px-7 py-5">
|
||||
<view class="viewer-footer-btn h-20 flex items-center justify-center rounded-[40rpx]" style="background: linear-gradient(135deg, #f88ca2, #ff6b9d); box-shadow: 0 4rpx 24rpx rgb(248 140 162 / 35%);" @click="handleClose">
|
||||
<text class="footer-text text-[30rpx] text-white font-bold">关 闭</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</template>
|
||||
<!-- 底部关闭 -->
|
||||
<view class="w-full shrink-0">
|
||||
<uh-button custom-class="py-2 uh-global-card-glass rounded-xl !bg-love/90 text-white border"
|
||||
@click="handleClose">
|
||||
关闭
|
||||
</uh-button>
|
||||
</view>
|
||||
</view>
|
||||
</uh-glass-popup>
|
||||
</template>
|
||||
@@ -1,193 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 相册密码解锁弹窗(源自旧项目 components/album-unlock-modal,新建复刻)
|
||||
* 输入密码解锁加密相册;2026-09-03 接入插件防刷验证码:
|
||||
* 首次提交若服务端要求验证码(403+附新码)则展示验证码行,携带后重试(验证码一次性)
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { getPluginCaptcha, unlockAlbum } from '@/api/uni-halo'
|
||||
import type { ICaptchaQuery, IPluginCaptcha } from '@/api/uni-halo'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
show: boolean
|
||||
albumName?: string
|
||||
albumKey?: string
|
||||
}>(), {
|
||||
albumName: '',
|
||||
albumKey: '',
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:show', show: boolean): void
|
||||
(e: 'success', data: { albumKey: string, token: string, photos: unknown[] }): void
|
||||
}>()
|
||||
|
||||
const isShow = ref(false)
|
||||
const password = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
// 防刷验证码(服务端 403 附新码 / 主动刷新)
|
||||
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 handleOnCancel() {
|
||||
password.value = ''
|
||||
resetCaptcha()
|
||||
isShow.value = false
|
||||
emit('update:show', false)
|
||||
}
|
||||
|
||||
async function handleOnConfirm() {
|
||||
if (!password.value.trim()) {
|
||||
uni.showToast({ title: '请输入密码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const captchaQuery: ICaptchaQuery | undefined = captchaImage.value
|
||||
? { captchaId: captchaId.value, captchaCode: captchaCode.value }
|
||||
: undefined
|
||||
const res = await unlockAlbum(props.albumKey, password.value, captchaQuery)
|
||||
if (res.data && (res.data as { token?: string }).token) {
|
||||
password.value = ''
|
||||
resetCaptcha()
|
||||
isShow.value = false
|
||||
emit('update:show', false)
|
||||
emit('success', {
|
||||
albumKey: props.albumKey,
|
||||
token: (res.data as { token: string }).token,
|
||||
photos: (res.data as { photos?: unknown[] }).photos || [],
|
||||
})
|
||||
uni.showToast({ title: '解锁成功', icon: 'success' })
|
||||
}
|
||||
}
|
||||
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>
|
||||
<wd-dialog
|
||||
v-model="isShow"
|
||||
title="相册密码"
|
||||
:show-cancel="true"
|
||||
confirm-text="解锁"
|
||||
confirm-button-color="#f88ca2"
|
||||
@cancel="handleOnCancel"
|
||||
@confirm="handleOnConfirm"
|
||||
>
|
||||
<view class="unlock-modal-content py-5">
|
||||
<view class="album-info flex flex-col items-center">
|
||||
<view class="lock-icon mb-5 text-[80rpx]">
|
||||
🔒
|
||||
</view>
|
||||
<view class="album-name mb-3 text-[32rpx] text-[#333] font-bold">
|
||||
{{ albumName }}
|
||||
</view>
|
||||
<view class="tip-text text-[26rpx] text-[#999]">
|
||||
此相册已加密,请输入密码查看
|
||||
</view>
|
||||
</view>
|
||||
<wd-input
|
||||
v-model="password"
|
||||
:password="true"
|
||||
placeholder="请输入相册密码"
|
||||
align="center"
|
||||
clearable
|
||||
class="password-input mt-9"
|
||||
/>
|
||||
|
||||
<!-- 防刷验证码(首次提交 403 后展示;点击图片可刷新) -->
|
||||
<view v-if="captchaSrc" class="captcha-box mt-5 flex items-center justify-center gap-4">
|
||||
<image
|
||||
:src="captchaSrc"
|
||||
class="captcha-img h-[76rpx] w-[200rpx] rounded-lg"
|
||||
mode="widthFix"
|
||||
@click="handleRefreshCaptcha"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="captchaCode"
|
||||
placeholder="验证码"
|
||||
align="center"
|
||||
clearable
|
||||
class="captcha-input w-[240rpx]"
|
||||
/>
|
||||
</view>
|
||||
<view v-if="captchaSrc" class="captcha-tip mt-2 text-center text-[22rpx] text-[#aaa]">
|
||||
点击图片刷新验证码
|
||||
</view>
|
||||
</view>
|
||||
</wd-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.unlock-modal-content {
|
||||
/* 布局全部由 UnoCSS 原子类实现 */
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,188 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { getPluginCaptcha, unlockAlbum } from '@/api/uni-halo'
|
||||
import type { ICaptchaQuery, IPluginCaptcha } from '@/api/uni-halo'
|
||||
|
||||
interface IProps {
|
||||
show : boolean
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
show : boolean
|
||||
albumName ?: string
|
||||
albumKey ?: string
|
||||
}>(), {
|
||||
albumName: '',
|
||||
albumKey: '',
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e : 'update:show', show : boolean) : void
|
||||
(e : 'success', data : { albumKey : string, token : string, photos : unknown[] }) : void
|
||||
}>()
|
||||
|
||||
const isShow = ref(false)
|
||||
const password = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
// 防刷验证码(服务端 403 附新码 / 主动刷新)
|
||||
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
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const captchaQuery : ICaptchaQuery | undefined = captchaImage.value
|
||||
? { captchaId: captchaId.value, captchaCode: captchaCode.value }
|
||||
: undefined
|
||||
const res = await unlockAlbum(props.albumKey, password.value, captchaQuery)
|
||||
if (res.data && (res.data as { token ?: string }).token) {
|
||||
password.value = ''
|
||||
resetCaptcha()
|
||||
isShow.value = false
|
||||
emit('update:show', false)
|
||||
emit('success', {
|
||||
albumKey: props.albumKey,
|
||||
token: (res.data as { token : string }).token,
|
||||
photos: (res.data as { photos ?: unknown[] }).photos || [],
|
||||
})
|
||||
uni.showToast({ title: '解锁成功', icon: 'success' })
|
||||
}
|
||||
}
|
||||
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> 解锁相册
|
||||
</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="album-name mb-3 text-lg text-gray-900 font-bold">
|
||||
{{ albumName }}
|
||||
</view>
|
||||
<view class="tip-text text-sm text-gray-600">
|
||||
此相册已加密,请输入密码查看
|
||||
</view>
|
||||
</view>
|
||||
<input v-model="password" :password="true" 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="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="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 ? '解锁中...' : '解锁' }}
|
||||
</uh-button>
|
||||
</view>
|
||||
</view>
|
||||
</uh-glass-popup>
|
||||
</template>
|
||||
@@ -1,11 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
interface IProps {
|
||||
customClass : Array<string>;
|
||||
customClass?: string;
|
||||
}
|
||||
const props = defineProps({
|
||||
customClass: () => {
|
||||
return []
|
||||
},
|
||||
|
||||
const props = withDefaults(defineProps<IProps>(), {
|
||||
customClass: ''
|
||||
})
|
||||
|
||||
function handleScrollTop() {
|
||||
@@ -19,13 +18,18 @@
|
||||
const visible = computed(() => {
|
||||
return !balckList.includes(currentPage.route)
|
||||
})
|
||||
|
||||
const _customClass = computed(() => {
|
||||
const colorClass = currentPage.route.includes('/love/')?'text-love':'text-primary'
|
||||
return `${props.customClass} ${colorClass}`
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="visible" class="fixed bottom-22 right-3 z-50 pb-safe">
|
||||
<view class="uh-global-card-glass border h-11 w-11 flex items-center justify-center rounded-full text-primary"
|
||||
:class="props.customClass" @click="handleScrollTop">
|
||||
<wd-icon name="arrow-up" size="20px" />
|
||||
<view class="uh-global-card-glass border h-11 w-11 flex items-center justify-center rounded-full"
|
||||
:class="_customClass" @click="handleScrollTop">
|
||||
<wd-icon name="arrow-up" size="42rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
Reference in New Issue
Block a user