phoneLogin.vue 5.2 KB

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