|
|
|
|
@ -76,6 +76,9 @@
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="ep:delete" class="mr-5px" /> {{ t('DataCollection.Device.batchDelete') }}
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-button type="primary" plain @click="openBatchEdit" v-hasPermi="['iot:device:update']">
|
|
|
|
|
<Icon icon="ep:edit" class="mr-5px" /> 批量编辑
|
|
|
|
|
</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</ContentWrap>
|
|
|
|
|
@ -137,7 +140,11 @@ ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-to
|
|
|
|
|
align="center"
|
|
|
|
|
prop="dataUnit"
|
|
|
|
|
width="80px"
|
|
|
|
|
/>
|
|
|
|
|
>
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
{{ formatDataUnit(scope.row.dataUnit) }}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
:label="t('DataCollection.Device.ratio')"
|
|
|
|
|
align="center"
|
|
|
|
|
@ -193,6 +200,27 @@ ref="planPaginationRef"
|
|
|
|
|
<DeviceAttributeForm ref="formRef" @success="getList" />
|
|
|
|
|
|
|
|
|
|
<!-- 单位导入对话框 -->
|
|
|
|
|
<Dialog title="批量编辑" v-model="batchEditVisible">
|
|
|
|
|
<el-form ref="batchEditFormRef" :model="batchEditForm" label-width="120px">
|
|
|
|
|
<el-form-item :label="t('DataCollection.Device.attributeType')">
|
|
|
|
|
<el-select v-model="batchEditForm.attributeType" clearable filterable :placeholder="t('DataCollection.Device.placeholderAttributeType')" class="w-1/1">
|
|
|
|
|
<el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="t('DataCollection.Device.dataUnit')">
|
|
|
|
|
<el-select v-model="batchEditForm.dataUnit" clearable :placeholder="t('DataCollection.DeviceModel.placeholderDataUnit')" class="w-1/1">
|
|
|
|
|
<el-option v-for="unit in unitList" :key="unit.id" :label="unit.name" :value="unit.id" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="t('DataCollection.Device.ratio')">
|
|
|
|
|
<el-input-number v-model="batchEditForm.ratio" :placeholder="t('DataCollection.Device.placeholderRatio')" :min="0" :precision="2" :step="0.01" class="!w-full" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<el-button @click="batchEditVisible = false">{{ t('common.cancel') }}</el-button>
|
|
|
|
|
<el-button type="primary" :loading="batchEditLoading" @click="handleBatchEdit">{{ t('common.ok') }}</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</Dialog>
|
|
|
|
|
<DeviceAttributeImportForm ref="importFormRef" @success="getList" />
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
@ -203,6 +231,7 @@ import { DeviceApi } from '@/api/iot/device'
|
|
|
|
|
import DeviceAttributeForm from './DeviceAttributeForm.vue'
|
|
|
|
|
import DeviceAttributeImportForm from './DeviceAttributeImportForm.vue'
|
|
|
|
|
import { DeviceAttributeTypeApi, DeviceAttributeTypeVO } from '@/api/iot/deviceattributetype'
|
|
|
|
|
import { ProductUnitApi, ProductUnitVO } from '@/api/erp/product/unit'
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n() // 国际化
|
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
|
|
@ -225,6 +254,7 @@ const props = defineProps<{
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const typeList = ref<DeviceAttributeTypeVO[]>([])
|
|
|
|
|
const unitList = ref<ProductUnitVO[]>([])
|
|
|
|
|
|
|
|
|
|
const loading = ref(false) // 列表的加载中
|
|
|
|
|
const list = ref([]) // 列表的数据
|
|
|
|
|
@ -252,6 +282,19 @@ const formatAddressValue = (value: unknown) => {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const loadUnitList = async () => {
|
|
|
|
|
if (unitList.value.length) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
unitList.value = await ProductUnitApi.getProductUnitSimpleList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formatDataUnit = (value: unknown) => {
|
|
|
|
|
if (value === null || value === undefined || value === '') {
|
|
|
|
|
return '-'
|
|
|
|
|
}
|
|
|
|
|
return unitList.value.find((unit) => String(unit.id) === String(value))?.name ?? String(value)
|
|
|
|
|
}
|
|
|
|
|
const selectedIds = ref<number[]>([])
|
|
|
|
|
const handleSelectionChange = (rows: any[]) => {
|
|
|
|
|
selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? []
|
|
|
|
|
@ -353,6 +396,51 @@ const handleBatchDelete = async () => {
|
|
|
|
|
await handleDelete(selectedIds.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const batchEditVisible = ref(false)
|
|
|
|
|
const batchEditLoading = ref(false)
|
|
|
|
|
const batchEditFormRef = ref()
|
|
|
|
|
const batchEditForm = reactive({
|
|
|
|
|
attributeType: undefined as number | undefined,
|
|
|
|
|
dataUnit: undefined as string | undefined,
|
|
|
|
|
ratio: undefined as number | undefined
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const resetBatchEditForm = () => {
|
|
|
|
|
batchEditForm.attributeType = undefined
|
|
|
|
|
batchEditForm.dataUnit = undefined
|
|
|
|
|
batchEditForm.ratio = undefined
|
|
|
|
|
batchEditFormRef.value?.resetFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const openBatchEdit = async () => {
|
|
|
|
|
if (!selectedIds.value.length) {
|
|
|
|
|
message.error('请选择需要编辑的数据')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resetBatchEditForm()
|
|
|
|
|
await loadUnitList()
|
|
|
|
|
|
|
|
|
|
batchEditVisible.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleBatchEdit = async () => {
|
|
|
|
|
try {
|
|
|
|
|
batchEditLoading.value = true
|
|
|
|
|
await DeviceApi.batchUpdateDeviceAttribute({
|
|
|
|
|
ids: selectedIds.value,
|
|
|
|
|
attributeType: batchEditForm.attributeType,
|
|
|
|
|
dataUnit: batchEditForm.dataUnit,
|
|
|
|
|
ratio: batchEditForm.ratio
|
|
|
|
|
})
|
|
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
|
|
batchEditVisible.value = false
|
|
|
|
|
selectedIds.value = []
|
|
|
|
|
tableRef.value?.clearSelection?.()
|
|
|
|
|
await getList()
|
|
|
|
|
} finally {
|
|
|
|
|
batchEditLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** 导入 */
|
|
|
|
|
const importFormRef = ref()
|
|
|
|
|
const handleImport = () => {
|
|
|
|
|
@ -393,6 +481,11 @@ onMounted(async () => {
|
|
|
|
|
} catch {
|
|
|
|
|
typeList.value = []
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await loadUnitList()
|
|
|
|
|
} catch {
|
|
|
|
|
unitList.value = []
|
|
|
|
|
}
|
|
|
|
|
updatePlanTableMaxHeight()
|
|
|
|
|
window.addEventListener('resize', updatePlanTableMaxHeight)
|
|
|
|
|
})
|
|
|
|
|
|