lginOther.vue 5.7 KB

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