Login.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <div class="topV">
  3. <div
  4. class="topV1"
  5. v-if="identityType === 0"
  6. :style="{ overflow: 'auto', backgroundSize: smallerThanLg ? 'cover' : 'cover' }"
  7. >
  8. </div>
  9. <div
  10. class="topV2"
  11. v-if="identityType === 1"
  12. :style="{ overflow: 'auto', backgroundSize: smallerThanLg ? 'cover' : 'cover' }"
  13. >
  14. </div>
  15. <div class="flex items-center text-white mt-40px ml-50px" style="position: absolute">
  16. <img alt="" class="mr-10px h-40px" src="@/assets/imgs/logo5.png" />
  17. </div>
  18. <div style="position: absolute; width: 100%; height: 100%; overflow: auto">
  19. <el-row>
  20. <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14">
  21. <div
  22. v-if="identityType === 0"
  23. class="column topText1"
  24. style="padding: 0; margin-top: 12vh; justify-content: center; align-items: center"
  25. >
  26. <span
  27. class="text-40px font-bold"
  28. style="margin-left: 2vw; letter-spacing: 10px; color: #fff"
  29. >欢迎来到颐年智慧医养数字平台</span
  30. >
  31. </div>
  32. <div
  33. v-if="identityType === 1"
  34. class="column topText2"
  35. style="padding: 0 4vw; margin-top: 20vh; justify-content: center; align-items: center"
  36. >
  37. <span class="text-50px font-bold" style="letter-spacing: 10px; color: #333"
  38. >欢迎来到颐年医养</span
  39. >
  40. <div class="column">
  41. <span class="text-25px font-bold">智慧康养SaaS管理平台,以科技赋能养老</span>
  42. <span
  43. class="text-25px font-bold"
  44. style="margin-top: 18px; letter-spacing: 8px; color: #333; text-indent: 40px"
  45. >让爱与关怀无处不在,引领未来养老新生态</span
  46. >
  47. </div>
  48. </div>
  49. </el-col>
  50. <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
  51. <div
  52. class="column"
  53. style="align-items: center; justify-content: center"
  54. :style="{ height: heightScreen + 'px' }"
  55. >
  56. <el-form
  57. ref="formLogin"
  58. :model="loginData.loginForm"
  59. :rules="LoginRules"
  60. class="login-form"
  61. label-position="top"
  62. label-width="120px"
  63. size="large"
  64. >
  65. <div
  66. class="column cardR"
  67. :style="{
  68. width: '460px',
  69. height: 500 + 'px',
  70. marginTop: heightScreen * 0.05 + 'px'
  71. }"
  72. >
  73. <div
  74. class="row"
  75. :style="{
  76. width: '382px',
  77. marginTop: -10 + 'px'
  78. }"
  79. >
  80. </div>
  81. <div
  82. class="row"
  83. :style="{
  84. width: '382px',
  85. marginTop: 28 + 'px'
  86. }"
  87. >
  88. <el-tabs v-model="loginType" class="demo-tabs" @tab-click="typeCK">
  89. <el-tab-pane label="" name="1">
  90. <template #label>
  91. <span
  92. class="text-20px font-bold"
  93. :style="{ color: loginType === '1' ? systemTheme : '#333333' }"
  94. >账号登录</span
  95. >
  96. </template>
  97. </el-tab-pane>
  98. </el-tabs>
  99. <div
  100. @click="typeCK(1)"
  101. class="column"
  102. style="align-items: center; cursor: pointer"
  103. >
  104. </div>
  105. </div>
  106. <el-form-item v-if="loginData.tenantEnable === 'true'" prop="tenantName">
  107. <div class="row inputM" :style="{ width: '382px', marginTop: '16px' }">
  108. <span style="width: 60px; font-size: 14px; color: #000">{{
  109. identityType === 0 ? '企业名' : '集团名'
  110. }}</span>
  111. <input
  112. style="height: 50px; font-size: 14px; color: #000"
  113. :style="{ width: '300px' }"
  114. v-model="loginData.loginForm.tenantName"
  115. @focus="focusHd"
  116. class="inputS"
  117. @keyup.enter="handleLogin"
  118. :placeholder="identityType === 0 ? '请输入企业名' : '请输入集团名'"
  119. />
  120. <div style="flex-grow: 1"></div>
  121. </div>
  122. </el-form-item>
  123. <el-form-item prop="username" size="small">
  124. <div class="row inputM" :style="{ width: '382px', marginTop: '-2px' }">
  125. <span style="width: 60px; font-size: 14px; letter-spacing: 12px; color: #000"
  126. >账号</span
  127. >
  128. <input
  129. style="height: 50px; font-size: 14px; color: #000"
  130. :style="{ width: '300px' }"
  131. v-model="loginData.loginForm.username"
  132. @focus="focusHd"
  133. class="inputS"
  134. @keyup.enter="handleLogin"
  135. placeholder="请输入账号或手机号"
  136. />
  137. <div style="flex-grow: 1"></div>
  138. </div>
  139. </el-form-item>
  140. <el-form-item prop="password" size="small">
  141. <div class="row inputM" :style="{ width: '382px', marginTop: '-2px' }">
  142. <span style="width: 60px; font-size: 14px; letter-spacing: 12px; color: #000"
  143. >密码</span
  144. >
  145. <input
  146. style="height: 50px; font-size: 14px; color: #000"
  147. :style="{ width: '260px' }"
  148. v-model="loginData.loginForm.password"
  149. @focus="focusHd"
  150. class="inputS2"
  151. @keyup.enter="handleLogin"
  152. placeholder="请输入密码"
  153. :type="hides ? 'password' : 'text'"
  154. />
  155. <div style="flex-grow: 1"></div>
  156. <div
  157. @click="hide"
  158. style="width: 20px; height: 20px; cursor: pointer"
  159. class="row"
  160. >
  161. <el-icon v-show="hides" color="#888888" size="18px"><Hide /></el-icon>
  162. <el-icon v-show="!hides" color="#888888" size="18px"><View /></el-icon>
  163. </div>
  164. </div>
  165. </el-form-item>
  166. <el-button
  167. type="primary"
  168. size="large"
  169. @click="handleLogin"
  170. :loading="loginLoading"
  171. :style="{ width: '382px', marginTop: '40px' }"
  172. style="height: 50px; font-size: 16px"
  173. >登录</el-button
  174. >
  175. <a
  176. class="aa"
  177. @mousemove="isMouseout = true"
  178. @mouseout="isMouseout = false"
  179. href="https://www.google.cn/intl/zh-CN/chrome/"
  180. target="_blank"
  181. :style="{ color: isMouseout ? systemTheme : '#888888' }"
  182. >使用谷歌浏览器,体验更佳 >></a
  183. >
  184. </div>
  185. </el-form>
  186. </div>
  187. </el-col>
  188. </el-row>
  189. </div>
  190. <!-- 账号登录 -->
  191. <!-- <LoginForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> -->
  192. <!-- 手机登录 -->
  193. <!-- <MobileForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> -->
  194. <!-- 二维码登录 -->
  195. <!-- <QrCodeForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> -->
  196. <!-- 注册 -->
  197. <!-- <RegisterForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> -->
  198. <!-- 三方登录 -->
  199. <!-- <SSOLoginVue class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" /> -->
  200. </div>
  201. </template>
  202. <script lang="ts" setup>
  203. import { useDesign } from '@/hooks/web/useDesign'
  204. import { useAppStore } from '@/store/modules/app'
  205. import { onMounted } from 'vue'
  206. // import { Hide, View } from '@element-plus/icons-vue'
  207. import * as LoginApi from '@/api/login'
  208. import { ElLoading } from 'element-plus'
  209. import * as authUtil from '@/utils/auth'
  210. import { useFormValid } from '@/views/Login/components/useLogin'
  211. import type { RouteLocationNormalizedLoaded } from 'vue-router'
  212. import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
  213. import { usePermissionStore } from '@/store/modules/permission'
  214. import { useUserStore } from '@/store/modules/user'
  215. // import { setLOGINPLATFORM } from '@/utils/auth'
  216. defineOptions({ name: 'Login' })
  217. const breakpoints = useBreakpoints(breakpointsTailwind)
  218. const smallerThanLg = breakpoints.smaller('xl') // only larger than md
  219. const { currentRoute, push } = useRouter()
  220. const { t } = useI18n()
  221. const appStore = useAppStore()
  222. const { getPrefixCls } = useDesign()
  223. const prefixCls = getPrefixCls('login')
  224. const widthScreen = ref(0)
  225. const heightScreen = ref(0)
  226. const titleWidth = ref(0)
  227. const src = ref(true)
  228. const hides = ref(true)
  229. const loginType = ref('1') //登录类型,扫码或者账号
  230. const identityType = ref(0) //身份类型
  231. const animationPlayState = ref('revert') //
  232. const systemTheme = ref(appStore.getTheme.elColorPrimary)
  233. const loginLoading = ref(false)
  234. const formLogin = ref()
  235. const { validForm } = useFormValid(formLogin)
  236. const redirect = ref<string>('')
  237. const isMouseout = ref(false)
  238. const isPhone = ref(false) //是不是手机端
  239. const userStore = useUserStore()
  240. const permissionStore = usePermissionStore()
  241. import fetchHttp from '@/config/axios/fetchHttp'
  242. const loginData = reactive({
  243. isShowPassword: false,
  244. captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,
  245. tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
  246. loginForm: {
  247. tenantName: '',
  248. username: '',
  249. password: '',
  250. captchaVerification: '',
  251. loginDevice: 1,
  252. rememberMe: true, // 默认记录我。如果不需要,可手动修改
  253. loginPlatform: 0 // 0 企业 1集团
  254. }
  255. })
  256. const LoginRules = {
  257. tenantName: [required],
  258. username: [required],
  259. password: [required]
  260. }
  261. widthScreen.value =
  262. screen.width ||
  263. window.innerWidth ||
  264. document.documentElement.clientWidth ||
  265. document.body.clientWidth
  266. heightScreen.value =
  267. screen.height ||
  268. window.innerHeight ||
  269. document.documentElement.clientHeight ||
  270. document.body.clientHeight
  271. onMounted(() => {
  272. if (widthScreen.value < heightScreen.value) {
  273. isPhone.value = true
  274. widthScreen.value = widthScreen.value * 3.6
  275. } else {
  276. heightScreen.value = heightScreen.value * 0.756
  277. }
  278. titleWidth.value = getTextWidthWithLetterSpacingDOM('欢迎来到颐年医养', '61px Arial', 10)
  279. console.log('字体宽度', titleWidth.value)
  280. getLoginFormCache()
  281. getTenantByWebsite()
  282. })
  283. const getTextWidthWithLetterSpacingDOM = (text, font, letterSpacing) => {
  284. const span = document.createElement('span')
  285. span.style.visibility = 'hidden' // 隐藏元素
  286. span.style.position = 'absolute' // 不影响页面布局
  287. span.style.font = font
  288. span.style.letterSpacing = letterSpacing + 'px'
  289. span.textContent = text
  290. document.body.appendChild(span) // 添加到DOM中
  291. const width = span.offsetWidth // 读取计算后的宽度
  292. document.body.removeChild(span) // 移除元素
  293. return width
  294. }
  295. watch(
  296. () => currentRoute.value,
  297. (route: RouteLocationNormalizedLoaded) => {
  298. redirect.value = route?.query?.redirect as string
  299. },
  300. {
  301. immediate: true
  302. }
  303. )
  304. const typeCK = (type) => {
  305. loginType.value = type
  306. }
  307. const identityCK = (type) => {
  308. identityType.value = type
  309. animationPlayState.value = 'revert'
  310. setTimeout(() => {
  311. animationPlayState.value = 'running'
  312. }, 3000)
  313. }
  314. const focusHd = () => {
  315. console.log('focusHd')
  316. }
  317. const hide = () => {
  318. hides.value = !hides.value
  319. }
  320. // 获取租户 ID
  321. const getTenantId = async () => {
  322. if (loginData.tenantEnable === 'true') {
  323. authUtil.setTenantId(1)
  324. // const res = await LoginApi.getTenantIdByName(loginData.loginForm.tenantName)
  325. // authUtil.setTenantId(res)
  326. }
  327. }
  328. const loading = ref() // ElLoading.service 返回的实例
  329. // 登录
  330. const handleLogin = async (params) => {
  331. loginLoading.value = true
  332. try {
  333. await getTenantId()
  334. const data = await validForm()
  335. if (!data) {
  336. return
  337. }
  338. loginData.loginForm.captchaVerification = params.captchaVerification
  339. loginData.loginForm.loginPlatform = identityType.value
  340. let paramsData = {
  341. organizationName: loginData.loginForm.tenantName,
  342. username: loginData.loginForm.username,
  343. password: loginData.loginForm.password
  344. }
  345. // const res = await LoginApi.login(loginData.loginForm)
  346. // const res = await LoginApi.login(paramsData)
  347. const res = await fetchHttp.post('/api/pc/auth/login', paramsData)
  348. if (!res) {
  349. return
  350. }
  351. loading.value = ElLoading.service({
  352. lock: true,
  353. text: '正在加载系统中...',
  354. background: 'rgba(0, 0, 0, 0.7)'
  355. })
  356. if (loginData.loginForm.rememberMe) {
  357. authUtil.setLoginForm(loginData.loginForm)
  358. } else {
  359. authUtil.removeLoginForm()
  360. }
  361. localStorage.setItem('identity', String(identityType.value))
  362. authUtil.setToken({
  363. refreshToken: res.accessToken,
  364. accessToken: res.accessToken
  365. })
  366. localStorage.setItem('organizationId', res.organizationId)
  367. redirect.value = '/'
  368. // if (!redirect.value) {
  369. // if (identityType.value == 0) {
  370. // redirect.value = '/'
  371. // } else {
  372. // redirect.value = '/home/data_index'
  373. // }
  374. // }
  375. // 判断是否为SSO登录
  376. if (redirect.value.indexOf('sso') !== -1) {
  377. window.location.href = window.location.href.replace('/login?redirect=', '')
  378. } else {
  379. push({ path: redirect.value || permissionStore.addRouters[0].path })
  380. }
  381. } finally {
  382. loginLoading.value = false
  383. loading.value?.close()
  384. }
  385. }
  386. // 根据域名,获得租户信息
  387. const getTenantByWebsite = async () => {
  388. // const website = location.host
  389. // const res = await LoginApi.getTenantByWebsite(website)
  390. // if (res) {
  391. // loginData.loginForm.tenantName = res.name
  392. // authUtil.setTenantId(res.id)
  393. // }
  394. }
  395. // 记住我
  396. const getLoginFormCache = () => {
  397. const loginForm = authUtil.getLoginForm()
  398. if (loginForm) {
  399. loginData.loginForm = {
  400. ...loginData.loginForm,
  401. username: loginForm.username ? loginForm.username : loginData.loginForm.username,
  402. password: loginForm.password ? loginForm.password : loginData.loginForm.password,
  403. rememberMe: loginForm.rememberMe,
  404. tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
  405. }
  406. }
  407. }
  408. </script>
  409. <style lang="scss" scoped>
  410. $prefix-cls: #{$namespace}-login;
  411. /* 定义动画 */
  412. @keyframes fadeIn {
  413. from {
  414. opacity: 0.2;
  415. }
  416. to {
  417. opacity: 1;
  418. }
  419. }
  420. /* 定义动画 */
  421. @keyframes fadeIn2 {
  422. from {
  423. opacity: 0.1;
  424. }
  425. to {
  426. opacity: 1;
  427. }
  428. }
  429. .#{$prefix-cls} {
  430. overflow: auto;
  431. &__left {
  432. &::before {
  433. position: absolute;
  434. top: 0;
  435. left: 0;
  436. z-index: -1;
  437. width: 100%;
  438. height: 100%;
  439. background-image: url('@/assets/svgs/login-bg.svg');
  440. background-position: center;
  441. background-repeat: no-repeat;
  442. content: '';
  443. }
  444. }
  445. }
  446. .topV {
  447. position: relative;
  448. width: 100%;
  449. height: 100%;
  450. background-attachment: fixed;
  451. background-color: #e0e7f9;
  452. background-repeat: no-repeat;
  453. }
  454. .topV1 {
  455. position: absolute;
  456. width: 100%;
  457. height: 100%;
  458. background-attachment: fixed;
  459. // background-image: url('@/assets/imgs/home_bg.png');
  460. background-image: url('@/assets/imgs/login_banner.png');
  461. background-repeat: no-repeat;
  462. opacity: 0.2;
  463. animation: fadeIn 0.7s ease-in forwards;
  464. }
  465. .topV2 {
  466. position: absolute;
  467. width: 100%;
  468. height: 100%;
  469. background-attachment: fixed;
  470. // background-image: url('@/assets/imgs/home_bg.png');
  471. background-image: url('@/assets/imgs/login_banner.png');
  472. background-repeat: no-repeat;
  473. opacity: 0.2;
  474. animation: fadeIn 0.7s ease-in forwards;
  475. }
  476. .topText1 {
  477. opacity: 0.1;
  478. animation: fadeIn2 0.8s ease-in forwards;
  479. }
  480. .topText2 {
  481. opacity: 0.1;
  482. animation: fadeIn2 0.8s ease-in forwards;
  483. }
  484. .column {
  485. display: flex;
  486. flex-direction: column;
  487. }
  488. .row {
  489. display: flex;
  490. flex-direction: row;
  491. align-items: center;
  492. }
  493. .cardR {
  494. display: flex;
  495. width: 20vw;
  496. padding: 26px 10px;
  497. background-color: white;
  498. border-radius: 12px;
  499. align-items: center;
  500. justify-content: start;
  501. box-shadow:
  502. 10px 10px 15px rgb(0 0 0 / 2%),
  503. -10px -10px 15px rgb(0 0 0 / 2%),
  504. 10px -10px 15px rgb(0 0 0 / 2%),
  505. -10px 10px 15px rgb(0 0 0 / 2%);
  506. }
  507. .inputM {
  508. width: 16.8vw;
  509. height: 50px;
  510. padding: 10px 12px;
  511. margin-top: 2vh;
  512. border: #ddd solid 1px;
  513. border-radius: 4px;
  514. }
  515. .inputS {
  516. width: 90%;
  517. background-color: transparent;
  518. border: none;
  519. outline: none;
  520. box-shadow: none;
  521. }
  522. .inputS2 {
  523. background-color: transparent;
  524. border: none;
  525. outline: none;
  526. box-shadow: none;
  527. }
  528. input::placeholder {
  529. font-family: Arial, sans-serif; /* 修改placeholder文本的字体 */
  530. font-size: 14px; /* 修改placeholder文本的字体大小 */
  531. color: #a0a0a0; /* 修改placeholder文本的颜色 */
  532. }
  533. :deep(.el-tabs__nav-wrap::after) {
  534. background-color: transparent;
  535. }
  536. :deep(.el-tabs__item) {
  537. padding: 0 12px;
  538. }
  539. .aa {
  540. margin-top: 20px;
  541. font-size: 12px;
  542. color: #888; /* 未访问链接的颜色 */
  543. }
  544. .aa:hover {
  545. margin-top: 20px;
  546. font-size: 12px;
  547. color: #13b4f1;
  548. }
  549. ::-webkit-scrollbar {
  550. width: 3px; //滚动条宽度
  551. }
  552. ::-webkit-scrollbar-thumb {
  553. //上层
  554. background: var(--el-border-color-dark); //背景颜色
  555. border-radius: 10px; //滚动条圆弧半径
  556. //-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); //滚动条阴影
  557. }
  558. ::-webkit-scrollbar-track {
  559. //底层
  560. //-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  561. background: #f7f8fa;
  562. border-radius: 0;
  563. }
  564. </style>