feat(quality-owner): 增加开通协议与强制阅读
This commit is contained in:
@@ -15,11 +15,19 @@ export interface QualityOwnerStatus {
|
||||
required_deposit_cent: number
|
||||
insurance_fee_bps: number
|
||||
premium_insurance_fee_bps: number
|
||||
agreement_title: string
|
||||
agreement_content: string
|
||||
agreement_read_seconds: number
|
||||
}
|
||||
|
||||
export async function fetchQualityOwnerStatus() {
|
||||
const { data } = await apiClient.get<ApiResponse<QualityOwnerStatus>>('/quality-owner/status')
|
||||
return data.data
|
||||
return {
|
||||
...data.data,
|
||||
agreement_title: data.data.agreement_title || '优质号主服务协议',
|
||||
agreement_content: data.data.agreement_content || '',
|
||||
agreement_read_seconds: Math.max(15, Number(data.data.agreement_read_seconds || 15)),
|
||||
}
|
||||
}
|
||||
|
||||
export async function activateQualityOwner() {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import AnnouncementContent from '@/features/announcement/components/AnnouncementContent.vue'
|
||||
import { renderAnnouncementMarkdown } from '@/features/announcement/utils/markdown'
|
||||
|
||||
const props = defineProps<{ content: string }>()
|
||||
|
||||
const html = computed(() => renderAnnouncementMarkdown(props.content))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AnnouncementContent class="quality-owner-agreement-content" :html="html" />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.quality-owner-agreement-content {
|
||||
color: #334155;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(h1),
|
||||
.quality-owner-agreement-content :deep(h2),
|
||||
.quality-owner-agreement-content :deep(h3) {
|
||||
margin: 18px 0 8px;
|
||||
color: #1f2937;
|
||||
font-weight: 800;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(p) {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(ul),
|
||||
.quality-owner-agreement-content :deep(ol) {
|
||||
margin: 8px 0;
|
||||
padding-left: 22px;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(table) {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
margin: 12px 0;
|
||||
overflow-x: auto;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(th),
|
||||
.quality-owner-agreement-content :deep(td) {
|
||||
min-width: 110px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid #e2e8f0;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(th) {
|
||||
background: #f8fafc;
|
||||
color: #1f2937;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.quality-owner-agreement-content {
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.quality-owner-agreement-content :deep(th),
|
||||
.quality-owner-agreement-content :deep(td) {
|
||||
min-width: 96px;
|
||||
padding: 7px 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { QualityOwnerStatus } from '@/features/quality-owner/api/qualityOwner'
|
||||
import { useQualityOwnerAgreement } from '../useQualityOwnerAgreement'
|
||||
|
||||
function status(readSeconds = 15): QualityOwnerStatus {
|
||||
return {
|
||||
user_id: 1,
|
||||
active: false,
|
||||
status: 'none',
|
||||
can_cancel: false,
|
||||
active_premium_listing_count: 0,
|
||||
deposit_amount_cent: 0,
|
||||
deposit_source: '',
|
||||
available_balance_cent: 20000,
|
||||
required_deposit_cent: 20000,
|
||||
insurance_fee_bps: 800,
|
||||
premium_insurance_fee_bps: 400,
|
||||
agreement_title: '优质号主服务协议',
|
||||
agreement_content: '协议正文',
|
||||
agreement_read_seconds: readSeconds,
|
||||
}
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
describe('useQualityOwnerAgreement', () => {
|
||||
it('阅读满 15 秒且勾选后才能确认', async () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date('2026-11-05T00:00:00Z'))
|
||||
const action = vi.fn()
|
||||
const agreement = useQualityOwnerAgreement()
|
||||
|
||||
agreement.open(status(), action)
|
||||
agreement.accepted.value = true
|
||||
expect(agreement.canConfirm.value).toBe(false)
|
||||
|
||||
vi.advanceTimersByTime(14_999)
|
||||
expect(agreement.remainingSeconds.value).toBe(1)
|
||||
expect(agreement.canConfirm.value).toBe(false)
|
||||
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(agreement.remainingSeconds.value).toBe(0)
|
||||
expect(agreement.canConfirm.value).toBe(true)
|
||||
|
||||
await agreement.confirm()
|
||||
expect(action).toHaveBeenCalledOnce()
|
||||
expect(agreement.visible.value).toBe(false)
|
||||
})
|
||||
|
||||
it('关闭后重新打开会重新计时并清除同意状态', () => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(new Date('2026-11-05T00:00:00Z'))
|
||||
const agreement = useQualityOwnerAgreement()
|
||||
|
||||
agreement.open(status(20), vi.fn())
|
||||
agreement.accepted.value = true
|
||||
vi.advanceTimersByTime(5000)
|
||||
agreement.close()
|
||||
agreement.open(status(), vi.fn())
|
||||
|
||||
expect(agreement.remainingSeconds.value).toBe(15)
|
||||
expect(agreement.accepted.value).toBe(false)
|
||||
expect(agreement.canConfirm.value).toBe(false)
|
||||
agreement.close()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,72 @@
|
||||
import { computed, getCurrentInstance, onUnmounted, ref } from 'vue'
|
||||
|
||||
import type { QualityOwnerStatus } from '@/features/quality-owner/api/qualityOwner'
|
||||
|
||||
type AgreementAction = () => void | Promise<void>
|
||||
|
||||
export function useQualityOwnerAgreement() {
|
||||
const visible = ref(false)
|
||||
const accepted = ref(false)
|
||||
const remainingSeconds = ref(0)
|
||||
const totalSeconds = ref(15)
|
||||
let pendingAction: AgreementAction | null = null
|
||||
let startedAt = 0
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const canConfirm = computed(() => visible.value && accepted.value && remainingSeconds.value <= 0)
|
||||
|
||||
function stopTimer() {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}
|
||||
|
||||
function updateRemaining() {
|
||||
const elapsed = Math.floor((Date.now() - startedAt) / 1000)
|
||||
remainingSeconds.value = Math.max(totalSeconds.value - elapsed, 0)
|
||||
if (remainingSeconds.value <= 0) stopTimer()
|
||||
}
|
||||
|
||||
function open(status: QualityOwnerStatus, action: AgreementAction) {
|
||||
stopTimer()
|
||||
totalSeconds.value = Math.max(15, Math.floor(Number(status.agreement_read_seconds || 15)))
|
||||
remainingSeconds.value = totalSeconds.value
|
||||
startedAt = Date.now()
|
||||
accepted.value = false
|
||||
pendingAction = action
|
||||
visible.value = true
|
||||
timer = setInterval(updateRemaining, 250)
|
||||
}
|
||||
|
||||
function close() {
|
||||
stopTimer()
|
||||
visible.value = false
|
||||
accepted.value = false
|
||||
remainingSeconds.value = 0
|
||||
pendingAction = null
|
||||
}
|
||||
|
||||
async function confirm() {
|
||||
if (!canConfirm.value) return false
|
||||
const action = pendingAction
|
||||
close()
|
||||
await action?.()
|
||||
return true
|
||||
}
|
||||
|
||||
if (getCurrentInstance()) {
|
||||
onUnmounted(stopTimer)
|
||||
}
|
||||
|
||||
return {
|
||||
visible,
|
||||
accepted,
|
||||
remainingSeconds,
|
||||
totalSeconds,
|
||||
canConfirm,
|
||||
open,
|
||||
close,
|
||||
confirm,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user