index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div
  3. v-loading="loading"
  4. class="l-flex--col"
  5. >
  6. <template v-if="!loading">
  7. <warning
  8. v-if="error"
  9. @retry="getDefaults"
  10. />
  11. <template v-if="canEdit">
  12. <tabs
  13. :items="tabs"
  14. :active.sync="active"
  15. />
  16. <keep-alive>
  17. <component
  18. :is="activeComponent"
  19. class="l-flex__fill"
  20. :info="info"
  21. @refresh="refresh"
  22. />
  23. </keep-alive>
  24. </template>
  25. <template v-else-if="!info">
  26. <div class="l-flex__fill l-flex--row center u-color--info">
  27. <div class="l-flex--col center">
  28. <div class="has-padding">未绑定接收卡,请联系管理员</div>
  29. </div>
  30. </div>
  31. </template>
  32. </template>
  33. </div>
  34. </template>
  35. <script>
  36. import { getReceivingCard } from '@/api/external'
  37. import {
  38. send,
  39. reset
  40. } from '@/views/device/detail/monitor'
  41. import Tabs from '@/views/device/detail/components/Tabs'
  42. import ReceivingCardTopology from './ReceivingCardTopology'
  43. import ReceivingCardInfo from './ReceivingCardInfo'
  44. import ReceivingCardInfoEdit from './ReceivingCardInfoEdit'
  45. export default {
  46. name: 'ReceivingCard',
  47. components: {
  48. Tabs,
  49. ReceivingCardTopology,
  50. ReceivingCardInfo,
  51. ReceivingCardInfoEdit
  52. },
  53. props: {
  54. device: {
  55. type: Object,
  56. default () {
  57. return null
  58. }
  59. },
  60. online: {
  61. type: [Boolean, String],
  62. default: false
  63. }
  64. },
  65. data () {
  66. return {
  67. active: 'topology',
  68. tabs: [
  69. { key: 'topology', name: '接收卡状态监测' },
  70. { key: 'info', name: '接收卡信息' }
  71. ],
  72. loading: false,
  73. error: false,
  74. info: null
  75. }
  76. },
  77. computed: {
  78. canEdit () {
  79. return this.accessSet.has(this.Access.MANAGE_DEVICES)
  80. },
  81. activeComponent () {
  82. switch (this.active) {
  83. case 'topology':
  84. return 'ReceivingCardTopology'
  85. case 'info':
  86. return this.canEdit ? 'ReceivingCardInfoEdit' : 'ReceivingCardInfo'
  87. default:
  88. return null
  89. }
  90. }
  91. },
  92. activated () {
  93. !this.info && this.getDefaults()
  94. },
  95. methods: {
  96. getDefaults () {
  97. if (this.loading) {
  98. return
  99. }
  100. this.info = null
  101. this.loading = true
  102. this.error = false
  103. getReceivingCard(this.device.id).then(
  104. ({ data }) => {
  105. if (data?.topology) {
  106. data.topology = JSON.parse(data.topology)
  107. }
  108. this.info = data
  109. },
  110. () => {
  111. this.error = true
  112. }
  113. ).finally(() => {
  114. this.loading = false
  115. })
  116. },
  117. refresh (options) {
  118. if (options.reset) {
  119. reset('topology')
  120. this.getDefaults()
  121. }
  122. if (options.tip && this.online) {
  123. this.$confirm(
  124. `${options.tip}发生变化,需重启设备生效,是否立即重启?`,
  125. { type: 'warning' }
  126. ).then(() => {
  127. send('/restart/ask')
  128. })
  129. }
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .c-card-grid {
  136. display: grid;
  137. overflow: auto;
  138. &.empty {
  139. position: relative;
  140. background: url("~@/assets/screen.png") 0 0 / 96px 96px repeat;
  141. &::after {
  142. content: "未录入";
  143. display: inline-flex;
  144. justify-content: center;
  145. align-items: center;
  146. position: absolute;
  147. top: 50%;
  148. left: 50%;
  149. width: 200px;
  150. height: 64px;
  151. color: #fff;
  152. font-size: 18px;
  153. letter-spacing: 6px;
  154. background-color: rgba($info--dark, 0.8);
  155. transform: translate(-50%, -50%);
  156. }
  157. }
  158. }
  159. .o-receiving-card {
  160. position: relative;
  161. display: inline-flex;
  162. justify-content: center;
  163. align-items: center;
  164. color: $info;
  165. background: url("~@/assets/screen.png") 0 0 / 100% 100% no-repeat;
  166. &.normal,
  167. &.error {
  168. color: $success--dark;
  169. }
  170. &::after {
  171. content: attr(status);
  172. position: absolute;
  173. top: 0;
  174. right: 0;
  175. width: 40px;
  176. padding: 4px 0;
  177. color: #fff;
  178. font-size: 12px;
  179. line-height: 1;
  180. text-align: center;
  181. background-color: $info;
  182. transform-origin: top right;
  183. transform: scale(0.8);
  184. }
  185. &.normal::after {
  186. background-color: $black;
  187. }
  188. &.error::after {
  189. background-color: $error;
  190. }
  191. &__status {
  192. display: inline-flex;
  193. justify-content: center;
  194. align-items: center;
  195. width: 36px;
  196. height: 36px;
  197. padding-bottom: 4px;
  198. color: $black;
  199. font-size: 14px;
  200. font-weight: bold;
  201. background: url("~@/assets/icon_card_unknown.png") 0 0 / 100% 100% no-repeat;
  202. }
  203. &.normal {
  204. .o-receiving-card__status {
  205. color: $error;
  206. background-image: url("~@/assets/icon_card_normal.png");
  207. }
  208. }
  209. &.error {
  210. .o-receiving-card__status {
  211. background-image: url("~@/assets/icon_card_abnormal.png");
  212. }
  213. }
  214. &__arrow {
  215. position: absolute;
  216. z-index: 1;
  217. &.left {
  218. transform: rotate(-90deg);
  219. }
  220. &.right {
  221. transform: rotate(90deg);
  222. }
  223. &.bottom {
  224. transform: rotate(180deg);
  225. }
  226. &::before {
  227. content: "";
  228. position: absolute;
  229. left: 50%;
  230. bottom: 20px;
  231. width: 6px;
  232. height: 46px;
  233. background-color: currentColor;
  234. transform: translateX(-50%);
  235. }
  236. &::after {
  237. content: "";
  238. position: absolute;
  239. left: 50%;
  240. bottom: 66px;
  241. border-left: 10px solid transparent;
  242. border-right: 10px solid transparent;
  243. border-bottom: 10px solid currentColor;
  244. transform: translateX(-50%);
  245. }
  246. }
  247. }
  248. </style>