login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 = this.$store.state.vuex_isUsrAuthYs
  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. if(ret.data){
  97. this.$store.state.vuex_versionInfo = ret.data || null
  98. checkVersionToLoadUpdate(ret.data,0,_this.formSubmit)
  99. }else{
  100. this.formSubmit()
  101. }
  102. }
  103. uni.hideLoading()
  104. })
  105. },
  106. // 过滤权限code
  107. fiterAuthCode(data) {
  108. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  109. return data;
  110. },
  111. // 表单提交
  112. formSubmit() {
  113. const _this = this;
  114. // 表单校验
  115. if (_this.form.username == '') {
  116. uni.showToast({ icon: 'none', title: '请输入用户账号' });
  117. return;
  118. }
  119. if (!isvalidNumLetter(_this.form.username)) {
  120. uni.showToast({ icon: 'none', title: '用户账号为数字或大小写字母组成!' });
  121. return;
  122. }
  123. if (_this.form.password == '') {
  124. uni.showToast({ icon: 'none', title: '请输入密码' });
  125. return;
  126. }
  127. if (_this.form.password.length < 6 || _this.form.password.length > 50) {
  128. uni.showToast({ icon: 'none', title: '请输入6-50位密码' });
  129. return;
  130. }
  131. if (!_this.isAuthuserYs) {
  132. uni.showToast({ icon: 'none', title: '请同意并阅读用户隐私政策' });
  133. return;
  134. }
  135. // 登录
  136. login(_this.form).then(res => {
  137. uni.hideLoading();
  138. if (res.status == 200) {
  139. console.log(_this.fiterAuthCode(res.data.auth_user))
  140. _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
  141. _this.$u.vuex('vuex_token', res.data.access_token);
  142. getApp().globalData.token = res.data.access_token;
  143. //登录成功将用户名密码存储到用户本地
  144. if (_this.isRemember) {
  145. //用户勾选“记住密码”
  146. _this.$u.vuex('vuex_user.account', _this.form.username);
  147. _this.$u.vuex('vuex_user.password', _this.form.password);
  148. } else {
  149. //用户没有勾选“记住密码”
  150. _this.$u.vuex('vuex_user.account', '');
  151. _this.$u.vuex('vuex_user.password', '');
  152. _this.form.username = '';
  153. _this.form.password = '';
  154. }
  155. uni.setStorageSync('loginTimeOut', 'NO');
  156. _this.toMain();
  157. } else {
  158. uni.showToast({ icon: 'none', title: res.message });
  159. }
  160. });
  161. },
  162. toMain() {
  163. // 跳转到首页
  164. uni.switchTab({
  165. url: '/pages/stock/index'
  166. });
  167. },
  168. // 忘记密码
  169. forgetPass() {
  170. uni.navigateTo({
  171. url: '/pages/login/forget-pass?username=' + this.form.username
  172. });
  173. },
  174. // 判断是否记住密码
  175. rememberChange(e) {
  176. this.isRemember = e.detail.value.length > 0;
  177. },
  178. // 隐私
  179. authuserChange(e) {
  180. this.$u.vuex('vuex_isUsrAuthYs', this.isAuthuserYs);
  181. //#ifdef APP-PLUS
  182. if(!this.isAuthuserYs){
  183. plus.runtime.disagreePrivacy()
  184. }else{
  185. plus.runtime.agreePrivacy()
  186. }
  187. //#endif
  188. },
  189. toYsPage() {
  190. uni.navigateTo({
  191. url: '/pages/login/userAuthYs'
  192. });
  193. }
  194. }
  195. };
  196. </script>
  197. <style scoped lang="scss">
  198. @import './login.scss';
  199. </style>