login-page.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="login-panel">
  3. <el-form class="mg-b-16">
  4. <el-form-item class="mg-b-8">
  5. <el-input v-model="username" placeholder="请输入登录名"></el-input>
  6. </el-form-item>
  7. <el-form-item class="mg-b-8">
  8. <el-input
  9. v-model="password"
  10. placeholder="请输入密码"
  11. show-password
  12. ></el-input>
  13. </el-form-item>
  14. </el-form>
  15. <button style="width:100%;" class="btn" @click="Login">登录</button>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. username: "",
  23. password: "",
  24. token: "",
  25. };
  26. },
  27. props: { token: "" },
  28. emits: {
  29. onLogin: null,
  30. },
  31. methods: {
  32. Login() {
  33. let that = this;
  34. if (that.username !== "" && that.password !== "") {
  35. that.API.requestData({
  36. isMust: false, // 请求是否携带 token ,默认为 true ,可缺省
  37. baseURL: "http://192.168.10.44:8082",
  38. method: "POST", // 请求方式,默认为 GET ,可缺省
  39. subUrl: "sys/login", // 请求接口地址,必传项
  40. data: {
  41. username: that.username,
  42. password: that.password,
  43. },
  44. success(res) {
  45. console.log("res:", res);
  46. if (res.data.authToken && res.data.user.laborName) {
  47. localStorage.setItem("authToken", res.data.authToken);
  48. localStorage.setItem("username", res.data.user.laborName);
  49. that.BASE.showMsg({
  50. msg: "登录成功",
  51. type: "success",
  52. });
  53. that.$router.push("/"); // 跳转到首页
  54. } else {
  55. that.BASE.showMsg({
  56. type: "error",
  57. msg: "输入的账号或密码错误",
  58. });
  59. }
  60. },
  61. });
  62. // that.$router.push('/monitor/home')
  63. // console.log(that.username,"---",that.password)
  64. } else {
  65. that.BASE.showMsg({
  66. type: "warning",
  67. msg: "请输入完整的账号或密码",
  68. });
  69. }
  70. // localStorage.setItem("token",'2222')
  71. // that.token=localStorage.getItem('token')
  72. // console.log("token:",that.token)
  73. // that.$emit("onLogin", {
  74. // username: that.username,
  75. // password: that.password,
  76. // token:that.token
  77. // });
  78. // console.log("token:",that.token)
  79. // that.$router.push('/')
  80. },
  81. },
  82. created() {
  83. // console.log("username:", that.username, "----", "password:", that.password);
  84. // that.$nextTick(() => {
  85. // that.API.requestData({
  86. // isMust: false, // 请求是否携带 token ,默认为 true ,可缺省
  87. // baseURL:"http://192.168.10.44:8082",
  88. // method: "POST", // 请求方式,默认为 GET ,可缺省
  89. // subUrl: "admin/loginvue", // 请求接口地址,必传项
  90. // data: {
  91. // username: that.username,
  92. // password: that.password,
  93. // },
  94. // success(res) {
  95. // localStorage.setItem("authToken", res.data.authToken);
  96. // localStorage.setItem("username", res.data.user.laborName);
  97. // // that.API.requestData({
  98. // // method: "POST", // 请求方式,默认为 GET ,可缺省
  99. // // subUrl: "admin/usermenu", // 请求接口地址,必传项
  100. // // success() {
  101. // // that.BASE.showMsg({
  102. // // msg: "登陆成功",
  103. // // type: "success",
  104. // // });
  105. // // that.$router.push('/'); // 跳转到首页
  106. // // },
  107. // // });
  108. // },
  109. // });
  110. // });
  111. },
  112. };
  113. </script>
  114. <style lang="less">
  115. .login-panel {
  116. width: 300px;
  117. height: 200px;
  118. position: absolute;
  119. padding: 32px;
  120. left: calc(50vw - 150px);
  121. top: calc(50vh - 120px);
  122. border: 1px solid @green;
  123. border-radius: 8px;
  124. }
  125. </style>