|
|
|
|
@ -120,13 +120,22 @@
@@ -120,13 +120,22 @@
|
|
|
|
|
</el-scrollbar> |
|
|
|
|
</el-tab-pane> |
|
|
|
|
</el-tabs> |
|
|
|
|
<el-empty |
|
|
|
|
v-if="Object.keys(modelValue).length === 0" |
|
|
|
|
description="暂无设备类别,请点击上方按钮添加" |
|
|
|
|
/> |
|
|
|
|
<div v-if="Object.keys(modelValue).length === 0"> |
|
|
|
|
<div |
|
|
|
|
class="bg-white rounded-xl w-340 shadow-sm p-12 border-2 border-dashed border-gray-200 hover:border-blue-400 transition-all duration-300 cursor-pointer flex items-center justify-center min-h-[200px]" |
|
|
|
|
@click="handleAdd" |
|
|
|
|
> |
|
|
|
|
<div class="flex flex-col items-center gap-3"> |
|
|
|
|
<el-icon :size="48" class="text-gray-400"> |
|
|
|
|
<Plus /> |
|
|
|
|
</el-icon> |
|
|
|
|
<span class="text-base font-medium text-gray-600">新增设备类别</span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<el-empty description="暂无设备类别,请点击上方按钮添加" /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<!-- Create/Edit Category Dialog --> |
|
|
|
|
<el-dialog |
|
|
|
|
v-model="dialogVisible" |
|
|
|
|
:title="'新增设备类别'" |
|
|
|
|
@ -167,7 +176,7 @@ import { useRoute } from 'vue-router'
@@ -167,7 +176,7 @@ import { useRoute } from 'vue-router'
|
|
|
|
|
import { UploadFilled, Plus } from '@element-plus/icons-vue' |
|
|
|
|
import type { IDeviceCategoryList, IDeviceCategoryOV } from '@/api/module/device/index.d' |
|
|
|
|
import type { FormInstance, FormRules, UploadFile } from 'element-plus' |
|
|
|
|
import { ElMessage } from 'element-plus' |
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus' |
|
|
|
|
import { createDeviceType, uploadDeviceTypeFile } from '@/api/module/device/category' |
|
|
|
|
import { ChannelEnum } from '@/api/module/channel/index' |
|
|
|
|
import type { IChannelOV } from '@/api/module/channel/index.d' |
|
|
|
|
@ -271,7 +280,6 @@ const setUploadRef = (el: any, key: string) => {
@@ -271,7 +280,6 @@ const setUploadRef = (el: any, key: string) => {
|
|
|
|
|
|
|
|
|
|
const handleFileChange = async (file: UploadFile, fileName: string) => { |
|
|
|
|
if (!file.raw) return |
|
|
|
|
|
|
|
|
|
const controller = new AbortController() |
|
|
|
|
uploadControllers[fileName] = controller |
|
|
|
|
uploadingStates[fileName] = true |
|
|
|
|
@ -285,17 +293,15 @@ const handleFileChange = async (file: UploadFile, fileName: string) => {
@@ -285,17 +293,15 @@ const handleFileChange = async (file: UploadFile, fileName: string) => {
|
|
|
|
|
}, |
|
|
|
|
controller, |
|
|
|
|
) |
|
|
|
|
if (res.code === 0) { |
|
|
|
|
ElMessage.success('上传成功') |
|
|
|
|
emit('on-load-device-categoty') |
|
|
|
|
} else { |
|
|
|
|
ElMessage.error(res.msg || '上传失败') |
|
|
|
|
} |
|
|
|
|
} catch (error: any) { |
|
|
|
|
if (error.name === 'CanceledError' || error.message === 'canceled') { |
|
|
|
|
ElMessage.info('上传已取消') |
|
|
|
|
} else { |
|
|
|
|
ElMessage.error('上传失败') |
|
|
|
|
if (res) { |
|
|
|
|
if (res.code === 0) { |
|
|
|
|
ElMessage.success('上传成功') |
|
|
|
|
emit('on-load-device-categoty') |
|
|
|
|
} else if (res.code === 10001) { |
|
|
|
|
ElMessage.success('取消成功') |
|
|
|
|
} else { |
|
|
|
|
ElMessage.error(res.msg || '上传失败') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} finally { |
|
|
|
|
delete uploadControllers[fileName] |
|
|
|
|
@ -312,6 +318,48 @@ const handleCancelUpload = (fileName: string) => {
@@ -312,6 +318,48 @@ const handleCancelUpload = (fileName: string) => {
|
|
|
|
|
uploadingStates[fileName] = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check if there are any uploading files |
|
|
|
|
const hasUploadingFiles = () => { |
|
|
|
|
return Object.values(uploadingStates).some(state => state === true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Cancel all uploads |
|
|
|
|
const cancelAllUploads = () => { |
|
|
|
|
Object.keys(uploadControllers).forEach(fileName => { |
|
|
|
|
handleCancelUpload(fileName) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Check before leaving step |
|
|
|
|
const checkBeforeLeave = async (): Promise<boolean> => { |
|
|
|
|
if (!hasUploadingFiles()) { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
ElMessageBox.confirm( |
|
|
|
|
'当前有文件正在上传,离开将取消所有上传任务,是否确定离开?', |
|
|
|
|
'提示', |
|
|
|
|
{ |
|
|
|
|
confirmButtonText: '确定离开', |
|
|
|
|
cancelButtonText: '取消', |
|
|
|
|
type: 'warning', |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
.then(() => { |
|
|
|
|
cancelAllUploads() |
|
|
|
|
resolve(true) |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
resolve(false) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
defineExpose({ |
|
|
|
|
checkBeforeLeave, |
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
|
|