This commit is contained in:
2023-10-29 13:17:28 +08:00
parent dee9051652
commit 336bcc662b
29 changed files with 3077 additions and 169 deletions

View File

@@ -18,7 +18,9 @@
appInit(500).then((res)=>{
console.log("获取到token创建长链接")
console.log(this.$socketTask.socketTask)
this.$socketTask.connectSocket()
setTimeout(()=>{
this.$socketTask.connectSocket()
},500)
}).then((error)=>{
console.log("未获取到IM的token")
})

View File

@@ -1,7 +1,15 @@
export default class config{
static prod="online"
static getZnzqApiUrl(){
return process.env.NODE_ENV === 'development' ? 'http://work.ii999.live:19002/znzq' :'http://172.16.2.3:19000/znzq';
if(process.env.NODE_ENV === 'development' ){
return 'http://work.ii999.live:19002/znzq'
}else{
if(this.prod=="online"){
return 'http://work.ii999.live:19002/znzq'
}else{
return 'http://172.16.2.3:19000/znzq'
}
}
}
static getBaseApiUrl(){
//return process.env.NODE_ENV === 'development' ? 'http://119.45.242.222:8989' :'http://172.16.2.3:8989';
@@ -9,7 +17,7 @@ export default class config{
}
static getImApiUrl(){
//return process.env.NODE_ENV === 'development' ? 'http://119.45.242.222:28000/v1' :'http://172.16.2.3:28000/v1';
return process.env.NODE_ENV === 'development' ? 'http://119.45.242.222:28000/v1' :'/im_api/v1';
return process.env.NODE_ENV === 'development' ? 'http://119.45.242.222/im_api/v1' :'/im_api/v1';
}
static getImAppId(){
return 10000;

View File

@@ -14,7 +14,9 @@ customHttp.interceptors.request.use((config) => {
if (config.custom.target == "znzq") {
config.baseURL = conf.getZnzqApiUrl()
const token = uni.getStorageSync('token');
config.headers["X-Access-Token"] = token;
config.header["X-Access-Token"] = token;
console.log("==================customHttp.interceptors.request.use")
console.log(config)
}
}

View File

@@ -22,16 +22,20 @@ export function appInit(ms) {
return new Promise((resolve, reject) => {
var i = 0;
let timer = setInterval(() => {
var hd_token = localStorage.getItem("im_imUserSign")
var im_imUserSign = localStorage.getItem("im_imUserSign")
var im_userId = localStorage.getItem("im_userId")
var hd_token = localStorage.getItem("hd_token")
i = i + 1;
if (i > 10) {
if (i > 30) {
reject("error")
}
if (hd_token) {
localStorage.setItem("imUserSign",hd_token)
if (im_imUserSign) {
localStorage.setItem("imUserSign",im_imUserSign)
localStorage.setItem("appId",10000)
localStorage.setItem("token",hd_token)
if(im_userId){
localStorage.setItem("userId",im_userId)
}

View File

@@ -3,9 +3,9 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript" src="./vconsole.min.js"></script>
<script type="text/javascript" src="/vconsole.min.js"></script>
<script>
// var vConsole = new VConsole();
var vConsole = new VConsole();
</script>
<title></title>
<!--preload-links-->

View File

@@ -12,7 +12,9 @@
"author": "php_echo@163.com",
"license": "ISC",
"dependencies": {
"base64-js": "^1.5.1",
"dayjs": "^1.11.10",
"js-base64": "^3.7.5",
"localforage": "^1.10.0",
"luch-request": "^3.1.1"
}

View File

@@ -447,28 +447,45 @@
content: 'TRTC_VIDEO_START'
};
this.sendMsg(formdata,formdata.msgType)
// this.sendMsg(formdata,formdata.msgType)
const userId=localStorage.getItem("userId")
const roomId=userId
const roomInfo={
roomId:"call_room",//后面改成发起人的手机号或者id
roomName:"某某发起的视频聊天",
creatorId:"creatorId",
creatorName:"发起人的昵称",
roomId:userId,//后面改成发起人的手机号或者id
roomName:`${userId}发起的视频聊天`,
creatorId:userId,
creatorName:userId,
publishId:userId,
publishName:userId,
isOver:0,
webrtcUrl:config.getSRSUrl()+"/call_room/uid13",
webrtcUrl:config.getSRSUrl()+`/${roomId}/${userId}`,
type:"webrtc",
offline:0
offline:0,
invitedUserList:[this.talkTo.userId]
}
this.$store
.dispatch('createRoom', roomInfo)
.then(res => {
location.href=config.getVideoRoomUrl(roomInfo.roomId,roomInfo.creatorId,1,1)
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)
})
})
this.$http.request({
if(1>0){
return false;
}
this.$http.request({
url: '/chat/sendMsg',
method: 'POST',
data: JSON.stringify(formdata),

View File

@@ -45,6 +45,8 @@
</template>
<script>
import customHttp from "@/common/customHttp.js"
import { Base64 } from 'js-base64';
export default {
data() {
@@ -146,91 +148,51 @@
return Math.floor(Math.random() * (max - min + 1)) + min
},
sublogin(e) {
var rules = {
phone: {
rules: [{
checkType: "required",
errorMsg: "请填写手机号码"
}, {
checkType: "phone",
errorMsg: "请填写正确的手机号码"
}]
},
password: {
rules: [{
checkType: "required",
errorMsg: "请输入密码"
}, {
checkType: "string",
checkRule: "4,6",
errorMsg: "至少输入4-6位"
}]
},
code: {
rules: [{
checkType: "required",
errorMsg: "请输入验证码"
}]
}
};
// var formData = e.detail.value;
var formData = JSON.parse(JSON.stringify(this.form));
var checkRes = this.$zmmFormCheck.check(formData, rules);
// #ifdef APP-PLUS
var cid = plus.push.getClientInfo().clientid
formData['cid'] = cid
// #endif
// #ifdef H5
// todo
var cid = ''
formData['cid'] = cid
// #endif
uni.setStorageSync('cid', cid);
console.log(cid)
if (checkRes) {
if (!this.agree) {
uni.showToast({
title: '请先同意《隐私及服务协议》',
icon: 'none'
});
return;
}
uni.showLoading()
formData.loginType = 1
this.$http.request({ //手机+验证码
url: '/v1/login',
method: 'POST',
data: JSON.stringify(formData),
success: (res) => {
if (res.data.code == 200) {
this.loginDone(res.data.data)
}
customHttp.customHttp.post('/api/im/app/login', {
"username": this.form.userName,
"password":Base64.encode(this.form.password)
}, {
params: {},
/* 会加在url上 */
header: {},
/* 会与全局header合并如有同名属性局部覆盖全局 */
dataType: 'json',
// 注如果局部custom与全局custom有同名属性则后面的属性会覆盖前面的属性相当于Object.assign(全局,局部)
custom: {
target: "znzq"
}, // 可以加一些自定义参数在拦截器等地方使用。比如这里我加了一个auth可在拦截器里拿到如果true就传token
}).then(res => {
console.log("=========获取到数据")
console.log(res)
if (res.statusCode == 200) {
if (res.data.code == 200) {
this.loginDone(res.data.result)
}
});
}
}).catch(err => {
})
} else {
uni.showToast({
title: this.$zmmFormCheck.error,
icon: "none",
position: 'bottom'
});
}
},
loginDone(data) {
uni.setStorageSync('appId', data.appId);
uni.setStorageSync('im_userId', data.userId);
uni.setStorageSync('userId', data.userId);
uni.setStorageSync('im_userId', data.id);
uni.setStorageSync('userId', data.id);
uni.setStorageSync('im_userCSign', data.userSign);
uni.setStorageSync('im_imUserSign', data.imUserSign);
uni.setStorageSync('imUserSign', data.imUserSign);
uni.setStorageSync('token', data.token);
uni.setStorageSync('hd_token', data.token);
uni.reLaunch({
url: '../tabbar1/index'
})
}
}
}
@@ -333,4 +295,4 @@
width: 300rpx;
margin-top: 120rpx;
}
</style>
</style>

View File

@@ -63,21 +63,49 @@
}
]
this.list=this.$fc.sortList({list:list,key:'name'})
console.log(customHttp)
console.log("================开始请求通讯录列表")
// 局部修改配置,局部配置优先级高于全局配置
customHttp.customHttp.post('/api/im/app/addressList', {userName: 'name', password: '123456'}, {
customHttp.customHttp.get('/api/im/app/addressList', {
params: {}, /* 会加在url上 */
header: {}, /* 会与全局header合并如有同名属性局部覆盖全局 */
dataType: 'json',
// 注如果局部custom与全局custom有同名属性则后面的属性会覆盖前面的属性相当于Object.assign(全局,局部)
custom: {target: "znzq"} // 可以加一些自定义参数在拦截器等地方使用。比如这里我加了一个auth可在拦截器里拿到如果true就传token
custom: {target: "znzq"} , // 可以加一些自定义参数在拦截器等地方使用。比如这里我加了一个auth可在拦截器里拿到如果true就传token
}).then(res => {
console.log("=========获取到数据")
console.log(res)
if(res.statusCode==200){
if(res.data.code==200){
var list=[]
res.data.result.records.map((item)=>{
console.log(item)
list.push({
name:item.realname,
avatar:item.portrait,
userId:item.userId,
userType:1,
chatNo:item.userId
})
})
this.list=this.$fc.sortList({list:list,key:'name'})
}
}
}).catch(err => {
})
/*
this.$http.request({
url: '/friend/friendList',
method: 'POST',
@@ -99,7 +127,8 @@
this.list=this.$fc.sortList({list:list,key:'name'})
}
}
});
});
*/
},
},
onNavigationBarButtonTap(e) {