perf: promserver重构、开始抽取常量

This commit is contained in:
chenjinsong
2020-07-15 20:43:19 +08:00
parent 20a7cc2147
commit ed91fd20ce
7 changed files with 257 additions and 392 deletions

View File

@@ -0,0 +1,11 @@
export const promServer = {
typeOption: [
{
key: 1,
value: 'Global'
}, {
key: 2,
value: 'Per-Datacenter'
}
],
};

View File

@@ -99,7 +99,7 @@
/*保存*/ /*保存*/
save() { save() {
this.$refs.accountForm.validate((valid) => { this.$refs.accountForm.validate(valid => {
if (valid) { if (valid) {
if (this.editUser.userId) { if (this.editUser.userId) {
this.$put('sys/user/update', this.editUser).then(response => { this.$put('sys/user/update', this.editUser).then(response => {

View File

@@ -0,0 +1,176 @@
<template>
<div class="right-box right-box-prom" v-clickoutside="clickos">
<!-- begin--顶部按钮-->
<div class="right-box-top-btns">
<button type="button" v-if="editPromServer.id" @click="del"
class="nz-btn nz-btn-size-normal nz-btn-size-alien nz-btn-style-light"
id="promServer-edit-del">
<span class="right-box-top-btn-icon"><i class="el-icon-delete"></i></span>
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
</button>
</div>
<!-- end--顶部按钮-->
<!-- begin--标题-->
<div class="right-box-title">{{editPromServer.id ? ($t("config.promServer.editProm") + " ID" + editPromServer.id) : $t("config.promServer.createProm")}}</div>
<!-- end--标题-->
<!-- begin--表单-->
<el-scrollbar class="right-box-form-box">
<el-form class="right-box-form" :model="editPromServer" label-position="top" :rules="rules" ref="promServerForm">
<!--DC-->
<el-form-item :label="$t('config.dc.dc')" prop="idc.name">
<div class="right-box-form-content">
<el-select value-key="id" popper-class="config-dropdown" v-model="editPromServer.idc" placeholder="" size="small">
<el-option v-for="item in dcData" :key="item.id" :label="item.name" :value="item" :id="'prom-edit-idc-op-'+item.id">
<span class="config-dropdown-label-txt">{{item.name}}</span>
</el-option>
</el-select>
</div>
</el-form-item>
<!--host-->
<el-form-item label="Host" prop="host">
<el-input type="text" placeholder="" v-model="editPromServer.host" size="small"></el-input>
</el-form-item>
<!--Port-->
<el-form-item label="Port" prop="port">
<el-input type="text" placeholder="" v-model.number="editPromServer.port" size="small"></el-input>
</el-form-item>
<!--type-->
<el-form-item :label="$t('config.promServer.type')" prop="type">
<el-select popper-class="config-dropdown" v-model="editPromServer.type" placeholder="" size="small">
<el-option v-for="item in $CONSTANTS.promServer.typeOption" :key="item.key" :label="item.value" :value="item.key" :id="'prom-edit-type-op-'+item.key"></el-option>
</el-select>
</el-form-item>
</el-form>
</el-scrollbar>
<!-- end--表单-->
<!--底部按钮-->
<div class="right-box-bottom-btns">
<button @click="esc" id="prom-esc"
class="nz-btn nz-btn-size-normal nz-btn-style-light nz-btn-min-width-100">
<span>{{$t('overall.cancel')}}</span>
</button>
<button @click="save" id="prom-save"
class="nz-btn nz-btn-size-normal nz-btn-style-normal nz-btn-min-width-100">
<span>{{$t('overall.save')}}</span>
</button>
</div>
</div>
</template>
<script>
import {host} from '../../common/js/validate';
import {port} from '../../common/js/validate';
export default {
name: "promServerBox",
props: {
promServer: Object
},
data() {
return {
rules: {
'idc.name': [
{required: true, message: this.$t('validate.required'), trigger: 'change'}
],
host: [
{required: true, message: this.$t('validate.required'), trigger: 'blur'},
{validator: host, trigger: 'blur'}
],
port: [
{validator: port, trigger: 'blur'},
{required: true, message: this.$t('validate.required')}
],
type: [
{required: true, message: this.$t('validate.required'), trigger: 'change'},
]
},
editPromServer: {},
dcData: [], //data center数据
}
},
methods: {
clickos() {
this.esc(false);
},
/*关闭弹框*/
esc(refresh) {
this.$emit("close", refresh);
},
/*保存*/
save() {
this.$refs.promServerForm.validate(valid => {
if (valid) {
if (this.editPromServer.id) {
this.$put('promServer', this.editPromServer).then(response => {
if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.esc(true);
} else {
this.$message.error(response.msg);
this.esc(false);
}
});
} else {
this.$post('promServer', this.editPromServer).then(response => {
if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.esc(true);
} else {
this.$message.error(response.msg);
this.esc(false);
}
});
}
} else {
return false;
}
})
},
/*删除*/
del() {
this.$confirm(this.$t("tip.confirmDelete"), {
confirmButtonText: this.$t("tip.yes"),
cancelButtonText: this.$t("tip.no"),
type: 'warning'
}).then(() => {
this.$delete("promServer?ids=" + this.editPromServer.id).then(response => {
if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.deleteSuccess")});
this.esc(true);
} else {
this.$message.error(response.msg);
}
});
});
},
//获取dc下拉列表数据
getDcData() {
this.$get('idc').then(response => {
if (response.code === 200) {
this.dcData = response.data.list;
}
})
},
},
watch: {
//将prop里的user转为组件内部对象
promServer: {
immediate: true,
deep: true,
handler(n) {
this.editPromServer = JSON.parse(JSON.stringify(n));
}
},
'editPromServer.idc': function (n, o) {
this.editPromServer.idcId = n.id;
},
},
mounted() {
this.getDcData();
}
}
</script>

View File

@@ -42,7 +42,7 @@
<div class="top-tool-search"> <div class="top-tool-search">
<search-input ref="searchInput" :searchMsg="searchMsg" @search="search" :inTransform="inTransform"></search-input> <search-input ref="searchInput" :searchMsg="searchMsg" @search="search" :inTransform="inTransform"></search-input>
</div> </div>
<button type="button" @click="toAdd" :title="$t('overall.createAccount')" <button type="button" @click="add" :title="$t('overall.createAccount')"
class="nz-btn nz-btn-size-normal nz-btn-style-light margin-l-20" id="account-add"> class="nz-btn nz-btn-size-normal nz-btn-style-light margin-l-20" id="account-add">
<i class="nz-icon-create-square nz-icon"></i> <i class="nz-icon-create-square nz-icon"></i>
</button> </button>
@@ -163,7 +163,7 @@
rightBox: { //弹出框相关 rightBox: { //弹出框相关
show: false, show: false,
}, },
blankUser: { blankUser: { //空白对象
userId: '', userId: '',
username: '', username: '',
email: '', email: '',
@@ -321,42 +321,20 @@
} }
}) })
}, },
toAdd() { add() {
this.cleanUser(); this.cleanUser();
this.rightBox.show = true; this.rightBox.show = true;
}, },
save() {
this.$refs.accountForm.validate((valid) => {
if (valid) {
if (this.user.userId) {
this.$put('sys/user/update', this.user).then(response => {
if (response.code === 200) {
this.rightBox.show = false;
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
} else {
this.$message.error(response.msg);
}
this.getTableData();
});
} else {
this.$post('sys/user/save', this.user).then(response => {
if (response.code === 200) {
this.rightBox.show = false;
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.getTableData();
} else {
this.$message.error(response.msg);
}
});
}
} else {
return false;
}
})
},
statusChange(user) { statusChange(user) {
this.user = user; this.$put('sys/user/update', user).then(response => {
this.save(); if (response.code === 200) {
this.rightBox.show = false;
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
} else {
this.$message.error(response.msg);
}
this.getTableData();
});
}, },
jumpTo(data, id) { jumpTo(data, id) {
this.$router.push({ this.$router.push({
@@ -370,15 +348,7 @@
this.rightBox.show = false; this.rightBox.show = false;
}, },
cleanUser() { cleanUser() {
this.user = { this.user = JSON.parse(JSON.stringify(this.blankUser));
userId: '',
username: '',
email: '',
status: '1',
createTime: '',
receiver: [],
lang: 'en'
}
}, },
pageNo(val) { pageNo(val) {
this.pageObj.pageNo = val; this.pageObj.pageNo = val;

View File

@@ -40,7 +40,7 @@
<div class="top-tool-search"> <div class="top-tool-search">
<search-input ref="searchInput" :searchMsg="searchMsg" @search="search" :inTransform="inTransform"></search-input> <search-input ref="searchInput" :searchMsg="searchMsg" @search="search" :inTransform="inTransform"></search-input>
</div> </div>
<button type="button" @click="toAdd" :title="$t('overall.createPrometheusServer')" <button type="button" @click="add" :title="$t('overall.createPrometheusServer')"
class="nz-btn nz-btn-size-normal nz-btn-style-light margin-l-20" id="prom-add"> class="nz-btn nz-btn-size-normal nz-btn-style-light margin-l-20" id="prom-add">
<i class="nz-icon-create-square nz-icon"></i> <i class="nz-icon-create-square nz-icon"></i>
</button> </button>
@@ -68,7 +68,7 @@
<div v-else-if="item.prop == 'option'" class="content-right-options"> <div v-else-if="item.prop == 'option'" class="content-right-options">
<span :title="$t('overall.view')" @click="detail(scope.row)" class="content-right-option" :id="'prom-detail-'+scope.row.id"><i class="nz-icon nz-icon-view"></i></span> <span :title="$t('overall.view')" @click="detail(scope.row)" class="content-right-option" :id="'prom-detail-'+scope.row.id"><i class="nz-icon nz-icon-view"></i></span>
&nbsp; &nbsp;
<span :title="$t('overall.edit')" @click="toEdit(scope.row)" class="content-right-option" :id="'prom-edit-'+scope.row.id"><i class="nz-icon nz-icon-edit"></i></span> <span :title="$t('overall.edit')" @click="edit(scope.row)" class="content-right-option" :id="'prom-edit-'+scope.row.id"><i class="nz-icon nz-icon-edit"></i></span>
&nbsp; &nbsp;
<span :title="$t('overall.delete')" @click="del(scope.row)" class="content-right-option" :id="'prom-del-'+scope.row.id"><i class="el-icon-delete"></i></span> <span :title="$t('overall.delete')" @click="del(scope.row)" class="content-right-option" :id="'prom-del-'+scope.row.id"><i class="el-icon-delete"></i></span>
</div> </div>
@@ -96,85 +96,7 @@
</div> </div>
</left-menu> </left-menu>
<transition name="right-box"> <transition name="right-box">
<div class="right-box right-box-prom" v-if="rightBox.show" v-clickoutside="clickos"> <prom-server-box v-if="rightBox.show" :prom-server="promServer" @close="closeRightBox"></prom-server-box>
<!-- begin--顶部按钮-->
<div class="right-box-top-btns">
<button type="button" v-if="rightBox.isEdit && promServer.id != ''" @click="del(promServer)"
id="prom-edit-del"
class="nz-btn nz-btn-size-normal nz-btn-size-alien nz-btn-style-light nz-btn-min-width-82">
<span class="right-box-top-btn-icon"><i class="el-icon-delete"></i></span>
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
</button>
<button v-if="!rightBox.isEdit" type="button" @click="saveOrToEdit"
class="nz-btn nz-btn-size-normal nz-btn-size-alien nz-btn-style-light nz-btn-min-width-82"
id="prom-edit-save">
<span class="right-box-top-btn-icon"><i class="nz-icon nz-icon-edit"></i></span>
<span class="right-box-top-btn-txt">{{$t('overall.edit')}}</span>
</button>
</div>
<!-- end--顶部按钮-->
<!-- begin--标题-->
<div class="right-box-title">{{rightBox.title}}</div>
<!-- end--标题-->
<!-- begin--表单-->
<el-scrollbar class="right-box-form-box">
<el-form class="right-box-form right-box-form-left" :model="promServer" label-position="right" label-width="120px" :rules="rules"
ref="promServerForm">
<!--DC start-->
<el-form-item :label="$t('config.dc.dc')" prop="idc.name">
<div class="right-box-form-content">
<el-select value-key="id" popper-class="config-dropdown"
v-model="promServer.idc" placeholder="" v-if="rightBox.isEdit" size="small">
<el-option @click.native="blurEditIdc()" v-for="item in idcData" :key="item.id" :label="item.name"
:value="item" :id="'prom-edit-idc-op-'+item.id">
<span class="config-dropdown-label-txt">{{item.name}}</span>
</el-option>
</el-select>
<div class="right-box-form-content-txt" v-if="!rightBox.isEdit">{{promServer.idc.name}}</div>
</div>
</el-form-item>
<!--DC end-->
<!--host-->
<el-form-item label="Host" prop="host">
<el-input type="text" v-if="rightBox.isEdit" placeholder="" v-model="promServer.host"
size="small"></el-input>
<div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{promServer.host}}</div>
</el-form-item>
<!--Port-->
<el-form-item label="Port" prop="port">
<el-input type="text" v-if="rightBox.isEdit" placeholder="" v-model.number="promServer.port"
size="small"></el-input>
<div v-if="!rightBox.isEdit" class="right-box-form-content-txt">{{promServer.port}}</div>
</el-form-item>
<!--type-->
<el-form-item :label="$t('config.promServer.type')" prop="type">
<el-select popper-class="config-dropdown" v-model="promServer.type" placeholder="" v-if="rightBox.isEdit"
size="small">
<el-option v-for="item in typeData" :key="item.key" :label="item.value" :value="item.key"
:id="'prom-edit-type-op-'+item.key"></el-option>
</el-select>
<div v-for="item in typeData" v-if="!rightBox.isEdit && item.key == promServer.type"
:id="'prom-edit-type-op-del-'+item.key" class="right-box-form-content-txt">{{item.value}}
</div>
</el-form-item>
</el-form>
</el-scrollbar>
<!-- end--表单-->
<!--底部按钮-->
<div class="right-box-bottom-btns">
<button @click="esc" id="prom-esc" class="nz-btn nz-btn-size-normal nz-btn-style-light nz-btn-min-width-100">
<span>{{$t('overall.cancel')}}</span>
</button>
<button v-if="rightBox.isEdit" @click="saveOrToEdit" id="prom-save"
class="nz-btn nz-btn-size-normal nz-btn-style-normal nz-btn-min-width-100">
<span>{{$t('overall.save')}}</span>
</button>
</div>
</div>
</transition> </transition>
<element-set <element-set
v-clickoutside="elementsetHide" v-clickoutside="elementsetHide"
@@ -187,14 +109,15 @@
</template> </template>
<script> <script>
import {host} from '../../common/js/validate';
import {port} from '../../common/js/validate';
import bus from '../../../libs/bus'; import bus from '../../../libs/bus';
var vm; import promServerBox from '../../common/rightBox/promServerBox';
export default { export default {
name: "prom", name: "promServer",
components: {
'prom-server-box': promServerBox
},
data() { data() {
vm = this;
return { return {
//底部上滑框相关 //底部上滑框相关
mainTableHeight: this.$tableHeight.normal, //主列表table高度 mainTableHeight: this.$tableHeight.normal, //主列表table高度
@@ -215,8 +138,6 @@
showTopBtn: false, showTopBtn: false,
rightBox: { //弹出框相关 rightBox: { //弹出框相关
show: false, show: false,
isEdit: false, //false查看true编辑
title: ''
}, },
loading: false, loading: false,
promServer: { promServer: {
@@ -225,21 +146,11 @@
port: 9090, port: 9090,
idc: {id: '', name: '', location: ''} idc: {id: '', name: '', location: ''}
}, },
rules: { blankPromServer: {
'idc.name': [ id: '',
{required: true, message: this.$t('validate.required'), trigger: 'change'} host: '',
], port: 9090,
host: [ idc: {id: '', name: '', location: ''}
{required: true, message: this.$t('validate.required'), trigger: 'blur'},
{validator: host, trigger: 'blur'}
],
port: [
{validator: port, trigger: 'blur'},
{required: true, message: this.$t('validate.required')}
],
type: [
{required: true, message: this.$t('validate.required'), trigger: 'change'},
]
}, },
pageObj: { pageObj: {
pageNo: 1, pageNo: 1,
@@ -286,16 +197,7 @@
tablelable: [], tablelable: [],
dropCol: [], dropCol: [],
tableData: [], tableData: [],
idcData: [], dcData: [],
typeData: [
{
key: 1,
value: 'Global'
}, {
key: 2,
value: 'Per-Datacenter'
}
],
searchMsg: { //给搜索框子组件传递的信息 searchMsg: { //给搜索框子组件传递的信息
zheze_none: true, zheze_none: true,
searchLabelList: [{ searchLabelList: [{
@@ -331,28 +233,6 @@
}], }],
}, },
searchLabel: {}, //搜索参数 searchLabel: {}, //搜索参数
idcSelectedData: {
id: '',
name: '',
location: '',
principal: '',
tel: ''
},
addIdcData: {
id: '',
name: '',
location: '',
principal: '',
tel: ''
},
popIdcData: {
id: '',
name: '',
location: '',
principal: '',
tel: ''
},
idcUserData: '',
} }
}, },
methods: { methods: {
@@ -374,7 +254,7 @@
detail.push({label: "Host", value: obj.host}); detail.push({label: "Host", value: obj.host});
detail.push({label: "Port", value: obj.port}); detail.push({label: "Port", value: obj.port});
let type = ""; let type = "";
for (let i = 0; i < this.typeData.length; i++) { for (let i = 0; i < this.$CONSTANTS.promServer.typeOption.length; i++) {
if (obj.key == this.typeData[i].type) { if (obj.key == this.typeData[i].type) {
type = this.typeData[i].value; type = this.typeData[i].value;
break; break;
@@ -422,13 +302,12 @@
clickos() { clickos() {
this.rightBox.show = false; this.rightBox.show = false;
}, },
toEdit: function (u) { edit(u) {
this.promServer = Object.assign({}, u); this.promServer = JSON.parse(JSON.stringify(u));
this.rightBox.isEdit = true;
this.rightBox.title = this.$t("config.promServer.editProm") + " ID" + u.id;
this.rightBox.show = true; this.rightBox.show = true;
}, },
del: function (u) { /*删除*/
del(u) {
this.$confirm(this.$t("tip.confirmDelete"), { this.$confirm(this.$t("tip.confirmDelete"), {
confirmButtonText: this.$t("tip.yes"), confirmButtonText: this.$t("tip.yes"),
cancelButtonText: this.$t("tip.no"), cancelButtonText: this.$t("tip.no"),
@@ -438,135 +317,28 @@
if (response.code === 200) { if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.deleteSuccess")}); this.$message({duration: 1000, type: 'success', message: this.$t("tip.deleteSuccess")});
this.getTableData(); this.getTableData();
this.rightBox.show = false;
} else {
this.$message.error(response.msg);
}
})
});
},
detail: function (u) {
this.promServer = Object.assign({}, u);
/*this.rightBox.isEdit = false;
this.rightBox.title = "Prometheus Server ID" + u.id;
this.rightBox.show = true;*/
this.targetTab = "detail";
this.showSubList = true;
},
toAdd: function () {
this.cleanPromServer();
this.rightBox.isEdit = true;
this.rightBox.title = this.$t("config.promServer.createProm");
this.rightBox.show = true;
},
save: function () {
this.$refs.promServerForm.validate((valid => {
if (valid) {
if (this.promServer.id) {
this.$put('promServer', this.promServer).then(response => {
if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.getTableData();
this.rightBox.isEdit = false;
this.esc();
} else {
this.$message.error(response.msg);
}
});
} else {
this.$post('promServer', this.promServer).then(response => {
if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.getTableData();
this.rightBox.isEdit = false;
this.esc();
} else {
this.$message.error(response.msg);
}
});
}
} else {
return false;
}
}))
},
saveOrToEdit: function () {
if (!this.rightBox.isEdit) {
this.toEdit(this.promServer);
} else {
this.save();
}
},
toEditIdc: function (item) {
if (!item.isEdit) {
//如果不在编辑状态,那么其他项如果有改动,则还原改动,最后开始编辑
this.blurEditIdc();
item.isEdit = true;
} else {
//如果已在编辑状态判断name是否有变更有变更则发请求
if (item.name != item.oldName) {
this.$put('idc', item).then(response => {
if (response.code === 200) {
item.errorMessage = '';
item.oldName = item.name;
item.isEdit = false;
this.getIdcData();
} else {
this.$set(item, 'errorMessage', response.msg);
}
})
} else {
item.errorMessage = '';
item.isEdit = false;
}
}
},
blurEditIdc: function () {
for (var i = 0; i < this.idcData.length; i++) {
if (this.idcData[i].isEdit) {
this.idcData[i].name = this.idcData[i].oldName;
this.idcData[i].isEdit = false;
this.idcData[i].errorMessage = '';
break;
}
}
},
toDelIdc: function (item) {
this.blurEditIdc();
this.$confirm(this.$t("tip.confirmDelete"), {
confirmButtonText: this.$t("tip.yes"),
cancelButtonText: this.$t("tip.no"),
type: 'warning'
}).then(() => {
this.$delete("idc?ids=" + item.id).then(response => {
if (response.code === 200) {
this.$message({duration: 1000, type: 'success', message: this.$t("tip.deleteSuccess")});
this.getTableData();
this.getIdcData();
} else { } else {
this.$message.error(response.msg); this.$message.error(response.msg);
} }
}); });
}); });
}, },
getIdcData: function () { detail(u) {
this.$get('idc', this.pageObj).then(response => { this.promServer = JSON.parse(JSON.stringify(u));
if (response.code === 200) { this.targetTab = "detail";
this.idcData = response.data.list; this.showSubList = true;
for (var i = 0; i < this.idcData.length; i++) {
this.$set(this.idcData[i], 'oldName', this.idcData[i].name);
this.$set(this.idcData[i], 'isEdit', false);
this.$set(this.idcData[i], this.idcData[i].name, false)
}
this.getTableData();
}
})
}, },
esc: function () { add() {
this.cleanPromServer();
this.rightBox.show = true;
},
closeRightBox(refresh) {
this.rightBox.show = false; this.rightBox.show = false;
if (refresh) {
this.getTableData();
}
}, },
jumpTo(data, id) { jumpTo(data, id) {
bus.$emit("menu-change", data); bus.$emit("menu-change", data);
this.$router.push({ this.$router.push({
@@ -576,7 +348,7 @@
} }
}); });
}, },
getTableData: function () { getTableData() {
this.tableData = []; this.tableData = [];
this.$set(this.searchLabel, "pageNo", this.pageObj.pageNo); this.$set(this.searchLabel, "pageNo", this.pageObj.pageNo);
this.$set(this.searchLabel, "pageSize", this.pageObj.pageSize); this.$set(this.searchLabel, "pageSize", this.pageObj.pageSize);
@@ -584,10 +356,10 @@
this.$get('promServer', this.searchLabel).then(response => { this.$get('promServer', this.searchLabel).then(response => {
this.loading = false; this.loading = false;
if (response.code === 200) { if (response.code === 200) {
for (var i = 0; i < response.data.list.length; i++) { for (let i = 0; i < response.data.list.length; i++) {
for (var j = 0; j < this.idcData.length; j++) { for (let j = 0; j < this.dcData.length; j++) {
if (response.data.list[i].idcId == this.idcData[j].id) { if (response.data.list[i].idcId == this.dcData[j].id) {
response.data.list[i].idc = Object.assign({}, this.idcData[j]); response.data.list[i].idc = this.dcData[j];
break; break;
} }
} }
@@ -597,14 +369,8 @@
} }
}) })
}, },
cleanPromServer: function () { cleanPromServer() {
this.promServer = { this.promServer = JSON.parse(JSON.stringify(this.blankPromServer));
id: '',
host: '',
port: 9090,
idcId: '',
idc: {id: '', name: '', location: ''}
}
}, },
pageNo(val) { pageNo(val) {
this.pageObj.pageNo = val; this.pageObj.pageNo = val;
@@ -615,7 +381,7 @@
localStorage.setItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId, val); localStorage.setItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId, val);
this.getTableData(); this.getTableData();
}, },
search: function (searchObj) { search(searchObj) {
this.pageObj.pageNo = 1; this.pageObj.pageNo = 1;
this.searchLabel = {}; this.searchLabel = {};
for (let item in searchObj) { for (let item in searchObj) {
@@ -625,86 +391,29 @@
} }
this.getTableData(); this.getTableData();
}, },
addNewData(type) { //获取dc数据
if (type === 'IDC') { getDcData() {
this.$post('idc', this.addIdcData).then(res => { return new Promise(resolve => {
if (res.code === 200) { this.$get('idc').then(response => {
const h = this.$createElement; if (response.code === 200) {
this.$notify({ this.dcData = response.data.list;
message: h('i', {style: 'color: teal'}, '添加成功'),
duration: 2000
});
this.getIdcData()
} else {
const h = this.$createElement;
this.$notify({
message: h('i', {style: 'color: teal'}, res.msg),
duration: 2000
});
}
})
}
},
getSingleIDCData(data, item) {
if (item !== 'edit') {
this.idcSelectedData = '';
this.idcData.forEach(item => {
if (item.id === data) {
this.idcSelectedData = item
} }
resolve();
}); });
} else { });
this.idcData.forEach(item => {
if (item.id === data) {
this.popIdcData.name = item.name
this.popIdcData.location = item.location
this.popIdcData.principal = item.principal
this.popIdcData.tel = item.tel
}
});
}
},
getUserData() {
this.$get('sys/user/list').then(response => {
if (response.code === 200) {
this.idcUserData = response.data.list
}
})
},
editData(data, id, item) {
item.id = id;
this.$put(data, item).then(res => {
if (res.code === 200) {
const h = this.$createElement;
this.$notify({
message: h('i', {style: 'color: teal'}, '修改成功'),
duration: 2000
})
} else {
const h = this.$createElement;
this.$notify({
message: h('i', {style: 'color: teal'}, res.msg),
duration: 2000
})
}
})
},
closeAllPop: function () {
this.$refs.idcConfigBox.forEach((item) => {
item.show(false)
})
}, },
}, },
mounted: function () { mounted: function () {
//初始化数据
Promise.all([this.getDcData()]).then(response => {
this.getTableData();
});
//是否存在分页缓存 //是否存在分页缓存
let pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId); let pageSize = localStorage.getItem('nz-pageSize-' + localStorage.getItem('nz-username') + '-' + this.tableId);
if (pageSize != 'undefined' && pageSize != null) { if (pageSize != 'undefined' && pageSize != null) {
this.pageObj.pageSize = pageSize this.pageObj.pageSize = pageSize
} }
this.getIdcData();
this.getUserData();
this.$nextTick(() => { this.$nextTick(() => {
//绑定滚动条事件控制top按钮 //绑定滚动条事件控制top按钮
let el = this.$refs.promTable.$el.querySelector(".el-table__body-wrapper"); let el = this.$refs.promTable.$el.querySelector(".el-table__body-wrapper");
@@ -733,9 +442,6 @@
}, },
watch: { watch: {
'promServer.idc': function (n, o) {
this.promServer.idcId = n.id;
},
promServer: { promServer: {
deep: true, deep: true,
handler(n) { handler(n) {

View File

@@ -19,7 +19,8 @@ import plTable from 'pl-table'
import 'pl-table/themes/index.css' import 'pl-table/themes/index.css'
import {post, get, put, del} from './http.js' import {post, get, put, del} from './http.js'
import {toTop, clickoutside, scrollBar, bottomBoxWindow, stringTimeParseToUnix, unixTimeParseToString, chartResizeTool} from './tools.js' import {toTop, clickoutside, scrollBar, bottomBoxWindow, stringTimeParseToUnix, unixTimeParseToString, chartResizeTool} from './components/common/js/tools.js'
import * as constants from './components/common/js/constants.js'
import Pagination from "./components/common/pagination"; //引入全局分页组件 import Pagination from "./components/common/pagination"; //引入全局分页组件
@@ -77,6 +78,7 @@ Vue.prototype.$post = post;
Vue.prototype.$get = get; Vue.prototype.$get = get;
Vue.prototype.$put = put; Vue.prototype.$put = put;
Vue.prototype.$delete = del; Vue.prototype.$delete = del;
Vue.prototype.$CONSTANTS = constants;
Vue.prototype.$toTop = toTop; //toTop置顶按钮方法 Vue.prototype.$toTop = toTop; //toTop置顶按钮方法
Vue.prototype.$bottomBoxWindow = bottomBoxWindow; //底部上滑框控制 Vue.prototype.$bottomBoxWindow = bottomBoxWindow; //底部上滑框控制
Vue.prototype.$stringTimeParseToUnix = stringTimeParseToUnix; Vue.prototype.$stringTimeParseToUnix = stringTimeParseToUnix;