|
@@ -22,8 +22,8 @@
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view v-if="showLogin">
|
|
<view v-if="showLogin">
|
|
|
- <login :ocode="ocode" :appkey="appkey" scope="snsapi_userinfo" :visible="visible" @success="callback()"
|
|
|
|
|
- @cancel="callback()" @fail="callback()" />
|
|
|
|
|
|
|
+ <login :ocode="ocode" :appkey="appkey" scope="snsapi_userinfo" :visible="visible"
|
|
|
|
|
+ @success="login_success_callback()" @cancel="login_cancel_callback()" @fail="login_fail_callback()" />
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
@@ -33,24 +33,29 @@
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
ceshi: 'code',
|
|
ceshi: 'code',
|
|
|
- huanjing: '部署环境' ,// 部署环境是key,用来获取环境
|
|
|
|
|
|
|
+ huanjing: '部署环境', // 部署环境是key,用来获取环境
|
|
|
visible: false,
|
|
visible: false,
|
|
|
showLogin: true,
|
|
showLogin: true,
|
|
|
appkey: '5AA49F3E4CACA380',
|
|
appkey: '5AA49F3E4CACA380',
|
|
|
- sub_appid: '1015730314_1941301045',
|
|
|
|
|
appid: 'wx2fc3f45732fae5d3', // 获取用户信息
|
|
appid: 'wx2fc3f45732fae5d3', // 获取用户信息
|
|
|
ocode: '1015730314', // 获取用户信息
|
|
ocode: '1015730314', // 获取用户信息
|
|
|
app_secret: '58D34C81D82B35179ED896C4362B0FC0', // 获取用户信息
|
|
app_secret: '58D34C81D82B35179ED896C4362B0FC0', // 获取用户信息
|
|
|
my_display: false,
|
|
my_display: false,
|
|
|
- userinfo: {},
|
|
|
|
|
|
|
+ userinfo: '',
|
|
|
wxcode: '',
|
|
wxcode: '',
|
|
|
- access_token: ''
|
|
|
|
|
|
|
+ access_token: '',
|
|
|
|
|
+ code: '',
|
|
|
|
|
+ from: 0
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- onLoad() {
|
|
|
|
|
|
|
+ onLoad(options) {
|
|
|
|
|
+ console.log(options)
|
|
|
|
|
+ if (options && JSON.stringify(options) != '{}' && typeof(options.from) != 'undefined') {
|
|
|
|
|
+ this.from = options.from
|
|
|
|
|
+ }
|
|
|
// 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
|
|
// 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
|
|
|
this.isTestEnvironment()
|
|
this.isTestEnvironment()
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
this.has_user_info()
|
|
this.has_user_info()
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
@@ -90,7 +95,7 @@
|
|
|
*/
|
|
*/
|
|
|
has_user_info() {
|
|
has_user_info() {
|
|
|
try {
|
|
try {
|
|
|
- this.userinfo = this.$store.state.userinfo
|
|
|
|
|
|
|
+ this.userinfo = this.$store.state.userInfo
|
|
|
const value = uni.getStorageSync('userinfo_storage_key');
|
|
const value = uni.getStorageSync('userinfo_storage_key');
|
|
|
if (value == '') {
|
|
if (value == '') {
|
|
|
if (typeof(this.userinfo) == 'undefined' || JSON.stringify(this.userinfo) == '{}') {
|
|
if (typeof(this.userinfo) == 'undefined' || JSON.stringify(this.userinfo) == '{}') {
|
|
@@ -103,6 +108,7 @@
|
|
|
} else {
|
|
} else {
|
|
|
this.showLogin = false
|
|
this.showLogin = false
|
|
|
this.userinfo = value
|
|
this.userinfo = value
|
|
|
|
|
+ this.$store.state.userInfo = this.userinfo
|
|
|
this.my_display = true
|
|
this.my_display = true
|
|
|
}
|
|
}
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -124,7 +130,7 @@
|
|
|
this.userinfo = {}
|
|
this.userinfo = {}
|
|
|
this.my_display = false
|
|
this.my_display = false
|
|
|
}, 30)
|
|
}, 30)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
this.showLogin = true
|
|
this.showLogin = true
|
|
|
this.visible = true
|
|
this.visible = true
|
|
@@ -133,39 +139,79 @@
|
|
|
console.log(e)
|
|
console.log(e)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 授权回调
|
|
|
|
|
|
|
+ * 授权登陆q取消回调
|
|
|
|
|
+ */
|
|
|
|
|
+ login_cancel_callback() {
|
|
|
|
|
+ this.userinfo = {};
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ title: '需要先授权,请点击右下角【重新授权】按钮'
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 授权登陆q取消回调
|
|
|
*/
|
|
*/
|
|
|
- callback: function({
|
|
|
|
|
|
|
+ login_fail_callback() {
|
|
|
|
|
+ this.userinfo = {};
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: 'none',
|
|
|
|
|
+ title: '授权失败,请先领取校园卡、激活',
|
|
|
|
|
+ duration: 3000,
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '提示',
|
|
|
|
|
+ content: '是否将校园卡二维码,保存到相册?',
|
|
|
|
|
+ showCancel: false,
|
|
|
|
|
+ success: res => {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ // 出现二维码,用户扫描二维码添加校园卡、激活
|
|
|
|
|
+ uni.downloadFile({
|
|
|
|
|
+ url: 'https://www.ecjtuit.edu.cn/img/zs.jpg',
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ console.log(res);
|
|
|
|
|
+ if (res.statusCode === 200) {
|
|
|
|
|
+ uni.saveImageToPhotosAlbum({
|
|
|
|
|
+ filePath: res.tempFilePath,
|
|
|
|
|
+ success: function() {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: "保存成功",
|
|
|
|
|
+ icon: "none"
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: function() {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: "保存失败,请稍后重试",
|
|
|
|
|
+ icon: "none"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (res.cancel) {
|
|
|
|
|
+ console.log('用户点击取消');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 授权登陆成功回调
|
|
|
|
|
+ */
|
|
|
|
|
+ login_success_callback: function({
|
|
|
detail
|
|
detail
|
|
|
}) {
|
|
}) {
|
|
|
- // console.log(detail)
|
|
|
|
|
- // {wxcode: "7f7Qi9rN8zQ1nifQiysTZ3WIeIWlgcGk"}
|
|
|
|
|
- if (detail === undefined) {
|
|
|
|
|
- this.userinfo = {};
|
|
|
|
|
- uni.showToast({
|
|
|
|
|
- icon: 'success',
|
|
|
|
|
- title: '需要先授权'
|
|
|
|
|
- });
|
|
|
|
|
- } 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()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ wxcode = ""
|
|
|
|
|
+ } = detail
|
|
|
|
|
+
|
|
|
|
|
+ // 获取wxcode
|
|
|
|
|
+ this.wxcode = wxcode
|
|
|
|
|
+
|
|
|
|
|
+ // 通过wxcode换取access_token
|
|
|
|
|
+ this.get_access_token()
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
* 通过wxcode换取access_token
|
|
* 通过wxcode换取access_token
|
|
@@ -183,17 +229,17 @@
|
|
|
'app_key': this.appkey,
|
|
'app_key': this.appkey,
|
|
|
'app_secret': this.app_secret,
|
|
'app_secret': this.app_secret,
|
|
|
'grant_type': 'authorization_code',
|
|
'grant_type': 'authorization_code',
|
|
|
- 'redirect_uri': 'mnp://wx2fc3f45732fae5d3'
|
|
|
|
|
|
|
+ 'redirect_uri': 'mnp://' + this.appid
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (res.data.refresh_token == '' || typeof(res.data.refresh_token) == 'undefined') {
|
|
if (res.data.refresh_token == '' || typeof(res.data.refresh_token) == 'undefined') {
|
|
|
uni.showToast({
|
|
uni.showToast({
|
|
|
title: '未获得token'
|
|
title: '未获得token'
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
this.access_token = res.data.access_token;
|
|
this.access_token = res.data.access_token;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 通过access_token换取用户信息
|
|
// 通过access_token换取用户信息
|
|
|
this.get_user_info();
|
|
this.get_user_info();
|
|
|
}
|
|
}
|
|
@@ -213,22 +259,14 @@
|
|
|
"access_token": this.access_token
|
|
"access_token": this.access_token
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (res.data.errcode == 0 && res.data.errmsg == 'OK') {
|
|
if (res.data.errcode == 0 && res.data.errmsg == 'OK') {
|
|
|
try {
|
|
try {
|
|
|
this.userinfo = res.data
|
|
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
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.$store.state.userInfo = this.userinfo
|
|
|
|
|
+
|
|
|
|
|
+ // 获得code,然后去检查是否存在数据库中
|
|
|
|
|
+ this.getCode()
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
console.log(e)
|
|
console.log(e)
|
|
|
}
|
|
}
|
|
@@ -240,24 +278,71 @@
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 获得code
|
|
|
|
|
+ */
|
|
|
|
|
+ getCode() {
|
|
|
|
|
+ uni.login({
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ // console.log('reshui', res);
|
|
|
|
|
+ if (res.code) {
|
|
|
|
|
+ this.code = res.code
|
|
|
|
|
+
|
|
|
|
|
+ // 检查用户是否存在第三方库
|
|
|
|
|
+ this.chk_user_is_in_db()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ title: res.errMsg,
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ /**
|
|
|
* 检查数据库中是否有该用户信息
|
|
* 检查数据库中是否有该用户信息
|
|
|
*/
|
|
*/
|
|
|
async chk_user_is_in_db() {
|
|
async chk_user_is_in_db() {
|
|
|
const res = await this.$myRequest({
|
|
const res = await this.$myRequest({
|
|
|
|
|
+ // host: 'local',
|
|
|
host: this.ceshi,
|
|
host: this.ceshi,
|
|
|
- url: '/',
|
|
|
|
|
|
|
+ url: '/HotWaters/wpopenid.action',
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
header: {
|
|
header: {
|
|
|
- 'content-type': 'application/json'
|
|
|
|
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
},
|
|
},
|
|
|
data: {
|
|
data: {
|
|
|
- "access_token": this.access_token
|
|
|
|
|
|
|
+ "userinfo": JSON.stringify(this.userinfo),
|
|
|
|
|
+ "code": this.code
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- if (res) {
|
|
|
|
|
- console.log(res);
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // console.log(res);
|
|
|
|
|
+ if (res.data.code == 0 || res.data.code == 100) {
|
|
|
|
|
+ // 存储用户信息
|
|
|
|
|
+ uni.setStorageSync('userinfo_storage_key', this.userinfo)
|
|
|
|
|
+ // 提示授权成功
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: 'success',
|
|
|
|
|
+ title: '授权成功',
|
|
|
|
|
+ duration: 800,
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ this.my_display = true
|
|
|
|
|
+
|
|
|
|
|
+ if (this.from != 0) {
|
|
|
|
|
+ uni.navigateBack({
|
|
|
|
|
+ delta: 1
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: 'success',
|
|
|
|
|
+ title: '授权失败:' + res.data.mess,
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ this.my_display = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -315,7 +400,7 @@
|
|
|
color: #333333;
|
|
color: #333333;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
.reset {
|
|
.reset {
|
|
|
position: fixed;
|
|
position: fixed;
|
|
|
display: flex;
|
|
display: flex;
|
|
@@ -325,7 +410,7 @@
|
|
|
bottom: 55rpx;
|
|
bottom: 55rpx;
|
|
|
font-family: Microsoft YaHei-3970(82674968);
|
|
font-family: Microsoft YaHei-3970(82674968);
|
|
|
color: #333333;
|
|
color: #333333;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
.icon-zhongzhi {
|
|
.icon-zhongzhi {
|
|
|
margin: 0 auto;
|
|
margin: 0 auto;
|
|
|
padding-top: 20rpx;
|
|
padding-top: 20rpx;
|