Merged
【修改描述】固件升级支持拖拽或粘贴式上传文件 #432
BaiXin_LuoHaoAdd on May 22
【修改描述】固件升级支持拖拽或粘贴式上传文件 #432
Merged
Merged fromluohao211737/webuifile_uploadintoopenUBMC/webuimain
Total: 10 files changed+166-33
| @@ -1,5 +1,5 @@ | |||
| 1 | <script lang="ts" setup> | 1 | <script lang="ts" setup> |
| 2 | -import { IconMore, IconSUpload } from '@computing/opendesign-icons'; | 2 | +import { IconMore, IconSUpload, IconXSolid } from '@computing/opendesign-icons'; |
| 3 | import { PropType, reactive, Ref, ref, toRefs } from 'vue'; | 3 | import { PropType, reactive, Ref, ref, toRefs } from 'vue'; |
| 4 | import { UploadFile } from 'element-plus/es/components/upload/src/upload'; | 4 | import { UploadFile } from 'element-plus/es/components/upload/src/upload'; |
| 5 | import { IUploadConfig } from '@/model/base-interface'; | 5 | import { IUploadConfig } from '@/model/base-interface'; |
| @@ -24,6 +24,16 @@ const fileName = ref(''); | |||
| 24 | const upload = ref(); | 24 | const upload = ref(); |
| 25 | const isError = ref(false); | 25 | const isError = ref(false); |
| 26 | const errorMsg = ref(''); | 26 | const errorMsg = ref(''); |
| 27 | +const isDragOver = ref(false); | ||
| 28 | + | ||
| 29 | +const addFile = (file?: File | null) => { | ||
| 30 | + if (!file || uploadConfig.disabled) { | ||
| 31 | + return; | ||
| 32 | + } | ||
| 33 | + upload.value.clearFiles(); | ||
| 34 | + upload.value.handleStart(file); | ||
| 35 | +}; | ||
| 36 | + | ||
| 27 | const handleSuccess = (response: any, file: UploadFile, list: UploadFile[]) => { | 37 | const handleSuccess = (response: any, file: UploadFile, list: UploadFile[]) => { |
| 28 | if (uploadConfig.onSuccess) { | 38 | if (uploadConfig.onSuccess) { |
| 29 | uploadConfig.onSuccess(response, file, list); | 39 | uploadConfig.onSuccess(response, file, list); |
| @@ -41,6 +51,31 @@ const handleExceed = (files: UploadFile[]) => { | |||
| 41 | upload.value.handleStart(files[0]); | 51 | upload.value.handleStart(files[0]); |
| 42 | }; | 52 | }; |
| 43 | 53 | ||
| 54 | +const handleDragEnter = () => { | ||
| 55 | + if (uploadConfig.enableDrop && !uploadConfig.disabled) { | ||
| 56 | + isDragOver.value = true; | ||
| 57 | + } | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | +const handleDragLeave = () => { | ||
| 61 | + isDragOver.value = false; | ||
| 62 | +}; | ||
| 63 | + | ||
| 64 | +const handleDrop = (event: DragEvent) => { | ||
| 65 | + isDragOver.value = false; | ||
| 66 | + if (!uploadConfig.enableDrop) { | ||
| 67 | + return; | ||
| 68 | + } | ||
| 69 | + addFile(event.dataTransfer?.files?.[0]); | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +const handlePaste = (event: ClipboardEvent) => { | ||
| 73 | + if (!uploadConfig.enablePaste) { | ||
| 74 | + return; | ||
| 75 | + } | ||
| 76 | + addFile(event.clipboardData?.files?.[0]); | ||
| 77 | +}; | ||
| 78 | + | ||
| 44 | const handleChange = (file: UploadFile, list: UploadFile[]) => { | 79 | const handleChange = (file: UploadFile, list: UploadFile[]) => { |
| 45 | if (file.status === 'ready' && uploadConfig.onAddItem) { | 80 | if (file.status === 'ready' && uploadConfig.onAddItem) { |
| 46 | fileItem.value = file; | 81 | fileItem.value = file; |
| @@ -85,6 +120,16 @@ const handleBeforeRemove = (file: UploadFile, list: UploadFile[]) => { | |||
| 85 | } | 120 | } |
| 86 | }; | 121 | }; |
| 87 | 122 | ||
| 123 | +const clearSelectedFile = () => { | ||
| 124 | + if (fileItem.value !== null) { | ||
| 125 | + upload.value.handleRemove(fileItem.value); | ||
| 126 | + } | ||
| 127 | + fileItem.value = null; | ||
| 128 | + fileName.value = ''; | ||
| 129 | + isError.value = false; | ||
| 130 | + errorMsg.value = ''; | ||
| 131 | +}; | ||
| 132 | + | ||
| 88 | const customUpload = (options: any): Promise<any> => { | 133 | const customUpload = (options: any): Promise<any> => { |
| 89 | return new Promise((resolve, reject) => { | 134 | return new Promise((resolve, reject) => { |
| 90 | let header = { | 135 | let header = { |
| @@ -109,10 +154,7 @@ const customUpload = (options: any): Promise<any> => { | |||
| 109 | }; | 154 | }; |
| 110 | defineExpose({ | 155 | defineExpose({ |
| 111 | clear: () => { | 156 | clear: () => { |
| 112 | - if (fileItem.value !== null) { | 157 | + clearSelectedFile(); |
| 113 | - upload.value.handleRemove(fileItem.value); | ||
| 114 | - } | ||
| 115 | - fileName.value = ''; | ||
| 116 | }, | 158 | }, |
| 117 | setError: (msg: string) => { | 159 | setError: (msg: string) => { |
| 118 | isError.value = true; | 160 | isError.value = true; |
| @@ -127,10 +169,40 @@ defineExpose({ | |||
| 127 | </script> | 169 | </script> |
| 128 | 170 | ||
| 129 | <template> | 171 | <template> |
| 130 | - <div class="file-upload" :style="uploadConfig.type !== 'button' ? style : {}"> | 172 | + <div |
| 173 | + class="file-upload" | ||
| 174 | + :class="{ 'drag-over': isDragOver }" | ||
| 175 | + :style="uploadConfig.type !== 'button' ? style : {}" | ||
| 176 | + :tabindex="uploadConfig.enablePaste ? 0 : undefined" | ||
| 177 | + @dragenter.prevent="handleDragEnter" | ||
| 178 | + @dragover.prevent="handleDragEnter" | ||
| 179 | + @dragleave.prevent="handleDragLeave" | ||
| 180 | + @drop.prevent="handleDrop" | ||
| 181 | + @paste="handlePaste" | ||
| 182 | + > | ||
| 183 | + <el-input | ||
| 184 | + v-if="uploadConfig.type !== 'button'" | ||
| 185 | + v-model="fileName" | ||
| 186 | + class="upload-display-input" | ||
| 187 | + :placeholder="uploadConfig.placeholder || $t('ADD_FILE')" | ||
| 188 | + :readonly="true" | ||
| 189 | + :class="{ 'error-input': isError && !uploadConfig.isNeedClearError }" | ||
| 190 | + :disabled="uploadConfig.disabled" | ||
| 191 | + /> | ||
| 192 | + <el-button | ||
| 193 | + v-if="fileName && uploadConfig.type !== 'button' && !uploadConfig.disabled" | ||
| 194 | + class="upload-clear" | ||
| 195 | + text | ||
| 196 | + @click.stop="clearSelectedFile" | ||
| 197 | + > | ||
| 198 | + <el-icon> | ||
| 199 | + <IconXSolid /> | ||
| 200 | + </el-icon> | ||
| 201 | + </el-button> | ||
| 131 | <el-upload | 202 | <el-upload |
| 132 | :id="uploadConfig.id || 'fileUpload'" | 203 | :id="uploadConfig.id || 'fileUpload'" |
| 133 | ref="upload" | 204 | ref="upload" |
| 205 | + :class="{ 'input-upload-selector': uploadConfig.type !== 'button' }" | ||
| 134 | :disabled="uploadConfig.disabled" | 206 | :disabled="uploadConfig.disabled" |
| 135 | :action="uploadConfig.action" | 207 | :action="uploadConfig.action" |
| 136 | :name="uploadConfig.name" | 208 | :name="uploadConfig.name" |
| @@ -162,20 +234,15 @@ defineExpose({ | |||
| 162 | </el-icon> | 234 | </el-icon> |
| 163 | {{ $t('COMMON_UPLOAD') }} | 235 | {{ $t('COMMON_UPLOAD') }} |
| 164 | </el-button> | 236 | </el-button> |
| 165 | - <el-input | 237 | + <el-button |
| 166 | v-else | 238 | v-else |
| 167 | - v-model="fileName" | 239 | + class="upload-more-button" |
| 168 | - :placeholder="uploadConfig.placeholder || $t('ADD_FILE')" | ||
| 169 | - :readonly="true" | ||
| 170 | - :class="{ 'error-input': isError && !uploadConfig.isNeedClearError }" | ||
| 171 | :disabled="uploadConfig.disabled" | 240 | :disabled="uploadConfig.disabled" |
| 172 | > | 241 | > |
| 173 | - <template #suffix> | 242 | + <el-icon> |
| 174 | - <el-icon class="el-input__icon"> | 243 | + <IconMore /> |
| 175 | - <IconMore /> | 244 | + </el-icon> |
| 176 | - </el-icon> | 245 | + </el-button> |
| 177 | - </template> | ||
| 178 | - </el-input> | ||
| 179 | </template> | 246 | </template> |
| 180 | 247 | ||
| 181 | <span></span> | 248 | <span></span> |
| @@ -188,6 +255,7 @@ defineExpose({ | |||
| 188 | 255 | ||
| 189 | <style lang="scss" scoped> | 256 | <style lang="scss" scoped> |
| 190 | .file-upload { | 257 | .file-upload { |
| 258 | + position: relative; | ||
| 191 | display: inline-block; | 259 | display: inline-block; |
| 192 | .error-text { | 260 | .error-text { |
| 193 | display: inline-block; | 261 | display: inline-block; |
| @@ -205,26 +273,70 @@ defineExpose({ | |||
| 205 | .upload-button:hover { | 273 | .upload-button:hover { |
| 206 | color: var(--o-button-color_hover); | 274 | color: var(--o-button-color_hover); |
| 207 | } | 275 | } |
| 276 | + &.drag-over { | ||
| 277 | + :deep(.upload-display-input .el-input__inner) { | ||
| 278 | + border-color: var(--o-input-border-color_hover); | ||
| 279 | + box-shadow: 0 0 0 1px var(--o-input-border-color_hover) inset; | ||
| 280 | + } | ||
| 281 | + } | ||
| 208 | .disabled, | 282 | .disabled, |
| 209 | .disabled:hover { | 283 | .disabled:hover { |
| 210 | color: var(--o-button-color_disabled) !important; | 284 | color: var(--o-button-color_disabled) !important; |
| 211 | } | 285 | } |
| 212 | 286 | ||
| 213 | :deep(.el-input) { | 287 | :deep(.el-input) { |
| 214 | - .el-input__suffix .el-input__icon { | ||
| 215 | - margin-right: 0; | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | .el-input__inner { | 288 | .el-input__inner { |
| 219 | padding-top: 8px; | 289 | padding-top: 8px; |
| 220 | padding-bottom: 8px; | 290 | padding-bottom: 8px; |
| 291 | + padding-right: 56px; | ||
| 221 | } | 292 | } |
| 293 | + } | ||
| 222 | 294 | ||
| 223 | - &:hover { | 295 | + .upload-display-input { |
| 224 | - .el-input__suffix .el-input__icon { | 296 | + width: 100%; |
| 225 | - color: var(--o-input-border-color_hover); | 297 | + } |
| 226 | - } | 298 | + |
| 227 | - } | 299 | + .input-upload-selector { |
| 300 | + position: absolute; | ||
| 301 | + top: 0; | ||
| 302 | + right: 0; | ||
| 303 | + width: 32px; | ||
| 304 | + height: 32px; | ||
| 305 | + z-index: 2; | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + .upload-more-button { | ||
| 309 | + min-width: 32px; | ||
| 310 | + width: 32px; | ||
| 311 | + height: 32px; | ||
| 312 | + padding: 0; | ||
| 313 | + border: none; | ||
| 314 | + color: var(--o-text-color-secondary); | ||
| 315 | + background: transparent; | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + .upload-more-button:hover { | ||
| 319 | + color: var(--o-input-border-color_hover); | ||
| 320 | + background: transparent; | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + .upload-clear { | ||
| 324 | + position: absolute; | ||
| 325 | + top: -7px; | ||
| 326 | + right: -7px; | ||
| 327 | + z-index: 3; | ||
| 328 | + min-width: 16px; | ||
| 329 | + width: 16px; | ||
| 330 | + height: 16px; | ||
| 331 | + padding: 0; | ||
| 332 | + border: 1px solid var(--o-border-color-base); | ||
| 333 | + border-radius: 50%; | ||
| 334 | + color: var(--o-text-color-secondary); | ||
| 335 | + background: var(--o-bg-color-base); | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + .upload-clear:hover { | ||
| 339 | + color: var(--o-color-danger); | ||
| 228 | } | 340 | } |
| 229 | } | 341 | } |
| 230 | </style> | 342 | </style> |
| @@ -233,6 +345,12 @@ defineExpose({ | |||
| 233 | .el-upload { | 345 | .el-upload { |
| 234 | display: flex; | 346 | display: flex; |
| 235 | } | 347 | } |
| 348 | + .input-upload-selector { | ||
| 349 | + .el-upload { | ||
| 350 | + width: 100%; | ||
| 351 | + height: 100%; | ||
| 352 | + } | ||
| 353 | + } | ||
| 236 | .el-upload-list { | 354 | .el-upload-list { |
| 237 | display: none; | 355 | display: none; |
| 238 | } | 356 | } |
Msrc/pages/Manager/Upgrade/components/manual/SpUpgrade.vue+4-0File content is under review, please try again later
Msrc/pages/Manager/Upgrade/components/manual/UpgradeModeStep1.vue+10-1File content is under review, please try again later