86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
/**
|
||
* 设备设置页:点击设备名称行弹出弹窗编辑,确认后 PUT /bst/device
|
||
* 依赖页面存在:id、xqobj、this.$http;需引入 DeviceNameEditModal
|
||
*/
|
||
export default {
|
||
data() {
|
||
return {
|
||
deviceNameModalVisible: false,
|
||
deviceNameDraft: '',
|
||
deviceNameSaving: false
|
||
}
|
||
},
|
||
computed: {
|
||
deviceNameDisplayText() {
|
||
const o = this.xqobj || {}
|
||
const n = o.name
|
||
if (n !== undefined && n !== null && String(n).trim() !== '') return String(n).trim()
|
||
const p = o.productName
|
||
if (p !== undefined && p !== null && String(p).trim() !== '') return String(p).trim()
|
||
return '—'
|
||
}
|
||
},
|
||
methods: {
|
||
onDeviceNameRowTap() {
|
||
const o = this.xqobj || {}
|
||
const n = o.name
|
||
this.deviceNameDraft = n !== undefined && n !== null ? String(n) : ''
|
||
this.deviceNameModalVisible = true
|
||
},
|
||
closeDeviceNameModal() {
|
||
this.deviceNameModalVisible = false
|
||
},
|
||
onDeviceNameModalConfirm(name) {
|
||
if (this.deviceNameSaving) return
|
||
const trimmed = (name || '').trim()
|
||
if (!trimmed) {
|
||
uni.showToast({
|
||
title: this.$i18n.t('pleaseEnterDeviceName'),
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
const o = this.xqobj || {}
|
||
const cur = o.name != null ? String(o.name).trim() : ''
|
||
if (trimmed === cur) {
|
||
this.closeDeviceNameModal()
|
||
return
|
||
}
|
||
const spaceId =
|
||
typeof this.deviceRoomSpaceId === 'function'
|
||
? this.deviceRoomSpaceId()
|
||
: o.spaceId || uni.getStorageSync('kjid') || ''
|
||
const data = {
|
||
id: this.id,
|
||
sn: o.sn,
|
||
spaceId,
|
||
roomId: o.roomId,
|
||
name: trimmed
|
||
}
|
||
this.deviceNameSaving = true
|
||
this.$http
|
||
.put('/bst/device', data)
|
||
.then((res) => {
|
||
this.deviceNameSaving = false
|
||
if (res.code == 200) {
|
||
this.xqobj.name = trimmed
|
||
uni.showToast({
|
||
title: res.msg || this.$i18n.t('operationSuccess'),
|
||
icon: 'success'
|
||
})
|
||
uni.$emit('deviceListNeedRefresh')
|
||
this.closeDeviceNameModal()
|
||
} else {
|
||
uni.showToast({
|
||
title: res.msg || this.$i18n.t('noData'),
|
||
icon: 'none'
|
||
})
|
||
}
|
||
})
|
||
.catch(() => {
|
||
this.deviceNameSaving = false
|
||
})
|
||
}
|
||
}
|
||
}
|