CommonTable.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="common-table">
  3. <div class="table__content_label">
  4. <div class="label-t" v-for="(item, index) in columns" :key="`svvhbcth-${index}`" :style="{ flexBasis }">{{
  5. item.name }}</div>
  6. </div>
  7. <div ref="scrollRef" class="table__content_list">
  8. <div class="table__content_list_row" v-for="(item, index) in tableData" :key="`svvhbct-${index}`">
  9. <div v-for="(t, i) in columns" :key="`svvhbctr-${i}`" :style="{ flexBasis }" class="table__content__list_item">
  10. <slot :name="t.prop" :scope="item">
  11. <span v-if="t.prop == 'syswarnLevel'" style="display: flex; align-items: center;justify-content: center;">
  12. <span :class="get(item, t.prop) ? 'icon-pie1' : 'icon-pie'">
  13. <span :class="get(item, t.prop) ? 'icon-item1' : 'icon-item'"></span>
  14. </span>
  15. <span>{{ get(item, t.prop) ? '报警' : '正常' }}</span>
  16. </span>
  17. <span v-else-if="t.prop == 'netStatus'" style="display: flex; align-items: center;justify-content: center;">
  18. <span :class="get(item, t.prop) ? 'icon-pie' : 'icon-pie1'">
  19. <span :class="get(item, t.prop) ? 'icon-item' : 'icon-item1'"></span>
  20. </span>
  21. <span>{{ get(item, t.prop) ? '在线' : '离线' }}</span>
  22. </span>
  23. <span v-else-if="t.prop == 'alarmLevelC'"
  24. :style="{ color: item.alarmLevelC == '低风险' ? '#00d8ff' : item.alarmLevelC == '一般风险' ? '#fcfc22' : item.alarmLevelC == '较大风险' ? '#ff7010' : item.alarmLevelC == '重大风险' ? '#df4e43' : item.alarmLevelC == '报警' ? '#ff0000' : '' }">{{
  25. get(item, t.prop) }}</span>
  26. <span v-else>{{ get(item, t.prop) }}</span>
  27. </slot>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import { computed, ref } from 'vue';
  35. import { useAutoScroll } from '/@/hooks/core/useAutoScroll';
  36. import _ from 'lodash';
  37. let props = defineProps({
  38. columns: {
  39. type: Array as any
  40. },
  41. autoScroll: {
  42. type: Boolean,
  43. default: false
  44. },
  45. tableData: {
  46. type: Array as any
  47. },
  48. defaultValue: {
  49. type: String,
  50. default: ''
  51. }
  52. })
  53. const scrollRef = ref(null);
  54. if (props.autoScroll) {
  55. useAutoScroll(scrollRef);
  56. }
  57. const flexBasis = computed(() => {
  58. return Math.fround(100 / props.columns.length) + '%';
  59. });
  60. /**
  61. * 安全获取对象属性值,当值为 null/undefined/空字符串时返回默认值
  62. *
  63. * @param o 要访问的对象
  64. * @param p 对象属性路径
  65. * @returns 属性值或默认值
  66. */
  67. function get(o, p) {
  68. const d = _.get(o, p);
  69. return _.isNil(d) ? props.defaultValue : d === '' ? props.defaultValue : d;
  70. }
  71. </script>
  72. <style lang="less" scoped>
  73. @import '/@/design/theme.less';
  74. .common-table {
  75. --image-content-label: url('/@/assets/images/home-container/configurable/hsq/1-5.png');
  76. --image-content-text: url('/@/assets/images/company/content-text.png');
  77. --image-list-head: url('/@/assets/images/home-container/configurable/firehome/list-head.png');
  78. --image-content-label-d: url(/@/assets/images/home-container/configurable/minehome/content-label.png);
  79. --image-content-body-d: url('/@/assets/images/home-container/configurable/minehome/content-body.png');
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. position: relative;
  84. width: 100%;
  85. height: 100%;
  86. padding: 10px 0px 0px 0px;
  87. box-sizing: border-box;
  88. .gallery-content {
  89. position: absolute;
  90. &:nth-child(1) {
  91. left: 22px;
  92. top: 4px;
  93. }
  94. &:nth-child(2) {
  95. display: flex;
  96. flex-direction: column;
  97. align-items: flex-end;
  98. right: 24px;
  99. top: 4px;
  100. }
  101. &:nth-child(3) {
  102. left: 22px;
  103. top: 72px;
  104. }
  105. &:nth-child(4) {
  106. display: flex;
  107. flex-direction: column;
  108. align-items: flex-end;
  109. right: 24px;
  110. top: 72px;
  111. }
  112. &:nth-child(5) {
  113. left: 50%;
  114. top: 50%;
  115. transform: translate(-50%, -50%);
  116. }
  117. .gallery-content-text {
  118. margin-bottom: 2px;
  119. }
  120. .gallery-content-text-r {
  121. margin-bottom: 2px;
  122. }
  123. .gallery-content-text1 {
  124. font-size: 24px;
  125. font-family: 'douyuFont';
  126. }
  127. .gallery-content-value,
  128. .gallery-content-value-r {
  129. font-family: 'douyuFont';
  130. color: #fff;
  131. }
  132. }
  133. .table__content_label {
  134. width: 400px;
  135. height: 32px;
  136. display: flex;
  137. justify-content: space-between;
  138. align-items: center;
  139. background-image: var(--image-content-label);
  140. background-size: 100% 100%;
  141. background-repeat: no-repeat;
  142. color: #3df6ff;
  143. .label-t {
  144. text-align: center;
  145. font-size: 14px;
  146. }
  147. }
  148. .table__content_list {
  149. height: calc(100% - 32px);
  150. width: 400px;
  151. display: flex;
  152. flex-direction: column;
  153. padding: 5px 0;
  154. box-sizing: border-box;
  155. overflow-y: auto;
  156. .table__content_list_row {
  157. width: 100%;
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: center;
  161. color: #fff;
  162. margin-bottom: 5px;
  163. background-size: 100% auto;
  164. background-repeat: no-repeat;
  165. background-position: center bottom;
  166. background-image: var(--image-content-text);
  167. span {
  168. display: inline-block;
  169. text-align: center;
  170. }
  171. }
  172. }
  173. .table__content__list_item {
  174. text-align: center;
  175. }
  176. .icon-pie {
  177. position: relative;
  178. width: 12px;
  179. height: 12px;
  180. border-radius: 50%;
  181. background-color: rgba(79, 255, 173, .3);
  182. margin-right: 5px;
  183. }
  184. .icon-pie1 {
  185. position: relative;
  186. width: 12px;
  187. height: 12px;
  188. border-radius: 50%;
  189. background-color: rgba(255, 79, 79, .3);
  190. margin-right: 5px;
  191. }
  192. .icon-item {
  193. position: absolute;
  194. left: 50%;
  195. top: 50%;
  196. transform: translate(-50%, -50%);
  197. width: 6px;
  198. height: 6px;
  199. border-radius: 50%;
  200. background-color: rgba(79, 255, 173);
  201. }
  202. .icon-item1 {
  203. position: absolute;
  204. left: 50%;
  205. top: 50%;
  206. transform: translate(-50%, -50%);
  207. width: 6px;
  208. height: 6px;
  209. border-radius: 50%;
  210. background-color: rgba(255, 79, 79);
  211. }
  212. ::-webkit-scrollbar {
  213. display: none;
  214. }
  215. }
  216. </style>