feat: panel改版

This commit is contained in:
陈劲松
2021-01-12 20:39:59 +08:00
committed by chenjinsong
parent 7d391d7aec
commit 5d9483ed63
4 changed files with 261 additions and 41 deletions

View File

@@ -1157,7 +1157,7 @@ li{
padding: 0 20px 20px 20px; padding: 0 20px 20px 20px;
border-radius: 10px; border-radius: 10px;
} }
.nz-pop-select-area { .nz-pop-select-area, .nz-pop-select-panel {
padding: 0 !important; padding: 0 !important;
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1) !important; box-shadow: 0 2px 12px 0 rgba(0,0,0,.1) !important;
} }

View File

@@ -0,0 +1,183 @@
<template>
<el-popover :placement="placement" popper-class="nz-pop nz-pop-select-panel" ref="selectPanelPopBox" transition="slide" v-model="popBox.show" width="400">
<div>
<div class="pop-item-wider">
<slot name="header"></slot>
<div class="select-panel-tree">
<el-tree
:data="panelData"
:draggable="!panelLock"
:expand-on-click-node="false"
:filter-node-method="filterNode"
:props="{label: 'name', children: 'children'}"
@check-change="clearOthers"
@node-click="selectPanel"
@node-drop="nodeDrop"
check-on-click-node
check-strictly
default-expand-all
highlight-current
node-key="id"
ref="panelTree">
<div class="tree--node" slot-scope="{ node, data }">
<span>{{ node.label }}</span>
<span class="tree--operation" v-if="!panelLock">
<span @click.stop="deletePanel(data)" class="panel-dropdown-btn panel-dropdown-btn-delete"><i class="nz-icon nz-icon-delete"></i></span>
<span @click.stop="editPanel(data)" class="panel-dropdown-btn"><i class="nz-icon nz-icon-edit"></i></span>
</span>
</div>
</el-tree>
</div>
</div>
</div>
<div slot="reference">
<slot name="trigger"></slot>
</div>
</el-popover>
</template>
<script>
export default {
name: "selectPanel",
props:{
placement: {type: String},
isEdit: {type: Boolean, default: true},
panelData: {type: Array},
showPanel: {type: Number},
panelLock: {type: Boolean, default: true},
filterPanel: {type: String},
},
mounted() {
this.$refs.panelTree.setCurrentKey(this.showPanel);
},
watch: {
filterPanel: {
immediate: true,
handler(n) {
this.$refs.panelTree && this.$refs.panelTree.filter(n);
}
}
},
data(){
return {
popBox: {show: false},
panel: {id: '', name: ''}
}
},
methods:{
/*
* node: 被拖的节点
* relative: 发生关系的节点
* position: ['before', 'after', 'inner'] 与relative节点的关系
* */
nodeDrop(node, relative, position, event) {
if (position === 'inner') {
node.data.pid = relative.data.id;
} else {
node.data.pid = relative.data.pid;
}
this.updateWeight();
},
filterNode(value, data) {
if (!value) return true;
return data.name.indexOf(value) !== -1;
},
updateWeight() {
let toUpdate = [];
let count = 0;
handler(this.panelData);
function handler(panelData) {
panelData.forEach(panel => {
panel.weight = count++;
toUpdate.push({id: panel.id, pid: panel.pid, weight: panel.weight});
if (panel.children && panel.children.length > 0) {
handler(panel.children);
}
});
}
this.$put("/panel/tree", toUpdate);
},
deletePanel(data) {
this.$emit("deletePanel", data);
},
editPanel(data) {
this.$emit("editPanel", data);
},
openBox(panel){
if (panel) {
this.panel = panel;
this.$refs.panelTree.setChecked(this.panel.id, true, false);
}
},
esc(){
this.popBox.show = false;
},
//确认选择某个节点,与父组件交互
selectPanel(data, checked, child) {
this.panel = data;
this.$emit('selectPanel', this.panel);
this.esc();
},
//tree设为单选
clearOthers(data, checked, child) {
if (checked) {
this.panel = data;
this.$refs.panelTree.setCheckedKeys([data.id]);
} else {
this.panel = {id: '', name: ''};
}
}
},
beforeDestroy(){
}
}
</script>
<style lang="scss">
.select-panel-tree {
height: 350px;
overflow: auto;
}
.select-panel-tree .el-tree-node__content {
height: 34px;
line-height: 34px;
}
.select-panel-tree .el-tree-node__content:hover {
color: $global-text-color-active;
}
.select-panel-tree .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
background-color: #F5F7FA;
font-weight: bold;
color: $global-text-color-active;
}
.tree--node {
display: flex;
justify-content: space-between;
width: calc(100% - 28px);
}
.tree--operation {
opacity: 0;
}
.tree--node:hover .tree--operation {
opacity: 1;
}
.panel-dropdown-btn {
color: #60BEFF;
}
.panel-dropdown-btn:hover {
color: #409EFF;
}
.panel-dropdown-btn-delete {
color: #F98D9A;
}
.panel-dropdown-btn-delete:hover {
color: #D96D7A;
}
</style>

