mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-25 14:25:23 +00:00
perf: 显示上传文件大小
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
type="default"
|
type="default"
|
||||||
@click="item.callback()"
|
@click="item.callback()"
|
||||||
>
|
>
|
||||||
<i :class="item.icon" />
|
<svg-icon :icon-class="item.icon" />
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
@@ -37,7 +37,8 @@ export default {
|
|||||||
},
|
},
|
||||||
xtermConfig: {
|
xtermConfig: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -56,21 +57,21 @@ export default {
|
|||||||
toolbar: [
|
toolbar: [
|
||||||
{
|
{
|
||||||
tip: this.$tc('ops.ScrollToTop'),
|
tip: this.$tc('ops.ScrollToTop'),
|
||||||
icon: 'fa fa-arrow-up',
|
icon: 'arrow-up',
|
||||||
callback: () => {
|
callback: () => {
|
||||||
this.xterm.scrollToTop()
|
this.xterm.scrollToTop()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tip: this.$tc('ops.ScrollToBottom'),
|
tip: this.$tc('ops.ScrollToBottom'),
|
||||||
icon: 'fa fa-arrow-down',
|
icon: 'arrow-down',
|
||||||
callback: () => {
|
callback: () => {
|
||||||
this.xterm.scrollToBottom()
|
this.xterm.scrollToBottom()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tip: this.$tc('ops.ClearScreen'),
|
tip: this.$tc('ops.ClearScreen'),
|
||||||
icon: 'fa fa-refresh',
|
icon: 'refresh',
|
||||||
callback: () => {
|
callback: () => {
|
||||||
this.xterm.reset()
|
this.xterm.reset()
|
||||||
}
|
}
|
||||||
|
@@ -1180,7 +1180,10 @@
|
|||||||
"Transfer": "Transfer",
|
"Transfer": "Transfer",
|
||||||
"UploadDir": "Upload Directory",
|
"UploadDir": "Upload Directory",
|
||||||
"RequiredUploadFile": "Please upload files!",
|
"RequiredUploadFile": "Please upload files!",
|
||||||
"DuplicateFileExists": "Duplicate file exists"
|
"DuplicateFileExists": "Duplicate file exists",
|
||||||
|
"NoFiles": "No Files",
|
||||||
|
"uploadFileLthHelpText": "Only files smaller than 200MB can be uploaded",
|
||||||
|
"FileSizeExceedsLimit": "File size exceeds limit"
|
||||||
},
|
},
|
||||||
"perms": {
|
"perms": {
|
||||||
"": "",
|
"": "",
|
||||||
|
@@ -1178,7 +1178,10 @@
|
|||||||
"Transfer": "ファイルを転送する",
|
"Transfer": "ファイルを転送する",
|
||||||
"UploadDir": "アップロードディレクトリ",
|
"UploadDir": "アップロードディレクトリ",
|
||||||
"RequiredUploadFile": "ファイルをアップロードしてください!",
|
"RequiredUploadFile": "ファイルをアップロードしてください!",
|
||||||
"DuplicateFileExists": "重複したファイルが存在する"
|
"DuplicateFileExists": "重複したファイルが存在する",
|
||||||
|
"NoFiles": "まだファイルがありません",
|
||||||
|
"uploadFileLthHelpText": "200MB 未満のファイルのみアップロードできます",
|
||||||
|
"FileSizeExceedsLimit": "ファイルサイズが制限を超えています"
|
||||||
},
|
},
|
||||||
"perms": {
|
"perms": {
|
||||||
"": "",
|
"": "",
|
||||||
|
@@ -1167,7 +1167,10 @@
|
|||||||
"Transfer": "传输",
|
"Transfer": "传输",
|
||||||
"UploadDir": "上传目录",
|
"UploadDir": "上传目录",
|
||||||
"RequiredUploadFile": "请上传文件!",
|
"RequiredUploadFile": "请上传文件!",
|
||||||
"DuplicateFileExists": "存在同名文件"
|
"DuplicateFileExists": "存在同名文件",
|
||||||
|
"NoFiles": "暂无文件",
|
||||||
|
"uploadFileLthHelpText": "只能上传小于200MB文件",
|
||||||
|
"FileSizeExceedsLimit": "文件大小超出限制"
|
||||||
},
|
},
|
||||||
"perms": {
|
"perms": {
|
||||||
"": "",
|
"": "",
|
||||||
|
5
src/icons/svg/arrow-down.svg
Normal file
5
src/icons/svg/arrow-down.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M24 42V6" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M36 30L24 42L12 30" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 358 B |
5
src/icons/svg/arrow-up.svg
Normal file
5
src/icons/svg/arrow-up.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M24 6V42" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M12 18L24 6L36 18" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 357 B |
@@ -407,4 +407,12 @@ export const pageScroll = _.throttle((id) => {
|
|||||||
}
|
}
|
||||||
}, 200)
|
}, 200)
|
||||||
|
|
||||||
|
export function formatFileSize(bytes) {
|
||||||
|
if (bytes === 0) return '0 Bytes'
|
||||||
|
const k = 1024
|
||||||
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||||
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||||
|
}
|
||||||
|
|
||||||
export { BASE_URL }
|
export { BASE_URL }
|
||||||
|
@@ -55,6 +55,10 @@
|
|||||||
<div class="el-upload__text">
|
<div class="el-upload__text">
|
||||||
{{ $t('common.imExport.dragUploadFileInfo') }}
|
{{ $t('common.imExport.dragUploadFileInfo') }}
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<span>
|
||||||
|
{{ $t('ops.uploadFileLthHelpText') }}
|
||||||
|
</span>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<el-progress v-if="ShowProgress" :percentage="progressLength" />
|
<el-progress v-if="ShowProgress" :percentage="progressLength" />
|
||||||
</el-card>
|
</el-card>
|
||||||
@@ -94,6 +98,7 @@ import { TreeTable } from '@/components'
|
|||||||
import Term from '@/components/Widgets/Term'
|
import Term from '@/components/Widgets/Term'
|
||||||
import Page from '@/layout/components/Page'
|
import Page from '@/layout/components/Page'
|
||||||
import { createJob, getJob, getTaskDetail, JobUploadFile } from '@/api/ops'
|
import { createJob, getJob, getTaskDetail, JobUploadFile } from '@/api/ops'
|
||||||
|
import { formatFileSize } from '@/utils/common'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BulkTransfer',
|
name: 'BulkTransfer',
|
||||||
@@ -197,6 +202,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.enableWS()
|
this.enableWS()
|
||||||
this.initData()
|
this.initData()
|
||||||
|
this.handleFileList(null, [])
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async initData() {
|
async initData() {
|
||||||
@@ -294,7 +300,7 @@ export default {
|
|||||||
return { hosts, nodes }
|
return { hosts, nodes }
|
||||||
},
|
},
|
||||||
truncateFileName(fullName) {
|
truncateFileName(fullName) {
|
||||||
const maxLength = 140 // 显示的最大字符数
|
const maxLength = 130 // 显示的最大字符数
|
||||||
if (fullName.length <= maxLength) {
|
if (fullName.length <= maxLength) {
|
||||||
return fullName
|
return fullName
|
||||||
}
|
}
|
||||||
@@ -302,14 +308,28 @@ export default {
|
|||||||
const secondPart = fullName.slice(-maxLength / 2)
|
const secondPart = fullName.slice(-maxLength / 2)
|
||||||
return firstPart + '...' + secondPart
|
return firstPart + '...' + secondPart
|
||||||
},
|
},
|
||||||
renderSameFile(file, fileList) {
|
handleFileList(file, fileList) {
|
||||||
const filenameList = fileList.map((file) => file.name)
|
const filenameList = fileList.map((file) => file.name)
|
||||||
const filenameCount = _.countBy(filenameList)
|
const filenameCount = _.countBy(filenameList)
|
||||||
// 找出同名文件
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
const emptyFileTip = document.getElementsByClassName('empty-file-tip')
|
||||||
|
if (emptyFileTip.length > 0) {
|
||||||
|
emptyFileTip[0].style = 'display:none'
|
||||||
|
}
|
||||||
const fileElementList = document.getElementsByClassName('el-upload-list__item-name')
|
const fileElementList = document.getElementsByClassName('el-upload-list__item-name')
|
||||||
if (fileElementList && fileElementList.length > 0) {
|
if (fileElementList && fileElementList.length > 0) {
|
||||||
for (const ele of fileElementList) {
|
for (const ele of fileElementList) {
|
||||||
|
// 显示文件大小
|
||||||
|
if (file.name === ele.outerText) {
|
||||||
|
ele.insertAdjacentHTML('beforeend',
|
||||||
|
`<i style="color: #1ab394;float: right;font-weight:normal">${formatFileSize(file.size)}</i>`)
|
||||||
|
}
|
||||||
|
// 文件大小超出限制
|
||||||
|
if (file.size > 200 * 1024 * 1024) {
|
||||||
|
this.$message.error(this.$tc('ops.FileSizeExceedsLimit'))
|
||||||
|
ele.style = 'background-color:var(--color-danger)'
|
||||||
|
}
|
||||||
|
// 同名文件提示
|
||||||
if (filenameCount[ele.outerText] > 1) {
|
if (filenameCount[ele.outerText] > 1) {
|
||||||
this.$message.error(this.$tc('ops.DuplicateFileExists'))
|
this.$message.error(this.$tc('ops.DuplicateFileExists'))
|
||||||
ele.style = 'background-color:var(--color-danger)'
|
ele.style = 'background-color:var(--color-danger)'
|
||||||
@@ -317,13 +337,18 @@ export default {
|
|||||||
ele.style = ''
|
ele.style = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const emptyFileElementList = document.getElementsByClassName('el-upload-list--text')[0]
|
||||||
|
const text = this.$tc('ops.NoFiles')
|
||||||
|
emptyFileElementList.insertAdjacentHTML('afterbegin',
|
||||||
|
`<div class="empty-file-tip" style="color: #c5c9cc;font-size: 18px;display: flex;justify-content: center;align-items: center;height: 100%">${text}</div>`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onFileChange(file, fileList) {
|
onFileChange(file, fileList) {
|
||||||
file.name = this.truncateFileName(file.name)
|
file.name = this.truncateFileName(file.name)
|
||||||
this.files = fileList
|
this.files = fileList
|
||||||
this.renderSameFile(file, fileList)
|
this.handleFileList(file, fileList)
|
||||||
},
|
},
|
||||||
execute() {
|
execute() {
|
||||||
const { hosts, nodes } = this.getSelectedNodesAndHosts()
|
const { hosts, nodes } = this.getSelectedNodesAndHosts()
|
||||||
@@ -469,11 +494,9 @@ export default {
|
|||||||
list-style: none;
|
list-style: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 180px;
|
height: 180px;
|
||||||
}
|
|
||||||
|
|
||||||
> > > .el-upload-list:not(:empty) {
|
|
||||||
border: 1px dashed #d9d9d9;
|
border: 1px dashed #d9d9d9;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Reference in New Issue
Block a user