login.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!-- -->
  2. <template>
  3. <div class="loginback">
  4. <div class="loginbox">
  5. <div class="loginbox_title">
  6. <p class="top">深圳海关外来入侵物种</p>
  7. <p class="bottom">监测指挥中心</p>
  8. </div>
  9. <el-form
  10. :model="ruleForm"
  11. :rules="rules"
  12. ref="ruleForm"
  13. class="demo-ruleForm"
  14. >
  15. <el-form-item label="" prop="username">
  16. <el-input
  17. prefix-icon="iconfont icon-yonghu"
  18. v-model="ruleForm.username"
  19. placeholder="请输入用户名"
  20. ></el-input>
  21. </el-form-item>
  22. <el-form-item label="" prop="password">
  23. <el-input
  24. prefix-icon="iconfont icon-mima2"
  25. v-model="ruleForm.password"
  26. placeholder="请输入密码"
  27. type="password"
  28. ></el-input>
  29. </el-form-item>
  30. <el-form-item label="">
  31. <el-checkbox-group v-model="ruleForm.type">
  32. <el-checkbox label="记住密码" name="type"></el-checkbox>
  33. </el-checkbox-group>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="info" @click="submitForm('ruleForm')" size="mini"
  37. >登&emsp;&emsp;录</el-button
  38. >
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  46. export default {
  47. //import引入的组件需要注入到对象中才能使用
  48. components: {},
  49. data() {
  50. //这里存放数据
  51. return {
  52. ruleForm: {
  53. username: "",
  54. password: "",
  55. type: "",
  56. },
  57. rules: {
  58. username: [
  59. { required: true, message: "请输入用户名", trigger: "blur" },
  60. ],
  61. password: [{ required: true, message: "请输入密码", trigger: "blur" }],
  62. },
  63. };
  64. },
  65. //监听属性 类似于data概念
  66. computed: {},
  67. //监控data中的数据变化
  68. watch: {},
  69. //方法集合
  70. methods: {
  71. submitForm(formName) {
  72. this.$refs[formName].validate((valid) => {
  73. if (valid) {
  74. if (this.ruleForm.type) {
  75. localStorage.setItem("username", this.ruleForm.username);
  76. localStorage.setItem("password", this.ruleForm.password);
  77. localStorage.setItem("type", 1);
  78. } else {
  79. localStorage.removeItem("username");
  80. localStorage.removeItem("password");
  81. localStorage.setItem("type", 0);
  82. }
  83. this.$axios({
  84. method: "POST",
  85. url: "/api/api_gateway?method=sysmenage.usermanager.user_login",
  86. data: this.qs.stringify({
  87. username: this.ruleForm.username,
  88. password: this.ruleForm.password,
  89. }),
  90. }).then((res) => {
  91. // console.log(res);
  92. if (res.data.data) {
  93. localStorage.setItem("session", res.data.data.session_key);
  94. this.$router.push("/Index/facilitydistribute");
  95. }
  96. });
  97. } else {
  98. return false;
  99. }
  100. });
  101. },
  102. },
  103. beforeCreate() {}, //生命周期 - 创建之前
  104. //生命周期 - 创建完成(可以访问当前this实例)
  105. created() {},
  106. beforeMount() {}, //生命周期 - 挂载之前
  107. //生命周期 - 挂载完成(可以访问DOM元素)
  108. mounted() {
  109. this.ruleForm.type = Boolean(Number(localStorage.getItem("type")));
  110. // console.log(this.ruleForm.type)
  111. if (this.ruleForm.type) {
  112. this.ruleForm.username = localStorage.getItem("username");
  113. this.ruleForm.password = localStorage.getItem("password");
  114. }
  115. },
  116. beforeUpdate() {}, //生命周期 - 更新之前
  117. updated() {}, //生命周期 - 更新之后
  118. beforeDestroy() {}, //生命周期 - 销毁之前
  119. destroyed() {}, //生命周期 - 销毁完成
  120. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  121. };
  122. </script>
  123. <style lang="less" scoped>
  124. .loginback {
  125. width: 100%;
  126. height: 100vh;
  127. background: url("../../assets/loginbg.png");
  128. background-color: #fff;
  129. background-size:100%;
  130. }
  131. .loginbox {
  132. width: 20%;
  133. padding: 20px;
  134. position: absolute;
  135. top: 25%;
  136. right: 17%;
  137. .loginbox_title {
  138. margin-bottom: 22px;
  139. p {
  140. font-weight: 700;
  141. }
  142. .top {
  143. font-size: 22px;
  144. margin-bottom: 10px;
  145. }
  146. .bottom {
  147. font-size: 28px;
  148. }
  149. }
  150. .el-input {
  151. // margin-bottom: 15px;
  152. }
  153. /deep/.el-input__inner {
  154. background-color: transparent;
  155. border: 0;
  156. border-bottom: 1px solid #cccccc;
  157. border-radius: 0;
  158. }
  159. /deep/.el-button--info {
  160. background-color: #409eff;
  161. border-color: #409eff;
  162. width: 100%;
  163. height: 40px;
  164. font-size: 16px;
  165. }
  166. }
  167. </style>