Skip to content

Commit 53c967c

Browse files
author
puhui999
committed
Merge remote-tracking branch 'yudao/feature/iot' into feature/iot
# Conflicts: # src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue # src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue # src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue # src/views/iot/thinkmodel/ThinkModelForm.vue # src/views/iot/thinkmodel/dataSpecs/ThinkModelArrayTypeDataSpecs.vue
2 parents 341eb57 + fe3715c commit 53c967c

File tree

18 files changed

+692
-43
lines changed

18 files changed

+692
-43
lines changed

src/api/iot/device/index.ts renamed to src/api/iot/device/device/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ export interface DeviceHistoryDataVO {
5555
data: string // 数据
5656
}
5757

58+
// IoT 设备状态枚举
59+
export enum DeviceStatusEnum {
60+
INACTIVE = 0, // 未激活
61+
ONLINE = 1, // 在线
62+
OFFLINE = 2, // 离线
63+
DISABLED = 3 // 已禁用
64+
}
65+
5866
// 设备 API
5967
export const DeviceApi = {
6068
// 查询设备分页
@@ -115,13 +123,18 @@ export const DeviceApi = {
115123
return await request.get({ url: `/iot/device/simple-list?`, params: { deviceType } })
116124
},
117125

118-
// 获取设备属性最新数据
126+
// 获取设备属性最���数据
119127
getDevicePropertiesLatestData: async (params: any) => {
120128
return await request.get({ url: `/iot/device/data/latest`, params })
121129
},
122130

123131
// 获取设备属性历史数据
124132
getDevicePropertiesHistoryData: async (params: any) => {
125133
return await request.get({ url: `/iot/device/data/history`, params })
134+
},
135+
136+
// 获取导入模板
137+
importDeviceTemplate: async () => {
138+
return await request.download({ url: `/iot/device/get-import-template` })
126139
}
127140
}

src/api/iot/plugininfo/index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import request from '@/config/axios'
2+
3+
// IoT 插件信息 VO
4+
export interface PluginInfoVO {
5+
id: number // 主键ID
6+
pluginId: string // 插件包id
7+
name: string // 插件名称
8+
description: string // 描述
9+
deployType: number // 部署方式
10+
file: string // 插件包文件名
11+
version: string // 插件版本
12+
type: number // 插件类型
13+
protocol: string // 设备插件协议类型
14+
status: number // 状态
15+
configSchema: string // 插件配置项描述信息
16+
config: string // 插件配置信息
17+
script: string // 插件脚本
18+
}
19+
20+
// IoT 插件信息 API
21+
export const PluginInfoApi = {
22+
// 查询IoT 插件信息分页
23+
getPluginInfoPage: async (params: any) => {
24+
return await request.get({ url: `/iot/plugin-info/page`, params })
25+
},
26+
27+
// 查询IoT 插件信息详情
28+
getPluginInfo: async (id: number) => {
29+
return await request.get({ url: `/iot/plugin-info/get?id=` + id })
30+
},
31+
32+
// 新增IoT 插件信息
33+
createPluginInfo: async (data: PluginInfoVO) => {
34+
return await request.post({ url: `/iot/plugin-info/create`, data })
35+
},
36+
37+
// 修改IoT 插件信息
38+
updatePluginInfo: async (data: PluginInfoVO) => {
39+
return await request.put({ url: `/iot/plugin-info/update`, data })
40+
},
41+
42+
// 删除IoT 插件信息
43+
deletePluginInfo: async (id: number) => {
44+
return await request.delete({ url: `/iot/plugin-info/delete?id=` + id })
45+
},
46+
47+
// 导出IoT 插件信息 Excel
48+
exportPluginInfo: async (params) => {
49+
return await request.download({ url: `/iot/plugin-info/export-excel`, params })
50+
}
51+
}

src/api/iot/thinkmodel/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum ProductFunctionAccessModeEnum {
5151
READ_ONLY = 'r' // 只读
5252
}
5353

