178 lines
4.4 KiB
Vue
178 lines
4.4 KiB
Vue
<script>
|
||
import {
|
||
version,
|
||
name
|
||
} from './package.json'
|
||
import {
|
||
versionName
|
||
} from '@/manifest.json'
|
||
import {appInit} from "@/common/utils.js"
|
||
import consoleImgs from '@/common/consoleImgs.js'
|
||
// #ifdef APP-PLUS
|
||
import appUpgrade from '@/common/appUpgrade.js';
|
||
const TUICalling = uni.requireNativePlugin("TUICallingUniPlugin-TUICallingModule");
|
||
// #endif
|
||
export default {
|
||
onLaunch: function() {
|
||
|
||
appInit(500).then((res)=>{
|
||
console.log("获取到token,创建长链接")
|
||
console.log(this.$socketTask.socketTask)
|
||
setTimeout(()=>{
|
||
this.$socketTask.connectSocket()
|
||
},500)
|
||
}).then((error)=>{
|
||
console.log("未获取到IM的token")
|
||
})
|
||
|
||
// #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) => {
|
||
var callx=res.data
|
||
if(callx){
|
||
var call=JSON.parse(callx)
|
||
function getInervalHour(startDate) {//获取两个时间之间的小时
|
||
if (!startDate) {
|
||
return '0秒'
|
||
}
|
||
var ms = new Date().getTime() - startDate;
|
||
if (ms < 0) return '0秒';
|
||
if((ms/1000)<60){
|
||
return Math.floor(ms / 1000)+'秒';
|
||
}else{
|
||
return Math.floor(ms / 1000 /60)+'分';
|
||
}
|
||
}
|
||
var msgType=''
|
||
if(call.type=='audio'){
|
||
msgType='TRTC_VOICE_END'
|
||
}
|
||
if(call.type=='video'){
|
||
msgType='TRTC_VIDEO_END'
|
||
}
|
||
this.$fc.pushOutMsg({
|
||
msgContent:getInervalHour(call.startTime),
|
||
msgType:msgType,
|
||
windowType:'SINGLE',
|
||
userId:call.userId,
|
||
})
|
||
uni.removeStorageSync('call')
|
||
}
|
||
}
|
||
});
|
||
},
|
||
onHide: function() {
|
||
console.log('App Hide')
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/*每个页面公共css */
|
||
@import '@/uni_modules/uni-scss/index.scss';
|
||
@import "@/static/styles/animation.css";
|
||
/* #ifndef APP-NVUE */
|
||
@import '@/static/customicons.css';
|
||
|
||
// 设置整个项目的背景色
|
||
page {
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* #endif */
|
||
|
||
// 以下内容最好转移到单页
|
||
|
||
</style>
|