Browse Source

feat: 更新消息提醒

double 2 years ago
parent
commit
6a2c8df7a2

BIN
src/assets/audio/order_ready.mp3


BIN
src/assets/audio/order_success.mp3


+ 38 - 24
src/components/common/layout/layout.vue

@@ -51,6 +51,12 @@
51 51
           </div>
52 52
       </div>
53 53
     </minePupop>
54
+    <audio ref="orderSuccessMp3" id="orderSuccessMp3" muted>
55
+      <source src="@/assets/audio/order_success.mp3" />
56
+    </audio>
57
+    <audio ref="orderReadyMp3" id="orderReadyMp3" muted>
58
+      <source src="@/assets/audio/order_ready.mp3" />
59
+    </audio>
54 60
   </div>
55 61
 </template>
56 62
 
@@ -79,31 +85,39 @@ export default {
79 85
   created () {
80 86
     this.getUserInfo()
81 87
 
82
-      console.log('开始连接...')
83
-      let token = this.$store.state.comVal.token || localStorage.getItem('token')
84
-      //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
85
-      this.wsInstance = new WebSocket(`wss://ws.ijolijoli.com?access_token=${token}`);
86
-      this.wsInstance.onopen = () => {
87
-        //当WebSocket创建成功时,触发onopen事件
88
-        console.log("连接成功");
89
-        this.timer = setInterval(() => {
90
-          this.wsInstance.send(JSON.stringify({type:'ping'}));
91
-        }, 30000);
92
-      }
93
-      this.wsInstance.onmessage = (e) => {
94
-        //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
95
-        console.log('收到消息',e.data)
96
-        let data = JSON.parse(e.data);
97
-        console.log(data)
98
-      }
99
-      this.wsInstance.onclose = (e) => {
100
-        //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
101
-        console.log("连接已关闭");
102
-      }
103
-      this.wsInstance.onerror = (e) => {
104
-        //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
105
-        console.log(e);
88
+    console.log('开始连接...')
89
+    let token = this.$store.state.comVal.token || localStorage.getItem('token')
90
+    //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
91
+    this.wsInstance = new WebSocket(`wss://ws.ijolijoli.com?access_token=${token}`);
92
+    this.wsInstance.onopen = () => {
93
+      //当WebSocket创建成功时,触发onopen事件
94
+      console.log("连接成功");
95
+      this.timer = setInterval(() => {
96
+        this.wsInstance.send(JSON.stringify({type:'ping'}));
97
+      }, 30000);
98
+    }
99
+    this.wsInstance.onmessage = (e) => {
100
+      //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
101
+      console.log('收到消息',e.data)
102
+      let data = JSON.parse(e.data);
103
+      if (data.data.type === 'order_success') {
104
+        console.log('预约成功信息播报')
105
+        this.$refs.orderSuccessMp3.play()
106
+      } else if (data.data.type === 'order_ready') {
107
+        // TODO: 播报动态语音还是固定的语音有待产品商榷
108
+        console.log('项目即将开始信息播报')
109
+        this.$refs.orderReadyMp3.play()
106 110
       }
111
+      console.log(data)
112
+    }
113
+    this.wsInstance.onclose = (e) => {
114
+      //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
115
+      console.log("连接已关闭");
116
+    }
117
+    this.wsInstance.onerror = (e) => {
118
+      //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
119
+      console.log(e);
120
+    }
107 121
   },
108 122
   components: {
109 123
     leftMenu,

+ 24 - 0
src/server/home.js

@@ -157,4 +157,28 @@ export default class Home {
157 157
     return $http.get(url.reservedRecords, params)
158 158
   }
159 159
 
160
+  // 清除未读消息  0清除所有 1清除预约成功 2清除取消
161
+  static clearMessage (type) {
162
+    return $http.get(url.clearMessage, type)
163
+  }
164
+
165
+  // 根据Id清除未读消息  消息记录id
166
+  static clearMessageById (id) {
167
+    return $http.get(url.clearMessageById, id)
168
+  }
169
+
170
+  // 获取消息列表 (成功/失败)  1预约成功 2取消预约
171
+  static getMessageByType ({ type, page, limit }) {
172
+    return $http.get(url.getMessageByType, { type, page, limit })
173
+  }
174
+
175
+  // 获取消息列表
176
+  static getMessageList ({ page, limit }) {
177
+    return $http.get(url.getMessageList, { page, limit })
178
+  }
179
+
180
+  // 获取是否有未读消息
181
+  static hasUnreadMessage () {
182
+    return $http.get(url.hasUnreadMessage)
183
+  }
160 184
 }

+ 17 - 2
src/server/urls.js

@@ -94,7 +94,22 @@ export default {
94 94
   // 创建标签
95 95
   schemeSave: '/v2/pad/scheme/save',
96 96
 
97
-    // 用户预约记录
98
-    reservedRecords: '/v2/pad/reserved/index'
97
+  // 用户预约记录
98
+  reservedRecords: '/v2/pad/reserved/index',
99
+
100
+  // 清除未读消息
101
+  clearMessage: '/v2/pad/message/batch_read',
102
+
103
+  // 根据Id清除未读消息
104
+  clearMessageById: '/v2/pad/message/read',
105
+
106
+  // 获取消息列表 (成功/失败)
107
+  getMessageByType: '/v2/pad/message/type_list',
108
+
109
+  // 获取消息列表
110
+  getMessageList: '/v2/pad/message/get_list',
111
+
112
+  // 获取是否有未读消息
113
+  hasUnreadMessage: '/v2/pad/message/get_message'
99 114
 
100 115
 }