phoneLogin.vue 5.1 KB

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