Commit 16a377ee authored by 黄媛媛's avatar 黄媛媛

11

parents 705fb78e 10d51510
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// //app.js
// App({
// onLaunch: function () {
// // 展示本地存储能力
// var logs = wx.getStorageSync('logs') || []
// logs.unshift(Date.now())
// wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// // 登录
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// }
// })
// // 获取用户信息
// wx.getSetting({
// success: res => {
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
// wx.getUserInfo({
// success: res => {
// // 可以将 res 发送给后台解码出 unionId
// this.globalData.userInfo = res.userInfo
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// if (this.userInfoReadyCallback) {
// this.userInfoReadyCallback(res)
// }
// }
// })
// }
// }
// })
// },
// globalData: {
// userInfo: null
// }
// })
import WeAppRedux from './redux/index.js';
import createStore from './redux/createStore.js';
import reducer from './store/reducer.js';
import ENVIRONMENT_CONFIG from './config/envConfig.js'
import PAGE_CONFIG from './config/pageConfig.js'
const { Provider } = WeAppRedux;
const store = createStore(reducer) // redux store
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
App(
Provider(store)(
{
globalData: {
emitter: null,
netcallController: null,
ENVIRONMENT_CONFIG,
PAGE_CONFIG
},
onShow: function (e) {
if (e.scene == 1007 || e.scene == 1008) {
try {
this.globalData.netcall && this.globalData.netcall.destroy()
this.globalData.nim && this.globalData.nim.destroy({
done: function () {
}
}
})
})
} catch (e) {
}
}
},
onLaunch: function (e) {
let userInfo = {
account: '17308037817',
nick: '罗超',
gender: 0,
createTime: 1514969730701,
updateTime: 1514969730701,
}
if (userInfo) {
this.globalData.userInfo = userInfo
}
let systemInfo = wx.getSystemInfoSync()
this.globalData.videoContainerSize = {
width: systemInfo.windowWidth,
height: systemInfo.windowHeight
}
this.globalData.isPushBeCallPage = false
}
})
},
globalData: {
userInfo: null
}
})
\ No newline at end of file
}
)
)
{
"pages": [
"pages/msg/index/index",
"pages/index/index",
"pages/video/index",
"pages/me/index",
"pages/validateForm/validateEnd/validateEnd",
"pages/welcome/welcome",
"pages/validateForm/validate/validate",
"pages/validateForm/validateEnd/validateEnd",
"pages/logs/logs",
"pages/me/index",
"pages/welcome/welcome",
"pages/msg/index",
"pages/logs/logs"
"pages/video/index"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black",
"navigationStyle": "custom"
},
"style": "v2",
"sitemapLocation": "sitemap.json",
......@@ -33,7 +30,7 @@
"selectedIconPath": "images/tabbar/homea.png"
},
{
"pagePath": "pages/msg/index",
"pagePath": "pages/msg/index/index",
"text": "消息",
"iconPath": "images/tabbar/msg.png",
"selectedIconPath": "images/tabbar/msga.png"
......
......@@ -18,7 +18,7 @@ let configMap = {
url: 'http://preapp.netease.im:8184'
},
online: {
appkey: 'b612b31e837c79c68f141aeb719d2b20',
appkey: '45c6af3c98409b18a84451215d0bdd6e',
url: 'https://app.netease.im'
},
};
......
......@@ -77,9 +77,9 @@ export default class IMController {
onpushevents: this.onPushEvents,
})
// 发送消息开始登陆
store.dispatch({
type: 'Login_StartLogin'
})
// store.dispatch({
// type: 'Login_StartLogin'
// })
}
/** 1
* 连接成功
......
import NetcallWeixin from '../vendors/NIM_Web_Netcall_weixin_v6.8.0.js'
import NIM from '../vendors/NIM_Web_NIM_weixin_v6.8.0.js'
import NIM from '../vendors/NIM_Web_NIM_weixin_v7.2.0.js'
import Emitter from '../utils/emitter.js'
let app = getApp()
......
// pages/msg/index.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
<view class='title'>
<text>消息(20)</text>
</view>
<view class="search">
<image src="/images/im/search.png"></image>
<text>搜索</text>
</view>
\ No newline at end of file
page{
font-family: -apple-system-font, Helvetica Neue, Helvetica, sans-serif;
font-size: 10pt;
/* line-height: 150%; */
min-height: 100%;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
}
.title{
background: #f1f1f1;
padding: 70rpx 30rpx 2rpx 30rpx;
font-size: 16pt;
border-bottom: 2rpx solid #EEE;
}
.search{
background: #F4F8FB;
height: 60rpx;
margin: 10rpx 30rpx;
border-radius: 12rpx;
text-align: center;
line-height: 60rpx
}
.search image{
width: 30rpx;
height: 30rpx;
margin-right: 10rpx;
margin-top:15rpx;
vertical-align: middle;
}
.search text{
font-size: 28rpx;
color: rgb(175, 178, 185);
}
\ No newline at end of file
import IMController from '../../../controller/im.js'
import { connect } from '../../../redux/index.js'
import { showToast, calcTimeHeader, clickLogoJumpToCard } from '../../../utils/util.js'
import { iconNoMessage } from '../../../utils/imageBase64.js'
let app = getApp()
let store = app.store
let startX = 0
let pageConfig = {
/**
* 页面的初始数据
*/
data: {
iconNoMessage: '',
loginUserAccount: '',
translateX: 0,
defaultUserLogo: '',
chatList: [], // [{account,nick,lastestMsg,type,timestamp,displayTime,message,unread,status}]
chatAccount: {}, // {accountName: accountName} 备注:消息通知key为notification
showSearchBox: 0,
searchConten: '',
isFocus: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
new IMController({
token: '111111',
account: '17308037817'
})
// 条目题目展示我的电脑
this.setData({
iconNoMessage,
defaultUserLogo: app.globalData.PAGE_CONFIG.defaultUserLogo
})
},
/**
* 阻止事件冒泡空函数
*/
stopEventPropagation() {
},
/**
* 显示时排序
*/
onShow() {
// this.sortChatList()
},
changeSearchBox: function (e) {
console.log(e.currentTarget.dataset.type)
this.setData({
showSearchBox: (e.currentTarget.dataset.type == 1 || this.data.searchConten.length > 0) ? 1 : 0,
isFocus: e.currentTarget.dataset.type == 1
});
console.log(this.data.showSearchBox)
},
searchInput: function (e) {
this.setData({
searchConten: e.detail.value
})
},
/**
* 排序chatlist
*/
sortChatList() {
if (this.data.chatList.length !== 0) {
let chatList = [...this.data.chatList]
chatList.sort((a, b) => {
return parseInt(b.timestamp) - parseInt(a.timestamp)
})
this.setData({
chatList
})
}
},
/**
* 传递消息进来,添加至最近会话列表
* 必须字段 {type, time, from,to}
*/
addNotificationToChatList(msg) {
let desc = ''
let self = this
switch (msg.type) {
case 'addFriend': {
desc = `添加好友-${msg.from}`
break
}
case 'deleteFriend': {
desc = `删除好友-${msg.from}`
break
}
case 'deleteMsg':
desc = `${msg.from}撤回了一条消息`
break
case 'custom':
let data = JSON.parse(msg.content)
let seen = []
let str = data['content'] || JSON.stringify(data, function (key, val) {
if (typeof val == "object") {
if (seen.indexOf(val) >= 0)
return
seen.push(val)
}
return val
}) // 可能没有content属性
desc = `自定义系统通知-${str}`
break
default:
desc = msg.type
break
}
if (!self.data.chatAccount['notification']) { // 没有系统通知
self.setData({
chatList: [{
account: '消息通知',
timestamp: msg.time,
displayTime: msg.time ? calcTimeHeader(msg.time) : '',
lastestMsg: desc,
}, ...self.data.chatList],
chatAccount: Object.assign({}, self.data.chatAccount, { notification: 'notification' })
})
} else {
let temp = [...self.data.chatList]
temp.map((message, index) => {
if (message.account === '消息通知') {
temp[index].lastestMsg = desc
temp[index].timestamp = msg.time
temp[index].displayTime = msg.time ? calcTimeHeader(msg.time) : ''
return
}
})
temp.sort((a, b) => {
return a.timestamp < b.timestamp
})
self.setData({
chatList: temp
})
}
},
/**
* 捕获从滑动删除传递来的事件
*/
catchDeleteNotification(e) {
store.dispatch({
type: 'Notification_Clear_All',
})
},
/**
* 捕获从滑动删除传递来的事件
*/
catchDeleteTap(e) {
let session = e.currentTarget.dataset.session
let chatAccount = Object.assign({}, this.data.chatAccount)
delete chatAccount[session]
let chatList = [...this.data.chatList]
let deleteIndex = 0
chatList.map((item, index) => {
if (item.session === session) {
deleteIndex = index
return
}
})
chatList.splice(deleteIndex, 1)
store.dispatch({
type: 'Delete_All_MessageByAccount',
payload: session
})
this.setData({
chatList,
chatAccount
})
},
/**
* 单击消息通知
*/
switchToMessageNotification() {
wx.navigateTo({
url: '../../partials/messageNotification/messageNotification',
})
},
/**
* 单击进入聊天页面
*/
switchToChating(e) {
let account = e.currentTarget.dataset.account
let session = e.currentTarget.dataset.session
// 更新会话对象
store.dispatch({
type: 'CurrentChatTo_Change',
payload: session
})
let typeAndAccount = session.split('-')
var chatType
if (typeAndAccount[0] === 'team') {
let card = this.data.groupList[typeAndAccount[1]] || {}
chatType = card.type || 'team'
store.dispatch({
type: 'Set_Current_Group',
payload: account
})
} else {
chatType = 'p2p'
}
// 告知服务器,标记会话已读
app.globalData.nim.resetSessionUnread(session)
// 跳转
wx.navigateTo({
url: `../../partials/chating/chating?chatTo=${account}&type=${chatType}`,
})
},
/**
* 单击进入个人区域
*/
switchToPersonCard(e) {
let account = e.currentTarget.dataset.account
if (account === 'ai-assistant') {
return
}
// 重置该人的未读数
// 重置某个会话的未读数,如果是已经存在的会话记录, 会将此会话未读数置为 0, 并会收到onupdatesession回调,而且此会话在收到消息之后依然会更新未读数
app.globalData.nim.resetSessionUnread(`p2p-${account}`)
// 压栈进入account介绍页
clickLogoJumpToCard(this.data.friendCard, account, true)
},
/**
* 判断消息类型,返回提示
*/
judgeMessageType(rawMsg) {
rawMsg = rawMsg || {}
let msgType = ''
if (rawMsg.type === 'image') {
msgType = '[图片]'
} else if (rawMsg.type === 'geo') {
msgType = '[位置]'
} else if (rawMsg.type === 'audio') {
msgType = '[语音]'
} else if (rawMsg.type === 'video') {
msgType = '[视频]'
} else if (rawMsg.type === 'custom') {
msgType = rawMsg.pushContent || '[自定义消息]'
} else if (rawMsg.type === 'tip') {
msgType = '[提醒消息]'
} else if (rawMsg.type === 'deleteMsg') {//可能是他人撤回消息
msgType = '[提醒消息]'
} else if (rawMsg.type === 'file') {
msgType = '[文件消息]'
} else if (rawMsg.type === '白板消息') {
msgType = '[白板消息]'
} else if (rawMsg.type === '阅后即焚') {
msgType = '[阅后即焚]'
} else if (rawMsg.type === 'robot') {
msgType = '[机器人消息]'
} else if (rawMsg.type === 'notification') {
msgType = '[通知消息]'
}
return msgType
},
/**
* 将原生消息转化为最近会话列表渲染数据
*/
convertRawMessageListToRenderChatList(rawMessageList, friendCard, groupList, unreadInfo) {
let chatList = []
let sessions = Object.keys(rawMessageList)
let index = 0
sessions.map(session => {
let account = session.indexOf('team-') === 0 ? session.slice(5, session.length) : session.slice(4, session.length)
let isP2p = session.indexOf('p2p-') === 0
let chatType = isP2p ? 'p2p' : (groupList[account] && groupList[account].type)
let sessionCard = (isP2p ? friendCard[account] : groupList[account]) || {}
let unixtimeList = Object.keys(rawMessageList[session])
if (!unixtimeList) {
return
}
let maxTime = Math.max(...unixtimeList)
if (maxTime) {
let msg = rawMessageList[session][maxTime + ''] || {}
let msgType = this.judgeMessageType(msg)
let lastestMsg = msgType
let status = isP2p ? (sessionCard.status || '离线') : ''
let nick = isP2p ? (sessionCard.nick || '非好友') : sessionCard.name
let avatar = isP2p ? (sessionCard.avatar || app.globalData.PAGE_CONFIG.defaultUserLogo) : (sessionCard.avatar || app.globalData.PAGE_CONFIG.defaultUserLogo)
chatList.push({
chatType,
session,
account,
status,
nick,
avatar,
lastestMsg: lastestMsg || msg.text,
type: msgType || msg.type,
timestamp: msg.time,
unread: unreadInfo[session] || 0,
displayTime: msg.time ? calcTimeHeader(msg.time) : ''
})
}
})
// 排序
chatList.sort((a, b) => {
return b.timestamp - a.timestamp
})
return chatList
},
/**
* 计算最近一条发送的通知消息列表
*/
caculateLastestNotification(notificationList) {
let temp = Object.assign({}, notificationList)
let lastestDesc = ''
let systemMaxIndex = null
let customMaxIndex = null
// 从大到小
let system = notificationList.system.sort((a, b) => {
return b.msg.time - a.msg.time
})
let custom = notificationList.custom.sort((a, b) => {
return b.msg.time - a.msg.time
})
if (system[0]) {
if (custom[0]) {
lastestDesc = system[0].msg.time - custom[0].msg.time ? system[0].desc : custom[0].desc
} else {
lastestDesc = system[0].desc
}
} else {
if (custom[0]) {
lastestDesc = custom[0].desc
}
}
return lastestDesc
}
}
let mapStateToData = (state) => {
let chatList = pageConfig.convertRawMessageListToRenderChatList(state.rawMessageList, state.friendCard, state.groupList, state.unreadInfo)
let latestNotification = pageConfig.caculateLastestNotification(state.notificationList)
return {
rawMessageList: state.rawMessageList,
userInfo: state.userInfo,
friendCard: state.friendCard,
groupList: state.groupList,
unreadInfo: state.unreadInfo,
chatList: chatList,
latestNotification
}
}
const mapDispatchToPage = (dispatch) => ({
})
let connectedPageConfig = connect(mapStateToData, mapDispatchToPage)(pageConfig)
Page(connectedPageConfig)
<view class='title'>
<text>消息(20)</text>
</view>
<view class="search">
<view class="{{showSearchBox==0?'':'hide'}}" bindtap="changeSearchBox" data-type="1">
<image src="/images/im/search.png"></image>
<text>搜索</text>
</view>
<input type='text' bindinput='searchInput' class="search-input {{showSearchBox==1?'':'hide'}}" bindblur="changeSearchBox" data-type="0" focus='{{isFocus}}'/>
</view>
<view class="msg-box">
<view class="msg-item">
<image class="avater" src="http://imgfile.oytour.com/New/Upload/User/20191018150051176.png"></image>
<view class="msg-content">
<view class="item-name">
罗超
</view>
<view class="lst-msg">
如果来不及的话,就直接使用Vue-table来做,这样会快一点
</view>
</view>
<view class="times">
<view class="timer">16:23</view>
<view>
<text class="pops">9</text>
</view>
</view>
</view>
<view class="msg-item" wx:if="{{chatList.length != 0}}" wx:for="{{chatList}}" wx:for-item="message" wx:key="message.time" data-session='{{message.session}}'>
<image class="avater" src="{{message.avatar}}"></image>
<view class="msg-content">
<view class="item-name">
{{message.nick}}
</view>
<view class="lst-msg">
{{message.lastestMsg}}
</view>
</view>
<view class="times">
<view class="timer">昨天</view>
<view wx:if="{{message.unread}}">
<text class="pops">{{message.unread || ''}}</text>
</view>
</view>
</view>
</view>
\ No newline at end of file
page{
font-family: -apple-system-font, Helvetica Neue, Helvetica, sans-serif;
font-size: 10pt;
/* line-height: 150%; */
min-height: 100%;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
}
.title{
background: #f1f1f1;
padding: 70rpx 30rpx 2rpx 30rpx;
font-size: 16pt;
border-bottom: 2rpx solid #EEE;
}
.search{
background: #F4F8FB;
height: 60rpx;
margin: 10rpx 30rpx;
border-radius: 12rpx;
text-align: center;
line-height: 60rpx
}
.search image{
width: 30rpx;
height: 30rpx;
margin-right: 10rpx;
margin-top:15rpx;
vertical-align: top;
}
.search text{
font-size: 28rpx;
color: rgb(175, 178, 185);
}
.search .search-input{
border: none;
outline: none;
margin: 0 12rpx;
height: 60rpx;
line-height: 60rpx;
font-size: 28rpx;
background: url('http://imgfile.oytour.com/New/Upload/Cloud/2020-02/20200217080946488.png');
background-position:left center;
background-size:30rpx 30rpx;
text-align: left;
padding-left: 40rpx;
background-repeat: no-repeat;
}
.msg-box{
margin-top: 10rpx;
}
.msg-box .msg-item{
display: flex;
height: 100rpx;
padding: 20rpx 30rpx;
flex-direction: row;
justify-content: flex-start;
}
.msg-box .msg-item:active{
background: #F4F8FB;
}
.msg-box .msg-item .avater{
height: 100rpx;
width: 100rpx;
border-radius: 100rpx;
margin-right: 20rpx;
}
.msg-box .msg-item .msg-content{
flex: 1;
}
.msg-box .msg-item .msg-content .item-name{
font-size: 36rpx;
font-weight: 600;
}
.msg-box .msg-item .msg-content .lst-msg{
font-size: 28rpx;
color: #888;
text-overflow: ellipsis;
white-space: normal;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
.msg-box .msg-item .times{
width: 100rpx;
text-align: right;
}
.msg-box .msg-item .times .timer{
font-size: 26rpx;
color: #999;
flex: 1;
margin-top: 10rpx;
}
.msg-box .msg-item .times .pops{
font-size: 26rpx;
height: 24rpx;
padding: 10rpx;
min-width: 24rpx;
border-radius: 44rpx;
color: #FFF;
background: #EA005E;
margin-top: 10rpx;
display: inline-block;
text-align: center;
line-height: 24rpx;
}
.hide{
display: none;
}
\ No newline at end of file
......@@ -4,15 +4,23 @@
"ignore": []
},
"setting": {
"urlCheck": true,
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"autoAudits": false,
"coverView": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false
"scopeDataCheck": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"compileType": "miniprogram",
"libVersion": "2.0.4",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment