login.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="login">
  3. <view class="app_top">
  4. <view class="welcome animated bounceIn">
  5. <view class="desc">您好,</view>
  6. <view class="desc">欢迎来到天保物流</view>
  7. </view>
  8. <image src="../../static/images/my.png" mode="widthFix" class="img"></image>
  9. </view>
  10. <view class="dk animated fadeInDown">
  11. <view class="bg">
  12. <text class="icon">&#xe8b9;</text>
  13. <input type="number" v-model="item.phone" maxlength="11" placeholder="请输入手机号" />
  14. </view>
  15. <view class="bg">
  16. <text class="icon">&#xe8b2;</text>
  17. <input :password="show" v-model="item.password" placeholder="请输入密码" />
  18. <view class="label"><view class="icon" :class="{ active: !show }" @click="show = !show">&#xe7a6;</view></view>
  19. </view>
  20. <view class="xy">
  21. <u-checkbox-group class="checkbox" v-model="item.checked">
  22. <u-checkbox size="15" shape="circle" label="我已阅读并同意" labelSize="13" name="true"></u-checkbox>
  23. </u-checkbox-group>
  24. <text class="a" @click="go('/pages/login/userAgreement?id=1')">《用户协议》</text>
  25. <text>和</text>
  26. <text class="a" @click="go('/pages/login/userAgreement?id=2')">《隐私政策》</text>
  27. </view>
  28. <button class="btn" @click="submit()">登录</button>
  29. <!-- <button class="btn register" @click="go('/pages/login/chooseRole')">注册</button> -->
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. show: true,
  38. item: {phone:'',password:'',checked:[]}
  39. };
  40. },
  41. onLoad() {
  42. //自动登陆
  43. if (uni.getStorageSync('token')) {
  44. uni.switchTab({ url: '/pages/index/index' });
  45. return;
  46. }
  47. //获取版本号和设备信息
  48. uni.getSystemInfo({
  49. success: res => {
  50. this.item.deviceMode = res.model + ' ' + res.system;
  51. // #ifdef APP-PLUS
  52. plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
  53. this.item.appVersion = wgtinfo.versionCode;
  54. });
  55. // #endif
  56. // #ifdef H5
  57. this.item.appVersion = '1.0.0';
  58. // #endif
  59. }
  60. });
  61. },
  62. methods: {
  63. toFaceLogin(){
  64. if(this.item.checked.length==0){
  65. this.common.toast('请同意并勾选协议');
  66. return;
  67. }
  68. this.common.to('/pages/login/faceLogin');
  69. },
  70. submit() {
  71. uni.clearStorageSync();
  72. let rule = [
  73. { name: 'phone', checkType: 'notnull', errorMsg: '手机号不能为空' },
  74. { name: 'phone', checkType: 'phoneno', errorMsg: '请输入正确的手机号' },
  75. { name: 'password', checkType: 'notnull', errorMsg: '请输入密码' },
  76. { name: 'checked', checkType: 'notnull', errorMsg: '请同意并勾选协议' }
  77. ];
  78. if (!this.verify.check(this.item, rule)) {
  79. uni.showModal({ content: this.verify.error, showCancel: false });
  80. return false;
  81. }
  82. let item = JSON.parse(JSON.stringify(this.item));
  83. item.phone = this.util.encrypt(this.item.phone);
  84. item.password = this.util.encrypt(this.item.password);
  85. this.http.request({
  86. url: '/sp-admin/app/AppUser/login',
  87. data: item,
  88. method: 'POST',
  89. success: res => {
  90. let data = res.data.data;
  91. uni.setStorageSync('token', data.tokenInfo.tokenValue);
  92. uni.setStorageSync('info', data.appUser);
  93. uni.setStorageSync('menu', data.per_list);
  94. uni.showToast({ title: '登录成功' });
  95. setTimeout(() => {
  96. uni.$emit('getMenu');
  97. uni.switchTab({ url: '/pages/index/index' });
  98. }, 1000);
  99. }
  100. });
  101. },
  102. go(url) {
  103. uni.navigateTo({ url: url });
  104. }
  105. }
  106. };
  107. </script>
  108. <style lang="scss"></style>