login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="login-wrap">
  3. <view class="login-head">
  4. <view v-if="showEnvTips">{{ envTips }}</view>
  5. </view>
  6. <view class="login-body">
  7. <image :src="`../../static/${theme}/logo.png`" class="logo"></image>
  8. <form class="login-form" @submit="AndroidCheckUpdate">
  9. <view class="form-item">
  10. <u-input v-model="form.username" :custom-style="{fontSize:'34upx'}" height="110" type="text" clearable placeholder="请输入用户账号" />
  11. </view>
  12. <view class="form-item">
  13. <u-input v-model="form.password" :custom-style="{fontSize:'34upx'}" height="110" type="password" :password-icon="true" maxlength="50" placeholder="请输入密码"/>
  14. </view>
  15. <view class="flex-box mt20">
  16. <view class="remember-pass">
  17. <checkbox-group @change="rememberChange">
  18. <label>
  19. <u-checkbox v-model="isRemember" label-size="13px" shape="circle">记住密码</u-checkbox>
  20. </label>
  21. </checkbox-group>
  22. </view>
  23. <view class="forget-pass" @click="forgetPass">忘记密码</view>
  24. </view>
  25. <view class="form-btn-con">
  26. <button class="form-btn" :disabled="isDisabled" :style="{'background':isDisabled?'#e5e5e5':$config('primaryColor')}" form-type="submit">登录</button>
  27. </view>
  28. </form>
  29. </view>
  30. <!-- 隐私协议 -->
  31. <view class="authUserYs">
  32. <u-checkbox-group width="45rpx" @change="authuserChange">
  33. <u-checkbox v-model="isAuthuserYs" :label-disabled="false" shape="circle">
  34. </u-checkbox>
  35. </u-checkbox-group>
  36. <view>登录代表同意</view>
  37. <view @click="toYsPage">
  38. <text>用户协议</text>及<text>隐私保护政策</text>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { checkVersionToLoadUpdate, setStorageForAppVersion,clzConfirm } from '@/libs/tools'
  45. import { isvalidNumLetter } from '@/libs/validate.js';
  46. import { login } from '@/api/user.js';
  47. import { getSysVersion } from '@/api/data.js'
  48. export default {
  49. data() {
  50. return {
  51. form: {
  52. username: this.$store.state.vuex_user.account,
  53. password: this.$store.state.vuex_user.password
  54. },
  55. isRemember: true, // 是否记住密码
  56. isAuthuserYs: false, // 是否同意隐私政策
  57. envTips: '',
  58. showEnvTips: false,
  59. theme: ''
  60. };
  61. },
  62. computed: {
  63. isDisabled() {
  64. return this.form.username == '' || this.form.password == ''
  65. }
  66. },
  67. onShow() {
  68. this.isRemember = this.$store.state.vuex_isRemember;
  69. this.envTips = getApp().globalData.envTips;
  70. this.showEnvTips = process.env.NODE_ENV == 'development';
  71. this.theme = getApp().globalData.theme;
  72. //#ifdef APP-PLUS
  73. this.isAuthuserYs = plus.runtime.isAgreePrivacy()
  74. uni.getSystemInfo({
  75. success:(res) => {
  76. console.log(res)
  77. // 获取最新版本信息
  78. plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
  79. wgtinfo.platform = res.platform
  80. getApp().globalData.version = wgtinfo
  81. })
  82. }
  83. })
  84. //#endif
  85. },
  86. methods: {
  87. // 版本更新
  88. AndroidCheckUpdate(){
  89. // let _this = this
  90. // let version = getApp().globalData.version
  91. // uni.showLoading({
  92. // title: '正在登录...'
  93. // });
  94. // getSysVersion({versionType:version.platform=='android'?'ANDROID':'IOS'}).then(ret => {
  95. // if(ret.status == 200){
  96. // this.$store.state.vuex_versionInfo = ret.data
  97. // checkVersionToLoadUpdate(ret.data,0,_this.formSubmit);
  98. // }
  99. // })
  100. this.formSubmit()
  101. },
  102. // 过滤权限code
  103. fiterAuthCode(data) {
  104. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  105. return data;
  106. },
  107. // 表单提交
  108. formSubmit() {
  109. const _this = this;
  110. // 表单校验
  111. if (_this.form.username == '') {
  112. uni.showToast({ icon: 'none', title: '请输入用户账号' });
  113. return;
  114. }
  115. if (!isvalidNumLetter(_this.form.username)) {
  116. uni.showToast({ icon: 'none', title: '用户账号为数字或大小写字母组成!' });
  117. return;
  118. }
  119. if (_this.form.password == '') {
  120. uni.showToast({ icon: 'none', title: '请输入密码' });
  121. return;
  122. }
  123. if (_this.form.password.length < 6 || _this.form.password.length > 50) {
  124. uni.showToast({ icon: 'none', title: '请输入6-50位密码' });
  125. return;
  126. }
  127. if (!_this.isAuthuserYs) {
  128. uni.showToast({ icon: 'none', title: '请同意并阅读用户隐私政策' });
  129. return;
  130. }
  131. // 登录
  132. login(_this.form).then(res => {
  133. uni.hideLoading();
  134. if (res.status == 200) {
  135. // _this.$u.vuex('vuex_token', 'Bearer ' + res.data.access_token);
  136. // _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
  137. // getApp().globalData.token = 'Bearer ' + res.data.access_token;
  138. _this.$u.vuex('vuex_token', res.data.access_token);
  139. getApp().globalData.token = res.data.access_token;
  140. //登录成功将用户名密码存储到用户本地
  141. if (_this.isRemember) {
  142. //用户勾选“记住密码”
  143. _this.$u.vuex('vuex_user.account', _this.form.username);
  144. _this.$u.vuex('vuex_user.password', _this.form.password);
  145. } else {
  146. //用户没有勾选“记住密码”
  147. _this.$u.vuex('vuex_user.account', '');
  148. _this.$u.vuex('vuex_user.password', '');
  149. _this.form.username = '';
  150. _this.form.password = '';
  151. }
  152. uni.setStorageSync('loginTimeOut', 'NO');
  153. _this.toMain();
  154. } else {
  155. uni.showToast({ icon: 'none', title: res.message });
  156. }
  157. });
  158. },
  159. toMain() {
  160. // 跳转到首页
  161. uni.switchTab({
  162. url: '/pages/index/index'
  163. });
  164. },
  165. // 忘记密码
  166. forgetPass() {
  167. uni.navigateTo({
  168. url: '/pages/login/forget-pass?username=' + this.form.username
  169. });
  170. },
  171. // 判断是否记住密码
  172. rememberChange(e) {
  173. this.isRemember = e.detail.value.length > 0;
  174. },
  175. // 隐私
  176. authuserChange(e) {
  177. this.$u.vuex('vuex_isUsrAuthYs', this.isAuthuserYs);
  178. //#ifdef APP-PLUS
  179. if(!this.isAuthuserYs){
  180. plus.runtime.disagreePrivacy()
  181. }else{
  182. plus.runtime.agreePrivacy()
  183. }
  184. //#endif
  185. },
  186. toYsPage() {
  187. uni.navigateTo({
  188. url: '/pages/login/userAuthYs'
  189. });
  190. }
  191. }
  192. };
  193. </script>
  194. <style scoped lang="scss">
  195. @import './login.scss';
  196. </style>