| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <template>
- <view class="progress-wrap">
- <view class="progress-track" :style="{ background: trackBg }">
- <view class="progress-fill" :style="{ width: safePercent + '%', background: fillColor }"></view>
- </view>
- </view>
- </template>
- <script>
- /**
- * 线性进度条(原子组件,纯 flexbox,不用 CSS Grid)
- * 用法:<ProgressBar :percent="68" />
- */
- export default {
- name: 'ProgressBar',
- props: {
- // 0-100
- percent: {
- type: Number,
- default: 0
- },
- color: {
- type: String,
- default: '#2E6FA8'
- },
- trackBg: {
- type: String,
- default: '#E8F3FC'
- }
- },
- computed: {
- safePercent() {
- var p = Number(this.percent) || 0
- if (p < 0) return 0
- if (p > 100) return 100
- return p
- },
- fillColor() {
- return this.color || '#2E6FA8'
- }
- }
- }
- </script>
- <style scoped>
- .progress-wrap {
- width: 100%;
- }
- .progress-track {
- width: 100%;
- height: 18rpx;
- border-radius: 10rpx;
- overflow: hidden;
- display: flex;
- align-items: stretch;
- }
- .progress-fill {
- height: 18rpx;
- border-radius: 10rpx;
- }
- </style>
|