index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <div
  3. ref="wrapper"
  4. v-loading="!loaded && loading"
  5. element-loading-background="transparent"
  6. >
  7. <warning
  8. v-if="!loaded && !loading"
  9. @click="getBoundThirdPartyDevices"
  10. />
  11. <div
  12. v-if="loaded"
  13. class="c-link-state l-flex--row"
  14. :class="className"
  15. >
  16. <div
  17. class="c-link-state__main"
  18. :style="styles"
  19. >
  20. <div
  21. v-for="item in items"
  22. :key="item.key"
  23. class="o-link-item"
  24. :class="item.className"
  25. @click="onClick(item)"
  26. >
  27. <div class="o-link-item__name">{{ item.label }}</div>
  28. <device-player
  29. v-if="item.key === 'led'"
  30. :device="device"
  31. autoplay
  32. retry
  33. />
  34. <svg-icon
  35. v-else
  36. class="o-link-item__img"
  37. :icon-class="item.icon"
  38. />
  39. </div>
  40. <div
  41. v-for="line in lines"
  42. :key="line.key"
  43. class="o-line"
  44. :class="line.className"
  45. />
  46. </div>
  47. </div>
  48. <slot />
  49. </div>
  50. </template>
  51. <script>
  52. import { getBoundThirdPartyDevices } from '@/api/external'
  53. import { ThirdPartyDevice } from '@/constant'
  54. const LinkItems = Object.freeze([
  55. {
  56. key: 'msr',
  57. label: '浪潮屏媒安播云平台'
  58. },
  59. {
  60. key: 'device',
  61. label: '浪潮超高清媒体播控器'
  62. },
  63. {
  64. key: 'led',
  65. label: 'LED大屏'
  66. },
  67. {
  68. key: ThirdPartyDevice.GATEWAY,
  69. alias: 'gateway',
  70. label: '浪潮物联网关',
  71. iconKey: 'gateway',
  72. canClick: true
  73. },
  74. {
  75. key: ThirdPartyDevice.TRAFFIC_CAMERA,
  76. alias: 'traffic_camera',
  77. label: '人流量监测摄像头',
  78. iconKey: 'camera',
  79. canClick: true
  80. },
  81. {
  82. key: ThirdPartyDevice.LED_CAMERA,
  83. alias: 'led_camera',
  84. label: 'LED屏监测摄像头',
  85. iconKey: 'camera',
  86. canClick: true
  87. },
  88. {
  89. key: ThirdPartyDevice.SENDING_CARD,
  90. alias: 'sending_card',
  91. label: '发送控制设备',
  92. iconKey: 'sending-card',
  93. canClick: true
  94. },
  95. {
  96. key: ThirdPartyDevice.RECEIVING_CARD,
  97. alias: 'receiving_card',
  98. label: '接收卡',
  99. iconKey: 'receiving-card',
  100. canClick: true
  101. }
  102. ])
  103. const LineFromeTo = {
  104. 1: ['msr', 'device'],
  105. 2: ['device', ThirdPartyDevice.SENDING_CARD],
  106. 3: [ThirdPartyDevice.SENDING_CARD, ThirdPartyDevice.RECEIVING_CARD],
  107. 4: [ThirdPartyDevice.RECEIVING_CARD, 'led'],
  108. 5: ['msr', ThirdPartyDevice.GATEWAY],
  109. 6: ['msr', ThirdPartyDevice.LED_CAMERA, ThirdPartyDevice.TRAFFIC_CAMERA],
  110. 7: ['msr', ThirdPartyDevice.LED_CAMERA],
  111. 8: ['msr', ThirdPartyDevice.LED_CAMERA],
  112. 9: ['msr', ThirdPartyDevice.TRAFFIC_CAMERA],
  113. 10: [ThirdPartyDevice.GATEWAY, 'led'],
  114. 11: ['msr', ThirdPartyDevice.GATEWAY, ThirdPartyDevice.LED_CAMERA, ThirdPartyDevice.TRAFFIC_CAMERA]
  115. }
  116. export default {
  117. name: 'FullLink',
  118. props: {
  119. device: {
  120. type: Object,
  121. required: true
  122. },
  123. theme: {
  124. type: String,
  125. default: 'dark'
  126. },
  127. square: {
  128. type: [Boolean, String],
  129. default: false
  130. }
  131. },
  132. data () {
  133. return {
  134. linkDeviceMap: null,
  135. scale: 1,
  136. loading: false,
  137. loaded: false
  138. }
  139. },
  140. computed: {
  141. online () {
  142. return this.device.onlineStatus === 1
  143. },
  144. targetId () {
  145. return this.device.id
  146. },
  147. className () {
  148. return [this.theme, this.square ? 'square' : ''].join(' ')
  149. },
  150. linkState () {
  151. const map = {
  152. msr: 1,
  153. device: this.online ? 1 : 0,
  154. led: this.online ? 1 : 0,
  155. [ThirdPartyDevice.GATEWAY]: -1,
  156. [ThirdPartyDevice.LED_CAMERA]: -1,
  157. [ThirdPartyDevice.TRAFFIC_CAMERA]: -1,
  158. [ThirdPartyDevice.SENDING_CARD]: -1,
  159. [ThirdPartyDevice.RECEIVING_CARD]: -1
  160. }
  161. if (this.linkDeviceMap) {
  162. for (const item of this.linkDeviceMap) {
  163. map[item.deviceType] = item.status
  164. }
  165. }
  166. return map
  167. },
  168. items () {
  169. const map = this.linkState
  170. return LinkItems.map(({ key, alias, label, iconKey, canClick }) => {
  171. const status = map[key]
  172. return {
  173. key, label, status, canClick,
  174. icon: status === -1
  175. ? 'link-unbound'
  176. : `link-${iconKey || key}-${status === 1 ? 'online' : 'offline'}`,
  177. className: [alias || key, canClick && ~status ? 'u-pointer' : ''].join(' ')
  178. }
  179. })
  180. },
  181. lines () {
  182. const state = this.linkState
  183. return Object.keys(LineFromeTo).map(key => {
  184. const from = LineFromeTo[key][0]
  185. const to = LineFromeTo[key].slice(1)
  186. return {
  187. key: `line${key}`,
  188. className: [`l${key}`, state[from] === 1 && to.some(key => state[key] === 1) ? 'linked' : ''].join(' ')
  189. }
  190. })
  191. },
  192. styles () {
  193. return {
  194. transform: `scale(${this.scale})`
  195. }
  196. }
  197. },
  198. created () {
  199. this.getBoundThirdPartyDevices()
  200. this.$timer = setInterval(this.getBoundThirdPartyDevices, 10000)
  201. },
  202. mounted () {
  203. this.checkScale()
  204. window.addEventListener('resize', this.checkScale)
  205. },
  206. beforeDestroy () {
  207. window.removeEventListener('resize', this.checkScale)
  208. clearInterval(this.$timer)
  209. },
  210. methods: {
  211. checkScale () {
  212. const elm = this.$refs.wrapper
  213. const width = elm.clientWidth
  214. const height = elm.clientHeight
  215. this.scale = this.square
  216. ? Math.min(width / 804, height / 640).toFixed(2)
  217. : Math.min(width / 966, height / 420).toFixed(2)
  218. },
  219. getBoundThirdPartyDevices () {
  220. if (this.loading) {
  221. return
  222. }
  223. this.loading = true
  224. getBoundThirdPartyDevices(this.targetId, true).then(({ data }) => {
  225. this.linkDeviceMap = data
  226. this.loaded = true
  227. }).finally(() => {
  228. this.loading = false
  229. })
  230. },
  231. onClick (item) {
  232. if (!item.canClick) {
  233. return
  234. }
  235. this.$emit('click', item)
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. @mixin getPosition($left, $top, $width, $height) {
  242. top: $top;
  243. left: $left;
  244. width: $width;
  245. height: $height;
  246. }
  247. .c-link-state {
  248. width: 100%;
  249. height: 100%;
  250. overflow: hidden;
  251. &__main {
  252. position: relative;
  253. width: 966px;
  254. height: 420px;
  255. transform-origin: left center;
  256. }
  257. &.dark {
  258. color: $black;
  259. }
  260. &.light {
  261. color: #fff;
  262. }
  263. &.square {
  264. .c-link-state__main {
  265. width: 804px;
  266. height: 640px;
  267. }
  268. .o-link-item {
  269. &.msr {
  270. top: 0;
  271. left: 0;
  272. }
  273. &.device {
  274. top: 75px;
  275. left: 286px;
  276. }
  277. &.sending_card {
  278. top: 75px;
  279. left: 472px;
  280. }
  281. &.receiving_card {
  282. top: 75px;
  283. left: 660px;
  284. }
  285. &.gateway {
  286. top: 432px;
  287. left: 52px;
  288. width: 138px;
  289. height: 138px;
  290. }
  291. &.traffic_camera {
  292. top: 280px;
  293. left: 460px;
  294. }
  295. &.led_camera {
  296. top: 400px;
  297. left: 290px;
  298. }
  299. &.led {
  300. top: 400px;
  301. left: 440px;
  302. }
  303. }
  304. .o-line {
  305. &.l1 {
  306. top: 166px;
  307. left: 232px;
  308. width: 60px;
  309. transform: none;
  310. }
  311. &.l2 {
  312. top: 166px;
  313. left: 418px;
  314. width: 60px;
  315. }
  316. &.l3 {
  317. top: 166px;
  318. left: 604px;
  319. width: 60px;
  320. }
  321. &.l4 {
  322. top: 202px;
  323. left: 728px;
  324. width: 198px;
  325. }
  326. &.l5 {
  327. top: 334px;
  328. left: 122px;
  329. width: 108px;
  330. transform: rotate(90deg);
  331. }
  332. &.l6 {
  333. top: 334px;
  334. left: 122px;
  335. width: 120px;
  336. }
  337. &.l7 {
  338. top: 334px;
  339. left: 240px;
  340. width: 120px;
  341. }
  342. &.l8 {
  343. top: 454px;
  344. left: 240px;
  345. }
  346. &.l9 {
  347. top: 334px;
  348. left: 240px;
  349. width: 234px;
  350. }
  351. &.l10 {
  352. top: 522px;
  353. left: 184px;
  354. width: 256px;
  355. }
  356. &.l11 {
  357. top: 230px;
  358. left: 122px;
  359. width: 104px;
  360. height: 2px;
  361. transform: rotate(90deg);
  362. transform-origin: left;
  363. }
  364. }
  365. }
  366. }
  367. @keyframes move {
  368. from {
  369. background-position: 0 0;
  370. }
  371. to {
  372. background-position: 3em 0;
  373. }
  374. }
  375. .o-link-item {
  376. position: absolute;
  377. z-index: 1;
  378. &__name {
  379. position: absolute;
  380. top: 100%;
  381. left: 50%;
  382. font-size: 14px;
  383. line-height: 1;
  384. white-space: nowrap;
  385. transform: translateX(-50%);
  386. }
  387. &__img {
  388. width: 100%;
  389. height: 100%;
  390. }
  391. &.msr {
  392. @include getPosition(0, 42px, 242px, 236px);
  393. }
  394. &.device {
  395. @include getPosition(270px, 0, 138px, 138px);
  396. }
  397. &.sending_card {
  398. @include getPosition(484px, 0, 138px, 138px);
  399. }
  400. &.receiving_card {
  401. @include getPosition(720px, 0, 138px, 138px);
  402. .o-link-item__name {
  403. transform: translateX(8px);
  404. }
  405. }
  406. &.gateway {
  407. @include getPosition(270px, 250px, 138px, 138px);
  408. }
  409. &.traffic_camera {
  410. @include getPosition(480px, 156px, 80px, 80px);
  411. }
  412. &.led_camera {
  413. @include getPosition(480px, 252px, 80px, 80px);
  414. }
  415. &.led {
  416. @include getPosition(604px, 208px, 352px, 198px);
  417. .o-link-item__name {
  418. top: -8px;
  419. left: auto;
  420. right: 0;
  421. bottom: auto;
  422. transform: translateY(-100%);
  423. }
  424. }
  425. }
  426. .o-line {
  427. position: absolute;
  428. background-color: $gray--light;
  429. &.linked {
  430. background-size: 3em 1em;
  431. background-image: linear-gradient(
  432. -90deg,
  433. transparent 0em,
  434. transparent 1em,
  435. #026af2 1em,
  436. #026af2 2em,
  437. transparent 3em
  438. );
  439. animation: move 0.6s linear infinite;
  440. }
  441. &.l1 {
  442. transform: skewY(-30deg);
  443. transform-origin: left;
  444. @include getPosition(180px, 178px, 122px, 2px);
  445. }
  446. &.l2 {
  447. @include getPosition(402px, 92px, 86px, 2px);
  448. }
  449. &.l3 {
  450. @include getPosition(618px, 92px, 106px, 2px);
  451. }
  452. &.l4 {
  453. transform: rotate(90deg);
  454. transform-origin: left;
  455. @include getPosition(788px, 129px, 80px, 2px);
  456. }
  457. &.l5 {
  458. transform: skewY(30deg);
  459. transform-origin: left;
  460. @include getPosition(170px, 244px, 122px, 2px);
  461. }
  462. &.l6 {
  463. @include getPosition(234px, 209px, 196px, 2px);
  464. }
  465. &.l7 {
  466. transform: rotate(90deg);
  467. transform-origin: left;
  468. @include getPosition(428px, 209px, 95px, 2px);
  469. }
  470. &.l8 {
  471. @include getPosition(428px, 304px, 66px, 2px);
  472. }
  473. &.l9 {
  474. @include getPosition(428px, 209px, 66px, 2px);
  475. }
  476. &.l10 {
  477. @include getPosition(376px, 356px, 228px, 2px);
  478. }
  479. }
  480. </style>