login.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. <button class="btn" @click="login()">登陆</button>
  15. <navigator url="/pages/find_pass" class="pass" hover-class="none">找回密码</navigator>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. item: {domainName:'柳工',remember:'0',debug:'false',checkcode:'',language:'CN',url:'/obpm'},
  25. uitem:{}
  26. };
  27. },
  28. onLoad(e) {
  29. //刷新
  30. uni.$on('index', res => {
  31. //this.refresh();
  32. uni.showLoading({
  33. title: '加载中',
  34. mask: true
  35. });
  36. });
  37. },
  38. mounted() {
  39. //自动登陆
  40. if (this.hasLogin()) {
  41. uni.switchTab({ url: '/pages/index/index' ,
  42. });
  43. }
  44. },
  45. methods: {
  46. //登陆
  47. login() {
  48. let rule = [{ name: 'username', checkType: 'notnull', errorMsg: '请输入账号' }, { name: 'password', checkType: 'notnull', errorMsg: '请输入密码' }];
  49. //if (!vm.verify.check(this.item, rule)) {
  50. // uni.showModal({ content: this.verify.error, showCancel: false });
  51. // return false;
  52. // }
  53. this.item.password = window.btoa(this.item.password);
  54. var p1=this.item.password.slice(2);
  55. var p2=this.item.password.substring(0,2)
  56. this.item.password=p1+p2;
  57. //console.log("this.item:"+this.item);
  58. this.http.request({
  59. url: this.http.urls.login,
  60. data: this.item,
  61. method: 'post',
  62. success: res => {
  63. console.log("gfgh==="+JSON.stringify(res));
  64. if(res.data.resultCode==1){
  65. uni.removeStorageSync('user');
  66. uni.setStorageSync('user', res.data);
  67. uni.$emit('index');
  68. uni.redirectTo({ url: '/pages/index/index' ,
  69. });
  70. console.log("res.data.resultCode==="+res.data.resultCode);
  71. }
  72. }
  73. });
  74. },
  75. }
  76. };
  77. </script>
  78. <style lang="scss">
  79. .bg {
  80. padding: 15px;
  81. image {
  82. width: 100%;
  83. height: 170px;
  84. border-radius: 5px;
  85. }
  86. .login {
  87. .form_group {
  88. border: 1px solid $line;
  89. border-radius: 5px;
  90. margin-top: 10px;
  91. .lable {
  92. width: 10px;
  93. }
  94. input {
  95. border: 0px;
  96. }
  97. }
  98. .btn {
  99. margin-top: 25px;
  100. width: 82%;
  101. }
  102. .pass {
  103. width: 90%;
  104. text-align: right;
  105. padding-top: 20px;
  106. //color: $cor;
  107. }
  108. }
  109. }
  110. </style>