index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. <h3>{{ data[index].title }}</h3>
  19. {{ data[index].businessData }}
  20. </div>
  21. <template #footer>
  22. <span class="dialog-footer">
  23. <el-button
  24. size="small"
  25. @click="index--"
  26. :disabled="data.length < 2 || index == 0"
  27. >上一条</el-button
  28. >
  29. <el-button
  30. size="small"
  31. @click="index++"
  32. :disabled="data.length == index + 1"
  33. >下一条</el-button
  34. >
  35. <el-button
  36. type="primary"
  37. size="small"
  38. :disabled="data.length == 0 || data[index].isRead"
  39. @click="confirm"
  40. >确认已读</el-button
  41. >
  42. <!-- <span class="more" @click="moreFn">查看更多 &gt;</span> -->
  43. </span>
  44. </template>
  45. </el-dialog>
  46. <div
  47. class="notice-table-warp"
  48. :class="modelValue ? 'notice-table-warp-open' : ''"
  49. @click.stop="closeNoticeTableModal"
  50. >
  51. <div class="notice-table" @click.stop v-loading="loading" >
  52. <div class="tabs">
  53. <ul>
  54. <li style="padding-left: 0; border: none" @click="pushInfoReq.whetherFlow = '';getPushInfo()" :class="pushInfoReq.whetherFlow === '' ? 'active' : ''">
  55. 全部({{pushInfoReq.total}})
  56. </li>
  57. <li @click="pushInfoReq.whetherFlow = 1;getPushInfo()" :class="pushInfoReq.whetherFlow === 1 ? 'active' : ''">流程</li>
  58. <li @click="pushInfoReq.whetherFlow = 0;getPushInfo()" :class="pushInfoReq.whetherFlow === 0 ? 'active' : ''">业务</li>
  59. </ul>
  60. <!-- <div class="more">查看更多&gt;</div> -->
  61. </div>
  62. <el-table :data="noticeData" style="width: 100%">
  63. <el-table-column prop="title" label="标题内容" width="250">
  64. <template #default="scope">
  65. <el-tooltip
  66. class="box-item"
  67. effect="dark"
  68. :content="scope.row.title"
  69. placement="top"
  70. >
  71. <div class="noticeData-title" @click="toDealWith(scope.row)">{{ scope.row.title }}</div>
  72. </el-tooltip>
  73. </template>
  74. </el-table-column>
  75. <el-table-column prop="businessType" label="类型" width="120">
  76. <template #default="scope">
  77. <span>{{ scope.row.businessType === 0 ? '流程' : '业务' }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="address" label="操作">
  81. <template #default="scope">
  82. <span style="cursor: pointer" @click="readFn(scope)">确认已读</span>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <div >
  87. <el-pagination style="text-align: center;" :page-size="5" layout="prev, pager, next" :total="pushInfoReq.total" @current-change="handlePageChange" />
  88. </div>
  89. <div class="notice-btn-box" style="margin-top: 20px">
  90. <!-- <el-button plain disabled>点击清空</el-button> -->
  91. <el-button type="primary" @click="allReadFn" v-if="noticeData.length != 0">全部已读</el-button>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </template>
  97. <script setup>
  98. import { ElMessageBox, ElNotification,ElMessage } from 'element-plus'
  99. import {
  100. getToken
  101. } from '@/utils/auth'
  102. const { proxy } = getCurrentInstance();
  103. defineProps({
  104. modelValue: {
  105. type: Object,
  106. default: false,
  107. },
  108. });
  109. const emit = defineEmits(["update:modelValue"],'changeNum');
  110. const closeNoticeTableModal = () => {
  111. emit("update:modelValue", false);
  112. };
  113. let noticeData = ref([])
  114. let index = ref(0)
  115. let data = ref([])
  116. let value = ref(false)
  117. const moreFn = () => {
  118. noticeTableModal.value = true
  119. }
  120. const toDealWith = (item) => {
  121. let urlConfig = {
  122. "0":'DealWith',
  123. "5":'Claim',
  124. "6":"Abnormal"
  125. }
  126. proxy.$router.push({
  127. name:urlConfig[item.businessType],
  128. })
  129. }
  130. const allReadFn = () => {
  131. ElMessageBox.confirm('此操作将会把所有未读消息标记为已读,是否继续?', '提示', {
  132. confirmButtonText: '确定',
  133. cancelButtonText: '取消',
  134. type: 'warning',
  135. }).then(() => {
  136. let arr = []
  137. noticeData.value.filter(item=>{
  138. arr.push(item.id)
  139. })
  140. commonRead(arr)
  141. }).catch(() => {
  142. ElMessage({
  143. type: 'info',
  144. message: '已取消操作'
  145. });
  146. });
  147. }
  148. const readFn = (item) => {
  149. commonRead([item.row.id])
  150. }
  151. const commonRead = (ids,type) => {
  152. proxy.post('/pushInfo/read',{idList:ids}).then(res=>{
  153. console.log(res)
  154. ElMessage({
  155. message: '已读成功',
  156. type: 'success',
  157. })
  158. if(type == 'confirm'){
  159. data.value[index].isRead = true
  160. }else{
  161. getPushInfo()
  162. }
  163. })
  164. }
  165. const confirm = () => {
  166. value.value = false
  167. commonRead([data.value[index.value].id],'confirm')
  168. }
  169. // proxy.post('sendMeg/page',{
  170. // pageNum:1,
  171. // pageSize:30,
  172. // }).then(res=>{
  173. // data.value = res.rows
  174. // })
  175. const socketInit = () => {
  176. window.ws = new WebSocket(
  177. 'ws://'+ import.meta.env.VITE_APP_IP +':20001'+ import.meta.env.VITE_APP_WS_API +'/webStock/' +
  178. getToken()
  179. // 'ws://192.168.1.97:8300/webStock/' + window.localStorage.getItem('token')
  180. )
  181. //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
  182. window.ws.onopen = function () {
  183. //当WebSocket创建成功时,触发onopen事件
  184. console.log('open')
  185. }
  186. window.ws.onmessage = function (e) {
  187. //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
  188. //在data.value前面插入
  189. const res = JSON.parse(e.data)
  190. console.log(res)
  191. if(res.type == 1) {
  192. index.value = 0
  193. data.value = res.list
  194. if(res.list.length > 0) value.value = true
  195. }
  196. if(res.type == 2) {
  197. emit('changeNum',res.count * 1)
  198. getPushInfo()
  199. }
  200. if(res.type == 3) {
  201. ElNotification({
  202. title: '提示',
  203. message: res.title,
  204. position: 'bottom-right',
  205. duration:0,
  206. })
  207. }
  208. }
  209. window.ws.onclose = function (e) {
  210. //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
  211. console.log('close')
  212. }
  213. window.ws.onerror = function (e) {
  214. //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
  215. console.log(error)
  216. }
  217. }
  218. let pushInfoReq = ref({
  219. pageNum: 1,
  220. pageSize: 5,
  221. pushRead: 0,
  222. type: '',
  223. total:0,
  224. whetherFlow:'',
  225. })
  226. const handlePageChange = (val) => {
  227. pushInfoReq.value.pageNum = val
  228. getPushInfo()
  229. }
  230. const loading = ref(false)
  231. const getPushInfo = () => {
  232. loading.value = true
  233. proxy.post('/pushInfo/page',pushInfoReq.value).then(res=>{
  234. noticeData.value = res.rows
  235. pushInfoReq.value.total = pushInfoReq.value.whetherFlow === '' ? res.total : pushInfoReq.value.total
  236. console.log(pushInfoReq)
  237. setTimeout(() => {
  238. loading.value = false
  239. }, 500);
  240. })
  241. }
  242. socketInit()
  243. const handleClose = () => {
  244. value.value = false
  245. }
  246. const openBottomBar = (type) => {
  247. if (type == 1) {
  248. ElNotification({
  249. message: '您有一封新的邮件,请注意查收。',
  250. type: 'warning',
  251. position: 'bottom-right',
  252. })
  253. } else if (type == 2) {
  254. value.value = true
  255. } else {
  256. noticeTableModal.value = true
  257. }
  258. }
  259. </script>
  260. <style lang="scss">
  261. .notice-table-warp {
  262. position: fixed;
  263. right: 0;
  264. top: 0;
  265. width: 100%;
  266. height: 100%;
  267. z-index: 1000;
  268. background: rgba(0, 0, 0, 0.1);
  269. transition: all 0.3s ease-in-out;
  270. opacity: 0;
  271. display: none;
  272. }
  273. .notice-table-warp-open {
  274. opacity: 1;
  275. display: block;
  276. }
  277. .notice-table {
  278. position: fixed;
  279. right: 2px;
  280. top: 52px;
  281. padding: 0 20px 20px;
  282. width: 500px;
  283. background: #fff;
  284. box-shadow: 0px 2px 20px 1px rgba(0, 0, 0, 0.1);
  285. z-index: 20;
  286. .notice-btn-box {
  287. text-align: right;
  288. }
  289. .tabs {
  290. display: flex;
  291. justify-content: space-between;
  292. height: 60px;
  293. line-height: 60px;
  294. font-size: 14px;
  295. font-weight: 400;
  296. ul {
  297. display: flex;
  298. margin: 23px 0;
  299. padding: 0;
  300. li {
  301. list-style: none;
  302. padding: 0 20px;
  303. cursor: pointer;
  304. height: 14px;
  305. line-height: 14px;
  306. border-left: 1px solid #dcdcdc;
  307. }
  308. .active {
  309. color: #0084ff;
  310. }
  311. }
  312. .more {
  313. color: #0084ff;
  314. cursor: pointer;
  315. }
  316. }
  317. }
  318. </style>
  319. <style>
  320. .noticeData-title{
  321. width: 100%;
  322. overflow: hidden;
  323. text-overflow: ellipsis;
  324. white-space: nowrap;
  325. cursor: pointer;
  326. }
  327. .commons-notice .el-table__row {
  328. height: 50px;
  329. }
  330. .commons-notice .el-dialog__footer {
  331. text-align: left !important;
  332. margin-top: 24px;
  333. }
  334. .commons-notice .more {
  335. color: #0084ff;
  336. float: right;
  337. cursor: pointer;
  338. }
  339. .commons-notice .el-dialog__header {
  340. background: #eeeeee;
  341. }
  342. .commons-notice .el-dialog__title {
  343. position: relative;
  344. padding-left: 30px;
  345. color: #333333;
  346. font-weight: bold;
  347. }
  348. .commons-notice .el-dialog__title::before {
  349. content: ' ';
  350. position: absolute;
  351. left: 0;
  352. top: 0;
  353. width: 20px;
  354. height: 20px;
  355. 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==);
  356. }
  357. </style>