im模块增加

This commit is contained in:
唐明明
2023-03-24 10:06:59 +08:00
parent d43fbd22fd
commit 7508bb7ce2
10 changed files with 182 additions and 31 deletions

View File

@@ -10,8 +10,8 @@ import router from '../router'
// 基础配置
const config = {
apiUrl : 'https://douhuo.douhuofalv.com/api/',
// apiUrl : 'https://api.douhuotest.douhuofalv.com/api/', //测试环境
// apiUrl : 'https://douhuo.douhuofalv.com/api/',
apiUrl : 'https://api.douhuotest.douhuofalv.com/api/', //测试环境
timeout : 60000
}

20
apis/interfaces/yxim.js Normal file
View File

@@ -0,0 +1,20 @@
/**
* Web唐明明
* 匆匆数载恍如梦,岁月迢迢华发增。
* 碌碌无为枉半生,一朝惊醒万事空。
* moduleName: 网易云信IM
*/
import { request } from '../index'
// 获取im登录
const imToken = data => {
return request({
url : 'im/token'
})
}
export {
imToken
}

58
im/INIT.js Normal file
View File

@@ -0,0 +1,58 @@
import Vue from 'vue'
import store from '@/store';
import NIMSDK from 'nim-web-sdk-ng/dist/NIM_UNIAPP_SDK'
import { imToken } from '@/apis/interfaces/yxim.js'
export const INIT = async () => {
let APPKEY = ''
let TOKEN = ''
let UID = ''
if( store.getters.getToken == '' || uni.getStorageSync('token') == '' ){
return '用户未登录'
}
await imToken().then(res => {
let { app_key, token, uid } = res;
APPKEY = app_key
TOKEN = token
UID = uid
}).catch(err => {
uni.showToast({
title: 'IM INIT ERR' + err.code,
icon : 'none'
})
})
const yxim = new NIMSDK({
appkey : APPKEY,
account : UID,
token : TOKEN,
debugLevel : 'debug',
needReconnect : true,
reconnectionAttempts: 5
})
// 注册监听事件
const eventList = [
'logined',
'kicked',
'willReconnect',
'disconnect',
'msg',
'syncdone',
]
eventList.forEach(key => {
yxim.on(key, res => {
console.log(`{$key}:`, res ? JSON.parse(JSON.stringify(res)): res)
})
})
await yxim.connect();
// 挂载全局变量方法
Vue.prototype.$nim = yxim;
}

22
main.js
View File

@@ -7,16 +7,20 @@ import store from './store'
import { router, RouterMount } from 'router'
import Mylink from './node_modules/uni-simple-router/dist/link.vue'
Vue.component('my-link', Mylink)
import { INIT } from './im/INIT'
Vue.use(uView)
Vue.use(router)
(async () => {
Vue.component('my-link', Mylink)
Vue.use(uView)
Vue.use(router)
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
await INIT();
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()
})
app.$mount()
})()

51
package-lock.json generated
View File

