代码拉取完成,页面将自动刷新
<script>
import Vue from 'vue'
export default {
onLaunch: function() {
uni.getSystemInfo({
success: function(e) {
// #ifndef MP
Vue.prototype.StatusBar = e.statusBarHeight;
if (e.platform == 'android') {
Vue.prototype.CustomBar = e.statusBarHeight + 50;
} else {
Vue.prototype.CustomBar = e.statusBarHeight + 45;
};
// #endif
// #ifdef MP-WEIXIN
Vue.prototype.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
Vue.prototype.Custom = custom;
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
// #endif
// #ifdef MP-ALIPAY
Vue.prototype.StatusBar = e.statusBarHeight;
Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
// #endif
}
})
//用户登录
this.authLogin()
},
onShow: function() {
},
onHide: function() {
},
methods: {
authLogin() {
uni.login({
provider: 'weixin',
success: async (loginRes) => {
let code = loginRes.code
this.$api.wechatLogin({
code
}).then(res => {
this.$store.commit('user/setUid', res.uid)
this.$store.commit('user/setUserInfo', res.userInfo)
this.$store.commit('user/setLogin', true)
if (res.token) {
this.$store.commit('user/setToken', res.token, res.tokenExpired)
}
// 登录成功
this.globalData.successCallbackHander.exec()
})
}
})
}
},
globalData: {
//登录回调函数
successCallbackHander: {
callbackList: new Array(),
//添加回调函数
add(func, _this) {
let isLogin = this.getState()
let route = _this.__route__
if (isLogin) {
func()
} else {
let callIndex = this.callbackList.findIndex(call => call.route == route)
if (callIndex === -1) {
this.callbackList.push({
func: func.bind(_this),
route: route
})
}
}
},
//执行回调函数
exec() {
this.callbackList.forEach(callback => callback.func())
},
getState: () => {
return Vue.prototype.$store.getters['user/getLogin']
}
}
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "./static/css/main.css";
@import "./static/css/icon.css";
@import "./static/css/animation.css";
@import "./static/icon/iconfont.css";
page {
background-color: #FFFFFF;
}
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。