index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="home-container">
  3. <grid-layout
  4. :layout.sync="layout"
  5. :col-num="14"
  6. :row-height="30"
  7. :is-draggable="false"
  8. :is-resizable="true"
  9. :is-mirrored="false"
  10. :vertical-compact="true"
  11. :margin="[10, 10]"
  12. :use-css-transforms="true"
  13. >
  14. <!-- <grid-item v-for="item in layout" :key="item.i" :x="item.x" :y="item.y" :w="item.w" :h="item.h" :i="item.i" :style="'display: ' + (item.i === '1' ? 'block' : 'none' )"> -->
  15. <grid-item v-for="item in layout" :key="item.i" :x="item.x" :y="item.y" :w="item.w" :h="item.h" :i="item.i">
  16. <component :is="components[item.i]" :ref="components[item.i]" class="card-box" v-bind="componentProps(item.i)" />
  17. </grid-item>
  18. </grid-layout>
  19. <information ref="Information" />
  20. </div>
  21. </template>
  22. <script>
  23. import { mapGetters } from 'vuex'
  24. import VueGridLayout from 'vue-grid-layout'
  25. import Search from './components/Search'
  26. import Message from './components/Message'
  27. import Business from './components/Business'
  28. import System from './components/System'
  29. // import System from './components/System'
  30. import Specification from './components/Specification'
  31. import Link from './components/Link'
  32. import Information from './components/Information'
  33. import Test from './components/Test'
  34. let sseClient
  35. export default {
  36. name: 'Home',
  37. components: {
  38. GridLayout: VueGridLayout.GridLayout,
  39. GridItem: VueGridLayout.GridItem,
  40. Search,
  41. Message,
  42. Business,
  43. System,
  44. Specification,
  45. Link,
  46. Information,
  47. Test
  48. },
  49. data() {
  50. return {
  51. layout: [
  52. { 'x': 0, 'y': 0, 'w': 14, 'h': 2, 'i': '0' },
  53. { 'x': 0, 'y': 2, 'w': 6, 'h': 12, 'i': '1' },
  54. { 'x': 0, 'y': 14, 'w': 6, 'h': 8, 'i': '2' },
  55. { 'x': 6, 'y': 2, 'w': 8, 'h': 8, 'i': '3' },
  56. { 'x': 6, 'y': 10, 'w': 8, 'h': 5, 'i': '4' },
  57. { 'x': 6, 'y': 15, 'w': 8, 'h': 7, 'i': '5' },
  58. { 'x': 0, 'y': 21, 'w': 14, 'h': 4, 'i': '6' }
  59. ],
  60. components: ['Search', 'Message', 'Business', 'System', 'System', 'Specification', 'Link']
  61. }
  62. },
  63. computed: {
  64. ...mapGetters([
  65. 'name'
  66. ])
  67. },
  68. created() {
  69. },
  70. mounted() {
  71. // this.calcLayoutWidth()
  72. this.connect()
  73. },
  74. beforeDestroy() {
  75. if (sseClient) {
  76. sseClient.disconnect()
  77. }
  78. },
  79. methods: {
  80. componentProps(index) {
  81. if (index === '3') {
  82. return { pageSize: 10 }
  83. }
  84. if (index === '4') {
  85. return { pageSize: 5 }
  86. }
  87. return {}
  88. },
  89. calcLayoutWidth() {
  90. document.getElementsByClassName('home-container')[0].style.width = document.getElementsByClassName('home-container')[0].offsetWidth + 'px'
  91. },
  92. connect() {
  93. sseClient = this.$sse.create({
  94. url: process.env.VUE_APP_BASE_API + '/subscribe/test1',
  95. format: 'json',
  96. withCredentials: true,
  97. polyfill: true
  98. })
  99. sseClient.on('error', (e) => {
  100. console.error('lost connection or failed to parse!', e)
  101. // If this error is due to an unexpected disconnection, EventSource will
  102. // automatically attempt to reconnect indefinitely. You will _not_ need to
  103. // re-add your handlers.
  104. })
  105. sseClient.on('message', this.handleMessage)
  106. sseClient.connect()
  107. .then(sse => {
  108. console.log('We\'re connected!')
  109. })
  110. .catch((err) => {
  111. // When this error is caught, it means the initial connection to the
  112. // events server failed. No automatic attempts to reconnect will be made.
  113. console.error('Failed to connect to server', err)
  114. })
  115. },
  116. handleMessage(message) {
  117. console.log(message)
  118. this.$refs.Message[0].addNewMessage(message)
  119. this.$refs.Information.open()
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. $msgCardHeaderHeight: 43px;
  126. .home-container {
  127. .card-box {
  128. height: 100%;
  129. ::v-deep {
  130. .el-card {
  131. height: 100%;
  132. .el-card__header {
  133. padding: 10px 10px !important;
  134. height: $msgCardHeaderHeight;
  135. span{
  136. font-weight: bold;
  137. }
  138. }
  139. .el-card__body {
  140. height: calc(100% - #{$msgCardHeaderHeight});
  141. padding: 0 10px 10px 10px;
  142. &>* {
  143. height: 100%;
  144. }
  145. }
  146. .el-scrollbar__wrap{
  147. overflow-x: hidden;
  148. }
  149. .el-scrollbar__bar.is-horizontal {
  150. display: none;
  151. }
  152. .el-table__row .cell {
  153. padding-left: 0 !important;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. .vue-grid-item:not(.vue-grid-placeholder) {
  160. background: #e0dede;
  161. }
  162. .vue-grid-item .resizing {
  163. opacity: 0.9;
  164. }
  165. .vue-grid-item .static {
  166. background: rgb(128, 128, 237);
  167. }
  168. .vue-grid-item .text {
  169. font-size: 24px;
  170. text-align: center;
  171. position: absolute;
  172. top: 0;
  173. bottom: 0;
  174. left: 0;
  175. right: 0;
  176. margin: auto;
  177. height: 100%;
  178. width: 100%;
  179. }
  180. .vue-grid-item .no-drag {
  181. height: 100%;
  182. width: 100%;
  183. }
  184. .vue-grid-item .minMax {
  185. font-size: 12px;
  186. }
  187. .vue-grid-item .add {
  188. cursor: pointer;
  189. }
  190. .vue-draggable-handle {
  191. position: absolute;
  192. width: 20px;
  193. height: 20px;
  194. top: 0;
  195. left: 0;
  196. background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>") no-repeat;
  197. background-position: bottom right;
  198. padding: 0 8px 8px 0;
  199. background-repeat: no-repeat;
  200. background-origin: content-box;
  201. box-sizing: border-box;
  202. cursor: pointer;
  203. }
  204. </style>