IndicatorDegrade.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="degrade-wrap" :class="wrapClass">
  3. <view class="degrade-icon">{{ icon }}</view>
  4. <view class="degrade-text">{{ text }}</view>
  5. <view class="degrade-action" v-if="retry && scene === 'error'">
  6. <text class="retry-btn" @tap="onRetry">重试</text>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. /**
  12. * IndicatorDegrade —— 降级态合集(P0-5,跨页面复用)
  13. * 文案契约:PRD §5.5 九个场景 + 新增 `incomplete` 场景(合规,文案硬编码在此组件内)
  14. *
  15. * Props:
  16. * scene {String} 必填:n0 / n1 / missing / invalid / upload-date / skip / unit-mismatch / other-type / error / incomplete
  17. * dates {Array} 缺失日期列表(skip 场景用)
  18. * date {String} 跳比参考日期(skip 场景用)
  19. * count {Number} 其他类型期数(other-type 场景用)
  20. * retry {Function} error 场景的重试回调
  21. */
  22. export default {
  23. name: 'IndicatorDegrade',
  24. props: {
  25. scene: { type: String, required: true },
  26. dates: { type: Array, default: function() { return [] } },
  27. date: { type: String, default: '' },
  28. count: { type: Number, default: 0 },
  29. /** scene='incomplete' 专用:报告总份数 */
  30. totalReportCount: { type: Number, default: 0 },
  31. /** scene='incomplete' 专用:本指标已具备期数 */
  32. pointsCount: { type: Number, default: 0 },
  33. retry: { type: Function, default: null }
  34. },
  35. computed: {
  36. wrapClass: function() {
  37. return this.scene === 'error' ? 'degrade-wrap-error' : 'degrade-wrap'
  38. },
  39. icon: function() {
  40. var s = this.scene
  41. if (s === 'n0' || s === 'missing' || s === 'invalid') return '—'
  42. if (s === 'n1') return '●'
  43. if (s === 'upload-date') return '*'
  44. if (s === 'skip') return 'ⓘ'
  45. if (s === 'unit-mismatch') return '*'
  46. if (s === 'other-type') return '—'
  47. if (s === 'error') return '⚠'
  48. if (s === 'incomplete') return 'ⓘ'
  49. return '—'
  50. },
  51. text: function() {
  52. var s = this.scene
  53. if (s === 'n0') return '暂无该指标数据'
  54. if (s === 'n1') return '首次记录 · 暂无对比'
  55. if (s === 'missing') return '该期未检测'
  56. if (s === 'invalid') return '该期无有效数值'
  57. if (s === 'upload-date') return '未识别到采样日期,按上传日期记录'
  58. if (s === 'skip') {
  59. var ds = this.dates && this.dates.length > 0 ? this.dates.join('、') : ''
  60. return ds ? ('ⓘ ' + ds + ' 两期未检测该项,对比的是 ' + (this.date || '')) : ('ⓘ 中间 N 期未检测该项,对比的是 ' + (this.date || ''))
  61. }
  62. if (s === 'unit-mismatch') return '该期单位与其他期不同,未做换算'
  63. if (s === 'other-type') return '其他报告类型有 ' + this.count + ' 期数据,暂不支持跨类型对比'
  64. if (s === 'error') return '趋势数据加载失败,请下拉重试'
  65. if (s === 'incomplete') {
  66. var pc = this.pointsCount || 0
  67. var tc = this.totalReportCount || 0
  68. if (pc === 0 && tc === 0) return '该成员暂无报告数据'
  69. if (pc === 0) return '共 ' + tc + ' 份报告,本指标暂无可显示的历史数据'
  70. return '共 ' + tc + ' 份报告,本指标目前 ' + pc + ' 期数据(历史数据整理中)'
  71. }
  72. return ''
  73. }
  74. },
  75. methods: {
  76. onRetry: function() {
  77. if (this.retry) this.retry()
  78. }
  79. }
  80. }
  81. </script>
  82. <style scoped lang="scss">
  83. .degrade-wrap {
  84. display: flex;
  85. flex-direction: row;
  86. align-items: center;
  87. justify-content: center;
  88. margin: 40rpx 0;
  89. padding: 16rpx;
  90. }
  91. .degrade-wrap-error {
  92. background: #FEF2F2;
  93. border: 1rpx dashed #FCA5A5;
  94. border-radius: 8rpx;
  95. }
  96. .degrade-icon {
  97. font-size: 24rpx;
  98. margin-right: 10rpx;
  99. width: 34rpx;
  100. text-align: center;
  101. }
  102. .degrade-text {
  103. font-size: 22rpx;
  104. line-height: 32rpx;
  105. color: #94A3B8;
  106. }
  107. .degrade-wrap-error .degrade-text {
  108. color: #EF4444;
  109. }
  110. .retry-btn {
  111. font-size: 20rpx;
  112. color: #EF4444;
  113. background: #FEE2E2;
  114. border-radius: 8rpx;
  115. padding: 6rpx 14rpx;
  116. margin-left: 12rpx;
  117. }
  118. </style>