|
|
@@ -4,7 +4,7 @@
|
|
|
<image src="../../static/images/banner2x.png" mode=""></image>
|
|
|
</view>
|
|
|
<view class="nav">
|
|
|
- <view class="menu">
|
|
|
+ <view class="menu" v-show="my_display">
|
|
|
<navigator :url="'/pages/reshui/reshui'" open-type="redirect" class="menu_item">
|
|
|
<image src="../../static/images/shower2x.png" mode=""></image>
|
|
|
<text>洗 浴</text>
|
|
|
@@ -14,24 +14,17 @@
|
|
|
<text>电费充值</text>
|
|
|
</navigator>
|
|
|
</view>
|
|
|
- </view>
|
|
|
- <!--弹窗-->
|
|
|
- <view class="banding-bg" v-if="showPop">
|
|
|
- <view class="banding-model">
|
|
|
- <view class="title-model">绑定</view>
|
|
|
- <view class="lineGroup-model">
|
|
|
- <text class="iconfont icon-shengchengmingpianicon label-icon-model"></text>
|
|
|
- <input type='number' class="input-model" maxlength="14" placeholder="请输入学号" v-model="stu_number" />
|
|
|
- </view>
|
|
|
- <view class="lineGroup-model">
|
|
|
- <text class="iconfont icon-cardid label-icon-model"></text>
|
|
|
- <input type='text' class="input-model" maxlength="18" placeholder="请输入身份证号码" v-model="id_card" />
|
|
|
- </view>
|
|
|
- <view class="btn-model">
|
|
|
- <button class="btn" @tap="confirmPop">绑定</button>
|
|
|
- </view>
|
|
|
+ <view class="reset">
|
|
|
+ <navigator url="" open-type="redirect" @click="reauthorization()" class="menu_item">
|
|
|
+ <text class="iconfont icon-zhongzhi"></text>
|
|
|
+ <text>重新授权</text>
|
|
|
+ </navigator>
|
|
|
</view>
|
|
|
</view>
|
|
|
+ <view v-if="showLogin">
|
|
|
+ <login :ocode="ocode" :appkey="appkey" scope="snsapi_userinfo" :visible="visible" @success="callback()"
|
|
|
+ @cancel="callback()" @fail="callback()" />
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
@@ -39,17 +32,26 @@
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- code: '',
|
|
|
- showPop: false, //弹窗
|
|
|
- stu_number: '',
|
|
|
- id_card: '',
|
|
|
ceshi: 'code',
|
|
|
- huanjing: '部署环境' // 部署环境是key,用来获取环境
|
|
|
+ huanjing: '部署环境' ,// 部署环境是key,用来获取环境
|
|
|
+ visible: false,
|
|
|
+ showLogin: true,
|
|
|
+ appkey: '5AA49F3E4CACA380',
|
|
|
+ sub_appid: '1015730314_1941301045',
|
|
|
+ appid: 'wx2fc3f45732fae5d3', // 获取用户信息
|
|
|
+ ocode: '1015730314', // 获取用户信息
|
|
|
+ app_secret: '58D34C81D82B35179ED896C4362B0FC0', // 获取用户信息
|
|
|
+ my_display: false,
|
|
|
+ userinfo: {},
|
|
|
+ wxcode: '',
|
|
|
+ access_token: ''
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|
|
|
// 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
|
|
|
this.isTestEnvironment()
|
|
|
+
|
|
|
+ this.has_user_info()
|
|
|
},
|
|
|
methods: {
|
|
|
/**
|
|
|
@@ -82,110 +84,180 @@
|
|
|
icon: 'success'
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- // 获取code
|
|
|
- this.getCode()
|
|
|
},
|
|
|
/**
|
|
|
- * 弹窗
|
|
|
+ * 是否有用户信息
|
|
|
*/
|
|
|
- confirmPop() { // 确认
|
|
|
- if (this.stu_number.length == 14 && this.id_card.length == 18) {
|
|
|
- // 获得code
|
|
|
- this.getCode('confirm')
|
|
|
- } else {
|
|
|
+ has_user_info() {
|
|
|
+ try {
|
|
|
+ this.userinfo = this.$store.state.userinfo
|
|
|
+ const value = uni.getStorageSync('userinfo_storage_key');
|
|
|
+ if (value == '') {
|
|
|
+ if (typeof(this.userinfo) == 'undefined' || JSON.stringify(this.userinfo) == '{}') {
|
|
|
+ this.showLogin = true
|
|
|
+ this.visible = true
|
|
|
+ } else {
|
|
|
+ this.showLogin = false
|
|
|
+ this.my_display = true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.showLogin = false
|
|
|
+ this.userinfo = value
|
|
|
+ this.my_display = true
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // console.log(e)
|
|
|
uni.showToast({
|
|
|
- title: '学号长度错误 或 身份证号 长度错误!',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
+ title: '异常:' + e,
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
- * param获得code
|
|
|
+ * 重新授权
|
|
|
*/
|
|
|
- getCode(param) {
|
|
|
- uni.login({
|
|
|
- success: (res) => {
|
|
|
- // console.log('index', res);
|
|
|
- if (res.code) {
|
|
|
- if (param == 'confirm')
|
|
|
- // 请求服务器,获得openid
|
|
|
- this.getOpenId(res.code)
|
|
|
- else
|
|
|
- this.selectUser(res.code)
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: res.errMsg,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
-
|
|
|
- this.showPop = true
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ reauthorization() {
|
|
|
+ try {
|
|
|
+ uni.removeStorageSync('userinfo_storage_key');
|
|
|
+ setTimeout(() => {
|
|
|
+ this.showLogin = false
|
|
|
+ this.userinfo = {}
|
|
|
+ this.my_display = false
|
|
|
+ }, 30)
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ this.showLogin = true
|
|
|
+ this.visible = true
|
|
|
+ }, 30)
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
},
|
|
|
+
|
|
|
/**
|
|
|
- * 请求服务器,获得openid
|
|
|
+ * 授权回调
|
|
|
*/
|
|
|
- async getOpenId(code) {
|
|
|
- if (this.stu_number == '' || this.id_card == '') {
|
|
|
+ callback: function({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ // console.log(detail)
|
|
|
+ // {wxcode: "7f7Qi9rN8zQ1nifQiysTZ3WIeIWlgcGk"}
|
|
|
+ if (detail === undefined) {
|
|
|
+ this.userinfo = {};
|
|
|
uni.showToast({
|
|
|
- title: '学号或身份证号为空'
|
|
|
+ icon: 'success',
|
|
|
+ title: '需要先授权'
|
|
|
});
|
|
|
- return
|
|
|
+ } else {
|
|
|
+ const {
|
|
|
+ wxcode = ""
|
|
|
+ } = detail
|
|
|
+
|
|
|
+ if (wxcode.length == 0) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '未获得wxcode',
|
|
|
+ duration: 500
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 获取wxcode
|
|
|
+ this.wxcode = wxcode
|
|
|
+
|
|
|
+ // 通过wxcode换取access_token
|
|
|
+ this.get_access_token()
|
|
|
+ }
|
|
|
}
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 通过wxcode换取access_token
|
|
|
+ */
|
|
|
+ async get_access_token() {
|
|
|
const res = await this.$myRequest({
|
|
|
- host: this.ceshi,
|
|
|
- url: '/HotWaters/wpopenid.action',
|
|
|
+ host: 'wecard',
|
|
|
+ url: '/connect/oauth2/token',
|
|
|
method: 'POST',
|
|
|
header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ 'content-type': 'application/json'
|
|
|
},
|
|
|
data: {
|
|
|
- code: code,
|
|
|
- stu_number: this.stu_number,
|
|
|
- id_card: this.id_card
|
|
|
+ 'wxcode': this.wxcode,
|
|
|
+ 'app_key': this.appkey,
|
|
|
+ 'app_secret': this.app_secret,
|
|
|
+ 'grant_type': 'authorization_code',
|
|
|
+ 'redirect_uri': 'mnp://wx2fc3f45732fae5d3'
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
- // console.log(res.data.mess);
|
|
|
- if (res.data.mess == '绑定成功') {
|
|
|
+
|
|
|
+ if (res.data.refresh_token == '' || typeof(res.data.refresh_token) == 'undefined') {
|
|
|
uni.showToast({
|
|
|
- title: '用户绑定成功!',
|
|
|
- icon: 'success'
|
|
|
+ title: '未获得token'
|
|
|
});
|
|
|
-
|
|
|
- this.showPop = false
|
|
|
+ } else {
|
|
|
+ this.access_token = res.data.access_token;
|
|
|
+
|
|
|
+ // 通过access_token换取用户信息
|
|
|
+ this.get_user_info();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 通过access_token换取用户信息
|
|
|
+ */
|
|
|
+ async get_user_info() {
|
|
|
+ const res = await this.$myRequest({
|
|
|
+ host: 'wecard',
|
|
|
+ url: '/connect/oauth/get-user-info',
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json'
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ "access_token": this.access_token
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res.data.errcode == 0 && res.data.errmsg == 'OK') {
|
|
|
+ try {
|
|
|
+ this.userinfo = res.data
|
|
|
+ this.$store.state.userinfo = this.userinfo
|
|
|
+ // 存储用户信息
|
|
|
+ uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
|
+ // 提示授权成功
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'success',
|
|
|
+ title: '授权成功',
|
|
|
+ duration: 800,
|
|
|
+ success: (res) => {
|
|
|
+ this.my_display = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
- title: res.data.mess,
|
|
|
- icon: 'success'
|
|
|
+ title: '未获得用户信息,请领取校园卡并激活',
|
|
|
+ duration: 3000
|
|
|
});
|
|
|
-
|
|
|
- this.showPop = true
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
- * 查询用户
|
|
|
+ * 检查数据库中是否有该用户信息
|
|
|
*/
|
|
|
- async selectUser(code) {
|
|
|
+ async chk_user_is_in_db() {
|
|
|
const res = await this.$myRequest({
|
|
|
host: this.ceshi,
|
|
|
- url: '/HotWaters/wpget_stu.action',
|
|
|
+ url: '/',
|
|
|
method: 'POST',
|
|
|
header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ 'content-type': 'application/json'
|
|
|
},
|
|
|
data: {
|
|
|
- code: code
|
|
|
+ "access_token": this.access_token
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
- // console.log(res);
|
|
|
- if (res.data.mess == '未查询到用户信息') {
|
|
|
- this.showPop = true
|
|
|
- } else {
|
|
|
- this.showPop = false
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res) {
|
|
|
+ console.log(res);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -243,81 +315,27 @@
|
|
|
color: #333333;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- .banding-bg {
|
|
|
- display: flex;
|
|
|
- justify-content: center;
|
|
|
- align-items: center;
|
|
|
- position: fixed;
|
|
|
- width: 750rpx;
|
|
|
- height: 1500rpx;
|
|
|
- background: rgba(0, 0, 0, 0.5);
|
|
|
-
|
|
|
- .banding-model {
|
|
|
+
|
|
|
+ .reset {
|
|
|
+ position: fixed;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
- justify-content: flex-start;
|
|
|
- background-color: #FFFFFF;
|
|
|
- position: fixed;
|
|
|
- left: 25rpx;
|
|
|
- top: 300rpx;
|
|
|
- width: 650rpx;
|
|
|
- border-radius: 15rpx;
|
|
|
- padding: 30rpx;
|
|
|
-
|
|
|
- .title-model {
|
|
|
- font-size: 46rpx;
|
|
|
- font-weight: bold;
|
|
|
- padding: 20rpx 0 20rpx 30rpx;
|
|
|
- }
|
|
|
-
|
|
|
- .lineGroup-model {
|
|
|
- display: flex;
|
|
|
- flex-direction: row;
|
|
|
- box-shadow: none;
|
|
|
- border-bottom: 1px solid #c2c2c2;
|
|
|
- font-size: 38rpx;
|
|
|
- white-space: nowrap;
|
|
|
-
|
|
|
- .label-icon-model {
|
|
|
- display: flex;
|
|
|
- flex-direction: row;
|
|
|
- align-items: center;
|
|
|
- font-size: 58rpx;
|
|
|
- width: 88rpx;
|
|
|
- height: 108rpx;
|
|
|
- line-height: 108rpx;
|
|
|
- color: $my-color-primary;
|
|
|
- margin: 22rpx 0 0 50rpx;
|
|
|
- }
|
|
|
-
|
|
|
- .input-model {
|
|
|
- margin-top: 20rpx;
|
|
|
- color: #00c200;
|
|
|
- height: 108rpx;
|
|
|
- line-height: 108rpx;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- .btn-model {
|
|
|
- display: flex;
|
|
|
- justify-content: center;
|
|
|
- align-items: center;
|
|
|
- padding: 50rpx;
|
|
|
-
|
|
|
- .btn {
|
|
|
- width: 280rpx;
|
|
|
- height: 110rpx;
|
|
|
- line-height: 110rpx;
|
|
|
- background-color: $my-color-primary;
|
|
|
- border-radius: 15rpx;
|
|
|
- font-size: 38rpx;
|
|
|
- text-align: center;
|
|
|
- color: #FFFFFF;
|
|
|
- }
|
|
|
+ align-items: flex-end;
|
|
|
+ right: 55rpx;
|
|
|
+ bottom: 55rpx;
|
|
|
+ font-family: Microsoft YaHei-3970(82674968);
|
|
|
+ color: #333333;
|
|
|
+
|
|
|
+ .icon-zhongzhi {
|
|
|
+ margin: 0 auto;
|
|
|
+ padding-top: 20rpx;
|
|
|
+ color: $my-color-primary;
|
|
|
+ width: 90rpx;
|
|
|
+ height: 70rpx;
|
|
|
+ font-size: 80rpx;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
</style>
|