Skip to content

Commit 9c36a72

Browse files
feat: 文档分页优化
1 parent 745a01c commit 9c36a72

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

ui/src/components/app-table/index.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ import { ref, nextTick, watch, computed, onMounted } from 'vue'
4646
import { MsgError } from '@/utils/message'
4747
defineOptions({ name: 'AppTable' })
4848
49+
import useStore from '@/stores'
50+
const { common } = useStore()
51+
4952
const props = defineProps({
5053
paginationConfig: {
5154
type: Object,
@@ -66,7 +69,8 @@ const props = defineProps({
6669
quickCreateMaxlength: {
6770
type: Number,
6871
default: () => 0
69-
}
72+
},
73+
storeKey: String
7074
})
7175
const emit = defineEmits(['changePage', 'sizeChange', 'creatQuick'])
7276
@@ -109,9 +113,15 @@ function quickCreateHandel() {
109113
110114
function handleSizeChange() {
111115
emit('sizeChange')
116+
if (props.storeKey) {
117+
common.savePage(props.storeKey, props.paginationConfig)
118+
}
112119
}
113120
function handleCurrentChange() {
114121
emit('changePage')
122+
if (props.storeKey) {
123+
common.savePage(props.storeKey, props.paginationConfig)
124+
}
115125
}
116126
defineExpose({})
117127

ui/src/stores/modules/common.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { defineStore } from 'pinia'
2-
import type { pageRequest } from '@/api/type/common'
32

43
export interface commonTypes {
54
breadcrumb: any
@@ -12,14 +11,14 @@ const useCommonStore = defineStore({
1211
state: (): commonTypes => ({
1312
breadcrumb: null,
1413
// 搜索和分页缓存
15-
paginationConfig: null,
16-
search: null
14+
paginationConfig: {},
15+
search: {}
1716
}),
1817
actions: {
1918
saveBreadcrumb(data: any) {
2019
this.breadcrumb = data
2120
},
22-
savePage(val: string, data: pageRequest) {
21+
savePage(val: string, data: any) {
2322
this.paginationConfig[val] = data
2423
},
2524
saveCondition(val: string, data: any) {

ui/src/views/document/index.vue

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
@selection-change="handleSelectionChange"
4949
v-loading="loading"
5050
:row-key="(row: any) => row.id"
51+
:storeKey="storeKey"
5152
>
5253
<el-table-column type="selection" width="55" :reserve-selection="true" />
5354
<el-table-column prop="name" label="文件名称" min-width="280">
@@ -156,8 +157,8 @@
156157
</LayoutContainer>
157158
</template>
158159
<script setup lang="ts">
159-
import { ref, onMounted, reactive, onBeforeUnmount } from 'vue'
160-
import { useRouter, useRoute } from 'vue-router'
160+
import { ref, onMounted, onBeforeUnmount, computed } from 'vue'
161+
import { useRouter, useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router'
161162
import { ElTable } from 'element-plus'
162163
import documentApi from '@/api/document'
163164
import ImportDocumentDialog from './component/ImportDocumentDialog.vue'
@@ -172,7 +173,24 @@ const {
172173
params: { id } // id为datasetID
173174
} = route as any
174175
175-
const { dataset, document } = useStore()
176+
const { common, dataset, document } = useStore()
177+
178+
const storeKey = 'documents'
179+
180+
onBeforeRouteUpdate((to: any, from: any) => {
181+
common.savePage(storeKey, null)
182+
common.saveCondition(storeKey, null)
183+
})
184+
onBeforeRouteLeave((to: any, from: any) => {
185+
if (to.name !== 'Paragraph') {
186+
common.savePage(storeKey, null)
187+
common.saveCondition(storeKey, null)
188+
} else {
189+
common.saveCondition(storeKey, filterText.value)
190+
}
191+
})
192+
const beforePagination = computed(() => common.paginationConfig[storeKey])
193+
const beforeSearch = computed(() => common.search[storeKey])
176194
177195
const SyncWebDialogRef = ref()
178196
const loading = ref(false)
@@ -182,7 +200,7 @@ const documentData = ref<any[]>([])
182200
const currentMouseId = ref(null)
183201
const datasetDetail = ref<any>({})
184202
185-
const paginationConfig = reactive({
203+
const paginationConfig = ref({
186204
current_page: 1,
187205
page_size: 10,
188206
total: 0
@@ -355,21 +373,21 @@ function cellMouseLeave() {
355373
}
356374
357375
function handleSizeChange() {
358-
paginationConfig.current_page = 1
376+
paginationConfig.value.current_page = 1
359377
getList()
360378
}
361379
362380
function getList(bool?: boolean) {
363381
documentApi
364382
.getDocument(
365383
id as string,
366-
paginationConfig,
384+
paginationConfig.value,
367385
filterText.value && { name: filterText.value },
368386
bool ? undefined : loading
369387
)
370388
.then((res) => {
371389
documentData.value = res.data.records
372-
paginationConfig.total = res.data.total
390+
paginationConfig.value.total = res.data.total
373391
})
374392
}
375393
@@ -380,12 +398,18 @@ function getDetail() {
380398
}
381399
382400
function refresh() {
383-
paginationConfig.current_page = 1
401+
paginationConfig.value.current_page = 1
384402
getList()
385403
}
386404
387405
onMounted(() => {
388406
getDetail()
407+
if (beforePagination.value) {
408+
paginationConfig.value = beforePagination.value
409+
}
410+
if (beforeSearch.value) {
411+
filterText.value = beforeSearch.value
412+
}
389413
getList()
390414
// 初始化定时任务
391415
initInterval()

0 commit comments

Comments
 (0)