login-page.vue 4.5 KB

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