boundPhone.vue 9.8 KB

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