11<template >
2- <el-tabs v-model =" activeName" class =" paragraph-tabs" @tab-click = " handleClick " >
2+ <el-tabs v-model =" activeName" class =" paragraph-tabs" >
33 <template v-for =" (item , index ) in newData " :key =" index " >
44 <el-tab-pane :label =" item.name" :name =" index" >
55 <template #label >
88 <span class =" ml-4" >{{ item?.name }}</span >
99 </div >
1010 </template >
11- <el-scrollbar ref =" scrollRef" :key =" index" >
12- <div class =" mb-16" >
13- <el-text type =" info" >{{ item.content.length }} 段落</el-text >
14- </div >
15- <div class =" paragraph-list" v-infinite-scroll =" loadScroll" >
16- <el-card
17- v-for =" (child, cIndex) in scrollData"
18- :key =" cIndex"
19- shadow =" never"
20- class =" card-never mb-16"
21- >
22- <div class =" flex-between" >
23- <span >{{ child.title || '-' }}</span >
24- <div >
25- <!-- 编辑分段按钮 -->
26- <el-button link @click =" editHandle(child, index, cIndex)" >
27- <el-icon ><EditPen /></el-icon >
28- </el-button >
29- <!-- 删除分段按钮 -->
30- <el-button link @click =" deleteHandle(child, index, cIndex)" >
31- <el-icon ><Delete /></el-icon >
32- </el-button >
33- </div >
34- </div >
35- <div class =" lighter mt-12" >
36- {{ child.content }}
37- </div >
38- <div class =" lighter mt-12" >
39- <el-text type =" info" > {{ child.content.length }} 个字符 </el-text >
40- </div >
41- </el-card >
42- </div >
43- </el-scrollbar >
11+ <div class =" mb-16" >
12+ <el-text type =" info" >{{ item.content.length }} 段落</el-text >
13+ </div >
14+ <div class =" paragraph-list" v-if =" activeName == index" >
15+ <el-scrollbar >
16+ <ParagraphList v-model =" item.content" :isConnect =" isConnect" > </ParagraphList >
17+ </el-scrollbar >
18+ </div >
4419 </el-tab-pane >
4520 </template >
4621 </el-tabs >
47- <EditParagraphDialog
48- ref =" EditParagraphDialogRef"
49- @updateContent =" updateContent"
50- :isConnect =" isConnect"
51- />
5222</template >
5323<script setup lang="ts">
54- import { ref , reactive , onMounted , watch , nextTick } from ' vue'
55- import { cloneDeep } from ' lodash'
56- import type { TabsPaneContext } from ' element-plus'
57- import EditParagraphDialog from ' ./EditParagraphDialog.vue'
58- import { filesize , getImgUrl } from ' @/utils/utils'
59- import { MsgConfirm } from ' @/utils/message'
24+ import { ref , onMounted , watch } from ' vue'
25+ import { getImgUrl } from ' @/utils/utils'
26+ import ParagraphList from ' ./ParagraphList.vue'
6027
6128const props = defineProps ({
6229 data: {
@@ -68,80 +35,20 @@ const props = defineProps({
6835
6936const emit = defineEmits ([' update:data' ])
7037
71- const EditParagraphDialogRef = ref ()
72- const scrollRef = ref ()
73-
7438const activeName = ref (0 )
75- const currentPIndex = ref (null ) as any
76- const currentCIndex = ref (null ) as any
7739
7840const newData = ref <any []>([])
7941
80- // 滚动加载数据
81- const paginationConfig = reactive ({
82- current_page: 1 ,
83- page_size: 20
84- })
85-
86- const scrollData = ref <any []>([])
87-
8842watch (
8943 () => props .data ,
9044 (value ) => {
9145 newData .value = value
92- paginationConfig .current_page = 1
93- nextTick (() => {
94- scrollRef .value ?.[activeName .value ]?.scrollTo (0 , 0 )
95- })
96- scrollData .value = newData .value [activeName .value ]?.content .slice (0 , paginationConfig .page_size )
9746 },
9847 {
9948 immediate: true
10049 }
10150)
10251
103- function loadScroll() {
104- if (newData .value [activeName .value ]?.content .length > scrollData .value .length ) {
105- paginationConfig .current_page += 1
106- scrollData .value .push (
107- ... newData .value [activeName .value ].content .slice (
108- (paginationConfig .current_page - 1 ) * paginationConfig .page_size ,
109- paginationConfig .current_page * paginationConfig .page_size
110- )
111- )
112- }
113- }
114-
115- function editHandle(item : any , index : number , cIndex : number ) {
116- currentPIndex .value = index
117- currentCIndex .value = cIndex
118- EditParagraphDialogRef .value .open (item )
119- }
120-
121- function deleteHandle(item : any , index : number , cIndex : number ) {
122- MsgConfirm (` 是否删除分段:${item .title || ' -' } ? ` , ` 删除后将不会存入知识库,对本地文档无影响。 ` , {
123- confirmButtonText: ' 删除' ,
124- confirmButtonClass: ' danger'
125- })
126- .then (() => {
127- newData .value [index ].content .splice (cIndex , 1 )
128- scrollData .value .splice (cIndex , 1 )
129- emit (' update:data' , newData .value )
130- })
131- .catch (() => {})
132- }
133-
134- function updateContent(data : any ) {
135- newData .value [currentPIndex .value ].content [currentCIndex .value ] = cloneDeep (data )
136- scrollData .value [currentCIndex .value ] = cloneDeep (data )
137- emit (' update:data' , newData .value )
138- }
139-
140- const handleClick = (tab : TabsPaneContext , event : Event ) => {
141- paginationConfig .current_page = 1
142- scrollData .value = newData .value [Number (tab .index )]?.content .slice (0 , paginationConfig .page_size )
143- }
144-
14552onMounted (() => {})
14653 </script >
14754<style scoped lang="scss">
@@ -172,6 +79,6 @@ onMounted(() => {})
17279 }
17380}
17481.paragraph-list {
175- height : calc (var (--create-dataset-height ) - 131 px );
82+ height : calc (var (--create-dataset-height ) - 101 px );
17683}
17784 </style >
0 commit comments