Commit e3ad46bf authored by xd's avatar xd

冲突

parents 539266b5 18ebed80
<template>
<van-dialog v-if="showAuth" v-model="show" id="wx-auth" title="微信授权" show-cancel-button
@confirm="handleConfirm"
>
<img class="logo" src="/img/photo.png" alt="logo" />
<div class="small-tips">
<p>为您提供优质服务,亿百分需要获取以下信息</p>
<p>&middot; 您的公开信息(昵称、头像等)</p>
</div>
</van-dialog>
</template>
<script>
export default {
name: "wxAuth",
components: {},
props: {
showAuth: {
type: Boolean,
default: false
}
},
data() {
return {
show: true
};
},
methods: {
handleConfirm() {
this.$emit('confirm');
}
}
};
</script>
<style lang="scss">
#wx-auth {
.logo {
width: 20%;
margin: 15px auto;
display: block;
border-radius: 50%;
}
.small-tips {
margin-left: 15px;
p {
padding: 5px 10px;
}
p:first-child {
font-size: 14px;
color: #333;
}
p:last-child {
font-size: 12px;
color: #ccc;
}
}
}
</style>
...@@ -69,16 +69,23 @@ ...@@ -69,16 +69,23 @@
</div> </div>
</template> </template>
<div class="btn-share" :style="type === 'coupon'? 'bottom: 0': ''" @click="handleShare">立即分享</div> <div class="btn-share" :style="type === 'coupon'? 'bottom: 0': ''" @click="handleShare">立即分享</div>
<wx-auth :show-auth="showAuthDialog" @confirm="handleCheckAuth"></wx-auth>
</div> </div>
</template> </template>
<script> <script>
import wxAuth from "@/components/wxAuth";
export default { export default {
name: "active-detail", name: "active-detail",
components: {}, components: { wxAuth },
data() { data() {
return { return {
code: '', showAuthDialog: false,
nowUrl: "",
userId: "",
code: "",
active_id: "",
type: "coupon", type: "coupon",
freeze: false, freeze: false,
rolling: false, rolling: false,
...@@ -119,10 +126,23 @@ export default { ...@@ -119,10 +126,23 @@ export default {
}; };
}, },
created() { created() {
console.log("活动详情1");
window.console.log("活动详情2");
console.log("url", location.href);
this.active_id = this.$route.query.id;
this.type = this.$route.query.type; this.type = this.$route.query.type;
// 检测用户身份 console.log("query", this.$route.query);
// 获取code // 验证用户是否登录
this.zReadyUserId() if (!sessionStorage.getItem("userId")) {
// 1.获取code
if (this.$route.query.code === undefined) {
this.showAuthDialog = true;
} else {
console.log("code", this.$route.query.code);
// 拿code 换取access_token
this.getAccessToken();
}
}
}, },
watch: { watch: {
prizeNumber() { prizeNumber() {
...@@ -140,31 +160,35 @@ export default { ...@@ -140,31 +160,35 @@ export default {
} }
}, },
methods: { methods: {
zReadyUserId() { getAccessToken() {
if (this.$route.query.code === undefined) { const base = {
alert("没code"); baseUrl: "https://api.weixin.qq.com/sns/oauth2/access_token?",
console.log('code', this.$route.query.code); appId: "ww4df265003b43fa0d",
this.zTestPreAuthCode(); secret: "kF8_-TZE2qad9OMaE2wYAED5rKjOb3Y5IUhHFLHVQAo",
} else { code: this.code,
alert("有code"); grant_type: "authorization_code"
// this.zTestGetNowUrlInfo(); };
// this.zTestGetUserInfoByOldToken(); },
}
handleCheckAuth() {
this.showAuthDialog = false;
this.getAuthCode();
}, },
// 获取code // 获取code
zTestPreAuthCode() { getAuthCode() {
// alert('获取code') // alert('获取code')
const basicInfo = { const basicInfo = {
head: "https://open.weixin.qq.com/connect/oauth2/authorize?", head: "https://open.weixin.qq.com/connect/oauth2/authorize?",
// appId: "wwd1cdbca7b8b2b6c4",
appId: "ww4df265003b43fa0d", appId: "ww4df265003b43fa0d",
redirectUrI: encodeURIComponent("oysales.oywanhao.com:8087/activeDetail?id=2&type=wheel"), redirectUrI: encodeURIComponent(
`oysales.oywanhao.com:8087/activeDetail?id=${this.active_id}&type=${this.type}`
),
responseType: "code", responseType: "code",
scope: "snsapi_base", scope: "snsapi_base",
state: "ztest", state: "ztest",
tail: "#wechat_redirect" tail: "#wechat_redirect"
}; };
console.log("redir_url", basicInfo.redirectUrI);
let url = let url =
basicInfo.head + basicInfo.head +
"appid=" + "appid=" +
...@@ -180,6 +204,68 @@ export default { ...@@ -180,6 +204,68 @@ export default {
basicInfo.tail; basicInfo.tail;
window.location.href = url; window.location.href = url;
}, },
getUserInfo() {
let headerData = {
agentId: "1000033",
corpId: "ww4df265003b43fa0d"
};
axios({
url:
"http://139.155.48.151:8085/workWx/auth/user/get?userId=" +
this.userId,
method: "get",
headers: headerData
})
.then(res => {
window.console.log("用户信息", res);
})
.catch(err => {
console.log(err);
});
},
getUserId() {
if (this.$route.query.code === undefined) {
alert("没code");
this.zTestPreAuthCode();
} else {
alert("有code");
this.zTestGetNowUrlInfo();
this.zTestGetUserInfoByOldToken();
}
},
zTestGetNowUrlInfo() {
this.nowUrl = JSON.stringify(this.$route.query);
this.code = String(this.$route.query.code);
console.log("nowUrl", this.nowUrl);
console.log("code", this.code);
},
zTestGetUserInfoByOldToken() {
let postData = {
code: this.code
};
let headerData = {
agentId: "1000033",
corpId: "ww4df265003b43fa0d"
};
this.zcache.userInfoResOld = "PostData:" + JSON.stringify(postData);
axios({
url:
"http://139.155.48.151:8085/workWx/auth/oauth2/getUserInfo?code=" +
this.code,
method: "post",
headers: headerData
})
.then(res => {
alert("获取用户信息接口成功");
this.userId = String(res.data.data.userId);
this.getUserInfo();
})
.catch(err => {
console.log(err);
});
},
Start_Game() { Start_Game() {
this.rolling = true; this.rolling = true;
const { wheelDeg, prizeList } = this; const { wheelDeg, prizeList } = this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment