|
|
|
@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
|
|
<Dialog v-model="dialogVisible" title="导入采集点分类" width="400">
|
|
|
|
|
|
|
|
<el-upload
|
|
|
|
|
|
|
|
ref="uploadRef"
|
|
|
|
|
|
|
|
v-model:file-list="fileList"
|
|
|
|
|
|
|
|
:action="importUrl + '?updateSupport=' + updateSupport"
|
|
|
|
|
|
|
|
:auto-upload="false"
|
|
|
|
|
|
|
|
:disabled="formLoading"
|
|
|
|
|
|
|
|
:headers="uploadHeaders"
|
|
|
|
|
|
|
|
:limit="1"
|
|
|
|
|
|
|
|
:on-error="submitFormError"
|
|
|
|
|
|
|
|
:on-exceed="handleExceed"
|
|
|
|
|
|
|
|
:on-success="submitFormSuccess"
|
|
|
|
|
|
|
|
accept=".xlsx, .xls"
|
|
|
|
|
|
|
|
drag
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<Icon icon="ep:upload" />
|
|
|
|
|
|
|
|
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
|
|
|
|
|
|
<template #tip>
|
|
|
|
|
|
|
|
<div class="el-upload__tip text-center">
|
|
|
|
|
|
|
|
<span>仅允许导入 xls、xlsx 格式文件。</span>
|
|
|
|
|
|
|
|
<el-link
|
|
|
|
|
|
|
|
:underline="false"
|
|
|
|
|
|
|
|
style="font-size: 12px; vertical-align: baseline"
|
|
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
|
|
@click="importTemplate"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
下载导入模板
|
|
|
|
|
|
|
|
</el-link>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
|
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">{{ t('common.ok') }}</el-button>
|
|
|
|
|
|
|
|
<el-button @click="dialogVisible = false">{{ t('common.cancel') }}</el-button>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
|
|
|
import { getAccessToken, getTenantId } from '@/utils/auth'
|
|
|
|
|
|
|
|
import download from '@/utils/download'
|
|
|
|
|
|
|
|
import { DeviceAttributeTypeApi } from '@/api/iot/deviceattributetype'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'DeviceAttributeTypeImportForm' })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
const message = useMessage()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
|
|
|
const formLoading = ref(false)
|
|
|
|
|
|
|
|
const uploadRef = ref()
|
|
|
|
|
|
|
|
const importUrl =
|
|
|
|
|
|
|
|
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/iot/device-attribute-type/import'
|
|
|
|
|
|
|
|
const uploadHeaders = ref()
|
|
|
|
|
|
|
|
const fileList = ref([])
|
|
|
|
|
|
|
|
const updateSupport = ref(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const open = () => {
|
|
|
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
|
|
updateSupport.value = 0
|
|
|
|
|
|
|
|
fileList.value = []
|
|
|
|
|
|
|
|
resetForm()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defineExpose({ open })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const submitForm = async () => {
|
|
|
|
|
|
|
|
if (fileList.value.length === 0) {
|
|
|
|
|
|
|
|
message.error('请选择导入文件')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadHeaders.value = {
|
|
|
|
|
|
|
|
Authorization: 'Bearer ' + getAccessToken(),
|
|
|
|
|
|
|
|
tenantId: getTenantId()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
formLoading.value = true
|
|
|
|
|
|
|
|
uploadRef.value!.submit()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const emits = defineEmits(['success'])
|
|
|
|
|
|
|
|
const submitFormSuccess = (response: any) => {
|
|
|
|
|
|
|
|
if (response.code !== 0) {
|
|
|
|
|
|
|
|
message.error(response.msg)
|
|
|
|
|
|
|
|
formLoading.value = false
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
message.alert(response.data)
|
|
|
|
|
|
|
|
formLoading.value = false
|
|
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
|
|
emits('success')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const submitFormError = (): void => {
|
|
|
|
|
|
|
|
message.error('导入失败')
|
|
|
|
|
|
|
|
formLoading.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const resetForm = async (): Promise<void> => {
|
|
|
|
|
|
|
|
formLoading.value = false
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
|
|
|
|
uploadRef.value?.clearFiles()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleExceed = (): void => {
|
|
|
|
|
|
|
|
message.error('最多只能上传一个文件')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const importTemplate = async () => {
|
|
|
|
|
|
|
|
const res = await DeviceAttributeTypeApi.importTemplate()
|
|
|
|
|
|
|
|
download.excel(res, '采集点分类导入模板.xls')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|