login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <script setup>
  2. import { reactive, ref } from "vue";
  3. import loginApi from "@/api/login";
  4. import { useUserStore } from "@/store";
  5. import { useRouter, useRoute } from "vue-router";
  6. import packageJson from "../../package.json";
  7. import { useAppStore } from "@/store";
  8. const appStore = useAppStore();
  9. const router = useRouter();
  10. const route = useRoute();
  11. const captcha = ref(null);
  12. const loading = ref(false);
  13. let isDevelop = import.meta.env.VITE_APP_ENV === "development";
  14. var odata = isDevelop
  15. ? { username: "admin", password: "123456", code: "" }
  16. : { username: "", password: "", code: "" };
  17. const form = reactive(odata);
  18. const refreshCaptcha = () => {
  19. form.code = "";
  20. form.uuid = "";
  21. loginApi.getCaptch().then((res) => {
  22. if (res.code === 200) {
  23. captcha.value = res.data.image;
  24. form.uuid = res.data.uuid;
  25. }
  26. });
  27. };
  28. refreshCaptcha();
  29. const userStore = useUserStore();
  30. const redirect = route.query.redirect ? route.query.redirect : "/";
  31. const handleSubmit = async ({ values, errors }) => {
  32. if (loading.value) {
  33. return;
  34. }
  35. loading.value = true;
  36. if (!errors) {
  37. const result = await userStore.login(form);
  38. if (!result) {
  39. loading.value = false;
  40. refreshCaptcha();
  41. return;
  42. }
  43. router.push(redirect);
  44. }
  45. loading.value = false;
  46. };
  47. </script>
  48. <template>
  49. <div
  50. class="login-container"
  51. :style="{ background: appStore.mode === 'dark' ? '#2e2e30e3' : '' }"
  52. >
  53. <h3 class="login-logo">
  54. <!-- <img src="/logo.png" alt="logo" />
  55. <span>{{ $title }}</span> -->
  56. </h3>
  57. <div
  58. class="login-width md:w-10/12 w-11/12 mx-auto flex justify-between h-full items-center"
  59. >
  60. <div
  61. class="w-6/12 mx-auto left-panel rounded-l pl-5 pr-5 hidden md:block"
  62. >
  63. <div class="logo">
  64. <span>{{ $title }} v{{ packageJson.version }}</span>
  65. </div>
  66. <div class="slogan flex justify-end">
  67. <!-- <span>---- {{ $t('sys.login.slogan') }}</span> -->
  68. </div>
  69. </div>
  70. <div class="md:w-6/12 w-11/12 md:rounded-r mx-auto pl-5 pr-5 pb-10">
  71. <h2 class="mt-10 text-3xl pb-0 mb-10 login-title">
  72. {{ $t("sys.login.title") }}
  73. </h2>
  74. <a-form :model="form" @submit="handleSubmit">
  75. <a-form-item
  76. field="username"
  77. :hide-label="true"
  78. :rules="[
  79. { required: true, message: $t('sys.login.usernameNotice') },
  80. ]"
  81. >
  82. <a-input
  83. v-model="form.username"
  84. class="w-full"
  85. size="large"
  86. :placeholder="$t('sys.login.username')"
  87. allow-clear
  88. >
  89. <template #prefix><icon-user /></template>
  90. </a-input>
  91. </a-form-item>
  92. <a-form-item
  93. field="password"
  94. :hide-label="true"
  95. :rules="[
  96. { required: true, message: $t('sys.login.passwordNotice') },
  97. ]"
  98. >
  99. <a-input-password
  100. v-model="form.password"
  101. :placeholder="$t('sys.login.password')"
  102. size="large"
  103. allow-clear
  104. >
  105. <template #prefix><icon-lock /></template>
  106. </a-input-password>
  107. </a-form-item>
  108. <a-form-item
  109. field="code"
  110. :hide-label="true"
  111. :rules="[
  112. {
  113. required: true,
  114. match: /^[a-zA-Z0-9]{4}$/,
  115. message: $t('sys.login.verifyCodeNotice'),
  116. },
  117. ]"
  118. >
  119. <a-input
  120. v-model="form.code"
  121. :placeholder="$t('sys.login.verifyCode')"
  122. size="large"
  123. allow-clear
  124. >
  125. <template #prefix><icon-safe /></template>
  126. <template #append>
  127. <img
  128. :src="captcha"
  129. style="height: 120px; height: 36px; cursor: pointer"
  130. @click="refreshCaptcha"
  131. />
  132. </template>
  133. </a-input>
  134. </a-form-item>
  135. <a-form-item :hide-label="true" class="mt-5">
  136. <a-button
  137. html-type="submit"
  138. type="primary"
  139. long
  140. size="large"
  141. :loading="loading"
  142. >
  143. {{ $t("sys.login.loginBtn") }}
  144. </a-button>
  145. </a-form-item>
  146. <!-- <a-divider orientation="center">{{
  147. $t("sys.login.otherLoginType")
  148. }}</a-divider>
  149. <div class="flex w-3/4 pt-2 mx-auto items-stretch justify-around">
  150. <a-avatar class="other-login wechat"><icon-wechat /></a-avatar>
  151. <a-avatar class="other-login alipay"
  152. ><icon-alipay-circle
  153. /></a-avatar>
  154. <a-avatar class="other-login qq"><icon-qq /></a-avatar>
  155. <a-avatar class="other-login weibo"><icon-weibo /></a-avatar>
  156. </div> -->
  157. </a-form>
  158. </div>
  159. </div>
  160. <div class="login-bg">
  161. <div class="fly bg-fly-circle1"></div>
  162. <div class="fly bg-fly-circle2"></div>
  163. <div class="fly bg-fly-circle3"></div>
  164. <div class="fly bg-fly-circle4"></div>
  165. </div>
  166. </div>
  167. </template>
  168. <style scoped lang="less">
  169. .login-container {
  170. width: 100%;
  171. height: 100%;
  172. position: absolute;
  173. background: rgb(145 185 233 / 50%);
  174. background-size: cover;
  175. z-index: 3;
  176. .login-logo {
  177. width: 100%;
  178. height: 80px;
  179. font-weight: 700;
  180. font-size: 20px;
  181. line-height: 32px;
  182. display: flex;
  183. padding: 0 20px;
  184. align-items: center;
  185. color: var(--color-text-1);
  186. img {
  187. width: 45px;
  188. height: 45px;
  189. margin-right: 10px;
  190. }
  191. }
  192. .login-width {
  193. max-width: 950px;
  194. background-color: var(--color-bg-3);
  195. padding: 10px;
  196. height: 500px;
  197. position: relative;
  198. top: 40%;
  199. margin-top: -255px;
  200. border-radius: 10px;
  201. z-index: 999;
  202. box-shadow: 0 2px 4px 2px #00000014;
  203. }
  204. .left-panel {
  205. height: 491px;
  206. background-image: url(@/assets/login_picture.svg);
  207. background-repeat: no-repeat;
  208. background-position: center 60px;
  209. background-size: contain;
  210. }
  211. .logo {
  212. display: flex;
  213. margin-top: 20px;
  214. color: #333;
  215. span {
  216. font-size: 28px;
  217. margin-left: 15px;
  218. color: rgb(var(--primary-6));
  219. }
  220. }
  221. .slogan {
  222. font-size: 16px;
  223. line-height: 50px;
  224. color: var(--color-text-1);
  225. }
  226. .login-title {
  227. color: var(--color-text-1);
  228. }
  229. :deep(.arco-input-append) {
  230. padding: 0 !important;
  231. }
  232. .other-login {
  233. cursor: pointer;
  234. }
  235. .qq:hover,
  236. .alipay:hover {
  237. background: #165dff;
  238. }
  239. .wechat:hover {
  240. background: #0f9c02;
  241. }
  242. .weibo:hover {
  243. background: #f3ce2b;
  244. }
  245. }
  246. .login-bg {
  247. width: 100%;
  248. overflow: hidden;
  249. z-index: 1;
  250. }
  251. .fly {
  252. pointer-events: none;
  253. position: fixed;
  254. z-index: 9999;
  255. }
  256. .bg-fly-circle1 {
  257. left: 40px;
  258. top: 100px;
  259. width: 100px;
  260. height: 100px;
  261. border-radius: 50%;
  262. background: linear-gradient(
  263. to right,
  264. rgba(var(--primary-6), 0.07),
  265. rgba(var(--primary-6), 0.04)
  266. );
  267. animation: move-ce64e0ea 2.5s linear infinite;
  268. }
  269. .bg-fly-circle2 {
  270. left: 15%;
  271. bottom: 5%;
  272. width: 150px;
  273. height: 150px;
  274. border-radius: 50%;
  275. background: linear-gradient(
  276. to right,
  277. rgba(var(--primary-6), 0.08),
  278. rgba(var(--primary-6), 0.04)
  279. );
  280. animation: move-ce64e0ea 3s linear infinite;
  281. }
  282. .bg-fly-circle3 {
  283. right: 12%;
  284. top: 90px;
  285. width: 145px;
  286. height: 145px;
  287. border-radius: 50%;
  288. background: linear-gradient(
  289. to right,
  290. rgba(var(--primary-6), 0.1),
  291. rgba(var(--primary-6), 0.04)
  292. );
  293. animation: move-ce64e0ea 2.5s linear infinite;
  294. }
  295. .bg-fly-circle4 {
  296. right: 5%;
  297. top: 60%;
  298. width: 160px;
  299. height: 160px;
  300. border-radius: 50%;
  301. background: linear-gradient(
  302. to right,
  303. rgba(var(--primary-6), 0.02),
  304. rgba(var(--primary-6), 0.04)
  305. );
  306. animation: move-ce64e0ea 3.5s linear infinite;
  307. }
  308. @keyframes move-ce64e0ea {
  309. 0% {
  310. transform: translateY(0) scale(1);
  311. }
  312. 50% {
  313. transform: translateY(25px) scale(1.1);
  314. }
  315. to {
  316. transform: translateY(0) scale(1);
  317. }
  318. }
  319. </style>