Browse Source

提交新代码

master
[yxf] 7 hours ago
parent
commit
e4f70b1f43
  1. 8
      im-uniapp/App.vue
  2. 184
      im-uniapp/pages/chat/chat-box.vue
  3. 4
      im-uniapp/pages/friend/friend.vue
  4. 11
      im-uniapp/pages/login/login.vue
  5. 2
      im-web/src/view/Login.vue

8
im-uniapp/App.vue

@ -45,10 +45,10 @@ export default {
wsApi.onMessage((cmd, msgInfo) => { wsApi.onMessage((cmd, msgInfo) => {
if (cmd == 2) { if (cmd == 2) {
// 线 // 线
uni.showModal({ // uni.showModal({
content: '您已在其他地方登录,将被强制下线', // content: '线',
showCancel: false, // showCancel: false,
}) // })
this.exit(); this.exit();
} else if (cmd == 3) { } else if (cmd == 3) {
if (!this.configStore.appInit || this.chatStore.loading) { if (!this.configStore.appInit || this.chatStore.loading) {

184
im-uniapp/pages/chat/chat-box.vue

@ -126,7 +126,7 @@ import UNI_APP from '@/.env.js';
export default { export default {
data() { data() {
return { return {
chat: {}, // chat: {},
userInfo: {}, userInfo: {},
group: {}, group: {},
groupMembers: [], groupMembers: [],
@ -1001,6 +1001,24 @@ export default {
} }
}, },
computed: { computed: {
chat() {
// store chat
if (!this.chatStore.chats || this.chatStore.chats.length === 0) {
return null;
}
const idx = this.activeChatIdx;
return this.chatStore.chats[idx] || this.chatStore.chats[0];
},
activeChatIdx: {
get() {
return this._activeChatIdx || 0;
},
set(val) {
this._activeChatIdx = val;
}
},
mine() { mine() {
return this.userStore.userInfo; return this.userStore.userInfo;
}, },
@ -1058,10 +1076,10 @@ export default {
return this.groupMembers.filter(m => !m.quit).length; return this.groupMembers.filter(m => !m.quit).length;
}, },
isGroup() { isGroup() {
return this.chat.type == 'GROUP'; return this.chat && this.chat.type == 'GROUP';
}, },
isPrivate() { isPrivate() {
return this.chat.type == 'PRIVATE'; return this.chat && this.chat.type == 'PRIVATE';
}, },
loading() { loading() {
return this.chatStore.loading; return this.chatStore.loading;
@ -1100,50 +1118,122 @@ export default {
} }
} }
}, },
onLoad(options) { async onLoad(options) {
// const chatIdx = options.chatIdx !== undefined ? parseInt(options.chatIdx) : 0;
this.chat = this.chatStore.chats[options.chatIdx];
// 20 //
let size = this.messageSize; uni.showLoading({
this.showMinIdx = size > 20 ? size - 20 : 0; title: '加载中...',
// mask: true
this.readedMessage() });
//
if (this.isGroup) { try {
this.loadGroup(this.chat.targetId); //
} else { let retryCount = 0;
this.loadFriend(this.chat.targetId); const maxRetry = 30; // 3
this.loadReaded(this.chat.targetId)
} // chats
// while ((!this.chatStore.chats || this.chatStore.chats.length === 0) && retryCount < maxRetry) {
this.chatStore.activeChat(options.chatIdx); await new Promise(resolve => setTimeout(resolve, 100));
// retryCount++;
this.isReceipt = false; }
//
this.isInBottom = true; //
this.newMessageSize = 0; if (!this.chatStore.chats || this.chatStore.chats.length === 0) {
// id if (this.chatStore.loadChat) {
this.maxTmpId = 0; await this.chatStore.loadChat();
// }
this.listenKeyBoard(); //
// await new Promise(resolve => setTimeout(resolve, 500));
this.windowHeight = uni.getSystemInfoSync().windowHeight; }
this.screenHeight = uni.getSystemInfoSync().screenHeight;
this.reCalChatMainHeight(); //
this.$nextTick(() => { if (!this.chatStore.chats || this.chatStore.chats.length === 0) {
// windowHeight //
this.windowHeight = uni.getSystemInfoSync().windowHeight; const cached = uni.getStorageSync('chat_chats');
this.reCalChatMainHeight(); if (cached && cached.length > 0) {
this.scrollToBottom(); this.chatStore.chats = cached;
// #ifdef H5 } else {
this.initHeight = window.innerHeight; throw new Error('暂无聊天数据');
// iosh5: }
const chatBox = document.getElementById('chatBox') }
chatBox.addEventListener('touchmove', e => {
e.preventDefault() //
}, { passive: false }); this.chat = this.chatStore.chats[chatIdx] || this.chatStore.chats[0];
// #endif
}); if (!this.chat || !this.chat.targetId) {
throw new Error('会话不存在');
}
uni.hideLoading();
// ...
// 20
let size = this.messageSize;
this.showMinIdx = size > 20 ? size - 20 : 0;
//
this.readedMessage()
//
if (this.isGroup) {
this.loadGroup(this.chat.targetId);
} else {
this.loadFriend(this.chat.targetId);
this.loadReaded(this.chat.targetId)
}
//
this.chatStore.activeChat(chatIdx);
//
this.isReceipt = false;
this.isInBottom = true;
this.newMessageSize = 0;
this.maxTmpId = 0;
//
this.listenKeyBoard();
//
this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.screenHeight = uni.getSystemInfoSync().screenHeight;
this.reCalChatMainHeight();
this.$nextTick(() => {
this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.reCalChatMainHeight();
this.scrollToBottom();
// #ifdef H5
this.initHeight = window.innerHeight;
const chatBox = document.getElementById('chatBox')
if (chatBox) {
chatBox.addEventListener('touchmove', e => {
e.preventDefault()
}, { passive: false });
}
// #endif
});
} catch (error) {
uni.hideLoading();
console.error('进入聊天页面失败:', error);
uni.showToast({
title: error.message || '加载失败,请稍后重试',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({
delta: 1,
fail: () => {
uni.switchTab({
url: "/pages/chat/chat"
});
}
});
}, 1500);
}
}, },
onUnload() { onUnload() {
this.unListenKeyboard(); this.unListenKeyboard();

4
im-uniapp/pages/friend/friend.vue

@ -1,7 +1,7 @@
<template> <template>
<view class="tab-page friend"> <view class="tab-page friend">
<nav-bar add search @add="onAddNewFriends" @search="showSearch = !showSearch">好友</nav-bar> <!-- <nav-bar add search @add="onAddNewFriends" @search="showSearch = !showSearch">好友</nav-bar>
<view class="nav-bar" v-if="showSearch"> <view class="nav-bar" v-if="showSearch">
<view class="nav-search"> <view class="nav-search">
<uni-search-bar v-model="searchText" radius="100" cancelButton="none" <uni-search-bar v-model="searchText" radius="100" cancelButton="none"
@ -27,7 +27,7 @@
</up-index-item> </up-index-item>
</template> </template>
</up-index-list> </up-index-list>
</view> </view> -->
</view> </view>
</template> </template>

11
im-uniapp/pages/login/login.vue

@ -87,14 +87,17 @@ export default {
url: 'https://api.ipify.org?format=json', url: 'https://api.ipify.org?format=json',
method: 'GET', method: 'GET',
success: (res) => { success: (res) => {
console.log("获取IP成功:", res.data); // console.log("IP", res.data);
this.dataForm.ip = res.data.ip; this.dataForm.ip = res.data.ip;
console.log("登录参数:", this.dataForm); // console.log("", this.dataForm);
resolve(res.data.ip); // Promise resolve(res.data.ip); // Promise
}, },
fail: (err) => { fail: (err) => {
console.log("获取IP失败:", err); // console.log("IP", err);
reject(err); // Promise // IPip
this.dataForm.ip = '';
// console.log("", this.dataForm);
resolve(''); // Promise
} }
}); });
}); });

2
im-web/src/view/Login.vue

@ -78,7 +78,7 @@ export default {
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
this.$http({ this.$http({
url: "/login", url: "/loginCustom",
method: 'post', method: 'post',
data: this.loginForm data: this.loginForm
}) })

Loading…
Cancel
Save