瀏覽代碼

修改switch 控件

zhengkaixin 11 月之前
父節點
當前提交
75e3f4f181

+ 1 - 1
components/tree/tree-node.vue

@@ -67,7 +67,7 @@
 		 
 		<view class="tags" v-if="level!=0">
 			<view class="tagsList">
-				<template  v-if="node.type!='7'" >
+				<template  v-if="node.type!='7'&&node.type!='6'" >
 					<view class="meter-state" v-if="node.online">
 									在线
 					</view>

+ 2 - 2
config/.env.dev.js

@@ -16,13 +16,13 @@ const UNI_APP = {
 	 //openId:"oK9Wr54VbEh3xvWYmD_zT5NbH4AY",
 	openId:"oLowyuOJvTszgk96C0f8j0XfcEXg",//zkx
 	
-	openId:"oLowyuAJ1Ld0ivnLj4qp1k5Vy_l4", //老板
+	//openId:"oLowyuAJ1Ld0ivnLj4qp1k5Vy_l4", //老板
 	//openId:"oLowyuFTU3SzpvU4pGNzWk7NC9y0", //wky
 	
 	//openId:"oLowyuHCGgMomNBQEXZSbb5SJxfQ",//杨所
 	//openId:"oLowyuMxAACLlFRDYcM9-w6v0b6o",
 	//openId:"oLowyuMMjIkA_bLA4MXzRQ3KJB2E",//fjj
-	openId:"oLowyuB1PliW0qAnJJ56axydeUOM",//zq
+	//openId:"oLowyuB1PliW0qAnJJ56axydeUOM",//zq
 	
 	//appid
 	VUE_APP_WXAPPID:"wx0b3c41a903053808",

+ 14 - 10
pages/equipmentDataMonitoring/electronicMonitoring.vue

@@ -70,19 +70,23 @@
 				智能监控电源
 				 <u-icon name="arrow-right" color="#cccccc" size="24" ></u-icon>
 			</view>
-			<view class="icon"  style="    display: flex;" >
+			<view class="icon" >
 				
-				<span>关</span>
+			<!-- 	<span>关</span>
 				<u-switch size="32" @change="switchBtnApi(meterDetail,$event)"  
 				 v-model="meterDetail.switchStatus"   inactive-color="#ff9900" ></u-switch >
-				<span>开</span>
-				<!-- <img src="@/assets/img/control.png"
-				 @tap.stop="switchBtnApi(meterDetail,0)"
-				 v-if="meterDetail.switchStatus"
-				 alt="" />
-				<img   @tap.stop="switchBtnApi(meterDetail,1)"
-				v-else
-				src="@/assets/img/switchClose.png" alt="" /> -->
+				<span>开</span> -->
+				
+				
+				<u-switch-jp size="42" 
+				:obj="{
+					width: '4em',
+					transform:'translateX(300%)',
+					sz:['已关闭','已开启'],
+					fontSize:'32rpx'
+				}"
+				@change="switchBtnApi(meterDetail,$event)"  
+				 v-model="meterDetail.switchStatus"   inactive-color="#ff9900" ></u-switch-jp >
 			</view>
 		</view>
 		<!-- 各时段用电量 -->

+ 9 - 4
pages/managementList/applyAuthorisation.vue

@@ -14,10 +14,15 @@
 					 </view>
 					 
 					 <view class="item2" >
-					 		<span>关</span>
-					 		<u-switch size="32" @change="switchBtnApi(item,$event)"  
-					 		 v-model="item.switchStatus"   inactive-color="#ff9900" ></u-switch >
-					 		<span>开</span>
+					 		<u-switch-jp size="42"
+					 		:obj="{
+					 			width: '4em',
+					 			transform:'translateX(300%)',
+					 			sz:['已关闭','已开启'],
+					 			fontSize:'32rpx'
+					 		}"
+					 		@change="switchBtnApi(item,$event)"  
+					 		 v-model="item.switchStatus"   inactive-color="#ff9900" ></u-switch-jp >
 					 </view>
 					 
 				</view>

