factory_mp_old/App.vue

95 lines
2.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>
export default {
// 此处globalData为了演示其作用不是uView框架的一部分
globalData: {
appid: 'wxf7d6140f507466be'
},
onLaunch() {
var that = this
// 1.1.0版本之前关于http拦截器代码已平滑移动到/common/http.interceptor.js中
// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明)
// import httpInterceptor from '@/common/http.interceptor.js'
// Vue.use(httpInterceptor, app)
// process.env.VUE_APP_PLATFORM 为通过js判断平台名称的方法结果分别如下
/**
* h5app-plus(nvue下也为app-plus)mp-weixinmp-alipay......
*/
//var that=this
// 小程序自动登录
// #ifdef MP-WEIXIN
uni.showLoading({
title: '微信自动登录中...',
mask: true
})
uni.login({
provider: 'weixin',
success: (loginRes) => {
this.$u.api.wxmplogin({
code: loginRes.code
}).then(res => {
this.$u.vuex('vuex_token', res.access)
this.$u.api.getUserInfo().then(res => {
uni.hideLoading()
uni.showToast({
title: "登录成功",
icon: "none"
})
uni.reLaunch({
url: "/pages/home/home"
})
this.$u.vuex('vuex_user', res)
// 修改资源请求地址
// this.$u.vuex('vuex_user.avatar', this.vuex_user.avatar +
// '?token=' + this.vuex_token)
})
}).catch(e => {
console.log(e)
uni.setStorageSync('wxmp_openid', e.data.wxmp_openid)
uni.hideLoading()
// uni.showToast({
// title: "暂未绑定微信!",
// icon: "none"
// })
uni.reLaunch({
url: '/pages/login/login'
})
})
}
});
// #endif
// #ifdef APP-PLUS
uni.showLoading({
title: '自动登录中...',
mask: true
})
uni.getStorage({
key: 'mySecret',
success: function (res) {
let secret = res.data
if(secret){
that.$u.api.loginSecret(JSON.parse(secret)).then(res=>{
that.$u.api.getUserInfo().then(res => {
that.$u.vuex('vuex_user', res)
// 修改资源请求地址
})
uni.reLaunch({
url: '/pages/home/home_'
})
})
}
},
complete() {
uni.hideLoading()
}
});
// #endif
},
}
</script>
<style lang="scss">
@import "uview-ui/index.scss";
@import "common/demo.scss";
</style>