commit
7ad303f64b
@ -1209,6 +1209,13 @@ export default {
|
|||||||
case 'msg/file/change':
|
case 'msg/file/change':
|
||||||
this.onmessage(msg.data)
|
this.onmessage(msg.data)
|
||||||
break
|
break
|
||||||
|
case 'getUploadParams':
|
||||||
|
// 接收到 getUploadParams 事件,分发 onUploadParams 事件,携带上传参数
|
||||||
|
this.$store.dispatch('updateMessage', {
|
||||||
|
event: 'onUploadParams',
|
||||||
|
data: this.getUploadParams(),
|
||||||
|
})
|
||||||
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
searchFileName(newValue) {
|
searchFileName(newValue) {
|
||||||
@ -2323,29 +2330,11 @@ export default {
|
|||||||
},
|
},
|
||||||
upload() {
|
upload() {
|
||||||
// 打开文件选择框
|
// 打开文件选择框
|
||||||
this.$store.dispatch('updateMessage', {
|
this.$store.dispatch('updateMessage', {event: 'openUploader'})
|
||||||
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,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
uploadFolder() {
|
uploadFolder() {
|
||||||
if (window.uploader.supportDirectory) {
|
if (window.uploader.supportDirectory) {
|
||||||
this.$store.dispatch('updateMessage', {
|
this.$store.dispatch('updateMessage', {event: 'uploadFolder'})
|
||||||
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,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
this.$message({
|
this.$message({
|
||||||
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() {
|
goBack() {
|
||||||
if (this.pathList.length <= 1) {
|
if (this.pathList.length <= 1) {
|
||||||
|
|||||||
@ -192,6 +192,7 @@ export default {
|
|||||||
successMsg: null,
|
successMsg: null,
|
||||||
enableDragUpload: true,// 是否启用拖拽上传
|
enableDragUpload: true,// 是否启用拖拽上传
|
||||||
uploader: null,
|
uploader: null,
|
||||||
|
resolveFilesAddedPromise: null, // 用于等待获取上传参数
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -218,17 +219,22 @@ export default {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'openUploader':
|
case 'openUploader':
|
||||||
this.params = msg.data || {}
|
|
||||||
if (this.$refs.uploadBtn) {
|
if (this.$refs.uploadBtn) {
|
||||||
$('#global-uploader-btn').click()
|
$('#global-uploader-btn').click()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'uploadFolder':
|
case 'uploadFolder':
|
||||||
this.params = msg.data || {}
|
|
||||||
if (this.$refs.folderBtn) {
|
if (this.$refs.folderBtn) {
|
||||||
$('#folder-uploader-btn').click()
|
$('#folder-uploader-btn').click()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case 'onUploadParams':
|
||||||
|
this.params = msg.data || {}
|
||||||
|
if (this.resolveFilesAddedPromise) {
|
||||||
|
// this.resolveFilesAddedPromise();
|
||||||
|
// this.resolveFilesAddedPromise = null;
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -308,13 +314,7 @@ export default {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onDragenter(e) {
|
onDragenter() {
|
||||||
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
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
isPath(str) {
|
isPath(str) {
|
||||||
// 这个正则表达式检测路径中的斜杠字符
|
// 这个正则表达式检测路径中的斜杠字符
|
||||||
@ -322,8 +322,27 @@ export default {
|
|||||||
},
|
},
|
||||||
async onFilesAdded(files) {
|
async onFilesAdded(files) {
|
||||||
if (files.length === 0) {
|
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)
|
let filenames = files.map(file => file.name)
|
||||||
const paths = Object.keys(this.uploader.filePaths)
|
const paths = Object.keys(this.uploader.filePaths)
|
||||||
paths.forEach(path => {
|
paths.forEach(path => {
|
||||||
|
|||||||
@ -273,7 +273,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
import {mapGetters} from 'vuex'
|
import { mapGetters, mapState } from 'vuex'
|
||||||
import {formatSize, formatTime} from '@/utils/number'
|
import {formatSize, formatTime} from '@/utils/number'
|
||||||
import {getElementToPageLeft, getElementToPageTop} from '@/utils/dom'
|
import {getElementToPageLeft, getElementToPageTop} from '@/utils/dom'
|
||||||
import api from '@/api/file-api'
|
import api from '@/api/file-api'
|
||||||
@ -294,6 +294,7 @@ export default {
|
|||||||
ImageViewer, IconFile,
|
ImageViewer, IconFile,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
...mapState(['message']),
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'name',
|
'name',
|
||||||
'avatar'
|
'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() {
|
mounted() {
|
||||||
// 加载布局
|
// 加载布局
|
||||||
if (this.$route.query.vmode) {
|
if (this.$route.query.vmode) {
|
||||||
@ -1255,24 +1268,21 @@ export default {
|
|||||||
// 上传文件
|
// 上传文件
|
||||||
if (action.name === '上传文件') {
|
if (action.name === '上传文件') {
|
||||||
// 打开文件选择框
|
// 打开文件选择框
|
||||||
this.$store.dispatch('updateMessage', { event: 'openUploader', data: {
|
this.$store.dispatch('updateMessage', { event: 'openUploader'})
|
||||||
// 传入的参数
|
|
||||||
folder: this.$route.query.folder,
|
|
||||||
currentDirectory: encodeURI(this.path),
|
|
||||||
username: this.$store.state.user.name,
|
|
||||||
userId: this.$store.state.user.userId
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
// 上传文件夹
|
// 上传文件夹
|
||||||
if (action.name === '上传文件夹') {
|
if (action.name === '上传文件夹') {
|
||||||
// 打开文件夹选择框
|
// 打开文件夹选择框
|
||||||
this.$store.dispatch('updateMessage', { event: 'uploadFolder', data: {
|
this.$store.dispatch('updateMessage', { event: 'uploadFolder'})
|
||||||
// 传入的参数
|
}
|
||||||
folder: this.$route.query.folder,
|
},
|
||||||
currentDirectory: encodeURI(this.path),
|
getUploadParams() {
|
||||||
username: this.$store.state.user.name,
|
return {
|
||||||
userId: this.$store.state.user.userId
|
// 传入的参数
|
||||||
}})
|
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