login.vue 6.6 KB

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