chris 3 жил өмнө
parent
commit
9cb5b6887d

+ 0 - 9
src/utils/common.js

@@ -18,12 +18,3 @@ export function parseJsonStr (str) {
   str = str.replace(/:s*([0-9]{15,})s*(,?)/g, ': "$1" $2')
   return JSON.parse(str)
 }
-
-/**
- * 发送通知已读反馈
- */
-export function readNotice (that, noticeId) {
-  let arr = []
-  arr.push(noticeId)
-  that.$store.dispatch('websocket/WEBSOCKET_SEND', JSON.stringify({'noticeIds': arr}))
-}

+ 32 - 0
src/utils/msg.js

@@ -0,0 +1,32 @@
+/**
+ * 通知页面跳转
+ */
+export function routeMsg (that, row) {
+  if (row.type === 1) {
+    that.$router.push({name: 'msgAnnouncement',
+      params: {notice: {
+        noticeId: row.noticeId,
+        businessId: row.businessId
+      }}})
+  } else if (row.type === 2) {
+    that.$router.push({name: 'msgApprove',
+      params: {notice: {
+        noticeId: row.noticeId,
+        businessId: row.businessId
+      }}})
+  } else {
+    that.$message.warning('消息类型不支持')
+  }
+}
+
+/**
+ * 发送通知已读反馈
+ */
+export function readNotice (that, noticeId) {
+  let index = that.$store.state.common.msgCollection.findIndex(item => item.noticeId === noticeId)
+  if (index === -1) return
+  that.$store.state.common.msgCollection.splice(index, 1)
+  let arr = []
+  arr.push(noticeId)
+  that.$store.dispatch('websocket/WEBSOCKET_SEND', JSON.stringify({'noticeIds': arr}))
+}

+ 7 - 18
src/views/common/msg.vue

@@ -5,13 +5,15 @@
 
 <script>
   import {parseJsonStr} from '@/utils/common'
