Ver código fonte

修复indexDB加载乱码问题,修复第一次进入空白问题

eosgetdice12 5 anos atrás
pai
commit
563d572303

+ 17 - 15
_src/api/modules/group.js

@@ -9,27 +9,29 @@ export default {
    * @param {Number} params.group_id  会话id
    * @param {Number} params.client_hash 客户端上的最新消息的hash 【可为null】
    */
-  getNewMsg (params) {
-    return axios.request({
+  async getNewMsg (params) {
+    let res = await axios.request({
       url: 'group/newMsg',
       method: 'get',
       needLogin: false,
       params: params
-    }).then(res => {
-      const objMessage = new Message()
-      objMessage.saveMsg(params['group_id'], res.data.data)
-      // 解密数据
-      res.data.data.list.forEach(item => {
-        if (item.msg_type == 4) {
-          // 针对红包类型
-          item.msg = JSON.parse(decryptoMsg(item.msg))
-        } else {
-          item.msg = decryptoMsg(item.msg)
-        }
-      })
+    })
 
-      return Promise.resolve(res)
+    const objMessage = new Message()
+    // 如果不同步执行,第一次初始化数据库会出现很奇怪的问题...
+    await objMessage.saveMsg(params['group_id'], res.data.data)
+
+    // 解密数据
+    res.data.data.list.forEach(item => {
+      if (item.msg_type == 4) {
+        // 针对红包类型
+        item.msg = JSON.parse(decryptoMsg(item.msg))
+      } else {
+        item.msg = decryptoMsg(item.msg)
+      }
     })
+
+    return res
   },
   /**
    * 群聊 获取历史消息【不需要登录】

+ 3 - 6
_src/store/db/Message.js

@@ -58,16 +58,13 @@ class Message extends TableHelper {
     objTable.put(obj)
   }
 
-  saveMsg (sessionId, data) {
+  async saveMsg (sessionId, data) {
     const objMessage = new Message()
     // 数据保存到indexDB
+    let objTable = await objMessage.getObjTable()
     for (let key in data.list) {
       let value = Object.assign({ 'session_id': sessionId }, data.list[key])
-      // console.log('for:' + key, value)
-      objMessage.getObjTable().then(objTable => {
-        objTable.put(value)
-        // console.log('put:' + key, value)
-      })
+      await objTable.put(value)
     }
 
     let objUser = new User()

+ 1 - 1
_src/util/util.js

@@ -246,7 +246,7 @@ export function addLinkItem (item) {
 
     item.content = twemoji.parse(item.content, {
       callback: function (icon, options) {
-        return 'https://w2.meechat.me/emoji/' + icon + '.svg?1'
+        return 'https://w2.meechat.me/emoji/' + icon + '.svg'
       }
     })
   }

+ 2 - 0
protected/controllers/GroupController.php

@@ -203,6 +203,8 @@ class GroupController extends BaseController {
         $data['list'] = array_filter($data['list'], function ($v) {
             return $v['state'] == 1;
         });
+        $data['list'] = array_values($data['list']);
+
         return $data;
     }