UnisKB/ui/src/views/dataset/component/ParagraphPreview.vue

144 lines
4.0 KiB
Vue
Raw Normal View History

2023-11-02 01:56:14 +00:00
<template>
2023-11-14 10:12:55 +00:00
<el-tabs v-model="activeName" class="paragraph-tabs" @tab-click="handleClick">
2023-11-08 11:08:54 +00:00
<template v-for="(item, index) in newData" :key="index">
2023-11-06 11:06:02 +00:00
<el-tab-pane :label="item.name" :name="index">
<template #label>
2023-11-08 11:08:54 +00:00
<div class="flex-center">
<img :src="getImgUrl(item && item?.name)" alt="" height="16" />
2023-11-06 11:06:02 +00:00
<span class="ml-4">{{ item?.name }}</span>
</div>
</template>
<el-scrollbar>
2023-12-05 11:21:13 +00:00
<div class="mb-16">
<el-text type="info">{{ item.content.length }} 段落</el-text>
</div>
2023-11-14 10:12:55 +00:00
<div class="paragraph-list">
2023-11-06 11:06:02 +00:00
<el-card
2023-11-08 11:08:54 +00:00
v-for="(child, cIndex) in item.content"
:key="cIndex"
2023-11-06 11:06:02 +00:00
shadow="never"
class="card-never mb-16"
>
<div class="flex-between">
2023-12-06 09:30:46 +00:00
<span>{{ child.title || '-' }}</span>
2023-11-06 11:06:02 +00:00
<div>
2023-11-08 11:08:54 +00:00
<!-- 编辑分段按钮 -->
<el-button link @click="editHandle(child, index, cIndex)">
2023-11-06 11:06:02 +00:00
<el-icon><Edit /></el-icon>
</el-button>
2023-11-08 11:08:54 +00:00
<!-- 删除分段按钮 -->
<el-button link @click="deleteHandle(child, index, cIndex)">
2023-11-06 11:06:02 +00:00
<el-icon><Delete /></el-icon>
</el-button>
</div>
</div>
<div class="lighter mt-12">
{{ child.content }}
</div>
<div class="lighter mt-12">
<el-text type="info"> {{ child.content.length }} 个字符 </el-text>
</div>
</el-card>
</div>
</el-scrollbar>
</el-tab-pane>
</template>
2023-11-02 01:56:14 +00:00
</el-tabs>
2023-11-14 10:12:55 +00:00
<EditParagraphDialog ref="EditParagraphDialogRef" @updateContent="updateContent" />
2023-11-02 01:56:14 +00:00
</template>
<script setup lang="ts">
2023-11-10 09:18:00 +00:00
import { ref, reactive, onMounted, watch } from 'vue'
2023-11-02 01:56:14 +00:00
import type { TabsPaneContext } from 'element-plus'
2023-11-14 10:12:55 +00:00
import EditParagraphDialog from './EditParagraphDialog.vue'
2023-11-06 11:06:02 +00:00
import { filesize, getImgUrl } from '@/utils/utils'
2023-11-08 11:08:54 +00:00
import { MsgConfirm } from '@/utils/message'
const props = defineProps({
2023-11-06 11:06:02 +00:00
data: {
type: Array<any>,
default: () => []
}
})
2023-11-08 11:08:54 +00:00
const emit = defineEmits(['update:data'])
2023-11-14 10:12:55 +00:00
const EditParagraphDialogRef = ref()
2023-11-08 11:08:54 +00:00
2023-11-06 11:06:02 +00:00
const activeName = ref(0)
2023-11-08 11:08:54 +00:00
const currentPIndex = ref(null) as any
const currentCIndex = ref(null) as any
2023-11-10 09:18:00 +00:00
const newData = ref<any[]>([])
watch(
() => props.data,
(value) => {
newData.value = value
},
{
immediate: true
}
)
2023-11-08 11:08:54 +00:00
function editHandle(item: any, index: number, cIndex: number) {
currentPIndex.value = index
currentCIndex.value = cIndex
2023-11-14 10:12:55 +00:00
EditParagraphDialogRef.value.open(item)
2023-11-08 11:08:54 +00:00
}
function deleteHandle(item: any, index: number, cIndex: number) {
2023-12-18 03:32:29 +00:00
MsgConfirm(`是否删除分段:${item.title || '-'} ?`, `删除后将不会存入知识库,对本地文档无影响。`, {
2023-11-08 11:08:54 +00:00
confirmButtonText: '删除',
confirmButtonClass: 'danger'
})
.then(() => {
newData.value[index].content.splice(cIndex, 1)
emit('update:data', newData.value)
})
.catch(() => {})
}
function updateContent(data: any) {
newData.value[currentPIndex.value].content[currentCIndex.value] = data
emit('update:data', newData.value)
}
2023-11-02 01:56:14 +00:00
const handleClick = (tab: TabsPaneContext, event: Event) => {
2023-11-08 11:08:54 +00:00
// console.log(tab, event)
2023-11-02 01:56:14 +00:00
}
2023-11-10 09:18:00 +00:00
onMounted(() => {})
2023-11-02 01:56:14 +00:00
</script>
<style scoped lang="scss">
2023-11-14 10:12:55 +00:00
.paragraph-tabs {
2023-11-06 11:06:02 +00:00
:deep(.el-tabs__item) {
2023-11-13 11:02:13 +00:00
background: var(--app-text-color-light-1);
2023-11-06 11:06:02 +00:00
margin: 4px;
border-radius: 4px;
padding: 5px 10px 5px 8px !important;
height: auto;
&:nth-child(2) {
margin-left: 0;
}
&:last-child {
margin-right: 0;
}
&.is-active {
border: 1px solid var(--el-color-primary);
background: var(--el-color-primary-light-9);
color: var(--el-text-color-primary);
}
2023-11-02 01:56:14 +00:00
}
2023-11-06 11:06:02 +00:00
:deep(.el-tabs__nav-wrap::after) {
display: none;
}
:deep(.el-tabs__active-bar) {
display: none;
}
}
2023-11-14 10:12:55 +00:00
.paragraph-list {
2023-11-21 07:22:10 +00:00
height: calc(var(--create-dataset-height) - 95px);
2023-11-02 01:56:14 +00:00
}
</style>