login.vue 6.2 KB

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