163 lines
3.4 KiB
Vue
163 lines
3.4 KiB
Vue
<template>
|
|
<view class="iots-component-box">
|
|
<view class="attr-item-left">
|
|
<view class="iconfont" :class="icon"></view>
|
|
<view class="attr-name">{{name}}</view>
|
|
<view class="select-list">
|
|
<uni-data-select
|
|
v-model="selectValue"
|
|
:localdata="range"
|
|
:clear="false"
|
|
@change="changeSelect"
|
|
></uni-data-select>
|
|
</view>
|
|
</view>
|
|
<view class="attr-item-right">
|
|
<view class="attr-value item-pie" v-show="charShow">
|
|
<qiun-data-charts
|
|
type="pie"
|
|
:opts="opts"
|
|
:chartData="chartData"
|
|
:canvas2d="true"
|
|
:reshow="charShow"
|
|
:canvasId="canvasId"
|
|
/>
|
|
</view>
|
|
<view class="attr-value item-pie" v-show="!charShow">
|
|
<u-empty></u-empty>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import uniDataSelect from "../../uni-data-select/uni-data-select.vue"
|
|
export default{
|
|
name: 'iots-pie',
|
|
props:{
|
|
// 选择值
|
|
value: {
|
|
type: [String,Number],
|
|
default: false
|
|
},
|
|
// 图表数据
|
|
dataList:{
|
|
type:[String,null],
|
|
default:50
|
|
},
|
|
// 图标
|
|
icon: {
|
|
type: [String],
|
|
default: 'icon-gongnengdingyi'
|
|
},
|
|
name: {
|
|
type: [String],
|
|
default: ''
|
|
}
|
|
},
|
|
components:{
|
|
uniDataSelect
|
|
},
|
|
data() {
|
|
return {
|
|
chartData: {},
|
|
selectValue:this.value,
|
|
charShow: true,
|
|
canvasId:this.$u.guid(32),
|
|
opts: {
|
|
color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
|
|
padding: [5,5,5,5],
|
|
enableScroll: false,
|
|
extra: {
|
|
pie: {
|
|
activeOpacity: 0.5,
|
|
activeRadius: 10,
|
|
offsetAngle: 0,
|
|
labelWidth: 15,
|
|
border: false,
|
|
borderWidth: 3,
|
|
borderColor: "#FFFFFF"
|
|
}
|
|
}
|
|
},
|
|
range: [
|
|
{ value: 0, text: "近1小时" },
|
|
{ value: 1, text: "近1天" },
|
|
{ value: 2, text: "近1周" },
|
|
],
|
|
};
|
|
},
|
|
watch: {
|
|
value(newValue) {
|
|
this.selectValue = newValue;
|
|
}
|
|
},
|
|
mounted() {
|
|
this.getServerData();
|
|
this.canvasId=this.$u.guid(32);
|
|
},
|
|
methods:{
|
|
getServerData() {
|
|
if(this.dataList){
|
|
this.chartData = JSON.parse(this.dataList);
|
|
}else{
|
|
this.charShow = false;
|
|
}
|
|
// setTimeout(() => {
|
|
// //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
|
|
// let res = {
|
|
// series: [
|
|
// {
|
|
// data: [{"name":"一班","value":50},{"name":"二班","value":30},{"name":"三班","value":20},{"name":"四班","value":18},{"name":"五班","value":8}]
|
|
// }
|
|
// ]
|
|
// };
|
|
// this.chartData = JSON.parse(JSON.stringify(res));
|
|
// }, 500);
|
|
},
|
|
// 点击步进器
|
|
changeSelect(e) {
|
|
console.log("e",e)
|
|
this.$emit('input', e);
|
|
this.$emit('change',e);
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.iots-component-box{
|
|
padding: 20rpx 20rpx;
|
|
background: #fff;
|
|
// display: flex;
|
|
// align-items: center;
|
|
// justify-content: space-between;
|
|
margin-top: 20rpx;
|
|
border-radius: 10rpx;
|
|
.attr-item-left{
|
|
display: flex;
|
|
align-items: center;
|
|
font-size: 28rpx;
|
|
color: #000;
|
|
.iconfont{
|
|
margin-right: 20rpx;
|
|
font-size: 40rpx;
|
|
}
|
|
.select-list{
|
|
margin-left: auto;
|
|
width: 160rpx;
|
|
}
|
|
}
|
|
.attr-item-right{
|
|
// flex: 1;
|
|
display: flex;
|
|
// flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: center;
|
|
.attr-value{
|
|
width: 100%;
|
|
height: 600rpx;
|
|
}
|
|
}
|
|
}
|
|
</style> |