Commit 07c44f71 authored by nick zheng's avatar nick zheng

fix: 知识库文件上传达到上限提示用户

parent 9611d68b
......@@ -559,6 +559,7 @@ equity_module:
get_points_for_interacting_with_the_ai: 'Get {points} points for interacting with the AI'
no_time_limit_when_used_up: 'No time limit, when used up'
agents_created_exceeds_tip: 'The number of agents created exceeds the current package benefits, please upgrade the package'
documents_uploaded_exceeds_tip: 'The number of documents uploaded exceeds the current package benefits, please upgrade the package(The remaining {count} can be uploaded)'
order_manage_module:
package_name: 'PackageName'
......
......@@ -557,6 +557,7 @@ equity_module:
get_points_for_interacting_with_the_ai: '获得{points}积分,用于和AI互动行动'
no_time_limit_when_used_up: '无期限,用完即止'
agents_created_exceeds_tip: '创建应用数量超出当前套餐权益,请升级套餐'
documents_uploaded_exceeds_tip: '上传文件超出当前套餐权益,请升级套餐(剩余可上传{count}个)'
order_manage_module:
package_name: '套餐名称'
......
......@@ -557,6 +557,7 @@ equity_module:
get_points_for_interacting_with_the_ai: '獲得{points}積分,用於和AI互動行動'
no_time_limit_when_used_up: '無期限,用完即止'
agents_created_exceeds_tip: '創建應用數量超出當前套餐權益,請升級套餐'
documents_uploaded_exceeds_tip: '上传文件超出当前套餐权益,请升级套餐(剩余可上传{count}个)'
order_manage_module:
package_name: '套餐名稱'
......
<script setup lang="ts">
import { computed, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { UploadFileInfo } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { UploadOne } from '@icon-park/vue-next'
import CustomIcon from '@/components/custom-icon/custom-icon.vue'
import { fetchUploadKnowledgeDocument } from '@/apis/knowledge'
import { useUserStore } from '@/store/modules/user'
interface Emit {
(e: 'next', value: number[]): void
......@@ -29,9 +31,14 @@ interface FileItem {
const { t } = useI18n()
const router = useRouter()
const userStore = useUserStore()
const emit = defineEmits<Emit>()
const uploadFileList = ref<FileItem[]>([])
const isExceedKnowledgeCount = ref(false)
const uploadFileIcon = (type: string) => {
return `https://gsst-poe-sit.gz.bcebos.com/icon/${type}.svg`
......@@ -53,8 +60,49 @@ const uploadFileSize = computed(() => (fileSize: number) => {
return (fileSize / Math.pow(binarySize, unit)).toPrecision(3) + ' ' + sizes[unit]
})
onMounted(async () => {
await handleGetEquityInfo()
})
async function handleGetEquityInfo() {
await userStore.fetchUpdateEquityInfo()
}
// 上传文件前限制
function handleLimitUpload(data: { file: UploadFileInfo }) {
function handleLimitUpload(data: { file: UploadFileInfo; fileList: UploadFileInfo[] }) {
// 上传数量达到上限
if (isExceedKnowledgeCount.value) {
return false
}
// 获取文件上传时多选的个数
let uploadKnowledgeCount = 0
const knowledgeFileList = document.getElementsByClassName('upload-knowledge-file')
if (knowledgeFileList && knowledgeFileList.length > 0) {
const knowledgeFile = knowledgeFileList[0].getElementsByTagName('input')
if (knowledgeFile && knowledgeFile.length > 0 && knowledgeFile[0].files && knowledgeFile[0].files.length > 0) {
uploadKnowledgeCount = knowledgeFile[0].files.length
}
}
const enableKnowledgeCount = Math.max(
0,
userStore.equityInfo.maxKnowledgeCount - userStore.equityInfo.usedKnowledgeCount - uploadFileList.value.length,
)
if (userStore.equityInfo.maxKnowledgeCount !== 0 && enableKnowledgeCount < uploadKnowledgeCount) {
isExceedKnowledgeCount.value = true
window.$message
.ctWarning(t('equity_module.documents_uploaded_exceeds_tip', { count: enableKnowledgeCount }), '')
.then(() => {
router.push({ name: 'Equity' })
})
.catch(() => {})
return false
}
const allowTypeList = ['md', 'doc', 'docx', 'pdf', 'txt']
const fileType = (data.file.file && data.file.file?.name.split('.')?.pop()?.toLowerCase()) || ''
......@@ -144,6 +192,26 @@ function handleDropFile(e: DragEvent) {
const files = e.dataTransfer?.files as FileList
const file = files[0]
isExceedKnowledgeCount.value = false
const dropKnowledgeCount = files.length
const enableKnowledgeCount = Math.max(
0,
userStore.equityInfo.maxKnowledgeCount - userStore.equityInfo.usedKnowledgeCount - uploadFileList.value.length,
)
if (userStore.equityInfo.maxKnowledgeCount !== 0 && enableKnowledgeCount < dropKnowledgeCount) {
isExceedKnowledgeCount.value = true
window.$message
.ctWarning(t('equity_module.documents_uploaded_exceeds_tip', { count: enableKnowledgeCount }), '')
.then(() => {
router.push({ name: 'Equity' })
})
.catch(() => {})
return
}
const allowTypeList = ['md', 'doc', 'docx', 'pdf', 'txt']
if (file && file.name) {
......@@ -175,12 +243,13 @@ function handleNextStep() {
directory-dnd
:show-file-list="false"
:disabled="uploadFileList.length >= 5"
class="upload-knowledge-file"
accept=".doc, .pdf, .docx, .txt, .md"
@before-upload="handleLimitUpload"
@change="handleUpload"
@drop="handleDropFile"
>
<NUploadDragger>
<NUploadDragger @click="isExceedKnowledgeCount = false">
<div class="mb-3 flex justify-center">
<UploadOne theme="outline" size="36" fill="#333" />
</div>
......
......@@ -573,6 +573,7 @@ declare namespace I18n {
get_points_for_interacting_with_the_ai: string
no_time_limit_when_used_up: string
agents_created_exceeds_tip: string
documents_uploaded_exceeds_tip: string
}
order_manage_module: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment