phoneLogin.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="login-wrap">
  3. <!-- <view v-if="!buildType" style="text-align: center;color: #999999;padding-top: 40px;">{{ envTips }}</view> -->
  4. <view class="logo">
  5. <u-image src="/static/logo.png" width="160" height="160"></u-image>
  6. </view>
  7. <form class="login-form" @submit="formSubmit">
  8. <view class="form-item">
  9. <input v-model="form.loginName" class="item-inp" name="loginName" type="text" maxlength="30" placeholder="请输入用户名" />
  10. </view>
  11. <view class="form-item">
  12. <input v-model="form.password" class="item-inp" name="password" password type="text" maxlength="12" placeholder="请输入密码" />
  13. </view>
  14. <view class="flex-box" style="margin-top: 40upx;">
  15. <view class="remember-pass">
  16. <u-checkbox shape="circle" v-model="isRemember" value="true" :size="30" :label-size="26" active-color="#4F88F7" class="login-form-checkbox" @change="rememberChange">记住密码</u-checkbox>
  17. </view>
  18. </view>
  19. <view class="form-btn-con">
  20. <button class="form-btn" form-type="submit">登录</button>
  21. </view>
  22. </form>
  23. <view class="authUserYs">
  24. <view class="xieyi">
  25. 首次登录会自动创建账号且代表同意
  26. <text @click="toYsPage()">
  27. 《乐色超人(骑手端)用户协议》
  28. </text>
  29. 及 <text>
  30. 《隐私政策》
  31. </text>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { checkVersionToLoadUpdate, setStorageForAppVersion,clzConfirm } from '@/libs/tools'
  38. import { isvalidPhone } from '@/libs/validate.js';
  39. import { loginPhone } from '@/api/login.js';
  40. import { getSysVersion } from '@/api/data.js'
  41. export default {
  42. data() {
  43. return {
  44. form: {
  45. loginName: this.$store.state.vuex_user.account,
  46. password: this.$store.state.vuex_user.password
  47. },
  48. isRemember: true, // 是否记住密码
  49. isAuthuserYs: true, // 是否同意隐私政策
  50. envTips: '',
  51. buildType: '',
  52. };
  53. },
  54. mounted() {
  55. this.isRemember = this.$store.state.vuex_isRemember || true;
  56. this.isAuthuserYs = this.$store.state.vuex_isUsrAuthYs || true;
  57. this.envTips = getApp().globalData.envTips;
  58. this.buildType = getApp().globalData.buildType;
  59. },
  60. onShow() {
  61. },
  62. methods: {
  63. // 获取微信login code
  64. getWechatCode(){
  65. const _this = this
  66. wx.login({
  67. success (res) {
  68. if (res.code) {
  69. //发起网络请求
  70. let formData = JSON.parse(JSON.stringify(_this.form))
  71. formData.code = res.code
  72. _this.submitForm(formData)
  73. } else {
  74. console.log('登录失败,点击“登录”重试!' + res.errMsg)
  75. }
  76. }
  77. })
  78. },
  79. // 表单提交
  80. formSubmit() {
  81. const _this = this;
  82. // 表单校验
  83. if (_this.form.loginName == '') {
  84. uni.showToast({ icon: 'none', title: '请输入用户名' });
  85. return;
  86. }
  87. if (!isvalidPhone(_this.form.loginName)) {
  88. uni.showToast({ icon: 'none', title: '请输入正确的手机号码' });
  89. return;
  90. }
  91. if (_this.form.password == '') {
  92. uni.showToast({ icon: 'none', title: '请输入密码' });
  93. return;
  94. }
  95. if (_this.form.password.length < 6 || _this.form.password.length > 12) {
  96. uni.showToast({ icon: 'none', title: '请输入6-12位密码' });
  97. return;
  98. }
  99. if (!_this.isAuthuserYs) {
  100. uni.showToast({ icon: 'none', title: '请同意并阅读用户隐私政策' });
  101. return;
  102. }
  103. uni.showLoading({
  104. title: '正在登录...'
  105. });
  106. // #ifdef MP-WEIXIN
  107. // 获取微信login code
  108. this.getWechatCode()
  109. // #endif
  110. // #ifndef MP-WEIXIN
  111. this.submitForm(_this.form)
  112. // #endif
  113. },
  114. submitForm(formData){
  115. const _this = this;
  116. // 登录
  117. loginPhone(formData).then(res => {
  118. uni.hideLoading();
  119. if (res.status == 200) {
  120. _this.$u.vuex('vuex_token', res.data);
  121. getApp().globalData.token = res.data;
  122. //登录成功将用户名密码存储到用户本地
  123. if (_this.isRemember) {
  124. //用户勾选“记住密码”
  125. _this.$u.vuex('vuex_user.account', _this.form.loginName);
  126. _this.$u.vuex('vuex_user.password', _this.form.password);
  127. } else {
  128. //用户没有勾选“记住密码”
  129. _this.$u.vuex('vuex_user.account', '');
  130. _this.$u.vuex('vuex_user.password', '');
  131. _this.form.loginName = '';
  132. _this.form.password = '';
  133. }
  134. uni.setStorageSync('loginTimeOut', 'NO');
  135. _this.toMain();
  136. } else {
  137. uni.showToast({ icon: 'none', title: res.message });
  138. }
  139. });
  140. },
  141. toMain() {
  142. // 跳转到首页
  143. uni.switchTab({
  144. url: '/pages/index/index'
  145. });
  146. },
  147. // 忘记密码
  148. forgetPass() {
  149. uni.navigateTo({
  150. url: '/pages/login/forget-pass?username=' + this.form.loginName
  151. });
  152. },
  153. // 判断是否记住密码
  154. rememberChange(e) {
  155. this.isRemember = e.value;
  156. },
  157. // 隐私
  158. authuserChange(e) {
  159. this.isAuthuserYs = e.value;
  160. this.$u.vuex('vuex_isUsrAuthYs', this.isAuthuserYs);
  161. },
  162. toYsPage() {
  163. uni.navigateTo({
  164. url: '/pages/agreement/agreement'
  165. });
  166. }
  167. }
  168. };
  169. </script>
  170. <style scoped lang="scss">
  171. @import './loginPw.scss';
  172. </style>