commit
5bab7c7186
@ -21,7 +21,7 @@
|
||||
</v-contextmenu-item>
|
||||
<v-contextmenu-submenu
|
||||
v-if="item.child"
|
||||
:disabled="item.homeDisable && (!path || path.length < 2)"
|
||||
:disabled="item.operation === 'create' && isNotUploadAllowed"
|
||||
:title="item.label"
|
||||
>
|
||||
<!-- 二级菜单 -->
|
||||
@ -91,7 +91,7 @@
|
||||
<el-popover
|
||||
popper-class="upload-file"
|
||||
v-if="showUploadButton"
|
||||
v-show="!(isRootPath && homeHidden)"
|
||||
v-show="!isNotUploadAllowed"
|
||||
v-model="isShowNewFolder"
|
||||
placement="bottom"
|
||||
trigger="hover"
|
||||
@ -839,6 +839,8 @@ import { formatSize, formatTime } from '@/utils/number'
|
||||
import EditElement from '@/views/markdown/EditElement'
|
||||
import Clipboard from 'clipboard'
|
||||
|
||||
import { isNotDragUploadAllowed } from '@/components/SimpleUploader/dragUploadUtils'
|
||||
|
||||
import _ from 'lodash'
|
||||
import path from 'path'
|
||||
import { mapGetters, mapState } from 'vuex'
|
||||
@ -878,10 +880,6 @@ export default {
|
||||
type: Number,
|
||||
default: 106,
|
||||
},
|
||||
homeHidden: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
showUploadButton: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
@ -1162,15 +1160,15 @@ export default {
|
||||
return '名称'
|
||||
}
|
||||
},
|
||||
isNotUploadAllowed() {
|
||||
return isNotDragUploadAllowed(this.$route)
|
||||
},
|
||||
searchOptionBtnClass() {
|
||||
return this.hasSearchFilterOption ? 'search-option-btn search-option-btn-active' : 'search-option-btn'
|
||||
},
|
||||
cmdKey() {
|
||||
return navigator.platform.startsWith('Mac') ? '⌘' : 'Ctrl'
|
||||
},
|
||||
isRootPath() {
|
||||
return !this.$route.query.path || this.$route.query.path.length < 2
|
||||
},
|
||||
fileClipboard() {
|
||||
return store.getters.fileClipboard
|
||||
},
|
||||
|
||||
43
src/components/SimpleUploader/dragUploadUtils.js
Normal file
43
src/components/SimpleUploader/dragUploadUtils.js
Normal file
@ -0,0 +1,43 @@
|
||||
// utils/dragUploadUtils.js
|
||||
|
||||
/**
|
||||
* 拖拽上传相关工具函数
|
||||
*/
|
||||
|
||||
// 特殊路由 - 完全禁止拖拽上传
|
||||
const SPECIAL_ROUTES = ['/recently', '/document', '/audio', '/image', '/video']
|
||||
|
||||
// 禁用拖拽路由 - 需要特定条件才允许
|
||||
const NO_DRAG_ROUTES = ['/favorite', '/mount', '/trash', '/tag']
|
||||
|
||||
/**
|
||||
* 检查是否禁止拖拽上传
|
||||
* @param {Object} route - 路由对象 { path, query }
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isNotDragUploadAllowed(route) {
|
||||
if (!route) return false
|
||||
|
||||
const { path, query = {} } = route
|
||||
const { keyword, searchOpenFolder } = query || {}
|
||||
|
||||
// 标准化路径
|
||||
const normalizedPath = path ? path.replace(/\/$/, '') : ''
|
||||
|
||||
// 三种禁用拖拽的条件
|
||||
const isSpecialRoute = SPECIAL_ROUTES.includes(normalizedPath)
|
||||
const isNoDragRoute = NO_DRAG_ROUTES.includes(normalizedPath) && !query.path
|
||||
const isSearchWithoutFolder = keyword && !searchOpenFolder
|
||||
|
||||
return isSpecialRoute || isNoDragRoute || isSearchWithoutFolder
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否允许拖拽上传
|
||||
* @param {Object} route - 路由对象 { path, query }
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isDragUploadAllowed(route) {
|
||||
return !isNotDragUploadAllowed(route)
|
||||
}
|
||||
|
||||
@ -118,7 +118,8 @@ import SparkMD5 from 'spark-md5'
|
||||
import api from '@/api/file-api'
|
||||
import {formatNetSpeed} from '@/utils/number'
|
||||
import {mapState} from 'vuex'
|
||||
import {encodeIfNeeded} from "@/utils/path";
|
||||
import {encodeIfNeeded} from "@/utils/path"
|
||||
import { isDragUploadAllowed } from './dragUploadUtils'
|
||||
|
||||
export default {
|
||||
components: {},
|
||||
@ -189,7 +190,7 @@ export default {
|
||||
fileListScrollTop: 0,
|
||||
dragoverLoop: null,
|
||||
successMsg: null,
|
||||
enableDragUpload: false,// 是否启用拖拽上传
|
||||
enableDragUpload: true,// 是否启用拖拽上传
|
||||
uploader: null,
|
||||
}
|
||||
},
|
||||
@ -198,8 +199,7 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
$route(route) {
|
||||
// 只有首页才启用拖拽上传
|
||||
this.enableDragUpload = route.path === '/'
|
||||
this.checkDrag(route)
|
||||
},
|
||||
message(msg) {
|
||||
switch (msg.event) {
|
||||
@ -233,7 +233,7 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.enableDragUpload = this.$route.path === '/'
|
||||
this.checkDrag(this.$route)
|
||||
let that = this
|
||||
let dropbox = document.body
|
||||
|
||||
@ -280,6 +280,9 @@ export default {
|
||||
destroyed() {
|
||||
},
|
||||
methods: {
|
||||
checkDrag(route) {
|
||||
this.enableDragUpload = isDragUploadAllowed(route)
|
||||
},
|
||||
onStorageTypeChange(chunkSize) {
|
||||
localStorage.setItem('uploader_chunk_size', chunkSize)
|
||||
if (this.options.chunkSize !== chunkSize && !this.panelShow) {
|
||||
|
||||
@ -406,15 +406,15 @@ export default {
|
||||
if (this.takeUpSpace === 0) {
|
||||
this.takeUpSpace = this.userInfo.takeUpSpace
|
||||
}
|
||||
const quota = this.userInfo.quota
|
||||
const space = this.takeUpSpace/1024/1024/1024
|
||||
if(space && quota > 0){
|
||||
const percentage = Number((space/quota * 100).toFixed(5))
|
||||
const spaceBytes = this.takeUpSpace
|
||||
const quotaBytes = this.userInfo.quota * 1024 * 1024 * 1024
|
||||
if(spaceBytes && quotaBytes > 0){
|
||||
const percentage = Number((spaceBytes/quotaBytes * 100).toFixed(5))
|
||||
this.percentage = percentage > 100 ? 100 : percentage
|
||||
if(this.isCollapse){
|
||||
return `${formatSize(this.takeUpSpace)}`
|
||||
} else {
|
||||
return `${formatSize(this.takeUpSpace)}/${quota}GB`
|
||||
return `${formatSize(this.takeUpSpace)}/${formatSize(quotaBytes)}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,17 +127,18 @@ export function formatTime(agoTime) {
|
||||
* @param {*} size
|
||||
*/
|
||||
export function formatSize(size) {
|
||||
if (size === 0) {
|
||||
return ''
|
||||
} else if (size < 1024) {
|
||||
return size + 'B'
|
||||
} else if (size < 1024 * 1024) {
|
||||
return (size/1024).toFixed(1) + 'k'
|
||||
} else if (size < 1024 * 1024 * 1024) {
|
||||
return (size/(1024 * 1024)).toFixed(1) + 'M'
|
||||
} else {
|
||||
return (size/(1024 * 1024 * 1024)).toFixed(1) + 'G'
|
||||
if (size === 0 || !size) return '0B';
|
||||
|
||||
const units = ['B', 'K', 'M', 'G', 'T'];
|
||||
let index = 0;
|
||||
let result = size;
|
||||
|
||||
while (result >= 1024 && index < units.length - 1) {
|
||||
result /= 1024;
|
||||
index++;
|
||||
}
|
||||
|
||||
return result.toFixed(1) + units[index];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
:defaultSort="sortable"
|
||||
:queryCondition="queryCondition"
|
||||
:contextMenus="contextMenus"
|
||||
homeHidden
|
||||
>
|
||||
</show-file>
|
||||
</div>
|
||||
@ -39,7 +38,7 @@
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
@ -39,7 +39,7 @@ export default {
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
@ -39,7 +39,7 @@ export default {
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
@ -38,7 +38,7 @@ export default {
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
@ -39,7 +39,7 @@ export default {
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
:defaultSort="sortable"
|
||||
:queryCondition="queryCondition"
|
||||
:contextMenus="contextMenus"
|
||||
homeHidden
|
||||
>
|
||||
</show-file>
|
||||
</div>
|
||||
@ -39,7 +38,7 @@
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles},
|
||||
{ label: '新建', operation: 'create' , child: createFiles},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
]
|
||||
|
||||
@ -241,12 +241,13 @@
|
||||
}
|
||||
},
|
||||
progressFormat() {
|
||||
const space = this.userInfo.takeUpSpace/1024/1024/1024
|
||||
const quota = this.userInfo.quota
|
||||
if(space && quota > 0){
|
||||
const percentage = Number((space/quota * 100).toFixed(1))
|
||||
this.percentage = percentage > 100 ? 100 : percentage
|
||||
return `${this.percentage}% (${formatSize(this.userInfo.takeUpSpace)}/${quota}GB)`;
|
||||
const spaceBytes = this.userInfo.takeUpSpace;
|
||||
const quotaBytes = this.userInfo.quota * 1024 * 1024 * 1024;
|
||||
|
||||
if (spaceBytes && quotaBytes > 0) {
|
||||
const percentage = Number((spaceBytes / quotaBytes * 100).toFixed(1));
|
||||
this.percentage = percentage > 100 ? 100 : percentage;
|
||||
return `${this.percentage}% (${formatSize(spaceBytes)}/${formatSize(quotaBytes)})`;
|
||||
}
|
||||
},
|
||||
// 设置formData
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
:defaultSort="sortable"
|
||||
:queryCondition="queryCondition"
|
||||
:contextMenus="contextMenus"
|
||||
homeHidden
|
||||
>
|
||||
</show-file>
|
||||
</div>
|
||||
@ -38,7 +37,7 @@ export default {
|
||||
},
|
||||
{ label: '刷新', operation: 'refresh'},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '新建', operation: 'create' , homeDisable: true, child: createFiles
|
||||
{ label: '新建', operation: 'create' , child: createFiles
|
||||
},
|
||||
{ divider: true, operation: 'divider' },
|
||||
{ label: '写文章', operation: 'createMarkdownFile'},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user