Login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <div
  3. :class="prefixCls"
  4. class="relative h-[100%] lt-md:px-10px lt-sm:px-10px lt-xl:px-10px lt-xl:px-10px"
  5. >
  6. <div class="relative mx-auto h-full flex">
  7. <div
  8. :class="`${prefixCls}__left flex-1 bg-gray-500 bg-opacity-20 relative p-30px lt-xl:hidden overflow-x-hidden overflow-y-auto`"
  9. >
  10. <!-- 左上角的 logo + 系统标题 -->
  11. <div class="relative flex items-center text-white">
  12. <img alt="" class="mr-10px h-48px w-48px" src="@/assets/imgs/logo.png" />
  13. <span class="text-20px font-bold">{{ underlineToHump(appStore.getTitle) }}</span>
  14. </div>
  15. <!-- 左边的背景图 + 欢迎语 -->
  16. <div class="h-[calc(100%-60px)] flex items-center justify-center">
  17. <TransitionGroup
  18. appear
  19. enter-active-class="animate__animated animate__bounceInLeft"
  20. tag="div"
  21. >
  22. <!-- <img key="1" alt="" class="w-350px" src="@/assets/svgs/login-box-bg.svg" />-->
  23. <!-- <img key="1" alt="" class="w-350px" src="@/assets/imgs/yf.jpg" />-->
  24. <!-- <div key="2" class="text-3xl text-white">{{ t('login.welcome') }}</div>-->
  25. <div key="3" class="mt-5 text-14px font-normal text-white">
  26. {{ t('login.message') }}
  27. </div>
  28. </TransitionGroup>
  29. </div>
  30. </div>
  31. <div
  32. class="relative flex-1 p-30px dark:bg-[var(--login-bg-color)] lt-sm:p-10px overflow-x-hidden overflow-y-auto"
  33. >
  34. <!-- 右上角的主题、语言选择 -->
  35. <div
  36. class="flex items-center justify-between at-2xl:justify-end at-xl:justify-end"
  37. style="color: var(--el-text-color-primary)"
  38. >
  39. <div class="flex items-center at-2xl:hidden at-xl:hidden">
  40. <img alt="" class="mr-10px h-48px w-48px" src="@/assets/imgs/logo.png" />
  41. <span class="text-20px font-bold">{{ underlineToHump(appStore.getTitle) }}</span>
  42. </div>
  43. <div class="flex items-center justify-end space-x-10px h-48px">
  44. <ThemeSwitch />
  45. <LocaleDropdown />
  46. </div>
  47. </div>
  48. <!-- 右边的登录界面 -->
  49. <Transition appear enter-active-class="animate__animated animate__bounceInRight">
  50. <div
  51. class="m-auto h-[calc(100%-60px)] w-[100%] flex items-center 2xl:max-w-500px lg:max-w-500px md:max-w-500px xl:max-w-500px"
  52. >
  53. <!-- 账号登录 -->
  54. <LoginForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
  55. <!-- 手机登录 -->
  56. <!-- <MobileForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  57. <!-- 二维码登录 -->
  58. <QrCodeForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
  59. <!-- 注册 -->
  60. <RegisterForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
  61. <!-- 三方登录 -->
  62. <!-- <SSOLoginVue class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  63. <!-- 忘记密码 -->
  64. <ForgetPasswordForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
  65. </div>
  66. </Transition>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <script lang="ts" setup>
  72. import { underlineToHump } from '@/utils'
  73. import { useDesign } from '@/hooks/web/useDesign'
  74. import { useAppStore } from '@/store/modules/app'
  75. import { ThemeSwitch } from '@/layout/components/ThemeSwitch'
  76. import { LocaleDropdown } from '@/layout/components/LocaleDropdown'
  77. import * as dd from 'dingtalk-jsapi'
  78. import { LoginForm, QrCodeForm, RegisterForm, ForgetPasswordForm } from './components'
  79. import { dingTalkLogin } from '../../api/login'
  80. import * as authUtil from '@/utils/auth'
  81. import { RouteLocationNormalizedLoaded } from 'vue-router'
  82. import { usePermissionStore } from '../../store/modules/permission'
  83. import * as LoginApi from '@/api/login'
  84. import { ElLoading } from 'element-plus'
  85. defineOptions({ name: 'Login' })
  86. const { t } = useI18n()
  87. const appStore = useAppStore()
  88. const { getPrefixCls } = useDesign()
  89. const prefixCls = getPrefixCls('login')
  90. const loading = ref<any>(null)
  91. const redirect = ref<string>('')
  92. const router = useRouter()
  93. watch(
  94. () => router.currentRoute.value,
  95. (route: RouteLocationNormalizedLoaded) => {
  96. redirect.value = route?.query?.redirect as string
  97. },
  98. {
  99. immediate: true
  100. }
  101. )
  102. const getTenantId = async () => {
  103. if (import.meta.env.VITE_APP_TENANT_ENABLE === 'true') {
  104. const res = await LoginApi.getTenantIdByName('芋道源码')
  105. debugger
  106. authUtil.setTenantId(res)
  107. }
  108. }
  109. const permissionStore = usePermissionStore()
  110. async function loginWithDingTalk() {
  111. const ddCorpId = import.meta.env.VITE_DD_CORPID
  112. const ddClientId = import.meta.env.VITE_DD_CLIENTID
  113. if (!ddCorpId || !ddClientId) return
  114. await getTenantId()
  115. dd.requestAuthCode({
  116. corpId: ddCorpId,
  117. clientId: ddClientId,
  118. success: (res: any) => {
  119. const { code } = res
  120. dingTalkLogin({ code, type: 10, state: new Date().getTime() }).then(async (res) => {
  121. console.log('res :>> ', res)
  122. loading.value = ElLoading.service({
  123. lock: true,
  124. text: '正在加载系统中...',
  125. background: 'rgba(0, 0, 0, 0.7)'
  126. })
  127. // authUtil.removeLoginForm()
  128. authUtil.setToken(res)
  129. if (!redirect.value) {
  130. redirect.value = '/'
  131. }
  132. if (redirect.value.indexOf('sso') !== -1) {
  133. window.location.href = window.location.href.replace('/login?redirect=', '')
  134. } else {
  135. router.push({ path: redirect.value || permissionStore.addRouters[0].path }).then(() => {
  136. loading.value.close()
  137. })
  138. }
  139. })
  140. },
  141. fail: (err: any) => {
  142. console.log('err :>> ', err)
  143. },
  144. complete: () => {
  145. console.log('11 :>> ', 11)
  146. }
  147. })
  148. }
  149. function dingTalkAutoLogin() {
  150. const ua = window.navigator.userAgent.toLowerCase()
  151. console.log('ua :>> ', ua)
  152. if (!ua.includes('dingtalk') && !ua.includes('dingtalkwork')) return
  153. loginWithDingTalk()
  154. }
  155. onMounted(() => {
  156. dingTalkAutoLogin()
  157. })
  158. </script>
  159. <style lang="scss" scoped>
  160. $prefix-cls: #{$namespace}-login;
  161. .#{$prefix-cls} {
  162. overflow: auto;
  163. &__left {
  164. &::before {
  165. position: absolute;
  166. top: 0;
  167. left: 0;
  168. z-index: -1;
  169. width: 100%;
  170. height: 100%;
  171. background-image: url('@/assets/imgs/yf.png');
  172. background-position: center;
  173. background-repeat: no-repeat;
  174. background-size: cover; /* 关键:图片覆盖整个容器 */
  175. content: '';
  176. }
  177. }
  178. }
  179. </style>
  180. <style lang="scss">
  181. .dark .login-form {
  182. .el-divider__text {
  183. background-color: var(--login-bg-color);
  184. }
  185. .el-card {
  186. background-color: var(--login-bg-color);
  187. }
  188. }
  189. </style>
  190. <!--<template>-->
  191. <!-- <div-->
  192. <!-- :class="prefixCls"-->
  193. <!-- class="relative h-[100%] lt-md:px-10px lt-sm:px-10px lt-xl:px-10px lt-xl:px-10px"-->
  194. <!-- >-->
  195. <!-- <div class="relative mx-auto h-full flex">-->
  196. <!-- <div-->
  197. <!-- :class="`${prefixCls}__left flex-1 bg-gray-500 bg-opacity-20 relative p-30px lt-xl:hidden overflow-x-hidden overflow-y-auto`"-->
  198. <!-- >-->
  199. <!-- &lt;!&ndash; 左上角的 logo + 系统标题 &ndash;&gt;-->
  200. <!-- <div class="relative flex items-center text-white">-->
  201. <!-- <img alt="" class="mr-10px h-48px w-48px" src="@/assets/imgs/logo.png" />-->
  202. <!-- <span class="text-20px font-bold">{{ underlineToHump(appStore.getTitle) }}</span>-->
  203. <!-- </div>-->
  204. <!-- &lt;!&ndash; 左边的背景图 + 欢迎语 &ndash;&gt;-->
  205. <!-- <div class="h-[calc(100%-60px)] flex items-center justify-center">-->
  206. <!-- <TransitionGroup-->
  207. <!-- appear-->
  208. <!-- enter-active-class="animate__animated animate__bounceInLeft"-->
  209. <!-- tag="div"-->
  210. <!-- >-->
  211. <!-- <img key="1" alt="" class="w-350px" src="@/assets/svgs/login-box-bg.svg" />-->
  212. <!-- <div key="2" class="text-3xl text-white">{{ t('login.welcome') }}</div>-->
  213. <!-- <div key="3" class="mt-5 text-14px font-normal text-white">-->
  214. <!-- {{ t('login.message') }}-->
  215. <!-- </div>-->
  216. <!-- </TransitionGroup>-->
  217. <!-- </div>-->
  218. <!-- </div>-->
  219. <!-- <div-->
  220. <!-- class="relative flex-1 p-30px dark:bg-[var(&#45;&#45;login-bg-color)] lt-sm:p-10px overflow-x-hidden overflow-y-auto"-->
  221. <!-- >-->
  222. <!-- &lt;!&ndash; 右上角的主题、语言选择 &ndash;&gt;-->
  223. <!-- <div-->
  224. <!-- class="flex items-center justify-between at-2xl:justify-end at-xl:justify-end"-->
  225. <!-- style="color: var(&#45;&#45;el-text-color-primary);"-->
  226. <!-- >-->
  227. <!-- <div class="flex items-center at-2xl:hidden at-xl:hidden">-->
  228. <!-- <img alt="" class="mr-10px h-48px w-48px" src="@/assets/imgs/logo.png" />-->
  229. <!-- <span class="text-20px font-bold" >{{ underlineToHump(appStore.getTitle) }}</span>-->
  230. <!-- </div>-->
  231. <!-- <div class="flex items-center justify-end space-x-10px h-48px">-->
  232. <!-- <ThemeSwitch />-->
  233. <!-- <LocaleDropdown />-->
  234. <!-- </div>-->
  235. <!-- </div>-->
  236. <!-- &lt;!&ndash; 右边的登录界面 &ndash;&gt;-->
  237. <!-- <Transition appear enter-active-class="animate__animated animate__bounceInRight">-->
  238. <!-- <div-->
  239. <!-- class="m-auto h-[calc(100%-60px)] w-[100%] flex items-center at-2xl:max-w-500px at-lg:max-w-500px at-md:max-w-500px at-xl:max-w-500px"-->
  240. <!-- >-->
  241. <!-- &lt;!&ndash; 账号登录 &ndash;&gt;-->
  242. <!-- <LoginForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  243. <!-- &lt;!&ndash; 手机登录 &ndash;&gt;-->
  244. <!-- <MobileForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  245. <!-- &lt;!&ndash; 二维码登录 &ndash;&gt;-->
  246. <!-- <QrCodeForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  247. <!-- &lt;!&ndash; 注册 &ndash;&gt;-->
  248. <!-- <RegisterForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  249. <!-- &lt;!&ndash; 三方登录 &ndash;&gt;-->
  250. <!-- <SSOLoginVue class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  251. <!-- &lt;!&ndash; 忘记密码 &ndash;&gt;-->
  252. <!-- <ForgetPasswordForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />-->
  253. <!-- </div>-->
  254. <!-- </Transition>-->
  255. <!-- </div>-->
  256. <!-- </div>-->
  257. <!-- </div>-->
  258. <!--</template>-->
  259. <!--<script lang="ts" setup>-->
  260. <!--import { underlineToHump } from '@/utils'-->
  261. <!--import { useDesign } from '@/hooks/web/useDesign'-->
  262. <!--import { useAppStore } from '@/store/modules/app'-->
  263. <!--import { ThemeSwitch } from '@/layout/components/ThemeSwitch'-->
  264. <!--import { LocaleDropdown } from '@/layout/components/LocaleDropdown'-->
  265. <!--import { LoginForm, MobileForm, QrCodeForm, RegisterForm, SSOLoginVue, ForgetPasswordForm } from './components'-->
  266. <!--defineOptions({ name: 'Login' })-->
  267. <!--const { t } = useI18n()-->
  268. <!--const appStore = useAppStore()-->
  269. <!--const { getPrefixCls } = useDesign()-->
  270. <!--const prefixCls = getPrefixCls('login')-->
  271. <!--</script>-->
  272. <!--<style lang="scss" scoped>-->
  273. <!--$prefix-cls: #{$namespace}-login;-->
  274. <!--.#{$prefix-cls} {-->
  275. <!-- overflow: auto;-->
  276. <!-- &__left {-->
  277. <!-- &::before {-->
  278. <!-- position: absolute;-->
  279. <!-- top: 0;-->
  280. <!-- left: 0;-->
  281. <!-- z-index: -1;-->
  282. <!-- width: 100%;-->
  283. <!-- height: 100%;-->
  284. <!-- background-image: url('@/assets/svgs/login-bg.svg');-->
  285. <!-- background-position: center;-->
  286. <!-- background-repeat: no-repeat;-->
  287. <!-- content: '';-->
  288. <!-- }-->
  289. <!-- }-->
  290. <!--}-->
  291. <!--</style>-->
  292. <!--<style lang="scss">-->
  293. <!--.dark .login-form {-->
  294. <!-- .el-divider__text {-->
  295. <!-- background-color: var(&#45;&#45;login-bg-color);-->
  296. <!-- }-->
  297. <!-- .el-card {-->
  298. <!-- background-color: var(&#45;&#45;login-bg-color);-->
  299. <!-- }-->
  300. <!--}-->
  301. <!--</style>-->