本地开发

This commit is contained in:
2023-11-16 10:52:39 +08:00
parent 75000d846b
commit 9a57e4aaab
18 changed files with 700 additions and 484 deletions

View File

@@ -15,107 +15,29 @@
export default {
onLaunch: function() {
localStorage.setItem("appId",10000)
appInit(500).then((res)=>{
console.log("获取到token创建长链接")
this.$store.dispatch('getAddressList');
setTimeout(()=>{
this.$socketTask.connectSocket()
},2500)
uni.setStorageSync("initReady",1)
},1000)
}).then((error)=>{
console.log("未获取到IM的token")
console.log(error)
})
// #ifdef H5
console.log(
`%c 考拉Team ${name} %c v${version} `,
'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff',
'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0; color: #fff; font-weight: bold;'
)
console.log(consoleImgs.fz)
// todo 下列两行
uni.setStorageSync('device', 'H5');
uni.setStorageSync('version', versionName);
// #endif
console.log('App Launch')
let token= uni.getStorageSync('imUserSign');
if (!token) {
//不存在则跳转至登录页
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen();
// #endif
} else {
// #ifdef H5
this.$socketTask.connectSocket()
// #endif
this.$store.dispatch('get_UserInfo').then(res=>{
// #ifdef APP-PLUS
var nickName=res.nickName
var portrait=res.portrait
this.$http.request({
url: '/trtc/getSign',
success: (res) => {
var sdkAppID=res.data.data.appId
var userID=res.data.data.userId
var userSig=res.data.data.sign
TUICalling.login({//登录音视频
sdkAppID: sdkAppID,
userID: userID,
userSig: userSig
},(res) => {
console.log('音视频登录成功')
TUICalling.setUserNickname({
nickName: nickName
})
TUICalling.setUserAvatar({
avatar: portrait
})
plus.io.requestFileSystem(plus.io.PRIVATE_WWW, function(fs) {
fs.root.getFile('/static/longcall.mp3', {
create: false
}, function(fileEntry) {
fileEntry.file(function(file) {
TUICalling.setCallingBell({
ringtone: file.fullPath
},(res) => {
console.log(JSON.stringify(res))
})
});
});
});
})
}
});
var nowCid=plus.push.getClientInfo().clientid
this.$http.request({
url: '/my/bindCid/'+nowCid,
success: (res) => {
console.log('新cid'+nowCid)
uni.setStorageSync('cid', nowCid);
}
});
// #endif
})
uni.reLaunch({
url: "wx/tabbar1/index",
}).then(res=>{
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen();
// #endif
})
}
// #ifdef APP-PLUS
uni.onNetworkStatusChange( (res)=> {
if(res.isConnected){
this.$store.dispatch('get_UserInfo')
}
});
// #endif
},
onShow: function() {
console.log('App Show')
uni.getStorage({
key: 'call',
success: (res) => {

View File

@@ -11,6 +11,7 @@ export default class config{
}
}
}
static getBaseApiUrl(){
//return process.env.NODE_ENV === 'development' ? 'http://119.45.242.222:8989' :'http://172.16.2.3:8989';
return process.env.NODE_ENV === 'development' ? 'http://119.45.242.222:8989' :'/base_api';
@@ -22,14 +23,14 @@ export default class config{
static getImAppId(){
return 10000;
}
static getVideoRoomUrl(room,userid,isPublish=0,isPlayer=1){
static getVideoRoomUrl(room,userid,isPublish=0,isPlayer=1,hasVideo=1){
if(process.env.NODE_ENV === 'development' ){
return `http://localhost:8080/hd-glasses-app/#/call_room?showInviteConfirmDialog=1&isPublish=${isPublish}&isPlayer=${isPlayer}&uid=${userid}&room=${room}`
return `http://localhost:8080/hd-glasses-app/#/call_room?showInviteConfirmDialog=1&isPublish=${isPublish}&isPlayer=${isPlayer}&uid=${userid}&room=${room}&hasVideo=${hasVideo}`
}else{
if(this.prod=="online"){
return `https://119.45.242.222/hd-glasses-app/#/call_room?showInviteConfirmDialog=1&isPublish=${isPublish}&isPlayer=${isPlayer}&uid=${userid}&room=${room}`
return `https://119.45.242.222/hd-glasses-app/#/call_room?showInviteConfirmDialog=1&isPublish=${isPublish}&isPlayer=${isPlayer}&uid=${userid}&room=${room}&hasVideo=${hasVideo}`
}else{
return `https://172.16.3.19/hd-glasses-app/#/call_room?showInviteConfirmDialog=1&isPublish=${isPublish}&isPlayer=${isPlayer}&uid=${userid}&room=${room}`
return `https://172.16.3.19/hd-glasses-app/#/call_room?showInviteConfirmDialog=1&isPublish=${isPublish}&isPlayer=${isPlayer}&uid=${userid}&room=${room}&hasVideo=${hasVideo}`
}
}
}

View File

@@ -73,6 +73,7 @@ export default {
const userId = uni.getStorageSync("userId")
const imUserSign = uni.getStorageSync("imUserSign")
var listeners = {};
@@ -95,6 +96,16 @@ export default {
console.log(this.socketTask)
console.log('sdk 成功连接的回调, 可以使用 sdk 请求数据了.');
sdk.getSingleUserInfo(userId).then(res=>{
console.log("获取到自己的用户信息")
console.log(res)
if(res.code==200){
uni.setStorageSync('userInfo', res.data);
}
})
// sdk.getAllFriend().then(res => {
// console.warn(res)
// })
@@ -106,9 +117,7 @@ export default {
console.warn(res)
})
return uni.switchTab({
url: "/pages/tabbar/index/index"
})
} else {
console.log('sdk 初始化失败.');
}

View File

@@ -1,22 +1,3 @@
/**
* getUrlKey 截取地址栏参数
* @param value
* @returns {String}
*/
export function getUrlParam(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
let url = window.location.href.split('#')[0];
let search = url.split('?')[1];
console.log(search);
if (search) {
var r = search.substr(0).match(reg);
if (r !== null) {
return unescape(r[2]);
}
return null;
} else return null;
}
export function appInit(ms) {
return new Promise((resolve, reject) => {
@@ -26,6 +7,7 @@ export function appInit(ms) {
var hd_userId = uni.getStorageSync("hd_userid")
if(hd_userId){
uni.setStorageSync("userId",hd_userId)
}else{
console.log("============未获取到hd_userid")
}
@@ -46,9 +28,29 @@ export function appInit(ms) {
resolve("ok")
}
}
}else{
uni.setStorageSync("initReady",null)
}
}, ms);
})
}
/**
* getUrlKey 截取地址栏参数
* @param value
* @returns {String}
*/
export function getUrlParam(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
let url = window.location.href
let search = url.split('?')[1];
console.log(search);
if (search) {
var r = search.substr(0).match(reg);
if (r !== null) {
return unescape(r[2]);
}
return null;
} else return null;
}

View File

@@ -436,56 +436,74 @@
}
});
},
sendVideoCall() {
sendVideoCall(hasVideo = 1) {
//发起视频
uni.showLoading({
title: '发起视频通话'
title: '发起通话'
});
var formdata = {
userId: this.talkTo.userId,
msgType: 'TRTC_VIDEO_START',
content: 'TRTC_VIDEO_START'
};
// this.sendMsg(formdata,formdata.msgType)
var formdata = null;
const userId=localStorage.getItem("userId")
const roomId=userId
const roomInfo={
roomId:userId,//后面改成发起人的手机号或者id
roomName:`${userId}发起的视频聊天`,
creatorId:userId,
creatorName:userId,
publishId:userId,
publishName:userId,
isOver:0,
webrtcUrl:config.getSRSUrl()+`/${roomId}/${userId}`,
type:"webrtc",
offline:0,
invitedUserList:[this.talkTo.userId]
if (hasVideo == 1) {
formdata = {
userId: this.talkTo.userId,
msgType: 'TRTC_VIDEO_START',
content: 'TRTC_VIDEO_START'
}
} else if (hasVideo == 0) {
formdata = {
userId: this.talkTo.userId,
msgType: 'TRTC_VOICE_START',
content: 'TRTC_VOICE_START'
}
}
// this.sendMsg(formdata,formdata.msgType)
const userId = localStorage.getItem("userId")
const roomId = userId
const userInfo = uni.getStorageSync("userInfo")
const roomInfo = {
roomId: userId, //后面改成发起人的手机号或者id
roomName: `${userInfo.nickName}发起的视频聊天`,
creatorId: userId,
creatorName: userInfo.nickName,
publishId: userId,
publishName: userInfo.nickName,
isOver: 0,
webrtcUrl: config.getSRSUrl() + `/${roomId}/${userId}`,
type: "webrtc",
offline: 0,
invitedUserList: [this.talkTo.userId],
hasVideo:hasVideo,
isForce:0
}
this.$store
.dispatch('createRoom', roomInfo)
.then(res => {
customHttp.customHttp.post("/api/im/app/wsMsg",{
msgType:"10000",
msgId:JSON.stringify(roomInfo),
cmd:"",
msgTxt:""
},{
customHttp.customHttp.post("/api/im/app/wsMsg", {
msgType: "10000",
msgId: JSON.stringify(roomInfo),
cmd: "",
msgTxt: ""
}, {
dataType: 'json',
custom: {target: "znzq"} ,
}).then((res1)=>{
location.href=config.getVideoRoomUrl(roomInfo.roomId,roomInfo.creatorId,1,1)
custom: {
target: "znzq"
},
}).then((res1) => {
location.href = config.getVideoRoomUrl(roomInfo.roomId, roomInfo.creatorId, 1, 1,hasVideo)
})
})
if(1>0){
return false;
}
this.$http.request({
if (1 > 0) {
return false;
}
this.$http.request({
url: '/chat/sendMsg',
method: 'POST',
data: JSON.stringify(formdata),
@@ -540,22 +558,21 @@
this.open();
break;
case '音视频':
this.sendVideoCall();
// uni.showActionSheet({
// itemList: ['视频通话', '语音通话'],
// success: res => {
// switch (res.tapIndex) {
// case 0:
// this.sendVideoCall();
// break;
// case 1:
// this.sendVoiceCall();
// break;
// default:
// break;
// }
// }
// });
uni.showActionSheet({
itemList: ['视频通话', '语音通话'],
success: res => {
switch (res.tapIndex) {
case 0:
this.sendVideoCall(1);
break;
case 1:
this.sendVideoCall(0);
break;
default:
break;
}
}
});
break;
case '收藏':
this.openpopup('popupfavorites');
@@ -703,44 +720,46 @@
function sendPhoto(filePath) {
//TODO
//发送图片
customHttp.upload(config.getImApiUrl() + '/file/upload', {
params: {}, /* 会加在url上 */
// #ifdef APP-PLUS || H5
files: [], // 需要上传的文件列表。使用 files 时filePath 和 name 不生效。App、H5 2.6.15+
// #endif
// #ifdef MP-ALIPAY
fileType: 'image/video/audio', // 仅支付宝小程序,且必填。
// #endif
filePath: filePath, // 要上传文件资源的路径。
// 注如果局部custom与全局custom有同名属性则后面的属性会覆盖前面的属性相当于Object.assign(全局,局部)
name: 'file', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
// #ifdef H5 || APP-PLUS
timeout: 60000, // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)
// #endif
header: {}, /* 会与全局header合并如有同名属性局部覆盖全局 */
formData: {}, // HTTP 请求中其他额外的 form data
// 返回当前请求的task, options。请勿在此处修改options。非必填
getTask: (task, options) => {
// task.onProgressUpdate((res) => {
// console.log('上传进度' + res.progress);
// console.log('已经上传的数据长度' + res.totalBytesSent);
// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
//
// // 测试条件,取消上传任务。
// if (res.progress > 50) {
// uploadTask.abort();
// }
// });
},
//validateStatus: (statusCode) => { // statusCode 必存在。此处示例为全局默认配置。演示,非必填选项
// return statusCode >= 200 && statusCode < 300
//}
}).then(res => {
// 返回的res.data 已经进行JSON.parse
}).catch(err => {
})
customHttp.upload(config.getImApiUrl() + '/file/upload', {
params: {},
/* 会加在url上 */
// #ifdef APP-PLUS || H5
files: [], // 需要上传的文件列表。使用 files 时filePath 和 name 不生效。App、H5 2.6.15+
// #endif
// #ifdef MP-ALIPAY
fileType: 'image/video/audio', // 仅支付宝小程序,且必填。
// #endif
filePath: filePath, // 要上传文件资源的路径。
// 注如果局部custom与全局custom有同名属性则后面的属性会覆盖前面的属性相当于Object.assign(全局,局部)
name: 'file', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
// #ifdef H5 || APP-PLUS
timeout: 60000, // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)
// #endif
header: {},
/* 会与全局header合并如有同名属性局部覆盖全局 */
formData: {}, // HTTP 请求中其他额外的 form data
// 返回当前请求的task, options。请勿在此处修改options。非必填
getTask: (task, options) => {
// task.onProgressUpdate((res) => {
// console.log('上传进度' + res.progress);
// console.log('已经上传的数据长度' + res.totalBytesSent);
// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
//
// // 测试条件,取消上传任务。
// if (res.progress > 50) {
// uploadTask.abort();
// }
// });
},
//validateStatus: (statusCode) => { // statusCode 必存在。此处示例为全局默认配置。演示,非必填选项
// return statusCode >= 200 && statusCode < 300
//}
}).then(res => {
// 返回的res.data 已经进行JSON.parse
}).catch(err => {
})
_this.$http.uploadFile({
url: config.getImApiUrl() + '/file/upload',
filePath: filePath,
@@ -787,8 +806,8 @@
}
},
sendMsg(e, msgType) {
if (!e) {
return;
}
@@ -1078,4 +1097,4 @@
justify-content: center;
align-items: center;
}
</style>
</style>

View File

@@ -179,6 +179,7 @@
},
loginDone(data) {
uni.setStorageSync('appId', data.appId);
uni.setStorageSync('im_userId', data.id);
uni.setStorageSync('userId', data.id);
uni.setStorageSync('im_userCSign', data.userSign);

View File

@@ -21,7 +21,9 @@
</template>
<script>
import {
getUrlParam
} from "../../common/utils"
export default {
data() {
@@ -54,7 +56,49 @@
return this.$store.state.friendApply;
}
},
onLoad() {
onLoad(options) {
console.log("首页获取到url参数")
console.log(options)
console.log(location.href)
if (options.imUserSign) {
uni.showLoading({
title: "加载中...",
mask: true
});
/*
uni.setStorageSync("imUserSign",getUrlParam("imUserSign"))
uni.setStorageSync("im_imUserSign",getUrlParam("imUserSign"))
uni.setStorageSync("userId",getUrlParam("uid"))
uni.setStorageSync("hd_userid",getUrlParam("uid"))
uni.setStorageSync("hd_token",getUrlParam("token"))
uni.setStorageSync("token",getUrlParam("token"))
*/
uni.setStorageSync("imUserSign", options.imUserSign)
uni.setStorageSync("im_imUserSign", options.imUserSign)
uni.setStorageSync("userId", options.uid)
uni.setStorageSync("hd_userid", options.uid)
uni.setStorageSync("hd_token", options.token)
uni.setStorageSync("token", options.token)
const timer = setInterval(() => {
if (uni.getStorageSync("initReady") == 1) {
console.log("==========进入首页 initReady为1开始跳转")
clearInterval(timer)
uni.hideLoading();
uni.navigateTo({
url: '../chatWindow/index?userId=' + options.tuid + '&windowType=' + options
.windowType
});
}
}, 500)
}
// uni.setStorageSync("token",hd_token)
// uni.setStorageSync("userId",hd_userId)
this.clickToSubmitSure = this.$fc.debounce(
e => {
uni.navigateTo({
@@ -65,10 +109,10 @@
true
);
},
filters:{
contentFilter(value){
filters: {
contentFilter(value) {
console.warn(value)
return "KKKKK"+value
return "KKKKK" + value
}
},
watch: {
@@ -141,14 +185,14 @@
toplist.push(obj[k]);
}
if (obj[k]['userId'] && obj[k]['top'] == 'N') {
try{
var _data=JSON.parse(obj[k].content)
if(_data.type=="IMAGE"){
obj[k].content="【图片】"
}else{
try {
var _data = JSON.parse(obj[k].content)
if (_data.type == "IMAGE") {
obj[k].content = "【图片】"
} else {
console.error(_data)
}
}catch(e){
} catch (e) {
//TODO handle the exception
}
NOTtoplist.push(obj[k]);
@@ -173,7 +217,7 @@
this.$store.dispatch('tabBarpull');
},
mounted() {
},
methods: {
longpressItem(e, i, v) {
@@ -219,4 +263,4 @@
text-align: center;
font-size: 28rpx;
}
</style>
</style>