login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. if (e.loginNo != undefined) {
  44. this.item.username = e.loginNo;
  45. this.item.password = e.password;
  46. this.login();
  47. }
  48. //刷新
  49. uni.$on('index', res => {
  50. //this.refresh();
  51. uni.showLoading({
  52. title: '加载中',
  53. mask: true
  54. });
  55. });
  56. },
  57. mounted() {
  58. //自动登陆
  59. if (this.hasLogin()) {
  60. //uni.redirectTo({ url: '/pages/index/index' ,
  61. // });
  62. }
  63. },
  64. methods: {
  65. //登陆
  66. login() {
  67. let rule = [{
  68. name: 'username',
  69. checkType: 'notnull',
  70. errorMsg: '请输入账号'
  71. }, {
  72. name: 'password',
  73. checkType: 'notnull',
  74. errorMsg: '请输入密码'
  75. }];
  76. //if (!vm.verify.check(this.item, rule)) {
  77. // uni.showModal({ content: this.verify.error, showCancel: false });
  78. // return false;
  79. // }
  80. this.item.password = window.btoa(this.item.password);
  81. var p1 = this.item.password.slice(2);
  82. var p2 = this.item.password.substring(0, 2)
  83. this.item.password = p1 + p2;
  84. //console.log("this.item:"+this.item);
  85. this.http.request({
  86. url: this.http.urls.login,
  87. data: this.item,
  88. method: 'post',
  89. success: res => {
  90. console.log("gfgh===" + JSON.stringify(res.data));
  91. if (res.data.resultCode == 1) {
  92. uni.removeStorageSync('user');
  93. uni.setStorageSync('user', res.data);
  94. this.myprofile();
  95. } else {
  96. this.checkcodeImg = res.data.checkcodeImg;
  97. }
  98. }
  99. });
  100. }, //登陆
  101. myprofile() {
  102. this.http.request({
  103. url: this.http.urls.myprofile,
  104. data: this.item,
  105. success: res => {
  106. if (res.data.errmsg == 'ok') {
  107. var accessToken = this.getUser().accessToken;
  108. res.data.data.accessToken = accessToken;
  109. uni.removeStorageSync('user');
  110. //console.log("gfgh==="+JSON.stringify(res.data.data));
  111. uni.setStorageSync('user', res.data.data);
  112. uni.$emit('index');
  113. uni.redirectTo({
  114. url: '/',
  115. });
  116. console.log("res.data.resultCode===" + res.data.errcode);
  117. }
  118. }
  119. });
  120. },
  121. }
  122. };
  123. </script>
  124. <style lang="scss">
  125. .bg {
  126. padding: 15px;
  127. image {
  128. width: 100%;
  129. height: 10px;
  130. border-radius: 5px;
  131. }
  132. .login {
  133. .form_group {
  134. border: 1px solid $line;
  135. border-radius: 5px;
  136. margin-top: 10px;
  137. .lable {
  138. width: 10px;
  139. }
  140. input {
  141. border: 0px;
  142. }
  143. }
  144. .btn {
  145. margin-top: 25px;
  146. width: 82%;
  147. }
  148. .pass {
  149. width: 90%;
  150. text-align: right;
  151. padding-top: 20px;
  152. //color: $cor;
  153. }
  154. }
  155. }
  156. </style>