UnisKB/ui/src/views/paragraph/index.vue

439 lines
14 KiB
Vue
Raw Normal View History

2023-11-10 11:05:52 +00:00
<template>
2024-05-23 10:41:48 +00:00
<LayoutContainer back-to="-1" class="document-detail">
2023-11-10 11:05:52 +00:00
<template #header>
2024-06-13 07:58:36 +00:00
<div style="width: 78%">
2024-05-23 10:41:48 +00:00
<h3 style="display: inline-block">{{ documentDetail?.name }}</h3>
<el-text type="info" v-if="documentDetail?.type === '1'"
2025-01-15 11:10:29 +00:00
>{{ $t('views.document.form.source_url.label') }}<el-link
:href="documentDetail?.meta?.source_url"
target="_blank"
>
2024-06-13 07:58:36 +00:00
<span class="break-all">{{ documentDetail?.meta?.source_url }} </span></el-link
2024-05-23 10:41:48 +00:00
>
</el-text>
</div>
<div class="header-button">
<el-button @click="batchSelectedHandle(true)" v-if="isBatch === false">
2025-01-15 11:10:29 +00:00
{{ $t('views.paragraph.setting.batchSelected') }}
</el-button>
<el-button @click="batchSelectedHandle(false)" v-if="isBatch === true">
2025-01-15 11:10:29 +00:00
{{ $t('views.paragraph.setting.cancelSelected') }}
</el-button>
<el-button
@click="addParagraph"
type="primary"
:disabled="loading"
v-if="isBatch === false"
>
2025-01-15 11:10:29 +00:00
{{ $t('views.paragraph.addParagraph') }}
</el-button>
2023-11-13 11:02:13 +00:00
</div>
2023-11-10 11:05:52 +00:00
</template>
2023-12-11 02:35:26 +00:00
<div
class="document-detail__main p-16"
2024-02-23 08:17:16 +00:00
v-loading="(paginationConfig.current_page === 1 && loading) || changeStateloading"
2023-12-11 02:35:26 +00:00
>
2023-11-13 11:02:13 +00:00
<div class="flex-between p-8">
2025-01-15 11:10:29 +00:00
<span>{{ paginationConfig.total }} {{ $t('views.paragraph.title') }}</span>
2023-11-13 11:02:13 +00:00
<el-input
v-model="search"
2025-01-13 03:15:51 +00:00
:placeholder="$t('common.search')"
2023-11-13 11:02:13 +00:00
class="input-with-select"
style="width: 260px"
2023-12-06 09:30:46 +00:00
@change="searchHandle"
clearable
2023-11-10 11:05:52 +00:00
>
2023-11-13 11:02:13 +00:00
<template #prepend>
<el-select v-model="searchType" placeholder="Select" style="width: 80px">
2025-01-15 11:10:29 +00:00
<el-option :label="$t('views.paragraph.searchBar.title')" value="title" />
<el-option :label="$t('views.paragraph.searchBar.content')" value="content" />
2023-11-13 11:02:13 +00:00
</el-select>
</template>
</el-input>
</div>
<el-scrollbar>
2023-12-07 07:22:07 +00:00
<div class="document-detail-height">
2025-01-15 11:10:29 +00:00
<el-empty v-if="paragraphDetail.length == 0" :description="$t('common.noData')" />
2023-11-13 11:02:13 +00:00
2023-12-11 02:35:26 +00:00
<InfiniteScroll
v-else
:size="paragraphDetail.length"
:total="paginationConfig.total"
:page_size="paginationConfig.page_size"
v-model:current_page="paginationConfig.current_page"
@load="getParagraphList"
:loading="loading"
>
<el-row>
<el-col
:xs="24"
:sm="12"
:md="8"
:lg="6"
:xl="6"
v-for="(item, index) in paragraphDetail"
:key="index"
class="p-8"
>
<!-- 批量操作card -->
<CardBox
v-if="isBatch === true"
shadow="hover"
:title="item.title || '-'"
:description="item.content"
class="document-card cursor"
:class="multipleSelection.includes(item.id) ? 'selected' : ''"
:showIcon="false"
@click="selectHandle(item.id)"
>
<div class="active-button" @click.stop></div>
<template #footer>
<div class="footer-content flex-between">
2025-01-15 11:10:29 +00:00
<span>
{{ numberFormat(item?.content.length) || 0 }}
{{ $t('views.paragraph.character_count') }}
</span>
</div>
</template>
</CardBox>
<!-- 非批量操作card -->
2023-12-11 02:35:26 +00:00
<CardBox
v-else
2023-12-11 02:35:26 +00:00
shadow="hover"
:title="item.title || '-'"
:description="item.content"
class="document-card cursor"
:class="item.is_active ? '' : 'disabled'"
:showIcon="false"
@click="editParagraph(item)"
>
<div class="active-button" @click.stop>
<el-switch
:loading="loading"
2023-12-11 02:35:26 +00:00
v-model="item.is_active"
:before-change="() => changeState(item)"
2023-12-11 02:35:26 +00:00
size="small"
/>
2023-11-13 11:02:13 +00:00
</div>
2023-12-11 02:35:26 +00:00
<template #footer>
<div class="footer-content flex-between">
2025-01-15 11:10:29 +00:00
<span>
{{ numberFormat(item?.content.length) || 0 }}
{{ $t('views.paragraph.character_count') }}
</span>
<span @click.stop>
<el-dropdown trigger="click">
<el-button text>
<el-icon><MoreFilled /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="openGenerateDialog(item)">
<el-icon><Connection /></el-icon>
2025-01-15 11:10:29 +00:00
{{
$t('views.document.setting.generateQuestion')
}}</el-dropdown-item
>
<el-dropdown-item @click="openSelectDocumentDialog(item)">
<AppIcon iconName="app-migrate"></AppIcon>
2025-01-15 11:10:29 +00:00
{{ $t('views.document.setting.migration') }}</el-dropdown-item
>
2025-01-13 03:15:51 +00:00
<el-dropdown-item icon="Delete" @click.stop="deleteParagraph(item)">{{
$t('common.delete')
}}</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</span>
2023-12-11 02:35:26 +00:00
</div>
</template>
</CardBox>
</el-col>
</el-row>
</InfiniteScroll>
2023-11-13 11:02:13 +00:00
</div>
</el-scrollbar>
<div class="mul-operation border-t w-full" v-if="isBatch === true">
<el-button :disabled="multipleSelection.length === 0" @click="openGenerateDialog()">
2025-01-14 11:28:30 +00:00
{{ $t('views.document.setting.generateQuestion') }}
</el-button>
2024-05-09 02:24:38 +00:00
<el-button :disabled="multipleSelection.length === 0" @click="openSelectDocumentDialog()">
2025-01-15 11:10:29 +00:00
{{ $t('views.document.setting.migration') }}
</el-button>
<el-button :disabled="multipleSelection.length === 0" @click="deleteMulParagraph">
2025-01-13 03:15:51 +00:00
{{ $t('common.delete') }}
</el-button>
2025-01-15 11:10:29 +00:00
<span class="ml-8">
{{ $t('views.document.selected') }} {{ multipleSelection.length }}
{{ $t('views.document.items') }}
</span>
</div>
2023-11-10 11:05:52 +00:00
</div>
2023-11-14 10:12:55 +00:00
<ParagraphDialog ref="ParagraphDialogRef" :title="title" @refresh="refresh" />
<SelectDocumentDialog ref="SelectDocumentDialogRef" @refresh="refreshMigrateParagraph" />
<GenerateRelatedDialog ref="GenerateRelatedDialogRef" @refresh="refresh" />
2023-11-10 11:05:52 +00:00
</LayoutContainer>
</template>
<script setup lang="ts">
2023-12-06 09:30:46 +00:00
import { reactive, ref, onMounted, computed } from 'vue'
2023-11-14 10:12:55 +00:00
import { useRoute } from 'vue-router'
2023-11-22 10:37:08 +00:00
import documentApi from '@/api/document'
import paragraphApi from '@/api/paragraph'
2023-11-13 11:02:13 +00:00
import ParagraphDialog from './component/ParagraphDialog.vue'
import SelectDocumentDialog from './component/SelectDocumentDialog.vue'
import GenerateRelatedDialog from '@/components/generate-related-dialog/index.vue'
2023-11-13 11:02:13 +00:00
import { numberFormat } from '@/utils/utils'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
2023-11-14 10:12:55 +00:00
import useStore from '@/stores'
2025-01-15 11:10:29 +00:00
import { t } from '@/locales'
2023-11-14 10:12:55 +00:00
const { paragraph } = useStore()
2023-11-10 11:05:52 +00:00
const route = useRoute()
const {
2023-11-24 11:02:52 +00:00
params: { id, documentId }
2023-11-10 11:05:52 +00:00
} = route as any
const SelectDocumentDialogRef = ref()
2023-11-13 11:02:13 +00:00
const ParagraphDialogRef = ref()
2023-11-10 11:05:52 +00:00
const loading = ref(false)
2024-02-23 08:17:16 +00:00
const changeStateloading = ref(false)
2023-11-10 11:05:52 +00:00
const documentDetail = ref<any>({})
const paragraphDetail = ref<any[]>([])
2023-11-13 11:02:13 +00:00
const title = ref('')
const search = ref('')
const searchType = ref('title')
// 批量操作
const isBatch = ref(false)
const multipleSelection = ref<any[]>([])
2023-12-11 02:35:26 +00:00
const paginationConfig = reactive({
2023-12-06 09:30:46 +00:00
current_page: 1,
2024-12-11 06:13:13 +00:00
page_size: 30,
2023-12-06 09:30:46 +00:00
total: 0
})
function refreshMigrateParagraph() {
paragraphDetail.value = paragraphDetail.value.filter(
(v) => !multipleSelection.value.includes(v.id)
)
multipleSelection.value = []
2025-01-15 11:10:29 +00:00
MsgSuccess(t('views.document.tip.migrationSuccess'))
}
function openSelectDocumentDialog(row?: any) {
if (row) {
multipleSelection.value = [row.id]
}
SelectDocumentDialogRef.value.open(multipleSelection.value)
}
function deleteMulParagraph() {
MsgConfirm(
2025-01-15 11:10:29 +00:00
`${t('views.document.delete.confirmTitle1')} ${multipleSelection.value.length} ${t('views.document.delete.confirmTitle2')}`,
t('views.paragraph.delete.confirmMessage'),
{
2025-01-13 03:15:51 +00:00
confirmButtonText: t('common.delete'),
confirmButtonClass: 'danger'
}
)
.then(() => {
paragraphApi
.delMulParagraph(id, documentId, multipleSelection.value, changeStateloading)
.then(() => {
paragraphDetail.value = paragraphDetail.value.filter(
(v) => !multipleSelection.value.includes(v.id)
)
multipleSelection.value = []
2025-01-15 11:10:29 +00:00
MsgSuccess(t('views.document.delete.successMessage'))
})
})
.catch(() => {})
}
function batchSelectedHandle(bool: boolean) {
isBatch.value = bool
multipleSelection.value = []
}
function selectHandle(id: string) {
if (multipleSelection.value.includes(id)) {
multipleSelection.value.splice(multipleSelection.value.indexOf(id), 1)
} else {
multipleSelection.value.push(id)
}
}
2023-12-06 09:30:46 +00:00
function searchHandle() {
2023-12-11 02:35:26 +00:00
paginationConfig.current_page = 1
2023-12-06 09:30:46 +00:00
paragraphDetail.value = []
getParagraphList()
}
function changeState(row: any) {
2023-11-13 11:02:13 +00:00
const obj = {
is_active: !row.is_active
2023-11-13 11:02:13 +00:00
}
paragraph
.asyncPutParagraph(id, documentId, row.id, obj, changeStateloading)
.then((res) => {
const index = paragraphDetail.value.findIndex((v) => v.id === row.id)
paragraphDetail.value[index].is_active = !paragraphDetail.value[index].is_active
return true
})
.catch(() => {
return false
})
2023-11-13 11:02:13 +00:00
}
function deleteParagraph(row: any) {
2025-01-15 11:10:29 +00:00
MsgConfirm(
`${t('views.paragraph.delete.confirmTitle')} ${row.title || '-'} ?`,
t('views.paragraph.delete.confirmMessage'),
{
confirmButtonText: t('common.delete'),
confirmButtonClass: 'danger'
}
)
2023-11-13 11:02:13 +00:00
.then(() => {
2023-12-15 03:04:10 +00:00
paragraph.asyncDelParagraph(id, documentId, row.id, loading).then(() => {
2023-12-07 07:22:07 +00:00
const index = paragraphDetail.value.findIndex((v) => v.id === row.id)
paragraphDetail.value.splice(index, 1)
2025-01-13 03:15:51 +00:00
MsgSuccess(t('common.deleteSuccess'))
2023-12-07 07:22:07 +00:00
})
2023-11-13 11:02:13 +00:00
})
.catch(() => {})
}
function addParagraph() {
2025-01-15 11:10:29 +00:00
title.value = t('views.paragraph.addParagraph')
2023-11-13 11:02:13 +00:00
ParagraphDialogRef.value.open()
}
2023-11-14 10:12:55 +00:00
function editParagraph(row: any) {
2025-01-15 11:10:29 +00:00
title.value = t('views.paragraph.paragraphDetail')
2023-11-13 11:02:13 +00:00
ParagraphDialogRef.value.open(row)
}
2023-11-10 11:05:52 +00:00
function getDetail() {
loading.value = true
2023-11-22 10:37:08 +00:00
documentApi
2023-11-24 11:02:52 +00:00
.getDocumentDetail(id, documentId)
2023-11-10 11:05:52 +00:00
.then((res) => {
documentDetail.value = res.data
loading.value = false
})
.catch(() => {
loading.value = false
})
}
2023-12-06 09:30:46 +00:00
function getParagraphList() {
2023-11-22 10:37:08 +00:00
paragraphApi
2023-12-06 09:30:46 +00:00
.getParagraph(
id,
documentId,
2023-12-11 02:35:26 +00:00
paginationConfig,
2023-12-06 09:30:46 +00:00
search.value && { [searchType.value]: search.value },
loading
)
2023-11-10 11:05:52 +00:00
.then((res) => {
2023-12-06 09:30:46 +00:00
paragraphDetail.value = [...paragraphDetail.value, ...res.data.records]
2023-12-11 02:35:26 +00:00
paginationConfig.total = res.data.total
2023-11-10 11:05:52 +00:00
})
}
2023-12-07 07:22:07 +00:00
function refresh(data: any) {
if (data) {
const index = paragraphDetail.value.findIndex((v) => v.id === data.id)
paragraphDetail.value.splice(index, 1, data)
} else {
2023-12-11 02:35:26 +00:00
paginationConfig.current_page = 1
2023-12-07 07:22:07 +00:00
paragraphDetail.value = []
getParagraphList()
}
2023-11-14 10:12:55 +00:00
}
const GenerateRelatedDialogRef = ref()
function openGenerateDialog(row?: any) {
const arr: string[] = []
if (row) {
arr.push(row.id)
} else {
multipleSelection.value.map((v) => {
if (v) {
arr.push(v)
}
})
}
GenerateRelatedDialogRef.value.open(arr, 'paragraph')
}
2023-11-10 11:05:52 +00:00
onMounted(() => {
getDetail()
2023-12-06 09:30:46 +00:00
getParagraphList()
2023-11-10 11:05:52 +00:00
})
</script>
<style lang="scss" scoped>
2023-11-13 11:02:13 +00:00
.document-detail {
2024-05-23 10:41:48 +00:00
.header-button {
2023-11-13 11:02:13 +00:00
position: absolute;
right: calc(var(--app-base-px) * 3);
}
.document-detail-height {
height: calc(var(--app-main-height) - 75px);
}
.document-card {
height: 210px;
background: var(--app-layout-bg-color);
border: 1px solid var(--app-layout-bg-color);
&.selected {
background: #ffffff;
&:hover {
background: #ffffff;
}
}
2023-11-13 11:02:13 +00:00
&:hover {
background: #ffffff;
border: 1px solid var(--el-border-color);
}
&.disabled {
background: var(--app-layout-bg-color);
border: 1px solid var(--app-layout-bg-color);
:deep(.description) {
color: var(--app-border-color-dark);
}
:deep(.title) {
color: var(--app-border-color-dark);
}
}
2024-01-24 07:42:12 +00:00
:deep(.content) {
2023-11-13 11:02:13 +00:00
-webkit-line-clamp: 5 !important;
2024-01-24 07:42:12 +00:00
height: 110px !important;
2023-11-13 11:02:13 +00:00
}
.active-button {
position: absolute;
right: 16px;
top: 16px;
}
2023-11-10 11:05:52 +00:00
}
&__main {
position: relative;
box-sizing: border-box;
.mul-operation {
position: absolute;
bottom: 0;
left: 0;
padding: 16px 24px;
box-sizing: border-box;
background: #ffffff;
}
}
2023-11-10 11:05:52 +00:00
}
</style>