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) => {
if (cmd == 2) {
// 线
uni.showModal({
content: '您已在其他地方登录,将被强制下线',
showCancel: false,
})
// uni.showModal({
// content: '线',
// showCancel: false,
// })
this.exit();
} else if (cmd == 3) {
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 {
data() {
return {
chat: {},
// chat: {},
userInfo: {},
group: {},
groupMembers: [],
@ -1001,6 +1001,24 @@ export default {
}
},
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() {
return this.userStore.userInfo;
},
@ -1058,10 +1076,10 @@ export default {
return this.groupMembers.filter(m => !m.quit).length;
},
isGroup() {
return this.chat.type == 'GROUP';
return this.chat && this.chat.type == 'GROUP';
},
isPrivate() {
return this.chat.type == 'PRIVATE';
return this.chat && this.chat.type == 'PRIVATE';
},
loading() {
return this.chatStore.loading;
@ -1100,50 +1118,122 @@ export default {
}
}
},
onLoad(options) {
//
this.chat = this.chatStore.chats[options.chatIdx];
// 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(options.chatIdx);
//
this.isReceipt = false;
//
this.isInBottom = true;
this.newMessageSize = 0;
// id
this.maxTmpId = 0;
//
this.listenKeyBoard();
//
this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.screenHeight = uni.getSystemInfoSync().screenHeight;
this.reCalChatMainHeight();
this.$nextTick(() => {
// windowHeight
this.windowHeight = uni.getSystemInfoSync().windowHeight;
this.reCalChatMainHeight();
this.scrollToBottom();
// #ifdef H5
this.initHeight = window.innerHeight;
// iosh5:
const chatBox = document.getElementById('chatBox')
chatBox.addEventListener('touchmove', e => {
e.preventDefault()
}, { passive: false });
// #endif
});
async onLoad(options) {
const chatIdx = options.chatIdx !== undefined ? parseInt(options.chatIdx) : 0;
//
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
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() {
this.unListenKeyboard();

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

@ -1,7 +1,7 @@
<template>
<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-search">
<uni-search-bar v-model="searchText" radius="100" cancelButton="none"
@ -27,7 +27,7 @@
</up-index-item>
</template>
</up-index-list>
</view>
</view> -->
</view>
</template>

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

@ -87,14 +87,17 @@ export default {
url: 'https://api.ipify.org?format=json',
method: 'GET',
success: (res) => {
console.log("获取IP成功:", res.data);
// console.log("IP", res.data);
this.dataForm.ip = res.data.ip;
console.log("登录参数:", this.dataForm);
// console.log("", this.dataForm);
resolve(res.data.ip); // Promise
},
fail: (err) => {
console.log("获取IP失败:", err);
reject(err); // Promise
// console.log("IP", err);
// 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) => {
if (valid) {
this.$http({
url: "/login",
url: "/loginCustom",
method: 'post',
data: this.loginForm
})

Loading…
Cancel
Save