| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <template>
- <view class="rp-wrap" :style="wrapStyle">
- <!-- SVG 环形:圆环 stroke-dasharray 实现进度 -->
- <svg :viewBox="viewBox" class="rp-svg" :style="svgStyle">
- <circle :cx="center" :cy="center" :r="radius" :stroke="trackColor" :stroke-width="strokeW" fill="none" />
- <circle
- :cx="center"
- :cy="center"
- :r="radius"
- :stroke="barColor"
- :stroke-width="strokeW"
- fill="none"
- :stroke-linecap="'round'"
- :stroke-dasharray="dashArray"
- :stroke-dashoffset="dashOffset"
- :transform="'rotate(-90 ' + center + ' ' + center + ')'"
- />
- </svg>
- <view class="rp-center">
- <text class="rp-value" :style="{ fontSize: valueFont }">{{ valueText }}</text>
- <text v-if="label" class="rp-label">{{ label }}</text>
- </view>
- </view>
- </template>
- <script>
- /**
- * RingProgress — 环形进度(原子级,SVG 自绘,rpx 自适应)
- * 用途:学时达标 / 认证进度 / 综合评级环
- * 契约:percent 0-100;valueText 居中数字;label 下方文字
- */
- export default {
- name: 'RingProgress',
- props: {
- percent: { type: Number, default: 0 },
- // 展示尺寸(px,组件内部按 rpx 换算)
- size: { type: Number, default: 160 },
- color: { type: String, default: '#2E6FA8' },
- label: { type: String, default: '' },
- valueText: { type: String, default: '' }
- },
- data() {
- return {
- trackColor: '#E3ECF4',
- strokeW: 10
- }
- },
- computed: {
- center() {
- return this.size / 2
- },
- radius() {
- return (this.size - this.strokeW) / 2
- },
- viewBox() {
- return '0 0 ' + this.size + ' ' + this.size
- },
- svgStyle() {
- return {
- width: this.size + 'px',
- height: this.size + 'px'
- }
- },
- wrapStyle() {
- return {
- width: this.size + 'px',
- height: this.size + 'px'
- }
- },
- circumference() {
- return 2 * Math.PI * this.radius
- },
- dashArray() {
- return this.circumference + ''
- },
- dashOffset() {
- var p = this.percent
- if (p < 0) p = 0
- if (p > 100) p = 100
- return this.circumference * (1 - p / 100)
- },
- barColor() {
- return this.color
- },
- valueFont() {
- return Math.round(this.size * 0.24) + 'px'
- }
- }
- }
- </script>
- <style scoped>
- .rp-wrap {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .rp-svg {
- display: block;
- }
- .rp-center {
- position: absolute;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .rp-value {
- font-weight: 700;
- color: #1F4E79;
- line-height: 1.2;
- }
- .rp-label {
- font-size: 20rpx;
- color: #3B5A78;
- margin-top: 4rpx;
- }
- </style>
|