63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
|
|
import { ref, computed } from 'vue'
|
||
|
|
import { onShow, onUnload } from '@dcloudio/uni-app'
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 简单的群聊hook
|
||
|
|
* @param {string} groupID 群组ID
|
||
|
|
*/
|
||
|
|
export default function useGroupChat(groupID) {
|
||
|
|
const groupInfo = ref({})
|
||
|
|
const members = ref([])
|
||
|
|
|
||
|
|
// 群聊成员映射
|
||
|
|
const chatMember = computed(() => {
|
||
|
|
const res = {}
|
||
|
|
members.value.forEach(member => {
|
||
|
|
res[member.id] = {
|
||
|
|
name: member.name,
|
||
|
|
avatar: member.avatar || '/static/default-avatar.png'
|
||
|
|
}
|
||
|
|
})
|
||
|
|
return res
|
||
|
|
})
|
||
|
|
|
||
|
|
// 获取群聊信息
|
||
|
|
async function getGroupInfo() {
|
||
|
|
const gid = typeof groupID === 'string' ? groupID : groupID.value
|
||
|
|
if (!gid) return
|
||
|
|
|
||
|
|
try {
|
||
|
|
// 这里可以调用API获取群聊信息
|
||
|
|
// const res = await getGroupDetail(gid)
|
||
|
|
// if (res && res.success) {
|
||
|
|
// groupInfo.value = res.data
|
||
|
|
// members.value = res.data.members || []
|
||
|
|
// }
|
||
|
|
|
||
|
|
// 暂时使用本地数据
|
||
|
|
groupInfo.value = {
|
||
|
|
groupID: gid,
|
||
|
|
name: '群聊',
|
||
|
|
status: 'active'
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
console.error('获取群聊信息失败:', error)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
onShow(() => {
|
||
|
|
getGroupInfo()
|
||
|
|
})
|
||
|
|
|
||
|
|
onUnload(() => {
|
||
|
|
// 清理资源
|
||
|
|
})
|
||
|
|
|
||
|
|
return {
|
||
|
|
groupInfo,
|
||
|
|
members,
|
||
|
|
chatMember,
|
||
|
|
getGroupInfo
|
||
|
|
}
|
||
|
|
}
|