2024-12-09 14:16:57 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view class="modbus-edit-wrap">
|
|
|
|
|
<!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
|
|
|
|
|
<u--form labelPosition="left" :labelStyle="{marginRight:'10px'}" labelWidth="100" labelAlign="right"
|
|
|
|
|
:model="model" :rules="rules" ref="form">
|
|
|
|
|
<u-form-item :label="$tt('modbus.deviceName')" prop="name" required borderBottom>
|
|
|
|
|
<u--input v-model="model.name" border="none" clearable></u--input>
|
|
|
|
|
</u-form-item>
|
|
|
|
|
<u-form-item :label="$tt('modbus.firmware')" prop="version" required borderBottom>
|
|
|
|
|
<u--input v-model="model.version" type="number" border="none" clearable></u--input>
|
|
|
|
|
</u-form-item>
|
|
|
|
|
</u--form>
|
|
|
|
|
<view class="edit-bottom-wrap">
|
|
|
|
|
<view class="btn-wrap">
|
|
|
|
|
<u-button type="primary" @click="handleSaveClick">保存</u-button>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2025-03-27 14:23:27 +08:00
|
|
|
|
</template>
|
2024-12-09 14:16:57 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
2025-03-27 14:23:27 +08:00
|
|
|
|
import {
|
|
|
|
|
updateDevice
|
|
|
|
|
} from '@/apis/modules/device';
|
2024-12-09 14:16:57 +08:00
|
|
|
|
|
|
|
|
|
export default {
|
2025-03-27 14:23:27 +08:00
|
|
|
|
data() {
|
2024-12-09 14:16:57 +08:00
|
|
|
|
return {
|
|
|
|
|
model: {
|
|
|
|
|
name: '',
|
|
|
|
|
version: '',
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
'name': {
|
|
|
|
|
type: 'string',
|
|
|
|
|
required: true,
|
|
|
|
|
message: this.$tt('modbus.inputDeviceName'),
|
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
|
},
|
|
|
|
|
'version': {
|
|
|
|
|
type: 'number',
|
|
|
|
|
required: true,
|
|
|
|
|
message: this.$tt('modbus.inputVersion'),
|
|
|
|
|
trigger: ['blur', 'change']
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data: null
|
|
|
|
|
};
|
|
|
|
|
},
|
2025-03-27 14:23:27 +08:00
|
|
|
|
onReady() {
|
2024-12-09 14:16:57 +08:00
|
|
|
|
//如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
|
|
|
|
|
this.$refs.form.setRules(this.rules)
|
|
|
|
|
},
|
2025-03-27 14:23:27 +08:00
|
|
|
|
onLoad(option) {
|
2024-12-09 14:16:57 +08:00
|
|
|
|
this.data = JSON.parse(decodeURIComponent(option.item));
|
2025-03-27 14:23:27 +08:00
|
|
|
|
const {
|
|
|
|
|
deviceName,
|
|
|
|
|
firmwareVersion
|
|
|
|
|
} = this.data;
|
2024-12-09 14:16:57 +08:00
|
|
|
|
this.model.name = deviceName;
|
|
|
|
|
this.model.version = firmwareVersion;
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2025-03-27 14:23:27 +08:00
|
|
|
|
handleSaveClick() {
|
2024-12-09 14:16:57 +08:00
|
|
|
|
this.$refs.form.validate().then(res => {
|
|
|
|
|
this.updateDeviceData();
|
|
|
|
|
}).catch(errors => {
|
|
|
|
|
console.log('校验失败');
|
|
|
|
|
})
|
|
|
|
|
},
|
2025-03-27 14:23:27 +08:00
|
|
|
|
updateDeviceData() {
|
2024-12-09 14:16:57 +08:00
|
|
|
|
let device = {
|
|
|
|
|
...this.data,
|
|
|
|
|
deviceId: this.data.deviceId,
|
|
|
|
|
deviceName: this.model.name,
|
|
|
|
|
firmwareVersion: this.model.version
|
|
|
|
|
};
|
|
|
|
|
updateDevice(device).then(res => {
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: 'success',
|
|
|
|
|
title: this.$tt('common.updateSuccessful')
|
|
|
|
|
});
|
|
|
|
|
uni.navigateBack({
|
|
|
|
|
delta: 1,
|
|
|
|
|
success: (e) => {
|
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
let prePage = pages[pages.length - 1];
|
|
|
|
|
//#endif
|
|
|
|
|
// #ifdef H5 || APP-PLUS
|
|
|
|
|
let prePage = pages[pages.length - 2];
|
|
|
|
|
//#endif
|
|
|
|
|
// 更新数据列表
|
|
|
|
|
prePage.$vm.deviceForm.subDeviceList = [];
|
|
|
|
|
prePage.$vm.getDevice();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.modbus-edit-wrap {
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
2025-03-27 14:23:27 +08:00
|
|
|
|
::v-deep .u-form-item__body__left__content__required {
|
2024-12-09 14:16:57 +08:00
|
|
|
|
left: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.edit-bottom-wrap {
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: 50px;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
|
|
.btn-wrap {
|
|
|
|
|
padding: 0 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|