index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <script setup lang="ts">
  2. import Motion from "./utils/motion";
  3. import { useRouter } from "vue-router";
  4. import { loginRules } from "./utils/rule";
  5. import phone from "./components/phone.vue";
  6. import qrCode from "./components/qrCode.vue";
  7. import regist from "./components/regist.vue";
  8. import update from "./components/update.vue";
  9. import { initRouter } from "/@/router/utils";
  10. import { message } from "@pureadmin/components";
  11. import type { FormInstance } from "element-plus";
  12. import { storageSession } from "/@/utils/storage";
  13. import { ref, reactive, watch, computed } from "vue";
  14. import { operates, thirdParty } from "./utils/enums";
  15. import { useUserStoreHook } from "/@/store/modules/user";
  16. import { bg, avatar, currentWeek } from "./utils/static";
  17. import { ReImageVerify } from "/@/components/ReImageVerify";
  18. import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
  19. const imgCode = ref("");
  20. const router = useRouter();
  21. const loading = ref(false);
  22. const checked = ref(false);
  23. const ruleFormRef = ref<FormInstance>();
  24. const currentPage = computed(() => {
  25. return useUserStoreHook().currentPage;
  26. });
  27. const ruleForm = reactive({
  28. username: "admin",
  29. password: "admin123",
  30. verifyCode: ""
  31. });
  32. const onLogin = async (formEl: FormInstance | undefined) => {
  33. loading.value = true;
  34. if (!formEl) return;
  35. await formEl.validate((valid, fields) => {
  36. if (valid) {
  37. // 模拟请求,需根据实际开发进行修改
  38. setTimeout(() => {
  39. loading.value = false;
  40. storageSession.setItem("info", {
  41. username: "admin",
  42. accessToken: "eyJhbGciOiJIUzUxMiJ9.test"
  43. });
  44. initRouter("admin").then(() => {});
  45. message.success("登陆成功");
  46. router.push("/");
  47. }, 2000);
  48. } else {
  49. loading.value = false;
  50. return fields;
  51. }
  52. });
  53. };
  54. function onHandle(value) {
  55. useUserStoreHook().SET_CURRENTPAGE(value);
  56. }
  57. watch(imgCode, value => {
  58. useUserStoreHook().SET_VERIFYCODE(value);
  59. });
  60. </script>
  61. <template>
  62. <img :src="bg" class="wave" />
  63. <div class="login-container">
  64. <div class="img">
  65. <component :is="currentWeek" />
  66. </div>
  67. <div class="login-box">
  68. <div class="login-form">
  69. <avatar class="avatar" />
  70. <Motion>
  71. <h2>Pure Admin</h2>
  72. </Motion>
  73. <el-form
  74. v-if="currentPage === 0"
  75. ref="ruleFormRef"
  76. :model="ruleForm"
  77. :rules="loginRules"
  78. size="large"
  79. @keyup.enter="onLogin(ruleFormRef)"
  80. >
  81. <Motion :delay="100">
  82. <el-form-item prop="username">
  83. <el-input
  84. clearable
  85. v-model="ruleForm.username"
  86. placeholder="账号"
  87. :prefix-icon="useRenderIcon('user')"
  88. />
  89. </el-form-item>
  90. </Motion>
  91. <Motion :delay="150">
  92. <el-form-item prop="password">
  93. <el-input
  94. clearable
  95. show-password
  96. v-model="ruleForm.password"
  97. placeholder="密码"
  98. :prefix-icon="useRenderIcon('lock')"
  99. />
  100. </el-form-item>
  101. </Motion>
  102. <Motion :delay="200">
  103. <el-form-item prop="verifyCode">
  104. <el-input
  105. clearable
  106. v-model="ruleForm.verifyCode"
  107. placeholder="验证码"
  108. :prefix-icon="
  109. useRenderIcon('ri:shield-keyhole-line', { online: true })
  110. "
  111. >
  112. <template v-slot:append>
  113. <ReImageVerify v-model:code="imgCode" />
  114. </template>
  115. </el-input>
  116. </el-form-item>
  117. </Motion>
  118. <Motion :delay="250">
  119. <el-form-item>
  120. <div class="w-full h-20px flex justify-between items-center">
  121. <el-checkbox v-model="checked">记住密码</el-checkbox>
  122. <el-button
  123. type="text"
  124. @click="useUserStoreHook().SET_CURRENTPAGE(4)"
  125. >
  126. 忘记密码?
  127. </el-button>
  128. </div>
  129. <el-button
  130. class="w-full mt-4"
  131. size="default"
  132. type="primary"
  133. :loading="loading"
  134. @click="onLogin(ruleFormRef)"
  135. >
  136. 登录
  137. </el-button>
  138. </el-form-item>
  139. </Motion>
  140. <Motion :delay="300">
  141. <el-form-item>
  142. <div class="w-full h-20px flex justify-between items-center">
  143. <el-button
  144. v-for="(item, index) in operates"
  145. :key="index"
  146. class="w-full mt-4"
  147. size="default"
  148. @click="onHandle(index + 1)"
  149. >
  150. {{ item.title }}
  151. </el-button>
  152. </div>
  153. </el-form-item>
  154. </Motion>
  155. </el-form>
  156. <Motion v-if="currentPage === 0" :delay="350">
  157. <el-form-item>
  158. <el-divider>
  159. <p class="text-gray-500 text-xs">第三方登录</p>
  160. </el-divider>
  161. <div class="w-full flex justify-evenly">
  162. <span
  163. v-for="(item, index) in thirdParty"
  164. :key="index"
  165. :title="`${item.title}登陆`"
  166. >
  167. <IconifyIconOnline
  168. :icon="`ri:${item.icon}-fill`"
  169. width="20"
  170. class="cursor-pointer text-gray-500 hover:text-blue-400"
  171. />
  172. </span>
  173. </div>
  174. </el-form-item>
  175. </Motion>
  176. <!-- 手机号登陆 -->
  177. <phone v-if="currentPage === 1" />
  178. <!-- 二维码登陆 -->
  179. <qrCode v-if="currentPage === 2" />
  180. <!-- 注册 -->
  181. <regist v-if="currentPage === 3" />
  182. <!-- 忘记密码 -->
  183. <update v-if="currentPage === 4" />
  184. </div>
  185. </div>
  186. </div>
  187. </template>
  188. <style scoped>
  189. @import url("/@/style/login.css");
  190. </style>
  191. <style lang="scss" scoped>
  192. :deep(.el-input-group__append, .el-input-group__prepend) {
  193. padding: 0;
  194. }
  195. </style>