修改我的页面:class=语法问题,:class=[]

master
chen 2022-03-28 11:21:04 +08:00
parent 2002b246ac
commit 446bcf228e
2 changed files with 187 additions and 3 deletions

View File

@ -0,0 +1,176 @@
<template>
<view
class="circle-progress"
:style="{
width: widthPx + 'px',
height: widthPx + 'px',
backgroundColor: bgColor
}"
>
<!-- 有的不支持canvas-id属性必须用id属性 -->
<canvas
class="canvas-bg"
:canvas-id="canvasId"
:id="canvasId"
:style="{
width: widthPx + 'px',
height: widthPx + 'px'
}"
></canvas>
<canvas
class="canvas"
:canvas-id="elId"
:id="elId"
:style="{
width: widthPx + 'px',
height: widthPx + 'px'
}"
></canvas>
<slot></slot>
</view>
</template>
<script>
export default {
name: 'circle-progress',
props: {
//
percent: {
type: Number,
default: 0,
// 0100
validator: val => {
return val >= 0 && val <= 100;
}
},
//
inactiveColor: {
type: String,
default: '#ececec'
},
//
activeColor: {
type: String,
default: '#009dff'
},
// 线rpx
borderWidth: {
type: [Number, String],
default: 14
},
// rpx
width: {
type: [Number, String],
default: 200
},
// ms
duration: {
type: [Number, String],
default: 1500
},
//
bgColor: {
type: String,
default: '#ffffff'
}
},
data() {
return {
canvasId: this.randomId(), //
elId: this.randomId(),
widthPx: uni.upx2px(this.width), // px
borderWidthPx: uni.upx2px(this.borderWidth), // px
startAngle: -Math.PI / 2, // canvas312
progressContext: null, // canvas
newPercent: 0, //
oldPercent: 0 //
};
},
watch: {
percent(nVal, oVal = 0) {
if (nVal > 100) nVal = 100;
if (nVal < 0) oVal = 0;
this.newPercent = nVal;
this.oldPercent = oVal;
setTimeout(() => {
this.drawCircleByProgress(oVal);
}, 50);
}
},
created() {
// 使
this.newPercent = this.percent;
this.oldPercent = 0;
},
mounted() {
this.drawProgressBg();
this.drawCircleByProgress(this.oldPercent);
},
methods: {
//progressID
randomId(){
return 'progressId'+parseInt(Math.random()*1000000)
},
drawProgressBg() {
let ctx = uni.createCanvasContext(this.canvasId, this);
ctx.setLineWidth(this.borderWidthPx); //
ctx.setStrokeStyle(this.inactiveColor); // 线
ctx.beginPath(); //
let radius = this.widthPx / 2;
ctx.arc(radius, radius, radius - this.borderWidthPx, 0, 2 * Math.PI, false);
ctx.stroke(); //
ctx.draw();
},
drawCircleByProgress(progress) {
let ctx = this.progressContext;
if (!ctx) {
ctx = uni.createCanvasContext(this.elId, this);
this.progressContext = ctx;
}
//
ctx.setLineCap('round');
// 线
ctx.setLineWidth(this.borderWidthPx);
ctx.setStrokeStyle(this.activeColor);
//
let time = Math.floor(this.duration / 200);
let endAngle = ((2 * Math.PI) / 100) * progress + this.startAngle;
ctx.beginPath();
// canvas
let radius = this.widthPx / 2;
ctx.arc(radius, radius, radius - this.borderWidthPx, this.startAngle, endAngle, false);
ctx.stroke();
ctx.draw();
//
if (this.newPercent > this.oldPercent) {
progress++;
if (progress > this.newPercent) return;
} else {
//
progress--;
if (progress < this.newPercent) return;
}
setTimeout(() => {
//
this.drawCircleByProgress(progress);
}, time);
}
}
};
</script>
<style scoped>
.circle-progress {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.canvas-bg {
position: absolute;
}
.canvas {
position: absolute;
}
</style>

View File

@ -34,13 +34,20 @@
<!-- 预约及时率上门准时率项目报修率 -->
<view class="disja mar-s20">
<view v-for="(item,index) in percentageList" :key="index" class="disjcac fc col3">
<cmd-progress type="circle" :percent="item.num" :width="60" :stroke-color="['#00a2e9','#e87c00','#0b56ec'][index]" :circleStrokeColor="['#c6e6f5','#f4dfc6','#c8d7f5'][index]" :strokeShape="'square'"></cmd-progress>
<!-- <cmd-progress type="circle" :percent="item.num" :width="60" :stroke-color="['#00a2e9','#e87c00','#0b56ec'][index]" :circleStrokeColor="['#c6e6f5','#f4dfc6','#c8d7f5'][index]" :strokeShape="'square'"></cmd-progress> -->
<arprogress :percent="item.num"
:inactiveColor="['#c6e6f5','#f4dfc6','#c8d7f5'][index]"
:activeColor="['#00a2e9','#e87c00','#0b56ec'][index]"
:borderWidth="7.8"
:width="120"
:duration="500"
bgColor="transparent"><text :style="{color: ['#00a2e9','#e87c00','#0b56ec'][index]}">{{item.num}}%</text></arprogress>
<view class="fon24 mar-s20">{{item.title}}</view>
</view>
</view>
<!-- 六宫格 -->
<view class="disjbac fw bacf" style="margin: 30rpx -20rpx 0rpx -20rpx;">
<view @tap="chooseGridEv(index)" class="disjcac fc width50 pad-sx40" v-for="(item,index) in gridList" :key="index" :class="`${(index%2!=0) ? 'bleft' : ''} ${(index < gridList.length-2) ? 'bbot' : ''}`" style="box-sizing: border-box;">
<view @tap="chooseGridEv(index)" class="disjcac fc width50 pad-sx40" v-for="(item,index) in gridList" :key="index" :class="[`${(index%2!=0) ? 'bleft' : ''} ${(index < gridList.length-2) ? 'bbot' : ''}`]" style="box-sizing: border-box;">
<image :src="item.imgsrc" mode="widthFix" lazy-load :style="{width: [52,52,46,50,46,52][index] + 'rpx',height: [48,45,52,52,53,52][index] + 'rpx'}"></image>
<view class="fon26 col3 mar-s20">{{item.title}}</view>
</view>
@ -60,8 +67,9 @@
import cmdProgress from '@/components/cmd-progress/cmd-progress.vue';
//
import footTabOne from '@/components/foot-tabs/foot-tab-one.vue';
import arprogress from '@/components/ar-circle-progress/index.vue'
export default {
components:{statusNavSlot,cmdProgress,'foot-tab' :footTabOne},
components:{statusNavSlot,cmdProgress,'foot-tab' :footTabOne,arprogress},
data() {
return {
newHeight: uni.getSystemInfoSync().statusBarHeight + 50,