+ 9 - 4
pages/tenantList/switchDetail.vue

@@ -10,10 +10,15 @@
 			   		电源状态
 			   	</view>
 			   	<view class="icon"  style="    display: flex;">
-					<span>关</span>
-					<u-switch size="32" @change="switchBtnApi(meterDetails.meter,$event)"  
-					 v-model="meterDetails.meter.switchStatus"   inactive-color="#ff9900" ></u-switch >
-					<span>开</span>
+					<u-switch-jp size="42"
+					:obj="{
+						width: '4em',
+						transform:'translateX(300%)',
+						sz:['已关闭','已开启'],
+						fontSize:'32rpx'
+					}"
+					@change="switchBtnApi(meterDetails.meter,$event)"  
+					 v-model="meterDetails.meter.switchStatus"   inactive-color="#ff9900" ></u-switch-jp >
 					<!-- 
 					<img src="@/assets/img/switchIcon.png"
 					 @tap.stop="switchBtnApi(meterDetails.meter,0)" class="img"

+ 222 - 0
uni_modules/uview-ui/components/u-switch-jp/u-switch-jp.vue

@@ -0,0 +1,222 @@
+<template>
+	<view class="u-switch" :class="[value == true ? 'u-switch--on' : '', disabled ? 'u-switch--disabled' : '']" @tap="onClick"
+	 :style="[switchStyle]">
+		<span class=" u-switch--text" v-if="obj.sz"
+		 :style="[textStyle]"
+		>{{obj.sz[value== true?1:0]}}</span>
+		<view class="u-switch__node node-class" 
+		 :style="[nodeStyle]"
+		>
+			<u-loading :show="loading" class="u-switch__loading" :size="size * 0.6" :color="loadingColor" />
+		</view>
+	</view>
+</template>
+
+<script>
+	/**
+	 * switch 开关选择器
+	 * @description 选择开关一般用于只有两个选择,且只能选其一的场景。
+	 * @tutorial https://www.uviewui.com/components/switch.html
+	 * @property {Boolean} loading 是否处于加载中(默认false)
+	 * @property {Boolean} disabled 是否禁用(默认false)
+	 * @property {String Number} size 开关尺寸,单位rpx(默认50)
+	 * @property {String} active-color 打开时的背景色(默认#2979ff)
+	 * @property {Boolean} inactive-color 关闭时的背景色(默认#ffffff)
+	 * @property {Boolean | Number | String} active-value 打开选择器时通过change事件发出的值(默认true)
+	 * @property {Boolean | Number | String} inactive-value 关闭选择器时通过change事件发出的值(默认false)
+	 * @event {Function} change 在switch打开或关闭时触发
+	 * @example <u-switch v-model="checked" active-color="red" inactive-color="#eee"></u-switch>
+	 */
+	export default {
+		name: "u-switch",
+		props: {
+			// 是否为加载中状态
+			obj: {
+				type: Object,
+				default () {
+					// 如下
+					// return [{
+					// 	text: '确定',
+					// 	color: '',
+					// 	fontSize: ''
+					// }]
+					return {};
+				}
+			},
+			loading: {
+				type: Boolean,
+				default: false
+			},
+			// 是否为禁用装填
+			disabled: {
+				type: Boolean,
+				default: false
+			},
+			// 开关尺寸,单位rpx
+			size: {
+				type: [Number, String],
+				default: 50
+			},
+			// 打开时的背景颜色
+			activeColor: {
+				type: String,
+				default: '#2979ff'
+			},
+			// 关闭时的背景颜色
+			inactiveColor: {
+				type: String,
+				default: '#ffffff'
+			},
+			// 通过v-model双向绑定的值
+			value: {
+				type: Boolean,
+				default: false
+			},
+			// 是否使手机发生短促震动,目前只在iOS的微信小程序有效(2020-05-06)
+			vibrateShort: {
+				type: Boolean,
+				default: false
+			},
+			// 打开选择器时的值
+			activeValue: {
+				type: [Number, String, Boolean],
+				default: true
+			},
+			// 关闭选择器时的值
+			inactiveValue: {
+				type: [Number, String, Boolean],
+				default: false
+			},
+		},
+		data() {
+			return {
+
+			}
+		},
+		computed: {
+			textStyle(){
+				
+				let style = {
+					
+					
+				};
+				if(this.obj.fontSize){
+					style.fontSize=this.obj.fontSize
+				}
+				
+				return style;
+			},
+			nodeStyle(){
+				var k= this.size+'rpx'
+				let style = {
+					width:k,
+					height: k
+				};
+				if(this.obj.transform&&this.value==true){
+					style.transform=this.obj.transform
+				}
+				return style;
+			},
+			switchStyle() {
+				let style = {};
+				if(this.obj.width){
+					style.width=this.obj.width
+				}
+				style.fontSize = this.size + 'rpx';
+				style.backgroundColor = this.value ? this.activeColor : this.inactiveColor;
+				
+				return style;
+			},
+			loadingColor() {
+				return this.value ? this.activeColor : null;
+			}
+		},
+		methods: {
+			onClick() {
+				if (!this.disabled && !this.loading) {
+					// 使手机产生短促震动,微信小程序有效,APP(HX 2.6.8)和H5无效
+					if(this.vibrateShort) uni.vibrateShort();
+					this.$emit('input', !this.value);
+					// 放到下一个生命周期,因为双向绑定的value修改父组件状态需要时间,且是异步的
+					this.$nextTick(() => {
+						this.$emit('change', this.value ? this.activeValue : this.inactiveValue);
+					})
+				}
+			}
+		}
+	};
+</script>
+
+<style lang="scss" scoped>
+	@import "../../libs/css/style.components.scss";
+	
+	.u-switch {
+		position: relative;
+		/* #ifndef APP-NVUE */
+		display: inline-block;
+		/* #endif */
+		box-sizing: initial;
+		width: 2em;
+		height: 1em;
+		background-color: #fff;
+		border: 1px solid rgba(0, 0, 0, 0.1);
+		border-radius: 1em;
+		transition: background-color 0.3s;
+		font-size: 50rpx;
+	}
+
+	.u-switch__node {
+		@include vue-flex;
+		align-items: center;
+		justify-content: center;
+		position: absolute;
+		top: 0;
+		left: 0;
+		border-radius: 100%;
+		z-index: 1;
+		background-color: #fff;
+		background-color: #fff;
+		box-shadow: 0 3px 1px 0 rgba(0, 0, 0, 0.05), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 3px 3px 0 rgba(0, 0, 0, 0.05);
+		box-shadow: 0 3px 1px 0 rgba(0, 0, 0, 0.05), 0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 3px 3px 0 rgba(0, 0, 0, 0.05);
+		transition: transform 0.3s cubic-bezier(0.3, 1.05, 0.4, 1.05);
+		transition: transform 0.3s cubic-bezier(0.3, 1.05, 0.4, 1.05), -webkit-transform 0.3s cubic-bezier(0.3, 1.05, 0.4, 1.05);
+		transition: transform cubic-bezier(0.3, 1.05, 0.4, 1.05);
+		transition: transform 0.3s cubic-bezier(0.3, 1.05, 0.4, 1.05)
+	}
+
+	.u-switch__loading {
+		@include vue-flex;
+		align-items: center;
+		justify-content: center;
+	}
+
+	.u-switch--on {
+		background-color: #1989fa;
+	}
+
+	.u-switch--on .u-switch__node {
+		transform: translateX(100%);
+	}
+
+	.u-switch--disabled {
+		opacity: 0.4;
+	}
+	.u-switch--text{
+		@include vue-flex;
+		align-items: center;
+		justify-content: center;
+		position: absolute;
+		top: 0;
+		left: 25rpx;
+	   
+		z-index: 1;
+		transform: translateX(20%);
+		color: #fff;
+	}
+	.u-switch--on{
+		.u-switch--text  {
+			transform: translateX(0%);
+		}
+	}
+	
+</style>