login.vue 3.8 KB

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