|
|
@@ -14,11 +14,12 @@
|
|
|
:items="tabs"
|
|
|
:active.sync="active"
|
|
|
/>
|
|
|
- <div class="l-flex__auto has-bottom-padding u-overflow-y--auto">
|
|
|
+ <div class="l-flex__auto has-bottom-padding u-align-self--center u-overflow-y--auto">
|
|
|
<wired
|
|
|
v-if="isWired"
|
|
|
key="wired"
|
|
|
- :wired="wired"
|
|
|
+ :eth.sync="eth"
|
|
|
+ :eths="eths"
|
|
|
/>
|
|
|
<wireless
|
|
|
v-if="isWireless"
|
|
|
@@ -31,6 +32,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import {
|
|
|
+ publish,
|
|
|
+ subscribe,
|
|
|
+ unsubscribe
|
|
|
+} from '@/utils/mqtt'
|
|
|
import {
|
|
|
validIP4,
|
|
|
validIP6
|
|
|
@@ -41,7 +47,7 @@ import Wired from './Wired'
|
|
|
import Wireless from './Wireless'
|
|
|
|
|
|
export default {
|
|
|
- name: 'ScreenNetwork',
|
|
|
+ name: 'DeviceNetwork',
|
|
|
components: {
|
|
|
Tabs,
|
|
|
Wired,
|
|
|
@@ -51,30 +57,121 @@ export default {
|
|
|
data () {
|
|
|
return {
|
|
|
tabs: [
|
|
|
- { key: 'wired', name: '有线网络' },
|
|
|
- { key: 'wireless', name: '无线网络' }
|
|
|
+ { key: 'wired', name: '有线网络' }/* ,
|
|
|
+ { key: 'wireless', name: '无线网络' } */
|
|
|
],
|
|
|
active: null,
|
|
|
- wired: null,
|
|
|
+ eth: '0',
|
|
|
+ eths: null,
|
|
|
wireless: null
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
+ topic () {
|
|
|
+ return `${this.device.productId}/${this.deviceId}/function/invoke/reply`
|
|
|
+ },
|
|
|
isWired () {
|
|
|
return this.active === 'wired'
|
|
|
},
|
|
|
+ wired () {
|
|
|
+ return this.eths?.[this.eth]
|
|
|
+ },
|
|
|
isWireless () {
|
|
|
return this.active === 'wireless'
|
|
|
}
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ online () {
|
|
|
+ if (this.online) {
|
|
|
+ subscribe([this.topic], this.onMessage)
|
|
|
+ } else {
|
|
|
+ clearTimeout(this.$timer)
|
|
|
+ unsubscribe([this.topic], this.onMessage)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created () {
|
|
|
+ this.$timer = -1
|
|
|
+ this.online && subscribe([this.topic], this.onMessage)
|
|
|
+ },
|
|
|
+ beforeDestroy () {
|
|
|
+ clearTimeout(this.$timer)
|
|
|
+ this.online && unsubscribe([this.topic], this.onMessage)
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ onMessage (topic, message) {
|
|
|
+ if (topic === this.topic) {
|
|
|
+ message = JSON.parse(message)
|
|
|
+ if (message.messageId === this.$messageId) {
|
|
|
+ this.closeLoading()
|
|
|
+ try {
|
|
|
+ const eths = JSON.parse(message.output)
|
|
|
+ if (eths?.length) {
|
|
|
+ this.showNetwork(eths)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '未发现设备网口,请稍后再试'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
invoke () {
|
|
|
- this.active = 'wired'
|
|
|
- this.wired = {
|
|
|
- mode: 'dhcp',
|
|
|
- ip4: this.createIPSetting(),
|
|
|
- ip6: this.createIPSetting(true)
|
|
|
+ if (!this.online) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '设备未上线,请稍后再试'
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
+ this.fetchNetwork()
|
|
|
+ },
|
|
|
+ fetchNetwork () {
|
|
|
+ this.$loadingDialog = this.$showLoading()
|
|
|
+ clearTimeout(this.$timer)
|
|
|
+ this.$messageId = `${Date.now()}`
|
|
|
+ publish(
|
|
|
+ `${this.device.productId}/${this.deviceId}/function/invoke`,
|
|
|
+ JSON.stringify({
|
|
|
+ messageId: this.$messageId,
|
|
|
+ timestamp: Date.now(),
|
|
|
+ 'function': 'network',
|
|
|
+ inputs: []
|
|
|
+ }),
|
|
|
+ true
|
|
|
+ ).then(
|
|
|
+ () => {
|
|
|
+ this.$timer = setTimeout(() => {
|
|
|
+ this.closeLoading()
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '未获取到设备网络状态,请稍后再试'
|
|
|
+ })
|
|
|
+ }, 5000)
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ this.closeLoading()
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '正在连接,请稍后再试'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ )
|
|
|
+ },
|
|
|
+ closeLoading () {
|
|
|
+ clearTimeout(this.$timer)
|
|
|
+ this.$messageId = null
|
|
|
+ this.$closeLoading(this.$loadingDialog)
|
|
|
+ this.$loadingDialog = null
|
|
|
+ },
|
|
|
+ showNetwork (eths) {
|
|
|
+ this.active = 'wired'
|
|
|
+ this.eth = '0'
|
|
|
+ this.eths = eths.map(eth => this.createEth(eth))
|
|
|
this.wireless = {
|
|
|
enable: true,
|
|
|
name: '',
|
|
|
@@ -83,11 +180,27 @@ export default {
|
|
|
}
|
|
|
this.$refs.networkDialg.show()
|
|
|
},
|
|
|
- createIPSetting (ip6) {
|
|
|
+ createEth (eth) {
|
|
|
+ const { name, setting, address, subnetMask, defaultGateway, preferredDNS, alternativeDNS } = eth
|
|
|
+ return {
|
|
|
+ name,
|
|
|
+ mode: setting === 'manual' ? 'manual' : 'dhcp',
|
|
|
+ ip4: {
|
|
|
+ enable: true,
|
|
|
+ address: address || '',
|
|
|
+ mask: subnetMask || '',
|
|
|
+ gateway: defaultGateway || '',
|
|
|
+ dns1: preferredDNS || '',
|
|
|
+ dns2: alternativeDNS || ''
|
|
|
+ },
|
|
|
+ ip6: this.createIPv6Setting()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ createIPv6Setting (ip6) {
|
|
|
return {
|
|
|
enable: false,
|
|
|
address: '',
|
|
|
- mask: ip6 ? 32 : '',
|
|
|
+ mask: 32,
|
|
|
gateway: '',
|
|
|
dns1: '',
|
|
|
dns2: ''
|
|
|
@@ -101,25 +214,24 @@ export default {
|
|
|
if (!this.validWired()) {
|
|
|
return
|
|
|
}
|
|
|
- const { mode, ip4, ip6 } = this.wired
|
|
|
+ const { name, mode, ip4, ip6 } = this.wired
|
|
|
const inputs = []
|
|
|
if (mode === 'dhcp') {
|
|
|
inputs.push({
|
|
|
- name: 'ip4',
|
|
|
+ name,
|
|
|
value: JSON.stringify({ setting: mode })
|
|
|
})
|
|
|
inputs.push({
|
|
|
- name: 'ip6',
|
|
|
+ name: `${name}-ipv6`,
|
|
|
value: JSON.stringify({ setting: mode })
|
|
|
})
|
|
|
} else {
|
|
|
if (ip4.enable) {
|
|
|
const { address, mask, gateway, dns1, dns2 } = ip4
|
|
|
inputs.push({
|
|
|
- name: 'ip4',
|
|
|
+ name,
|
|
|
value: JSON.stringify({
|
|
|
setting: mode,
|
|
|
- enable: 1,
|
|
|
address,
|
|
|
subnetMask: mask,
|
|
|
defaultGateway: gateway,
|
|
|
@@ -127,19 +239,14 @@ export default {
|
|
|
alternativeDNS: dns2
|
|
|
})
|
|
|
})
|
|
|
- } else {
|
|
|
- inputs.push({
|
|
|
- name: 'ip4',
|
|
|
- value: JSON.stringify({ setting: mode, enable: 0 })
|
|
|
- })
|
|
|
}
|
|
|
if (ip6.enable) {
|
|
|
const { address, mask, gateway, dns1, dns2 } = ip6
|
|
|
inputs.push({
|
|
|
- name: 'ip6',
|
|
|
+ name: `${name}-ipv6`,
|
|
|
value: JSON.stringify({
|
|
|
+ name,
|
|
|
setting: mode,
|
|
|
- enable: 1,
|
|
|
address,
|
|
|
subnetPrefixLegth: mask,
|
|
|
defaultGateway: gateway,
|
|
|
@@ -147,15 +254,10 @@ export default {
|
|
|
alternativeDNS: dns2
|
|
|
})
|
|
|
})
|
|
|
- } else {
|
|
|
- inputs.push({
|
|
|
- name: 'ip6',
|
|
|
- value: JSON.stringify({ setting: mode, enable: 0 })
|
|
|
- })
|
|
|
}
|
|
|
}
|
|
|
this.$confirm(
|
|
|
- '将有线网络设置为配置内容?',
|
|
|
+ `将${name}有线网络设置为配置内容?`,
|
|
|
{ type: 'warning' }
|
|
|
).then(() => {
|
|
|
done()
|
|
|
@@ -223,11 +325,11 @@ export default {
|
|
|
if (!this.isValid(mask, validIP4, type, '子网掩码')) {
|
|
|
return false
|
|
|
}
|
|
|
- if (!this.isValid(gateway, validIP4, type, '网关')) {
|
|
|
- return false
|
|
|
+ if (gateway && !validIP4(gateway)) {
|
|
|
+ return this.onError('IPv4的网关格式错误')
|
|
|
}
|
|
|
- if (!this.isValid(dns1, validIP4, type, '主DNS')) {
|
|
|
- return false
|
|
|
+ if (dns1 && !validIP4(dns1)) {
|
|
|
+ return this.onError('IPv4的主DNS格式错误')
|
|
|
}
|
|
|
if (dns2 && !validIP4(dns2)) {
|
|
|
return this.onError('IPv4的备DNS格式错误')
|
|
|
@@ -240,11 +342,11 @@ export default {
|
|
|
if (!this.isValid(address, validIP6, type, 'IP地址')) {
|
|
|
return false
|
|
|
}
|
|
|
- if (!this.isValid(gateway, validIP6, type, '网关')) {
|
|
|
- return false
|
|
|
+ if (gateway && !validIP6(gateway)) {
|
|
|
+ return this.onError('IPv6的网关格式错误')
|
|
|
}
|
|
|
- if (!this.isValid(dns1, validIP6, type, '主DNS')) {
|
|
|
- return false
|
|
|
+ if (dns1 && !validIP6(dns1)) {
|
|
|
+ return this.onError('IPv6的主DNS格式错误')
|
|
|
}
|
|
|
if (dns2 && !validIP6(dns2)) {
|
|
|
return this.onError('IPv6的备DNS格式错误')
|