| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <template>
- <view @click="showLog">
- </view>
- </template>
- <script>
- import { choseType } from '@/api/index.js';
- import {
- mapMutations,
- mapState
- } from 'vuex';
- import {
- getUserInfo
- } from '@/api/login.js';
- // #ifdef H5
- import {
- wechatAuth
- } from '@/api/wx';
- // #endif
- // #ifdef MP-WEIXIN
- import {
- wechatMpAuth
- } from '@/api/wx';
- // #endif
- export default {
- computed: {
- ...mapState(['urlFile'])
- },
- onLoad(option) {
- let obj = this;
- // 判断是否需要保存定向地址
- // #ifdef H5
- this.loadH5()
- // #endif
- // #ifdef MP-WEIXIN
- this.loadMp(option)
- // #endif
- },
- methods: {
- ...mapMutations(['setUserInfo', 'login']),
- // #ifdef H5
- loadH5() {
- let obj = this;
- let url = window.location.href;
- let code = url.match(/code=([0-9]|[a-z]|[A-Z])*/g)[0].replace('code=', '');
- // 设置成功后修改当前页面
- history.replaceState({
- name: '首页'
- }, '首页', obj.urlFile + '/#/pages/user/user');
- let spread = uni.getStorageSync('spread') || '';
- wechatAuth({
- code: code,
- spread: spread,
- }).then(({
- data
- }) => {
- obj.wchatAuth(data);
- }).catch((e) => {
- console.log(e)
- });;
- },
- // #endif
- // #ifdef MP-WEIXIN
- loadMp(option) {
- let obj = this;
- // 获取登录授权页数据
- let user = obj.$api.prePage().userInfo;
- // #ifndef MP
- // 获取推广人id
- let spread_spid = uni.getStorageSync('spread') || '';
- // #endif
- // #ifdef MP
- // 小程序推广人
- let spread_code = uni.getStorageSync('spread_code') || '';
- // #endif
- wechatMpAuth({
- code: option.code,
- iv: user.target.iv,
- encryptedData: user.target.encryptedData,
- // #ifndef MP
- spread_spid: spread_spid,
- // #endif
- // #ifdef MP
- spread_code: spread_code
- // #endif
- }).then(({
- data
- }) => {
- obj.wchatAuth(data);
- }).catch((e) => {
- uni.showModal({
- title: '错误',
- content: JSON.stringify(e),
- showCancel: false,
- });
- });
- },
- // #endif
- wchatAuth(data) {
- let obj = this;
- // 保存token
- uni.setStorageSync('token', data.token);
- let path = uni.getStorageSync('present');
- // 获取用户基础信息
- getUserInfo({}).then(e => {
- obj.$log.addLog(e.data)
- obj.login();
- // 保存返回用户数据
- obj.setUserInfo(e.data);
- let chooseType = uni.getStorageSync('chooseType') || ''
- // 没有选择身份或没有填写身份信息
- if (e.data.ext_info == null) {
- if (!chooseType) {
- uni.navigateTo({
- url: '/pages/index/identity',
- fail() {
- uni.switchTab({
- url: '/pages/user/user',
- fail() {
- }
- })
- }
- });
- } else {
- // if (chooseType == 1) {
-
- // uni.navigateTo({
- // url: `/pages/public/PatRegister`
- // });
- // }
- // if (chooseType == 2) {
- // uni.navigateTo({
- // url: `/pages/public/DocRegister`
- // });
- // }
- // if (chooseType == 3) {
- // uni.navigateTo({
- // url: `/pages/public/MecRegister`
- // });
- // }
- choseType({
- type: chooseType*1
- })
- .then(function(e) {
- if (e.msg == '修改成功') {
- if (chooseType == 1) {
- uni.navigateTo({
- url: `/pages/public/PatRegister`
- });
- }
- if (chooseType == 2) {
- uni.navigateTo({
- url: `/pages/public/DocRegister`
- });
- }
- if (chooseType == 3) {
- uni.navigateTo({
- url: `/pages/public/MecRegister`
- });
- }
- }
- })
- .catch(e => {
- console.log(e);
- });
- }
- } else if (e.data.ext_info != null) {
- // 1是病人 2是医生 3是机构
- // 校验用户类型和入口是否一致
- if (!chooseType) {
- if(path.indexOf('expert') != -1) {
- uni.navigateTo({
- url: path
- })
- }
- uni.switchTab({
- url: '/pages/index/home',
- fail(e) {
- obj.$log.addLog('t4')
- uni.switchTab({
- url: '/pages/user/user',
- fail() {
- }
- })
- }
- })
- } else {
-
- if (e.data.type == 2) {
- uni.setTabBarItem({
- index: 0,
- text: '首页',
- iconPath: 'static/tabBar/tab-home.png',
- selectedIconPath: 'static/tabBar/tab-home-current.png'
- });
- uni.setTabBarItem({
- index: 1,
- text: '我的病人',
- iconPath: 'static/tabBar/tab-cate.png',
- selectedIconPath: 'static/tabBar/tab-cate-current.png',
- visible: true
- });
- uni.setTabBarItem({
- index: 2,
- text: '科普学习',
- iconPath: 'static/tabBar/tab-study.png',
- selectedIconPath: 'static/tabBar/tab-study-current.png',
- visible: false
- });
- uni.setTabBarItem({
- index: 3,
- text: '接单',
- iconPath: 'static/tabBar/jd.png',
- selectedIconPath: 'static/tabBar/jd-act.png',
- visible: true
- })
- uni.setTabBarItem({
- index: 4,
- text: '我的',
- iconPath: 'static/tabBar/tab-my.png',
- selectedIconPath: 'static/tabBar/tab-my-current.png'
- });
- }
- if (e.data.type == 3) {
- uni.setTabBarItem({
- index: 0,
- text: '首页',
- iconPath: 'static/tabBar/tab-home.png',
- selectedIconPath: 'static/tabBar/tab-home-current.png'
- });
- uni.setTabBarItem({
- index: 1,
- text: '咨询记录',
- iconPath: 'static/tabBar/tab-cate.png',
- selectedIconPath: 'static/tabBar/tab-cate-current.png',
- visible: true
- });
- uni.setTabBarItem({
- index: 2,
- text: '科普学习',
- iconPath: 'static/tabBar/tab-study.png',
- selectedIconPath: 'static/tabBar/tab-study-current.png',
- visible: false
- });
- uni.setTabBarItem({
- index: 3,
- text: '发布订单',
- iconPath: 'static/tabBar/jd.png',
- selectedIconPath: 'static/tabBar/jd-act.png',
- pagePath: '/pages/dd/dd',
- visible: true
- })
- uni.setTabBarItem({
- index: 4,
- text: '我的',
- iconPath: 'static/tabBar/tab-my.png',
- selectedIconPath: 'static/tabBar/tab-my-current.png'
- });
- }
- if (e.data.type == 1) {
- uni.setTabBarItem({
- index: 0,
- text: '首页',
- iconPath: 'static/tabBar/tab-home.png',
- selectedIconPath: 'static/tabBar/tab-home-current.png'
- });
- uni.setTabBarItem({
- index: 1,
- text: '咨询记录',
- iconPath: 'static/tabBar/tab-cate.png',
- selectedIconPath: 'static/tabBar/tab-cate-current.png',
- visible: true
- });
- uni.setTabBarItem({
- index: 2,
- text: '科普学习',
- iconPath: 'static/tabBar/tab-study.png',
- selectedIconPath: 'static/tabBar/tab-study-current.png',
- visible: false
- });
- uni.setTabBarItem({
- index: 3,
- text: '接单',
- iconPath: 'static/tabBar/jd.png',
- selectedIconPath: 'static/tabBar/jd-act.png',
- visible: false
- })
- uni.setTabBarItem({
- index: 4,
- text: '我的',
- iconPath: 'static/tabBar/tab-my.png',
- selectedIconPath: 'static/tabBar/tab-my-current.png.png'
- });
- }
- uni.switchTab({
- url: '/pages/index/home',
- fail(e) {
- obj.$log.addLog('t4')
- uni.switchTab({
- url: '/pages/user/user',
- fail() {
- }
- })
- }
- })
-
- }
- } else {
- obj.$log.addLog('t3')
- uni.switchTab({
- url: '/pages/index/home',
- fail() {
- uni.switchTab({
- url: '/pages/user/user',
- fail() {
- }
- })
- }
- })
- }
- }).catch((e) => {
- uni.showModal({
- title: '错误',
- content: JSON.stringify(e),
- showCancel: false,
- });
- });;
- },
- showLog() {
- let log = this.$log.getLog();
- uni.showModal({
- title: '日志',
- content: JSON.stringify(log),
- showCancel: false,
- });
- }
- }
- };
- </script>
- <style></style>
|