status-tag.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <text class="status-tag" :class="tagClass">{{ tagText }}</text>
  3. </template>
  4. <script>
  5. /**
  6. * 状态徽标(原子组件)
  7. * 目的:把 status → 文案/颜色的映射收敛到一处,避免各页面各写一份导致口径漂移。
  8. * 用法:<StatusTag status="published" type="cohort" />
  9. */
  10. export default {
  11. name: 'StatusTag',
  12. props: {
  13. // 状态值
  14. status: {
  15. type: String,
  16. default: ''
  17. },
  18. // 业务域:cohort / credit / attendance / promo
  19. type: {
  20. type: String,
  21. default: ''
  22. },
  23. // 自定义文案(优先于映射)
  24. text: {
  25. type: String,
  26. default: ''
  27. }
  28. },
  29. computed: {
  30. tagText() {
  31. if (this.text) return this.text
  32. var map = this.textMap()
  33. return map[this.status] || this.status || '未知'
  34. },
  35. tagClass() {
  36. return 'tag-' + this.colorKey()
  37. },
  38. colorKey() {
  39. var map = this.colorMap()
  40. return map[this.status] || 'grey'
  41. }
  42. },
  43. methods: {
  44. textMap() {
  45. var map = {
  46. // 批次
  47. draft: '未发布',
  48. published: '可报名',
  49. ongoing: '进行中',
  50. full: '已满',
  51. closed: '已截止',
  52. signed: '已报名',
  53. // 学时
  54. effective: '生效中',
  55. pending: '待生效',
  56. objected: '异议中',
  57. rejected: '已驳回',
  58. settled: '已结算',
  59. // 签到
  60. success: '签到成功',
  61. dupe: '已签到',
  62. invalid: '码无效',
  63. // 通用
  64. accepted: '已通过',
  65. rejected2: '未通过',
  66. // 晋升
  67. promoted: '已晋升',
  68. evaluated: '评定中',
  69. // 证据包
  70. done: '已完成',
  71. processing: '生成中',
  72. failed: '生成失败'
  73. }
  74. if (this.type === 'credit') {
  75. return map
  76. }
  77. return map
  78. },
  79. colorMap() {
  80. var map = {
  81. draft: 'grey',
  82. published: 'blue',
  83. ongoing: 'green',
  84. full: 'orange',
  85. closed: 'grey',
  86. signed: 'blue',
  87. effective: 'green',
  88. pending: 'orange',
  89. objected: 'blue',
  90. rejected: 'red',
  91. settled: 'grey',
  92. success: 'green',
  93. dupe: 'blue',
  94. invalid: 'red',
  95. accepted: 'green',
  96. promoted: 'green',
  97. evaluated: 'blue',
  98. done: 'green',
  99. processing: 'blue',
  100. failed: 'red'
  101. }
  102. return map
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .status-tag {
  109. font-size: 22rpx;
  110. padding: 4rpx 16rpx;
  111. border-radius: 8rpx;
  112. line-height: 1.5;
  113. }
  114. .tag-blue { background: #E8F3FC; color: #2E6FA8; }
  115. .tag-green { background: #E6F6EE; color: #0E8A4F; }
  116. .tag-orange { background: #FEF3E2; color: #B9770E; }
  117. .tag-red { background: #FDE8E8; color: #C0392B; }
  118. .tag-grey { background: #F0F4F9; color: #3B5A78; }
  119. </style>