login.vue 6.8 KB

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