detail.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <el-drawer :model-value="visible" direction="rtl" size="700px" append-to-body @update:model-value="$emit('update:visible', $event)">
  3. <!-- 自定义标题 -->
  4. <template #header>
  5. <div class="drawer-head">
  6. <el-icon style="color:#5b9bd5;margin-right:8px;"><List /></el-icon>
  7. <span class="drawer-head-name">{{ row.dictName }}</span>
  8. <span class="drawer-head-type">{{ row.dictType }}</span>
  9. </div>
  10. </template>
  11. <div class="drawer-wrap">
  12. <!-- 加载中 -->
  13. <div v-if="loading" class="drawer-loading">
  14. <el-icon class="is-loading"><Loading /></el-icon>
  15. <span>加载中...</span>
  16. </div>
  17. <!-- 空数据 -->
  18. <div v-else-if="!dataList.length" class="drawer-empty">
  19. <el-icon style="font-size:36px;"><Document /></el-icon>
  20. <div>暂无字典数据</div>
  21. </div>
  22. <template v-else>
  23. <!-- 统计卡片 -->
  24. <el-row :gutter="12" class="stat-row">
  25. <el-col :span="disabledCount > 0 ? 8 : 12">
  26. <div class="stat-card">
  27. <div class="stat-num">{{ dataList.length }}</div>
  28. <div class="stat-label">共计条目</div>
  29. </div>
  30. </el-col>
  31. <el-col :span="disabledCount > 0 ? 8 : 12">
  32. <div class="stat-card">
  33. <div class="stat-num success">{{ normalCount }}</div>
  34. <div class="stat-label">正常</div>
  35. </div>
  36. </el-col>
  37. <el-col v-if="disabledCount > 0" :span="8">
  38. <div class="stat-card">
  39. <div class="stat-num danger">{{ disabledCount }}</div>
  40. <div class="stat-label">停用</div>
  41. </div>
  42. </el-col>
  43. </el-row>
  44. <!-- 数据列表 -->
  45. <div v-for="item in dataList" :key="item.dictCode" class="dict-item">
  46. <div class="dict-cell">
  47. <div class="dict-cell-key">标签</div>
  48. <div class="dict-cell-val">
  49. <el-tag v-if="item.listClass && item.listClass !== 'default'" :type="item.listClass === 'primary' ? undefined : item.listClass" size="small">{{ item.dictLabel }}</el-tag>
  50. <span v-else>{{ item.dictLabel }}</span>
  51. </div>
  52. </div>
  53. <div class="dict-cell">
  54. <div class="dict-cell-key">键值</div>
  55. <div class="dict-cell-val">{{ item.dictValue }}</div>
  56. </div>
  57. <div class="dict-cell">
  58. <div class="dict-cell-key">状态</div>
  59. <div class="dict-cell-val">
  60. <el-tag :type="item.status === '0' ? 'success' : 'danger'" size="small">
  61. {{ item.status === '0' ? '正常' : '停用' }}
  62. </el-tag>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. </div>
  68. </el-drawer>
  69. </template>
  70. <script setup>
  71. import { listData } from '@/api/system/dict/data'
  72. const props = defineProps({
  73. visible: { type: Boolean, default: false },
  74. row: { type: Object, default: () => ({}) }
  75. })
  76. const emit = defineEmits(['update:visible'])
  77. const loading = ref(false)
  78. const dataList = ref([])
  79. const normalCount = computed(() => dataList.value.filter(r => r.status === '0').length)
  80. const disabledCount = computed(() => dataList.value.filter(r => r.status !== '0').length)
  81. watch(() => props.visible, (val) => {
  82. if (val) {
  83. loadData()
  84. } else {
  85. dataList.value = []
  86. }
  87. })
  88. function loadData() {
  89. if (!props.row?.dictType) return
  90. loading.value = true
  91. dataList.value = []
  92. listData({ dictType: props.row.dictType, pageSize: 100, pageNum: 1 }).then(response => {
  93. dataList.value = response.rows || []
  94. }).catch(() => {}).finally(() => {
  95. loading.value = false
  96. })
  97. }
  98. </script>
  99. <style scoped>
  100. .drawer-head {
  101. display: flex;
  102. align-items: center;
  103. }
  104. .drawer-head-name {
  105. font-size: 16px;
  106. font-weight: 600;
  107. color: #2c3e50;
  108. margin-right: 8px;
  109. }
  110. .drawer-head-type {
  111. font-size: 14px;
  112. color: #95a5a6;
  113. font-family: monospace;
  114. }
  115. .drawer-wrap {
  116. padding: 0 20px 20px;
  117. }
  118. .drawer-loading {
  119. display: flex;
  120. align-items: center;
  121. justify-content: center;
  122. height: 120px;
  123. color: #aaa;
  124. font-size: 13px;
  125. gap: 8px;
  126. }
  127. .drawer-empty {
  128. text-align: center;
  129. color: #bbb;
  130. padding: 60px 0;
  131. font-size: 13px;
  132. }
  133. .drawer-empty .el-icon {
  134. display: block;
  135. margin: 0 auto 8px;
  136. }
  137. .stat-row {
  138. margin-bottom: 16px;
  139. }
  140. .stat-card {
  141. background: #f7f9fb;
  142. border: 1px solid #e8ecf0;
  143. border-radius: 6px;
  144. padding: 10px 14px;
  145. text-align: center;
  146. }
  147. .stat-num {
  148. font-size: 22px;
  149. font-weight: 700;
  150. color: #2c3e50;
  151. }
  152. .stat-num.success { color: #27ae60; }
  153. .stat-num.danger { color: #e74c3c; }
  154. .stat-label {
  155. font-size: 11px;
  156. color: #95a5a6;
  157. margin-top: 4px;
  158. }
  159. .dict-item {
  160. display: grid;
  161. grid-template-columns: 1fr 1fr 1fr;
  162. border: 1px solid #e8ecf0;
  163. border-radius: 6px;
  164. overflow: hidden;
  165. margin-bottom: 8px;
  166. }
  167. .dict-cell {
  168. display: grid;
  169. grid-template-columns: 70px 1fr;
  170. border-right: 1px solid #f0f4f8;
  171. }
  172. .dict-cell:last-child {
  173. border-right: 0;
  174. }
  175. .dict-cell-key {
  176. padding: 9px 14px;
  177. font-size: 12px;
  178. color: #888;
  179. background: #f7f9fb;
  180. border-right: 1px solid #f0f4f8;
  181. }
  182. .dict-cell-val {
  183. padding: 9px 14px;
  184. font-size: 13px;
  185. color: #2c3e50;
  186. word-break: break-all;
  187. display: flex;
  188. align-items: center;
  189. }
  190. </style>