login.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <div class="flex column center align-center wrapper" v-if="config.$state.layout.screenWidth>=768">
  3. <div class="box">
  4. <div class="wrapper_login">
  5. <div class="flex grid12 gaps custom-gaps">
  6. <div class="col-6 sidebox">
  7. <div style="z-index:1;position: relative;">
  8. <img class="mt-10 mb-30" src="~assets/logo.svg" style="width:80%" />
  9. <div class="mb-20" style="color:#fff">品牌介绍</div>
  10. <div class="mb-30">
  11. 平台采用Vue.js3.0技术,结合Typescript.js、pania缓存技术、Element-Plus、vite打包技术架构前端技术栈,后端采用SpringBoot,结合Mybatis-Plus技术、Mysql8.0、Redis等架构接口服务端,技术新效率高交互好。
  12. </div>
  13. <el-divider class="mt-30" style="background-color:#909399"></el-divider>
  14. <div class="mt-30">坚持自主、高效,追求卓越、超越梦想。</div>
  15. </div>
  16. </div>
  17. <div class="col-6">
  18. <div style="height: 100%; padding: 64px 70px 48px; position: relative" v-show="loginMode==1">
  19. <div style="color:#404856;margin-bottom: 40px;" class="flex justify-space-between align-center">
  20. <div>
  21. <h2>账号登录</h2>
  22. </div>
  23. <div class="flex align-center">
  24. <el-tooltip content="切换扫码登录" placement="top">
  25. <div class="box"><img src="~assets/login/qrecode.png" style="width:34px"
  26. @click="onLoginModeChange(2)" /></div>
  27. </el-tooltip>
  28. </div>
  29. </div>
  30. <div>
  31. <el-form @keyup.enter="onSubmit(formRef)" ref="formRef" :rules="rules" size="large" :model="form">
  32. <el-form-item prop="accountName">
  33. <el-input ref="accountName" type="text" clearable v-model="form.accountName" placeholder="请输入账号">
  34. <template #prefix>
  35. <Icon name="fa fa-user" class="form-item-icon" size="16" color="var(--el-input-icon-color)" />
  36. </template>
  37. </el-input>
  38. </el-form-item>
  39. <el-form-item prop="password">
  40. <el-input ref="password" v-model="form.password" type="password" placeholder="请输入密码" show-password>
  41. <template #prefix>
  42. <Icon name="fa fa-unlock-alt" class="form-item-icon" size="16"
  43. color="var(--el-input-icon-color)" />
  44. </template>
  45. </el-input>
  46. </el-form-item>
  47. <el-form-item v-if="state.showCaptcha" prop="captcha">
  48. <el-row class="w100" :gutter="15">
  49. <el-col :span="16">
  50. <el-input ref="captcha" type="text" placeholder="请输入验证码" v-model="form.captcha" clearable
  51. autocomplete="off">
  52. <template #prefix>
  53. <Icon name="fa fa-ellipsis-h" class="form-item-icon" size="16"
  54. color="var(--el-input-icon-color)" />
  55. </template>
  56. </el-input>
  57. </el-col>
  58. <el-col :span="8">
  59. <img @click="onChangeCaptcha" class="captcha-img"
  60. :src="buildCaptchaUrl() + '?id=' + state.captchaId" alt="" />
  61. </el-col>
  62. </el-row>
  63. </el-form-item>
  64. <el-checkbox v-model="form.keep" label="保持会话" size="default"></el-checkbox>
  65. <el-form-item>
  66. <el-button :loading="form.loading"
  67. style="width: 100%; letter-spacing: 2px; font-weight: 300; margin-top: 15px" round type="primary"
  68. size="large" @click="onSubmit(formRef)">
  69. 登录
  70. </el-button>
  71. </el-form-item>
  72. </el-form>
  73. </div>
  74. <div class="mt-50" style="text-align:center;color:#909399">
  75. @CopyRight 2021-2022 保晓家科技有限公司
  76. </div>
  77. </div>
  78. <div style="height: 100%; padding: 64px 70px 48px; position: relative" v-show="loginMode==2">
  79. <div style="color:#404856;margin-bottom: 40px;" class="flex justify-space-between align-center">
  80. <div>
  81. <h2>扫码登录</h2>
  82. </div>
  83. <div class="flex align-center">
  84. <el-tooltip content="切换账号登录" placement="top">
  85. <div class="box"><img src="~assets/login/pc.png" style="width:34px" @click="onLoginModeChange(1)" />
  86. </div>
  87. </el-tooltip>
  88. </div>
  89. </div>
  90. <div class="flex column center">
  91. <div class="box">
  92. <!-- <img src="~assets/login/qrcord_test.svg" style="width:196px" /> -->
  93. <div id="QRcode_Area" style=" width: 300px; height: 340px; "></div>
  94. </div>
  95. <!-- <div style="color:#515a6e">请使用微信二维码扫描登录</div> -->
  96. </div>
  97. <div class="mt-50" style="text-align:center;color:#909399">
  98. @CopyRight 2021-2022 保晓家科技有限公司
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. <div class="box mt-50 flex justify-center align-center" style="text-align:center;color:#515a6e">
  105. <div class="box ml-10">
  106. © Ouicai.com
  107. </div>
  108. <div class="box ml-10">
  109. 联系我们
  110. </div>
  111. <div class="box ml-10">
  112. 帮助文档
  113. </div>
  114. <div class="box ml-10">
  115. 备案号: 京ICP备20029021号-1
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="login" v-if="config.$state.layout.screenWidth<768">
  121. <div class="login-box">
  122. <div class="head">
  123. <img src="~assets/logo.svg" alt="" />
  124. </div>
  125. <div class="form">
  126. <div style="margin-top:30px;text-align: center;color:#3a485a">
  127. <h3>车位销售运营管理平台</h3>
  128. </div>
  129. <div class="content">
  130. <el-form @keyup.enter="onSubmit(formRef)" ref="formRef" :rules="rules" size="large" :model="form">
  131. <el-form-item prop="accountName">
  132. <el-input ref="accountName" type="text" clearable v-model="form.accountName" placeholder="请输入账号">
  133. <template #prefix>
  134. <Icon name="fa fa-user" class="form-item-icon" size="16" color="var(--el-input-icon-color)" />
  135. </template>
  136. </el-input>
  137. </el-form-item>
  138. <el-form-item prop="password">
  139. <el-input ref="password" v-model="form.password" type="password" placeholder="请输入密码" show-password>
  140. <template #prefix>
  141. <Icon name="fa fa-unlock-alt" class="form-item-icon" size="16" color="var(--el-input-icon-color)" />
  142. </template>
  143. </el-input>
  144. </el-form-item>
  145. <el-form-item v-if="state.showCaptcha" prop="captcha">
  146. <el-row class="w100" :gutter="15">
  147. <el-col :span="16">
  148. <el-input ref="captcha" type="text" placeholder="请输入验证码" v-model="form.captcha" clearable
  149. autocomplete="off">
  150. <template #prefix>
  151. <Icon name="fa fa-ellipsis-h" class="form-item-icon" size="16"
  152. color="var(--el-input-icon-color)" />
  153. </template>
  154. </el-input>
  155. </el-col>
  156. <el-col :span="8">
  157. <el-image @click="onChangeCaptcha" class="captcha-img"
  158. :src="buildCaptchaUrl() + '?id=' + state.captchaId" alt="" fit="cover" />
  159. </el-col>
  160. </el-row>
  161. </el-form-item>
  162. <el-checkbox v-model="form.keep" label=保持会话 size="default"></el-checkbox>
  163. <el-form-item>
  164. <el-button :loading="form.loading" class="submit-button" round type="primary" size="large"
  165. @click="onSubmit(formRef)">
  166. 登录
  167. </el-button>
  168. </el-form-item>
  169. </el-form>
  170. </div>
  171. <div style="margin-bottom:30px;text-align: center;color:#3a485a"> @CopyRight 2021-2022 保晓家科技有限公司</div>
  172. </div>
  173. </div>
  174. </div>
  175. </template>
  176. <script setup lang="ts">
  177. import { watch, getCurrentInstance, onMounted, onBeforeUnmount, reactive, ref, onUnmounted } from 'vue'
  178. import type { ElForm } from 'element-plus'
  179. import { ElNotification } from 'element-plus'
  180. import { useConfig } from '/@/stores/config'
  181. import { useAdminInfo } from '/@/stores/adminInfo'
  182. import { login, qrcodeLogin } from '/@/api/backend'
  183. import { buildCaptchaUrl } from '/@/api/common'
  184. import { uuid } from '../../utils/random'
  185. import { validatorPassword, validatorAccount } from '/@/utils/validate'
  186. import { useSiteConfig } from '/@/stores/siteConfig'
  187. import { useRouter } from 'vue-router'
  188. var timer: NodeJS.Timer
  189. const router = useRouter()
  190. const querys = router.currentRoute.value.query
  191. const config = useConfig()
  192. const adminInfo = useAdminInfo()
  193. const siteConfig = useSiteConfig()
  194. const state = reactive({
  195. showCaptcha: true,
  196. captchaId: uuid(),
  197. appid: 'wwb5feafad13ca46b7',
  198. agentid: '1000002',
  199. backUrl:'http://web.baoxiaojia.dingsenhulian.com/back'
  200. })
  201. const isSzkj = ref<Boolean>(true)
  202. const checkQrCode = () => {
  203. new WwLogin({
  204. id: 'QRcode_Area',
  205. appid: state.appid,
  206. agentid: state.agentid,
  207. redirect_uri: state.backUrl,
  208. state: '',
  209. href: '',
  210. lang: 'zh',
  211. })
  212. }
  213. const loginMode = ref(1)
  214. const onLoginModeChange = (val: number) => {
  215. loginMode.value = val
  216. }
  217. const onChangeCaptcha = () => {
  218. form.captcha = ''
  219. state.captchaId = uuid()
  220. }
  221. const formRef = ref<InstanceType<typeof ElForm>>()
  222. const form = reactive({
  223. accountName: '',
  224. password: '',
  225. captcha: '',
  226. keep: false,
  227. loading: false,
  228. captchaId: '',
  229. })
  230. // 表单验证规则
  231. const rules = reactive({
  232. accountName: [
  233. {
  234. required: true,
  235. message: '请输入账号',
  236. trigger: 'blur',
  237. },
  238. {
  239. validator: validatorAccount,
  240. trigger: 'blur',
  241. },
  242. ],
  243. password: [
  244. {
  245. required: true,
  246. message: '请输入密码',
  247. trigger: 'blur',
  248. },
  249. {
  250. validator: validatorPassword,
  251. trigger: 'blur',
  252. },
  253. ],
  254. captcha: [
  255. {
  256. required: true,
  257. message: '请输入验证码',
  258. trigger: 'blur',
  259. },
  260. {
  261. min: 4,
  262. max: 6,
  263. message: '验证码长度必须在4到6位之间',
  264. trigger: 'blur',
  265. },
  266. ],
  267. })
  268. onMounted(() => {
  269. checkQrCode()
  270. config.$state.layout.screenWidth
  271. const vm: any = getCurrentInstance()
  272. if (form.accountName === '') {
  273. vm.ctx.$refs.accountName.focus()
  274. } else if (form.password === '') {
  275. vm.ctx.$refs.password.focus()
  276. } else if (form.captcha === '') {
  277. vm.ctx.$refs.captcha.focus()
  278. }
  279. timer = setInterval(() => {
  280. onChangeCaptcha()
  281. }, 60000)
  282. state.showCaptcha = true
  283. })
  284. onUnmounted(() => {
  285. clearInterval(timer)
  286. })
  287. const onSubmit = (formEl: InstanceType<typeof ElForm> | undefined) => {
  288. if (!formEl) return
  289. formEl.validate((valid) => {
  290. if (valid) {
  291. form.loading = true
  292. form.captchaId = state.captchaId
  293. login('post', form)
  294. .then((res) => {
  295. form.loading = false
  296. adminInfo.$state = res.data.userinfo
  297. ElNotification({
  298. message: res.msg,
  299. type: 'success',
  300. })
  301. router.push({ name: res.data.routeName })
  302. })
  303. .catch((err) => {
  304. onChangeCaptcha()
  305. form.loading = false
  306. })
  307. } else {
  308. onChangeCaptcha()
  309. return false
  310. }
  311. })
  312. }
  313. </script>
  314. <style scoped lang="scss">
  315. .switch-language {
  316. position: fixed;
  317. top: 20px;
  318. right: 20px;
  319. z-index: 1;
  320. }
  321. .bubble {
  322. overflow: hidden;
  323. background: url(/@/assets/bg.jpg) repeat;
  324. }
  325. .form-item-icon {
  326. height: auto;
  327. }
  328. .login {
  329. position: absolute;
  330. display: flex;
  331. width: 1000px;
  332. padding: 0;
  333. z-index: 1;
  334. top: 0;
  335. left: 50%;
  336. align-items: flex-start;
  337. justify-content: center;
  338. transform: translate(-50%, 0);
  339. background: linear-gradient(0deg, #3a485a 0%, #607089 100%);
  340. height: 100%;
  341. .login-box {
  342. overflow: hidden;
  343. width: 430px;
  344. padding: 0;
  345. background: #fff;
  346. margin-top: 0px;
  347. }
  348. .head {
  349. background: #1c1f3a;
  350. height: 100px;
  351. padding: 30px;
  352. img {
  353. display: block;
  354. width: 230px;
  355. margin: 0 auto;
  356. user-select: none;
  357. }
  358. }
  359. .form {
  360. position: relative;
  361. .profile-avatar {
  362. display: block;
  363. position: absolute;
  364. height: 100px;
  365. width: 100px;
  366. border-radius: 50%;
  367. border: 4px solid #fff;
  368. top: -50px;
  369. right: 175px;
  370. z-index: 2;
  371. user-select: none;
  372. }
  373. .content {
  374. padding: 30px 40px 10px 40px;
  375. }
  376. .submit-button {
  377. width: 100%;
  378. letter-spacing: 2px;
  379. font-weight: 300;
  380. margin-top: 15px;
  381. }
  382. }
  383. }
  384. .chang-lang :deep(.el-dropdown-menu__item) {
  385. justify-content: center;
  386. }
  387. .content :deep(.el-input__prefix) {
  388. display: flex;
  389. align-items: center;
  390. }
  391. .captcha-img {
  392. width: 100%;
  393. transform: scale(1.2);
  394. margin-left: 5px;
  395. margin-top: 4px;
  396. }
  397. .wrapper {
  398. height: calc(100vh);
  399. }
  400. .wrapper_login {
  401. z-index: 3;
  402. box-shadow: 0px 20px 80px 0px rgb(0 0 0 / 30%);
  403. position: relative;
  404. min-height: 564px;
  405. background-color: white;
  406. width: 1000px;
  407. }
  408. .sidebox {
  409. //background: linear-gradient(0deg, #3a485a 0%, #607089 100%);
  410. background-image: url(/@/assets/load_back_image.svg);
  411. background-size: cover;
  412. background-repeat: no-repeat;
  413. color: #fff;
  414. position: relative;
  415. padding: 80px 80px 48px;
  416. min-height: 564px;
  417. }
  418. .sidebox::before,
  419. .sidebox::after {
  420. content: '';
  421. position: absolute;
  422. top: 0;
  423. left: 0;
  424. bottom: 0;
  425. right: 0;
  426. background: url(/@/assets/login/left-1.png) no-repeat 0 0;
  427. }
  428. .sidebox::before {
  429. content: '';
  430. position: absolute;
  431. top: 0;
  432. left: 0;
  433. bottom: 0;
  434. right: 0;
  435. background: url(/@/assets/login/left-2.png) no-repeat right bottom;
  436. }
  437. .wrapper:before {
  438. content: '';
  439. position: fixed;
  440. bottom: 0;
  441. background-size: contain;
  442. background-repeat: no-repeat;
  443. z-index: 1;
  444. width: 394px;
  445. height: 468px;
  446. background-image: url(/@/assets/login/bg-left.png);
  447. left: 0;
  448. }
  449. .wrapper::after {
  450. content: '';
  451. position: fixed;
  452. bottom: 0;
  453. background-size: contain;
  454. background-repeat: no-repeat;
  455. z-index: 1;
  456. width: 487px;
  457. height: 412px;
  458. background-image: url(/@/assets/login/bg-right.png);
  459. right: 0;
  460. }
  461. // 根据需求自定义二维码样式
  462. .impowerBox .title {
  463. display: none;
  464. }
  465. .impowerBox .status.status_browser {
  466. display: none;
  467. }
  468. .impowerBox .qrcode {
  469. border: none;
  470. width: 225px;
  471. height: 225px;
  472. }
  473. .impowerBox .status {
  474. display: none;
  475. }
  476. @media screen and (max-width: 720px) {
  477. .login {
  478. display: flex;
  479. align-items: center;
  480. justify-content: center;
  481. .login-box {
  482. width: 340px;
  483. margin-top: 0;
  484. }
  485. }
  486. }
  487. @media screen and (max-width: 1230px) {
  488. .wrapper_login {
  489. width: 1040px;
  490. }
  491. }
  492. @media screen and (max-width: 1040px) {
  493. .wrapper_login {
  494. width: 768px;
  495. }
  496. }
  497. @media screen and (max-width: 768px) {
  498. .wrapper_login {
  499. width: 668px;
  500. }
  501. }
  502. </style>