bug修改

This commit is contained in:
qiudan 2024-04-11 14:38:56 +08:00
parent d6c3990908
commit 76f90e3f88
1 changed files with 687 additions and 655 deletions

View File

@ -42,13 +42,9 @@
<span style="margin-left: 10px">接通</span>
</el-col>
</el-form-item> -->
<div style="margin-bottom: 24px;">
<div style="margin-bottom: 24px">
<p class="title">dhcp4</p>
<el-switch
v-model="dhcp4"
active-text="开"
inactive-text="关">
</el-switch>
<el-switch v-model="dhcp4" active-text="开" inactive-text="关"> </el-switch>
</div>
<div v-show="!dhcp4">
<p class="title">静态地址</p>
@ -58,8 +54,7 @@
<template slot-scope="scope">
<!-- <el-input v-model="scope.row.address" @change="changeVal(scope.row,scope.$index)"></el-input> -->
<el-form-item :prop="'tableData.' + scope.$index + '.address'" :rules="rules.address" class="tableFormItem">
<el-input v-model.trim="scope.row.address"
placeholder="例172.1.1.16/24" :disabled="disable"/>
<el-input v-model.trim="scope.row.address" placeholder="例172.1.1.16/24" :disabled="disable" />
</el-form-item>
</template>
</el-table-column>
@ -80,15 +75,17 @@
<el-input v-model="scope.row.term" @change="changeVal(scope.row,scope.$index)"></el-input>
</template>
</el-table-column> -->
<el-table-column
fixed="right"
label="操作"
width="350"
>
<el-table-column fixed="right" label="操作" width="350">
<template slot-scope="scope">
<!-- <el-button @click="deleteRowsTableData(scope)" v-if="scope.$index < sizeForm.tableData.length-1" type="text" size="small">删除行
</el-button> -->
<el-button @click="deleteRowsTableData(scope)" v-if="scope.$index != 0" type="text" size="small" :disabled="disable">删除行
<el-button
@click="deleteRowsTableData(scope)"
v-if="scope.$index != 0"
type="text"
size="small"
:disabled="disable"
>删除行
</el-button>
</template>
</el-table-column>
@ -159,8 +156,7 @@
<template slot-scope="scope">
<!-- <el-input v-model="scope.row.to" @change="changeValT(scope.row,scope.$index)"></el-input> -->
<el-form-item :prop="'tableRouter.' + scope.$index + '.to'" :rules="rules.to" class="tableFormItem">
<el-input v-model.trim="scope.row.to"
placeholder="例172.1.1.16/24" :disabled="disable" />
<el-input v-model.trim="scope.row.to" placeholder="例172.1.1.16/24" :disabled="disable" />
</el-form-item>
</template>
</el-table-column>
@ -168,30 +164,34 @@
<template slot-scope="scope">
<!-- <el-input v-model="scope.row.via" @change="changeValT(scope.row,scope.$index)"></el-input> -->
<el-form-item :prop="'tableRouter.' + scope.$index + '.via'" :rules="rules.via" class="tableFormItem">
<el-input v-model.trim="scope.row.via"
placeholder="例172.1.1.16" :disabled="disable"/>
<el-input v-model.trim="scope.row.via" placeholder="例172.1.1.16" :disabled="disable" />
</el-form-item>
</template>
</el-table-column>
<el-table-column prop="metric" label="metric">
<template slot-scope="scope">
<!-- <el-input v-model="scope.row.metric" @change="changeValT(scope.row,scope.$index)"></el-input> -->
<el-form-item :prop="'tableRouter.'+ scope.$index + '.metric'" :rules="rules.metric" class="tableFormItem">
<el-input v-model.trim="scope.row.metric"
placeholder="例100" :disabled="disable"/>
<el-form-item
:prop="'tableRouter.' + scope.$index + '.metric'"
:rules="rules.metric"
class="tableFormItem"
>
<el-input v-model.trim="scope.row.metric" placeholder="例100" :disabled="disable" />
</el-form-item>
</template>
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="350"
>
<el-table-column fixed="right" label="操作" width="350">
<!-- <template slot-scope="scope" >
<el-button @click="handleClick(scope.row)" type="primary" :disabled="scope.row.disabled" size="small">确认</el-button>
</template> -->
<template slot-scope="scope">
<el-button @click="deleteRows(scope)" v-if="scope.$index < sizeForm.tableRouter.length" type="text" size="small" :disabled="disable">删除行
<el-button
@click="deleteRows(scope)"
v-if="scope.$index < sizeForm.tableRouter.length"
type="text"
size="small"
:disabled="disable"
>删除行
</el-button>
</template>
</el-table-column>
@ -215,23 +215,27 @@
</el-form-item> -->
<el-button type="primary" @click="addRowsDNS()" style="margin-bottom: 10px" v-if="!disable">新增</el-button>
<el-table :data="sizeForm.tableDataDNS" border style="width: 95%">
<el-table-column prop="address" label="地址">
<template slot-scope="scope">
<!-- <el-input v-model="scope.row.address" @change="changeVal(scope.row,scope.$index)"></el-input> -->
<el-form-item :prop="'tableDataDNS.'+ scope.$index + '.address'" :rules="rules.addressDNS" class="tableFormItem">
<el-input v-model.trim="scope.row.address"
placeholder="例172.1.1.16" :disabled="disable" />
<el-form-item
:prop="'tableDataDNS.' + scope.$index + '.address'"
:rules="rules.addressDNS"
class="tableFormItem"
>
<el-input v-model.trim="scope.row.address" placeholder="例172.1.1.16" :disabled="disable" />
</el-form-item>
</template>
</el-table-column>
<el-table-column
fixed="right"
label="操作"
width="350"
>
<el-table-column fixed="right" label="操作" width="350">
<template slot-scope="scope">
<el-button @click="deleteRowsDNS(scope)" v-if="scope.$index < sizeForm.tableDataDNS.length" type="text" size="small" :disabled="disable">删除行
<el-button
@click="deleteRowsDNS(scope)"
v-if="scope.$index < sizeForm.tableDataDNS.length"
type="text"
size="small"
:disabled="disable"
>删除行
</el-button>
</template>
</el-table-column>
@ -239,7 +243,13 @@
</div>
<!-- <el-form-item >
<el-col :span="6"> -->
<el-button type="primary" @click="commit(sizeForm.tableRouter,sizeForm.tableData,sizeForm.tableDataDNS,sizeForm)" style="margin-top:10px" v-if="!disable">保存</el-button>
<el-button
type="primary"
@click="commit(sizeForm.tableRouter, sizeForm.tableData, sizeForm.tableDataDNS, sizeForm)"
style="margin-top: 10px"
v-if="!disable"
>保存</el-button
>
<!-- </el-col>
</el-form-item> -->
</div>
@ -249,7 +259,6 @@
</template>
<script>
export default {
data() {
let validateIPAddress = (rule, value, callback) => {
@ -269,9 +278,9 @@ export default {
if (!isCorrect) {
callback(new Error('请输入正确的IP地址'));
} else {
callback()
}
callback();
}
};
let validateIPAddressYes = (rule, value, callback) => {
if (value == null) {
return callback(new Error('IP地址不能为空'));
@ -306,10 +315,9 @@ export default {
}
}
}
}
}
}
};
let metric = (rule, value, callback) => {
if (!value) {
return callback(new Error('输入不可以为空'));
@ -327,7 +335,7 @@ export default {
}
}
}, 0);
}
};
return {
dhcp4: false,
@ -335,16 +343,31 @@ export default {
columnPropIndex: 0, //
columnData: [], //
rules: {
gateway4: [{ required: true, pattern: /^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/,message: "请输入正确的IP地址", trigger: "blur"}],
via: [{ required: true, pattern: /^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/,message: "请输入正确的IP地址", trigger: "blur"}],
gateway4: [
{
required: true,
pattern:
/^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/,
message: '请输入正确的IP地址',
trigger: 'blur'
}
],
via: [
{
required: true,
pattern:
/^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/,
message: '请输入正确的IP地址',
trigger: 'blur'
}
],
// via:[{ required: true, validator: validateIPAddress, trigger: "blur" }]
addressDNS:[{ required: true, validator: validateIPAddress, trigger: "blur" }],
address:[{ required: true, validator: validateIPAddressYes, trigger: "blur" }],
to:[{ required: true, validator: validateIPAddressYes, trigger: "blur" }],
metric:[{ required: true, validator: metric, trigger: "blur" }],
addressDNS: [{ required: true, validator: validateIPAddress, trigger: 'blur' }],
address: [{ required: true, validator: validateIPAddressYes, trigger: 'blur' }],
to: [{ required: true, validator: validateIPAddressYes, trigger: 'blur' }],
metric: [{ required: true, validator: metric, trigger: 'blur' }]
},
optionsa: [
{
value: '1',
@ -430,7 +453,6 @@ export default {
// address: '',
// },
// {
// id:'',
// address: '',
// },
@ -448,13 +470,13 @@ export default {
// id:'',
// address: '',
// }
],
]
},
options: [
{
value: '',
label: ''
},
}
// {
// value: 'wlan0',
// label: 'wlan0'
@ -516,7 +538,7 @@ export default {
// agreement: 'NO',
// Range: '1',
id: '',
address: '192.168.50.10/24',
address: '192.168.50.10/24'
// term: '',
// disabled:true
},
@ -524,7 +546,7 @@ export default {
// agreement: 'YES',
// Range: '1',
id: '',
address: '192.168.1.5/24',
address: '192.168.1.5/24'
// term: '17',
// disabled:true
},
@ -532,7 +554,7 @@ export default {
// agreement: 'YES',
// Range: '1',
id: '',
address: '192.168.1.5/24',
address: '192.168.1.5/24'
// term: '17',
// disabled:true
}
@ -542,7 +564,7 @@ export default {
// agreement: 'NO',
// Range: '1',
id: '',
address: '192.168.50.10/24',
address: '192.168.50.10/24'
// term: '',
// disabled:true
},
@ -550,57 +572,55 @@ export default {
// agreement: 'YES',
// Range: '1',
id: '',
address: '192.168.1.5/24',
address: '192.168.1.5/24'
// term: '17',
// disabled:true
}
],
tableDataPanduan: [],
optionsData: 'eth0',
disable:false, //
disable: false //
};
},
watch: {
},
watch: {},
created() {
this.createMqtt()
this.createMqtt();
setTimeout(() => {
this.publishClient()
this.publishClient();
}, 1000 * 3);
},
mounted() {
if (localStorage.getItem('roleName') == '系统管理员') {
this.disable = false
this.disable = false;
} else {
this.disable = true
this.disable = true;
}
},
methods: {
//
commit(tableRouter, tableData, tableDataDNS, sizeForm) {
console.log("tableData",tableData)
console.log("tableDataDNS",tableDataDNS)
console.log("sizeForm",sizeForm)
var tableRouterN = tableRouter.map(value => {
return value.to+','+value.via+','+value.metric
})
var tableDataN = tableData.map(item => {
return item.address
})
var tableDataDNSN = tableDataDNS.map(item => {
return item.address
})
console.log('tableData', tableData);
console.log('tableDataDNS', tableDataDNS);
console.log('sizeForm', sizeForm);
var tableRouterN = tableRouter.map((value) => {
return value.to + ',' + value.via + ',' + value.metric;
});
var tableDataN = tableData.map((item) => {
return item.address;
});
var tableDataDNSN = tableDataDNS.map((item) => {
return item.address;
});
var ner = {
type:"netplanSet",
type: 'netplanSet',
ethName: sizeForm.name,
dhcp4: this.dhcp4,
addresses: tableDataN, //
gateway4: sizeForm.gateway4,
nameservers: tableDataDNSN, //DNS
routes: tableRouterN //
}
};
this.$confirm('此操作将重新设置网络, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
@ -611,7 +631,7 @@ export default {
type: 'success',
message: '设置成功!'
});
console.log("JSON.stringify(ner)",JSON.stringify(ner))
console.log('JSON.stringify(ner)', JSON.stringify(ner));
window.publish('Contorl_client', JSON.stringify(ner));
this.sizeForm = {
name: '',
@ -638,8 +658,8 @@ export default {
speed: '',
tableRouter: [],
tableData: [],
tableDataDNS: [],
}
tableDataDNS: []
};
const loading = this.$loading({
lock: true,
text: 'Loading',
@ -648,7 +668,7 @@ export default {
});
setTimeout(() => {
loading.close();
this.publishClient()
this.publishClient();
}, 5000);
})
.catch(() => {
@ -664,13 +684,15 @@ export default {
const circle = this.sizeForm.tableRouter[0]; //
if (circle) {
const newObj = {};
for (let key in circle) { //newObj
for (let key in circle) {
//newObj
newObj[key] = '';
}
this.sizeForm.tableRouter.splice(this.sizeForm.tableRouter.length, 0, newObj);
} else {
const newObj = {};
for (let key in circle) { //newObj
for (let key in circle) {
//newObj
newObj[key] = '';
}
this.sizeForm.tableRouter.splice(this.sizeForm.tableRouter.length, 0, newObj);
@ -686,7 +708,8 @@ export default {
const circle = this.sizeForm.tableData[0]; //
if (circle) {
const newObj = {};
for (let key in circle) { //newObj
for (let key in circle) {
//newObj
newObj[key] = '';
}
// this.sizeForm.tableData.splice(this.sizeForm.tableData.length-1, 0, newObj);
@ -703,13 +726,15 @@ export default {
const circle = this.sizeForm.tableDataDNS[0]; //
if (circle) {
const newObj = {};
for (let key in circle) { //newObj
for (let key in circle) {
//newObj
newObj[key] = '';
}
this.sizeForm.tableDataDNS.splice(this.sizeForm.tableDataDNS.length, 0, newObj);
} else {
const newObj = {};
for (let key in circle) { //newObj
for (let key in circle) {
//newObj
newObj[key] = '';
}
this.sizeForm.tableDataDNS.splice(this.sizeForm.tableDataDNS.length, 0, newObj);
@ -724,80 +749,75 @@ export default {
//
var topicSends = ['Contorl_server'];
window.PubScribe(topicSends, -1, this.realInfo);
},
publishClient() {
window.publish('Contorl_client',JSON.stringify({"type":"getNet"}));
window.publish('Contorl_client', JSON.stringify({ type: 'getNet' }));
},
/** 实时数据分类 */
realInfo(topic, message) {
// console.log("topic",topic)
switch (topic) {
case "Contorl_server":
case 'Contorl_server':
try {
const utf8decoder = new TextDecoder()
const u8arr = new Uint8Array(message)
const temp = utf8decoder.decode(u8arr) //
const msg = JSON.parse(temp) //JSON
const utf8decoder = new TextDecoder();
const u8arr = new Uint8Array(message);
const temp = utf8decoder.decode(u8arr); //
const msg = JSON.parse(temp); //JSON
if (msg.type == 'getNet') {
console.log("msg",msg)
console.log('msg', msg);
// const netaddres = JSON.parse(msg.netaddres)
// console.log("netaddres",netaddres)
// const netstates = JSON.parse(msg.netstates)
this.changeNetstates(msg)
}
} catch (error) {
this.changeNetstates(msg);
}
} catch (error) {}
break;
}
},
changeNetstates(msg) {
console.log("msg",msg)
console.log('msg', msg);
// var optionsDataN = this.optionsData
console.log(" msg.netstates[this.optionsData]",this.optionsData)
console.log(' msg.netstates[this.optionsData]', this.optionsData);
if (msg.netplan[this.optionsData] != undefined) {
this.dhcp4 = msg.netplan[this.optionsData].dhcp4||false
this.dhcp4 = msg.netplan[this.optionsData].dhcp4 || false;
}
if (msg.netstates[this.optionsData] != undefined) {
this.sizeForm.name = this.optionsData
this.sizeForm.mtu = msg.netstates[this.optionsData].mtu
var data = msg.netaddres[this.optionsData]
this.sizeForm.speed = msg.netstates[this.optionsData].speed
this.tableDataPanduan = []
var optionN = Object.keys(msg.netplan)
this.sizeForm.name = this.optionsData;
this.sizeForm.mtu = msg.netstates[this.optionsData].mtu;
var data = msg.netaddres[this.optionsData];
this.sizeForm.speed = msg.netstates[this.optionsData].speed;
this.tableDataPanduan = [];
var optionN = Object.keys(msg.netplan);
var optionNrr = optionN.map((value, index) => {
return {
value: value,
label: value
}
})
console.log("optionNrr",optionNrr)
this.options = optionNrr
};
});
console.log('optionNrr', optionNrr);
this.options = optionNrr;
if (msg.netstates[this.optionsData].isup == true) {
this.sizeForm.status='YES'
this.sizeForm.status = 'YES';
} else {
this.sizeForm.status='NO'
this.sizeForm.status = 'NO';
}
for (let i = 0; i < data.length; i++) {
if (data[i].family == 17) {
this.sizeForm.mac =data[i].address
this.sizeForm.mac = data[i].address;
} else if (data[i].family == 2) {
this.tableDataPanduan.push(data[i])
this.tableDataPanduan.push(data[i]);
}
}
if (this.tableDataPanduan.length == msg.netplan[this.optionsData].addresses.length) {
for (let i = 0; i < this.tableDataPanduan.length; i++) {
for (let b = 0; b < msg.netplan[this.optionsData].addresses.length; b++) {
// console.log("str1",netstates.netplan.eth0.addresses[b].substring(0,netstates.netplan.eth0.addresses[b].indexOf("/")))
var ipos = msg.netplan[this.optionsData].addresses[b].indexOf("/");//
var ipos = msg.netplan[this.optionsData].addresses[b].indexOf('/'); //
let str1 = msg.netplan[this.optionsData].addresses[b].substring(0, ipos);
if (this.tableDataPanduan[i].address == str1) {
} else {
// this.$message({
// message: '',
@ -807,27 +827,30 @@ export default {
}
}
}
var addressesN = msg.netplan[this.optionsData].addresses.map((value, index) => {
let addressesN = [];
if (msg.netplan[this.optionsData].addresses && msg.netplan[this.optionsData].addresses.length > 0) {
addressesN = msg.netplan[this.optionsData].addresses.map((value, index) => {
return {
address: value,
id: index
};
});
}
})
this.sizeForm.tableData = addressesN
this.sizeForm.tableData = addressesN;
//
var dataJ = msg.netplan[this.optionsData].routes
this.sizeForm.tableRouter=[]
var dataJ = msg.netplan[this.optionsData].routes;
this.sizeForm.tableRouter = [];
for (let r = 0; r < dataJ.length; r++) {
this.sizeForm.tableRouter.push(dataJ[r])
this.sizeForm.tableRouter.push(dataJ[r]);
}
this.sizeForm.gateway4 = msg.netplan[this.optionsData].gateway4
this.sizeForm.gateway4 = msg.netplan[this.optionsData].gateway4;
var legend = msg.netplan[this.optionsData].nameservers.addresses.map((value, index) => {
return {
address: value,
id: index
}
})
this.sizeForm.tableDataDNS = legend
};
});
this.sizeForm.tableDataDNS = legend;
} else {
this.sizeForm = {
name: this.optionsData,
@ -843,51 +866,54 @@ export default {
mtu: '',
mac: '',
moren: '',
speed:'',
}
speed: ''
};
//
var dataJ = msg.netplan[this.optionsData].routes
this.sizeForm.tableRouter=[]
var dataJ = msg.netplan[this.optionsData].routes;
this.sizeForm.tableRouter = [];
for (let r = 0; r < dataJ.length; r++) {
this.sizeForm.tableRouter.push(dataJ[r])
this.sizeForm.tableRouter.push(dataJ[r]);
}
var addressesN = msg.netplan[this.optionsData].addresses.map((value, index) => {
let addressesN = [];
if (msg.netplan[this.optionsData].addresses && msg.netplan[this.optionsData].addresses.length > 0) {
addressesN = msg.netplan[this.optionsData].addresses.map((value, index) => {
return {
address: value,
id: index
};
});
}
})
this.sizeForm.tableData = addressesN
this.sizeForm.tableData = addressesN;
var legend = msg.netplan[this.optionsData].nameservers.addresses.map((value, index) => {
return {
address: value,
id: index
};
});
this.sizeForm.tableDataDNS = legend;
}
})
this.sizeForm.tableDataDNS = legend
}
},
changeName(val) {
console.log("val",val)
this.sizeForm.name = val
this.optionsData = val
this.publishClient()
console.log('val', val);
this.sizeForm.name = val;
this.optionsData = val;
this.publishClient();
},
gernerateClass(status) {
console.log("status",status)
console.log('status', status);
if (status == 'YES') {
return 'status'
return 'status';
} else {
return 'statusNo'
return 'statusNo';
}
},
changeVal(val, e) {
this.sizeForm.tableData[e].disabled = false
this.sizeForm.tableData[e].disabled = false;
},
changeValT(val, e) {
this.sizeForm.tableRouter[e].disabled = false
this.sizeForm.tableRouter[e].disabled = false;
},
handleClick(scope, e) {
console.log(scope, 'scope');
@ -940,10 +966,16 @@ export default {
}
}
.status {
width: 10px; height: 10px; border-radius: 50%; background: green
width: 10px;
height: 10px;
border-radius: 50%;
background: green;
}
.statusNo {
width: 10px; height: 10px; border-radius: 50%; background: red
width: 10px;
height: 10px;
border-radius: 50%;
background: red;
}
</style>