客户端消息发送

This commit is contained in:
2023-09-25 19:15:47 +08:00
parent daa9c98598
commit 161631f6a0
22 changed files with 153 additions and 359 deletions

View File

@@ -0,0 +1,8 @@
export default class config{
static getImApiUrl(){
return process.env.NODE_ENV === 'development' ? 'http://127.0.0.1:28000/v1' :'http://www.shudong.xyz/shudong_api/';
}
static getImAppId(){
return 10000;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -30,9 +30,9 @@ Vue.prototype.$pinyin = pinyin;
// #ifdef H5
Vue.prototype.$socketTask = socketTask;
uni.lim = lim;
// uni.lim = lim;
Vue.prototype.imsdk = lim
// Vue.prototype.imsdk = lim
// #endif
@@ -58,7 +58,8 @@ export function createApp() {
// #ifdef H5
app.config.globalProperties.$socketTask = socketTask
app.config.globalProperties.imsdk = imsdk
app.config.globalProperties.imsdk = lim
// #endif
app.use(store);
return {

View File

@@ -49,6 +49,8 @@ let observer = null;
import favorites from '../favorites/index.vue';
import chatItem from './chat-item.vue';
import sendCard from './sendCard.vue';
export default {
components: {
chatItem,
@@ -627,18 +629,26 @@ export default {
if (!e) {
return;
}
this.$fc.pushOutMsg({
/*
this.$fc.pushOutMsg({
msgContent: e,
msgType: msgType,
windowType: this.talkTo.windowType,
userId: this.talkTo.userId
});
this.msg = '';
this.msg = '';
*/
// #ifdef H5
this.msgFocus = false;
this.$nextTick(() => {
this.msgFocus = true;
});
console.log("==============sdk:")
console.log(this.talkTo.userId)
this.imsdk.lim.im.sendP2PMessage(this.imsdk.lim.im.createP2PTextMessage(this.talkTo.userId, e))
// #endif
},
startRecognize() {

View File

@@ -229,14 +229,7 @@
url: '../tabbar1/index'
})
return;
// #ifdef H5
this.$socketTask.connectSocket()
// #endif
this.$store.dispatch('get_UserInfo').then(res => {
})
}
}

View File

@@ -21,6 +21,10 @@
</template>
<script>
import config from "@/common/config.js"
const ListenerMap = {
onSocketConnectEvent: (option, status, data) => {
console.log("已建立连接:" + JSON.stringify(status));
@@ -189,19 +193,33 @@
console.log(this.imsdk)
//app服务登录成功去登录im
const lim = this.imsdk
const sdk = lim.im;
var listeners = {};
for (const v in ListenerMap) {
listeners[v] = ListenerMap[v];
}
sdk.init("http://127.0.0.1:28000/v1","10000", "18200702230", "asdasdsd", listeners, function(
const userId=uni.getStorageSync("userId")
const imUserSign=uni.getStorageSync("imUserSign")
console.log(this.imsdk)
this.imsdk.lim.im.init(config.getImApiUrl(),config.getImAppId(),userId,imUserSign, listeners, function(
sdk) {
if (sdk) {
console.log('sdk 成功连接的回调, 可以使用 sdk 请求数据了.');
sdk.getAllFriend().then(res=>{
console.warn(res)
})
sdk.getUserSequence().then(res=>{
console.warn(res)
})
sdk.getUserConversationList(0).then(res=>{
console.warn(res)
})
return uni.switchTab({
url: "/pages/tabbar/index/index"
})
@@ -210,6 +228,7 @@
}
})
},
methods: {
longpressItem(e, i, v) {

View File

@@ -20,11 +20,43 @@
},
methods: {
bindClick(e){
//注释之前的旧代码,直接跳转到里聊天页
/*
uni.navigateTo({
url:'../personInfo/detail?param='+e.item.data.userId
})
})
*/
uni.navigateTo({
url: '../chatWindow/index?userId=' + e.item.data.userId + '&windowType=' + e.windowType
});
},
getflist(){
//TODO 从接口获取
var list=[
{
name:"测试18200702230",
avatar:"item.portrait",
userId:"18200702230",
userType:"item.userType",
chatNo:"item.chatNo"
},
{
name:"测试18200000000",
avatar:"item.portrait",
userId:"18200000000",
userType:"item.userType",
chatNo:"item.chatNo"
},{
name:"测试18200000001",
avatar:"item.portrait",
userId:"18200000001",
userType:"item.userType",
chatNo:"item.chatNo"
}
]
this.list=this.$fc.sortList({list:list,key:'name'})
this.$http.request({
url: '/friend/friendList',
method: 'POST',