573 lines
18 KiB
Vue
573 lines
18 KiB
Vue
<template>
|
|
<MarketingPageShell :tip="t('kb.article.pageTip')">
|
|
<div class="table-toolbar">
|
|
<div class="toolbar-left">
|
|
<div class="toolbar-filters">
|
|
<a-input
|
|
v-model="keyword"
|
|
allow-clear
|
|
class="mkt-filter-search"
|
|
:placeholder="t('kb.article.searchPlaceholder')"
|
|
@press-enter="handleSearch"
|
|
@clear="handleSearch"
|
|
/>
|
|
<a-select
|
|
v-model="categoryFilter"
|
|
allow-clear
|
|
:style="{ width: '150px' }"
|
|
:placeholder="t('kb.article.categoryFilter')"
|
|
@change="handleSearch"
|
|
>
|
|
<a-option v-for="c in categories" :key="c.id" :value="c.id">{{ c.name }}</a-option>
|
|
</a-select>
|
|
<a-select
|
|
v-model="statusFilter"
|
|
allow-clear
|
|
:style="{ width: '120px' }"
|
|
:placeholder="t('kb.article.statusFilter')"
|
|
@change="handleSearch"
|
|
>
|
|
<a-option value="draft">{{ t('kb.article.status.draft') }}</a-option>
|
|
<a-option value="published">{{ t('kb.article.status.published') }}</a-option>
|
|
<a-option value="offline">{{ t('kb.article.status.offline') }}</a-option>
|
|
</a-select>
|
|
<a-select
|
|
v-model="audienceFilter"
|
|
allow-clear
|
|
:style="{ width: '120px' }"
|
|
:placeholder="t('kb.article.audienceFilter')"
|
|
@change="handleSearch"
|
|
>
|
|
<a-option value="customer">{{ t('kb.article.audience.customer') }}</a-option>
|
|
<a-option value="internal">{{ t('kb.article.audience.internal') }}</a-option>
|
|
</a-select>
|
|
<a-button class="app-btn-search" @click="handleSearch">
|
|
{{ t('common.search') }}
|
|
</a-button>
|
|
</div>
|
|
<a-button
|
|
v-if="canEdit"
|
|
class="btn-add app-btn-primary-soft"
|
|
@click="openModal()"
|
|
>
|
|
{{ t('common.add') }}
|
|
</a-button>
|
|
</div>
|
|
<div class="toolbar-right">
|
|
<a-space :size="8">
|
|
<a-button @click="loadList">{{ t('common.refresh') }}</a-button>
|
|
<PaginationPro
|
|
:total-count="totalCount"
|
|
v-model:current-page="currentPage"
|
|
v-model:page-size="pageSize"
|
|
@page-change="loadList"
|
|
@page-size-change="loadList"
|
|
/>
|
|
</a-space>
|
|
</div>
|
|
</div>
|
|
|
|
<a-spin :loading="listLoading" class="list-spin">
|
|
<div ref="tableContainerRef" class="list-wrap">
|
|
<HandsontablePro
|
|
:columns="hotColumns"
|
|
:data="tableRows"
|
|
:total="totalCount"
|
|
:current-page="currentPage"
|
|
:page-size="pageSize"
|
|
:show-action-column="true"
|
|
:action-renderer="actionRenderer"
|
|
:stretch-columns="true"
|
|
:height="handsontableHeight"
|
|
:read-only="true"
|
|
@action-click="handleActionClick"
|
|
/>
|
|
</div>
|
|
</a-spin>
|
|
|
|
<ModalPro
|
|
v-model:visible="modalVisible"
|
|
:title="editingId ? t('kb.article.modal.edit') : t('kb.article.modal.add')"
|
|
:confirm-loading="modalLoading"
|
|
width="780px"
|
|
unmount-on-close
|
|
@ok="handleModalOk"
|
|
@cancel="handleModalCancel"
|
|
>
|
|
<a-form
|
|
ref="formRef"
|
|
:model="formState"
|
|
:rules="formRules"
|
|
layout="vertical"
|
|
class="kb-article-form"
|
|
>
|
|
<a-row :gutter="16">
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.categoryId')" field="categoryId">
|
|
<a-select
|
|
v-model="formState.categoryId"
|
|
:placeholder="t('kb.article.form.categoryId')"
|
|
allow-search
|
|
>
|
|
<a-option v-for="c in categories" :key="c.id" :value="c.id">{{ c.name }}</a-option>
|
|
</a-select>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.title')" field="title">
|
|
<a-input
|
|
v-model="formState.title"
|
|
:max-length="200"
|
|
:placeholder="t('kb.article.form.titlePlaceholder')"
|
|
allow-clear
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="24">
|
|
<a-form-item :label="t('kb.article.form.summary')" field="summary">
|
|
<a-textarea
|
|
v-model="formState.summary"
|
|
:max-length="500"
|
|
:auto-size="{ minRows: 2, maxRows: 4 }"
|
|
:placeholder="t('kb.article.form.summaryPlaceholder')"
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="8">
|
|
<a-form-item :label="t('kb.article.form.audience')" field="audience">
|
|
<a-select v-model="formState.audience">
|
|
<a-option value="customer">{{ t('kb.article.audience.customer') }}</a-option>
|
|
<a-option value="internal">{{ t('kb.article.audience.internal') }}</a-option>
|
|
</a-select>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="8">
|
|
<a-form-item :label="t('kb.article.form.status')" field="status">
|
|
<a-select v-model="formState.status">
|
|
<a-option value="draft">{{ t('kb.article.status.draft') }}</a-option>
|
|
<a-option value="published">{{ t('kb.article.status.published') }}</a-option>
|
|
<a-option value="offline">{{ t('kb.article.status.offline') }}</a-option>
|
|
</a-select>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="8">
|
|
<a-form-item :label="t('kb.article.form.sortOrder')" field="sortOrder">
|
|
<a-input-number v-model="formState.sortOrder" :min="0" :precision="0" style="width: 100%" />
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.tags')" field="tags">
|
|
<a-input
|
|
v-model="formState.tags"
|
|
:placeholder="t('kb.article.form.tagsPlaceholder')"
|
|
allow-clear
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.expireTime')" field="expireTime">
|
|
<a-date-picker
|
|
v-model="formState.expireTime"
|
|
show-time
|
|
style="width: 100%"
|
|
value-format="YYYY-MM-DD HH:mm:ss"
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.relatedPath')" field="relatedPath">
|
|
<a-input
|
|
v-model="formState.relatedPath"
|
|
:placeholder="t('kb.article.form.relatedPathPlaceholder')"
|
|
allow-clear
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.relatedLabel')" field="relatedLabel">
|
|
<a-input
|
|
v-model="formState.relatedLabel"
|
|
:placeholder="t('kb.article.form.relatedLabelPlaceholder')"
|
|
allow-clear
|
|
/>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12">
|
|
<a-form-item :label="t('kb.article.form.isPinned')" field="isPinned">
|
|
<a-switch v-model="formState.isPinned" />
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="24">
|
|
<a-form-item :label="t('kb.article.form.content')" field="content">
|
|
<a-tabs v-model:active-key="contentTab" type="rounded" size="small">
|
|
<a-tab-pane key="edit" :title="t('kb.article.tab.edit')">
|
|
<a-textarea
|
|
v-model="formState.content"
|
|
:auto-size="{ minRows: 10, maxRows: 18 }"
|
|
:placeholder="t('kb.article.form.contentPlaceholder')"
|
|
/>
|
|
</a-tab-pane>
|
|
<a-tab-pane key="preview" :title="t('kb.article.tab.preview')">
|
|
<div class="kb-preview">
|
|
<MarkdownViewer :content="formState.content || ''" />
|
|
</div>
|
|
</a-tab-pane>
|
|
</a-tabs>
|
|
</a-form-item>
|
|
</a-col>
|
|
</a-row>
|
|
</a-form>
|
|
</ModalPro>
|
|
</MarketingPageShell>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { computed, onMounted, reactive, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { Message, Modal } from '@arco-design/web-vue'
|
|
import type { FormInstance } from '@arco-design/web-vue'
|
|
import HandsontablePro from '@/components/HandsontablePro/index.vue'
|
|
import PaginationPro from '@/components/PaginationPro/index.vue'
|
|
import ModalPro from '@/components/ModalPro/index.vue'
|
|
import MarkdownViewer from '@/components/MarkdownViewer/index.vue'
|
|
import { useTableContainerHeight } from '@/composables/useTableContainerHeight'
|
|
import { hasPermission } from '@/utils/rbac-permission'
|
|
import { renderWarehouseActionBtn, wrapWarehouseActions } from '@/utils/warehouseActionRenderer'
|
|
import {
|
|
adminDeleteArticle,
|
|
adminGetArticle,
|
|
adminListCategories,
|
|
adminOfflineArticle,
|
|
adminPageArticles,
|
|
adminPinArticle,
|
|
adminPublishArticle,
|
|
adminSaveArticle,
|
|
type KbArticle,
|
|
type KbCategory,
|
|
} from '@/api/kb'
|
|
import MarketingPageShell from '@/views/marketing/components/MarketingPageShell.vue'
|
|
|
|
defineOptions({ name: 'KbArticle' })
|
|
|
|
const { t } = useI18n()
|
|
const { tableContainerRef, tableHeight } = useTableContainerHeight()
|
|
const handsontableHeight = computed(() => Math.max(tableHeight.value || 0, 400))
|
|
const canEdit = computed(() => hasPermission('Knowledge.Article.Edit'))
|
|
const canPublish = computed(() => hasPermission('Knowledge.Article.Publish'))
|
|
|
|
interface ArticleRow extends KbArticle {
|
|
statusText: string
|
|
audienceText: string
|
|
pinnedText: string
|
|
publishTimeText: string
|
|
}
|
|
|
|
const tableRows = ref<ArticleRow[]>([])
|
|
const categories = ref<KbCategory[]>([])
|
|
const totalCount = ref(0)
|
|
const listLoading = ref(false)
|
|
const keyword = ref('')
|
|
const categoryFilter = ref<number | undefined>()
|
|
const statusFilter = ref<string | undefined>()
|
|
const audienceFilter = ref<string | undefined>()
|
|
const currentPage = ref(1)
|
|
const pageSize = ref(50)
|
|
|
|
const modalVisible = ref(false)
|
|
const modalLoading = ref(false)
|
|
const editingId = ref<number | undefined>()
|
|
const contentTab = ref('edit')
|
|
const formRef = ref<FormInstance>()
|
|
|
|
const formState = reactive({
|
|
categoryId: undefined as number | undefined,
|
|
title: '',
|
|
summary: '',
|
|
content: '',
|
|
audience: 'customer',
|
|
status: 'draft',
|
|
tags: '',
|
|
relatedPath: '',
|
|
relatedLabel: '',
|
|
isPinned: false,
|
|
sortOrder: 0,
|
|
expireTime: undefined as string | undefined,
|
|
})
|
|
|
|
const formRules = {
|
|
categoryId: [{ required: true, message: t('kb.article.form.categoryId') }],
|
|
title: [{ required: true, message: t('kb.article.form.title') }],
|
|
content: [{ required: true, message: t('kb.article.form.content') }],
|
|
}
|
|
|
|
const hotColumns = computed(() => [
|
|
{ key: 'title', label: t('kb.article.col.title'), width: 220 },
|
|
{ key: 'categoryName', label: t('kb.article.col.category'), width: 120 },
|
|
{ key: 'statusText', label: t('kb.article.col.status'), width: 90 },
|
|
{ key: 'audienceText', label: t('kb.article.col.audience'), width: 80 },
|
|
{ key: 'pinnedText', label: t('kb.article.col.pinned'), width: 70 },
|
|
{ key: 'viewCount', label: t('kb.article.col.views'), width: 70 },
|
|
{ key: 'publishTimeText', label: t('kb.article.col.publishTime'), width: 160 },
|
|
])
|
|
|
|
function statusText(status: string) {
|
|
if (status === 'published') return t('kb.article.status.published')
|
|
if (status === 'offline') return t('kb.article.status.offline')
|
|
return t('kb.article.status.draft')
|
|
}
|
|
|
|
function audienceText(audience: string) {
|
|
return audience === 'internal'
|
|
? t('kb.article.audience.internal')
|
|
: t('kb.article.audience.customer')
|
|
}
|
|
|
|
function toRow(item: KbArticle): ArticleRow {
|
|
return {
|
|
...item,
|
|
statusText: statusText(item.status),
|
|
audienceText: audienceText(item.audience),
|
|
pinnedText: item.isPinned ? t('kb.article.yes') : t('kb.article.no'),
|
|
publishTimeText: item.publishTime ? String(item.publishTime).replace('T', ' ').slice(0, 19) : '--',
|
|
}
|
|
}
|
|
|
|
function actionRenderer(row: ArticleRow, _rowIndex: number) {
|
|
const buttons: string[] = []
|
|
if (canEdit.value) {
|
|
buttons.push(renderWarehouseActionBtn('edit', t('common.edit')))
|
|
}
|
|
if (canPublish.value) {
|
|
if (row.status !== 'published') {
|
|
buttons.push(renderWarehouseActionBtn('publish', t('kb.article.publish')))
|
|
} else {
|
|
buttons.push(renderWarehouseActionBtn('offline', t('kb.article.offline'), 'end'))
|
|
}
|
|
buttons.push(
|
|
renderWarehouseActionBtn(
|
|
'pin',
|
|
row.isPinned ? t('kb.article.pinOff') : t('kb.article.pinOn'),
|
|
'star',
|
|
),
|
|
)
|
|
}
|
|
if (canEdit.value) {
|
|
buttons.push(renderWarehouseActionBtn('delete', t('common.delete')))
|
|
}
|
|
return wrapWarehouseActions(buttons)
|
|
}
|
|
|
|
function handleActionClick(row: ArticleRow, _rowIndex: number, action?: string) {
|
|
if (!row) return
|
|
if (action === 'edit') void openModal(row)
|
|
if (action === 'publish') confirmPublish(row)
|
|
if (action === 'offline') confirmOffline(row)
|
|
if (action === 'pin') void togglePin(row)
|
|
if (action === 'delete') confirmDelete(row)
|
|
}
|
|
|
|
function handleSearch() {
|
|
currentPage.value = 1
|
|
void loadList()
|
|
}
|
|
|
|
async function loadCategories() {
|
|
categories.value = await adminListCategories()
|
|
}
|
|
|
|
async function loadList() {
|
|
listLoading.value = true
|
|
try {
|
|
const res = await adminPageArticles({
|
|
page: currentPage.value,
|
|
pageSize: pageSize.value,
|
|
keyword: keyword.value.trim() || undefined,
|
|
categoryId: categoryFilter.value,
|
|
status: statusFilter.value,
|
|
audience: audienceFilter.value,
|
|
})
|
|
tableRows.value = res.items.map(toRow)
|
|
totalCount.value = res.total
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('help.loadFailed'))
|
|
} finally {
|
|
listLoading.value = false
|
|
}
|
|
}
|
|
|
|
function resetForm() {
|
|
formState.categoryId = undefined
|
|
formState.title = ''
|
|
formState.summary = ''
|
|
formState.content = ''
|
|
formState.audience = 'customer'
|
|
formState.status = 'draft'
|
|
formState.tags = ''
|
|
formState.relatedPath = ''
|
|
formState.relatedLabel = ''
|
|
formState.isPinned = false
|
|
formState.sortOrder = 0
|
|
formState.expireTime = undefined
|
|
contentTab.value = 'edit'
|
|
}
|
|
|
|
async function openModal(row?: KbArticle) {
|
|
resetForm()
|
|
editingId.value = row?.id
|
|
modalVisible.value = true
|
|
if (row?.id) {
|
|
try {
|
|
const detail = await adminGetArticle(row.id)
|
|
formState.categoryId = detail.categoryId
|
|
formState.title = detail.title
|
|
formState.summary = detail.summary || ''
|
|
formState.content = detail.content || ''
|
|
formState.audience = detail.audience || 'customer'
|
|
formState.status = detail.status || 'draft'
|
|
formState.tags = detail.tags || ''
|
|
formState.relatedPath = detail.relatedPath || ''
|
|
formState.relatedLabel = detail.relatedLabel || ''
|
|
formState.isPinned = detail.isPinned
|
|
formState.sortOrder = detail.sortOrder
|
|
formState.expireTime = detail.expireTime
|
|
? String(detail.expireTime).replace('T', ' ').slice(0, 19)
|
|
: undefined
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('help.loadFailed'))
|
|
modalVisible.value = false
|
|
}
|
|
}
|
|
}
|
|
|
|
function handleModalCancel() {
|
|
modalVisible.value = false
|
|
editingId.value = undefined
|
|
}
|
|
|
|
async function handleModalOk() {
|
|
try {
|
|
await formRef.value?.validate()
|
|
} catch {
|
|
return false
|
|
}
|
|
if (!formState.categoryId) {
|
|
Message.warning(t('kb.article.form.categoryId'))
|
|
return false
|
|
}
|
|
modalLoading.value = true
|
|
try {
|
|
await adminSaveArticle({
|
|
id: editingId.value,
|
|
categoryId: formState.categoryId,
|
|
title: formState.title.trim(),
|
|
summary: formState.summary.trim() || undefined,
|
|
content: formState.content,
|
|
audience: formState.audience,
|
|
status: formState.status,
|
|
tags: formState.tags.trim() || undefined,
|
|
relatedPath: formState.relatedPath.trim() || undefined,
|
|
relatedLabel: formState.relatedLabel.trim() || undefined,
|
|
isPinned: formState.isPinned,
|
|
sortOrder: formState.sortOrder,
|
|
expireTime: formState.expireTime || undefined,
|
|
})
|
|
Message.success(t('common.saveSuccess'))
|
|
modalVisible.value = false
|
|
editingId.value = undefined
|
|
await loadList()
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('common.saveFailed'))
|
|
return false
|
|
} finally {
|
|
modalLoading.value = false
|
|
}
|
|
}
|
|
|
|
function confirmPublish(row: KbArticle) {
|
|
Modal.confirm({
|
|
title: t('kb.article.publish'),
|
|
content: t('kb.article.publishConfirm', { title: row.title }),
|
|
onOk: async () => {
|
|
try {
|
|
await adminPublishArticle(row.id)
|
|
Message.success(t('common.saveSuccess'))
|
|
await loadList()
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('common.saveFailed'))
|
|
}
|
|
},
|
|
})
|
|
}
|
|
|
|
function confirmOffline(row: KbArticle) {
|
|
Modal.confirm({
|
|
title: t('kb.article.offline'),
|
|
content: t('kb.article.offlineConfirm', { title: row.title }),
|
|
onOk: async () => {
|
|
try {
|
|
await adminOfflineArticle(row.id)
|
|
Message.success(t('common.saveSuccess'))
|
|
await loadList()
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('common.saveFailed'))
|
|
}
|
|
},
|
|
})
|
|
}
|
|
|
|
async function togglePin(row: KbArticle) {
|
|
try {
|
|
await adminPinArticle(row.id, !row.isPinned)
|
|
Message.success(t('common.saveSuccess'))
|
|
await loadList()
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('common.saveFailed'))
|
|
}
|
|
}
|
|
|
|
function confirmDelete(row: KbArticle) {
|
|
Modal.confirm({
|
|
title: t('common.delete'),
|
|
content: t('kb.article.deleteConfirm', { title: row.title }),
|
|
onOk: async () => {
|
|
try {
|
|
await adminDeleteArticle(row.id)
|
|
Message.success(t('common.deleteSuccess'))
|
|
await loadList()
|
|
} catch (e: any) {
|
|
Message.error(e?.message || t('common.saveFailed'))
|
|
}
|
|
},
|
|
})
|
|
}
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
await loadCategories()
|
|
} catch {
|
|
// ignore
|
|
}
|
|
await loadList()
|
|
})
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
@import '@/views/marketing/styles/admin-shared.less';
|
|
|
|
.kb-article-form {
|
|
:deep(.arco-form-item) {
|
|
margin-bottom: 14px;
|
|
}
|
|
}
|
|
|
|
.kb-preview {
|
|
min-height: 220px;
|
|
max-height: 360px;
|
|
overflow: auto;
|
|
padding: 12px;
|
|
border: 1px solid var(--color-border-2);
|
|
border-radius: 6px;
|
|
background: var(--color-fill-1, #f7f8fa);
|
|
}
|
|
</style>
|