iot-ui-app/components/iot-components/switch-btn/iots-switch-btn.vue

123 lines
2.3 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 v-if="logShow" class="iconfont icon-unordered-list" @click="clickLog"></view>
</view>
<view class="attr-item-right">
<view class="attr-value item-switch-btn">
<view class="iconfont icon-kaiguan" @click="changeSwitch" :class="switchValue?'active':''"></view>
<!-- <u-button type="primary"><view class="iconfont icon-kaiguan"></view></u-button> -->
</view>
</view>
</view>
</template>
<script>
export default{
name: 'iots-switch-btn',
props:{
// 选择值
value: {
type: Boolean,
default: false
},
// 大小
size:{
type:Number,
default:50
},
// 加载状态
loading:{
type:Boolean,
default:false
},
// 图标处理后
icon: {
type: [String],
default: 'icon-gongnengdingyi'
},
name: {
type: [String],
default: ''
},
logShow:{
type: [Boolean],
default: true
}
},
data() {
return {
switchValue: this.value
};
},
watch: {
value(newValue) {
this.switchValue = newValue;
}
},
methods:{
// 点击步进器
changeSwitch() {
let flag = !this.switchValue
console.log("e",flag)
this.$emit('input', flag);
this.$emit('change', flag);
},
clickLog(){
this.$emit('clickLog');
}
}
}
</script>
<style lang="scss" scoped>
@import '../common.css';
.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;
// }
// }
.attr-item-right{
flex: 1;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
.attr-value{
display: flex;
align-items: center;
justify-content: flex-end;
height: 70rpx;
flex: 1;
}
}
}
.icon-kaiguan{
padding: 16rpx;
background: #e5e5e5;
color: #7f7f7f;
font-size: 40rpx;
border-radius: 50%;
font-weight: bold;
&.active{
background: #0960ff;
color: #fff;
}
}
</style>