phoneLogin.vue 5.2 KB

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