login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div id="userLayout" class="user-layout-wrapper">
  3. <div class="container">
  4. <div class="top">
  5. <div class="desc">
  6. <img class="logo_login" src="@/assets/logo_login.png" alt="" />
  7. </div>
  8. <div class="header">
  9. <a href="/">
  10. <!-- <img src="~@/assets/logo.png" class="logo" alt="logo" /> -->
  11. <span class="title">Gin-Vue-Admin</span>
  12. </a>
  13. </div>
  14. </div>
  15. <div class="main">
  16. <el-form
  17. :model="loginForm"
  18. :rules="rules"
  19. ref="loginForm"
  20. @keyup.enter.native="submitForm"
  21. >
  22. <el-form-item prop="username">
  23. <el-input
  24. placeholder="请输入用户名"
  25. v-model="loginForm.username"
  26. >
  27. <i
  28. class="el-input__icon el-icon-user"
  29. slot="suffix"
  30. ></i></el-input>
  31. </el-form-item>
  32. <el-form-item prop="password">
  33. <el-input
  34. :type="lock === 'lock' ? 'password' : 'text'"
  35. placeholder="请输入密码"
  36. v-model="loginForm.password"
  37. >
  38. <i
  39. :class="'el-input__icon el-icon-' + lock"
  40. @click="changeLock"
  41. slot="suffix"
  42. ></i>
  43. </el-input>
  44. </el-form-item>
  45. <el-form-item style="position:relative">
  46. <el-input
  47. v-model="loginForm.captcha"
  48. name="logVerify"
  49. placeholder="请输入验证码"
  50. style="width:60%"
  51. />
  52. <div class="vPic">
  53. <img
  54. v-if="picPath"
  55. :src="path + picPath"
  56. alt="请输入验证码"
  57. @click="loginVefify()"
  58. />
  59. </div>
  60. </el-form-item>
  61. <el-form-item>
  62. <el-button type="primary" @click="submitForm" style="width:100%"
  63. >登 录</el-button
  64. >
  65. </el-form-item>
  66. </el-form>
  67. </div>
  68. <div class="footer">
  69. <div class="links">
  70. <a href="http://doc.henrongyi.top/"
  71. ><img src="@/assets/docs.png" class="link-icon"
  72. /></a>
  73. <a href="https://www.yuque.com/flipped-aurora/"
  74. ><img src="@/assets/yuque.png" class="link-icon"
  75. /></a>
  76. <a href="https://github.com/flipped-aurora/gin-vue-admin"
  77. ><img src="@/assets/github.png" class="link-icon"
  78. /></a>
  79. <a href="https://space.bilibili.com/322210472"
  80. ><img src="@/assets/video.png" class="link-icon"
  81. /></a>
  82. </div>
  83. <div class="copyright">
  84. Copyright &copy; {{ curYear }} 💖flipped-aurora
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. </template>
  90. <script>
  91. import { mapActions } from "vuex";
  92. import { captcha } from "@/api/user";
  93. const path = process.env.VUE_APP_BASE_API;
  94. export default {
  95. name: "Login",
  96. data() {
  97. const checkUsername = (rule, value, callback) => {
  98. if (value.length < 5 || value.length > 12) {
  99. return callback(new Error("请输入正确的用户名"));
  100. } else {
  101. callback();
  102. }
  103. };
  104. const checkPassword = (rule, value, callback) => {
  105. if (value.length < 6 || value.length > 12) {
  106. return callback(new Error("请输入正确的密码"));
  107. } else {
  108. callback();
  109. }
  110. };
  111. return {
  112. curYear: 0,
  113. lock: "lock",
  114. loginForm: {
  115. username: "admin",
  116. password: "123456",
  117. captcha: "",
  118. captchaId: "",
  119. },
  120. rules: {
  121. username: [{ validator: checkUsername, trigger: "blur" }],
  122. password: [{ validator: checkPassword, trigger: "blur" }],
  123. },
  124. path: path,
  125. logVerify: "",
  126. picPath: "",
  127. };
  128. },
  129. created() {
  130. this.loginVefify();
  131. this.curYear = new Date().getFullYear();
  132. },
  133. methods: {
  134. ...mapActions("user", ["LoginIn"]),
  135. async login() {
  136. await this.LoginIn(this.loginForm);
  137. },
  138. async submitForm() {
  139. this.$refs.loginForm.validate(async (v) => {
  140. if (v) {
  141. this.login();
  142. this.loginVefify();
  143. } else {
  144. this.$message({
  145. type: "error",
  146. message: "请正确填写登录信息",
  147. showClose: true,
  148. });
  149. this.loginVefify();
  150. return false;
  151. }
  152. });
  153. },
  154. changeLock() {
  155. this.lock === "lock" ? (this.lock = "unlock") : (this.lock = "lock");
  156. },
  157. loginVefify() {
  158. captcha({}).then((ele) => {
  159. this.picPath = ele.data.picPath;
  160. this.loginForm.captchaId = ele.data.captchaId;
  161. });
  162. },
  163. },
  164. };
  165. </script>
  166. <style scoped lang="scss">
  167. .login-register-box {
  168. height: 100vh;
  169. .login-box {
  170. width: 40vw;
  171. position: absolute;
  172. left: 50%;
  173. margin-left: -22vw;
  174. top: 5vh;
  175. .logo {
  176. height: 35vh;
  177. width: 35vh;
  178. }
  179. }
  180. }
  181. .link-icon {
  182. width: 20px;
  183. min-width: 20px;
  184. height: 20px;
  185. border-radius: 10px;
  186. }
  187. .vPic {
  188. width: 33%;
  189. height: 38px;
  190. float: right !important;
  191. background: #ccc;
  192. img {
  193. cursor: pointer;
  194. vertical-align: middle;
  195. }
  196. }
  197. .logo_login {
  198. width: 100px;
  199. }
  200. #userLayout.user-layout-wrapper {
  201. height: 100%;
  202. position: relative;
  203. &.mobile {
  204. .container {
  205. .main {
  206. max-width: 368px;
  207. width: 98%;
  208. }
  209. }
  210. }
  211. .container {
  212. position: relative;
  213. overflow: auto;
  214. width: 100%;
  215. min-height: 100%;
  216. background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
  217. background-size: 100%;
  218. padding: 110px 0 144px;
  219. a {
  220. text-decoration: none;
  221. }
  222. .top {
  223. text-align: center;
  224. margin-top: 20px;
  225. .header {
  226. height: 44px;
  227. line-height: 44px;
  228. margin-bottom: 30px;
  229. .badge {
  230. position: absolute;
  231. display: inline-block;
  232. line-height: 1;
  233. vertical-align: middle;
  234. margin-left: -12px;
  235. margin-top: -10px;
  236. opacity: 0.8;
  237. }
  238. .logo {
  239. height: 44px;
  240. vertical-align: top;
  241. margin-right: 16px;
  242. border-style: none;
  243. }
  244. .title {
  245. font-size: 33px;
  246. color: rgba(0, 0, 0, 0.85);
  247. font-family: Avenir, "Helvetica Neue", Arial, Helvetica, sans-serif;
  248. font-weight: 600;
  249. position: relative;
  250. top: 2px;
  251. }
  252. }
  253. .desc {
  254. font-size: 14px;
  255. color: rgba(0, 0, 0, 0.45);
  256. margin-top: 12px;
  257. }
  258. }
  259. .main {
  260. min-width: 260px;
  261. width: 368px;
  262. margin: 0 auto;
  263. }
  264. .footer {
  265. position: relative;
  266. width: 100%;
  267. padding: 0 20px;
  268. margin: 40px 0 10px;
  269. text-align: center;
  270. .links {
  271. margin-bottom: 8px;
  272. font-size: 14px;
  273. width: 330px;
  274. display: inline-flex;
  275. flex-direction: row;
  276. justify-content: space-between;
  277. padding-right: 40px;
  278. a {
  279. color: rgba(0, 0, 0, 0.45);
  280. transition: all 0.3s;
  281. }
  282. }
  283. .copyright {
  284. color: rgba(0, 0, 0, 0.45);
  285. font-size: 14px;
  286. padding-right: 40px;
  287. }
  288. }
  289. }
  290. }
  291. </style>