Files
JayuCloud/YumiNail-Frontend/src/views/admin/LegalAgreementsView.vue
T

215 lines
8.9 KiB
Vue

<template>
<div class="admin-page">
<div class="page-header">
<div>
<h2>协议管理</h2>
<p>维护用户登录/注册前需要阅读并同意的用户协议和隐私政策。</p>
</div>
<a-button type="primary" @click="openCreate">新增协议</a-button>
</div>
<a-table :columns="columns" :data-source="agreements" :loading="loading" row-key="id" :scroll="{ x: 'max-content' }" bordered>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<a-tag :color="record.status === 1 ? 'green' : 'default'">{{ record.statusText || (record.status === 1 ? '已发布' : '草稿/停用') }}</a-tag>
</template>
<template v-else-if="column.key === 'action'">
<a-space>
<a-button size="small" @click="openEdit(record)">编辑</a-button>
<a-button size="small" type="primary" :disabled="record.status === 1" @click="publishAgreement(record.id)">发布</a-button>
<a-button size="small" danger :disabled="record.status !== 1" @click="disableAgreement(record.id)">停用</a-button>
</a-space>
</template>
</template>
</a-table>
<a-modal
v-model:open="modalOpen"
:title="editingId ? '编辑协议' : '新增协议'"
width="760px"
:mask-closable="false"
:confirm-loading="saving"
@ok="saveAgreement"
>
<a-form layout="vertical">
<a-form-item label="协议类型">
<a-select v-model:value="form.agreementType">
<a-select-option value="USER_TERMS">用户协议</a-select-option>
<a-select-option value="PRIVACY_POLICY">隐私政策</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="标题">
<a-input v-model:value="form.title" placeholder="例如:Fingertip Designer 用户协议" />
</a-form-item>
<a-form-item label="版本">
<a-input v-model:value="form.version" placeholder="例如:2026-05-18" />
</a-form-item>
<a-form-item label="内容">
<a-textarea v-model:value="form.content" :rows="12" placeholder="请输入协议正文,支持 HTML / Markdown" />
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
/**
* Purpose: LegalAgreementAdminVO supports LegalAgreementsView.vue by holding or executing the legal agreement admin vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminLegalAgreementApi, type LegalAgreementAdminVO } from '@/api/admin'
import type { IdType } from '@/utils/id'
/**
* Purpose: loading supports LegalAgreementsView.vue by holding or executing the loading page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loading = ref(false)
/**
* Purpose: saving supports LegalAgreementsView.vue by holding or executing the saving page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const saving = ref(false)
/**
* Purpose: modalOpen supports LegalAgreementsView.vue by holding or executing the modal open page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const modalOpen = ref(false)
/**
* Purpose: editingId supports LegalAgreementsView.vue by holding or executing the editing id page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const editingId = ref<IdType | null>(null)
/**
* Purpose: agreements supports LegalAgreementsView.vue by holding or executing the agreements page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const agreements = ref<LegalAgreementAdminVO[]>([])
/**
* Purpose: form supports LegalAgreementsView.vue by holding or executing the form page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const form = reactive({
agreementType: 'USER_TERMS' as 'USER_TERMS' | 'PRIVACY_POLICY',
title: '',
version: '',
content: ''
})
/**
* Purpose: columns supports LegalAgreementsView.vue by holding or executing the columns page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const columns = [
{ title: '类型', dataIndex: 'agreementTypeName', key: 'agreementTypeName' },
{ title: '标题', dataIndex: 'title', key: 'title' },
{ title: '版本', dataIndex: 'version', key: 'version' },
{ title: '状态', dataIndex: 'status', key: 'status' },
{ title: '生效时间', dataIndex: 'effectiveTime', key: 'effectiveTime' },
{ title: '操作', key: 'action', width: 220 }
]
/**
* Purpose: loadAgreements supports LegalAgreementsView.vue by holding or executing the load agreements page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loadAgreements = async () => {
loading.value = true
try {
agreements.value = await adminLegalAgreementApi.list() as unknown as LegalAgreementAdminVO[]
} finally {
loading.value = false
}
}
/**
* Purpose: resetForm supports LegalAgreementsView.vue by holding or executing the reset form page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const resetForm = () => {
editingId.value = null
form.agreementType = 'USER_TERMS'
form.title = ''
form.version = ''
form.content = ''
}
/**
* Purpose: openCreate supports LegalAgreementsView.vue by holding or executing the open create page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const openCreate = () => {
resetForm()
modalOpen.value = true
}
/**
* Purpose: openEdit supports LegalAgreementsView.vue by holding or executing the open edit page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const openEdit = (record: Record<string, any>) => {
const agreement = record as LegalAgreementAdminVO
editingId.value = agreement.id
form.agreementType = agreement.agreementType
form.title = agreement.title
form.version = agreement.version
form.content = agreement.content
modalOpen.value = true
}
/**
* Purpose: saveAgreement supports LegalAgreementsView.vue by holding or executing the save agreement page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const saveAgreement = async () => {
if (!form.title || !form.version || !form.content) {
message.warning('请填写完整协议信息')
return
}
saving.value = true
try {
if (editingId.value) {
await adminLegalAgreementApi.update(editingId.value, { ...form })
} else {
await adminLegalAgreementApi.create({ ...form })
}
message.success('保存成功')
modalOpen.value = false
await loadAgreements()
} finally {
saving.value = false
}
}
/**
* Purpose: publishAgreement supports LegalAgreementsView.vue by holding or executing the publish agreement page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const publishAgreement = async (id: IdType) => {
await adminLegalAgreementApi.publish(id)
message.success('发布成功')
await loadAgreements()
}
/**
* Purpose: disableAgreement supports LegalAgreementsView.vue by holding or executing the disable agreement page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const disableAgreement = async (id: IdType) => {
await adminLegalAgreementApi.disable(id)
message.success('已停用')
await loadAgreements()
}
onMounted(loadAgreements)
</script>
<style scoped>
.admin-page { padding: 16px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.page-header h2 { margin: 0 0 6px; }
.page-header p { margin: 0; color: var(--text-secondary); }
</style>