|
@@ -1,5 +1,7 @@
|
|
|
<script>
|
|
|
import Vue from 'vue'
|
|
|
+ import BASE_URL from './config.js'
|
|
|
+ import {mapActions} from 'vuex'
|
|
|
export default {
|
|
|
onLaunch: function() {
|
|
|
uni.getSystemInfo({
|
|
@@ -18,7 +20,7 @@
|
|
|
let custom = wx.getMenuButtonBoundingClientRect();
|
|
|
Vue.prototype.Custom = custom;
|
|
|
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
|
|
|
- // #endif
|
|
|
+ // #endif
|
|
|
|
|
|
// #ifdef MP-ALIPAY
|
|
|
Vue.prototype.StatusBar = e.statusBarHeight;
|
|
@@ -110,7 +112,86 @@
|
|
|
},
|
|
|
onHide: function() {
|
|
|
console.log('App Hide')
|
|
|
- }
|
|
|
+ },
|
|
|
+ created: async function() {
|
|
|
+ // 获取 URL 中的 code 参数
|
|
|
+ const urlParams = new URLSearchParams(window.location.search);
|
|
|
+ const code = urlParams.get('code');
|
|
|
+
|
|
|
+ console.log('传入 code -------');
|
|
|
+ console.log(code);
|
|
|
+
|
|
|
+ if (code) {
|
|
|
+ try {
|
|
|
+ // 发起请求获取用户信息
|
|
|
+ const [err, res] = await uni.request({
|
|
|
+ url: BASE_URL + `/flowable-server/app/proxy?appid=wxa79f618dcaf992f7&secret=24f99f0d9ed67b9078cd545be50f9ccb&code=` + code,
|
|
|
+ method: 'GET'
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res && res.statusCode === 200) {
|
|
|
+ console.log('用户信息获取成功-----------');
|
|
|
+ const data = res.data;
|
|
|
+ console.log(data);
|
|
|
+ console.log(data.openId);
|
|
|
+ // 将微信用户的 openId 存到本地
|
|
|
+ uni.setStorageSync('openId', data.openId);
|
|
|
+ console.log('getStorageSync-> ', uni.getStorageSync('openId'));
|
|
|
+ } else {
|
|
|
+ console.error('获取用户信息失败:', res.data);
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.error('请求失败:', err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断当前微信号的openId 是否已经存入到数据库了,如果存入了,那么就直接通过openId匹配登录,否则就进入登录页面
|
|
|
+ const flag = true;
|
|
|
+ const localOpenId = uni.getStorageSync('openId');
|
|
|
+ if (localOpenId) {
|
|
|
+ try {
|
|
|
+ // 发起请求获取库中的openId
|
|
|
+ const [err, res] = await uni.request({
|
|
|
+ url: BASE_URL + `/system-server/sys/user/allOpenIds`,
|
|
|
+ method: 'GET'
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res && res.statusCode === 200) {
|
|
|
+ const data = res.data;
|
|
|
+ console.log('allOpenIds:', data);
|
|
|
+ // 确保 data 是数组
|
|
|
+ if (Array.isArray(data) && data.includes(localOpenId)) {
|
|
|
+ // 包含的话,则直接根据 openId来实现登录
|
|
|
+ console.log(`data 包含 openId: ${localOpenId}`);
|
|
|
+ const [err, res] = await uni.request({
|
|
|
+ url: BASE_URL + `/auth-server/user/sys/wxLogin`,
|
|
|
+ method: 'POST',
|
|
|
+ data: { openId: localOpenId },
|
|
|
+ header: {
|
|
|
+ 'domain': 'ydddl'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (res && res.statusCode === 200) {
|
|
|
+ this.$store.commit('SET_TOKEN',res.data.token);
|
|
|
+ await this.refreshUserInfo();
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '../index/index',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.error('请求失败:', err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ console.log('进来了');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapActions(['refreshUserInfo']),
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
</script>
|