@@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"moment": "^2.29.4",
"nim-web-sdk-ng": "^0.12.3",
"uni-read-pages": "^1.0.5",
"uni-simple-router": "^2.0.7",
"uview-ui": "^2.0.31",
@@ -164,6 +165,16 @@
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"peer": true
},
"node_modules/eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="
},
"node_modules/magic-string": {
"version": "0.25.9",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz",
@@ -192,11 +203,26 @@
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/nim-web-sdk-ng": {
"version": "0.12.3",
"resolved": "https://registry.npmjs.org/nim-web-sdk-ng/-/nim-web-sdk-ng-0.12.3.tgz",
"integrity": "sha512-S1RYQDz5n/tCqdHVv5fIBKBB60hdvySLTLo1xSgPVrk725GrGSXXyblWZeaWazUoFuLzfSKyrK0LRCJoAMcHYw==",
"dependencies": {
"eventemitter3": "^4.0.7",
"lodash-es": "^4.17.21",
"platform": "^1.3.6"
}
},
"node_modules/picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
},
"node_modules/platform": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz",
"integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
},
"node_modules/postcss": {
"version": "8.4.20",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz",
@@ -457,6 +483,16 @@
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"peer": true
},
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="
},
"magic-string": {
"version": "0.25.9",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz",
@@ -476,11 +512,26 @@
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz",
"integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw=="
},
"nim-web-sdk-ng": {
"version": "0.12.3",
"resolved": "https://registry.npmjs.org/nim-web-sdk-ng/-/nim-web-sdk-ng-0.12.3.tgz",
"integrity": "sha512-S1RYQDz5n/tCqdHVv5fIBKBB60hdvySLTLo1xSgPVrk725GrGSXXyblWZeaWazUoFuLzfSKyrK0LRCJoAMcHYw==",
"requires": {
"eventemitter3": "^4.0.7",
"lodash-es": "^4.17.21",
"platform": "^1.3.6"
}
},
"picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
},
"platform": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz",
"integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
},
"postcss": {
"version": "8.4.20",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz",

View File

@@ -1,6 +1,7 @@
{
"dependencies": {
"moment": "^2.29.4",
"nim-web-sdk-ng": "^0.12.3",
"uni-read-pages": "^1.0.5",
"uni-simple-router": "^2.0.7",
"uview-ui": "^2.0.31",

View File

@@ -599,6 +599,11 @@
"selectedIconPath": "static/icons/tabs_show_02.png",
"pagePath": "pages/work/index",
"text": "工作台"
},{
"iconPath": "static/icons/tabs_icon_04.png",
"selectedIconPath": "static/icons/tabs_icon_04.png",
"pagePath": "pages/im/msg",
"text": "消息"
}, {
"iconPath": "static/icons/tabs_icon_03.png",
"selectedIconPath": "static/icons/tabs_show_03.png",

View File

@@ -3,23 +3,6 @@
<list>
<cell v-for="(item, index) in 99" :key="index">消息{{index}}</cell>
</list>
<!-- <view class="chat-soll">
<view v-for="(item, index) in 50" :key="index">{{item}}滚动的聊天记录</view>
</view>
<view class="chat-footer">
<view class="chat-inputs">
<view class="chat-icon">
<image src="@/static/im/icon_01.png" mode="widthFix"></image>
</view>
<input class="chat-input" type="text" placeholder="输入框" confirm-type="send">
<view class="chat-icon">
<image src="@/static/im/icon_02.png" mode="widthFix"></image>
</view>
<view class="chat-icon">
<image src="@/static/im/icon_00.png" mode="widthFix"></image>
</view>
</view>
</view> -->
</view>
</template>

View File

@@ -58,6 +58,11 @@
}
}
},
onShow() {
console.log()
// this.$nim.msg()
},
methods: {
onMsg(id){
let cartId = id || null

View File

@@ -131,6 +131,16 @@
"resolved" "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz"
"version" "2.0.2"
"eventemitter3@^4.0.7":
"integrity" "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
"resolved" "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz"
"version" "4.0.7"
"lodash-es@^4.17.21":
"integrity" "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="
"resolved" "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz"
"version" "4.17.21"
"magic-string@^0.25.7":
"integrity" "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ=="
"resolved" "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz"
@@ -148,11 +158,25 @@
"resolved" "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz"
"version" "3.3.4"
"nim-web-sdk-ng@^0.12.3":
"integrity" "sha512-S1RYQDz5n/tCqdHVv5fIBKBB60hdvySLTLo1xSgPVrk725GrGSXXyblWZeaWazUoFuLzfSKyrK0LRCJoAMcHYw=="
"resolved" "https://registry.npmjs.org/nim-web-sdk-ng/-/nim-web-sdk-ng-0.12.3.tgz"
"version" "0.12.3"
dependencies:
"eventemitter3" "^4.0.7"
"lodash-es" "^4.17.21"
"platform" "^1.3.6"
"picocolors@^1.0.0":
"integrity" "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
"resolved" "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz"
"version" "1.0.0"
"platform@^1.3.6":
"integrity" "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
"resolved" "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz"
"version" "1.3.6"
"postcss@^8.1.10", "postcss@^8.4.14":
"integrity" "sha512-6Q04AXR1212bXr5fh03u8aAwbLxAQNGQ/Q1LNa0VfOI06ZAlhPHtQvE4OIdpj4kLThXilalPnmDSOD65DcHt+g=="
"resolved" "https://registry.npmjs.org/postcss/-/postcss-8.4.20.tgz"