boundPhone.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <view>
  3. <view class="index">
  4. <view class="index-top">
  5. 登录
  6. </view>
  7. <!-- <view class="index-title">
  8. 为了保护账号安全,需要绑定手机号
  9. </view> -->
  10. <view class="index-input index-phone">
  11. <input type="text" class="tel-input" v-model="tel" placeholder="请输入手机号">
  12. </view>
  13. <view v-if="showPsd" class="index-input index-yanzheng">
  14. <input type="text" password class="tel-input" v-model="password" placeholder="请输入密码">
  15. </view>
  16. <view v-else class="index-input index-yanzheng">
  17. <input type="text" class="yzm-input" v-model="verify" maxlength="6" placeholder="输入6位验证码">
  18. <view class="shu" />
  19. <text @tap="getYZM">{{countDown ? `${countDown}s` : '获取'}}</text>
  20. </view>
  21. <view class="index-tip">
  22. <text @click="changeType">{{ `${showPsd ? '验证码' : '密码'}登录` }}</text>
  23. </view>
  24. <view class="index-deal">
  25. <checkbox :checked="checked" @click="checked = !checked" color="#FF232C" style="transform:scale(0.6)" />
  26. <text>我已阅读并同意</text>
  27. <text class="red" @click="agreement">《大卫博士争霸赛许可及服务协议》</text>
  28. </view>
  29. <view class="index-btn" @click="$noMultipleClicks(submit)">
  30. 立即登录
  31. </view>
  32. <!-- <view class="index-bottom">
  33. 若绑定失败请联系你的客服
  34. </view> -->
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. mapState
  41. } from "vuex";
  42. import {
  43. api_getYZM,
  44. api_submitTelYZM,
  45. api_changeTel,
  46. getLogin
  47. } from '../../api.js'
  48. import privacyPopup from '../../components/privacyPopup.vue'
  49. export default {
  50. data() {
  51. return {
  52. showPsd: false,
  53. tel: '', //手机号
  54. verify: '', //验证码
  55. verify_key: '', //验证码 key
  56. checked: false,
  57. noClick: true,
  58. account: '',
  59. password: '',
  60. countDown: 0, //验证码已发送倒计时
  61. submiting: false,
  62. avatarUrl: '',
  63. // showPrivacy: getApp().globalData.showPrivacy,
  64. showPrivacy: true,
  65. }
  66. },
  67. components: {
  68. privacyPopup
  69. },
  70. computed: {
  71. ...mapState(['userServerInfo']),
  72. userWeixinInfo() { //用户微信信息
  73. return this.$store.state.userWeixinInfo
  74. }
  75. },
  76. onShow() {
  77. this.avatarUrl = this.userServerInfouni && this.userServerInfouni.avatar
  78. },
  79. watch: {
  80. verify(n) { //监听验证码输入,输入结束后且通过验证,收起手机软键盘
  81. if (n.match(/^\d{6}$/) && this.tel.match(/^1\d{10}$/)) {
  82. uni.hideKeyboard()
  83. }
  84. }
  85. },
  86. methods: {
  87. handleDisagree(e) {
  88. getApp().globalData.showPrivacy = true;
  89. this.innerShow = true
  90. },
  91. handleAgreePrivacyAuthorization(e) {
  92. getApp().globalData.showPrivacy = false;
  93. this.innerShow = false
  94. },
  95. openPrivacyContract() {
  96. wx.openPrivacyContract({
  97. success: res => {
  98. console.log('openPrivacyContract success')
  99. },
  100. fail: res => {
  101. console.error('openPrivacyContract fail', res)
  102. }
  103. })
  104. },
  105. changeType() {
  106. this.showPsd = !this.showPsd
  107. this.tel = ''
  108. this.verify = ''
  109. this.verify_key = ''
  110. this.account = ''
  111. this.password = ''
  112. },
  113. getuserinfo() { //获取用户信息
  114. uni.getUserInfo().then(([getUserWeixinInfoErr, userWeixinInfo]) => { //获取完成后
  115. if (getUserWeixinInfoErr) {
  116. return
  117. }
  118. // this.$store.commit('HIDEGETUSERINFOBUTTON') //隐藏透明按钮
  119. // let _this = this
  120. // this.$store.dispatch('onLaunch').then(()=> {
  121. // _this.init()
  122. // }) //触发初始化方法
  123. })
  124. },
  125. agreement() {
  126. uni.navigateTo({
  127. url: '../boundPhone/agreement'
  128. })
  129. },
  130. getYZM() { //点击发送验证码
  131. if (this.countDown) {
  132. return
  133. }
  134. if (this.tel.match(/^1\d{10}$/)) { //手机号校验
  135. if (this.countDown) { //如果正在倒计时,表示验证码已发送
  136. uni.showModal({
  137. content: "验证码已发送,请稍后重试",
  138. showCancel: false
  139. })
  140. } else { //发送网络请求
  141. if (!this.requesting) {
  142. this.requesting = true
  143. uni.showLoading({
  144. title: '加载中',
  145. mask: true
  146. })
  147. this.$ajax.get(`${api_getYZM}?phone=${this.tel}`).then(([, {
  148. data: res
  149. }]) => {
  150. this.requesting = false
  151. this.$hideLoading()
  152. if (res.code === 200) { //验证码发送成功,开始倒计时
  153. this.verify_key = res.data.verify_key
  154. uni.showModal({
  155. content: "验证码发送成功",
  156. showCancel: false
  157. })
  158. this.countDown = 90
  159. this.timer = setInterval(() => {
  160. this.countDown--
  161. if (!this.countDown) {
  162. this.countDown = 0
  163. clearInterval(this.timer)
  164. }
  165. }, 1111)
  166. } else if (res.code === 400) { //手机号不存在
  167. uni.showModal({
  168. title: '手机号不存在',
  169. content: '请确认手机号或联系上级进行信息确认',
  170. showCancel: false,
  171. confirmText: '确定',
  172. success: res => {
  173. if (res.confirm) {
  174. this.tel = ''
  175. }
  176. }
  177. })
  178. } else if (res.code === 600) { //手机号已注册
  179. uni.showModal({
  180. title: '手机号已注册',
  181. content: '请确认手机号是否输入正确',
  182. showCancel: false,
  183. confirmText: '确定',
  184. success: res => {
  185. if (res.confirm) {
  186. this.tel = ''
  187. }
  188. }
  189. })
  190. } else {
  191. uni.showModal({
  192. title: '提示',
  193. content: res.message,
  194. showCancel: false
  195. })
  196. }
  197. })
  198. }
  199. }
  200. } else { //手机号校验不通过,出现红色抖动文字提示用户
  201. uni.showModal({
  202. content: "请输入正确的手机号",
  203. showCancel: false
  204. })
  205. }
  206. },
  207. async pswSubmit() {
  208. this.account = this.tel
  209. if (this.account == '') {
  210. uni.showToast({
  211. title: '请输入账号',
  212. icon: 'none'
  213. })
  214. return false
  215. }
  216. if (this.password == '') {
  217. uni.showToast({
  218. title: '请输入密码',
  219. icon: 'none'
  220. })
  221. return false
  222. }
  223. if (this.checked === false) {
  224. uni.showToast({
  225. title: '请勾选服务协议',
  226. icon: 'none'
  227. })
  228. return false
  229. }
  230. const [, {
  231. code
  232. }] = await uni.login() //获取 code
  233. this.$ajax.post(getLogin, { //提交手机号 验证码 用户头像
  234. account: this.account,
  235. password: this.password,
  236. code
  237. }).then(([, {
  238. data: res
  239. }]) => {
  240. // setTimeout(() => {
  241. // this.$hideLoading()
  242. // this.submiting = false
  243. // }, 345)
  244. if (res.code === 200) {
  245. this.$store.commit('HIDEPHONE')
  246. uni.showToast({
  247. title: '登录成功'
  248. })
  249. uni.navigateBack({
  250. delta: 1
  251. });
  252. } else {
  253. // uni.showModal({
  254. // content: res.msg,
  255. // showCancel:false
  256. // })
  257. uni.showToast({
  258. title: res.msg,
  259. icon: 'none'
  260. })
  261. }
  262. })
  263. },
  264. async verifySubmit() {
  265. if (this.tel.match(/^1\d{10}$/) && this.verify.match(/^\d{6}$/)) { //是校验输入是否合法
  266. if (!this.submiting) {
  267. if (this.checked === false) {
  268. uni.showModal({
  269. content: "请勾选服务协议",
  270. showCancel: false
  271. })
  272. return false
  273. }
  274. this.submiting = true
  275. uni.showLoading({
  276. title: '',
  277. mask: true
  278. }) //显示loading
  279. const [, {
  280. code
  281. }] = await uni.login() //获取 code
  282. this.$ajax.post(this.changeTel ? api_changeTel : api_submitTelYZM, { //提交手机号 验证码 用户头像
  283. phone: this.tel,
  284. verify_code: this.verify,
  285. verify_key: this.verify_key,
  286. avatar: this.avatarUrl,
  287. code
  288. }).then(([, {
  289. data: res
  290. }]) => {
  291. setTimeout(() => {
  292. this.$hideLoading()
  293. this.submiting = false
  294. }, 345)
  295. if (res.code === 200) {
  296. uni.showToast({
  297. title: '登录成功'
  298. })
  299. this.$store.commit('HIDEPHONE')
  300. // this.$store.dispatch('onLaunch') //触发初始化方法
  301. uni.navigateBack({
  302. delta: 1
  303. });
  304. } else if (res.code === 300) {
  305. this.verify = ''
  306. uni.showModal({
  307. content: "验证码错误,请重新获取",
  308. showCancel: false
  309. })
  310. } else if (res.code === 400) {
  311. this.verify = ''
  312. uni.showModal({
  313. content: "验证码已超时,请重新输入",
  314. showCancel: false
  315. })
  316. } else if (res.code === 600) { // 表示用户已经绑定过手机号
  317. this.$store.commit('HIDEPHONE')
  318. uni.navigateBack({
  319. delta: 1
  320. });
  321. // this.$store.dispatch('onLaunch') //触发初始化方法
  322. } else {
  323. this.tel = ''
  324. this.verify = ''
  325. uni.showModal({
  326. content: "验证码或手机号无效,请重新输入",
  327. showCancel: false
  328. })
  329. }
  330. })
  331. }
  332. } else {
  333. uni.showModal({
  334. content: "请输入正确的手机号和验证码",
  335. showCancel: false
  336. })
  337. }
  338. },
  339. submit() { //点击提交
  340. this.showPsd ? this.pswSubmit() : this.verifySubmit()
  341. }
  342. }
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. .index {
  347. padding: 74rpx 68rpx;
  348. &-top {
  349. color: #333333;
  350. font-size: 60rpx;
  351. font-weight: bold;
  352. }
  353. &-title {
  354. font-size: 32rpx;
  355. color: #333333;
  356. margin-top: 15rpx;
  357. }
  358. &-input {
  359. width: 606rpx;
  360. height: 104rpx;
  361. padding: 30rpx 40rpx;
  362. background: #F8F8F8;
  363. border-radius: 8px;
  364. }
  365. &-phone {
  366. margin-top: 112rpx;
  367. }
  368. &-yanzheng {
  369. display: flex;
  370. justify-content: space-between;
  371. align-items: center;
  372. margin-top: 30rpx;
  373. .shu {
  374. width: 0rpx;
  375. height: 40rpx;
  376. border: 2rpx solid #CCCCCC;
  377. }
  378. text {
  379. width: 116rpx;
  380. line-height: 60rpx;
  381. text-align: center;
  382. border: 2rpx solid #FB231F;
  383. border-radius: 30rpx;
  384. font-size: 28rpx;
  385. font-weight: bold;
  386. color: #FB231F;
  387. }
  388. }
  389. &-tip {
  390. text-align: end;
  391. margin-top: 40rpx;
  392. }
  393. // &-yanzheng {
  394. // // display: flex;
  395. // // justify-content: space-between;
  396. // // align-items: center;
  397. // margin-top: 30rpx;
  398. // // .shu {
  399. // // width: 0rpx;
  400. // // height: 40rpx;
  401. // // border: 2rpx solid #CCCCCC;
  402. // // }
  403. // // text {
  404. // // font-size: 28rpx;
  405. // // font-weight: bold;
  406. // // color: #333333;
  407. // // }
  408. // }
  409. &-deal {
  410. margin: 160rpx 0 60rpx 0;
  411. font-size: 24rpx;
  412. .red {
  413. color: #FF232C;
  414. }
  415. }
  416. &-btn {
  417. color: #fff;
  418. font-size: 32rpx;
  419. width: 590rpx;
  420. line-height: 104rpx;
  421. text-align: center;
  422. background: linear-gradient(93deg, #FF232C 0%, #FF571B 100%);
  423. border-radius: 52rpx;
  424. margin: 0 auto;
  425. }
  426. &-bottom {
  427. margin-top: 160rpx;
  428. text-align: center;
  429. font-size: 28rpx;
  430. color: #333333;
  431. }
  432. }
  433. </style>