2023-11-10 11:05:52 +00:00
|
|
|
|
<template>
|
2023-11-13 11:02:13 +00:00
|
|
|
|
<LayoutContainer :header="documentDetail?.name" back-to="-1" class="document-detail">
|
2023-11-10 11:05:52 +00:00
|
|
|
|
<template #header>
|
2023-11-13 11:02:13 +00:00
|
|
|
|
<div class="document-detail__header">
|
|
|
|
|
|
<el-button @click="addParagraph" type="primary" :disabled="loading"> 添加分段 </el-button>
|
|
|
|
|
|
</div>
|
2023-11-10 11:05:52 +00:00
|
|
|
|
</template>
|
2023-12-07 07:22:07 +00:00
|
|
|
|
<div class="document-detail__main p-16" v-loading="pageConfig.current_page === 1 && loading">
|
2023-11-13 11:02:13 +00:00
|
|
|
|
<div class="flex-between p-8">
|
2023-12-06 09:30:46 +00:00
|
|
|
|
<span>{{ pageConfig.total }} 段落</span>
|
2023-11-13 11:02:13 +00:00
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="search"
|
|
|
|
|
|
placeholder="搜索"
|
|
|
|
|
|
class="input-with-select"
|
|
|
|
|
|
style="width: 260px"
|
2023-12-06 09:30:46 +00:00
|
|
|
|
@change="searchHandle"
|
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">
|
|
|
|
|
|
<el-option label="标题" value="title" />
|
|
|
|
|
|
<el-option label="内容" value="content" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-scrollbar>
|
2023-12-07 07:22:07 +00:00
|
|
|
|
<div class="document-detail-height">
|
2023-12-06 09:30:46 +00:00
|
|
|
|
<el-empty v-if="paragraphDetail.length == 0" description="暂无数据" />
|
2023-12-06 11:09:54 +00:00
|
|
|
|
<el-row v-else v-infinite-scroll="loadDataset" :infinite-scroll-disabled="disabledScroll">
|
2023-11-13 11:02:13 +00:00
|
|
|
|
<el-col
|
|
|
|
|
|
:xs="24"
|
|
|
|
|
|
:sm="12"
|
|
|
|
|
|
:md="8"
|
|
|
|
|
|
:lg="6"
|
2023-12-06 02:39:35 +00:00
|
|
|
|
:xl="6"
|
2023-11-13 11:02:13 +00:00
|
|
|
|
v-for="(item, index) in paragraphDetail"
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
class="p-8"
|
|
|
|
|
|
>
|
|
|
|
|
|
<CardBox
|
|
|
|
|
|
shadow="hover"
|
2023-12-06 09:30:46 +00:00
|
|
|
|
:title="item.title || '-'"
|
2023-11-13 11:02:13 +00:00
|
|
|
|
:description="item.content"
|
|
|
|
|
|
class="document-card cursor"
|
|
|
|
|
|
:class="item.is_active ? '' : 'disabled'"
|
|
|
|
|
|
:showIcon="false"
|
|
|
|
|
|
@click="editParagraph(item)"
|
|
|
|
|
|
>
|
2023-11-21 07:22:10 +00:00
|
|
|
|
<div class="active-button" @click.stop>
|
2023-12-05 11:21:13 +00:00
|
|
|
|
<el-switch
|
|
|
|
|
|
v-model="item.is_active"
|
|
|
|
|
|
@change="changeState($event, item)"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
/>
|
2023-11-13 11:02:13 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div class="footer-content flex-between">
|
|
|
|
|
|
<span> {{ numberFormat(item?.content.length) || 0 }} 个 字符 </span>
|
|
|
|
|
|
<el-tooltip effect="dark" content="删除" placement="top">
|
|
|
|
|
|
<el-button text @click.stop="deleteParagraph(item)" class="delete-button">
|
|
|
|
|
|
<el-icon><Delete /></el-icon>
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</CardBox>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
2023-12-06 09:30:46 +00:00
|
|
|
|
<div style="padding: 16px 10px">
|
|
|
|
|
|
<el-divider v-if="paragraphDetail.length > 0 && loading">
|
|
|
|
|
|
<el-text type="info"> 加载中...</el-text>
|
|
|
|
|
|
</el-divider>
|
|
|
|
|
|
<el-divider v-if="noMore">
|
|
|
|
|
|
<el-text type="info"> 到底啦!</el-text>
|
|
|
|
|
|
</el-divider>
|
|
|
|
|
|
</div>
|
2023-11-13 11:02:13 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-scrollbar>
|
2023-11-10 11:05:52 +00:00
|
|
|
|
</div>
|
2023-11-14 10:12:55 +00:00
|
|
|
|
<ParagraphDialog ref="ParagraphDialogRef" :title="title" @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 { numberFormat } from '@/utils/utils'
|
|
|
|
|
|
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
2023-11-14 10:12:55 +00:00
|
|
|
|
import useStore from '@/stores'
|
|
|
|
|
|
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
|
|
|
|
|
|
|
2023-11-13 11:02:13 +00:00
|
|
|
|
const ParagraphDialogRef = ref()
|
2023-11-10 11:05:52 +00:00
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
2023-12-06 09:30:46 +00:00
|
|
|
|
const pageConfig = reactive({
|
|
|
|
|
|
current_page: 1,
|
|
|
|
|
|
page_size: 20,
|
|
|
|
|
|
total: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const noMore = computed(
|
2023-12-06 11:09:54 +00:00
|
|
|
|
() =>
|
|
|
|
|
|
paragraphDetail.value.length > 0 &&
|
|
|
|
|
|
paragraphDetail.value.length === pageConfig.total &&
|
2023-12-07 07:22:07 +00:00
|
|
|
|
pageConfig.total > 20 &&
|
|
|
|
|
|
!loading.value
|
2023-12-06 09:30:46 +00:00
|
|
|
|
)
|
2023-12-06 11:09:54 +00:00
|
|
|
|
const disabledScroll = computed(
|
2023-12-06 09:30:46 +00:00
|
|
|
|
() => paragraphDetail.value.length > 0 && (loading.value || noMore.value)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
function loadDataset() {
|
2023-12-06 11:09:54 +00:00
|
|
|
|
if (pageConfig.total > pageConfig.page_size) {
|
|
|
|
|
|
pageConfig.current_page += 1
|
|
|
|
|
|
getParagraphList()
|
|
|
|
|
|
}
|
2023-12-06 09:30:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function searchHandle() {
|
|
|
|
|
|
pageConfig.current_page = 1
|
|
|
|
|
|
paragraphDetail.value = []
|
|
|
|
|
|
getParagraphList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-13 11:02:13 +00:00
|
|
|
|
function changeState(bool: Boolean, row: any) {
|
|
|
|
|
|
const obj = {
|
|
|
|
|
|
is_active: bool
|
|
|
|
|
|
}
|
|
|
|
|
|
loading.value = true
|
2023-11-14 10:12:55 +00:00
|
|
|
|
paragraph
|
2023-11-24 11:02:52 +00:00
|
|
|
|
.asyncPutParagraph(id, documentId, row.id, obj)
|
2023-11-13 11:02:13 +00:00
|
|
|
|
.then((res) => {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function deleteParagraph(row: any) {
|
2023-12-06 09:30:46 +00:00
|
|
|
|
MsgConfirm(`是否删除段落:${row.title || '-'} ?`, `删除后无法恢复,请谨慎操作。`, {
|
2023-11-13 11:02:13 +00:00
|
|
|
|
confirmButtonText: '删除',
|
|
|
|
|
|
confirmButtonClass: 'danger'
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(() => {
|
2023-12-07 07:22:07 +00:00
|
|
|
|
paragraphApi.delParagraph(id, documentId, row.id, loading).then(() => {
|
|
|
|
|
|
const index = paragraphDetail.value.findIndex((v) => v.id === row.id)
|
|
|
|
|
|
paragraphDetail.value.splice(index, 1)
|
|
|
|
|
|
MsgSuccess('删除成功')
|
|
|
|
|
|
})
|
2023-11-13 11:02:13 +00:00
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addParagraph() {
|
|
|
|
|
|
title.value = '添加分段'
|
|
|
|
|
|
ParagraphDialogRef.value.open()
|
|
|
|
|
|
}
|
2023-11-14 10:12:55 +00:00
|
|
|
|
function editParagraph(row: any) {
|
2023-11-13 11:02:13 +00:00
|
|
|
|
title.value = '分段详情'
|
|
|
|
|
|
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,
|
|
|
|
|
|
pageConfig,
|
|
|
|
|
|
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]
|
|
|
|
|
|
pageConfig.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 {
|
|
|
|
|
|
pageConfig.current_page = 1
|
|
|
|
|
|
paragraphDetail.value = []
|
|
|
|
|
|
getParagraphList()
|
|
|
|
|
|
}
|
2023-11-14 10:12:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
&__header {
|
|
|
|
|
|
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);
|
|
|
|
|
|
&: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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
:deep(.description) {
|
|
|
|
|
|
-webkit-line-clamp: 5 !important;
|
|
|
|
|
|
height: 110px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.active-button {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
right: 16px;
|
|
|
|
|
|
top: 16px;
|
|
|
|
|
|
}
|
2023-11-10 11:05:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|