fix: Dealing with the issue of filename exceeding 128 characters when uploading documents(#2144)

Co-authored-by: wangdan-fit2cloud <dan.wang@fit2cloud.com>
This commit is contained in:
shaohuzhang1 2025-02-09 15:09:55 +08:00 committed by GitHub
parent 761b686214
commit d9abe8d675
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import { number } from 'echarts'
export function toThousands(num: any) { export function toThousands(num: any) {
return num?.toString().replace(/\d+/, function (n: any) { return num?.toString().replace(/\d+/, function (n: any) {
return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
@ -51,7 +53,6 @@ export function getImgUrl(name: string) {
} }
// 是否是白名单后缀 // 是否是白名单后缀
export function isRightType(name: string, type: string) { export function isRightType(name: string, type: string) {
console.log(name, type)
return typeList[type].includes(fileType(name).toLowerCase()) return typeList[type].includes(fileType(name).toLowerCase())
} }
@ -100,3 +101,10 @@ export function downloadByURL(url: string, name: string) {
a.click() a.click()
document.body.removeChild(a) document.body.removeChild(a)
} }
// 截取文件名
export function cutFilename(filename: string, num: number) {
const lastIndex = filename.lastIndexOf('.')
const suffix = lastIndex === -1 ? '' : filename.substring(lastIndex + 1)
return filename.substring(0, num - suffix.length - 1) + '.' + suffix
}

View File

@ -121,6 +121,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, reactive, watch } from 'vue' import { ref, computed, onMounted, reactive, watch } from 'vue'
import ParagraphPreview from '@/views/dataset/component/ParagraphPreview.vue' import ParagraphPreview from '@/views/dataset/component/ParagraphPreview.vue'
import { cutFilename } from '@/utils/utils'
import documentApi from '@/api/document' import documentApi from '@/api/document'
import useStore from '@/stores' import useStore from '@/stores'
import type { KeyValue } from '@/api/type/common' import type { KeyValue } from '@/api/type/common'
@ -186,8 +187,12 @@ function splitDocument() {
.postSplitDocument(fd) .postSplitDocument(fd)
.then((res: any) => { .then((res: any) => {
const list = res.data const list = res.data
if (checkedConnect.value) {
list.map((item: any) => { list.map((item: any) => {
if (item.name.length > 128) {
item.name = cutFilename(item.name, 128)
}
if (checkedConnect.value) {
item.content.map((v: any) => { item.content.map((v: any) => {
v['problem_list'] = v.title.trim() v['problem_list'] = v.title.trim()
? [ ? [
@ -197,8 +202,9 @@ function splitDocument() {
] ]
: [] : []
}) })
}) }
} })
paragraphList.value = list paragraphList.value = list
loading.value = false loading.value = false
}) })

View File

@ -161,7 +161,11 @@
</em> </em>
</p> </p>
<div class="upload__decoration"> <div class="upload__decoration">
<p>{{ $t('views.document.upload.formats') }}TXTMarkdownPDFDOCXHTMLXLSXLSXCSVZIP</p> <p>
{{
$t('views.document.upload.formats')
}}TXTMarkdownPDFDOCXHTMLXLSXLSXCSVZIP
</p>
</div> </div>
</div> </div>
</el-upload> </el-upload>
@ -207,7 +211,9 @@ const form = ref({
}) })
const rules = reactive({ const rules = reactive({
fileList: [{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }] fileList: [
{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }
]
}) })
const FormRef = ref() const FormRef = ref()
@ -217,11 +223,17 @@ watch(form.value, (value) => {
}) })
function downloadTemplate(type: string) { function downloadTemplate(type: string) {
documentApi.exportQATemplate(`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`, type) documentApi.exportQATemplate(
`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`,
type
)
} }
function downloadTableTemplate(type: string) { function downloadTableTemplate(type: string) {
documentApi.exportTableTemplate(`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`, type) documentApi.exportTableTemplate(
`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`,
type
)
} }
function radioChange() { function radioChange() {