login.vue 6.6 KB

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