commit
7ad303f64b
@ -1209,6 +1209,13 @@ export default {
|
||||
case 'msg/file/change':
|
||||
this.onmessage(msg.data)
|
||||
break
|
||||
case 'getUploadParams':
|
||||
// 接收到 getUploadParams 事件,分发 onUploadParams 事件,携带上传参数
|
||||
this.$store.dispatch('updateMessage', {
|
||||
event: 'onUploadParams',
|
||||
data: this.getUploadParams(),
|
||||
})
|
||||
break
|
||||
}
|
||||
},
|
||||
searchFileName(newValue) {
|
||||
@ -2323,29 +2330,11 @@ export default {
|
||||
},
|
||||
upload() {
|
||||
// 打开文件选择框
|
||||
this.$store.dispatch('updateMessage', {
|
||||
event: 'openUploader',
|
||||
data: {
|
||||
// 传入的参数
|
||||
folder: this.$route.query.searchOpenFolder || this.$route.query.folder,
|
||||
currentDirectory: this.getQueryPath(),
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId,
|
||||
},
|
||||
})
|
||||
this.$store.dispatch('updateMessage', {event: 'openUploader'})
|
||||
},
|
||||
uploadFolder() {
|
||||
if (window.uploader.supportDirectory) {
|
||||
this.$store.dispatch('updateMessage', {
|
||||
event: 'uploadFolder',
|
||||
data: {
|
||||
// 传入的参数
|
||||
folder: this.$route.query.searchOpenFolder || this.$route.query.folder,
|
||||
currentDirectory: this.getQueryPath(),
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId,
|
||||
},
|
||||
})
|
||||
this.$store.dispatch('updateMessage', {event: 'uploadFolder'})
|
||||
} else {
|
||||
this.$message({
|
||||
message: '该浏览器不支持上传文件夹',
|
||||
@ -2353,6 +2342,14 @@ export default {
|
||||
})
|
||||
}
|
||||
},
|
||||
getUploadParams() {
|
||||
return {
|
||||
folder: this.$route.query.searchOpenFolder || this.$route.query.folder,
|
||||
currentDirectory: this.getQueryPath(),
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId,
|
||||
}
|
||||
},
|
||||
// 浏览器的返回事件
|
||||
goBack() {
|
||||
if (this.pathList.length <= 1) {
|
||||
|
||||
@ -192,6 +192,7 @@ export default {
|
||||
successMsg: null,
|
||||
enableDragUpload: true,// 是否启用拖拽上传
|
||||
uploader: null,
|
||||
resolveFilesAddedPromise: null, // 用于等待获取上传参数
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -218,17 +219,22 @@ export default {
|
||||
}
|
||||
break
|
||||
case 'openUploader':
|
||||
this.params = msg.data || {}
|
||||
if (this.$refs.uploadBtn) {
|
||||
$('#global-uploader-btn').click()
|
||||
}
|
||||
break
|
||||
case 'uploadFolder':
|
||||
this.params = msg.data || {}
|
||||
if (this.$refs.folderBtn) {
|
||||
$('#folder-uploader-btn').click()
|
||||
}
|
||||
break
|
||||
case 'onUploadParams':
|
||||
this.params = msg.data || {}
|
||||
if (this.resolveFilesAddedPromise) {
|
||||
// this.resolveFilesAddedPromise();
|
||||
// this.resolveFilesAddedPromise = null;
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -308,13 +314,7 @@ export default {
|
||||
});
|
||||
});
|
||||
},
|
||||
onDragenter(e) {
|
||||
this.params = {
|
||||
currentDirectory: this.$route.query.path || '/',
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId,
|
||||
folder: this.$route.query.searchOpenFolder || this.$route.query.folder
|
||||
}
|
||||
onDragenter() {
|
||||
},
|
||||
isPath(str) {
|
||||
// 这个正则表达式检测路径中的斜杠字符
|
||||
@ -322,8 +322,27 @@ export default {
|
||||
},
|
||||
async onFilesAdded(files) {
|
||||
if (files.length === 0) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const waitForParams = new Promise((resolve, reject) => {
|
||||
this.resolveFilesAddedPromise = resolve;
|
||||
// 添加超时以防止未收到响应时挂起,如果服务端没有及时返回上传参数,则取消上传
|
||||
setTimeout(() => reject(new Error('Timeout waiting for upload parameters')), 3000);
|
||||
});
|
||||
|
||||
await this.$store.dispatch('updateMessage', { event: 'getUploadParams' });
|
||||
|
||||
await waitForParams;
|
||||
|
||||
await this.doFilesAdded(files);
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to add files:", error);
|
||||
this.uploaderCancel();
|
||||
}
|
||||
},
|
||||
async doFilesAdded(files) {
|
||||
let filenames = files.map(file => file.name)
|
||||
const paths = Object.keys(this.uploader.filePaths)
|
||||
paths.forEach(path => {
|
||||
|
||||
@ -273,7 +273,7 @@
|
||||
</template>
|
||||
<script>
|
||||
|
||||
import {mapGetters} from 'vuex'
|
||||
import { mapGetters, mapState } from 'vuex'
|
||||
import {formatSize, formatTime} from '@/utils/number'
|
||||
import {getElementToPageLeft, getElementToPageTop} from '@/utils/dom'
|
||||
import api from '@/api/file-api'
|
||||
@ -294,6 +294,7 @@ export default {
|
||||
ImageViewer, IconFile,
|
||||
},
|
||||
computed: {
|
||||
...mapState(['message']),
|
||||
...mapGetters([
|
||||
'name',
|
||||
'avatar'
|
||||
@ -403,6 +404,18 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
message(msg) {
|
||||
switch (msg.event) {
|
||||
case 'getUploadParams':
|
||||
this.$store.dispatch('updateMessage', {
|
||||
event: 'onUploadParams',
|
||||
data: this.getUploadParams(),
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 加载布局
|
||||
if (this.$route.query.vmode) {
|
||||
@ -1255,24 +1268,21 @@ export default {
|
||||
// 上传文件
|
||||
if (action.name === '上传文件') {
|
||||
// 打开文件选择框
|
||||
this.$store.dispatch('updateMessage', { event: 'openUploader', data: {
|
||||
// 传入的参数
|
||||
folder: this.$route.query.folder,
|
||||
currentDirectory: encodeURI(this.path),
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId
|
||||
}})
|
||||
this.$store.dispatch('updateMessage', { event: 'openUploader'})
|
||||
}
|
||||
// 上传文件夹
|
||||
if (action.name === '上传文件夹') {
|
||||
// 打开文件夹选择框
|
||||
this.$store.dispatch('updateMessage', { event: 'uploadFolder', data: {
|
||||
// 传入的参数
|
||||
folder: this.$route.query.folder,
|
||||
currentDirectory: encodeURI(this.path),
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId
|
||||
}})
|
||||
this.$store.dispatch('updateMessage', { event: 'uploadFolder'})
|
||||
}
|
||||
},
|
||||
getUploadParams() {
|
||||
return {
|
||||
// 传入的参数
|
||||
folder: this.$route.query.folder,
|
||||
currentDirectory: encodeURI(this.path),
|
||||
username: this.$store.state.user.name,
|
||||
userId: this.$store.state.user.userId
|
||||
}
|
||||
},
|
||||
// 新建文件夹
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user