123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <view>
- </view>
- </template>
- <script>
- import {
- getUserInfo
- } from '@/api/user.js';
- import {
- mapMutations,
- mapState
- } from 'vuex';
-
- import {
- wechatAuth
- } from '@/api/wx';
-
-
- import {
- wechatMpAuth
- } from '@/api/wx';
-
- export default {
- computed: {
- ...mapState(['urlFile'])
- },
- onLoad(option) {
- let obj = this;
-
-
- this.loadH5()
-
-
- this.loadMp(option)
-
- },
- methods: {
- ...mapMutations('user', ['login', 'setUserInfo', 'logout']),
-
- loadH5() {
- let obj = this;
- let url = window.location.href;
- let code = url.match(/code=([0-9]|[a-z]|[A-Z])*/g)[0].replace('code=', '');
- let spread = uni.getStorageSync('spread') || '';
- wechatAuth({
- code: code,
- spread: spread,
- }).then(({
- data
- }) => {
- obj.wchatAuth(data);
-
- history.replaceState({ name: '首页' }, '首页', obj.urlFile+'/pages/index/index');
- }).catch((e) => {
- uni.showModal({
- title: '错误',
- content: JSON.stringify(e),
- showCancel: false,
- });
- });;
- },
-
-
- loadMp(option) {
- let obj = this;
-
- let user = obj.$api.prePage().userInfo;
-
-
- let spread_spid = uni.getStorageSync('spread') || '';
-
-
-
- let spread_code = uni.getStorageSync('spread_code') || '';
-
- wechatMpAuth({
- code: option.code,
- iv: user.target.iv,
- encryptedData: user.target.encryptedData,
-
- spread_spid: spread_spid,
-
-
- spread_code: spread_code
-
- }).then(({
- data
- }) => {
- obj.wchatAuth(data);
- }).catch((e) => {
- uni.showModal({
- title: '错误',
- content: JSON.stringify(e),
- showCancel: false,
- });
- });
- },
-
- wchatAuth(data) {
- let obj = this;
-
- uni.setStorageSync('token', data.token);
-
- getUserInfo({}).then(e => {
- obj.login();
-
- obj.setUserInfo(e.data);
- let ur = uni.getStorageSync('present') || '/pages/index/index';
-
- if (ur == 'pages/product/product') {
- ur = '/pages/index/index'
- }
- if (!e.data.phone) {
- uni.showModal({
- title: '提示',
- content: '请先绑定手机号',
- showCancel: false,
- success: res => {
- if (res.confirm) {
- uni.navigateTo({
- url: '/pages/set/phone',
- });
- }
- },
- });
- } else {
- uni.switchTab({
- url: ur,
- fail(e) {
- uni.navigateTo({
- url: ur,
- fail(e) {
- uni.navigateTo({
- url: '/pages/index/index',
- });
- }
- });
- }
- });
- }
- }).catch((e) => {
- uni.showModal({
- title: '错误',
- content: JSON.stringify(e),
- showCancel: false,
- });
- });;
- }
- }
- };
- </script>
- <style></style>
|