Skip to content

Commit c87ed7f

Browse files
committed
【代码评审】IoT:数据桥梁的接入
1 parent 79507ae commit c87ed7f

File tree

12 files changed

+52
-39
lines changed

12 files changed

+52
-39
lines changed

src/api/iot/device/group/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ export interface DeviceGroupVO {
1111

1212
// IoT 设备分组 API
1313
export const DeviceGroupApi = {
14-
// 查询IoT 设备分组分页
14+
// 查询设备分组分页
1515
getDeviceGroupPage: async (params: any) => {
1616
return await request.get({ url: `/iot/device-group/page`, params })
1717
},
1818

19-
// 查询IoT 设备分组详情
19+
// 查询设备分组详情
2020
getDeviceGroup: async (id: number) => {
2121
return await request.get({ url: `/iot/device-group/get?id=` + id })
2222
},
2323

24-
// 新增IoT 设备分组
24+
// 新增设备分组
2525
createDeviceGroup: async (data: DeviceGroupVO) => {
2626
return await request.post({ url: `/iot/device-group/create`, data })
2727
},
2828

29-
// 修改IoT 设备分组
29+
// 修改设备分组
3030
updateDeviceGroup: async (data: DeviceGroupVO) => {
3131
return await request.put({ url: `/iot/device-group/update`, data })
3232
},
3333

34-
// 删除IoT 设备分组
34+
// 删除设备分组
3535
deleteDeviceGroup: async (id: number) => {
3636
return await request.delete({ url: `/iot/device-group/delete?id=` + id })
3737
},

src/api/iot/statistics/index.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import request from '@/config/axios'
22

3-
/** 统计数据类型 */
3+
/** IoT 统计数据类型 */
44
export interface IotStatisticsSummaryRespVO {
55
productCategoryCount: number
66
productCount: number
@@ -16,29 +16,26 @@ export interface IotStatisticsSummaryRespVO {
1616
productCategoryDeviceCounts: Record<string, number>
1717
}
1818

19-
/** 消息统计数据类型 */
19+
/** IoT 消息统计数据类型 */
2020
export interface IotStatisticsDeviceMessageSummaryRespVO {
2121
upstreamCounts: Record<number, number>
2222
downstreamCounts: Record<number, number>
2323
}
2424

2525
// IoT 数据统计 API
2626
export const ProductCategoryApi = {
27-
// 查询IoT基础数据统计
27+
// 查询基础的数据统计
2828
getIotStatisticsSummary: async () => {
29-
return await request.get<IotStatisticsSummaryRespVO>({
29+
return await request.get<IotStatisticsSummaryRespVO>({
3030
url: `/iot/statistics/get-summary`
3131
})
3232
},
3333

34-
// 查询IoT上下行消息数据统计
35-
getIotStatisticsDeviceMessageSummary: async (params: {
36-
startTime: number
37-
endTime: number
38-
}) => {
39-
return await request.get<IotStatisticsDeviceMessageSummaryRespVO>({
40-
url: `/iot/statistics/get-log-summary`,
41-
params
34+
// 查询设备上下行消息的数据统计
35+
getIotStatisticsDeviceMessageSummary: async (params: { startTime: number; endTime: number }) => {
36+
return await request.get<IotStatisticsDeviceMessageSummaryRespVO>({
37+
url: `/iot/statistics/get-log-summary`,
38+
params
4239
})
4340
}
44-
}
41+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
:disabled="formType === 'update'"
4444
/>
4545
</el-form-item>
46-
<el-form-item v-if="formData.deviceType === 1" label="网关设备" prop="gatewayId">
46+
<el-form-item
47+
v-if="formData.deviceType === DeviceTypeEnum.GATEWAY_SUB"
48+
label="网关设备"
49+
prop="gatewayId"
50+
>
4751
<el-select v-model="formData.gatewayId" placeholder="子设备可选择父设备" clearable>
4852
<el-option
4953
v-for="gateway in gatewayDevices"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { beginOfDay, dateFormatter, endOfDay, formatDate } from '@/utils/formatT
5959
6060
defineProps<{ product: ProductVO; device: DeviceVO }>()
6161
62-
/** IoT 设备 数据详情 */
62+
/** IoT 设备数据详情 */
6363
defineOptions({ name: 'IoTDeviceDataDetail' })
6464
6565
const dialogVisible = ref(false) // 弹窗的是否展示
@@ -78,9 +78,9 @@ const queryParams = reactive({
7878
formatDate(endOfDay(new Date()))
7979
]
8080
})
81-
8281
const queryFormRef = ref() // 搜索的表单
8382
83+
/** 获得设备历史数据 */
8484
const getList = async () => {
8585
detailLoading.value = true
8686
try {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
/>
3131
<div class="mt-5 text-center">
3232
<el-button v-if="isEditing" @click="cancelEdit">取消</el-button>
33-
<el-button v-if="isEditing" type="primary" @click="saveConfig" :disabled="hasJsonError"
34-
>保存</el-button
35-
>
33+
<el-button v-if="isEditing" type="primary" @click="saveConfig" :disabled="hasJsonError">
34+
保存
35+
</el-button>
3636
<el-button v-else @click="enableEdit">编辑</el-button>
3737
<!-- TODO @芋艿:缺一个下发按钮 -->
3838
</div>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,19 @@ const copyToClipboard = async (text: string) => {
120120
/** 打开 MQTT 参数弹框的方法 */
121121
const openMqttParams = async () => {
122122
try {
123-
const res = await DeviceApi.getMqttConnectionParams(device.id)
123+
const data = await DeviceApi.getMqttConnectionParams(device.id)
124124
// 根据 API 响应结构正确获取数据
125+
// TODO @haohao:'N/A' 是不是在 ui 里处理哈
125126
mqttParams.value = {
126-
mqttClientId: res.mqttClientId || 'N/A',
127-
mqttUsername: res.mqttUsername || 'N/A',
128-
mqttPassword: res.mqttPassword || 'N/A'
127+
mqttClientId: data.mqttClientId || 'N/A',
128+
mqttUsername: data.mqttUsername || 'N/A',
129+
mqttPassword: data.mqttPassword || 'N/A'
129130
}
130131
131132
// 显示 MQTT 弹框
132133
mqttDialogVisible.value = true
133134
} catch (error) {
134-
console.error('获取MQTT连接参数出错', error)
135+
console.error('获取 MQTT 连接参数出错', error)
135136
message.error('获取MQTT连接参数失败,请检查网络连接或联系管理员')
136137
}
137138
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ defineOptions({ name: 'IoTDeviceDetail' })
5151
5252
const route = useRoute()
5353
const message = useMessage()
54-
const id = Number(route.params.id) // 将字符串转换为数字
54+
const id = route.params.id // 将字符串转换为数字
5555
const loading = ref(true) // 加载中
5656
const product = ref<ProductVO>({} as ProductVO) // 产品详情
5757
const device = ref<DeviceVO>({} as DeviceVO) // 设备详情

src/views/iot/product/product/ProductForm.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</el-radio-group>
4646
</el-form-item>
4747
<el-form-item
48-
v-if="formData.deviceType === 0 || formData.deviceType === 2"
48+
v-if="[DeviceTypeEnum.DEVICE, DeviceTypeEnum.GATEWAY].includes(formData.deviceType)"
4949
label="联网方式"
5050
prop="netType"
5151
>
@@ -62,7 +62,11 @@
6262
/>
6363
</el-select>
6464
</el-form-item>
65-
<el-form-item v-if="formData.deviceType === 1" label="接入网关协议" prop="protocolType">
65+
<el-form-item
66+
v-if="formData.deviceType === DeviceTypeEnum.GATEWAY_SUB"
67+
label="接入网关协议"
68+
prop="protocolType"
69+
>
6670
<el-select
6771
v-model="formData.protocolType"
6872
placeholder="请选择接入网关协议"
@@ -120,7 +124,13 @@
120124
</template>
121125

122126
<script setup lang="ts">
123-
import { ValidateTypeEnum, ProductApi, ProductVO, DataFormatEnum } from '@/api/iot/product/product'
127+
import {
128+
ValidateTypeEnum,
129+
ProductApi,
130+
ProductVO,
131+
DataFormatEnum,
132+
DeviceTypeEnum
133+
} from '@/api/iot/product/product'
124134
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
125135
import { ProductCategoryApi, ProductCategoryVO } from '@/api/iot/product/category'
126136
import { UploadImg } from '@/components/UploadFile'

src/views/iot/product/product/detail/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const { currentRoute } = useRouter()
3434
3535
const route = useRoute()
3636
const message = useMessage()
37-
const id = Number(route.params.id) // 编号
37+
const id = route.params.id // 编号
3838
const loading = ref(true) // 加载中
3939
const product = ref<ProductVO>({} as ProductVO) // 详情
4040
const activeTab = ref('info') // 默认为 info 标签页

src/views/iot/rule/databridge/IoTDataBridgeForm.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ import {
8383
RocketMQConfigForm
8484
} from './config'
8585
86-
/** IoT 数据桥梁 表单 */
86+
/** IoT 数据桥梁的表单 */
8787
defineOptions({ name: 'IoTDataBridgeForm' })
8888
8989
const { t } = useI18n() // 国际化
@@ -95,8 +95,8 @@ const formLoading = ref(false) // 表单的加载中:1)修改时的数据加
9595
const formType = ref('') // 表单的类型:create - 新增;update - 修改
9696
const formData = ref<DataBridgeVO>({
9797
status: 0,
98-
direction: 1,
99-
type: 1,
98+
direction: 1, // TODO @puhui999:枚举类
99+
type: 1, // TODO @puhui999:枚举类
100100
config: {} as any
101101
})
102102
const formRules = reactive({

0 commit comments

Comments
 (0)