import { onMounted, reactive, ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import { auditCreatorApi, listCreatorDocumentsApi, pageCreatorsApi } from '@/api/admin/creator' /** 与后端 CreatorService 的状态取值保持一致 */ export const CREATOR_STATUS = [ { value: 'pending', label: '待审核', tag: 'warning' }, { value: 'approved', label: '已通过', tag: 'success' }, { value: 'rejected', label: '已驳回', tag: 'danger' }, { value: 'frozen', label: '已冻结', tag: 'info' } ] export const CREATOR_TYPE = [ { value: 'INDIVIDUAL', label: '个人' }, { value: 'COMPANY', label: '机构' } ] export function creatorStatusMeta(status) { return ( CREATOR_STATUS.find((item) => item.value === status) || { label: status || '-', tag: 'info' } ) } export function creatorTypeText(type) { return CREATOR_TYPE.find((item) => item.value === type)?.label || type || '-' } export function useCreatorAudit() { const rows = ref([]) const total = ref(0) const loading = ref(false) const keyword = ref('') const statusFilter = ref(undefined) const typeFilter = ref(undefined) const currentPage = ref(1) const pageSize = ref(10) const auditVisible = ref(false) const auditSaving = ref(false) const auditTarget = ref(null) const auditForm = reactive({ action: 'APPROVE', reason: '', rejectCode: '' }) const documentsVisible = ref(false) const documentsLoading = ref(false) const documents = ref([]) const documentsTarget = ref(null) async function load() { loading.value = true try { const res = await pageCreatorsApi({ pageIndex: currentPage.value, pageSize: pageSize.value, keyword: keyword.value.trim() || undefined, status: statusFilter.value, type: typeFilter.value }) rows.value = res.data?.list || [] total.value = res.data?.total || 0 } finally { loading.value = false } } function query() { currentPage.value = 1 load() } function reset() { keyword.value = '' statusFilter.value = undefined typeFilter.value = undefined query() } function handleSizeChange() { currentPage.value = 1 load() } async function openDocuments(row) { documentsTarget.value = row documentsVisible.value = true documentsLoading.value = true documents.value = [] try { documents.value = (await listCreatorDocumentsApi(row.id)).data || [] } finally { documentsLoading.value = false } } function openAudit(row, action = 'APPROVE') { auditTarget.value = row auditForm.action = action auditForm.reason = '' auditForm.rejectCode = '' auditVisible.value = true } async function confirmAudit() { const row = auditTarget.value if (!row) return if (auditForm.action === 'REJECT' && !auditForm.reason.trim()) { return ElMessage.warning('驳回必须填写原因') } auditSaving.value = true try { await auditCreatorApi(row.id, { action: auditForm.action, reason: auditForm.reason.trim(), rejectCode: auditForm.rejectCode.trim() }) ElMessage.success('审核已提交') auditVisible.value = false await load() } finally { auditSaving.value = false } } /** 冻结是不可逆的运营动作,单独二次确认 */ async function freeze(row) { try { await ElMessageBox.confirm(`冻结后「${row.name}」将无法提交内容,确认冻结?`, '冻结创作者', { confirmButtonText: '确认冻结', cancelButtonText: '取消', type: 'warning' }) } catch { return } await auditCreatorApi(row.id, { action: 'FREEZE', reason: '运营冻结' }) ElMessage.success('已冻结') await load() } onMounted(load) return { rows, total, loading, keyword, statusFilter, typeFilter, currentPage, pageSize, auditVisible, auditSaving, auditTarget, auditForm, documentsVisible, documentsLoading, documents, documentsTarget, load, query, reset, handleSizeChange, openDocuments, openAudit, confirmAudit, freeze } }