<template>
|
<view>
|
<u-toast ref="uToast"></u-toast>
|
|
<view class="" v-if="loginFlag">
|
登陆异常:{{loginText}}
|
</view>
|
|
<view class="text-xl" v-if="workFlag">
|
请使用企业微信客户端扫码打开!
|
</view>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
loginFlag: false,
|
loginText: "",
|
workFlag:false,
|
|
code: 0,
|
state: 0,
|
status: "0",
|
flag: true,
|
number: "",
|
number2: ""
|
}
|
},
|
async onLoad(options) {
|
try {
|
//http://asset.mengdong.icu/h5/?status=1&number=6688898
|
this.status = options.status;
|
console.log('status=' + this.status);
|
if (this.status === "1") {
|
this.number = options.number;
|
this.flag = false
|
this.navToCode();
|
}
|
} catch (e) {
|
|
}
|
|
if (this.flag) {
|
this.code = options.code;
|
this.state = options.state;
|
|
await this.login(this.code);
|
|
if (!this.loginFlag) {
|
await this.getUserInfo();
|
let json = this.state.split("^");
|
|
if (json[0] === "share") {
|
this.number = json[1];
|
setTimeout(() => {
|
this.navToShare();
|
}, 0)
|
} else {
|
this.navTo();
|
}
|
}
|
|
|
|
}
|
|
},
|
methods: {
|
navTo() {
|
uni.switchTab({
|
url: "../index/index?state=" + this.state
|
})
|
},
|
navToShare() {
|
uni.reLaunch({
|
url: "../assets/repairInfo?number=" + this.number
|
})
|
},
|
|
navToCode() {
|
|
var ua = window.navigator.userAgent.toLowerCase();
|
if ((ua.match(/MicroMessenger/i) == 'micromessenger') && (ua.match(/wxwork/i) == 'wxwork')) {
|
//生产
|
window.location.href =`http://open.weixin.qq.com/connect/oauth2/authorize?appid=ww9516eee214a997e5&redirect_uri=http://uat.zhongyishutong.xyz/h5/&response_type=code&state=share^${this.number}&scope=snsapi_userinfo@asset#wechat_redirect`;
|
|
//测试
|
// window.location.href =`http://open.weixin.qq.com/connect/oauth2/authorize?appid=wwb3c45e4348576dc2&redirect_uri=http://asset.mengdong.icu/h5/&response_type=code&state=share^${this.number}&scope=snsapi_userinfo@asset#wechat_redirect`;
|
} else if (ua.match(/micromessenger/i) == 'micromessenger') {
|
this.workFlag=true;
|
}
|
|
},
|
|
//登陆
|
async login(code) {
|
await this.$http.get('/h5login', {
|
params: {
|
code: code
|
}
|
})
|
.then(res => {
|
// debugger;
|
console.log(res.data)
|
if (res.data.code === 0) {
|
// this.$refs.uToast.show({
|
// type: 'success',
|
// message: "登陆成功"
|
// });
|
|
this.token = res.data.token;
|
console.log('token=' + this.token);
|
this.value1 = this.token;
|
uni.setStorageSync('token', this.token);
|
} else {
|
this.loginFlag = true;
|
this.loginText = res.data.msg;
|
}
|
|
}).catch(err => {
|
this.loginFlag = true;
|
this.loginText = '异常' + err;
|
console.log('错误', err.data)
|
})
|
},
|
|
async getUserInfo() {
|
await this.$http.get('/assets/approval/getUserDetail')
|
.then(res => {
|
// debugger;
|
if (res.data.code === 0) {
|
let data = res.data.data;
|
uni.setStorageSync('user', data);
|
console.log('姓名:' + data.userName)
|
console.log('user=', data)
|
}
|
}).catch(err => {
|
console.log('错误', err.data)
|
})
|
},
|
}
|
}
|
</script>
|
|
<style>
|
|
</style>
|