index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="commons-notice">
  3. <el-dialog
  4. title="系统公告"
  5. v-model="value"
  6. width="460px"
  7. :align-center="true"
  8. :before-close="handleClose"
  9. >
  10. <div class="title">
  11. <!-- {{ data.length == 0 ? '暂无数据' : data[indexCopy].title}} -->
  12. </div>
  13. <div
  14. class="text-content"
  15. v-if="data.length > 0"
  16. style="margin-top: 10px"
  17. >
  18. {{ data[index].content }}
  19. </div>
  20. <template #footer>
  21. <span class="dialog-footer">
  22. <!-- <el-button
  23. size="small"
  24. @click="index--"
  25. :disabled="data.length < 2 || index == 0"
  26. >上一条</el-button
  27. >
  28. <el-button
  29. size="small"
  30. @click="index++"
  31. :disabled="data.length == index + 1"
  32. >下一条</el-button
  33. > -->
  34. <!-- <el-button
  35. type="primary"
  36. size="small"
  37. :disabled="data.length == 0"
  38. @click="confirm"
  39. >确认已读</el-button
  40. > -->
  41. <!-- <span class="more" @click="moreFn">查看更多 &gt;</span> -->
  42. </span>
  43. </template>
  44. </el-dialog>
  45. <div
  46. class="notice-table-warp"
  47. :class="modelValue ? 'notice-table-warp-open' : ''"
  48. @click.stop="closeNoticeTableModal"
  49. >
  50. <div class="notice-table" @click.stop>
  51. <div class="tabs">
  52. <ul>
  53. <li style="padding-left: 0; border: none" @click="tableTagType = 1" :class="tableTagType == 1 ? 'active' : ''">
  54. 全部(0)
  55. </li>
  56. <li @click="tableTagType = 2" :class="tableTagType == 2 ? 'active' : ''">待办(0)</li>
  57. <li @click="tableTagType = 3" :class="tableTagType == 3 ? 'active' : ''">通知(0)</li>
  58. </ul>
  59. <div class="more">查看更多&gt;</div>
  60. </div>
  61. <el-table :data="noticeData" style="width: 100%">
  62. <el-table-column prop="date" label="标题内容" width="250">
  63. </el-table-column>
  64. <el-table-column prop="name" label="类型" width="120">
  65. </el-table-column>
  66. <el-table-column prop="address" label="操作">
  67. <template #default="scope">
  68. <span style="cursor: pointer">未读</span>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <div class="notice-btn-box" style="margin-top: 20px">
  73. <el-button plain disabled>点击清空</el-button>
  74. <el-button type="primary" disabled>全部已读</el-button>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script setup>
  81. import { ElMessageBox, ElNotification } from 'element-plus'
  82. import {
  83. getToken
  84. } from '@/utils/auth'
  85. const { proxy } = getCurrentInstance();
  86. defineProps({
  87. modelValue: {
  88. type: Object,
  89. default: false,
  90. },
  91. });
  92. const emit = defineEmits(["update:modelValue"]);
  93. const closeNoticeTableModal = () => {
  94. emit("update:modelValue", false);
  95. };
  96. const tableTagType = ref(1)
  97. let noticeData = ref([
  98. // {
  99. // date: '2016-05-02',
  100. // name: '王小虎',
  101. // address: '上海市普陀区金沙江路 1518 弄',
  102. // },
  103. // {
  104. // date: '2016-05-04',
  105. // name: '王小虎',
  106. // address: '上海市普陀区金沙江路 1517 弄',
  107. // },
  108. // {
  109. // date: '2016-05-01',
  110. // name: '王小虎',
  111. // address: '上海市普陀区金沙江路 1519 弄',
  112. // },
  113. // {
  114. // date: '2016-05-03',
  115. // name: '王小虎',
  116. // address: '上海市普陀区金沙江路 1516 弄',
  117. // },
  118. ])
  119. let index = ref(0)
  120. let data = ref([])
  121. let value = ref(false)
  122. const moreFn = () => {
  123. noticeTableModal.value = true
  124. }
  125. const confirm = () => {
  126. value.value = false
  127. }
  128. // proxy.post('sendMeg/page',{
  129. // pageNum:1,
  130. // pageSize:30,
  131. // }).then(res=>{
  132. // data.value = res.rows
  133. // })
  134. const socketInit = () => {
  135. window.ws = new WebSocket(
  136. 'ws://'+ import.meta.env.VITE_APP_IP +':20001'+ import.meta.env.VITE_APP_WS_API +'/webStock/' +
  137. getToken()
  138. // 'ws://192.168.1.97:8300/webStock/' + window.localStorage.getItem('token')
  139. )
  140. //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
  141. window.ws.onopen = function () {
  142. //当WebSocket创建成功时,触发onopen事件
  143. console.log('open')
  144. }
  145. window.ws.onmessage = function (e) {
  146. //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
  147. //在data.value前面插入
  148. console.log(JSON.parse(e.data).data)
  149. data.value.unshift({title:"最新公告",content:JSON.parse(e.data).data})
  150. index.value = 0
  151. value.value = true
  152. }
  153. window.ws.onclose = function (e) {
  154. //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
  155. console.log('close')
  156. }
  157. window.ws.onerror = function (e) {
  158. //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
  159. console.log(error)
  160. }
  161. }
  162. socketInit()
  163. const handleClose = () => {
  164. value.value = false
  165. }
  166. const openBottomBar = (type) => {
  167. if (type == 1) {
  168. ElNotification({
  169. message: '您有一封新的邮件,请注意查收。',
  170. type: 'warning',
  171. position: 'bottom-right',
  172. })
  173. } else if (type == 2) {
  174. value.value = true
  175. } else {
  176. noticeTableModal.value = true
  177. }
  178. }
  179. </script>
  180. <style lang="scss">
  181. .notice-table-warp {
  182. position: fixed;
  183. right: 0;
  184. top: 0;
  185. width: 100%;
  186. height: 100%;
  187. z-index: 1000;
  188. background: rgba(0, 0, 0, 0.1);
  189. transition: all 0.3s ease-in-out;
  190. opacity: 0;
  191. display: none;
  192. }
  193. .notice-table-warp-open {
  194. opacity: 1;
  195. display: block;
  196. }
  197. .notice-table {
  198. position: fixed;
  199. right: 2px;
  200. top: 52px;
  201. padding: 0 20px 20px;
  202. width: 500px;
  203. background: #fff;
  204. box-shadow: 0px 2px 20px 1px rgba(0, 0, 0, 0.1);
  205. z-index: 20;
  206. .notice-btn-box {
  207. text-align: right;
  208. }
  209. .tabs {
  210. display: flex;
  211. justify-content: space-between;
  212. height: 60px;
  213. line-height: 60px;
  214. font-size: 14px;
  215. font-weight: 400;
  216. ul {
  217. display: flex;
  218. margin: 23px 0;
  219. padding: 0;
  220. li {
  221. list-style: none;
  222. padding: 0 20px;
  223. cursor: pointer;
  224. height: 14px;
  225. line-height: 14px;
  226. border-left: 1px solid #dcdcdc;
  227. }
  228. .active {
  229. color: #0084ff;
  230. }
  231. }
  232. .more {
  233. color: #0084ff;
  234. cursor: pointer;
  235. }
  236. }
  237. }
  238. </style>
  239. <style>
  240. .commons-notice .el-table__row {
  241. height: 50px;
  242. }
  243. .commons-notice .el-dialog__footer {
  244. text-align: left !important;
  245. margin-top: 24px;
  246. }
  247. .commons-notice .more {
  248. color: #0084ff;
  249. float: right;
  250. cursor: pointer;
  251. }
  252. .commons-notice .el-dialog__header {
  253. background: #eeeeee;
  254. }
  255. .commons-notice .el-dialog__title {
  256. position: relative;
  257. padding-left: 30px;
  258. color: #333333;
  259. font-weight: bold;
  260. }
  261. .commons-notice .el-dialog__title::before {
  262. content: ' ';
  263. position: absolute;
  264. left: 0;
  265. top: 0;
  266. width: 20px;
  267. height: 20px;
  268. background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABHNCSVQICAgIfAhkiAAAAftJREFUOE+tlT9MU1EUxr9zWwgBI/D6Boh/EnbCRiImMhBCGqNhcnDQrbgRAyxGBgYICzXYDbrB4OBENIaY4GAMrmqc3DQxMrxWNGkH0Hv83m0ptvS1EHqTm/fuO+f+zjn3nHueoGYoIFju7kGXGeTrJOd1qlwqq30HdJdzCwX7GY9+7QsX/yO4Ph66gHb0+EkiUzAyRklnrcHyugirb4jKYj/YlgUcHOlVgJrxLkLMHJVSEOmLAFV/Vt2j8SzUrsh0/ncodEDnmec9BswsYV1Vu1RD6+842zmvUR6vkRcAm0Y+vxR6Ku7MVv3bMFir65nVT/gZDNNgBw1+oM7ACe9DTy0e4GHwQnS5uxedbRs8s1t1w1S7I9O5cRfJU/8j9Ybq6ll9ieLhfdFM7w1IfDsyAacFAkXonySB3gokNhuZhNMDGcLfNIGJXWZ3pDVA+z4EfiXwaouA384GzDApEpEUlzXrgI1Dhn7B4cEITOwCYob1aK40iCYMuVlS1BLAY0GMz8ssWxMNdElpVjaaJ+RZCaJ3GbIXASyXTdPC1udAcK8E8TcJvNO4sJtePfsa/bmbDvIj8QrGTDS8ei6QsDkk/Hl2mpm6zUH0bSliGaU8bBLHQ7XA832CXLDomsORxLUvgDfGTJ2pfcGuc1+6qn1VoK1ssBXoOX8B/wDYqv5bje949AAAAABJRU5ErkJggg==);
  269. }
  270. </style>