54+
// TODO @puhui999:getProductThingModelPage => getThingModelPage 哈,不用带 product 前缀
5455
// IoT 产品物模型 API
5556
export const ThinkModelApi = {
5657
// 查询产品物模型分页

src/utils/dict.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,8 @@ export enum DICT_TYPE {
239239
IOT_PRODUCT_FUNCTION_TYPE = 'iot_product_function_type', // IOT 产品功能类型
240240
IOT_DATA_TYPE = 'iot_data_type', // IOT 数据类型
241241
IOT_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型
242-
IOT_RW_TYPE = 'iot_rw_type' // IOT 读写类型
242+
IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型
243+
IOT_PLUGIN_DEPLOY_TYPE = 'iot_plugin_deploy_type', // IOT 插件部署类型
244+
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态
245+
IOT_PLUGIN_TYPE = 'iot_plugin_type' // IOT 插件类型
243246
}

src/views/iot/device/device/DeviceForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</Dialog>
8686
</template>
8787
<script setup lang="ts">
88-
import { DeviceApi, DeviceVO } from '@/api/iot/device'
88+
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
8989
import { DeviceGroupApi } from '@/api/iot/device/group'
9090
import { DeviceTypeEnum, ProductApi, ProductVO } from '@/api/iot/product/product'
9191
import { UploadImg } from '@/components/UploadFile'

src/views/iot/device/device/DeviceGroupForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</template>
2727

2828
<script setup lang="ts">
29-
import { DeviceApi } from '@/api/iot/device'
29+
import { DeviceApi } from '@/api/iot/device/device'
3030
import { DeviceGroupApi } from '@/api/iot/device/group'
3131
3232
defineOptions({ name: 'IoTDeviceGroupForm' })
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<template>
2+
<Dialog v-model="dialogVisible" title="设备导入" width="400">
3+
<el-upload
4+
ref="uploadRef"
5+
v-model:file-list="fileList"
6+
:action="importUrl + '?updateSupport=' + updateSupport"
7+
:auto-upload="false"
8+
:disabled="formLoading"
9+
:headers="uploadHeaders"
10+
:limit="1"
11+
:on-error="submitFormError"
12+
:on-exceed="handleExceed"
13+
:on-success="submitFormSuccess"
14+
accept=".xlsx, .xls"
15+
drag
16+
>
17+
<Icon icon="ep:upload" />
18+
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
19+
<template #tip>
20+
<div class="el-upload__tip text-center">
21+
<div class="el-upload__tip">
22+
<el-checkbox v-model="updateSupport" />
23+
是否更新已经存在的设备数据
24+
</div>
25+
<span>仅允许导入 xls、xlsx 格式文件。</span>
26+
<el-link
27+
:underline="false"
28+
style="font-size: 12px; vertical-align: baseline"
29+
type="primary"
30+
@click="importTemplate"
31+
>
32+
下载模板
33+
</el-link>
34+
</div>
35+
</template>
36+
</el-upload>
37+
<template #footer>
38+
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
39+
<el-button @click="dialogVisible = false">取 消</el-button>
40+
</template>
41+
</Dialog>
42+
</template>
43+
44+
<script lang="ts" setup>
45+
import { DeviceApi } from '@/api/iot/device/device'
46+
import { getAccessToken, getTenantId } from '@/utils/auth'
47+
import download from '@/utils/download'
48+
49+
defineOptions({ name: 'IoTDeviceImportForm' })
50+
51+
const message = useMessage() // 消息弹窗
52+
53+
const dialogVisible = ref(false) // 弹窗的是否展示
54+
const formLoading = ref(false) // 表单的加载中
55+
const uploadRef = ref()
56+
const importUrl =
57+
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/iot/device/import'
58+
const uploadHeaders = ref() // 上传 Header 头
59+
const fileList = ref([]) // 文件列表
60+
const updateSupport = ref(0) // 是否更新已经存在的设备数据
61+
62+
/** 打开弹窗 */
63+
const open = () => {
64+
dialogVisible.value = true
65+
updateSupport.value = 0
66+
fileList.value = []
67+
resetForm()
68+
}
69+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
70+
71+
/** 提交表单 */
72+
const submitForm = async () => {
73+
if (fileList.value.length == 0) {
74+
message.error('请上传文件')
75+
return
76+
}
77+
// 提交请求
78+
uploadHeaders.value = {
79+
Authorization: 'Bearer ' + getAccessToken(),
80+
'tenant-id': getTenantId()
81+
}
82+
formLoading.value = true
83+
uploadRef.value!.submit()
84+
}
85+
86+
/** 文件上传成功 */
87+
const emits = defineEmits(['success'])
88+
const submitFormSuccess = (response: any) => {
89+
if (response.code !== 0) {
90+
message.error(response.msg)
91+
formLoading.value = false
92+
return
93+
}
94+
// 拼接提示语
95+
const data = response.data
96+
let text = '上传成功数量:' + data.createDeviceNames.length + ';'
97+
for (let deviceName of data.createDeviceNames) {
98+
text += '< ' + deviceName + ' >'
99+
}
100+
text += '更新成功数量:' + data.updateDeviceNames.length + ';'
101+
for (const deviceName of data.updateDeviceNames) {
102+
text += '< ' + deviceName + ' >'
103+
}
104+
text += '更新失败数量:' + Object.keys(data.failureDeviceNames).length + ';'
105+
for (const deviceName in data.failureDeviceNames) {
106+
text += '< ' + deviceName + ': ' + data.failureDeviceNames[deviceName] + ' >'
107+
}
108+
message.alert(text)
109+
formLoading.value = false
110+
dialogVisible.value = false
111+
// 发送操作成功的事件
112+
emits('success')
113+
}
114+
115+
/** 上传错误提示 */
116+
const submitFormError = (): void => {
117+
message.error('上传失败,请您重新上传!')
118+
formLoading.value = false
119+
}
120+
121+
/** 重置表单 */
122+
const resetForm = async (): Promise<void> => {
123+
// 重置上传状态和文件
124+
formLoading.value = false
125+
await nextTick()
126+
uploadRef.value?.clearFiles()
127+
}
128+
129+
/** 文件数超出提示 */
130+
const handleExceed = (): void => {
131+
message.error('最多只能上传一个文件!')
132+
}
133+
134+
/** 下载模板操作 */
135+
const importTemplate = async () => {
136+
const res = await DeviceApi.importDeviceTemplate()
137+
download.excel(res, '设备导入模版.xls')
138+
}
139+
</script>

src/views/iot/device/device/detail/DeviceDataDetail.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@
5353
</Dialog>
5454
</template>
5555
<script setup lang="ts">
56-
import { DeviceApi, DeviceHistoryDataVO, DeviceVO } from '@/api/iot/device'
56+
import { DeviceApi, DeviceHistoryDataVO, DeviceVO } from '@/api/iot/device/device'
5757
import { ProductVO } from '@/api/iot/product/product'
5858
import { beginOfDay, dateFormatter, endOfDay, formatDate } from '@/utils/formatTime'
59-
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
6059
6160
const props = defineProps<{ product: ProductVO; device: DeviceVO }>()
6261

src/views/iot/device/device/detail/DeviceDetailsHeader.vue

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,22 @@
3535
<DeviceForm ref="formRef" @success="emit('refresh')" />
3636
</template>
3737
<script setup lang="ts">
38-
import { ref } from 'vue'
39-
import DeviceForm from '@/views/iot/device/DeviceForm.vue'
38+
import DeviceForm from '@/views/iot/device/device/DeviceForm.vue'
4039
import { ProductVO } from '@/api/iot/product/product'
41-
import { DeviceVO } from '@/api/iot/device'
42-
import { useRouter } from 'vue-router'
40+
import { DeviceVO } from '@/api/iot/device/device'
4341
4442
const message = useMessage()
4543
const router = useRouter()
4644
47-
// 操作修改
45+
const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>()
46+
const emit = defineEmits(['refresh'])
47+
48+
/** 操作修改 */
4849
const formRef = ref()
4950
const openForm = (type: string, id?: number) => {
5051
formRef.value.open(type, id)
5152
}
5253
53-
const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>()
54-
const emit = defineEmits(['refresh'])
55-
5654
/** 复制到剪贴板方法 */
5755
const copyToClipboard = async (text: string) => {
5856
try {
@@ -63,11 +61,7 @@ const copyToClipboard = async (text: string) => {
6361
}
6462
}
6563
66-
/**
67-
* 跳转到产品详情页面
68-
*
69-
* @param productId 产品 ID
70-
*/
64+
/** 跳转到产品详情页面 */
7165
const goToProductDetail = (productId: number) => {
7266
router.push({ name: 'IoTProductDetail', params: { id: productId } })
7367
}

src/views/iot/device/device/detail/DeviceDetailsInfo.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,14 @@
7979
</ContentWrap>
8080
</template>
8181
<script setup lang="ts">
82-
import { ref } from 'vue'
8382
import { DICT_TYPE } from '@/utils/dict'
8483
import { ProductVO } from '@/api/iot/product/product'
8584
import { formatDate } from '@/utils/formatTime'
86-
import { DeviceVO } from '@/api/iot/device'
85+
import { DeviceVO } from '@/api/iot/device/device'
8786
8887
const message = useMessage() // 消息提示
8988
9089
const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>() // 定义 Props
91-
9290
const emit = defineEmits(['refresh']) // 定义 Emits
9391
9492
const activeNames = ref(['basicInfo']) // 展示的折叠面板

0 commit comments

Comments
 (0)