lginOther.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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" @input='passwordInput' border="none" placeholder="请输入手机号码">
  10. </u--input>
  11. </u-form-item>
  12. <u-form-item label="密码" prop="password" borderBottom>
  13. <u--input v-model="dataDetails.password" @input='passwordInput' border="none"
  14. placeholder="请输入密码,6-16位字符"></u--input>
  15. </u-form-item>
  16. </u--form>
  17. <u-button @tap="login" class="code-style submit" :disabled="isdisabled">登录</u-button>
  18. <u-button @click='goregister' class="code-style submit">手机号一键注册</u-button>
  19. <view class='flex' style='color:#6A6A6A;margin-top:10px;'>
  20. <view style='flex:1;text-align:center;border-right:1px solid #E8E9ED;' class="Regular"
  21. @click="forgetpass()">忘记密码</view>
  22. <view @click='gocode' style='flex:1;text-align:center;' class="Regular">验证码登录</view>
  23. </view>
  24. </view>
  25. <u-toast ref="uToast"></u-toast>
  26. </view>
  27. </template>
  28. <script>
  29. var _this
  30. import helper from '@/common/helper.js';
  31. export default {
  32. data() {
  33. return {
  34. isdisabled: true,
  35. dataDetails: {
  36. phone: '',
  37. password: ''
  38. },
  39. rules: {
  40. phone: [{
  41. required: true,
  42. message: '请输入手机号',
  43. trigger: ['blur'],
  44. },
  45. {
  46. // 自定义验证函数,见上说明
  47. validator: (rule, value, callback) => {
  48. // 上面有说,返回true表示校验通过,返回false表示不通过
  49. // uni.$u.test.mobile()就是返回true或者false的
  50. return uni.$u.test.mobile(value);
  51. },
  52. message: '手机号码不正确',
  53. // 触发器可以同时用blur和change
  54. trigger: ['blur'],
  55. }
  56. ],
  57. password: {
  58. type: 'string',
  59. required: true,
  60. min: 6,
  61. max: 16,
  62. message: '长度在6-16位字符之间',
  63. trigger: ['blur'],
  64. },
  65. }
  66. }
  67. },
  68. onReady() {
  69. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  70. this.$refs.loginForm.setRules(this.rules)
  71. },
  72. onLoad() {
  73. _this = this
  74. },
  75. methods: {
  76. passwordInput() {
  77. if (this.dataDetails.password && this.dataDetails.phone) {
  78. this.isdisabled = false
  79. } else {
  80. this.isdisabled = true
  81. }
  82. },
  83. forgetpass() {
  84. uni.navigateTo({
  85. url: '/pages/mine/settings/editPassword'
  86. })
  87. },
  88. goregister() {
  89. uni.navigateTo({
  90. url: '/pages/public/register'
  91. })
  92. },
  93. gocode() {
  94. uni.navigateTo({
  95. url: '/pages/public/login'
  96. })
  97. },
  98. navBack() {
  99. uni.navigateBack();
  100. },
  101. codeChange(text) {
  102. this.tips = text;
  103. },
  104. login() {
  105. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  106. this.$refs.loginForm.validate().then(res => {
  107. uni.showLoading({
  108. title: '登录中',
  109. mask:true
  110. })
  111. _this.$request.baseRequest('get', '/commonUser/login', _this.dataDetails).then(res => {
  112. _this.$request.baseRequest('', '/driverInfo/firstAuthentication', {
  113. driverPhone: _this.dataDetails.phone,
  114. }).then(res1 => {
  115. uni.setStorageSync('pcUserInfo', res.data)
  116. uni.setStorageSync('userInfo', res.data)
  117. uni.setStorageSync('firstAuthentication', res1.data)
  118. helper.getListByUserId()
  119. _this.$store.commit('login', res.data)
  120. // that.liangxinLogin()
  121. uni.switchTab({
  122. url: '/pages/goodSource/index'
  123. });
  124. uni.hideLoading()
  125. //
  126. //
  127. })
  128. .catch(res => {
  129. uni.$u.toast(res.message);
  130. });
  131. })
  132. .catch(res => {
  133. uni.showToast({
  134. title: res.message,
  135. icon: 'none',
  136. duration: 2000
  137. })
  138. });
  139. }).catch(errors => {
  140. this.$refs.uToast.show({
  141. type: 'error',
  142. message: "校验失败",
  143. })
  144. })
  145. },
  146. reset() {
  147. const validateList = ['userInfo.name', 'userInfo.sex', 'radiovalue1', 'checkboxValue1', 'intro',
  148. 'hotel', 'code', 'userInfo.birthday'
  149. ]
  150. this.$refs.form1.resetFields()
  151. this.$refs.form1.clearValidate()
  152. setTimeout(() => {
  153. this.$refs.form1.clearValidate(validateList)
  154. // 或者使用 this.$refs.form1.clearValidate()
  155. }, 10)
  156. },
  157. hideKeyboard() {
  158. uni.hideKeyboard()
  159. },
  160. goregister() {
  161. uni.$u.route('/pages/public/register');
  162. },
  163. },
  164. }
  165. </script>
  166. <style lang="scss">
  167. .content {
  168. background: url(../../static/images/mine/bg@2x.png);
  169. background-size: 100% 100%;
  170. height: 100vh;
  171. padding-top: 85px;
  172. position: relative;
  173. }
  174. .back-btn {
  175. position: absolute;
  176. left: 40upx;
  177. z-index: 9999;
  178. padding-top: var(--status-bar-height);
  179. top: 40upx;
  180. font-size: 40upx;
  181. color: red;
  182. }
  183. .wrapper {
  184. position: relative;
  185. z-index: 90;
  186. padding-bottom: 40upx;
  187. height: 100%;
  188. padding: 0 30px;
  189. }
  190. .code-style {
  191. background: #2772FB;
  192. color: white;
  193. }
  194. .use-password {
  195. margin-top: 31rpx;
  196. }
  197. .submit {
  198. margin-top: 40rpx;
  199. }
  200. </style>