|
@@ -7,13 +7,40 @@ import {
|
|
|
import ImApi from './apis/im'
|
|
|
import UserApi from './apis/user'
|
|
|
import AppIMDelegate from "./delegate/app-im-delegate";
|
|
|
-import { fotmatDate } from './utils/date'
|
|
|
+import {
|
|
|
+ fotmatDate
|
|
|
+} from './utils/date'
|
|
|
|
|
|
var QQMapWX = require('/utils/qqmap-wx-jssdk.min.js')
|
|
|
var timer = null
|
|
|
App({
|
|
|
onLaunch: function (options) {
|
|
|
//检查是否存在新版本
|
|
|
+ const updateManager = wx.getUpdateManager()
|
|
|
+ updateManager.onCheckForUpdate(function (res) {
|
|
|
+ // 请求完新版本信息的回调
|
|
|
+ if (res.hasUpdate) {
|
|
|
+ updateManager.onUpdateReady(function () {
|
|
|
+ wx.showModal({
|
|
|
+ title: '更新提示',
|
|
|
+ content: '新版本已经准备好,是否重启应用?',
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
|
+ updateManager.applyUpdate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ updateManager.onUpdateFailed(function () {
|
|
|
+ // 新的版本下载失败
|
|
|
+ wx.showModal({
|
|
|
+ title: '已经有新版本了哟~',
|
|
|
+ content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
this.appIMDelegate = new AppIMDelegate(this);
|
|
|
this.appIMDelegate.onLaunch(options);
|
|
|
this.globalData.qqmapsdk = new QQMapWX({
|
|
@@ -32,7 +59,9 @@ App({
|
|
|
setTimeout(() => {
|
|
|
this.appIMDelegate.onShow()
|
|
|
wx.getUserInfo({
|
|
|
- complete: (res) => {console.log(res, 'userinfo')},
|
|
|
+ complete: (res) => {
|
|
|
+ console.log(res, 'userinfo')
|
|
|
+ },
|
|
|
})
|
|
|
UserApi.getUserInfoById(this.globalData.userinfo.viewerId).then(res => {
|
|
|
this.globalData.userinfo = res.data
|
|
@@ -92,37 +121,41 @@ App({
|
|
|
getIMHandler() {
|
|
|
return this.appIMDelegate.getIMHandlerDelegate();
|
|
|
},
|
|
|
- async getNewMessage (msg) {
|
|
|
- const { conversations } = this.globalData
|
|
|
+ async getNewMessage(msg) {
|
|
|
+ const {
|
|
|
+ conversations
|
|
|
+ } = this.globalData
|
|
|
let item = conversations.find(item => item.id === msg.fromId)
|
|
|
if (item) {
|
|
|
- item.latestMsgContent = msg.content
|
|
|
- item.latestMsgTime = msg.sendTime
|
|
|
- item.unReadNum ? item.unReadNum++ : item.unReadNum = 1
|
|
|
- this.globalData.conversations = this.dealConversations(conversations)
|
|
|
+ item.latestMsgContent = msg.content
|
|
|
+ item.latestMsgTime = msg.sendTime
|
|
|
+ item.unReadNum ? item.unReadNum++ : item.unReadNum = 1
|
|
|
+ this.globalData.conversations = this.dealConversations(conversations)
|
|
|
} else {
|
|
|
- await this.getContact()
|
|
|
+ await this.getContact()
|
|
|
}
|
|
|
-},
|
|
|
-getContact(isNewMsg) {
|
|
|
- return ImApi.getContacts().then(res => {
|
|
|
- const friends = res.data.friends
|
|
|
- const {
|
|
|
- conversations
|
|
|
- } = this.globalData
|
|
|
- this.globalData.unViewMsg = 0
|
|
|
- this.globalData.conversations = this.dealConversations(friends.map(item => {
|
|
|
- const con = conversations.find(con => con.id === item.id)
|
|
|
- if (con) {
|
|
|
- item = Object.assign(con, item)
|
|
|
- } else if (isNewMsg){
|
|
|
- item.unReadNum = 1
|
|
|
- }
|
|
|
- this.globalData.unViewMsg += item.unReadNum
|
|
|
- return item
|
|
|
- }))
|
|
|
- })
|
|
|
-},
|
|
|
+ },
|
|
|
+ getContact(isNewMsg) {
|
|
|
+ return ImApi.getContacts().then(res => {
|
|
|
+ const friends = res.data.friends
|
|
|
+ const {
|
|
|
+ conversations
|
|
|
+ } = this.globalData
|
|
|
+ this.globalData.unViewMsg = 0
|
|
|
+ this.globalData.conversations = this.dealConversations(friends.map(item => {
|
|
|
+ if (conversations) {
|
|
|
+ const con = conversations.find(con => con.id === item.id)
|
|
|
+ if (con) {
|
|
|
+ item = Object.assign(con, item)
|
|
|
+ } else if (isNewMsg) {
|
|
|
+ item.unReadNum = 1
|
|
|
+ }
|
|
|
+ this.globalData.unViewMsg += item.unReadNum
|
|
|
+ }
|
|
|
+ return item
|
|
|
+ }))
|
|
|
+ })
|
|
|
+ },
|
|
|
dealConversations(conversations) {
|
|
|
return conversations.map(item => {
|
|
|
let content = item.latestMsgContent
|
|
@@ -139,12 +172,14 @@ getContact(isNewMsg) {
|
|
|
} catch (err) {}
|
|
|
item.latestMsgContent = content
|
|
|
const now = new Date()
|
|
|
- if (now.getMonth() === new Date(item.latestMsgTime).getMonth() && now.getDate() === new Date(item.latestMsgTime).getDate()) {
|
|
|
+ if (item.latestMsgTime && now.getMonth() === new Date(item.latestMsgTime).getMonth() && now.getDate() === new Date(item.latestMsgTime).getDate()) {
|
|
|
item.timeStr = fotmatDate(item.latestMsgTime, 'hh:mm')
|
|
|
- } else {
|
|
|
+ } else if (item.latestMsgTime) {
|
|
|
item.timeStr = fotmatDate(item.latestMsgTime, 'MM/dd')
|
|
|
+ } else {
|
|
|
+ item.timeStr = ''
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return item
|
|
|
}).sort((a, b) => new Date(b.latestMsgTime) - new Date(a.latestMsgTime))
|
|
|
},
|