mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-19 01:36:38 +08:00
feat: 210 AI对话页面文件列表增加分页功能
This commit is contained in:
parent
fe7fa46a0c
commit
67f508c7da
@ -66,7 +66,8 @@ html, body {
|
|||||||
margin 0;
|
margin 0;
|
||||||
|
|
||||||
.el-dialog__body {
|
.el-dialog__body {
|
||||||
max-height 90vh
|
max-height 80vh
|
||||||
|
overflow-y auto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,64 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-container class="file-select-box">
|
<el-container class="file-select-box">
|
||||||
<a class="file-upload-img" @click="fetchFiles">
|
<a class="file-upload-img" @click="fetchFiles(1)">
|
||||||
<i class="iconfont icon-attachment-st"></i>
|
<i class="iconfont icon-attachment-st"></i>
|
||||||
</a>
|
</a>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
|
class="file-list-dialog"
|
||||||
v-model="show"
|
v-model="show"
|
||||||
:close-on-click-modal="true"
|
:close-on-click-modal="true"
|
||||||
:show-close="true"
|
:show-close="true"
|
||||||
:width="800"
|
:width="800"
|
||||||
title="文件管理"
|
title="文件管理"
|
||||||
>
|
>
|
||||||
|
<el-scrollbar ref="scrollbarRef" max-height="80vh" style="height: 100%;" @scroll="onScroll">
|
||||||
<div class="file-list">
|
<div class="file-list">
|
||||||
<el-row :gutter="20">
|
<el-row :gutter="20">
|
||||||
<el-col :span="3">
|
<el-col :span="3">
|
||||||
<div class="grid-content">
|
<div class="grid-content">
|
||||||
<el-upload
|
<el-upload
|
||||||
class="avatar-uploader"
|
class="avatar-uploader"
|
||||||
:auto-upload="true"
|
:auto-upload="true"
|
||||||
:show-file-list="false"
|
:show-file-list="false"
|
||||||
:http-request="afterRead"
|
:http-request="afterRead"
|
||||||
accept=".doc,.docx,.jpg,.png,.jpeg,.xls,.xlsx,.ppt,.pptx,.pdf,.mp4,.mp3"
|
accept=".doc,.docx,.jpg,.png,.jpeg,.xls,.xlsx,.ppt,.pptx,.pdf,.mp4,.mp3"
|
||||||
>
|
>
|
||||||
<el-icon class="avatar-uploader-icon">
|
<el-icon class="avatar-uploader-icon">
|
||||||
<Plus/>
|
<Plus/>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</div>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="3" v-for="file in fileList" :key="file.url">
|
|
||||||
<div class="grid-content">
|
|
||||||
<el-tooltip
|
|
||||||
class="box-item"
|
|
||||||
effect="dark"
|
|
||||||
:content="file.name"
|
|
||||||
placement="top">
|
|
||||||
<el-image :src="file.url" fit="cover" v-if="isImage(file.ext)" @click="insertURL(file)"/>
|
|
||||||
<el-image :src="GetFileIcon(file.ext)" fit="cover" v-else @click="insertURL(file)"/>
|
|
||||||
</el-tooltip>
|
|
||||||
|
|
||||||
<div class="opt">
|
|
||||||
<el-button type="danger" size="small" :icon="Delete" @click="removeFile(file)" circle/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</el-col>
|
||||||
</el-col>
|
<el-col :span="3" v-for="file in fileData.items" :key="file.url">
|
||||||
</el-row>
|
<div class="grid-content">
|
||||||
</div>
|
<el-tooltip
|
||||||
|
class="box-item"
|
||||||
|
effect="dark"
|
||||||
|
:content="file.name"
|
||||||
|
placement="top">
|
||||||
|
<el-image :src="file.url" fit="cover" v-if="isImage(file.ext)" @click="insertURL(file)"/>
|
||||||
|
<el-image :src="GetFileIcon(file.ext)" fit="cover" v-else @click="insertURL(file)"/>
|
||||||
|
</el-tooltip>
|
||||||
|
|
||||||
|
<div class="opt">
|
||||||
|
<el-button type="danger" size="small" :icon="Delete" @click="removeFile(file)" circle/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<el-row justify="center" v-if="!fileData.isLastPage" @click="fetchFiles(fileData.page)">
|
||||||
|
<el-link>加载更多</el-link>
|
||||||
|
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
|
</el-scrollbar>
|
||||||
|
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</el-container>
|
</el-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {ref} from "vue";
|
import {reactive, ref} from "vue";
|
||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
import {httpGet, httpPost} from "@/utils/http";
|
import {httpGet, httpPost} from "@/utils/http";
|
||||||
import {Delete, Plus} from "@element-plus/icons-vue";
|
import {Delete, Plus} from "@element-plus/icons-vue";
|
||||||
@ -64,15 +71,45 @@ const props = defineProps({
|
|||||||
const emits = defineEmits(['selected']);
|
const emits = defineEmits(['selected']);
|
||||||
const show = ref(false)
|
const show = ref(false)
|
||||||
const fileList = ref([])
|
const fileList = ref([])
|
||||||
|
const scrollbarRef = ref(null)
|
||||||
|
const fileData = reactive({
|
||||||
|
items:[],
|
||||||
|
page: 1,
|
||||||
|
isLastPage: true,
|
||||||
|
})
|
||||||
|
|
||||||
const fetchFiles = () => {
|
const fetchFiles = (pageNo) => {
|
||||||
show.value = true
|
if(pageNo === 1) show.value = true
|
||||||
httpPost("/api/upload/list").then(res => {
|
httpPost("/api/upload/list", { page: pageNo || 1, page_size: 30 }).then(res => {
|
||||||
fileList.value = res.data
|
const { items, page, total_page } = res.data
|
||||||
|
|
||||||
|
if(page === 1){
|
||||||
|
fileData.items = items
|
||||||
|
}else{
|
||||||
|
fileData.items = [...fileData.items, ...items]
|
||||||
|
}
|
||||||
|
|
||||||
|
fileData.isLastPage = (page === total_page)
|
||||||
|
|
||||||
|
if(!fileData.isLastPage){
|
||||||
|
fileData.page = page + 1
|
||||||
|
}
|
||||||
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// el-scrollbar 滚动回调
|
||||||
|
const onScroll = (options) => {
|
||||||
|
const wrapRef = scrollbarRef.value.wrapRef
|
||||||
|
scrollbarRef.value.moveY = wrapRef.scrollTop * 100 / wrapRef.clientHeight
|
||||||
|
scrollbarRef.value.moveX = wrapRef.scrollLeft * 100 / wrapRef.clientWidth
|
||||||
|
const poor = wrapRef.scrollHeight - wrapRef.clientHeight
|
||||||
|
// 判断滚动到底部 自动加载数据
|
||||||
|
if (options.scrollTop + 2 >= poor && !fileData.isLastPage) {
|
||||||
|
fetchFiles(fileData.page)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const afterRead = (file) => {
|
const afterRead = (file) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@ -120,9 +157,10 @@ const insertURL = (file) => {
|
|||||||
|
|
||||||
.el-dialog__body {
|
.el-dialog__body {
|
||||||
//padding 0
|
//padding 0
|
||||||
|
overflow hidden
|
||||||
|
|
||||||
.file-list {
|
.file-list {
|
||||||
|
margin-right 10px
|
||||||
.grid-content {
|
.grid-content {
|
||||||
margin-bottom 10px
|
margin-bottom 10px
|
||||||
position relative
|
position relative
|
||||||
|
Loading…
Reference in New Issue
Block a user