|
|
|
import App from './App'
|
|
|
|
|
|
|
|
// #ifndef VUE3
|
|
|
|
import Vue from 'vue'
|
|
|
|
import './uni.promisify.adaptor'
|
|
|
|
import uView from './uni_modules/vk-uview-ui';
|
|
|
|
Vue.use(uView);
|
|
|
|
|
|
|
|
import unverified from '@/components/unverified.vue';
|
|
|
|
import insufficient from '@/components/insufficient.vue';
|
|
|
|
import share from '@/components/share.vue';
|
|
|
|
import dashan from '@/components/dashan.vue';
|
|
|
|
Vue.component('unverified', unverified)
|
|
|
|
Vue.component('insufficient', insufficient)
|
|
|
|
Vue.component('share', share)
|
|
|
|
Vue.component('dashan', dashan)
|
|
|
|
Vue.config.productionTip = false
|
|
|
|
|
|
|
|
import api from '@/api/index.js'
|
|
|
|
Vue.prototype.$api = api
|
|
|
|
Vue.prototype.$articleShareUrl = "https://api.lyiyuan.cn/profile/upload/web/index.html#/pages/dongtai/detail?type=web&id="
|
|
|
|
Vue.prototype.$userShareUrl = "https://api.lyiyuan.cn/profile/upload/web/index.html#/pages/login/reg?id="
|
|
|
|
|
|
|
|
let bgAudioManager = uni.getBackgroundAudioManager();
|
|
|
|
uni.$on("playAudio",res=>{
|
|
|
|
bgAudioManager.src = 'https://api.lyiyuan.cn/profile/upload/static/tishiyin.mp3';
|
|
|
|
bgAudioManager.play();
|
|
|
|
bgAudioManager = null
|
|
|
|
})
|
|
|
|
|
|
|
|
//socket
|
|
|
|
let timer = null;
|
|
|
|
uni.$on("openSocket",function(res){
|
|
|
|
uni.connectSocket({
|
|
|
|
url: 'wss://api.lyiyuan.cn/websocket?userId='+uni.getStorageSync('userInfo').id
|
|
|
|
});
|
|
|
|
uni.onSocketOpen(function (res) {
|
|
|
|
xintiao()
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({"userId": uni.getStorageSync("userInfo").id,"topic":"heart_beat"})});
|
|
|
|
console.log('WebSocket连接已打开!');
|
|
|
|
uni.setStorageSync("isOpen",true)
|
|
|
|
uni.$emit("watchSocket")
|
|
|
|
});
|
|
|
|
|
|
|
|
uni.$on("watchSocket",res=>{
|
|
|
|
uni.onSocketMessage(function (res) {
|
|
|
|
const obj = res.data?JSON.parse(res.data):{};
|
|
|
|
console.log(obj)
|
|
|
|
uni.$emit("toChatObj",res)
|
|
|
|
if(obj.topic == 'message'){
|
|
|
|
if(obj.type>=8){
|
|
|
|
if(uni.getStorageSync("userInfo").id == obj.sellerId){
|
|
|
|
if(obj.type == 12){
|
|
|
|
uni.$emit("watchEvent",obj)
|
|
|
|
}
|
|
|
|
if(obj.type == 20){
|
|
|
|
uni.$emit("toJieshouYinship",obj)
|
|
|
|
}
|
|
|
|
if(obj.type == 18){
|
|
|
|
if(obj.userMsgVoice == 1){
|
|
|
|
uni.$emit("playAudio")
|
|
|
|
}
|
|
|
|
if(obj.userMsgShock == 1){
|
|
|
|
uni.vibrateLong({
|
|
|
|
complete: function (res) {
|
|
|
|
console.log('success',res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
uni.navigateTo({
|
|
|
|
url: "/pages/pipei/shipin/detail?type=3&id="+obj.userId+'&fid='+obj.sellerId
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if(obj.type == 19){
|
|
|
|
if(obj.userMsgVoice == 1){
|
|
|
|
uni.$emit("playAudio")
|
|
|
|
}
|
|
|
|
if(obj.userMsgShock == 1){
|
|
|
|
uni.vibrateLong({
|
|
|
|
complete: function (res) {
|
|
|
|
console.log('success',res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
uni.navigateTo({
|
|
|
|
url: "/pages/pipei/shipin/detail?type=4&id="+obj.userId+'&fid='+obj.sellerId
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if(obj.type == 9){
|
|
|
|
if(obj.userMsgVoice == 1){
|
|
|
|
uni.$emit("playAudio")
|
|
|
|
}
|
|
|
|
if(obj.userMsgShock == 1){
|
|
|
|
uni.vibrateLong({
|
|
|
|
complete: function (res) {
|
|
|
|
console.log('success',res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
uni.showModal({
|
|
|
|
title: '温馨提示',
|
|
|
|
content: '来自'+obj.sellerNickname+"发起的视频匹配,是否同意",
|
|
|
|
cancelText: '拒绝',
|
|
|
|
confirmText: '同意',
|
|
|
|
success: res => {
|
|
|
|
if(res.confirm){
|
|
|
|
console.log(obj, uni.getStorageSync("userInfo"))
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({
|
|
|
|
"userId": uni.getStorageSync("userInfo").id,
|
|
|
|
sellerId: obj.userId,
|
|
|
|
type: 10,
|
|
|
|
"topic":"message"
|
|
|
|
})})
|
|
|
|
if(uni.getStorageSync("userInfo").id == obj.sellerId){
|
|
|
|
console.log("toChat",uni.getStorageSync("userInfo").id , obj.userId)
|
|
|
|
uni.navigateTo({
|
|
|
|
url: "/pages/pipei/shipin/detail?type=2&id="+obj.userId
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({
|
|
|
|
"userId": uni.getStorageSync("userInfo").id,
|
|
|
|
sellerId: obj.userId,
|
|
|
|
type: 11,
|
|
|
|
"topic":"message"
|
|
|
|
})})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: () => {},
|
|
|
|
complete: () => {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if(obj.type == 8){
|
|
|
|
if(obj.userMsgVoice == 1){
|
|
|
|
uni.$emit("playAudio")
|
|
|
|
}
|
|
|
|
if(obj.userMsgShock == 1){
|
|
|
|
uni.vibrateLong({
|
|
|
|
complete: function (res) {
|
|
|
|
console.log('success',res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
uni.showModal({
|
|
|
|
title: '温馨提示',
|
|
|
|
content: '来自'+obj.sellerNickname+"发起的语音匹配,是否同意",
|
|
|
|
cancelText: '拒绝',
|
|
|
|
confirmText: '同意',
|
|
|
|
success: res => {
|
|
|
|
if(res.confirm){
|
|
|
|
console.log(obj, uni.getStorageSync("userInfo"))
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({
|
|
|
|
"userId": uni.getStorageSync("userInfo").id,
|
|
|
|
sellerId: obj.userId,
|
|
|
|
type: 10,
|
|
|
|
"topic":"message"
|
|
|
|
})})
|
|
|
|
if(uni.getStorageSync("userInfo").id == obj.sellerId){
|
|
|
|
console.log("toChat",uni.getStorageSync("userInfo").id , obj.userId)
|
|
|
|
uni.navigateTo({
|
|
|
|
url: "/pages/pipei/shipin/detail?type=1&id="+obj.userId
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({
|
|
|
|
"userId": uni.getStorageSync("userInfo").id,
|
|
|
|
sellerId: obj.userId,
|
|
|
|
type: 11,
|
|
|
|
"topic":"message"
|
|
|
|
})})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: () => {},
|
|
|
|
complete: () => {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if(obj.type == 10 || obj.type==11){
|
|
|
|
uni.$emit("jiantingTiaozhuan",obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
uni.$emit("toChatXiaoxiObj",res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
uni.$on("duanYinship",obj=>{
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({
|
|
|
|
"userId": obj.userId,
|
|
|
|
"sellerId": obj.sellerId,
|
|
|
|
type: 12,
|
|
|
|
"topic":"message"
|
|
|
|
})})
|
|
|
|
})
|
|
|
|
uni.$on("jieshouYinship",obj=>{
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({
|
|
|
|
"userId": obj.userId,
|
|
|
|
"sellerId": obj.sellerId,
|
|
|
|
type: 20,
|
|
|
|
"topic":"message"
|
|
|
|
})})
|
|
|
|
})
|
|
|
|
uni.$on("showToast",res=>{
|
|
|
|
uni.showToast({
|
|
|
|
icon: "none",
|
|
|
|
position: "bottom",
|
|
|
|
title: res?'对方已挂断':"对方已拒绝"
|
|
|
|
})
|
|
|
|
})
|
|
|
|
uni.onSocketClose(function (res) {
|
|
|
|
clearInterval(timer)
|
|
|
|
uni.closeSocket();
|
|
|
|
uni.removeStorageSync("isOpen")
|
|
|
|
console.log('WebSocket 已关闭!');
|
|
|
|
setTimeout(()=>{
|
|
|
|
if(uni.getStorageSync("userInfo").id){
|
|
|
|
uni.$emit("openSocket")
|
|
|
|
}
|
|
|
|
},1000)
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
function xintiao() {
|
|
|
|
timer = setInterval(()=>{
|
|
|
|
uni.setStorageSync("isOpen",true)
|
|
|
|
uni.sendSocketMessage({data:JSON.stringify({"userId": uni.getStorageSync("userInfo").id,"topic":"heart_beat"})});
|
|
|
|
}, 30000)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
if(uni.getStorageSync("userInfo").id){
|
|
|
|
uni.$emit("openSocket")
|
|
|
|
}
|
|
|
|
},1000)
|
|
|
|
|
|
|
|
|
|
|
|
App.mpType = 'app'
|
|
|
|
const app = new Vue({
|
|
|
|
...App
|
|
|
|
})
|
|
|
|
app.$mount()
|
|
|
|
// #endif
|
|
|
|
// #ifdef VUE3
|
|
|
|
import { createSSRApp } from 'vue'
|
|
|
|
export function createApp() {
|
|
|
|
const app = createSSRApp(App)
|
|
|
|
return {
|
|
|
|
app
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #endif
|