beifen.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view style="width: 100%;height: 100%;">
  3. <!-- logo -->
  4. <view style="height: 30vh;" class="flex justify-center align-center">
  5. <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/logo.png" style="width: 404rpx;height: 156rpx;"></image>
  6. </view>
  7. <!--
  8. 登录:
  9. 输入框: 手机号 验证码
  10. 按钮: 登录 一键授权 暂不登录
  11. 下划线: 注册账号 账号密码登录
  12. -->
  13. <!-- 输入框 -->
  14. <view style="height: 30vh;padding: 0 100rpx;">
  15. <!-- 手机号 -->
  16. <view style="padding-bottom: 36rpx;display: flex;border-bottom: 1rpx solid #E0E0E0;margin-bottom: 60rpx;">
  17. <!-- 图标 手机图标-->
  18. <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/phone.png" style="width: 32rpx;height: 32rpx;margin-right: 20rpx;"></image>
  19. <!-- 线条 方向是竖-->
  20. <view style="margin-right: 20rpx;">
  21. <u-line color="#D8D8D8" direction="col" />
  22. </view>
  23. <input v-model="phoneData" placeholder="请输入手机号" style="height: 28rpx;" />
  24. </view>
  25. <!-- 验证码 -->
  26. <view style="padding-bottom: 36rpx;display: flex;border-bottom: 1rpx solid #E0E0E0;margin-bottom: 60rpx" v-if="!ispwdlogin">
  27. <!-- 图标 手机图标-->
  28. <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/Verification.png" style="width: 32rpx;height: 32rpx;margin-right: 20rpx;"></image>
  29. <!-- 线条 方向是竖-->
  30. <view style="margin-right: 20rpx;">
  31. <u-line color="#D8D8D8" direction="col" />
  32. </view>
  33. <wInput v-model="verCode" type="number" maxlength="6" placeholder="请输入验证码" isShowCode ref="runCode" @setCode="getVerCode()"></wInput>
  34. </view>
  35. <!-- 密码 -->
  36. <view style="padding-bottom: 36rpx;display: flex;border-bottom: 1rpx solid #E0E0E0;margin-bottom: 60rpx" v-if="ispwdlogin">
  37. <!-- 图标 手机图标-->
  38. <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/password.png" style="width: 32rpx;height: 32rpx;margin-right: 20rpx;"></image>
  39. <!-- 线条 方向是竖-->
  40. <view style="margin-right: 20rpx;">
  41. <u-line color="#D8D8D8" direction="col" />
  42. </view>
  43. <input v-model="password" placeholder="请输入密码" :password="true" style="height: 28rpx;" />
  44. </view>
  45. </view>
  46. <!-- 按钮 -->
  47. <view style="height: 30vh;padding: 0 80rpx;">
  48. <!-- 登录 -->
  49. <u-button @click="startReg()" type="primary" shape="circle" :loading="isRotate" :custom-style="customStyle">登录</u-button>
  50. <view class="flex align-center justify-between" style="margin: 70rpx 0 100rpx 0;">
  51. <button :class="" open-type="getUserInfo" style="box-shadow: 0px 0px 16px 0px rgba(0, 0, 0, 0.08);border-radius: 60rpx;border: 0.3rpx solid #dedede;"
  52. @getuserinfo="getinfo">
  53. <view :class="rotate_loop" style="font-size: 30rpx;color: #84BB43;">
  54. <slot name="text">微信授权一键登录</slot>
  55. </view>
  56. </button>
  57. <button @click="toindex()" style="width: 45%;font-size: 30rpx;border-radius: 60rpx;box-shadow: 0px 0px 16px 0px rgba(0, 0, 0, 0.08);border: 0.3rpx solid #dedede;color: #7a7a7a;" :custom-style="customStyle" :class="buttonBorder">暂不登录</button>
  58. </view>
  59. <!-- <view class="flex align-center justify-between" style="margin: 70rpx 0 100rpx 0;">
  60. <u-button open-type="getUserInfo" @getuserInfo="getinfo" shape="circle" style="width: 50%;font-size: 30rpx;color:#84BB43;" :custom-style="customStyle"
  61. hair-line="false">微信授权一键登录</u-button>
  62. <u-button @click="toindex()" shape="circle" style="width: 45%;font-size: 30rpx;" hair-line="false">暂不登录</u-button>
  63. </view> -->
  64. <view class="flex align-center justify-between">
  65. <view style="width: 50%;text-align: center;">
  66. <text style="text-decoration:underline; color: #666666;" @click="goreg">注册账号</text>
  67. </view>
  68. <view style="width: 50%;text-align: center;">
  69. <text style="text-decoration:underline ; color: #666666;" @click="ispwd">{{ispwdlogin?'验证码':'账号密码'}}登录</text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. var _this;
  77. import wInput from '../../components/watch-input.vue' //input
  78. import wButton from '../../components/watch-button.vue' //button
  79. import request from '../../common/request.js'
  80. var user = require('../../common/user.js');
  81. import {
  82. mapState,
  83. mapMutations,
  84. mapGetters,
  85. mapActions
  86. } from 'vuex';
  87. import store from '@/store'
  88. import auth from '../../common/authorize.js'
  89. // import IMService from "../../common/goeasyimutil.js"
  90. export default {
  91. computed: {
  92. ...mapGetters({
  93. hasLogin: 'verifyJwt'
  94. }),
  95. ...mapState(['user'])
  96. },
  97. data() {
  98. return {
  99. //一键登录按钮样式
  100. customStyle: {
  101. boxShadow: '0px 0px 16px 0px rgba(0, 0, 0, 0.08)',
  102. },
  103. //logo图片 base64
  104. phoneData: '', // 用户/电话
  105. verCode: "", //验证码
  106. password: "", //密码
  107. ispwdlogin: false, //是否使用密码登录
  108. isRotate: false, //是否登录按钮加载旋转
  109. istrue: false,
  110. num: 1,
  111. imgitem: {
  112. istrue: false,
  113. name: "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
  114. },
  115. show: false,
  116. isphoneNum: false
  117. }
  118. },
  119. onLoad() {
  120. const jwt = store.getters['getJwt'];
  121. uni.checkSession({
  122. success() {
  123. uni.navigateTo({
  124. url: '../index/index'
  125. })
  126. return;
  127. },
  128. fail() {
  129. uni.navigateTo({
  130. url: "../doctor_related/doctor_info"
  131. })
  132. }
  133. })
  134. },
  135. components: {
  136. wInput,
  137. wButton,
  138. },
  139. mounted() {
  140. _this = this;
  141. },
  142. methods: {
  143. //验证码点击事件
  144. getVerCode: async function() {
  145. //获取验证码
  146. if (_this.phoneData.length != 11) {
  147. uni.showToast({
  148. icon: 'none',
  149. position: 'bottom',
  150. title: '手机号不正确'
  151. });
  152. return false;
  153. }
  154. console.log(_this.phoneData)
  155. let res = await this.$request.post("common/putverfiy", {
  156. 'phone': _this.phoneData
  157. });
  158. if (res.status == 0) {
  159. uni.setStorageSync('verfiyCode', res.data);
  160. uni.showToast({
  161. icon: 'none',
  162. position: 'bottom',
  163. title: '验证码发送,请查收'
  164. });
  165. this.$refs.runCode.$emit('runCode'); //触发倒计时(一般用于请求成功验证码后调用)
  166. setTimeout(function() {
  167. _this.$refs.runCode.$emit('runCode', 0); //假装模拟下需要 终止倒计时
  168. uni.showToast({
  169. icon: 'none',
  170. position: 'bottom',
  171. title: '模拟倒计时终止'
  172. });
  173. }, 3000)
  174. } else {
  175. uni.showToast({
  176. icon: 'none',
  177. position: 'bottom',
  178. title: '请求失败'
  179. });
  180. }
  181. },
  182. //点击登录
  183. startReg: async function() {
  184. //注册
  185. if (this.isRotate) {
  186. //判断是否加载中,避免重复点击请求
  187. return false;
  188. }
  189. if (this.phoneData.length != 11) {
  190. uni.showToast({
  191. icon: 'none',
  192. position: 'bottom',
  193. title: '手机号不正确'
  194. });
  195. return false;
  196. }
  197. if (this.ispwdlogin) {
  198. // 账号密码登陆
  199. if (this.password < 6) {
  200. uni.showToast({
  201. icon: 'none',
  202. position: 'bottom',
  203. title: '密码位数不低于6位'
  204. });
  205. return false;
  206. }
  207. // 发送登陆
  208. let res = await this.$request.post('common/passLogin', {
  209. 'phone': this.phoneData,
  210. 'password': this.password
  211. });
  212. if (res.status == 0) {
  213. uni.showToast({
  214. icon: 'none',
  215. position: 'bottom',
  216. title: '登陆成功'
  217. });
  218. store.commit('setJwt', res.data.token);
  219. store.commit('setUser', res.data);
  220. store.commit('login');
  221. // 写一个跳转到首页
  222. setTimeout(function() {
  223. uni.navigateBack({
  224. delta: 1
  225. })
  226. uni.switchTab({
  227. url: "../index/index"
  228. })
  229. }, 2000)
  230. return false;
  231. } else {
  232. uni.showToast({
  233. icon: 'none',
  234. position: 'bottom',
  235. title: res.message
  236. });
  237. return false;
  238. }
  239. } else {
  240. if (this.verCode.length != 4) {
  241. uni.showToast({
  242. icon: 'none',
  243. position: 'bottom',
  244. title: '验证码不正确'
  245. });
  246. return false;
  247. }
  248. let code = uni.getStorageSync('verfiyCode')
  249. if (code == null || code == '') {
  250. uni.showToast({
  251. icon: 'none',
  252. position: 'bottom',
  253. title: '验证码错误'
  254. });
  255. return false;
  256. } else {
  257. if (this.verCode == code) {
  258. // 发送登陆
  259. let res = await this.$request.post('common/phoneLogin', {
  260. 'phone': this.phoneData
  261. });
  262. if (res.status == 0) {
  263. uni.showToast({
  264. icon: 'none',
  265. position: 'bottom',
  266. title: '登陆成功'
  267. });
  268. uni.removeStorage('verfiyCode')
  269. store.commit('setJwt', res.data.token);
  270. store.commit('setUser', res.data);
  271. store.commit('login');
  272. // 写一个跳转到首页
  273. setTimeout(function() {
  274. uni.navigateBack({
  275. delta: 1
  276. })
  277. uni.switchTab({
  278. url: "../index/index"
  279. })
  280. }, 2000)
  281. return false;
  282. } else {
  283. uni.showToast({
  284. icon: 'none',
  285. position: 'bottom',
  286. title: res.message
  287. });
  288. return false;
  289. }
  290. } else {
  291. uni.showToast({
  292. icon: 'none',
  293. position: 'bottom',
  294. title: '验证码错误'
  295. });
  296. return false;
  297. }
  298. }
  299. }
  300. _this.isRotate = true
  301. setTimeout(function() {
  302. _this.isRotate = false
  303. }, 3000)
  304. },
  305. toindex() {
  306. uni.switchTab({
  307. url: "../index/index"
  308. })
  309. },
  310. goreg() {
  311. uni.navigateTo({
  312. url: "./reg"
  313. })
  314. },
  315. ispwd() {
  316. this.ispwdlogin = !this.ispwdlogin
  317. },
  318. // 一键登录
  319. getinfo: async function(e) {
  320. let that = this;
  321. let meToken = user.loginByWeixin(e.detail.userInfo).then(res => {
  322. console.log('返回的res',res)
  323. if (res.status == 0) {
  324. uni.showToast({
  325. title: "登录成功",
  326. icon: "none",
  327. duration: 2000
  328. })
  329. console.log(res.data);
  330. if (typeof res.data.token != 'undefined') {
  331. console.log('我登录来 !');
  332. getApp().globalData.imService = new IMService();
  333. let loginResult = getApp().globalData.imService.login({
  334. uuid: res.data.data.flag,
  335. name: res.data.data.name,
  336. avatar: res.data.data.avatar
  337. });
  338. if (loginResult) {
  339. //连接IM
  340. getApp().globalData.imService.connectIM();
  341. }
  342. store.commit('setJwt', res.data.token);
  343. store.commit('setUser', res.data);
  344. store.commit('login');
  345. uni.showToast({
  346. title: "登录成功",
  347. icon: "none",
  348. duration: 2000
  349. })
  350. setTimeout(function() {
  351. uni.navigateBack({
  352. delta: 1
  353. })
  354. uni.switchTab({
  355. url: "../index/index"
  356. })
  357. }, 2000)
  358. } else {
  359. that.session_key = res.data.session_key
  360. that.openid = res.data.openid
  361. that.show = true
  362. }
  363. }
  364. })
  365. },
  366. getPhoneNumber: async function(e) {
  367. let res = await this.$request.post("api/v2/common/getPhoneNumber", {
  368. iv: e.detail.iv,
  369. encryptedData: e.detail.encryptedData,
  370. session_key: this.session_key,
  371. openid: this.openid
  372. })
  373. this.show = false
  374. if (res.status == 0) {
  375. if (res.data.token) {
  376. store.commit('setJwt', res.data.token);
  377. store.commit('setUser', res.data);
  378. store.commit('login');
  379. uni.showToast({
  380. title: "登录成功",
  381. icon: "none",
  382. duration: 2000
  383. })
  384. // 写一个跳转到首页
  385. setTimeout(function() {
  386. uni.navigateBack({
  387. delta: 1
  388. })
  389. uni.switchTab({
  390. url: "../index/index"
  391. })
  392. }, 2000)
  393. }
  394. }
  395. }
  396. }
  397. }
  398. </script>
  399. <style>
  400. @import url("../../components/colorui/icon.css");
  401. @import url("./css/main.css");
  402. page {
  403. background-color: #fff;
  404. }
  405. </style>