Browse Source

提交新代码

master
[yxf] 9 hours ago
parent
commit
e4f70b1f43
  1. 8
      im-uniapp/App.vue
  2. 112
      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) {

112
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,14 +1118,63 @@ export default {
} }
} }
}, },
onLoad(options) { async onLoad(options) {
// const chatIdx = options.chatIdx !== undefined ? parseInt(options.chatIdx) : 0;
this.chat = this.chatStore.chats[options.chatIdx];
//
uni.showLoading({
title: '加载中...',
mask: true
});
try {
//
let retryCount = 0;
const maxRetry = 30; // 3
// chats
while ((!this.chatStore.chats || this.chatStore.chats.length === 0) && retryCount < maxRetry) {
await new Promise(resolve => setTimeout(resolve, 100));
retryCount++;
}
//
if (!this.chatStore.chats || this.chatStore.chats.length === 0) {
if (this.chatStore.loadChat) {
await this.chatStore.loadChat();
}
//
await new Promise(resolve => setTimeout(resolve, 500));
}
//
if (!this.chatStore.chats || this.chatStore.chats.length === 0) {
//
const cached = uni.getStorageSync('chat_chats');
if (cached && cached.length > 0) {
this.chatStore.chats = cached;
} else {
throw new Error('暂无聊天数据');
}
}
//
this.chat = this.chatStore.chats[chatIdx] || this.chatStore.chats[0];
if (!this.chat || !this.chat.targetId) {
throw new Error('会话不存在');
}
uni.hideLoading();
// ...
// 20 // 20
let size = this.messageSize; let size = this.messageSize;
this.showMinIdx = size > 20 ? size - 20 : 0; this.showMinIdx = size > 20 ? size - 20 : 0;
// //
this.readedMessage() this.readedMessage()
// //
if (this.isGroup) { if (this.isGroup) {
this.loadGroup(this.chat.targetId); this.loadGroup(this.chat.targetId);
@ -1115,35 +1182,58 @@ export default {
this.loadFriend(this.chat.targetId); this.loadFriend(this.chat.targetId);
this.loadReaded(this.chat.targetId) this.loadReaded(this.chat.targetId)
} }
// //
this.chatStore.activeChat(options.chatIdx); this.chatStore.activeChat(chatIdx);
// //
this.isReceipt = false; this.isReceipt = false;
//
this.isInBottom = true; this.isInBottom = true;
this.newMessageSize = 0; this.newMessageSize = 0;
// id
this.maxTmpId = 0; this.maxTmpId = 0;
// //
this.listenKeyBoard(); this.listenKeyBoard();
// //
this.windowHeight = uni.getSystemInfoSync().windowHeight; this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.screenHeight = uni.getSystemInfoSync().screenHeight; this.screenHeight = uni.getSystemInfoSync().screenHeight;
this.reCalChatMainHeight(); this.reCalChatMainHeight();
this.$nextTick(() => { this.$nextTick(() => {
// windowHeight
this.windowHeight = uni.getSystemInfoSync().windowHeight; this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.reCalChatMainHeight(); this.reCalChatMainHeight();
this.scrollToBottom(); this.scrollToBottom();
// #ifdef H5 // #ifdef H5
this.initHeight = window.innerHeight; this.initHeight = window.innerHeight;
// iosh5:
const chatBox = document.getElementById('chatBox') const chatBox = document.getElementById('chatBox')
if (chatBox) {
chatBox.addEventListener('touchmove', e => { chatBox.addEventListener('touchmove', e => {
e.preventDefault() e.preventDefault()
}, { passive: false }); }, { passive: false });
}
// #endif // #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