index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div
  3. id="userLayout"
  4. class="w-full h-full relative"
  5. >
  6. <div
  7. class="rounded-lg flex items-center justify-evenly w-full h-full bg-white md:w-screen md:h-screen md:bg-[#194bfb]"
  8. >
  9. <div class="md:w-3/5 w-10/12 h-full flex items-center justify-evenly">
  10. <div class="oblique h-[130%] w-3/5 bg-white transform -rotate-12 absolute -ml-52" />
  11. <!-- 分割斜块 -->
  12. <div class="z-[999] pt-12 pb-10 md:w-96 w-full rounded-lg flex flex-col justify-between box-border">
  13. <div>
  14. <div class="flex items-center justify-center">
  15. <img
  16. class="w-24"
  17. :src="$GIN_VUE_ADMIN.appLogo"
  18. alt
  19. >
  20. </div>
  21. <div class="mb-9">
  22. <p class="text-center text-4xl font-bold">{{ $GIN_VUE_ADMIN.appName }}</p>
  23. <p class="text-center text-sm font-normal text-gray-500 mt-2.5">A management platform using Golang and Vue
  24. </p>
  25. </div>
  26. <el-form
  27. ref="loginForm"
  28. :model="loginFormData"
  29. :rules="rules"
  30. :validate-on-rule-change="false"
  31. @keyup.enter="submitForm"
  32. >
  33. <el-form-item
  34. prop="username"
  35. class="mb-6"
  36. >
  37. <el-input
  38. v-model="loginFormData.username"
  39. size="large"
  40. placeholder="请输入用户名"
  41. suffix-icon="user"
  42. />
  43. </el-form-item>
  44. <el-form-item
  45. prop="password"
  46. class="mb-6"
  47. >
  48. <el-input
  49. v-model="loginFormData.password"
  50. show-password
  51. size="large"
  52. type="password"
  53. placeholder="请输入密码"
  54. />
  55. </el-form-item>
  56. <el-form-item
  57. v-if="loginFormData.openCaptcha"
  58. prop="captcha"
  59. class="mb-6"
  60. >
  61. <div class="flex w-full justify-between">
  62. <el-input
  63. v-model="loginFormData.captcha"
  64. placeholder="请输入验证码"
  65. size="large"
  66. class="flex-1 mr-5"
  67. />
  68. <div class="w-1/3 h-11 bg-[#c3d4f2] rounded">
  69. <img
  70. v-if="picPath"
  71. class="w-full h-full"
  72. :src="picPath"
  73. alt="请输入验证码"
  74. @click="loginVerify()"
  75. >
  76. </div>
  77. </div>
  78. </el-form-item>
  79. <el-form-item class="mb-6">
  80. <el-button
  81. class="shadow shadow-blue-600 h-11 w-full"
  82. type="primary"
  83. size="large"
  84. @click="submitForm"
  85. >登 录</el-button>
  86. </el-form-item>
  87. </el-form>
  88. </div>
  89. </div>
  90. </div>
  91. <div class="hidden md:block w-1/2 h-full float-right bg-[#194bfb]"><img
  92. class="h-full"
  93. src="@/assets/login_right_banner.jpg"
  94. alt="banner"
  95. ></div>
  96. </div>
  97. <BottomInfo class="left-0 right-0 absolute bottom-3 mx-auto w-full z-20">
  98. <div class="links items-center justify-center gap-2 hidden md:flex">
  99. <a
  100. href="http://doc.henrongyi.top/"
  101. target="_blank"
  102. >
  103. <img
  104. src="@/assets/docs.png"
  105. class="w-8 h-8"
  106. alt="文档"
  107. >
  108. </a>
  109. <a
  110. href="https://support.qq.com/product/371961"
  111. target="_blank"
  112. >
  113. <img
  114. src="@/assets/kefu.png"
  115. class="w-8 h-8"
  116. alt="客服"
  117. >
  118. </a>
  119. <a
  120. href="https://github.com/flipped-aurora/gin-vue-admin"
  121. target="_blank"
  122. >
  123. <img
  124. src="@/assets/github.png"
  125. class="w-8 h-8"
  126. alt="github"
  127. >
  128. </a>
  129. <a
  130. href="https://space.bilibili.com/322210472"
  131. target="_blank"
  132. >
  133. <img
  134. src="@/assets/video.png"
  135. class="w-8 h-8"
  136. alt="视频站"
  137. >
  138. </a>
  139. </div>
  140. </BottomInfo>
  141. </div>
  142. </template>
  143. <script setup>
  144. import { captcha } from '@/api/user'
  145. import { checkDB } from '@/api/initdb'
  146. import BottomInfo from '@/view/layout/bottomInfo/bottomInfo.vue'
  147. import { reactive, ref } from 'vue'
  148. import { ElMessage } from 'element-plus'
  149. import { useRouter } from 'vue-router'
  150. import { useUserStore } from '@/pinia/modules/user'
  151. defineOptions({
  152. name: 'Login',
  153. })
  154. const router = useRouter()
  155. // 验证函数
  156. const checkUsername = (rule, value, callback) => {
  157. if (value.length < 5) {
  158. return callback(new Error('请输入正确的用户名'))
  159. } else {
  160. callback()
  161. }
  162. }
  163. const checkPassword = (rule, value, callback) => {
  164. if (value.length < 6) {
  165. return callback(new Error('请输入正确的密码'))
  166. } else {
  167. callback()
  168. }
  169. }
  170. // 获取验证码
  171. const loginVerify = () => {
  172. captcha({}).then(async(ele) => {
  173. rules.captcha.push({
  174. max: ele.data.captchaLength,
  175. min: ele.data.captchaLength,
  176. message: `请输入${ele.data.captchaLength}位验证码`,
  177. trigger: 'blur',
  178. })
  179. picPath.value = ele.data.picPath
  180. loginFormData.captchaId = ele.data.captchaId
  181. loginFormData.openCaptcha = ele.data.openCaptcha
  182. })
  183. }
  184. loginVerify()
  185. // 登录相关操作
  186. const loginForm = ref(null)
  187. const picPath = ref('')
  188. const loginFormData = reactive({
  189. username: '',
  190. password: '',
  191. captcha: '',
  192. captchaId: '',
  193. openCaptcha: false,
  194. })
  195. const rules = reactive({
  196. username: [{ validator: checkUsername, trigger: 'blur' }],
  197. password: [{ validator: checkPassword, trigger: 'blur' }],
  198. captcha: [
  199. {
  200. message: '验证码格式不正确',
  201. trigger: 'blur',
  202. },
  203. ],
  204. })
  205. const userStore = useUserStore()
  206. const login = async() => {
  207. return await userStore.LoginIn(loginFormData)
  208. }
  209. const submitForm = () => {
  210. loginForm.value.validate(async(v) => {
  211. if (v) {
  212. const flag = await login()
  213. if (!flag) {
  214. loginVerify()
  215. }
  216. } else {
  217. ElMessage({
  218. type: 'error',
  219. message: '请正确填写登录信息',
  220. showClose: true,
  221. })
  222. loginVerify()
  223. return false
  224. }
  225. })
  226. }
  227. // 跳转初始化
  228. const checkInit = async() => {
  229. const res = await checkDB()
  230. if (res.code === 0) {
  231. if (res.data?.needInit) {
  232. userStore.NeedInit()
  233. router.push({ name: 'Init' })
  234. } else {
  235. ElMessage({
  236. type: 'info',
  237. message: '已配置数据库信息,无法初始化',
  238. })
  239. }
  240. }
  241. }
  242. </script>