login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="u-page content">
  3. <u-icon class="back-btn" name="arrow-left" color="black" size="20" @click="navBack"></u-icon>
  4. <view class="wrapper">
  5. <image style='width:38px;height:38px;margin-bottom:10px;' src='@/static/logo.png'></image>
  6. <h2 class="title">欢迎使用网络货运</h2>
  7. <u--form labelPosition="left" :model="dataDetails" ref="loginForm" labelWidth="80">
  8. <u-form-item label="电话" prop="phone" borderBottom>
  9. <u--input v-model="dataDetails.phone" border="none" placeholder="请输入手机号码"></u--input>
  10. </u-form-item>
  11. <u-form-item label="验证码" prop="code" labelWidth="80" borderBottom>
  12. <u--input v-model="dataDetails.code" border="none" placeholder="请填写验证码"></u--input>
  13. <u-button slot="right" @tap="getCode" :text="tips" class="code-style" size="mini"
  14. :disabled="disabled1">
  15. </u-button>
  16. </u-form-item>
  17. <u-code ref="uCode" @change="codeChange" seconds="20" @start="disabled1 = true"
  18. @end="disabled1 = false">
  19. </u-code>
  20. </u--form>
  21. <u-button @tap="login"class="code-style submit">登录</u-button>
  22. <view @click='gonumber' class="use-password" style='text-align:center;color:#6A6A6A;'>使用账号密码登录</view>
  23. <!-- <u-button type="primary" text="登录" customStyle="margin-top: 50px" @click="login()"></u-button>
  24. <u-button type="primary" @click='goregister'>手机号一键注册</u-button> -->
  25. <!-- <u-loading-page :loading="isLoading" bg-color="#e8e8e8"></u-loading-page> -->
  26. </view>
  27. <u-toast ref="uToast"></u-toast>
  28. </view>
  29. </template>
  30. <script>
  31. var _this
  32. import helper from '@/common/helper.js';
  33. export default {
  34. data() {
  35. return {
  36. isLoading: false,
  37. disabled1: false,
  38. tips: '',
  39. showCalendar: false,
  40. showBirthday: false,
  41. dataDetails: {
  42. phone: '',
  43. code: ''
  44. },
  45. rules: {
  46. phone: [
  47. {
  48. required: true,
  49. message: '请输入手机号',
  50. trigger: ['change', 'blur'],
  51. },
  52. {
  53. // 自定义验证函数,见上说明
  54. validator: (rule, value, callback) => {
  55. // 上面有说,返回true表示校验通过,返回false表示不通过
  56. // uni.$u.test.mobile()就是返回true或者false的
  57. return uni.$u.test.mobile(value);
  58. },
  59. message: '手机号码不正确',
  60. // 触发器可以同时用blur和change
  61. trigger: [ 'blur'],
  62. }
  63. ],
  64. code: {
  65. type: 'string',
  66. required: true,
  67. len: 6,
  68. message: '请填写6位验证码',
  69. trigger: ['blur'],
  70. },
  71. }
  72. }
  73. },
  74. onReady() {
  75. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  76. this.$refs.loginForm.setRules(this.rules)
  77. },
  78. onLoad() {
  79. _this = this
  80. },
  81. methods: {
  82. gonumber(){
  83. uni.navigateTo({
  84. url:'/pages/public/lginOther'
  85. })
  86. },
  87. navBack() {
  88. uni.navigateBack();
  89. },
  90. codeChange(text) {
  91. this.tips = text;
  92. },
  93. getCode() {
  94. if (this.dataDetails.phone.length != 11) {
  95. this.$refs.uToast.show({
  96. type: 'error',
  97. message: "手机号输入错误",
  98. })
  99. } else {
  100. if (this.$refs.uCode.canGetCode) {
  101. // 模拟向后端请求验证码
  102. uni.showLoading({
  103. title: '正在获取验证码'
  104. })
  105. _this.$request.baseRequest('get', '/commonUser/sendVerifyCode', {
  106. phone: this.dataDetails.phone
  107. }).then(res => {
  108. uni.hideLoading();
  109. // 这里此提示会被this.start()方法中的提示覆盖
  110. uni.$u.toast('验证码已发送');
  111. // 通知验证码组件内部开始倒计时
  112. this.$refs.uCode.start();
  113. })
  114. .catch(res => {
  115. uni.$u.toast(res.message);
  116. });
  117. } else {
  118. uni.$u.toast('倒计时结束后再发送');
  119. }
  120. }
  121. },
  122. login() {
  123. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  124. this.$refs.loginForm.validate().then(res => {
  125. uni.$u.toast('校验通过')
  126. this.isLoading = true
  127. _this.$request.baseRequest('get', '/commonUser/loginVerifyCode', {
  128. phone: _this.dataDetails.phone,
  129. verifyCode: _this.dataDetails.code
  130. }).then(res => {
  131. _this.$request.baseRequest('', '/driverInfo/firstAuthentication', {
  132. driverPhone: _this.dataDetails.phone,
  133. }).then(res1 => {
  134. uni.setStorageSync('pcUserInfo', res.data)
  135. uni.setStorageSync('userInfo', res.data)
  136. uni.setStorageSync('firstAuthentication', res1.data)
  137. helper.getListByUserId()
  138. _this.$store.commit('login', res.data)
  139. // that.liangxinLogin()
  140. uni.switchTab({
  141. url: '/pages/goodSource/index'
  142. });
  143. _this.isLoading = false
  144. //
  145. //
  146. })
  147. .catch(res => {
  148. uni.$u.toast(res.message);
  149. });
  150. // that.$request.TokenRequest('post', '/commonUser/api/loginQuickly', {
  151. // mobilePhone: that.model1.phone,
  152. // veriCode: that.model1.code
  153. // }).then(res1 => {
  154. // uni.setStorageSync('pcUserInfo', res1.data)
  155. // uni.setStorageSync('userInfo', res.data)
  156. // helper.getListByUserId()
  157. // that.$store.commit('login', res.data)
  158. // // that.liangxinLogin()
  159. // uni.switchTab({
  160. // url: '/pages/index/index'
  161. // });
  162. // this.isLoading = false
  163. // })
  164. })
  165. .catch(res => {
  166. uni.showToast({
  167. title: res.message,
  168. icon: 'none',
  169. duration: 2000
  170. })
  171. });
  172. }).catch(errors => {
  173. this.$refs.uToast.show({
  174. type: 'error',
  175. message: "校验失败",
  176. })
  177. })
  178. },
  179. reset() {
  180. const validateList = ['userInfo.name', 'userInfo.sex', 'radiovalue1', 'checkboxValue1', 'intro',
  181. 'hotel', 'code', 'userInfo.birthday'
  182. ]
  183. this.$refs.form1.resetFields()
  184. this.$refs.form1.clearValidate()
  185. setTimeout(() => {
  186. this.$refs.form1.clearValidate(validateList)
  187. // 或者使用 this.$refs.form1.clearValidate()
  188. }, 10)
  189. },
  190. hideKeyboard() {
  191. uni.hideKeyboard()
  192. },
  193. goregister() {
  194. uni.$u.route('/pages/public/register');
  195. },
  196. },
  197. }
  198. </script>
  199. <style lang="scss">
  200. .content {
  201. background: url(../../static/images/mine/bg@2x.png);
  202. background-size: 100% 100%;
  203. height: 100vh;
  204. padding-top: 85px;
  205. position: relative;
  206. }
  207. .back-btn {
  208. position: absolute;
  209. left: 40upx;
  210. z-index: 9999;
  211. padding-top: var(--status-bar-height);
  212. top: 40upx;
  213. font-size: 40upx;
  214. color: red;
  215. }
  216. .wrapper {
  217. position: relative;
  218. z-index: 90;
  219. padding-bottom: 40upx;
  220. height: 100%;
  221. padding: 0 30px;
  222. }
  223. .code-style {
  224. background: #2772FB;
  225. color: white;
  226. }
  227. .use-password{
  228. margin-top: 31rpx;
  229. }
  230. .submit{
  231. margin-top: 40rpx;
  232. }
  233. </style>