login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="login-wrap">
  3. <view v-if="showEnvTips" style="text-align: center;color: #999999;padding-top: 40px;">{{ envTips }}</view>
  4. <image :src="`/static/${theme}/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" :style="{background: $config('buttonColors')}" 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. showEnvTips: '',
  57. theme: ''
  58. };
  59. },
  60. mounted() {
  61. this.theme = this.$config('themePath')
  62. this.isRemember = this.$store.state.vuex_isRemember;
  63. this.isAuthuserYs = this.$store.state.vuex_isUsrAuthYs;
  64. this.envTips = getApp().globalData.envTips;
  65. this.showEnvTips = process.env.NODE_ENV == 'development'
  66. },
  67. onShow() {
  68. //#ifdef APP-PLUS
  69. uni.getSystemInfo({
  70. success:(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. console.log(data.permCodes)
  123. return data;
  124. },
  125. // 表单提交
  126. formSubmit() {
  127. const _this = this;
  128. // 表单校验
  129. if (_this.form.username == '') {
  130. uni.showToast({ icon: 'none', title: '请输入用户名' });
  131. return;
  132. }
  133. if (!isvalidPhone(_this.form.username)) {
  134. uni.showToast({ icon: 'none', title: '请输入正确的手机号码' });
  135. return;
  136. }
  137. if (_this.form.password == '') {
  138. uni.showToast({ icon: 'none', title: '请输入密码' });
  139. return;
  140. }
  141. if (_this.form.password.length < 6 || _this.form.password.length > 12) {
  142. uni.showToast({ icon: 'none', title: '请输入6-12位密码' });
  143. return;
  144. }
  145. if (!_this.isAuthuserYs) {
  146. uni.showToast({ icon: 'none', title: '请同意并阅读用户隐私政策' });
  147. return;
  148. }
  149. uni.showLoading({
  150. title: '正在登录...'
  151. });
  152. // 登录
  153. login(_this.form).then(ret => {
  154. uni.hideLoading();
  155. let res = ret.data ? ret.data : ret;
  156. if (res.status == 200) {
  157. _this.$u.vuex('vuex_token', res.access_token);
  158. _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.auth_user));
  159. getApp().globalData.token = res.access_token;
  160. //登录成功将用户名密码存储到用户本地
  161. if (_this.isRemember) {
  162. //用户勾选“记住密码”
  163. _this.$u.vuex('vuex_user.account', _this.form.username);
  164. _this.$u.vuex('vuex_user.password', _this.form.password);
  165. } else {
  166. //用户没有勾选“记住密码”
  167. _this.$u.vuex('vuex_user.account', '');
  168. _this.$u.vuex('vuex_user.password', '');
  169. _this.form.username = '';
  170. _this.form.password = '';
  171. }
  172. uni.setStorageSync('loginTimeOut', 'NO');
  173. _this.toMain();
  174. } else {
  175. uni.showToast({ icon: 'none', title: res.message });
  176. }
  177. });
  178. },
  179. toMain() {
  180. // 跳转到首页
  181. uni.switchTab({
  182. url:'/pages/index/index'
  183. })
  184. },
  185. // 申请试用
  186. applyTrial() {
  187. uni.navigateTo({
  188. url: '/pages/login/apply-trial'
  189. });
  190. },
  191. // 忘记密码
  192. forgetPass() {
  193. uni.navigateTo({
  194. url: '/pages/login/forget-pass?username=' + this.form.username
  195. });
  196. },
  197. // 判断是否记住密码
  198. rememberChange(e) {
  199. this.isRemember = e.detail.value.length > 0;
  200. },
  201. // 隐私
  202. authuserChange(e) {
  203. this.isAuthuserYs = e.detail.value.length > 0;
  204. this.$u.vuex('vuex_isUsrAuthYs', this.isAuthuserYs);
  205. },
  206. toYsPage() {
  207. uni.navigateTo({
  208. url: '/pages/login/userAuthYs'
  209. });
  210. }
  211. }
  212. };
  213. </script>
  214. <style scoped lang="scss">
  215. @import './login.scss';
  216. </style>