Skip to content

Commit d9abe8d

Browse files
fix: Dealing with the issue of filename exceeding 128 characters when uploading documents(#2144)
Co-authored-by: wangdan-fit2cloud <dan.wang@fit2cloud.com>
1 parent 761b686 commit d9abe8d

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

ui/src/utils/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { number } from 'echarts'
2+
13
export function toThousands(num: any) {
24
return num?.toString().replace(/\d+/, function (n: any) {
35
return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
@@ -51,7 +53,6 @@ export function getImgUrl(name: string) {
5153
}
5254
// 是否是白名单后缀
5355
export function isRightType(name: string, type: string) {
54-
console.log(name, type)
5556
return typeList[type].includes(fileType(name).toLowerCase())
5657
}
5758

@@ -100,3 +101,10 @@ export function downloadByURL(url: string, name: string) {
100101
a.click()
101102
document.body.removeChild(a)
102103
}
104+
105+
// 截取文件名
106+
export function cutFilename(filename: string, num: number) {
107+
const lastIndex = filename.lastIndexOf('.')
108+
const suffix = lastIndex === -1 ? '' : filename.substring(lastIndex + 1)
109+
return filename.substring(0, num - suffix.length - 1) + '.' + suffix
110+
}

ui/src/views/dataset/component/SetRules.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<script setup lang="ts">
122122
import { ref, computed, onMounted, reactive, watch } from 'vue'
123123
import ParagraphPreview from '@/views/dataset/component/ParagraphPreview.vue'
124+
import { cutFilename } from '@/utils/utils'
124125
import documentApi from '@/api/document'
125126
import useStore from '@/stores'
126127
import type { KeyValue } from '@/api/type/common'
@@ -186,8 +187,12 @@ function splitDocument() {
186187
.postSplitDocument(fd)
187188
.then((res: any) => {
188189
const list = res.data
189-
if (checkedConnect.value) {
190-
list.map((item: any) => {
190+
191+
list.map((item: any) => {
192+
if (item.name.length > 128) {
193+
item.name = cutFilename(item.name, 128)
194+
}
195+
if (checkedConnect.value) {
191196
item.content.map((v: any) => {
192197
v['problem_list'] = v.title.trim()
193198
? [
@@ -197,8 +202,9 @@ function splitDocument() {
197202
]
198203
: []
199204
})
200-
})
201-
}
205+
}
206+
})
207+
202208
paragraphList.value = list
203209
loading.value = false
204210
})

ui/src/views/dataset/component/UploadComponent.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@
161161
</em>
162162
</p>
163163
<div class="upload__decoration">
164-
<p>{{ $t('views.document.upload.formats') }}TXT、Markdown、PDF、DOCX、HTML、XLS、XLSX、CSV、ZIP</p>
164+
<p>
165+
{{
166+
$t('views.document.upload.formats')
167+
}}TXT、Markdown、PDF、DOCX、HTML、XLS、XLSX、CSV、ZIP
168+
</p>
165169
</div>
166170
</div>
167171
</el-upload>
@@ -207,7 +211,9 @@ const form = ref({
207211
})
208212
209213
const rules = reactive({
210-
fileList: [{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }]
214+
fileList: [
215+
{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }
216+
]
211217
})
212218
const FormRef = ref()
213219
@@ -217,11 +223,17 @@ watch(form.value, (value) => {
217223
})
218224
219225
function downloadTemplate(type: string) {
220-
documentApi.exportQATemplate(`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`, type)
226+
documentApi.exportQATemplate(
227+
`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`,
228+
type
229+
)
221230
}
222231
223232
function downloadTableTemplate(type: string) {
224-
documentApi.exportTableTemplate(`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`, type)
233+
documentApi.exportTableTemplate(
234+
`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`,
235+
type
236+
)
225237
}
226238
227239
function radioChange() {

0 commit comments

Comments
 (0)