login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <image class="banner-img" src="/static/img/img019.png" mode="scaleToFill"></image>
  5. </view>
  6. <view class="loginTitle"><text>登录</text></view>
  7. <view class="login_text">
  8. <view class="login_input flex">
  9. <view class="login_img">
  10. <image src="/static/icon/img03.png"></image>
  11. </view>
  12. <view class="login_name"><input class="uni-input" v-model="username" focus placeholder="请输入手机号" />
  13. </view>
  14. </view>
  15. <view class="login_input flex">
  16. <view class="login_img">
  17. <image src="/static/icon/img04.png"></image>
  18. </view>
  19. <view class="login_name"><input class="uni-input" type="password" v-model="passward" focus
  20. placeholder="请输入密码" /></view>
  21. </view>
  22. <view><button type="green" class="uni-button uni-button-green" @click="toLogin">登录</button></view>
  23. <view><button type="green" class="uni-button uni-button-green uni-button-green-plain" plain="true"
  24. hover-class="none" @click="register">注册</button></view>
  25. <navigator url="./forget">
  26. <view class="forget">忘记密码</view>
  27. </navigator>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. mapState,
  34. mapMutations
  35. } from 'vuex';
  36. import {
  37. login,
  38. getUserInfo
  39. } from '@/api/login.js';
  40. export default {
  41. data() {
  42. return {
  43. username: '',
  44. passward: '',
  45. // #ifdef APP-PLUS
  46. // 保存当前是否为微信浏览器
  47. weixinB: false,
  48. // #endif
  49. chooseType: ''
  50. };
  51. },
  52. onLoad() {
  53. this.weixinB = uni.getStorageSync('weichatBrowser')
  54. this.chooseType = uni.getStorageSync('chooseType') || ''
  55. },
  56. methods: {
  57. ...mapMutations(['setUserInfo', 'login']),
  58. //登录
  59. async toLogin() {
  60. let obj = this;
  61. obj.logining = true;
  62. if (obj.username == '') {
  63. obj.$api.msg('请输入手机号');
  64. return;
  65. }
  66. if (obj.passward == '') {
  67. obj.$api.msg('请输入密码');
  68. return;
  69. }
  70. login({
  71. account: obj.username,
  72. password: obj.passward
  73. })
  74. .then(function(e) {
  75. console.log('登录数据', e)
  76. uni.setStorageSync('token', e.data.token);
  77. // console.log('打印---token',token);
  78. obj.userInfo();
  79. })
  80. .catch(function(e) {
  81. console.log(e);
  82. });
  83. },
  84. //获取用户信息
  85. userInfo() {
  86. let obj = this;
  87. getUserInfo({})
  88. .then(function(e) {
  89. obj.setUserInfo(e.data);
  90. // if(e.data.ext_info == null){
  91. // uni.navigateTo({
  92. // url: `/pages/index/identity`
  93. // });
  94. // }
  95. // if(e.data.ext_info != null){
  96. // // 1是病人 2是医生 3是机构
  97. // uni.switchTab({
  98. // url: `/pages/index/home`
  99. // })
  100. // }
  101. // 没有选择身份或没有填写身份信息
  102. if (e.data.ext_info == null) {
  103. if (!obj.chooseType) {
  104. uni.navigateTo({
  105. url: '/pages/index/identity',
  106. fail() {
  107. uni.switchTab({
  108. url: '/pages/user/user',
  109. fail() {
  110. }
  111. })
  112. }
  113. });
  114. } else {
  115. if (obj.chooseType == 1) {
  116. uni.navigateTo({
  117. url: `/pages/public/PatRegister`
  118. });
  119. }
  120. if (obj.chooseType == 2) {
  121. uni.navigateTo({
  122. url: `/pages/public/DocRegister`
  123. });
  124. }
  125. if (obj.chooseType == 3) {
  126. uni.navigateTo({
  127. url: `/pages/public/MecRegister`
  128. });
  129. }
  130. }
  131. } else if (e.data.ext_info != null) {
  132. // 1是病人 2是医生 3是机构
  133. // 校验用户类型和入口是否一致
  134. if (e.data.type != obj.chooseType) {
  135. uni.showModal({
  136. title: '提示',
  137. content: '您当前的用户类型和入口类型不一致,请选择相应的入口进入!',
  138. success: function(res) {
  139. setTimeout(function() {
  140. //安卓手机
  141. document.addEventListener(
  142. "WeixinJSBridgeReady",
  143. function() {
  144. WeixinJSBridge.call("closeWindow");
  145. },
  146. false
  147. );
  148. //ios手机
  149. WeixinJSBridge.call("closeWindow");
  150. }, 100);
  151. }
  152. })
  153. } else {
  154. if (e.data.type == 2) {
  155. uni.setTabBarItem({
  156. index: 0,
  157. text: '首页',
  158. iconPath: 'static/tabBar/tab-home.png',
  159. selectedIconPath: 'static/tabBar/tab-home-current.png'
  160. });
  161. uni.setTabBarItem({
  162. index: 1,
  163. text: '我的病人',
  164. iconPath: 'static/tabBar/tab-cate.png',
  165. selectedIconPath: 'static/tabBar/tab-cate-current.png',
  166. visible: true
  167. });
  168. uni.setTabBarItem({
  169. index: 2,
  170. text: '科普学习',
  171. iconPath: 'static/tabBar/tab-study.png',
  172. selectedIconPath: 'static/tabBar/tab-study-current.png',
  173. visible: false
  174. });
  175. uni.setTabBarItem({
  176. index: 3,
  177. text: '接单',
  178. iconPath: 'static/tabBar/jd.png',
  179. selectedIconPath: 'static/tabBar/jd-act.png',
  180. visible: true
  181. })
  182. uni.setTabBarItem({
  183. index: 4,
  184. text: '我的',
  185. iconPath: 'static/tabBar/tab-my.png',
  186. selectedIconPath: 'static/tabBar/tab-my-current.png'
  187. });
  188. }
  189. if (e.data.type == 3) {
  190. uni.setTabBarItem({
  191. index: 0,
  192. text: '首页',
  193. iconPath: 'static/tabBar/tab-home.png',
  194. selectedIconPath: 'static/tabBar/tab-home-current.png'
  195. });
  196. uni.setTabBarItem({
  197. index: 1,
  198. text: '咨询记录',
  199. iconPath: 'static/tabBar/tab-cate.png',
  200. selectedIconPath: 'static/tabBar/tab-cate-current.png',
  201. visible: true
  202. });
  203. uni.setTabBarItem({
  204. index: 2,
  205. text: '科普学习',
  206. iconPath: 'static/tabBar/tab-study.png',
  207. selectedIconPath: 'static/tabBar/tab-study-current.png',
  208. visible: false
  209. });
  210. uni.setTabBarItem({
  211. index: 3,
  212. text: '发布订单',
  213. iconPath: 'static/tabBar/jd.png',
  214. selectedIconPath: 'static/tabBar/jd-act.png',
  215. pagePath: '/pages/dd/dd',
  216. visible: true
  217. })
  218. uni.setTabBarItem({
  219. index: 4,
  220. text: '我的',
  221. iconPath: 'static/tabBar/tab-my.png',
  222. selectedIconPath: 'static/tabBar/tab-my-current.png'
  223. });
  224. }
  225. if (e.data.type == 1) {
  226. uni.setTabBarItem({
  227. index: 0,
  228. text: '首页',
  229. iconPath: 'static/tabBar/tab-home.png',
  230. selectedIconPath: 'static/tabBar/tab-home-current.png'
  231. });
  232. uni.setTabBarItem({
  233. index: 1,
  234. text: '咨询记录',
  235. iconPath: 'static/tabBar/tab-cate.png',
  236. selectedIconPath: 'static/tabBar/tab-cate-current.png',
  237. visible: true
  238. });
  239. uni.setTabBarItem({
  240. index: 2,
  241. text: '科普学习',
  242. iconPath: 'static/tabBar/tab-study.png',
  243. selectedIconPath: 'static/tabBar/tab-study-current.png',
  244. visible: true
  245. });
  246. uni.setTabBarItem({
  247. index: 3,
  248. text: '接单',
  249. iconPath: 'static/tabBar/jd.png',
  250. selectedIconPath: 'static/tabBar/jd-act.png',
  251. visible: false
  252. })
  253. uni.setTabBarItem({
  254. index: 4,
  255. text: '我的',
  256. iconPath: 'static/tabBar/tab-my.png',
  257. selectedIconPath: 'static/tabBar/tab-my-current.png.png'
  258. });
  259. }
  260. uni.switchTab({
  261. url: '/pages/index/home',
  262. fail(e) {
  263. obj.$log.addLog('t4')
  264. uni.switchTab({
  265. url: '/pages/user/user',
  266. fail() {
  267. }
  268. })
  269. }
  270. })
  271. }
  272. } else {
  273. obj.$log.addLog('t3')
  274. uni.switchTab({
  275. url: '/pages/index/home',
  276. fail() {
  277. uni.switchTab({
  278. url: '/pages/user/user',
  279. fail() {
  280. }
  281. })
  282. }
  283. })
  284. }
  285. })
  286. .catch(function(e) {
  287. console.log(e)
  288. });
  289. },
  290. //跳转注册页
  291. register() {
  292. uni.navigateTo({
  293. url: `/pages/public/register`
  294. });
  295. },
  296. //跳转忘记密码
  297. forget() {
  298. uni.navigateTo({
  299. url: `/pages/public/forget`
  300. });
  301. },
  302. // 后退
  303. navBack() {
  304. uni.navigateBack();
  305. }
  306. }
  307. };
  308. </script>
  309. <style lang="scss">
  310. page {
  311. height: 100%;
  312. }
  313. .container {
  314. width: 100%;
  315. height: 100%;
  316. background-size: 100%;
  317. }
  318. .container_text {
  319. width: 100%;
  320. height: 500rpx;
  321. top: 0rpx;
  322. image {
  323. width: 100%;
  324. }
  325. }
  326. .login_text {
  327. margin: auto 30rpx;
  328. position: relative;
  329. padding: 100rpx 102rpx;
  330. background-color: #ffffff;
  331. margin-top: -180rpx;
  332. border-radius: 20rpx;
  333. .login_input {
  334. border-bottom: 1px solid #f0f0f0;
  335. margin-bottom: 65rpx;
  336. .login_img image {
  337. height: 35rpx;
  338. width: 29rpx;
  339. margin-right: 20rpx;
  340. }
  341. .uni-input {
  342. text-align: left;
  343. width: 470rpx;
  344. font-size: 28rpx !important;
  345. }
  346. .login_name {
  347. color: #333333;
  348. }
  349. }
  350. .other {
  351. margin-top: 60rpx;
  352. .fenge {
  353. width: 30%;
  354. height: 2rpx;
  355. background-color: #eeeeee;
  356. }
  357. .qita {
  358. font-size: 28rpx;
  359. color: #999999;
  360. }
  361. }
  362. .weixin {
  363. width: 75rpx;
  364. height: 75rpx;
  365. margin: 25rpx auto;
  366. }
  367. .weixin image {
  368. width: 100%;
  369. height: 100%;
  370. }
  371. .weixin_text {
  372. text-align: center;
  373. font-size: 28rpx;
  374. color: #999999;
  375. }
  376. .forget {
  377. font-size: 28rpx;
  378. width: 100%;
  379. text-align: right;
  380. color: #999999;
  381. }
  382. .uni-button-green {
  383. color: #ffffff;
  384. background-color: #6786FB;
  385. margin: 40rpx 10rpx;
  386. border-radius: 50rpx;
  387. }
  388. .uni-button-green-plain {
  389. border: 1px solid #6786FB;
  390. margin: 40rpx 10rpx;
  391. border-radius: 50rpx;
  392. color: #6786FB;
  393. background-color: #ffffff;
  394. }
  395. .uni-button {
  396. height: 85rpx;
  397. line-height: 85rpx;
  398. }
  399. }
  400. .loginTitle {
  401. position: absolute;
  402. top: 250rpx;
  403. width: 100%;
  404. text-align: center;
  405. color: white;
  406. font-size: 40rpx;
  407. }
  408. </style>