Merge branch 'lr' of http://1.94.221.165:3000/sx/jiuyiUniapp
This commit is contained in:
commit
4e769f24ed
|
@ -208,10 +208,11 @@ export const news = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 群聊发消息
|
// 消息列表
|
||||||
getMessageList(param) {
|
getMessageList(param) {
|
||||||
return util.request({
|
return util.request({
|
||||||
url: `/user/chat/getMessageList`,
|
// url: `/user/chat/getMessageList`,
|
||||||
|
url: `/user/chat/getMsgListById`,
|
||||||
query: param.query,
|
query: param.query,
|
||||||
data: param.data,
|
data: param.data,
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
|
|
|
@ -15,6 +15,9 @@ import {
|
||||||
reactive,
|
reactive,
|
||||||
watch,
|
watch,
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
|
import {
|
||||||
|
onLoad,
|
||||||
|
} from "@dcloudio/uni-app"
|
||||||
// 工具库
|
// 工具库
|
||||||
import util from '@/common/js/util';
|
import util from '@/common/js/util';
|
||||||
const {
|
const {
|
||||||
|
@ -149,6 +152,8 @@ onMounted(() => {
|
||||||
//
|
//
|
||||||
// proxy.$refs.alert.open()
|
// proxy.$refs.alert.open()
|
||||||
|
|
||||||
|
})
|
||||||
|
onLoad(()=>{
|
||||||
// 获取未读消息数量
|
// 获取未读消息数量
|
||||||
getNoReadNum()
|
getNoReadNum()
|
||||||
})
|
})
|
||||||
|
@ -182,6 +187,7 @@ function handleMenu(item) {
|
||||||
else uni.navigateTo({
|
else uni.navigateTo({
|
||||||
url: `/${item.pagePath}`,
|
url: `/${item.pagePath}`,
|
||||||
})
|
})
|
||||||
|
getNoReadNum()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -221,9 +227,10 @@ function getNoReadNum() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #ifdef APP
|
||||||
const unreadCount = uni.$chat.getTotalUnreadMessageCount();
|
const unreadCount = uni.$chat.getTotalUnreadMessageCount();
|
||||||
|
|
||||||
noReadNum.value = +unreadCount > 99 ? '99+' : unreadCount;
|
noReadNum.value = +unreadCount > 99 ? '99+' : unreadCount;
|
||||||
|
// #endif
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -43,9 +43,11 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
// #ifdef APP
|
||||||
uni.offKeyboardHeightChange(rs => {
|
uni.offKeyboardHeightChange(rs => {
|
||||||
console.log('rs', rs)
|
console.log('rs', rs)
|
||||||
})
|
})
|
||||||
|
// #endif
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,430 +1,433 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* 通讯录
|
* 通讯录
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
useStore,
|
useStore,
|
||||||
} from 'vuex'
|
} from 'vuex'
|
||||||
import {
|
import {
|
||||||
ref,
|
ref,
|
||||||
computed,
|
computed,
|
||||||
reactive,
|
reactive,
|
||||||
onMounted,
|
onMounted,
|
||||||
onUnmounted,
|
onUnmounted,
|
||||||
inject,
|
inject,
|
||||||
getCurrentInstance,
|
getCurrentInstance,
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
// 工具库
|
// 工具库
|
||||||
import util from '@/common/js/util.js'
|
import util from '@/common/js/util.js'
|
||||||
// 腾讯云聊天
|
// 腾讯云聊天
|
||||||
import TencentCloudChat from '@tencentcloud/chat';
|
import TencentCloudChat from '@tencentcloud/chat';
|
||||||
// api
|
// api
|
||||||
import api from '@/api/index.js'
|
import api from '@/api/index.js'
|
||||||
import pinyin from 'js-pinyin'
|
import pinyin from 'js-pinyin'
|
||||||
import {
|
import {
|
||||||
forEach
|
forEach
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
const {
|
const {
|
||||||
proxy
|
proxy
|
||||||
} = getCurrentInstance();
|
} = getCurrentInstance();
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const userinfo = computed(() => {
|
const userinfo = computed(() => {
|
||||||
let result = store.state.userinfo
|
let result = store.state.userinfo
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
const msgType = {}
|
const msgType = {}
|
||||||
// 用户列表
|
// 用户列表
|
||||||
const userList = reactive({
|
const userList = reactive({
|
||||||
data: [],
|
data: [],
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
total: 0,
|
total: 0,
|
||||||
})
|
})
|
||||||
// 当前操作的用户
|
// 当前操作的用户
|
||||||
let user = reactive({})
|
let user = reactive({})
|
||||||
// 列表下标
|
// 列表下标
|
||||||
const listKey = ref('')
|
const listKey = ref('')
|
||||||
// 字母列表
|
// 字母列表
|
||||||
const letterList = [{
|
const letterList = [{
|
||||||
key: 'other',
|
key: 'other',
|
||||||
name: '#',
|
name: '#',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'a',
|
key: 'a',
|
||||||
name: 'A',
|
name: 'A',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'b',
|
key: 'b',
|
||||||
name: 'B',
|
name: 'B',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'c',
|
key: 'c',
|
||||||
name: 'C',
|
name: 'C',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'd',
|
key: 'd',
|
||||||
name: 'D',
|
name: 'D',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'e',
|
key: 'e',
|
||||||
name: 'E',
|
name: 'E',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'f',
|
key: 'f',
|
||||||
name: 'F',
|
name: 'F',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'g',
|
key: 'g',
|
||||||
name: 'G',
|
name: 'G',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'h',
|
key: 'h',
|
||||||
name: 'H',
|
name: 'H',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'i',
|
key: 'i',
|
||||||
name: 'I',
|
name: 'I',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'j',
|
key: 'j',
|
||||||
name: 'J',
|
name: 'J',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'k',
|
key: 'k',
|
||||||
name: 'K',
|
name: 'K',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'l',
|
key: 'l',
|
||||||
name: 'L',
|
name: 'L',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'm',
|
key: 'm',
|
||||||
name: 'M',
|
name: 'M',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'n',
|
key: 'n',
|
||||||
name: 'N',
|
name: 'N',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'o',
|
key: 'o',
|
||||||
name: 'O',
|
name: 'O',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'p',
|
key: 'p',
|
||||||
name: 'P',
|
name: 'P',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'q',
|
key: 'q',
|
||||||
name: 'Q',
|
name: 'Q',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'r',
|
key: 'r',
|
||||||
name: 'R',
|
name: 'R',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 's',
|
key: 's',
|
||||||
name: 'S',
|
name: 'S',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 't',
|
key: 't',
|
||||||
name: 'T',
|
name: 'T',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'u',
|
key: 'u',
|
||||||
name: 'U',
|
name: 'U',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'v',
|
key: 'v',
|
||||||
name: 'V',
|
name: 'V',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'w',
|
key: 'w',
|
||||||
name: 'W',
|
name: 'W',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'x',
|
key: 'x',
|
||||||
name: 'X',
|
name: 'X',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'y',
|
key: 'y',
|
||||||
name: 'Y',
|
name: 'Y',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'z',
|
key: 'z',
|
||||||
name: 'Z',
|
name: 'Z',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
// 是否移动
|
// 是否移动
|
||||||
const touchmove = ref(false)
|
const touchmove = ref(false)
|
||||||
// 字母列表dom属性
|
// 字母列表dom属性
|
||||||
const letterDom = reactive({
|
const letterDom = reactive({
|
||||||
itemHeight: 0,
|
itemHeight: 0,
|
||||||
minHeight: 0,
|
minHeight: 0,
|
||||||
maxHeight: 0,
|
maxHeight: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
})
|
})
|
||||||
// 右滑菜单
|
// 右滑菜单
|
||||||
const rightOption = [{
|
const rightOption = [{
|
||||||
text: '删除',
|
text: '删除',
|
||||||
style: {
|
style: {
|
||||||
backgroundColor: '#F85050'
|
backgroundColor: '#F85050'
|
||||||
},
|
},
|
||||||
fn: (user) => delFriend(user),
|
fn: (user) => delFriend(user),
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// text: '修改备注',
|
// text: '修改备注',
|
||||||
// style: {
|
// style: {
|
||||||
// backgroundColor: '#10C100'
|
// backgroundColor: '#10C100'
|
||||||
// },
|
// },
|
||||||
// fn: (user) => setFriendNote(user),
|
// fn: (user) => setFriendNote(user),
|
||||||
// },
|
// },
|
||||||
]
|
]
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
// 获取朋友列表
|
|
||||||
getFriendList()
|
|
||||||
// 获取字母属性
|
|
||||||
getLetterProperty()
|
|
||||||
// 添加监听
|
|
||||||
addlistener()
|
|
||||||
|
|
||||||
// proxy.$refs.note.open()
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
removelistener()
|
|
||||||
})
|
|
||||||
|
|
||||||
const viewData = ref([])
|
|
||||||
|
|
||||||
// 添加加好友监听
|
|
||||||
function addlistener() {
|
|
||||||
let onFriendListUpdated = (event) => {
|
|
||||||
console.log('onFriendListUpdated', event.data);
|
|
||||||
getFriendList()
|
|
||||||
}
|
|
||||||
|
|
||||||
uni.$chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除加好友监听
|
|
||||||
function removelistener() {
|
|
||||||
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, () => {});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
// 获取朋友列表
|
// 获取朋友列表
|
||||||
function getFriendList() {
|
getFriendList()
|
||||||
// 验证sdk是否准备完毕
|
// 获取字母属性
|
||||||
let isReady = uni.$chat.isReady();
|
getLetterProperty()
|
||||||
console.log('getFriendList', isReady)
|
// 添加监听
|
||||||
|
addlistener()
|
||||||
|
|
||||||
if (!isReady) {
|
// proxy.$refs.note.open()
|
||||||
setTimeout(function() {
|
})
|
||||||
getFriendList()
|
|
||||||
}, 500);
|
onUnmounted(() => {
|
||||||
|
removelistener()
|
||||||
|
})
|
||||||
|
|
||||||
|
const viewData = ref([])
|
||||||
|
|
||||||
|
// 添加加好友监听
|
||||||
|
function addlistener() {
|
||||||
|
let onFriendListUpdated = (event) => {
|
||||||
|
console.log('onFriendListUpdated', event.data);
|
||||||
|
getFriendList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// #ifdef APP
|
||||||
|
uni.$chat.on(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, onFriendListUpdated);
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除加好友监听
|
||||||
|
function removelistener() {
|
||||||
|
// #ifdef APP
|
||||||
|
uni.$chat.off(TencentCloudChat.EVENT.FRIEND_LIST_UPDATED, () => { });
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取朋友列表
|
||||||
|
function getFriendList() {
|
||||||
|
// 验证sdk是否准备完毕
|
||||||
|
let isReady = uni.$chat.isReady();
|
||||||
|
console.log('getFriendList', isReady)
|
||||||
|
|
||||||
|
if (!isReady) {
|
||||||
|
setTimeout(function () {
|
||||||
|
getFriendList()
|
||||||
|
}, 500);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
api.news.getFriendList().then(rs => {
|
||||||
|
if (rs.code == 200) {
|
||||||
|
const result = rs.data
|
||||||
|
userList.data.length = 0
|
||||||
|
userList.data = handleUserList(result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log('getFriendList')
|
util.alert({
|
||||||
|
content: rs.msg,
|
||||||
//
|
showCancel: false,
|
||||||
api.news.getFriendList().then(rs => {
|
|
||||||
if (rs.code == 200) {
|
|
||||||
const result = rs.data
|
|
||||||
userList.data.length = 0
|
|
||||||
userList.data = handleUserList(result)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
util.alert({
|
|
||||||
content: rs.msg,
|
|
||||||
showCancel: false,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户列表排序
|
* 用户列表排序
|
||||||
* @param {Object} userList
|
* @param {Object} userList
|
||||||
*/
|
*/
|
||||||
function handleUserList(userList) {
|
function handleUserList(userList) {
|
||||||
// 筛选后的用户列表
|
// 筛选后的用户列表
|
||||||
const userArr = []
|
const userArr = []
|
||||||
// 遍历用户列表
|
// 遍历用户列表
|
||||||
for (let i = 0; i < userList.length; i++) {
|
for (let i = 0; i < userList.length; i++) {
|
||||||
const user = userList[i]
|
const user = userList[i]
|
||||||
// 取拼音
|
// 取拼音
|
||||||
let char = pinyin.getCamelChars(user.remark || user.userNickname);
|
let char = pinyin.getCamelChars(user.remark || user.userNickname);
|
||||||
// 假设姓名的第一个字符为姓氏
|
// 假设姓名的第一个字符为姓氏
|
||||||
const letter = char.charAt(0)
|
const letter = char.charAt(0)
|
||||||
// 下标
|
// 下标
|
||||||
let find_index = userArr.findIndex(item => {
|
let find_index = userArr.findIndex(item => {
|
||||||
return item.key === letter
|
return item.key === letter
|
||||||
|
})
|
||||||
|
|
||||||
|
// 未找到追加整过数组 找到追加到子数组
|
||||||
|
if (find_index == -1) {
|
||||||
|
userArr.push({
|
||||||
|
letter: letter,
|
||||||
|
key: letter,
|
||||||
|
child: [user]
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
// 未找到追加整过数组 找到追加到子数组
|
userArr[find_index].child.push(user)
|
||||||
if (find_index == -1) {
|
|
||||||
userArr.push({
|
|
||||||
letter: letter,
|
|
||||||
key: letter,
|
|
||||||
child: [user]
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
userArr[find_index].child.push(user)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照姓氏的字典序对二维数组进行排序
|
|
||||||
// userArr.sort((a, b) => {
|
|
||||||
// const surnameA = a.key;
|
|
||||||
// const surnameB = b.key;
|
|
||||||
// return surnameA.localeCompare(surnameB);
|
|
||||||
// });
|
|
||||||
return userArr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 按照姓氏的字典序对二维数组进行排序
|
||||||
|
// userArr.sort((a, b) => {
|
||||||
|
// const surnameA = a.key;
|
||||||
|
// const surnameB = b.key;
|
||||||
|
// return surnameA.localeCompare(surnameB);
|
||||||
|
// });
|
||||||
|
return userArr;
|
||||||
|
}
|
||||||
|
|
||||||
// 获取
|
|
||||||
function getLetterProperty() {
|
|
||||||
const query = uni.createSelectorQuery().in(proxy);
|
|
||||||
|
|
||||||
query.select(".letterBox").boundingClientRect((data) => {
|
// 获取
|
||||||
letterDom.minHeight = data.top
|
function getLetterProperty() {
|
||||||
letterDom.height = data.height
|
const query = uni.createSelectorQuery().in(proxy);
|
||||||
letterDom.maxHeight = data.bottom
|
|
||||||
letterDom.itemHeight = data.height / letterList.length
|
|
||||||
}).exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 手指触摸开始
|
query.select(".letterBox").boundingClientRect((data) => {
|
||||||
function handleTouchStart(ev) {
|
letterDom.minHeight = data.top
|
||||||
touchmove.value = true
|
letterDom.height = data.height
|
||||||
}
|
letterDom.maxHeight = data.bottom
|
||||||
|
letterDom.itemHeight = data.height / letterList.length
|
||||||
|
}).exec();
|
||||||
|
}
|
||||||
|
|
||||||
// 手指触摸移动
|
// 手指触摸开始
|
||||||
function handleTouchMove(ev) {
|
function handleTouchStart(ev) {
|
||||||
if (!touchmove.value) return
|
touchmove.value = true
|
||||||
// 判断临界值
|
}
|
||||||
let result = ev.touches[0].pageY
|
|
||||||
result = Math.max(result, letterDom.minHeight)
|
|
||||||
result = Math.min(result, letterDom.maxHeight)
|
|
||||||
|
|
||||||
// 计算当前在那个下标
|
// 手指触摸移动
|
||||||
let index = Math.floor(result - letterDom.minHeight) / letterDom.itemHeight
|
function handleTouchMove(ev) {
|
||||||
index = parseInt(index)
|
if (!touchmove.value) return
|
||||||
|
// 判断临界值
|
||||||
|
let result = ev.touches[0].pageY
|
||||||
|
result = Math.max(result, letterDom.minHeight)
|
||||||
|
result = Math.min(result, letterDom.maxHeight)
|
||||||
|
|
||||||
// 修改下标
|
// 计算当前在那个下标
|
||||||
listKey.value = letterList[index].key
|
let index = Math.floor(result - letterDom.minHeight) / letterDom.itemHeight
|
||||||
}
|
index = parseInt(index)
|
||||||
|
|
||||||
// 手指触摸结束
|
// 修改下标
|
||||||
function handleTouchEnd(ev) {
|
listKey.value = letterList[index].key
|
||||||
touchmove.value = false
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 手指触摸结束
|
||||||
* 点击字母
|
function handleTouchEnd(ev) {
|
||||||
* @param {Object} item 点击的当前项
|
touchmove.value = false
|
||||||
*/
|
}
|
||||||
function handleLetter(item) {
|
|
||||||
listKey.value = item.key
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 右滑菜单
|
* 点击字母
|
||||||
* @param {Object} ev 默认事件
|
* @param {Object} item 点击的当前项
|
||||||
* @param {Object} user 用户信息
|
*/
|
||||||
*/
|
function handleLetter(item) {
|
||||||
function handleSwipeAction(ev, user) {
|
listKey.value = item.key
|
||||||
ev.content.fn(user)
|
}
|
||||||
proxy.$refs.swipeAction.closeAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除好友
|
* 右滑菜单
|
||||||
* @param {Object} user 需要删除的好友信息
|
* @param {Object} ev 默认事件
|
||||||
*/
|
* @param {Object} user 用户信息
|
||||||
function delFriend(user) {
|
*/
|
||||||
new Promise((resolve, reject) => {
|
function handleSwipeAction(ev, user) {
|
||||||
util.alert({
|
ev.content.fn(user)
|
||||||
content: `确认删除好友${user.remark || user.userNickname}?`
|
proxy.$refs.swipeAction.closeAll()
|
||||||
}).then(res => {
|
}
|
||||||
if (!res.confirm) return
|
|
||||||
return resolve()
|
/**
|
||||||
})
|
* 删除好友
|
||||||
}).then(rs => {
|
* @param {Object} user 需要删除的好友信息
|
||||||
api.news.deleteFriend({
|
*/
|
||||||
query: {
|
function delFriend(user) {
|
||||||
toUserIds: user.userId,
|
new Promise((resolve, reject) => {
|
||||||
},
|
util.alert({
|
||||||
}).then(rs => {
|
content: `确认删除好友${user.remark || user.userNickname}?`
|
||||||
if (rs.code === 200) {
|
}).then(res => {
|
||||||
// 获取朋友列表
|
if (!res.confirm) return
|
||||||
getFriendList()
|
return resolve()
|
||||||
return
|
|
||||||
}
|
|
||||||
util.alert({
|
|
||||||
content: rs.msg,
|
|
||||||
showCancel: false,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}).then(rs => {
|
||||||
|
api.news.deleteFriend({
|
||||||
/**
|
|
||||||
* 设置好友备注
|
|
||||||
* @param {Object} ev 需要操作的好友信息
|
|
||||||
*/
|
|
||||||
function setFriendNote(ev) {
|
|
||||||
// 合并用户信息
|
|
||||||
Object.assign(user, ev)
|
|
||||||
// 打开设置用户备注弹窗
|
|
||||||
setTimeout(() => {
|
|
||||||
proxy.$refs.note.open()
|
|
||||||
}, 50)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置好友备注
|
|
||||||
function handleSaveNote() {
|
|
||||||
api.news.setNotes({
|
|
||||||
query: {
|
query: {
|
||||||
name: user.note || '',
|
toUserIds: user.userId,
|
||||||
friendId: user.userId,
|
},
|
||||||
}
|
|
||||||
}).then(rs => {
|
}).then(rs => {
|
||||||
if (rs.code === 200) {
|
if (rs.code === 200) {
|
||||||
proxy.$refs.note.close()
|
// 获取朋友列表
|
||||||
//
|
getFriendList()
|
||||||
refreshFriendList()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
util.alert({
|
util.alert({
|
||||||
content: rs.msg,
|
content: rs.msg,
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 点击用户
|
* 设置好友备注
|
||||||
* @param {Object} user 当前用户信息
|
* @param {Object} ev 需要操作的好友信息
|
||||||
*/
|
*/
|
||||||
function handleUser(user) {
|
function setFriendNote(ev) {
|
||||||
util.toChat({
|
// 合并用户信息
|
||||||
name: user.remark || user.userNickname,
|
Object.assign(user, ev)
|
||||||
msgId: user.userId,
|
// 打开设置用户备注弹窗
|
||||||
type: 'C2C',
|
setTimeout(() => {
|
||||||
})
|
proxy.$refs.note.open()
|
||||||
}
|
}, 50)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
// 设置好友备注
|
||||||
* 跳转
|
function handleSaveNote() {
|
||||||
* @param {Object} url
|
api.news.setNotes({
|
||||||
*/
|
query: {
|
||||||
function link(url) {
|
name: user.note || '',
|
||||||
uni.navigateTo({
|
friendId: user.userId,
|
||||||
url,
|
}
|
||||||
|
}).then(rs => {
|
||||||
|
if (rs.code === 200) {
|
||||||
|
proxy.$refs.note.close()
|
||||||
|
//
|
||||||
|
refreshFriendList()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
util.alert({
|
||||||
|
content: rs.msg,
|
||||||
|
showCancel: false,
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击用户
|
||||||
|
* @param {Object} user 当前用户信息
|
||||||
|
*/
|
||||||
|
function handleUser(user) {
|
||||||
|
util.toChat({
|
||||||
|
name: user.remark || user.userNickname,
|
||||||
|
msgId: user.userId,
|
||||||
|
type: 'C2C',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转
|
||||||
|
* @param {Object} url
|
||||||
|
*/
|
||||||
|
function link(url) {
|
||||||
|
uni.navigateTo({
|
||||||
|
url,
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -449,10 +452,10 @@
|
||||||
<view class="letter ptb10 plr30 c666 f20">{{ item.letter }}</view>
|
<view class="letter ptb10 plr30 c666 f20">{{ item.letter }}</view>
|
||||||
<view class="child pl30 pr50">
|
<view class="child pl30 pr50">
|
||||||
<uni-swipe-action-item :right-options="rightOption" v-for="(user, secIndex) in item.child"
|
<uni-swipe-action-item :right-options="rightOption" v-for="(user, secIndex) in item.child"
|
||||||
:key="secIndex" @click="handleSwipeAction($event,user)">
|
:key="secIndex" @click="handleSwipeAction($event, user)">
|
||||||
<view class="item rows ptb20" @click="handleUser(user)">
|
<view class="item rows ptb20" @click="handleUser(user)">
|
||||||
<image class="wh80 avatar cir" :src="user.avatar" mode="aspectFill" />
|
<image class="wh80 avatar cir" :src="user.avatar" mode="aspectFill" />
|
||||||
<view class="name thd f1 ml20 c333 f32">{{user.remark || user.userNickname}}</view>
|
<view class="name thd f1 ml20 c333 f32">{{ user.remark || user.userNickname }}</view>
|
||||||
</view>
|
</view>
|
||||||
</uni-swipe-action-item>
|
</uni-swipe-action-item>
|
||||||
</view>
|
</view>
|
||||||
|
@ -475,7 +478,7 @@
|
||||||
<uni-popup ref="note" type="bottom" mask-background-color="rgba(0,0,0,0)">
|
<uni-popup ref="note" type="bottom" mask-background-color="rgba(0,0,0,0)">
|
||||||
<view class="noteAlt popBot plr25 bfff">
|
<view class="noteAlt popBot plr25 bfff">
|
||||||
<view class="header rows ptb20">
|
<view class="header rows ptb20">
|
||||||
<view class="title c333 f34">设置好友({{user.remark}})备注</view>
|
<view class="title c333 f34">设置好友({{ user.remark }})备注</view>
|
||||||
<uni-icons type="closeempty" size="40rpx" @click="$refs.note.close()" />
|
<uni-icons type="closeempty" size="40rpx" @click="$refs.note.close()" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
@ -489,47 +492,47 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
// 朋友列表
|
// 朋友列表
|
||||||
.firendBox {
|
.firendBox {
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.scroll {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.scroll {
|
// 列表项
|
||||||
height: 100%;
|
.li {
|
||||||
}
|
.letter {
|
||||||
|
background-color: #eee;
|
||||||
// 列表项
|
|
||||||
.li {
|
|
||||||
.letter {
|
|
||||||
background-color: #eee;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 子集
|
|
||||||
.child {
|
|
||||||
.item+.item {
|
|
||||||
border-top: 2rpx solid #eee;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 字母列表
|
// 子集
|
||||||
.letterBox {
|
.child {
|
||||||
position: absolute;
|
.item+.item {
|
||||||
top: 50%;
|
border-top: 2rpx solid #eee;
|
||||||
right: 0;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置好友备注
|
|
||||||
.noteAlt {
|
|
||||||
box-shadow: 0 0 20rpx #0003;
|
|
||||||
|
|
||||||
.content {
|
|
||||||
.input {
|
|
||||||
padding: 20rpx 20rpx;
|
|
||||||
background-color: #eaeaea;
|
|
||||||
border-radius: 20rpx;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 字母列表
|
||||||
|
.letterBox {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
right: 0;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置好友备注
|
||||||
|
.noteAlt {
|
||||||
|
box-shadow: 0 0 20rpx #0003;
|
||||||
|
|
||||||
|
.content {
|
||||||
|
.input {
|
||||||
|
padding: 20rpx 20rpx;
|
||||||
|
background-color: #eaeaea;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
|
@ -69,7 +69,7 @@ const list = reactive([])
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.type == 0) {
|
if (props.type == 0) {
|
||||||
getList()
|
getList()
|
||||||
} else if(props.type == 1) {
|
} else if (props.type == 1) {
|
||||||
// 视频消息
|
// 视频消息
|
||||||
} else if (props.type == 2) {
|
} else if (props.type == 2) {
|
||||||
// 商城消息
|
// 商城消息
|
||||||
|
@ -79,7 +79,7 @@ onMounted(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
// removeListener()
|
removeListener()
|
||||||
})
|
})
|
||||||
|
|
||||||
// 开启监听消息
|
// 开启监听消息
|
||||||
|
@ -93,7 +93,9 @@ function addListener() {
|
||||||
|
|
||||||
// 移除监听
|
// 移除监听
|
||||||
function removeListener() {
|
function removeListener() {
|
||||||
uni.$chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED);
|
// #ifdef APP
|
||||||
|
uni.$chat.off(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取消息列表
|
// 获取消息列表
|
||||||
|
@ -104,7 +106,8 @@ function getList() {
|
||||||
}
|
}
|
||||||
}).then(rs => {
|
}).then(rs => {
|
||||||
if (rs.code == 200) {
|
if (rs.code == 200) {
|
||||||
list.data = handleList(rs.data);
|
// list.data = handleList(rs.data);
|
||||||
|
list.data = handleList(JSON.parse(rs.msg).SessionItem);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.alert({
|
util.alert({
|
||||||
|
@ -112,17 +115,6 @@ function getList() {
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// // 验证sdk是否准备完毕
|
|
||||||
// let isReady = uni.$chat.isReady();
|
|
||||||
// if (!isReady) {
|
|
||||||
// setTimeout(function () {
|
|
||||||
// getList();
|
|
||||||
// }, 1000);
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// uni.$chat.getMessageList({})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,53 +122,37 @@ function getList() {
|
||||||
* @param {Object} item
|
* @param {Object} item
|
||||||
*/
|
*/
|
||||||
function handleList(list) {
|
function handleList(list) {
|
||||||
list.forEach(item => {
|
|
||||||
item.callbackJson = JSON.parse(item.callbackJson);
|
|
||||||
|
|
||||||
if (item.groupId != null) {
|
|
||||||
item.unreadCount = getGroupNoReadNum(item.groupId)
|
|
||||||
}
|
|
||||||
if (item.callbackJson.callback_json.length) {
|
|
||||||
let msgType = item.callbackJson.callback_json[0].MsgType;
|
|
||||||
if (msgType == TencentCloudChat.TYPES.MSG_TEXT) {
|
|
||||||
item.chatText = item.callbackJson.callback_json[0].MsgContent.Text
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_IMAGE) {
|
|
||||||
item.chatText = '[图片]'
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_AUDIO) {
|
|
||||||
item.chatText = '[语音]'
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_VIDEO) {
|
|
||||||
item.chatText = '[视频]'
|
|
||||||
} else if (msgType == TencentCloudChat.TYPES.MSG_CUSTOM) {
|
|
||||||
if (item.callbackJson.callback_json[0].businessType == 'redPacket') {
|
|
||||||
item.chatText = `[红包] ${item.callbackJson.blessing}`
|
|
||||||
} else if (item.callbackJson.callback_json[0].businessType == '1') {
|
|
||||||
// if (item.callbackJson.callback_json[0].call_type == '1') {
|
|
||||||
// item.chatText = '[语音通话]'
|
|
||||||
// } else if (item.callbackJson.callback_json[0].call_type == '2') {
|
|
||||||
// item.chatText = '[视频通话]'
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询群聊未读数量
|
|
||||||
function getGroupNoReadNum(groupId) {
|
|
||||||
// 验证sdk是否准备完毕
|
// 验证sdk是否准备完毕
|
||||||
let isReady = uni.$chat.isReady();
|
let isReady = uni.$chat.isReady();
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
getGroupNoReadNum(groupId);
|
handleList(list);
|
||||||
}, 800);
|
}, 800);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const unreadCount = uni.$chat.getTotalUnreadMessageCount('GROUP', groupId);
|
list.forEach(item => {
|
||||||
|
item.MsgTime = handleDate(item.MsgTime)
|
||||||
|
|
||||||
return unreadCount;
|
let type = item.Type == 1 ? `C2C${item.To_Account}` : `GROUP${item.GroupId}`;
|
||||||
|
uni.$chat.getConversationProfile(type).then(rs => {
|
||||||
|
let res = rs.data.conversation;
|
||||||
|
|
||||||
|
item.chatText = res.lastMessage.messageForShow;
|
||||||
|
item.unreadCount = res.unreadCount;
|
||||||
|
if (item.Type == 1) {
|
||||||
|
item.avatar = res.userProfile.avatar;
|
||||||
|
item.name = res.userProfile.nick;
|
||||||
|
} else if (item.Type == 2) {
|
||||||
|
item.avatar = res.groupProfile.avatar;
|
||||||
|
item.name = res.groupProfile.name;
|
||||||
|
item.num = res.groupProfile.memberCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 点击用户
|
// // 点击用户
|
||||||
|
@ -204,14 +180,14 @@ function handleChat(item) {
|
||||||
// 单聊
|
// 单聊
|
||||||
if (item.groupId == null) {
|
if (item.groupId == null) {
|
||||||
param.type = 'C2C'
|
param.type = 'C2C'
|
||||||
param.name = `${item.callbackJson.from_name}`
|
param.name = `${item.name}`
|
||||||
param.msgId = `${item.callbackJson.from_id}`
|
param.msgId = `${item.To_Account}`
|
||||||
} else {
|
} else {
|
||||||
// 群聊
|
// 群聊
|
||||||
param.type = 'GROUP'
|
param.type = 'GROUP'
|
||||||
param.name = `${item.groupChatDTO.name}`
|
param.name = `${item.name}`
|
||||||
param.msgId = `${item.groupId}`
|
param.msgId = `${item.GroupId}`
|
||||||
param.num = `${item.groupChatDTO.memberCount}`
|
param.num = `${item.num}`
|
||||||
}
|
}
|
||||||
|
|
||||||
setRead(item)
|
setRead(item)
|
||||||
|
@ -240,7 +216,7 @@ function delMsg(item) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let conversationId = item.groupId == null ? `C2C${item.fromId}` : `GROUP${item.groupId}`;
|
let conversationId = item.Type == 1 ? `C2C${item.To_Account}` : `GROUP${item.GroupId}`;
|
||||||
|
|
||||||
uni.$chat.deleteConversation(conversationId).then(rs => {
|
uni.$chat.deleteConversation(conversationId).then(rs => {
|
||||||
getList()
|
getList()
|
||||||
|
@ -258,7 +234,7 @@ function setRead(item) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let conversationId = item.groupId == null ? `C2C${item.fromId}` : `GROUP${item.groupId}`;
|
let conversationId = item.Type == 1 ? `C2C${item.To_Account}` : `GROUP${item.GroupId}`;
|
||||||
uni.$chat.setMessageRead({
|
uni.$chat.setMessageRead({
|
||||||
conversationID: conversationId,
|
conversationID: conversationId,
|
||||||
}).then(rs => {
|
}).then(rs => {
|
||||||
|
@ -266,6 +242,21 @@ function setRead(item) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 时间转换
|
||||||
|
function handleDate(timestamp) {
|
||||||
|
var timestamp = +timestamp * 1000;
|
||||||
|
var date = new Date(timestamp);
|
||||||
|
|
||||||
|
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
|
||||||
|
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
|
||||||
|
var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
|
||||||
|
var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
|
||||||
|
var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
|
||||||
|
|
||||||
|
var formattedDate = M + D + h + m + s;
|
||||||
|
return formattedDate
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -326,25 +317,28 @@ function setRead(item) {
|
||||||
@click="handleMenu($event, item)">
|
@click="handleMenu($event, item)">
|
||||||
<view class="item rows ptb20 plr30" @click.stop="handleChat(item)">
|
<view class="item rows ptb20 plr30" @click.stop="handleChat(item)">
|
||||||
<view class="image wh90 pr">
|
<view class="image wh90 pr">
|
||||||
<template v-if="item.groupId == null">
|
<!-- <template v-if="item.groupId == null">
|
||||||
<image class="cir wh90" :src="item.callbackJson.from_url" mode="aspectFill" />
|
<image class="cir wh90" :src="item.callbackJson.from_url" mode="aspectFill" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<image class="cir wh90" :src="item.groupChatDTO.groupFaceUrl" mode="aspectFill" />
|
<image class="cir wh90" :src="item.groupChatDTO.groupFaceUrl" mode="aspectFill" />
|
||||||
</template>
|
</template> -->
|
||||||
|
|
||||||
|
<image class="cir wh90" :src="item.avatar" mode="aspectFill" />
|
||||||
<view class="mark pa t0 r0 cfff f22 cir" v-if="item.unreadCount">{{ item.unreadCount }}
|
<view class="mark pa t0 r0 cfff f22 cir" v-if="item.unreadCount">{{ item.unreadCount }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="col f1 ml20">
|
<view class="col f1 ml20">
|
||||||
<view class="rows">
|
<view class="rows">
|
||||||
<template v-if="item.groupId == null">
|
<view class="name f1 thd c333 f32">{{ item.name }}</view>
|
||||||
|
<!-- <template v-if="item.groupId == null">
|
||||||
<view class="name f1 thd c333 f32">{{ item.callbackJson.from_name }}</view>
|
<view class="name f1 thd c333 f32">{{ item.callbackJson.from_name }}</view>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<view class="name f1 thd c333 f32">{{ item.groupChatDTO.name }}</view>
|
<view class="name f1 thd c333 f32">{{ item.groupChatDTO.name }}</view>
|
||||||
</template>
|
</template> -->
|
||||||
<view class="datetime c999 f22">
|
<view class="datetime c999 f22">
|
||||||
{{ util.formatTime('MM-dd HH:mm', item.createTime) }}</view>
|
{{ util.formatTime('MM-dd HH:mm', item.MsgTime) }}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="desc thd mt10 c666 f24">{{ item.chatText }}</view>
|
<view class="desc thd mt10 c666 f24">{{ item.chatText }}</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
|
@ -155,7 +155,9 @@ function addListener() {
|
||||||
}, 200)
|
}, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #ifdef APP
|
||||||
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
|
uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听内容滚动
|
// 监听内容滚动
|
||||||
|
@ -210,6 +212,7 @@ function sendMsg(param) {
|
||||||
data: param.data,
|
data: param.data,
|
||||||
}).then((rs) => {
|
}).then((rs) => {
|
||||||
if (rs.code == 200) {
|
if (rs.code == 200) {
|
||||||
|
getHistory()
|
||||||
param.success ? param.success() : ''
|
param.success ? param.success() : ''
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -310,15 +313,15 @@ function getMoreHistroy() {
|
||||||
*/
|
*/
|
||||||
function getHistory(param = {}) {
|
function getHistory(param = {}) {
|
||||||
// 验证sdk是否准备完毕
|
// 验证sdk是否准备完毕
|
||||||
|
// #ifdef APP
|
||||||
let isReady = uni.$chat.isReady();
|
let isReady = uni.$chat.isReady();
|
||||||
//
|
|
||||||
if (!isReady && userinfo.value.id) {
|
if (!isReady && userinfo.value.id) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
getHistory(param)
|
getHistory()
|
||||||
}, 200);
|
}, 200);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//
|
// #endif
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
// 获取单聊聊天记录
|
// 获取单聊聊天记录
|
||||||
|
|
|
@ -94,7 +94,9 @@ function imLoading() {
|
||||||
|
|
||||||
// 移除监听
|
// 移除监听
|
||||||
function removeListener() {
|
function removeListener() {
|
||||||
|
// #ifdef APP
|
||||||
uni.$chat.off(TencentCloudChat.EVENT.SDK_READY);
|
uni.$chat.off(TencentCloudChat.EVENT.SDK_READY);
|
||||||
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue