login.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="login-wrap">
  3. <view v-if="!buildType" style="text-align: center;color: #999999;padding-top: 40px;">{{ envTips }}</view>
  4. <image src="../../static/logo-h.png" class="logo"></image>
  5. <form class="login-form" @submit="formSubmit">
  6. <view class="form-item">
  7. <u-icon size="34" color="#999" name="account"></u-icon>
  8. <input v-model="form.username" class="item-inp" name="username" type="number" maxlength="11" placeholder="请输入用户名" />
  9. </view>
  10. <view class="form-item">
  11. <u-icon size="34" color="#999" name="lock"></u-icon>
  12. <input v-model="form.password" class="item-inp" name="password" password type="text" maxlength="12" placeholder="请输入密码" />
  13. </view>
  14. <view class="flex-box" style="margin-top: 60upx;">
  15. <view class="remember-pass">
  16. <checkbox-group @change="rememberChange">
  17. <label>
  18. <checkbox value="true" :checked="isRemember" class="login-form-checkbox" />
  19. <text>记住密码</text>
  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" form-type="submit">登录</button>
  27. <!-- <text class="apply-btn" @click="applyTrial">还没有账号?马上申请试用</text> -->
  28. </view>
  29. </form>
  30. <view class="authUserYs">
  31. <checkbox-group @change="authuserChange">
  32. <label>
  33. <checkbox value="true" :checked="isAuthuserYs" class="login-form-checkbox" />
  34. 登录代表同意
  35. <text @click="toYsPage()">章鱼车管家用户协议及隐私保护政策</text>
  36. </label>
  37. </checkbox-group>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import market from "@/js_sdk/dc-market/market.js"
  43. import { checkVersionToLoadUpdate, setStorageForAppVersion,clzConfirm } from '@/libs/tools'
  44. import { isvalidPhone } from '@/libs/validate.js';
  45. import { login } from '@/api/user.js';
  46. import { getSysVersion } from '@/api/data.js'
  47. export default {
  48. data() {
  49. return {
  50. form: {
  51. username: this.$store.state.vuex_user.account,
  52. password: this.$store.state.vuex_user.password
  53. },
  54. isRemember: true, // 是否记住密码
  55. isAuthuserYs: false, // 是否同意隐私政策
  56. envTips: '',
  57. buildType: ''
  58. };
  59. },
  60. mounted() {
  61. this.isRemember = this.$store.state.vuex_isRemember;
  62. this.isAuthuserYs = this.$store.state.vuex_isUsrAuthYs;
  63. this.envTips = getApp().globalData.envTips;
  64. this.buildType = getApp().globalData.buildType;
  65. },
  66. onShow() {
  67. //#ifdef APP-PLUS
  68. uni.getSystemInfo({
  69. success:(res) => {
  70. console.log(res)
  71. //检测当前平台,如果是安卓则启动安卓更新
  72. if(res.platform=="android"){
  73. // 获取最新版本信息
  74. plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
  75. getApp().globalData.version = wgtinfo
  76. this.AndroidCheckUpdate()
  77. })
  78. }
  79. }
  80. })
  81. //#endif
  82. },
  83. methods: {
  84. // 安卓版本更新
  85. AndroidCheckUpdate(){
  86. let _this = this
  87. getSysVersion().then(ret => {
  88. if(ret.status == 200){
  89. this.$store.state.vuex_versionInfo = ret.data
  90. let currTimeStamp = new Date(ret.data.publicDate).getTime();
  91. // 判断缓存时间
  92. uni.getStorage({
  93. key: 'tip_version_update_time',
  94. success: function (res) {
  95. let lastTimeStamp = res.data;
  96. //定义提醒的时间间隔,避免烦人的一直提示,一个小时:36000;一天:60*60*1000*24
  97. let tipTimeLength = 60*60*1000*3;
  98. // 强制更新
  99. if(ret.data.forceUpgrade == 1){
  100. tipTimeLength = 0
  101. //进行版本型号的比对 以及下载更新请求
  102. checkVersionToLoadUpdate(ret.data,0,market);
  103. }else{
  104. if((lastTimeStamp+tipTimeLength) <= currTimeStamp){
  105. //重新设置时间戳
  106. setStorageForAppVersion(currTimeStamp);
  107. //进行版本型号的比对 以及下载更新请求
  108. checkVersionToLoadUpdate(ret.data,0,market);
  109. }
  110. }
  111. },
  112. fail:function(res){
  113. setStorageForAppVersion(currTimeStamp);
  114. }
  115. });
  116. }
  117. })
  118. },
  119. // 过滤权限code
  120. fiterAuthCode(data) {
  121. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  122. return data;
  123. },
  124. // 表单提交
  125. formSubmit() {
  126. const _this = this;
  127. // 表单校验
  128. if (_this.form.username == '') {
  129. uni.showToast({ icon: 'none', title: '请输入用户名' });
  130. return;
  131. }
  132. if (!isvalidPhone(_this.form.username)) {
  133. uni.showToast({ icon: 'none', title: '请输入正确的手机号码' });
  134. return;
  135. }
  136. if (_this.form.password == '') {
  137. uni.showToast({ icon: 'none', title: '请输入密码' });
  138. return;
  139. }
  140. if (_this.form.password.length < 6 || _this.form.password.length > 12) {
  141. uni.showToast({ icon: 'none', title: '请输入6-12位密码' });
  142. return;
  143. }
  144. if (!_this.isAuthuserYs) {
  145. uni.showToast({ icon: 'none', title: '请同意并阅读用户隐私政策' });
  146. return;
  147. }
  148. uni.showLoading({
  149. title: '正在登录...'
  150. });
  151. // 登录
  152. login(_this.form).then(ret => {
  153. uni.hideLoading();
  154. let res = ret.data ? ret.data : ret;
  155. if (res.status == 200) {
  156. _this.$u.vuex('vuex_token', 'Bearer ' + res.access_token);
  157. _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.auth_user));
  158. getApp().globalData.token = 'Bearer ' + res.access_token;
  159. //登录成功将用户名密码存储到用户本地
  160. if (_this.isRemember) {
  161. //用户勾选“记住密码”
  162. _this.$u.vuex('vuex_user.account', _this.form.username);
  163. _this.$u.vuex('vuex_user.password', _this.form.password);
  164. } else {
  165. //用户没有勾选“记住密码”
  166. _this.$u.vuex('vuex_user.account', '');
  167. _this.$u.vuex('vuex_user.password', '');
  168. _this.form.username = '';
  169. _this.form.password = '';
  170. }
  171. uni.setStorageSync('loginTimeOut', 'NO');
  172. _this.toMain();
  173. } else {
  174. uni.showToast({ icon: 'none', title: res.message });
  175. }
  176. });
  177. },
  178. toMain() {
  179. // 跳转到首页
  180. uni.redirectTo({
  181. url: '/pages/index'
  182. });
  183. },
  184. // 申请试用
  185. applyTrial() {
  186. uni.navigateTo({
  187. url: '/pages/login/apply-trial'
  188. });
  189. },
  190. // 忘记密码
  191. forgetPass() {
  192. uni.navigateTo({
  193. url: '/pages/login/forget-pass?username=' + this.form.username
  194. });
  195. },
  196. // 判断是否记住密码
  197. rememberChange(e) {
  198. this.isRemember = e.detail.value.length > 0;
  199. },
  200. // 隐私
  201. authuserChange(e) {
  202. this.isAuthuserYs = e.detail.value.length > 0;
  203. this.$u.vuex('vuex_isUsrAuthYs', this.isAuthuserYs);
  204. },
  205. toYsPage() {
  206. uni.navigateTo({
  207. url: '/pages/login/userAuthYs'
  208. });
  209. }
  210. }
  211. };
  212. </script>
  213. <style scoped lang="scss">
  214. @import './login.scss';
  215. </style>