<!-- 自定义 echart 组件 -->
<template>
<div>
<!-- echart表格 -->
<div :id="id" class="myChart" :style="echartStyle"></div>
</div>
</template>
<script>
export default {
props: {
// 样式
echartStyle: {
type: Object,
default(){
return {}
}
},
// 标题文本
titleText: {
type: String,
default: ''
},
// 提示框键名
tooltipFormatter: {
type: String,
default: ''
},
// 扇形区域名称
opinion: {
type: Array,
default(){
return []
}
},
// 提示框标题
seriesName: {
type: String,
default: ''
},
// 扇形区域数据
opinionData: {
type: Array,
default(){
return []
}
},
id:{
type: String,
default: ''
}
},
data(){
return {
//
}
},
mounted(){
this.$nextTick(function() {
this.drawPie(this.id);
});
},
methods: {
// 监听扇形图点击
eConsole(param) {
// 向父组件传值
this.$emit("currentEchartData",param.name);
},
// 绘制饼状图
drawPie(id){
this.charts = this.$echarts.init(document.getElementById(id));
this.charts.on("click", this.eConsole);
this.charts.setOption({
title: {
text: this.titleText, // 标题文本
left: 30,
top:10,
textStyle:{
fontSize:16,
fontWeight:400
}
},
tooltip : {
trigger: 'item',
// formatter: "{a} <br/> " + this.tooltipFormatter + ":{c} ({d}%)"
formatter: this.tooltipFormatter + ":{c} ({d}%)"
},
legend: {
orient : 'vertical',
right:20,
bottom:20,
type:'scroll',
// left: 'center',
data: this.opinion // 扇形区域名称
},
series : [
{
name:this.seriesName, // 提示框标题
type: 'pie',
radius : '65%',
center: ['35%', '50%'],
selectedMode: 'single',
data:this.opinionData, // 扇形区域数据
itemStyle:{
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
},
},
// normal:{
// label:{
// show: true,
// formatter: '{b} : {c} ({d}%)'
// },
// labelLine :{show:true}
// }
}
],
color:['#77A1E5', '#449A2A', '#24CBE5', '#8BBC21', '#C42525', '#058DC7', '#FF9655', '#DDDF00']
})
}
}
}
</script>
<style>
.myChart{
width: 47%;
height:300px;
float:left;
margin:0 0 2% 2%;
border:1px solid #e1e1e1;
-webkit-border-radius:4px;
-moz-border-radius:4px;
-ms-border-radius:4px;
border-radius:4px;
}
</style>
https://www.cnblogs.com/crazycode2/p/7902813.html
<template>
<div class="ux-layout-main" style="padding: 25px 0px 25px 25px;">
<div style="margin-bottom: 10px;" class="clearfix">
<ux-tabs @tab-click="onTabClick">
<template v-for="platformModule in platformModuleArray">
<ux-tab-pane :tab="platformModule.ptiName" :name="platformModule.ptiId + ''">
<template v-if="platformModule.moduleVersions">
<template v-for="moduleVersion in platformModule.moduleVersions">
<!-- 内容 -->
<m-echarts :id="platformModule.ptiId + moduleVersion.module"
:echartStyle="s"
:titleText="moduleVersion.module + '版本分布图'"
:tooltipFormatter="b"
:opinion="moduleVersion.versions"
:seriesName="d"
:opinionData="moduleVersion.lst"
v-on:currentEchartData="getEchartData"></m-echarts>
</template>
</template>
</ux-tab-pane>
</template>
</ux-tabs>
<ux-form layout="inline">
<ux-form-item label="机房">
<ux-select v-model="searchData.labInfo" name="labInfo" style="width: 188px;" placeholder="请选择" @change="onSelectedDrug">
<ux-option
v-for="lab in labInfos"
:key="lab.labId"
:label="lab.labName"
:value="lab.labId">
</ux-option>
</ux-select>
</ux-form-item>
<ux-form-item label="节点">
<ux-select v-model="searchData.node" name="node" style="width: 188px;" placeholder="请选择">
<ux-option
v-for="nodeInfo in nodeInfos"
:key="nodeInfo.id"
:label="nodeInfo.name"
:value="nodeInfo.id">
</ux-option>
</ux-select>
</ux-form-item>
<ux-form-item>
<ux-input v-model="searchData.version" placeholder="请输入版本号"/>
</ux-form-item>
<ux-form-item>
<ux-button type="primary">查询</ux-button>
</ux-form-item>
<ux-form-item>
<ux-button type="primary" @click="()=>reset()">重置</ux-button>
</ux-form-item>
</ux-form>
<article class="doc" style="margin-top:10px;">
<ux-table :columns="columns" v-model="data" :loading="loading" size="middle" bordered :row-selection="rowSelection"/>
</article>
<div>
<div class="search-version">
<span >已选择{{rowSelection.selectedRowKeys.length}}项</span>
<template>
<ux-checkbox v-model="cChecked" @change="searchServerId" label="仅显示已选择项"/>
<ux-popconfirm title="本次操作建议不超过10条记录查询,坚持本次操作?" :disabled="rowSelection.selectedRowKeys.length < 10" @confirm="onConfirm" @cancel="onCancel">
<ux-button type="primary" @click="()=>batchSearchVersion()">批量查询版本号</ux-button>
</ux-popconfirm>
</template>
</div>
<div class="pagination-css" style="float:right;margin: 15px 8px 0px 0px;">
<ux-pagination
show-quick-jumper
show-size-changer
:page-size-options="[10, 20, 40, 50, 60, 100]"
@page-size-change="pageSizeChange"
:show-before-total="showBeforeTotal"
:current="pageNum"
:page-size="pageSize"
:total="dataTotal">
</ux-pagination>
</div>
</div>
</div>
</div>
</template>
<script>
import service from 'servicePath/index';
import mEcharts from 'viewsPath/versionMgn/Echarts.vue';
import UxMessage from '@suning/uxcool/es/message';
const options = {
// tooltip: {
// trigger: 'item',
// // formatter: '{b}   {c} <br>{d}%',
// formatter: '{b} {c} {d}%',
// },
// legend: {
// show: false,
// },
// series: [
// {
// name: '未处理事件',
// type: 'pie',
// radius: '55%',
// center: ['50%', '50%'],
// data: [{ value: 30, name: '灾难' }, { value: 80, name: '警告' }, { value: 40, name: '严重' }],
// },
// ],
};
const defaultSearchData = {
labInfo: null,
platform: null,
node: null,
version : null,
ids : null,
flushFlag : 0,
}
function getCols() {
return [
{
key: 'labName',
title: '机房',
dataIndex: 'labName',
cellRender(text, record) {
return {text};
},
},
{
key: 'nodeName',
title: '节点',
dataIndex: 'nodeName',
cellRender(text, record) {
return {text};
},
},
{
key: 'serverName',
title: '机器',
dataIndex: 'serverName',
cellRender(text, record) {
return {text};
},
},
{
key: 'version',
title: '版本',
dataIndex: 'version',
cellRender(text, record) {
return {text};
},
}];
}
function getData() {
var params = {
platform : this.searchData.platform,
labInfo : this.searchData.labInfo,
node : this.searchData.node,
version : this.searchData.version,
flushFlag : this.searchData.flushFlag,
ids : this.searchData.ids,
rows : this.pageSize,
page : this.pageNum,
}
console.info("getData() platform = ", this.searchData.platform,
", labInfo = ", this.searchData.labInfo, " , node = ", this.searchData.node, " , version = ", this.searchData.version,
" , flushFlag = ", this.searchData.flushFlag,
" , ids = ", this.searchData.ids, " , rows = ", this.pageSize, " , page = ", this.pageNum);
service.getMachineVersionInfo(params).then((data) => {
this.dataTotal = data.total;
this.data = data.rows;
this.loading = false;
});
}
export default {
components: {
mEcharts
},
data() {
return {
platformModuleArray:[],
options,
// a:'水果销售统计',
b:'版本数量',
// c:['香蕉','苹果','橘子'],
d:'',
// e:[
// {value:3, name:'香蕉'},
// {value:3, name:'苹果'},
// {value:3, name:'橘子'}
// ],
s: {
height: ''
},
searchData: {
...defaultSearchData,
},
labInfos : [],
nodeInfos : [],
pageSize : 10,
pageNum : 1,
columns : [],
data : [],
loading: true,
dataTotal: 0,
rowSelection: {
selectedRowKeys: [],
onChange(selectedRowKeys, selectedRow, op, prevSelectRowKeys) {
this.selectedRowKeys = selectedRowKeys;
}
},
cChecked : false,
confirm : false,
};
},
methods: {
getAllPlatformModule(){
return service.getAllPlatformModule().then((data) => {
if(data && data.length >= 0){
this.platformModuleArray = data;
this.searchData.platform = data[0].ptiId;
this.getNodeInfo();
}
});
},
getEchartData(val){
console.log(val);
},
getEffectInfolab(){
return service.getEffectInfolab().then((data) => {
this.labInfos = data;
});
},
getNodeInfo(){
this.searchData.node = "";
var params = {
platform : this.searchData.platform,
labInfo : this.searchData.labInfo,
}
console.info("getNodeInfo() platform = ", this.searchData.platform, " , labInfo = " + this.searchData.labInfo);
return service.getNodeInfo(params).then((data) => {
this.nodeInfos = data;
});
},
showBeforeTotal(total, pageSize, totalPage, pageNo, range) {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
this.loading = true;
this.pageNum = pageNo;
getData.call(this);
// return "共" + total + "条, 每页显示" + pageSize + "条, 共" + totalPage + "页";
return "共" + total + "条记录";
},
pageSizeChange(current, size) {
this.pageSize = size;
},
onSelectedDrug(){
this.getNodeInfo();
},
reset(){
this.rowSelection.selectedRowKeys = [];
this.cChecked = false;
this.searchData.labInfo = null;
this.searchData.node = null;
this.searchData.version = null;
this.searchData.ids = null;
this.searchData.flushFlag = 0;
this.pageNum = 1;
this.getNodeInfo();
},
onTabClick(args) {
this.searchData.platform = args;
this.reset();
},
searchServerId(e){
if(e.target.checked){
this.searchData.ids = this.rowSelection.selectedRowKeys.join(",");
this.data = getData.call(this);
} else{
this.reset();
}
},
batchSearchVersion(){
if(this.rowSelection.selectedRowKeys.length == 0){
UxMessage.warning('请选择机器进行批量查询版本号操作!');
} else if(this.rowSelection.selectedRowKeys.length <= 10){
console.info(1111);
this.searchData.ids = this.rowSelection.selectedRowKeys.join(",");
getData.call(this);
} else if(this.rowSelection.selectedRowKeys.length > 10 && this.confirm){
console.info(2222);
this.confirm = false;
this.searchData.flushFlag = 1;
this.searchData.ids = this.rowSelection.selectedRowKeys.join(",");
getData.call(this);
this.searchData.flushFlag = 0;
}
},
onConfirm() {
console.log('confirm');
this.confirm = true;
this.batchSearchVersion();
},
onCancel() {
this.confirm = false;
},
},
created() {
this.getAllPlatformModule();
this.getEffectInfolab();
this.columns = getCols.call(this);
this.data = getData.call(this);
},
mounted(){
}
};
</script>
<style scoped>
.clearfix:before,
.clearfix:after {
content:"";
display:table;
}
.clearfix:after {
clear:both;
}
.search-version {
float:left;
margin:15px 0 0 8px;
}
.search-version>span {
margin-right:10px;
}
</style>