login.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="u-page">
  3. <u--form labelPosition="left" :model="model1" ref="form1">
  4. <u-form-item label="电话" prop="phone" borderBottom ref="item1">
  5. <u--input v-model="model1.phone" border="none" placeholder="电话"></u--input>
  6. </u-form-item>
  7. <u-form-item label="验证码" prop="code" labelWidth="80" borderBottom>
  8. <u--input v-model="model1.code" border="none" placeholder="请填写验证码"></u--input>
  9. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="mini" :disabled="disabled1">
  10. </u-button>
  11. </u-form-item>
  12. <u-code ref="uCode" @change="codeChange" seconds="20" @start="disabled1 = true" @end="disabled1 = false">
  13. </u-code>
  14. </u--form>
  15. <u-button type="primary" text="提交" customStyle="margin-top: 50px" @click="submit"></u-button>
  16. </view>
  17. </template>
  18. <script>
  19. import helper from '@/common/helper.js';
  20. export default {
  21. data() {
  22. return {
  23. disabled1: false,
  24. tips: '',
  25. showCalendar: false,
  26. showBirthday: false,
  27. model1: {
  28. phone: '13333333333',
  29. code: '123456'
  30. },
  31. rules: {
  32. code: {
  33. type: 'string',
  34. required: true,
  35. len: 6,
  36. message: '请填写4位验证码',
  37. trigger: ['blur']
  38. },
  39. }
  40. }
  41. },
  42. onReady() {
  43. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  44. this.$refs.form1.setRules(this.rules)
  45. },
  46. methods: {
  47. codeChange(text) {
  48. this.tips = text;
  49. },
  50. getCode() {
  51. if (this.$refs.uCode.canGetCode) {
  52. // 模拟向后端请求验证码
  53. uni.showLoading({
  54. title: '正在获取验证码'
  55. })
  56. setTimeout(() => {
  57. uni.hideLoading();
  58. // 这里此提示会被this.start()方法中的提示覆盖
  59. uni.$u.toast('验证码已发送');
  60. // 通知验证码组件内部开始倒计时
  61. this.$refs.uCode.start();
  62. }, 2000);
  63. } else {
  64. uni.$u.toast('倒计时结束后再发送');
  65. }
  66. },
  67. submit() {
  68. let that = this
  69. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  70. this.$refs.form1.validate().then(res => {
  71. uni.$u.toast('校验通过')
  72. debugger
  73. that.$request.baseRequest('get', '/commonUser/loginVerifyCode', {
  74. phone: that.model1.phone,
  75. verifyCode: that.model1.code
  76. }).then(res => {
  77. that.$request.TokenRequest('post', '/commonUser/api/loginQuickly', {
  78. mobilePhone:that.model1.phone,
  79. veriCode: that.model1.code
  80. }).then(res1 => {
  81. debugger
  82. uni.setStorageSync('pcUserInfo', res1.data)
  83. uni.setStorageSync('userInfo', res.data)
  84. helper.getListByUserId()
  85. that.$store.commit('login', res.data)
  86. // that.liangxinLogin()
  87. uni.switchTab({
  88. url: '/pages/index/index'
  89. });
  90. uni.hideLoading()
  91. })
  92. })
  93. .catch(res => {
  94. uni.showToast({
  95. title: res.message,
  96. icon: 'none',
  97. duration: 2000
  98. })
  99. });
  100. }).catch(errors => {
  101. uni.$u.toast('校验失败')
  102. })
  103. },
  104. reset() {
  105. const validateList = ['userInfo.name', 'userInfo.sex', 'radiovalue1', 'checkboxValue1', 'intro',
  106. 'hotel', 'code', 'userInfo.birthday'
  107. ]
  108. this.$refs.form1.resetFields()
  109. this.$refs.form1.clearValidate()
  110. setTimeout(() => {
  111. this.$refs.form1.clearValidate(validateList)
  112. // 或者使用 this.$refs.form1.clearValidate()
  113. }, 10)
  114. },
  115. hideKeyboard() {
  116. uni.hideKeyboard()
  117. }
  118. },
  119. }
  120. </script>
  121. <style lang="scss">
  122. </style>