<template>
<view class="container">
<image class="containers" src='../assets/images/page.png'></image>
<view class="size">欢迎来到</view>
<loading hidden="{{loadingHidden}}">
加载中...
</loading>
<van-notify id="custom-selector" />
<van-notify id="van-notify" />
</view>
</template>
<script>
import wepy from 'wepy'
import fetch from '../utils/fetch.js'
import Notify from '../components/vant/notify/notify'
export default class Index extends wepy.page {
config = {
navigationBarTitleText: 'wechat',
'usingComponents': {
'van-notify': '../components/vant/notify/index'
}
}
onShow () {
this.login()
}
data = {
loadingHidden: true
}
methods = {
}
login () {
// 显示正在加载
this.loadingHidden = false
this.$apply()
const _this = this
wepy.login({
success (res) {
fetch({
url: 'https://yx.seee.com.cn/ashare/edocApp/login',
method: 'POST',
data: {
'PARAMETER': {
'WECHAT_CODE': res.code
}
}
}).then((res) => {
_this.loadingHidden = true
_this.$apply()
if (res.data.RESPONSE_HEADER && res.data.RESPONSE_HEADER.RESPONSE_STATUS === 'Y') {
if (res.data.RESPONSE_CONTEXT && res.data.RESPONSE_CONTEXT.USER_NAME) {
wepy.setStorageSync('userName', res.data.RESPONSE_CONTEXT.USER_NAME)
}
if (res.data.RESPONSE_CONTEXT && res.data.RESPONSE_CONTEXT.WECHAT_OPENID) {
wepy.setStorageSync('openId', res.data.RESPONSE_CONTEXT.WECHAT_OPENID)
}
wepy.redirectTo({
url: 'index'
})
} else {
Notify(res.data.RESPONSE_HEADER.RESPONSE_MESSAGE)
if (res.data.RESPONSE_HEADER && res.data.RESPONSE_HEADER.WECHAT_OPENID) {
wepy.setStorageSync('openId', res.data.RESPONSE_HEADER.WECHAT_OPENID)
wepy.redirectTo({
url: 'register'
})
}
}
})
}
})
}
}
</script>
<style lang="less">
.container {
position:fixed;
width:100%;
height:100%;
.containers {
position: absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
.size {
position: fixed;
top:10%;
text-align: center;
width:100%;
color:#4BD863;
}
}
</style>