IM 部分页面逻辑,聊天列表-详情页
This commit is contained in:
@@ -2,19 +2,27 @@ import {
|
||||
request
|
||||
} from '../index'
|
||||
|
||||
const getImToken = () => {
|
||||
return request({
|
||||
url: 'im/token',
|
||||
}, true)
|
||||
}
|
||||
|
||||
const getFriends = () => {
|
||||
return request({
|
||||
url: 'im/friends',
|
||||
})
|
||||
}, true)
|
||||
}
|
||||
|
||||
const getUserInfo = async (targetId) => {
|
||||
const [err, res] = await request({
|
||||
url: 'im/userInfo/' + targetId,
|
||||
})
|
||||
return res
|
||||
const [err, res] = await uni.request({
|
||||
url: 'http://api.zh.shangkelian.cn/api/im/userInfo/' + targetId,
|
||||
})
|
||||
return res.data.data
|
||||
}
|
||||
|
||||
export {
|
||||
getFriends
|
||||
getImToken,
|
||||
getFriends,
|
||||
getUserInfo
|
||||
}
|
||||
|
||||
10
pages.json
10
pages.json
@@ -384,20 +384,12 @@
|
||||
"buttons": [{
|
||||
"float": "right",
|
||||
"fontSrc": "/static/uniicons.ttf",
|
||||
"text": "\ue64d"
|
||||
"text": "\ue607"
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/im/chum",
|
||||
"name": "ImChum",
|
||||
"style": {
|
||||
"navigationBarTitleText": "好友",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/wallet/add",
|
||||
"name": "WalletAdd",
|
||||
|
||||
1208
pages/im/chat.nvue
1208
pages/im/chat.nvue
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
||||
<template>
|
||||
<view>
|
||||
好友列表
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
</style>
|
||||
@@ -183,7 +183,8 @@
|
||||
$footer-height: 55px;
|
||||
|
||||
.scroll {
|
||||
height: calc(100vh - 55px);
|
||||
height: calc(100vh - 55px);
|
||||
width: 100vw;
|
||||
padding: 0 $uni-spacing-col-lg;
|
||||
}
|
||||
|
||||
@@ -242,11 +243,11 @@
|
||||
}
|
||||
|
||||
.msg {
|
||||
font-size: $uni-font-size-lg;
|
||||
font-size: $uni-font-size-base;
|
||||
margin: $uni-spacing-col-base;
|
||||
padding: $uni-spacing-col-base + 5rpx;
|
||||
padding: $uni-spacing-col-lg;
|
||||
word-wrap: break-word;
|
||||
width: 70%;
|
||||
width: 60%;
|
||||
border-radius: $uni-border-radius-base;
|
||||
position: relative;
|
||||
|
||||
|
||||
14
pages/im/friends/index.vue
Normal file
14
pages/im/friends/index.vue
Normal file
@@ -0,0 +1,14 @@
|
||||
<template>
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
8
pages/im/friends/info.vue
Normal file
8
pages/im/friends/info.vue
Normal file
@@ -0,0 +1,8 @@
|
||||
<template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
8
pages/im/friends/mine.vue
Normal file
8
pages/im/friends/mine.vue
Normal file
@@ -0,0 +1,8 @@
|
||||
<template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
@@ -1,43 +1,43 @@
|
||||
<template>
|
||||
<div>
|
||||
<u-popup overlay mode="left" closeable closeOnClickOverlay :show="showLeft" @close="showLeft = false">
|
||||
<leftMenu></leftMenu>
|
||||
</u-popup>
|
||||
|
||||
<div class="container">
|
||||
<div class="msg-item u-border-bottom" v-for="(item, index) in conversations" @click="toDetail(item)">
|
||||
<div class="avatar">
|
||||
<u-badge numberType="ellipsis" max="99" shape="horn" absolute :offset="[-7, -7]"
|
||||
:value="item.unreadMessageCount" />
|
||||
<u-avatar shape="square" :src="friend(item.targetId).portraitUrl"></u-avatar>
|
||||
</div>
|
||||
<div class="content ">
|
||||
<div class="name">
|
||||
<h3>{{ friend(item.targetId).name }}</h3>
|
||||
<span class="time">{{ item.sentTime|timeCustomCN }}</span>
|
||||
<div v-if="$store.state.token != ''">
|
||||
<div class="container">
|
||||
<div class="msg-item u-border-bottom" v-for="(item, index) in conversations" @click="toDetail(item)">
|
||||
<div class="avatar">
|
||||
<u-badge numberType="ellipsis" max="99" shape="horn" absolute :offset="[-7, -7]"
|
||||
:value="item.unreadMessageCount" />
|
||||
<u-avatar shape="square" :src="friend(item.targetId).portraitUrl"></u-avatar>
|
||||
</div>
|
||||
<div class="content ">
|
||||
<div class="name">
|
||||
<h3>{{ friend(item.targetId).name }}</h3>
|
||||
<span class="time">{{ item.sentTime|timeCustomCN }}</span>
|
||||
</div>
|
||||
<div class="u-line-1">{{ item.latestMessage.content }}</div>
|
||||
</div>
|
||||
<div class="u-line-1">{{ item.latestMessage.content }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<u-loadmore status="nomore" />
|
||||
</div>
|
||||
<div v-else>
|
||||
<button @click="toLogin">去登录</button>
|
||||
</div>
|
||||
<u-loadmore status="nomore" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as RongIMLib from '@rongcloud/imlib-uni'
|
||||
import im from '@/utils/im/index.js'
|
||||
import leftMenu from './components/left_menu.vue'
|
||||
import userAuth from '@/public/userAuth'
|
||||
import {
|
||||
getImToken
|
||||
} from '@/apis/interfaces/im.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
leftMenu
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isShown: true, // 当前页面显示状态
|
||||
conversations: [], // 会话列表
|
||||
showLeft: false
|
||||
conversations: [] // 会话列表
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -47,7 +47,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {},
|
||||
onLoad() {
|
||||
getImToken().then(res => {
|
||||
im.syncFriends()
|
||||
im.connect(res.token, res.userInfo)
|
||||
})
|
||||
},
|
||||
onShow() {
|
||||
this.getConversationList()
|
||||
this.isShown = true
|
||||
@@ -57,7 +62,6 @@
|
||||
},
|
||||
onNavigationBarButtonTap(e) {
|
||||
if (e.index == 0) {
|
||||
this.showLeft = true
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -68,6 +72,15 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 检查登录
|
||||
toLogin() {
|
||||
if (this.$store.state.token === '') {
|
||||
const Auth = new userAuth()
|
||||
Auth.Login()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
getFriend(targetId) {
|
||||
return this.$store.getters.userInfo(targetId)
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
getUserInfo
|
||||
} from "@/apis/interfaces/im.js"
|
||||
} from "@/apis/interfaces/im.js"
|
||||
|
||||
export default {
|
||||
state: {
|
||||
@@ -19,7 +19,7 @@ export default {
|
||||
if (state.friends.filter((item) => item.userId == targetId)[0]) {
|
||||
return state.friends.filter((item) => String(item.userId) == targetId)[0]
|
||||
} else {
|
||||
return getUserInfo()
|
||||
return getUserInfo(targetId)
|
||||
}
|
||||
},
|
||||
sender(state) {
|
||||
|
||||
@@ -43,6 +43,10 @@ const connect = (token, userInfo) => {
|
||||
store.dispatch('setSenderInfo', userInfo)
|
||||
|
||||
setNotifyBadge()
|
||||
}
|
||||
|
||||
const disconnect = () => {
|
||||
RongIMLib.disconnect()
|
||||
}
|
||||
|
||||
const addListeners = () => {
|
||||
|
||||
Reference in New Issue
Block a user