redirect.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view @click="showLog">
  3. </view>
  4. </template>
  5. <script>
  6. import { choseType } from '@/api/index.js';
  7. import {
  8. mapMutations,
  9. mapState
  10. } from 'vuex';
  11. import {
  12. getUserInfo
  13. } from '@/api/login.js';
  14. // #ifdef H5
  15. import {
  16. wechatAuth
  17. } from '@/api/wx';
  18. // #endif
  19. // #ifdef MP-WEIXIN
  20. import {
  21. wechatMpAuth
  22. } from '@/api/wx';
  23. // #endif
  24. export default {
  25. computed: {
  26. ...mapState(['urlFile'])
  27. },
  28. onLoad(option) {
  29. let obj = this;
  30. // 判断是否需要保存定向地址
  31. // #ifdef H5
  32. this.loadH5()
  33. // #endif
  34. // #ifdef MP-WEIXIN
  35. this.loadMp(option)
  36. // #endif
  37. },
  38. methods: {
  39. ...mapMutations(['setUserInfo', 'login']),
  40. // #ifdef H5
  41. loadH5() {
  42. let obj = this;
  43. let url = window.location.href;
  44. let code = url.match(/code=([0-9]|[a-z]|[A-Z])*/g)[0].replace('code=', '');
  45. // 设置成功后修改当前页面
  46. history.replaceState({
  47. name: '首页'
  48. }, '首页', obj.urlFile + '/#/pages/user/user');
  49. let spread = uni.getStorageSync('spread') || '';
  50. wechatAuth({
  51. code: code,
  52. spread: spread,
  53. }).then(({
  54. data
  55. }) => {
  56. obj.wchatAuth(data);
  57. }).catch((e) => {
  58. console.log(e)
  59. });;
  60. },
  61. // #endif
  62. // #ifdef MP-WEIXIN
  63. loadMp(option) {
  64. let obj = this;
  65. // 获取登录授权页数据
  66. let user = obj.$api.prePage().userInfo;
  67. // #ifndef MP
  68. // 获取推广人id
  69. let spread_spid = uni.getStorageSync('spread') || '';
  70. // #endif
  71. // #ifdef MP
  72. // 小程序推广人
  73. let spread_code = uni.getStorageSync('spread_code') || '';
  74. // #endif
  75. wechatMpAuth({
  76. code: option.code,
  77. iv: user.target.iv,
  78. encryptedData: user.target.encryptedData,
  79. // #ifndef MP
  80. spread_spid: spread_spid,
  81. // #endif
  82. // #ifdef MP
  83. spread_code: spread_code
  84. // #endif
  85. }).then(({
  86. data
  87. }) => {
  88. obj.wchatAuth(data);
  89. }).catch((e) => {
  90. uni.showModal({
  91. title: '错误',
  92. content: JSON.stringify(e),
  93. showCancel: false,
  94. });
  95. });
  96. },
  97. // #endif
  98. wchatAuth(data) {
  99. let obj = this;
  100. // 保存token
  101. uni.setStorageSync('token', data.token);
  102. let path = uni.getStorageSync('present');
  103. // 获取用户基础信息
  104. getUserInfo({}).then(e => {
  105. obj.$log.addLog(e.data)
  106. obj.login();
  107. // 保存返回用户数据
  108. obj.setUserInfo(e.data);
  109. let chooseType = uni.getStorageSync('chooseType') || ''
  110. // 没有选择身份或没有填写身份信息
  111. if (e.data.ext_info == null) {
  112. if (!chooseType) {
  113. uni.navigateTo({
  114. url: '/pages/index/identity',
  115. fail() {
  116. uni.switchTab({
  117. url: '/pages/user/user',
  118. fail() {
  119. }
  120. })
  121. }
  122. });
  123. } else {
  124. // if (chooseType == 1) {
  125. // uni.navigateTo({
  126. // url: `/pages/public/PatRegister`
  127. // });
  128. // }
  129. // if (chooseType == 2) {
  130. // uni.navigateTo({
  131. // url: `/pages/public/DocRegister`
  132. // });
  133. // }
  134. // if (chooseType == 3) {
  135. // uni.navigateTo({
  136. // url: `/pages/public/MecRegister`
  137. // });
  138. // }
  139. choseType({
  140. type: chooseType*1
  141. })
  142. .then(function(e) {
  143. if (e.msg == '修改成功') {
  144. if (chooseType == 1) {
  145. uni.navigateTo({
  146. url: `/pages/public/PatRegister`
  147. });
  148. }
  149. if (chooseType == 2) {
  150. uni.navigateTo({
  151. url: `/pages/public/DocRegister`
  152. });
  153. }
  154. if (chooseType == 3) {
  155. uni.navigateTo({
  156. url: `/pages/public/MecRegister`
  157. });
  158. }
  159. }
  160. })
  161. .catch(e => {
  162. console.log(e);
  163. });
  164. }
  165. } else if (e.data.ext_info != null) {
  166. // 1是病人 2是医生 3是机构
  167. // 校验用户类型和入口是否一致
  168. if (!chooseType) {
  169. if(path.indexOf('expert') != -1) {
  170. uni.navigateTo({
  171. url: path
  172. })
  173. }
  174. uni.switchTab({
  175. url: '/pages/index/home',
  176. fail(e) {
  177. obj.$log.addLog('t4')
  178. uni.switchTab({
  179. url: '/pages/user/user',
  180. fail() {
  181. }
  182. })
  183. }
  184. })
  185. } else {
  186. if (e.data.type == 2) {
  187. uni.setTabBarItem({
  188. index: 0,
  189. text: '首页',
  190. iconPath: 'static/tabBar/tab-home.png',
  191. selectedIconPath: 'static/tabBar/tab-home-current.png'
  192. });
  193. uni.setTabBarItem({
  194. index: 1,
  195. text: '我的病人',
  196. iconPath: 'static/tabBar/tab-cate.png',
  197. selectedIconPath: 'static/tabBar/tab-cate-current.png',
  198. visible: true
  199. });
  200. uni.setTabBarItem({
  201. index: 2,
  202. text: '科普学习',
  203. iconPath: 'static/tabBar/tab-study.png',
  204. selectedIconPath: 'static/tabBar/tab-study-current.png',
  205. visible: false
  206. });
  207. uni.setTabBarItem({
  208. index: 3,
  209. text: '接单',
  210. iconPath: 'static/tabBar/jd.png',
  211. selectedIconPath: 'static/tabBar/jd-act.png',
  212. visible: true
  213. })
  214. uni.setTabBarItem({
  215. index: 4,
  216. text: '我的',
  217. iconPath: 'static/tabBar/tab-my.png',
  218. selectedIconPath: 'static/tabBar/tab-my-current.png'
  219. });
  220. }
  221. if (e.data.type == 3) {
  222. uni.setTabBarItem({
  223. index: 0,
  224. text: '首页',
  225. iconPath: 'static/tabBar/tab-home.png',
  226. selectedIconPath: 'static/tabBar/tab-home-current.png'
  227. });
  228. uni.setTabBarItem({
  229. index: 1,
  230. text: '咨询记录',
  231. iconPath: 'static/tabBar/tab-cate.png',
  232. selectedIconPath: 'static/tabBar/tab-cate-current.png',
  233. visible: true
  234. });
  235. uni.setTabBarItem({
  236. index: 2,
  237. text: '科普学习',
  238. iconPath: 'static/tabBar/tab-study.png',
  239. selectedIconPath: 'static/tabBar/tab-study-current.png',
  240. visible: false
  241. });
  242. uni.setTabBarItem({
  243. index: 3,
  244. text: '发布订单',
  245. iconPath: 'static/tabBar/jd.png',
  246. selectedIconPath: 'static/tabBar/jd-act.png',
  247. pagePath: '/pages/dd/dd',
  248. visible: true
  249. })
  250. uni.setTabBarItem({
  251. index: 4,
  252. text: '我的',
  253. iconPath: 'static/tabBar/tab-my.png',
  254. selectedIconPath: 'static/tabBar/tab-my-current.png'
  255. });
  256. }
  257. if (e.data.type == 1) {
  258. uni.setTabBarItem({
  259. index: 0,
  260. text: '首页',
  261. iconPath: 'static/tabBar/tab-home.png',
  262. selectedIconPath: 'static/tabBar/tab-home-current.png'
  263. });
  264. uni.setTabBarItem({
  265. index: 1,
  266. text: '咨询记录',
  267. iconPath: 'static/tabBar/tab-cate.png',
  268. selectedIconPath: 'static/tabBar/tab-cate-current.png',
  269. visible: true
  270. });
  271. uni.setTabBarItem({
  272. index: 2,
  273. text: '科普学习',
  274. iconPath: 'static/tabBar/tab-study.png',
  275. selectedIconPath: 'static/tabBar/tab-study-current.png',
  276. visible: false
  277. });
  278. uni.setTabBarItem({
  279. index: 3,
  280. text: '接单',
  281. iconPath: 'static/tabBar/jd.png',
  282. selectedIconPath: 'static/tabBar/jd-act.png',
  283. visible: false
  284. })
  285. uni.setTabBarItem({
  286. index: 4,
  287. text: '我的',
  288. iconPath: 'static/tabBar/tab-my.png',
  289. selectedIconPath: 'static/tabBar/tab-my-current.png.png'
  290. });
  291. }
  292. uni.switchTab({
  293. url: '/pages/index/home',
  294. fail(e) {
  295. obj.$log.addLog('t4')
  296. uni.switchTab({
  297. url: '/pages/user/user',
  298. fail() {
  299. }
  300. })
  301. }
  302. })
  303. }
  304. } else {
  305. obj.$log.addLog('t3')
  306. uni.switchTab({
  307. url: '/pages/index/home',
  308. fail() {
  309. uni.switchTab({
  310. url: '/pages/user/user',
  311. fail() {
  312. }
  313. })
  314. }
  315. })
  316. }
  317. }).catch((e) => {
  318. uni.showModal({
  319. title: '错误',
  320. content: JSON.stringify(e),
  321. showCancel: false,
  322. });
  323. });;
  324. },
  325. showLog() {
  326. let log = this.$log.getLog();
  327. uni.showModal({
  328. title: '日志',
  329. content: JSON.stringify(log),
  330. showCancel: false,
  331. });
  332. }
  333. }
  334. };
  335. </script>
  336. <style></style>