+  import {routeMsg} from '@/utils/msg'
   export default {
     name: 'msg',
     data () {
       return {
         visible: false,
         id: 0,
-        dataForm: {}
+        dataForm: {},
+        notify: {}
       }
     },
     mounted () {
@@ -59,7 +61,7 @@
       // 通知
       notice (item) {
         const h = this.$createElement
-        this.$notify({
+        this.notify = this.$notify({
           title: item.title,
           message: h('div', {}, [
             h('p', {}, '消息类别:' + this.getMsgType(item.type)),
@@ -79,23 +81,10 @@
       },
       // 跳转到消息页面
       detail (row) {
-        if (!row) return
-        if (row.type === 1) {
-          this.$router.push({name: 'msgAnnouncement',
-            params: {notice: {
-              noticeId: row.noticeId,
-              businessId: row.businessId
-            }}})
-        } else if (row.type === 2) {
-          this.$router.push({name: 'msgApprove',
-            params: {notice: {
-              noticeId: row.noticeId,
-              businessId: row.businessId
-            }}})
-        } else {
-          this.$message.warning('消息类型不支持')
+        routeMsg(this, row)
+        if (this.notify) {
+          this.notify.close()
         }
-        // console.log('item = ' + JSON.stringify(row))
       },
       // 获取消息类型
       getMsgType (type) {

+ 7 - 1
src/views/modules/msg-center/announcement-detail.vue

@@ -3,6 +3,7 @@
     title="查看"
     width="60%"
     :close-on-click-modal="false"
+    @close="closeDialog"
     :visible.sync="visible">
     <div style="margin-left: 20px;margin-right: 20px">
       <e-desc title="基本信息" column="2">
@@ -18,7 +19,7 @@
       </e-desc>
     </div>
     <span slot="footer" class="dialog-footer">
-      <el-button @click="visible = false">返回</el-button>
+      <el-button @click="closeDialog">返回</el-button>
     </span>
   </el-dialog>
 </template>
@@ -57,6 +58,11 @@
             this.dataForm = data.data
           }
         })
+      },
+      // 关闭页面
+      closeDialog () {
+        this.visible = false
+        this.$emit('refreshDataList')
       }
     }
   }

+ 10 - 6
src/views/modules/msg-center/announcement.vue

@@ -59,7 +59,7 @@
         align="center"
         label="是否已读">
         <template slot-scope="scope">
-          <span v-if="scope.row.isRead === 0">未读</span>
+          <span v-if="Number(scope.row.isRead) === 0" style="color: red">未读</span>
           <span v-else>已读</span>
         </template>
       </el-table-column>
@@ -91,7 +91,7 @@
         width="150"
         label="操作">
         <template slot-scope="scope">
-          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.noticeId, false)">查看</el-button>
+          <el-button type="text" size="small" @click="detailHandle(scope.row)">查看</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -105,7 +105,7 @@
       layout="total, sizes, prev, pager, next, jumper">
     </el-pagination>
     <!-- 弹窗,详情 -->
-    <detail v-if="addOrUpdateVisible" ref="addOrUpdate"></detail>
+    <detail v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getAnnouncementList"></detail>
   </div>
 </template>
 
@@ -114,6 +114,7 @@
   import { getAnnouncementList } from '@/api/msg'
   import { getCusList } from '@/api/cus'
   import { downloadUrl } from '@/api/file'
+  import {readNotice} from '@/utils/msg'
   export default {
     name: 'announcement',
     components: {
@@ -131,6 +132,7 @@
     },
     watch: {
       listenNotice: function (notice) {
+        console.log('notice = ' + JSON.stringify(notice))
         if (!notice) return
         this.dataForm.noticeId = notice.noticeId
         this.dataForm.businessId = notice.businessId
@@ -160,6 +162,7 @@
       },
       // 获取数据列表
       getAnnouncementList () {
+        this.dataList = []
         this.dataListLoading = true
         let params = {
           'current': this.pageIndex,
@@ -211,12 +214,13 @@
           }
         })
       },
-      // 新增 / 修改
-      addOrUpdateHandle (id, disable) {
+      // 详情
+      detailHandle (row) {
         this.addOrUpdateVisible = true
         this.$nextTick(() => {
-          this.$refs.addOrUpdate.init(id)
+          this.$refs.addOrUpdate.init(row.noticeId)
         })
+        readNotice(this, row.noticeId)
       }
     }
   }

+ 1 - 0
src/views/modules/msg-center/approve.vue

@@ -210,6 +210,7 @@
       },
       // 获取数据列表
       getApprovalList () {
+        this.dataList = []
         this.dataListLoading = true
         let params = {
           'current': this.pageIndex,

+ 4 - 21
src/views/modules/msg-center/notice.vue

@@ -89,7 +89,7 @@
 </template>
 
 <script>
-  import {readNotice} from '@/utils/common'
+  import {readNotice, routeMsg} from '@/utils/msg'
   export default {
     name: 'notice',
     created () {
@@ -137,30 +137,13 @@
         this.dataListSelections = val
       },
       // 设为已读
-      checkHandle (id) {
-        // 获取记录
-        let index = this.$store.state.common.msgCollection.findIndex(item => item.noticeId === id)
-        this.$store.state.common.msgCollection.splice(index, 1)
-        readNotice(this, id)
+      checkHandle (noticeId) {
+        readNotice(this, noticeId)
         this.getNoticeList()
       },
       // 查看消息
       detailHandle (row) {
-        if (row.type === 1) {
-          this.$router.push({name: 'msgAnnouncement',
-            params: {notice: {
-              noticeId: row.noticeId,
-              businessId: row.businessId
-            }}})
-        } else if (row.type === 2) {
-          this.$router.push({name: 'msgApprove',
-            params: {notice: {
-              noticeId: row.noticeId,
-              businessId: row.businessId
-            }}})
-        } else {
-          this.$message.warning('消息类型不支持')
-        }
+        routeMsg(this, row)
       }
     }
   }