App.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div id="app">
  3. <router-view/>
  4. </div>
  5. </template>
  6. <script>
  7. import cqcyCode from "@/utils/cqcyCode";
  8. import {getToken} from '@/utils/auth'
  9. import {showAlertWin} from "@/utils/cqcy";
  10. export default {
  11. name: 'App',
  12. provide() {
  13. return {
  14. getWebSocket: this,
  15. __self: this
  16. }
  17. },
  18. metaInfo() {
  19. return {
  20. title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
  21. titleTemplate: title => {
  22. return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
  23. }
  24. }
  25. },
  26. data() {
  27. return {
  28. webSocket: null,
  29. clientRole: null
  30. }
  31. },
  32. mounted() {
  33. this.clientRole = cqcyCode['clientRole']
  34. this.initWebSocket()
  35. },
  36. created() {
  37. $("body").on("mousedown", '.el-message-box__header', (e) => {
  38. const dialogHeaderEl = document.querySelector('.el-message-box__header')
  39. const dragDom = document.querySelector('.el-message-box')
  40. dialogHeaderEl.style.cursor = 'move'
  41. // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  42. const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
  43. // 鼠标按下,计算当前元素距离可视区的距离
  44. const disX = e.clientX - dialogHeaderEl.offsetLeft
  45. const disY = e.clientY - dialogHeaderEl.offsetTop
  46. // 获取到的值带px 正则匹配替换
  47. let styL, styT
  48. // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
  49. if (sty.left.includes('%')) {
  50. styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
  51. styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
  52. } else {
  53. let lefts = sty.left
  54. let tops = sty.top
  55. if (sty.left == 'auto') {
  56. lefts = '0px'
  57. }
  58. if (sty.top == 'auto') {
  59. tops = '0px'
  60. }
  61. styL = +lefts.replace(/\px/g, '')
  62. styT = +tops.replace(/\px/g, '')
  63. }
  64. const dragDomWidth = dragDom.offsetWidth
  65. const dragDomHeight = dragDom.offsetHeight
  66. const screenWidth = document.body.clientWidth
  67. const screenHeight = document.body.clientHeight
  68. const maxDragDomLeft = screenWidth - dragDomWidth
  69. const maxDragDomTop = screenHeight - dragDomHeight
  70. document.onmousemove = function (e) {
  71. // 通过事件委托,计算移动的距离
  72. const l = e.clientX - disX
  73. const t = e.clientY - disY
  74. // 移动当前元素
  75. let _left = l + styL
  76. _left = _left < 0 ? 0 : _left
  77. _left = _left > maxDragDomLeft ? maxDragDomLeft : _left
  78. let _top = t + styT
  79. _top = _top < 0 ? 0 : _top
  80. _top = _top > maxDragDomTop ? maxDragDomTop : _top
  81. dragDom.style.left = `${_left}px`
  82. dragDom.style.top = `${_top}px`
  83. dragDom.style.position = `absolute`
  84. // 将此时的位置传出去
  85. // binding.value({x:e.pageX,y:e.pageY})
  86. }
  87. document.onmouseup = function (e) {
  88. document.onmousemove = null
  89. document.onmouseup = null
  90. }
  91. })
  92. },
  93. destroyed() {
  94. },
  95. methods: {
  96. initWebSocket() {
  97. console.log('webSocket');
  98. let _this = this
  99. if (typeof (WebSocket) === 'undefined') {
  100. showAlertWin(_this, null, '您使用的环境暂不支持socket服务!')
  101. } else {
  102. let wsurl = ''
  103. let wsbase = cqcyCode['ws']
  104. let sysHost = localStorage.getItem('SYS_HOST_BASE')
  105. if (sysHost) {
  106. wsurl = wsbase.replace('{0}', sysHost)
  107. } else {
  108. wsurl = wsbase.replace('{0}', cqcyCode['host'] + ':' + cqcyCode['port'])
  109. }
  110. // 实例化socket
  111. _this.webSocket = new WebSocket(wsurl + getToken())
  112. // 监听socket连接
  113. _this.webSocket.onopen = _this.webSocketOpen
  114. // 监听socket错误信息
  115. _this.webSocket.onerror = _this.webSocketError
  116. // 监听socket消息
  117. _this.webSocket.onmessage = _this.webSocketMessage
  118. // 监听socket关闭
  119. _this.webSocket.onclose = _this.webSocketClose
  120. }
  121. },
  122. webSocketOpen(e) {
  123. console.log('open', e)
  124. let _this = this
  125. let count = 0
  126. const interval = setInterval(() => {
  127. count++
  128. // console.log('count', count)
  129. if (_this.webSocket && _this.webSocket.readyState === 1) {
  130. _this.webSocket.send(getToken())
  131. } else {
  132. clearInterval(interval)
  133. }
  134. }, 5 * 1000)
  135. },
  136. webSocketError(e) {
  137. console.log('error', e)
  138. },
  139. webSocketMessage(e) {
  140. console.log('message', e)
  141. },
  142. webSocketClose(e) {
  143. console.log('close', e)
  144. this.webSocket.close()
  145. this.webSocket = null
  146. }
  147. }
  148. }
  149. </script>
  150. <style rel="stylesheet/scss" lang="scss">
  151. ::-webkit-scrollbar {
  152. width: 8px;
  153. height: 6px;
  154. opacity: 0.4;
  155. }
  156. ::-webkit-scrollbar-track {
  157. background-color: white;
  158. border-radius: 8px;
  159. opacity: 0.4;
  160. }
  161. ::-webkit-scrollbar-track-piece {
  162. width: 4px;
  163. }
  164. ::-webkit-scrollbar-thumb {
  165. border-radius: 8px;
  166. background-color: gray;
  167. opacity: 0.4;
  168. }
  169. .contextmenu {
  170. margin: 0;
  171. background: #fff;
  172. z-index: 3000;
  173. position: absolute;
  174. list-style-type: none;
  175. padding: 5px 0;
  176. border-radius: 4px;
  177. font-size: 12px;
  178. font-weight: 400;
  179. color: #333;
  180. box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);
  181. }
  182. .contextmenu-black {
  183. background: black;
  184. color: white;
  185. }
  186. .contextmenu li {
  187. margin: 0;
  188. padding: 7px 16px;
  189. cursor: pointer;
  190. }
  191. .contextmenu-black li {
  192. border-bottom: 1px solid;
  193. margin: 0 5px;
  194. }
  195. .contextmenu-black li:last-child {
  196. border-bottom: 0;
  197. }
  198. .contextmenu li:hover {
  199. background: #eee;
  200. }
  201. .contextmenu-black li:hover {
  202. background: none;
  203. }
  204. .close_confirm .el-message-box__btns {
  205. display: flex;
  206. flex-direction: row-reverse;
  207. .el-button {
  208. margin: 0 0.5rem;
  209. }
  210. }
  211. </style>