feat: 文档分页优化
This commit is contained in:
parent
745a01cc58
commit
9c36a7202d
@ -46,6 +46,9 @@ import { ref, nextTick, watch, computed, onMounted } from 'vue'
|
|||||||
import { MsgError } from '@/utils/message'
|
import { MsgError } from '@/utils/message'
|
||||||
defineOptions({ name: 'AppTable' })
|
defineOptions({ name: 'AppTable' })
|
||||||
|
|
||||||
|
import useStore from '@/stores'
|
||||||
|
const { common } = useStore()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
paginationConfig: {
|
paginationConfig: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@ -66,7 +69,8 @@ const props = defineProps({
|
|||||||
quickCreateMaxlength: {
|
quickCreateMaxlength: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: () => 0
|
default: () => 0
|
||||||
}
|
},
|
||||||
|
storeKey: String
|
||||||
})
|
})
|
||||||
const emit = defineEmits(['changePage', 'sizeChange', 'creatQuick'])
|
const emit = defineEmits(['changePage', 'sizeChange', 'creatQuick'])
|
||||||
|
|
||||||
@ -109,9 +113,15 @@ function quickCreateHandel() {
|
|||||||
|
|
||||||
function handleSizeChange() {
|
function handleSizeChange() {
|
||||||
emit('sizeChange')
|
emit('sizeChange')
|
||||||
|
if (props.storeKey) {
|
||||||
|
common.savePage(props.storeKey, props.paginationConfig)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function handleCurrentChange() {
|
function handleCurrentChange() {
|
||||||
emit('changePage')
|
emit('changePage')
|
||||||
|
if (props.storeKey) {
|
||||||
|
common.savePage(props.storeKey, props.paginationConfig)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defineExpose({})
|
defineExpose({})
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { pageRequest } from '@/api/type/common'
|
|
||||||
|
|
||||||
export interface commonTypes {
|
export interface commonTypes {
|
||||||
breadcrumb: any
|
breadcrumb: any
|
||||||
@ -12,14 +11,14 @@ const useCommonStore = defineStore({
|
|||||||
state: (): commonTypes => ({
|
state: (): commonTypes => ({
|
||||||
breadcrumb: null,
|
breadcrumb: null,
|
||||||
// 搜索和分页缓存
|
// 搜索和分页缓存
|
||||||
paginationConfig: null,
|
paginationConfig: {},
|
||||||
search: null
|
search: {}
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
saveBreadcrumb(data: any) {
|
saveBreadcrumb(data: any) {
|
||||||
this.breadcrumb = data
|
this.breadcrumb = data
|
||||||
},
|
},
|
||||||
savePage(val: string, data: pageRequest) {
|
savePage(val: string, data: any) {
|
||||||
this.paginationConfig[val] = data
|
this.paginationConfig[val] = data
|
||||||
},
|
},
|
||||||
saveCondition(val: string, data: any) {
|
saveCondition(val: string, data: any) {
|
||||||
|
|||||||
@ -48,6 +48,7 @@
|
|||||||
@selection-change="handleSelectionChange"
|
@selection-change="handleSelectionChange"
|
||||||
v-loading="loading"
|
v-loading="loading"
|
||||||
:row-key="(row: any) => row.id"
|
:row-key="(row: any) => row.id"
|
||||||
|
:storeKey="storeKey"
|
||||||
>
|
>
|
||||||
<el-table-column type="selection" width="55" :reserve-selection="true" />
|
<el-table-column type="selection" width="55" :reserve-selection="true" />
|
||||||
<el-table-column prop="name" label="文件名称" min-width="280">
|
<el-table-column prop="name" label="文件名称" min-width="280">
|
||||||
@ -156,8 +157,8 @@
|
|||||||
</LayoutContainer>
|
</LayoutContainer>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, reactive, onBeforeUnmount } from 'vue'
|
import { ref, onMounted, onBeforeUnmount, computed } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router'
|
||||||
import { ElTable } from 'element-plus'
|
import { ElTable } from 'element-plus'
|
||||||
import documentApi from '@/api/document'
|
import documentApi from '@/api/document'
|
||||||
import ImportDocumentDialog from './component/ImportDocumentDialog.vue'
|
import ImportDocumentDialog from './component/ImportDocumentDialog.vue'
|
||||||
@ -172,7 +173,24 @@ const {
|
|||||||
params: { id } // id为datasetID
|
params: { id } // id为datasetID
|
||||||
} = route as any
|
} = route as any
|
||||||
|
|
||||||
const { dataset, document } = useStore()
|
const { common, dataset, document } = useStore()
|
||||||
|
|
||||||
|
const storeKey = 'documents'
|
||||||
|
|
||||||
|
onBeforeRouteUpdate((to: any, from: any) => {
|
||||||
|
common.savePage(storeKey, null)
|
||||||
|
common.saveCondition(storeKey, null)
|
||||||
|
})
|
||||||
|
onBeforeRouteLeave((to: any, from: any) => {
|
||||||
|
if (to.name !== 'Paragraph') {
|
||||||
|
common.savePage(storeKey, null)
|
||||||
|
common.saveCondition(storeKey, null)
|
||||||
|
} else {
|
||||||
|
common.saveCondition(storeKey, filterText.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const beforePagination = computed(() => common.paginationConfig[storeKey])
|
||||||
|
const beforeSearch = computed(() => common.search[storeKey])
|
||||||
|
|
||||||
const SyncWebDialogRef = ref()
|
const SyncWebDialogRef = ref()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@ -182,7 +200,7 @@ const documentData = ref<any[]>([])
|
|||||||
const currentMouseId = ref(null)
|
const currentMouseId = ref(null)
|
||||||
const datasetDetail = ref<any>({})
|
const datasetDetail = ref<any>({})
|
||||||
|
|
||||||
const paginationConfig = reactive({
|
const paginationConfig = ref({
|
||||||
current_page: 1,
|
current_page: 1,
|
||||||
page_size: 10,
|
page_size: 10,
|
||||||
total: 0
|
total: 0
|
||||||
@ -355,7 +373,7 @@ function cellMouseLeave() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleSizeChange() {
|
function handleSizeChange() {
|
||||||
paginationConfig.current_page = 1
|
paginationConfig.value.current_page = 1
|
||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,13 +381,13 @@ function getList(bool?: boolean) {
|
|||||||
documentApi
|
documentApi
|
||||||
.getDocument(
|
.getDocument(
|
||||||
id as string,
|
id as string,
|
||||||
paginationConfig,
|
paginationConfig.value,
|
||||||
filterText.value && { name: filterText.value },
|
filterText.value && { name: filterText.value },
|
||||||
bool ? undefined : loading
|
bool ? undefined : loading
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
documentData.value = res.data.records
|
documentData.value = res.data.records
|
||||||
paginationConfig.total = res.data.total
|
paginationConfig.value.total = res.data.total
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,12 +398,18 @@ function getDetail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
paginationConfig.current_page = 1
|
paginationConfig.value.current_page = 1
|
||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getDetail()
|
getDetail()
|
||||||
|
if (beforePagination.value) {
|
||||||
|
paginationConfig.value = beforePagination.value
|
||||||
|
}
|
||||||
|
if (beforeSearch.value) {
|
||||||
|
filterText.value = beforeSearch.value
|
||||||
|
}
|
||||||
getList()
|
getList()
|
||||||
// 初始化定时任务
|
// 初始化定时任务
|
||||||
initInterval()
|
initInterval()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user