feat:【IoT 物联网】增加配置推送哈
This commit is contained in:
@ -20,13 +20,16 @@
|
|||||||
保存
|
保存
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button v-else @click="enableEdit">编辑</el-button>
|
<el-button v-else @click="enableEdit">编辑</el-button>
|
||||||
<!-- TODO @芋艿:缺一个下发按钮 -->
|
<el-button v-if="!isEditing" type="success" @click="handleConfigPush" :loading="pushLoading">
|
||||||
|
配置推送
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
|
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
|
||||||
|
import { IotDeviceMessageMethodEnum } from '@/views/iot/utils/constants'
|
||||||
import { jsonParse } from '@/utils'
|
import { jsonParse } from '@/utils'
|
||||||
import { isEmpty } from '@/utils/is'
|
import { isEmpty } from '@/utils/is'
|
||||||
|
|
||||||
@ -42,6 +45,7 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
const loading = ref(false) // 加载中
|
const loading = ref(false) // 加载中
|
||||||
|
const pushLoading = ref(false) // 推送加载中
|
||||||
const config = ref<any>({}) // 只存储 config 字段
|
const config = ref<any>({}) // 只存储 config 字段
|
||||||
const hasJsonError = ref(false) // 是否有 JSON 格式错误
|
const hasJsonError = ref(false) // 是否有 JSON 格式错误
|
||||||
|
|
||||||
@ -74,6 +78,32 @@ const saveConfig = async () => {
|
|||||||
isEditing.value = false
|
isEditing.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 配置推送处理函数 */
|
||||||
|
const handleConfigPush = async () => {
|
||||||
|
try {
|
||||||
|
// 二次确认
|
||||||
|
await message.confirm('确定要推送配置到设备吗?此操作将远程更新设备配置。', '配置推送确认')
|
||||||
|
|
||||||
|
pushLoading.value = true
|
||||||
|
|
||||||
|
// 调用配置推送接口
|
||||||
|
await DeviceApi.sendDeviceMessage({
|
||||||
|
deviceId: props.device.id,
|
||||||
|
method: IotDeviceMessageMethodEnum.CONFIG_PUSH.method,
|
||||||
|
params: config.value
|
||||||
|
})
|
||||||
|
|
||||||
|
message.success('配置推送成功!')
|
||||||
|
} catch (error) {
|
||||||
|
if (error !== 'cancel') {
|
||||||
|
message.error('配置推送失败!')
|
||||||
|
console.error('配置推送错误:', error)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
pushLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 更新设备配置 */
|
/** 更新设备配置 */
|
||||||
const updateDeviceConfig = async () => {
|
const updateDeviceConfig = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
</el-button-group>
|
</el-button-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<!-- TODO @芋艿:参考阿里云,实时刷新! -->
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-switch
|
<el-switch
|
||||||
size="large"
|
size="large"
|
||||||
|
|||||||
@ -43,5 +43,12 @@ export const IotDeviceMessageMethodEnum = {
|
|||||||
method: 'thing.service.invoke',
|
method: 'thing.service.invoke',
|
||||||
name: '服务调用',
|
name: '服务调用',
|
||||||
upstream: false
|
upstream: false
|
||||||
|
},
|
||||||
|
|
||||||
|
// ========== 设备配置 ==========
|
||||||
|
CONFIG_PUSH: {
|
||||||
|
method: 'thing.config.push',
|
||||||
|
name: '配置推送',
|
||||||
|
upstream: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user