boundPhone.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. changeType() {
  88. this.showPsd = !this.showPsd
  89. this.tel = ''
  90. this.verify = ''
  91. this.verify_key = ''
  92. this.account = ''
  93. this.password = ''
  94. },
  95. getuserinfo() { //获取用户信息
  96. uni.getUserInfo().then(([getUserWeixinInfoErr, userWeixinInfo]) => { //获取完成后
  97. if (getUserWeixinInfoErr) {
  98. return
  99. }
  100. // this.$store.commit('HIDEGETUSERINFOBUTTON') //隐藏透明按钮
  101. // let _this = this
  102. // this.$store.dispatch('onLaunch').then(()=> {
  103. // _this.init()
  104. // }) //触发初始化方法
  105. })
  106. },
  107. agreement() {
  108. uni.navigateTo({
  109. url: '../boundPhone/agreement'
  110. })
  111. },
  112. getYZM() { //点击发送验证码
  113. if (this.countDown) {
  114. return
  115. }
  116. if (this.tel.match(/^1\d{10}$/)) { //手机号校验
  117. if (this.countDown) { //如果正在倒计时,表示验证码已发送
  118. uni.showModal({
  119. content: "验证码已发送,请稍后重试",
  120. showCancel: false
  121. })
  122. } else { //发送网络请求
  123. if (!this.requesting) {
  124. this.requesting = true
  125. uni.showLoading({
  126. title: '加载中',
  127. mask: true
  128. })
  129. this.$ajax.get(`${api_getYZM}?phone=${this.tel}`).then(([, {
  130. data: res
  131. }]) => {
  132. this.requesting = false
  133. this.$hideLoading()
  134. if (res.code === 200) { //验证码发送成功,开始倒计时
  135. this.verify_key = res.data.verify_key
  136. uni.showModal({
  137. content: "验证码发送成功",
  138. showCancel: false
  139. })
  140. this.countDown = 90
  141. this.timer = setInterval(() => {
  142. this.countDown--
  143. if (!this.countDown) {
  144. this.countDown = 0
  145. clearInterval(this.timer)
  146. }
  147. }, 1111)
  148. } else if (res.code === 400) { //手机号不存在
  149. uni.showModal({
  150. title: '手机号不存在',
  151. content: '请确认手机号或联系上级进行信息确认',
  152. showCancel: false,
  153. confirmText: '确定',
  154. success: res => {
  155. if (res.confirm) {
  156. this.tel = ''
  157. }
  158. }
  159. })
  160. } else if (res.code === 600) { //手机号已注册
  161. uni.showModal({
  162. title: '手机号已注册',
  163. content: '请确认手机号是否输入正确',
  164. showCancel: false,
  165. confirmText: '确定',
  166. success: res => {
  167. if (res.confirm) {
  168. this.tel = ''
  169. }
  170. }
  171. })
  172. } else {
  173. uni.showModal({
  174. title: '提示',
  175. content: res.message,
  176. showCancel: false
  177. })
  178. }
  179. })
  180. }
  181. }
  182. } else { //手机号校验不通过,出现红色抖动文字提示用户
  183. uni.showModal({
  184. content: "请输入正确的手机号",
  185. showCancel: false
  186. })
  187. }
  188. },
  189. async pswSubmit() {
  190. this.account = this.tel
  191. if (this.account == '') {
  192. uni.showToast({
  193. title: '请输入账号',
  194. icon: 'none'
  195. })
  196. return false
  197. }
  198. if (this.password == '') {
  199. uni.showToast({
  200. title: '请输入密码',
  201. icon: 'none'
  202. })
  203. return false
  204. }
  205. if (this.checked === false) {
  206. uni.showToast({
  207. title: '请勾选服务协议',
  208. icon: 'none'
  209. })
  210. return false
  211. }
  212. const [, {
  213. code
  214. }] = await uni.login() //获取 code
  215. this.$ajax.post(getLogin, { //提交手机号 验证码 用户头像
  216. account: this.account,
  217. password: this.password,
  218. code
  219. }).then(([, {
  220. data: res
  221. }]) => {
  222. // setTimeout(() => {
  223. // this.$hideLoading()
  224. // this.submiting = false
  225. // }, 345)
  226. if (res.code === 200) {
  227. this.$store.commit('HIDEPHONE')
  228. uni.showToast({
  229. title: '登录成功'
  230. })
  231. uni.navigateBack({
  232. delta: 1
  233. });
  234. } else {
  235. // uni.showModal({
  236. // content: res.msg,
  237. // showCancel:false
  238. // })
  239. uni.showToast({
  240. title: res.msg,
  241. icon: 'none'
  242. })
  243. }
  244. })
  245. },
  246. async verifySubmit() {
  247. if (this.tel.match(/^1\d{10}$/) && this.verify.match(/^\d{6}$/)) { //是校验输入是否合法
  248. if (!this.submiting) {
  249. if (this.checked === false) {
  250. uni.showModal({
  251. content: "请勾选服务协议",
  252. showCancel: false
  253. })
  254. return false
  255. }
  256. this.submiting = true
  257. uni.showLoading({
  258. title: '',
  259. mask: true
  260. }) //显示loading
  261. const [, {
  262. code
  263. }] = await uni.login() //获取 code
  264. this.$ajax.post(this.changeTel ? api_changeTel : api_submitTelYZM, { //提交手机号 验证码 用户头像
  265. phone: this.tel,
  266. verify_code: this.verify,
  267. verify_key: this.verify_key,
  268. avatar: this.avatarUrl,
  269. code
  270. }).then(([, {
  271. data: res
  272. }]) => {
  273. setTimeout(() => {
  274. this.$hideLoading()
  275. this.submiting = false
  276. }, 345)
  277. if (res.code === 200) {
  278. uni.showToast({
  279. title: '登录成功'
  280. })
  281. this.$store.commit('HIDEPHONE')
  282. // this.$store.dispatch('onLaunch') //触发初始化方法
  283. uni.navigateBack({
  284. delta: 1
  285. });
  286. } else if (res.code === 300) {
  287. this.verify = ''
  288. uni.showModal({
  289. content: "验证码错误,请重新获取",
  290. showCancel: false
  291. })
  292. } else if (res.code === 400) {
  293. this.verify = ''
  294. uni.showModal({
  295. content: "验证码已超时,请重新输入",
  296. showCancel: false
  297. })
  298. } else if (res.code === 600) { // 表示用户已经绑定过手机号
  299. this.$store.commit('HIDEPHONE')
  300. uni.navigateBack({
  301. delta: 1
  302. });
  303. // this.$store.dispatch('onLaunch') //触发初始化方法
  304. } else {
  305. this.tel = ''
  306. this.verify = ''
  307. uni.showModal({
  308. content: "验证码或手机号无效,请重新输入",
  309. showCancel: false
  310. })
  311. }
  312. })
  313. }
  314. } else {
  315. uni.showModal({
  316. content: "请输入正确的手机号和验证码",
  317. showCancel: false
  318. })
  319. }
  320. },
  321. submit() { //点击提交
  322. this.showPsd ? this.pswSubmit() : this.verifySubmit()
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="scss" scoped>
  328. .index {
  329. padding: 74rpx 68rpx;
  330. &-top {
  331. color: #333333;
  332. font-size: 60rpx;
  333. font-weight: bold;
  334. }
  335. &-title {
  336. font-size: 32rpx;
  337. color: #333333;
  338. margin-top: 15rpx;
  339. }
  340. &-input {
  341. width: 606rpx;
  342. height: 104rpx;
  343. padding: 30rpx 40rpx;
  344. background: #F8F8F8;
  345. border-radius: 8px;
  346. }
  347. &-phone {
  348. margin-top: 112rpx;
  349. }
  350. &-yanzheng {
  351. display: flex;
  352. justify-content: space-between;
  353. align-items: center;
  354. margin-top: 30rpx;
  355. .shu {
  356. width: 0rpx;
  357. height: 40rpx;
  358. border: 2rpx solid #CCCCCC;
  359. }
  360. text {
  361. width: 116rpx;
  362. line-height: 60rpx;
  363. text-align: center;
  364. border: 2rpx solid #FB231F;
  365. border-radius: 30rpx;
  366. font-size: 28rpx;
  367. font-weight: bold;
  368. color: #FB231F;
  369. }
  370. }
  371. &-tip {
  372. text-align: end;
  373. margin-top: 40rpx;
  374. }
  375. // &-yanzheng {
  376. // // display: flex;
  377. // // justify-content: space-between;
  378. // // align-items: center;
  379. // margin-top: 30rpx;
  380. // // .shu {
  381. // // width: 0rpx;
  382. // // height: 40rpx;
  383. // // border: 2rpx solid #CCCCCC;
  384. // // }
  385. // // text {
  386. // // font-size: 28rpx;
  387. // // font-weight: bold;
  388. // // color: #333333;
  389. // // }
  390. // }
  391. &-deal {
  392. margin: 160rpx 0 60rpx 0;
  393. font-size: 24rpx;
  394. .red {
  395. color: #FF232C;
  396. }
  397. }
  398. &-btn {
  399. color: #fff;
  400. font-size: 32rpx;
  401. width: 590rpx;
  402. line-height: 104rpx;
  403. text-align: center;
  404. background: linear-gradient(93deg, #FF232C 0%, #FF571B 100%);
  405. border-radius: 52rpx;
  406. margin: 0 auto;
  407. }
  408. &-bottom {
  409. margin-top: 160rpx;
  410. text-align: center;
  411. font-size: 28rpx;
  412. color: #333333;
  413. }
  414. }
  415. </style>