login.vue 7.2 KB

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