View File

@@ -168,7 +168,7 @@
<div class="right-box-form-box" ref="scrollbar"> <div class="right-box-form-box" ref="scrollbar">
<el-form :model="editChart" :rules="rules" class="right-box-form right-box-form-left" label-position="right" label-width="120px" ref="chartForm"> <el-form :model="editChart" :rules="rules" class="right-box-form right-box-form-left" label-position="right" label-width="120px" ref="chartForm">
<el-form-item :label="$t('dashboard.panel.title')" prop="panelName" v-if="showPanel.type != 'dashboard' && showPanel.type != 'project' && showPanel.type != 'asset' && showPanel.type != 'model'"> <el-form-item :label="$t('dashboard.panel.title')" prop="panelName" v-if="showPanel.type != 'dashboard' && showPanel.type != 'project' && showPanel.type != 'asset' && showPanel.type != 'model'">
<el-autocomplete <!--<el-autocomplete
:fetch-suggestions="panelSuggestion" :fetch-suggestions="panelSuggestion"
@input="inputPanel" @input="inputPanel"
placeholder="" placeholder=""
@@ -178,7 +178,18 @@
v-model.trim="editChart.panelName" v-model.trim="editChart.panelName"
value-key="name" value-key="name"
> >
</el-autocomplete> </el-autocomplete>-->
<select-panel :filter-panel="filterPanel" :panel-lock="true" :panelData="panelData" :placement="'bottom-start'" @selectPanel="selectPanel" ref="selectPanel"
v-if="!editChart.id">
<template v-slot:header>
<div class="panel-select-header">
<el-input :placeholder="$t('overall.search')" clearable size="mini" style="width: 340px; margin-right: 5px;" v-model="filterPanel"></el-input>
</div>
</template>
<template v-slot:trigger>
<el-input placeholder="" readonly="readonly" size="small" v-model="panelName"></el-input>
</template>
</select-panel>
<el-input :value="editChart.panelName" readonly="readonly" size="small" v-if="editChart.id"></el-input> <el-input :value="editChart.panelName" readonly="readonly" size="small" v-if="editChart.id"></el-input>
</el-form-item> </el-form-item>
@@ -495,6 +506,8 @@
import promqlInput from "./explore/promqlInput"; import promqlInput from "./explore/promqlInput";
import {nzNumber} from "../../common/js/validate"; import {nzNumber} from "../../common/js/validate";
import richTextEditor from "../../charts/richTextEditor"; import richTextEditor from "../../charts/richTextEditor";
import selectPanel from "../../common/popBox/selectPanel";
var rz = { var rz = {
methods: { methods: {
rz(e) { rz(e) {
@@ -518,7 +531,7 @@
save:false, save:false,
}, },
editChart: {}, editChart: {},
filterPanel: "",
statisticsList: this.$CONSTANTS.statisticsList, statisticsList: this.$CONSTANTS.statisticsList,
promqlCount: 1, promqlCount: 1,
@@ -625,7 +638,8 @@
'chart-preview':chartPreview, 'chart-preview':chartPreview,
'alert-chart-param':alertChartParam, 'alert-chart-param':alertChartParam,
'promql-input': promqlInput, 'promql-input': promqlInput,
'rich-text-editor':richTextEditor 'rich-text-editor':richTextEditor,
selectPanel,
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
@@ -641,6 +655,10 @@
clickOutside() { clickOutside() {
this.esc(false); this.esc(false);
}, },
selectPanel(panel) {
this.panelName = panel.name;
this.panelId = panel.id;
},
toAddPanel() { toAddPanel() {
this.$refs.panelBox2.show(true); this.$refs.panelBox2.show(true);
this.panel = { this.panel = {
@@ -829,10 +847,8 @@
}, },
// 新建图表 // 新建图表
addCharts(params) { addCharts(params) {
let panelId;
let panel;
//先处理panel //先处理panel
let panelPromise=new Promise(resolve => { /*let panelPromise=new Promise(resolve => {
if (this.panelId) { if (this.panelId) {
panelId = this.panelId; panelId = this.panelId;
panel=this.panelData.find(p => p.id === this.panelId); panel=this.panelData.find(p => p.id === this.panelId);
@@ -861,17 +877,16 @@
}); });
} }
} }
}); });*/
panelPromise.then(()=>{ //panelPromise.then(()=>{
if (panelId) { if (this.panelId) {
this.panelId = panelId;
this.$post('panel/' + this.panelId + '/charts', params ? params : this.editChart).then(response => { this.$post('panel/' + this.panelId + '/charts', params ? params : this.editChart).then(response => {
if (response.code === 200) { if (response.code === 200) {
this.esc(); this.esc();
this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")}); this.$message({duration: 1000, type: 'success', message: this.$t("tip.saveSuccess")});
this.$refs.chartForm.resetFields();//清空表单 this.$refs.chartForm.resetFields();//清空表单
this.$emit('on-create-success', 'create', response.data, params, panel); this.$emit('on-create-success', 'create', response.data, params, {id: this.panelId, name: this.panelName});
} else { } else {
if (response.msg) { if (response.msg) {
this.$message.error(response.msg); this.$message.error(response.msg);
@@ -882,7 +897,7 @@
this.prevent_opt.save=false this.prevent_opt.save=false
}); });
} }
}) //})
}, },
// 更新图表 // 更新图表
updateCharts(params) { updateCharts(params) {
@@ -1684,21 +1699,6 @@
} }
} }
}, },
editChart: {
deep: true,
immediate: true,
handler(n) {
let panel = this.panelData.find(p => {
return p.name == n.panelName;
});
if(panel){
this.panelId = panel.id;
}else{
this.panelId = null;
}
}
}
}, },
beforeDestroy() { beforeDestroy() {
if(this.$refs.chartTag){ if(this.$refs.chartTag){

View File

@@ -6,13 +6,27 @@
</div> </div>
<template v-else> <template v-else>
<div class="top-tool-main-left"> <div class="top-tool-main-left">
<el-dropdown @command="panelChange" class="panel-dropdown-title" trigger="click" placement="bottom-start" > <select-panel :current-panel="showPanel" :filter-panel="filterPanel" :panel-lock="panelLock" :panelData="panelData" :placement="'bottom-start'" @deletePanel="del" @editPanel="edit"
@selectPanel="panelChange" ref="selectPanel" style="width: 300px;">
<template v-slot:header>
<div class="panel-select-header">
<el-input :placeholder="$t('overall.search')" clearable size="mini" style="width: 340px; margin-right: 5px;" v-model="filterPanel"></el-input>
<span :title='$t("dashboard.panel.createPanelTitleSec")' @click="toAdd" class="panel-select-add" v-has="'panel_toAdd'"><i class="nz-icon nz-icon-plus"></i></span>
</div>
</template>
<template v-slot:trigger>
<el-input class="panel-name input-x-mini-26" placeholder="" readonly="readonly" v-model="showPanel.name">
<i class="el-icon-menu" slot="prefix"></i>
</el-input>
</template>
</select-panel>
<!--<el-dropdown @command="panelChange" class="panel-dropdown-title" trigger="click" placement="bottom-start" >
<el-row :gutter="10" class="el-dropdown-link" style="padding-right: 5px"> <el-row :gutter="10" class="el-dropdown-link" style="padding-right: 5px">
<el-col :span="21" class="panel-list-title" :title="showPanel.name">{{showPanel.name}}</el-col> <el-col :span="21" class="panel-list-title" :title="showPanel.name">{{showPanel.name}}</el-col>
<el-col :span="3" style="padding-left:0px !important;"><i class="nz-icon nz-icon-arrow-down"></i></el-col> <el-col :span="3" style="padding-left:0px !important;"><i class="nz-icon nz-icon-arrow-down"></i></el-col>
</el-row> </el-row>
<el-dropdown-menu class="nz-dashboard-dropdown panel-dropdown-title-space" slot="dropdown" > <el-dropdown-menu class="nz-dashboard-dropdown panel-dropdown-title-space" slot="dropdown" >
<!--<el-dropdown-item>{{$t('dashboard.panel.createPanelTitleSec')}}</el-dropdown-item>--> &lt;!&ndash;<el-dropdown-item>{{$t('dashboard.panel.createPanelTitleSec')}}</el-dropdown-item>&ndash;&gt;
<div ref="dashboardScrollbar" style="height: 100%; overflow: auto"> <div ref="dashboardScrollbar" style="height: 100%; overflow: auto">
<el-dropdown-item > <el-dropdown-item >
<el-row class="panel-list-width" :gutter="10" > <el-row class="panel-list-width" :gutter="10" >
@@ -47,7 +61,7 @@
</draggable> </draggable>
</div> </div>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>-->
</div> </div>
<div class="top-tool-main-right"> <div class="top-tool-main-right">
<div class="top-tool-search relative-position margin-r-20"> <div class="top-tool-search relative-position margin-r-20">
@@ -108,6 +122,8 @@
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import pickTime from "../../common/pickTime"; import pickTime from "../../common/pickTime";
import exportXLSX from "../../common/exportXLSX"; import exportXLSX from "../../common/exportXLSX";
import selectPanel from "../../common/popBox/selectPanel";
export default { export default {
name: "panel", name: "panel",
data() { data() {
@@ -192,6 +208,7 @@
draggable, draggable,
'pick-time':pickTime, 'pick-time':pickTime,
'export-excel':exportXLSX, 'export-excel':exportXLSX,
selectPanel,
}, },
methods: { methods: {
//刷新 //刷新
@@ -217,8 +234,8 @@
//this.$refs.chartList.initCurrentRecordNum(); //this.$refs.chartList.initCurrentRecordNum();
this.$refs.chartList.cleanData(); this.$refs.chartList.cleanData();
this.getData(this.filter); this.getData(this.filter);
}, },
del(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"),
@@ -696,7 +713,7 @@
panelContent.style.background = '#d8dce1'; panelContent.style.background = '#d8dce1';
}, },
filterPanelFocus:function(e){ /*filterPanelFocus:function(e){
e.stopPropagation(); e.stopPropagation();
}, },
filterPanelFunc:function(){ filterPanelFunc:function(){
@@ -706,7 +723,7 @@
}else{ }else{
this.showPanelList = this.panelData; this.showPanelList = this.panelData;
} }
}, },*/
tableListEnter(){ tableListEnter(){
this.tableHover = true; this.tableHover = true;
}, },
@@ -751,8 +768,7 @@
} }
.panel-list-width { .panel-list-width {
width:240px; width: 400px;
overflow: hidden;
} }
.panel-dropdown-title { .panel-dropdown-title {
@@ -857,10 +873,6 @@
} }
/* end--Panel-自定义可编辑的el-select下拉框样式*/ /* end--Panel-自定义可编辑的el-select下拉框样式*/
.panel-select-width {
width: 150px;
}
.panel-refresh-interval { .panel-refresh-interval {
margin-right: 5px; margin-right: 5px;
float: right; float: right;
@@ -949,6 +961,31 @@
} }
</style> </style>
<style lang="scss"> <style lang="scss">
.panel-name {
position: relative;
.el-input__prefix i {
position: absolute;
left: 3px;
top: calc(50% + 1px);
transform: translateY(-50%);
}
}
.panel-name>input {
cursor: pointer;
padding-left: 27px !important;
}
.panel-select-header {
padding: 0 0 10px 16px;
width: 400px;
}
.panel-select-add {
cursor: pointer;
}
.panel-select-add:hover {
color: $global-text-color-active;
}
.panel .top-tools input { .panel .top-tools input {
background-color: $content-right-background-color; background-color: $content-right-background-color;
} }