OfficeApp/App.vue
weipengfei e3ed71c27b 更新
2023-11-24 11:49:39 +08:00

123 lines
3.6 KiB
Vue

<script>
//#ifdef APP-PLUS
const jpushModule = uni.requireNativePlugin("JG-JPush");
// #endif
import {
loginShopAccount,
loginParseToken,
userInfo
} from "@/api/oaUser.js"
export default {
onLaunch: async function(info) {
// let noticeArr = []
// jpushModule.addNotificationListener(res => {
// if (!noticeArr.includes(res.messageID)) {
// const audioContext = uni.createInnerAudioContext()
// // 设置音频文件地址
// audioContext.src = `/static/audio/order.mp3`;
// // console.log(res.messageID)
// audioContext.play()
// noticeArr.push(res.messageID)
// console.log("app的监听")
// }
// })
// uni.showModal({
// content: info.referrerInfo.extraData
// })
if (info.referrerInfo?.extraData?.uniMP) {
//监听宿主App通讯数据
uni.onHostEventReceive((event, data) => {
if (event == 'getLocation') uni.$emit('uniMP_getLocation', data);
});
uni.setStorageSync('uniMP', info.referrerInfo?.extraData?.uniMP);
uni.setStorageSync('APP_token', info.referrerInfo?.extraData?.token);
try {
let res = await loginParseToken({
// token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjZXNoaS1taWRkbGUubGloYWluay5jbiIsImF1ZCI6ImNlc2hpLW1pZGRsZS5saWhhaW5rLmNuIiwiaWF0IjoxNzAwNzkzMjY2LCJuYmYiOjE3MDA3OTMyNjYsImV4cCI6MTcwMTM5ODA2NiwiZGF0YSI6eyJ1aWQiOjUsInBob25lIjoiMTc2ODUxNTE2NDMiLCJhdmF0YXIiOiIvcmVzb3VyY2UvaW1hZ2UvYWRtaW5hcGkvZGVmYXVsdC9kZWZhdWx0X2F2YXRhci5wbmciLCJuaWNrbmFtZSI6Ilx1NzUyOFx1NjIzNzE3Njg1MTUxNjQzIn19.ctEIiBUd6T6zpp9m3x5wdop5vnBcnpS6VOliy4uz9bc"
token: info.referrerInfo?.extraData?.token
})
// let res = await loginShopAccount({
// shop_token: info.referrerInfo?.extraData?.token
// });
this.$store.commit('SET_USERINFO', {
user: {},
token: res.data.token
})
this.$store.dispatch('initConfig');
let {
data
} = await userInfo();
this.$store.commit('setUserInfo', data);
// this.$isResolve()
// uni.$emit('home_initUserInfo', data);
// return;
} catch (e) {
// this.$isResolve()
console.log(e);
}
}
console.log('App Launch')
try {
if (!this.$store.state.app.token) uni.reLaunch({
url: '/pages/oaLogin/oaLogin',
success() {
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen(); // 关闭渲染启动图
// #endif
this.$isResolve()
}
})
else {
this.$store.dispatch('initConfig');
this.$isResolve()
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen(); // 关闭渲染启动图
// #endif
}
} catch (e) {
this.$isResolve()
// #ifdef APP-PLUS
uni.reLaunch({
url: '/pages/oaLogin/oaLogin',
success() {
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen(); // 关闭渲染启动图
// #endif
this.$isResolve()
}
})
// #endif
}
},
onShow: function() {
const audioContext = uni.createInnerAudioContext()
// 设置音频文件地址
audioContext.src = '/static/mp3/order.mp3'
// 播放音频
//#ifdef APP-PLUS
jpushModule.addNotificationListener(res => {
if (res.notificationEventType == 'notificationOpened') return
audioContext.play()
uni.vibrateLong();
console.log("app的监听")
})
// #endif
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style>
/*每个页面公共css */
@import "static/css/base.css";
@import "static/css/style.scss";
view {
box-sizing: border-box;
}
</style>