login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view>
  3. <!--<view class="l_top"><image src="" mode="aspectFill"></image></view>-->
  4. <view class="bg">
  5. <view class="login">
  6. <view class="form_group">
  7. <view class="lable"><text class="icon">&#xe6a0;</text></view>
  8. <input type="text" placeholder="邮箱/名字/工号/手机号" v-model="item.username" />
  9. </view>
  10. <view class="form_group">
  11. <view class="lable"><text class="icon">&#xe728;</text></view>
  12. <input type="password" placeholder="密码" v-model="item.password" />
  13. </view>
  14. <view class="form_group" v-if="checkcodeImg !=''">
  15. <view class="lable" style="width: 25%;">
  16. <image :src=checkcodeImg style="height: 70rpx;"></image>
  17. </view>
  18. <input type="text" placeholder="验证码" v-model="item.checkcode" />
  19. </view>
  20. <button class="btn" @click="login()">登陆</button>
  21. <navigator url="/pages/find_pass" class="pass" hover-class="none">找回密码</navigator>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. item: {
  31. domainName: '柳工',
  32. remember: '0',
  33. debug: 'false',
  34. checkcode: '',
  35. language: 'CN',
  36. url: '/obpm'
  37. },
  38. uitem: {},
  39. checkcodeImg: ''
  40. };
  41. },
  42. onLoad(e) {
  43. //刷新
  44. uni.$on('index', res => {
  45. //this.refresh();
  46. uni.showLoading({
  47. title: '加载中',
  48. mask: true
  49. });
  50. });
  51. },
  52. mounted() {
  53. //自动登陆
  54. if (this.hasLogin()) {
  55. //uni.redirectTo({ url: '/pages/index/index' ,
  56. // });
  57. }
  58. },
  59. methods: {
  60. //登陆
  61. login() {
  62. let rule = [{
  63. name: 'username',
  64. checkType: 'notnull',
  65. errorMsg: '请输入账号'
  66. }, {
  67. name: 'password',
  68. checkType: 'notnull',
  69. errorMsg: '请输入密码'
  70. }];
  71. //if (!vm.verify.check(this.item, rule)) {
  72. // uni.showModal({ content: this.verify.error, showCancel: false });
  73. // return false;
  74. // }
  75. this.item.password = window.btoa(this.item.password);
  76. var p1 = this.item.password.slice(2);
  77. var p2 = this.item.password.substring(0, 2)
  78. this.item.password = p1 + p2;
  79. //console.log("this.item:"+this.item);
  80. this.http.request({
  81. url: this.http.urls.login,
  82. data: this.item,
  83. method: 'post',
  84. success: res => {
  85. console.log("gfgh===" + JSON.stringify(res.data));
  86. if (res.data.resultCode == 1) {
  87. uni.removeStorageSync('user');
  88. uni.setStorageSync('user', res.data);
  89. this.myprofile();
  90. } else {
  91. this.checkcodeImg = res.data.checkcodeImg;
  92. }
  93. }
  94. });
  95. }, //登陆
  96. myprofile() {
  97. this.http.request({
  98. url: this.http.urls.myprofile,
  99. data: this.item,
  100. success: res => {
  101. if (res.data.errmsg == 'ok') {
  102. var accessToken = this.getUser().accessToken;
  103. res.data.data.accessToken = accessToken;
  104. uni.removeStorageSync('user');
  105. //console.log("gfgh==="+JSON.stringify(res.data.data));
  106. uni.setStorageSync('user', res.data.data);
  107. uni.$emit('index');
  108. uni.redirectTo({
  109. url: '/',
  110. });
  111. console.log("res.data.resultCode===" + res.data.errcode);
  112. }
  113. }
  114. });
  115. },
  116. }
  117. };
  118. </script>
  119. <style lang="scss">
  120. .bg {
  121. padding: 15px;
  122. image {
  123. width: 100%;
  124. height: 10px;
  125. border-radius: 5px;
  126. }
  127. .login {
  128. .form_group {
  129. border: 1px solid $line;
  130. border-radius: 5px;
  131. margin-top: 10px;
  132. .lable {
  133. width: 10px;
  134. }
  135. input {
  136. border: 0px;
  137. }
  138. }
  139. .btn {
  140. margin-top: 25px;
  141. width: 82%;
  142. }
  143. .pass {
  144. width: 90%;
  145. text-align: right;
  146. padding-top: 20px;
  147. //color: $cor;
  148. }
  149. }
  150. }
  151. </style>