LoginForm.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. <template>
  2. <el-form
  3. v-show="getShow"
  4. ref="formLogin"
  5. :model="loginData.loginForm"
  6. :rules="LoginRules"
  7. class="login-form"
  8. label-position="top"
  9. label-width="120px"
  10. size="large"
  11. >
  12. <el-row style="margin-right: -10px; margin-left: -10px">
  13. <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
  14. <el-form-item>
  15. <LoginFormTitle style="width: 100%" />
  16. </el-form-item>
  17. </el-col>
  18. <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px">-->
  19. <!-- <el-form-item v-if="loginData.tenantEnable === 'true'" prop="tenantName">-->
  20. <!-- <el-input-->
  21. <!-- v-model="loginData.loginForm.tenantName"-->
  22. <!-- :placeholder="t('login.tenantNamePlaceholder')"-->
  23. <!-- :prefix-icon="iconHouse"-->
  24. <!-- link-->
  25. <!-- type="primary"-->
  26. <!-- />-->
  27. <!-- </el-form-item>-->
  28. <!-- </el-col>-->
  29. <el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: 30px">
  30. <el-form-item prop="username">
  31. <el-input
  32. v-model="loginData.loginForm.username"
  33. :placeholder="t('login.usernamePlaceholder')"
  34. :prefix-icon="iconAvatar"
  35. />
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: 15px">
  39. <el-form-item prop="password">
  40. <el-input
  41. v-model="loginData.loginForm.password"
  42. :placeholder="t('login.passwordPlaceholder')"
  43. :prefix-icon="iconLock"
  44. show-password
  45. type="password"
  46. @keyup.enter="getCode()"
  47. />
  48. </el-form-item>
  49. </el-col>
  50. <el-col
  51. :span="24"
  52. style="padding-right: 10px; padding-left: 10px; margin-top: -10px; margin-bottom: -20px"
  53. >
  54. <el-form-item>
  55. <el-row justify="space-between" style="width: 100%">
  56. <el-col :span="6">
  57. <el-checkbox v-model="loginData.loginForm.rememberMe">
  58. {{ t('login.remember') }}
  59. </el-checkbox>
  60. </el-col>
  61. <el-col :offset="6" :span="12">
  62. <el-link
  63. style="float: right"
  64. type="primary"
  65. @click="setLoginState(LoginStateEnum.RESET_PASSWORD)"
  66. >
  67. {{ t('login.forgetPassword') }}
  68. </el-link>
  69. </el-col>
  70. </el-row>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
  74. <el-form-item>
  75. <XButton
  76. :loading="loginLoading"
  77. :title="t('login.login')"
  78. class="w-[100%]"
  79. type="primary"
  80. @click="getCode()"
  81. />
  82. </el-form-item>
  83. </el-col>
  84. <Verify
  85. v-if="loginData.captchaEnable === 'true'"
  86. ref="verify"
  87. :captchaType="captchaType"
  88. :imgSize="{ width: '400px', height: '200px' }"
  89. mode="pop"
  90. @success="handleLogin"
  91. />
  92. <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
  93. <el-form-item>
  94. <el-row :gutter="5" justify="space-between" style="width: 100%">
  95. <!-- <el-col :span="8">-->
  96. <!-- <XButton-->
  97. <!-- :title="t('login.btnMobile')"-->
  98. <!-- class="w-[100%]"-->
  99. <!-- @click="setLoginState(LoginStateEnum.MOBILE)"-->
  100. <!-- />-->
  101. <!-- </el-col>-->
  102. <el-col :span="24">
  103. <XButton
  104. :title="t('login.btnQRCode')"
  105. class="w-[100%]"
  106. @click="setLoginState(LoginStateEnum.QR_CODE)"
  107. />
  108. </el-col>
  109. <!-- <el-col :span="12">-->
  110. <!-- <XButton-->
  111. <!-- :title="t('login.btnRegister')"-->
  112. <!-- class="w-[100%]"-->
  113. <!-- @click="setLoginState(LoginStateEnum.REGISTER)"-->
  114. <!-- />-->
  115. <!-- </el-col>-->
  116. </el-row>
  117. </el-form-item>
  118. </el-col>
  119. <!-- <el-divider content-position="center">{{ t('login.otherLogin') }}</el-divider>-->
  120. <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px">-->
  121. <!-- <el-form-item>-->
  122. <!-- <div class="w-[100%] flex justify-between">-->
  123. <!-- <Icon-->
  124. <!-- v-for="(item, key) in socialList"-->
  125. <!-- :key="key"-->
  126. <!-- :icon="item.icon"-->
  127. <!-- :size="30"-->
  128. <!-- class="anticon cursor-pointer"-->
  129. <!-- color="#999"-->
  130. <!-- @click="doSocialLogin(item.type)"-->
  131. <!-- />-->
  132. <!-- </div>-->
  133. <!-- </el-form-item>-->
  134. <!-- </el-col>-->
  135. <!-- <el-divider content-position="center">萌新必读</el-divider>-->
  136. <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px">-->
  137. <!-- <el-form-item>-->
  138. <!-- <div class="w-[100%] flex justify-between">-->
  139. <!-- <el-link href="https://doc.iocoder.cn/" target="_blank">📚开发指南</el-link>-->
  140. <!-- <el-link href="https://doc.iocoder.cn/video/" target="_blank">🔥视频教程</el-link>-->
  141. <!-- <el-link href="https://www.iocoder.cn/Interview/good-collection/" target="_blank">-->
  142. <!-- ⚡面试手册-->
  143. <!-- </el-link>-->
  144. <!-- <el-link href="http://static.yudao.iocoder.cn/mp/Aix9975.jpeg" target="_blank">-->
  145. <!-- 🤝外包咨询-->
  146. <!-- </el-link>-->
  147. <!-- </div>-->
  148. <!-- </el-form-item>-->
  149. <!-- </el-col>-->
  150. </el-row>
  151. </el-form>
  152. </template>
  153. <script lang="ts" setup>
  154. import { ElLoading } from 'element-plus'
  155. import LoginFormTitle from './LoginFormTitle.vue'
  156. import type { RouteLocationNormalizedLoaded } from 'vue-router'
  157. import { useIcon } from '@/hooks/web/useIcon'
  158. import * as authUtil from '@/utils/auth'
  159. import { usePermissionStore } from '@/store/modules/permission'
  160. import * as LoginApi from '@/api/login'
  161. import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'
  162. defineOptions({ name: 'LoginForm' })
  163. const { t } = useI18n()
  164. const message = useMessage()
  165. const iconHouse = useIcon({ icon: 'ep:house' })
  166. const iconAvatar = useIcon({ icon: 'ep:avatar' })
  167. const iconLock = useIcon({ icon: 'ep:lock' })
  168. const formLogin = ref()
  169. const { validForm } = useFormValid(formLogin)
  170. const { setLoginState, getLoginState } = useLoginState()
  171. const { currentRoute, push } = useRouter()
  172. const permissionStore = usePermissionStore()
  173. const redirect = ref<string>('')
  174. const loginLoading = ref(false)
  175. const verify = ref()
  176. const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字
  177. const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
  178. const LoginRules = {
  179. tenantName: [required],
  180. username: [required],
  181. password: [required]
  182. }
  183. const loginData = reactive({
  184. isShowPassword: false,
  185. captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,
  186. tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
  187. loginForm: {
  188. tenantName: import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT || '',
  189. username: import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME || '',
  190. password: import.meta.env.VITE_APP_DEFAULT_LOGIN_PASSWORD || '',
  191. captchaVerification: '',
  192. rememberMe: true // 默认记录我。如果不需要,可手动修改
  193. }
  194. })
  195. const socialList = [
  196. { icon: 'ant-design:wechat-filled', type: 30 },
  197. { icon: 'ant-design:dingtalk-circle-filled', type: 20 },
  198. { icon: 'ant-design:github-filled', type: 0 },
  199. { icon: 'ant-design:alipay-circle-filled', type: 0 }
  200. ]
  201. // 获取验证码
  202. const getCode = async () => {
  203. // 情况一,未开启:则直接登录
  204. if (loginData.captchaEnable === 'false') {
  205. await handleLogin({})
  206. } else {
  207. // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
  208. // 弹出验证码
  209. verify.value.show()
  210. }
  211. }
  212. // 获取租户 ID
  213. const getTenantId = async () => {
  214. if (loginData.tenantEnable === 'true') {
  215. const res = await LoginApi.getTenantIdByName(loginData.loginForm.tenantName)
  216. authUtil.setTenantId(res)
  217. }
  218. }
  219. // 记住我
  220. const getLoginFormCache = () => {
  221. const loginForm = authUtil.getLoginForm()
  222. if (loginForm) {
  223. loginData.loginForm = {
  224. ...loginData.loginForm,
  225. username: loginForm.username ? loginForm.username : loginData.loginForm.username,
  226. password: loginForm.password ? loginForm.password : loginData.loginForm.password,
  227. rememberMe: loginForm.rememberMe,
  228. tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
  229. }
  230. }
  231. }
  232. // 根据域名,获得租户信息
  233. const getTenantByWebsite = async () => {
  234. const website = location.host
  235. const res = await LoginApi.getTenantByWebsite(website)
  236. if (res) {
  237. loginData.loginForm.tenantName = res.name
  238. authUtil.setTenantId(res.id)
  239. }
  240. }
  241. const loading = ref() // ElLoading.service 返回的实例
  242. // 登录
  243. const handleLogin = async (params: any) => {
  244. loginLoading.value = true
  245. try {
  246. await getTenantId()
  247. const data = await validForm()
  248. if (!data) {
  249. return
  250. }
  251. const loginDataLoginForm = { ...loginData.loginForm }
  252. loginDataLoginForm.captchaVerification = params.captchaVerification
  253. const res = await LoginApi.login(loginDataLoginForm)
  254. // if (!res) {
  255. // return
  256. // }
  257. loading.value = ElLoading.service({
  258. lock: true,
  259. text: '正在加载系统中...',
  260. background: 'rgba(0, 0, 0, 0.7)'
  261. })
  262. if (loginDataLoginForm.rememberMe) {
  263. authUtil.setLoginForm(loginDataLoginForm)
  264. } else {
  265. authUtil.removeLoginForm()
  266. }
  267. authUtil.setToken(res)
  268. if (!redirect.value) {
  269. redirect.value = '/'
  270. }
  271. // 判断是否为SSO登录
  272. if (redirect.value.indexOf('sso') !== -1) {
  273. window.location.href = window.location.href.replace('/login?redirect=', '')
  274. } else {
  275. await push({ path: redirect.value || permissionStore.addRouters[0].path })
  276. }
  277. } finally {
  278. loginLoading.value = false
  279. loading.value.close()
  280. }
  281. }
  282. // 社交登录
  283. const doSocialLogin = async (type: number) => {
  284. if (type === 0) {
  285. message.error('此方式未配置')
  286. } else {
  287. loginLoading.value = true
  288. if (loginData.tenantEnable === 'true') {
  289. // 尝试先通过 tenantName 获取租户
  290. await getTenantId()
  291. // 如果获取不到,则需要弹出提示,进行处理
  292. if (!authUtil.getTenantId()) {
  293. try {
  294. const data = await message.prompt('请输入租户名称', t('common.reminder'))
  295. if (data?.action !== 'confirm') throw 'cancel'
  296. const res = await LoginApi.getTenantIdByName(data.value)
  297. authUtil.setTenantId(res)
  298. } catch (error) {
  299. if (error === 'cancel') return
  300. } finally {
  301. loginLoading.value = false
  302. }
  303. }
  304. }
  305. // 计算 redirectUri
  306. // 注意: type、redirect 需要先 encode 一次,否则钉钉回调会丢失。
  307. // 配合 social-login.vue#getUrlValue() 使用
  308. const redirectUri =
  309. location.origin +
  310. '/social-login?' +
  311. encodeURIComponent(`type=${type}&redirect=${redirect.value || '/'}`)
  312. // 进行跳转
  313. window.location.href = await LoginApi.socialAuthRedirect(type, encodeURIComponent(redirectUri))
  314. }
  315. }
  316. watch(
  317. () => currentRoute.value,
  318. (route: RouteLocationNormalizedLoaded) => {
  319. redirect.value = route?.query?.redirect as string
  320. },
  321. {
  322. immediate: true
  323. }
  324. )
  325. onMounted(() => {
  326. getLoginFormCache()
  327. getTenantByWebsite()
  328. })
  329. </script>
  330. <style lang="scss" scoped>
  331. :deep(.anticon) {
  332. &:hover {
  333. color: var(--el-color-primary) !important;
  334. }
  335. }
  336. .login-code {
  337. float: right;
  338. width: 100%;
  339. height: 38px;
  340. img {
  341. width: 100%;
  342. height: auto;
  343. max-width: 100px;
  344. vertical-align: middle;
  345. cursor: pointer;
  346. }
  347. }
  348. </style>
  349. <!--<template>-->
  350. <!-- <el-form-->
  351. <!-- v-show="getShow"-->
  352. <!-- ref="formLogin"-->
  353. <!-- :model="loginData.loginForm"-->
  354. <!-- :rules="LoginRules"-->
  355. <!-- class="login-form"-->
  356. <!-- label-position="top"-->
  357. <!-- label-width="120px"-->
  358. <!-- size="large"-->
  359. <!-- >-->
  360. <!-- <el-row style="display: flex;justify-content: center">-->
  361. <!-- <el-image v-if="loginType === 'uname'" :src="imgsaoma" class="clickable-image" alt="扫码登录" title="扫码登录" @click="changeLogin('dingding')"/>-->
  362. <!-- <el-image v-if="loginType === 'dingding'" :src="imgreturn" class="clickable-image" alt="返回" title="返回" @click="changeLogin('uname')"/>-->
  363. <!-- <el-image :src="img" class=" h-100px" style="margin-top: 16%"/>-->
  364. <!-- <div v-if="loginType === 'uname'" style="width: 90%">-->
  365. <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: 85px">-->
  366. <!-- <el-form-item prop="username" >-->
  367. <!-- <el-input v-model="loginData.loginForm.username" :placeholder="t('login.usernamePlaceholder')" type="text" auto-complete="off" :prefix-icon="iconAvatar"/>-->
  368. <!-- </el-form-item>-->
  369. <!-- </el-col>-->
  370. <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px;margin-top: 15px">-->
  371. <!-- <el-form-item prop="password">-->
  372. <!-- <el-input-->
  373. <!-- v-model="loginData.loginForm.password"-->
  374. <!-- :placeholder="t('login.passwordPlaceholder')"-->
  375. <!-- :prefix-icon="iconLock"-->
  376. <!-- show-password-->
  377. <!-- type="password"-->
  378. <!-- @keyup.enter="getCode()"-->
  379. <!-- />-->
  380. <!-- </el-form-item>-->
  381. <!-- </el-col>-->
  382. <!-- <el-col-->
  383. <!-- :span="24"-->
  384. <!-- style="padding-right: 10px; padding-left: 10px; margin-top: 20px;"-->
  385. <!-- >-->
  386. <!-- <el-form-item>-->
  387. <!-- <el-row justify="space-between" style="width: 100%;">-->
  388. <!-- <el-col :span="6">-->
  389. <!-- <el-checkbox v-model="loginData.loginForm.rememberMe">-->
  390. <!-- {{ t('login.remember') }}-->
  391. <!-- </el-checkbox>-->
  392. <!-- </el-col>-->
  393. <!-- <el-col :offset="6" :span="12">-->
  394. <!-- <el-link-->
  395. <!-- style="float: right"-->
  396. <!-- type="primary"-->
  397. <!-- @click="setLoginState(LoginStateEnum.RESET_PASSWORD)"-->
  398. <!-- >-->
  399. <!-- {{ t('login.forgetPassword') }}-->
  400. <!-- </el-link>-->
  401. <!-- </el-col>-->
  402. <!-- </el-row>-->
  403. <!-- </el-form-item>-->
  404. <!-- </el-col>-->
  405. <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px;margin-bottom: 10px">-->
  406. <!-- <el-form-item>-->
  407. <!-- <XButton-->
  408. <!-- style="height: 4em;background-color: rgb(11, 26, 50);border: none;opacity: 1;color: rgb(186, 205, 224)"-->
  409. <!-- :loading="loginLoading"-->
  410. <!-- :title="t('login.login')"-->
  411. <!-- class="w-[100%]"-->
  412. <!-- type="primary"-->
  413. <!-- @click="getCode()"-->
  414. <!-- />-->
  415. <!-- </el-form-item>-->
  416. <!-- </el-col>-->
  417. <!-- <Verify-->
  418. <!-- v-if="loginData.captchaEnable === 'true'"-->
  419. <!-- ref="verify"-->
  420. <!-- :captchaType="captchaType"-->
  421. <!-- :imgSize="{ width: '400px', height: '200px' }"-->
  422. <!-- mode="pop"-->
  423. <!-- @success="handleLogin"-->
  424. <!-- />-->
  425. <!-- </div>-->
  426. <!-- <div v-if="loginType === 'dingding'" id="login_container" style="margin-left: 8%;margin-top: 18%">-->
  427. <!-- </div>-->
  428. <!-- </el-row>-->
  429. <!-- </el-form>-->
  430. <!--</template>-->
  431. <!--<script lang="ts" setup>-->
  432. <!--import img from '@/assets/imgs/img.png'-->
  433. <!--import imgsaoma from '@/assets/imgs/saoma.png'-->
  434. <!--import imgreturn from '@/assets/imgs/return.png'-->
  435. <!--import { ElLoading } from 'element-plus'-->
  436. <!--import type { RouteLocationNormalizedLoaded } from 'vue-router'-->
  437. <!--import { useIcon } from '@/hooks/web/useIcon'-->
  438. <!--import * as DictDataApi from '@/api/system/dict/dict.data'-->
  439. <!--import * as authUtil from '@/utils/auth'-->
  440. <!--import { usePermissionStore } from '@/store/modules/permission'-->
  441. <!--import * as LoginApi from '@/api/login'-->
  442. <!--import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'-->
  443. <!--import { ref,nextTick,onMounted } from 'vue';-->
  444. <!--const appId = 'dingik345qmyhtysvs2x'-->
  445. <!--const dingRedirectUrl = 'http://1.94.244.160:91/login?loginType=dingding&type=20'-->
  446. <!--onMounted(()=>{-->
  447. <!-- getTenantName();-->
  448. <!--})-->
  449. <!--const getTenantName=async ()=>{-->
  450. <!-- const queryParams = reactive({-->
  451. <!-- pageNo: 1,-->
  452. <!-- pageSize: 10,-->
  453. <!-- label: '',-->
  454. <!-- status: undefined,-->
  455. <!-- dictType: 'tenant_name'-->
  456. <!-- })-->
  457. <!-- const data = await DictDataApi.getDictDataPage(queryParams)-->
  458. <!-- loginData.loginForm.tenantName = data.list[0].label;-->
  459. <!--}-->
  460. <!--const loginType = ref('uname');-->
  461. <!--const changeLogin = async (type) => {-->
  462. <!-- console.log(loginData.loginForm.tenantName)-->
  463. <!-- await getTenantId()-->
  464. <!-- loginType.value = type;-->
  465. <!-- if (type === 'dingding') {-->
  466. <!-- initDingLogin();-->
  467. <!-- }-->
  468. <!--};-->
  469. <!--const initDingLogin=()=> {-->
  470. <!-- // if (window.DDLogin) {-->
  471. <!-- var url = dingRedirectUrl-->
  472. <!-- var state = _getRandomString(10);-->
  473. <!-- var gotoUrl = encodeURIComponent(-->
  474. <!-- "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?" +-->
  475. <!-- "appid=" + appId +-->
  476. <!-- "&response_type=code" +-->
  477. <!-- "&scope=snsapi_login" +-->
  478. <!-- "&state=" + state +-->
  479. <!-- "&redirect_uri=" + url-->
  480. <!-- );-->
  481. <!-- nextTick(() => {-->
  482. <!-- var obj = window.DDLogin({-->
  483. <!-- id: "login_container",-->
  484. <!-- goto: gotoUrl,-->
  485. <!-- style: "border:none;background-color:#FFFFFF;",-->
  486. <!-- width: '90%', // 二维码的宽度-->
  487. <!-- height: "290", // 二维码的高度-->
  488. <!-- })-->
  489. <!-- // 重置扫码登录框的样式,让登录框居中-->
  490. <!-- let box = document.getElementById('login_container')-->
  491. <!-- box.querySelector('iframe').style.top = '0'-->
  492. <!-- box.querySelector('iframe').style.bottom = '0'-->
  493. <!-- box.querySelector('iframe').style.left = '0'-->
  494. <!-- box.querySelector('iframe').style.right = '0'-->
  495. <!-- box.querySelector('iframe').style.margin = 'auto'-->
  496. <!-- })-->
  497. <!-- /* new window.DDLogin({-->
  498. <!-- id: "login_container",-->
  499. <!-- goto: gotoUrl,-->
  500. <!-- style: "border:none;background-color:#FFFFFF;",-->
  501. <!-- width: "350",-->
  502. <!-- height: "350",-->
  503. <!-- }); */-->
  504. <!-- var handleMessage = function (event) {-->
  505. <!-- var origin = event.origin;-->
  506. <!-- if (origin === "https://login.dingtalk.com") {-->
  507. <!-- var loginTmpCode = event.data;-->
  508. <!-- console.log(loginTmpCode)-->
  509. <!-- window.location.href =-->
  510. <!-- "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingik345qmyhtysvs2x&response_type=code&scope=snsapi_login&state=" +-->
  511. <!-- state +-->
  512. <!-- "&redirect_uri=" +-->
  513. <!-- url +-->
  514. <!-- "&loginTmpCode=" +-->
  515. <!-- loginTmpCode;-->
  516. <!-- }-->
  517. <!-- };-->
  518. <!-- if (typeof window.addEventListener != "undefined") {-->
  519. <!-- window.addEventListener("message", handleMessage, false);-->
  520. <!-- } else if (typeof window.attachEvent != "undefined") {-->
  521. <!-- window.attachEvent("onmessage", handleMessage);-->
  522. <!-- }-->
  523. <!-- // }-->
  524. <!--}-->
  525. <!--const _getRandomString=(len)=> {-->
  526. <!-- len = len || 10;-->
  527. <!-- let $chars = "ABCDEFGHIJKMNOPQRSTUVWXYZ"; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1-->
  528. <!-- let maxPos = $chars.length;-->
  529. <!-- let pwd = "";-->
  530. <!-- for (var i = 0; i < len; i++) {-->
  531. <!-- pwd += $chars.charAt(Math.floor(Math.random() * maxPos));-->
  532. <!-- }-->
  533. <!-- return pwd;-->
  534. <!--}-->
  535. <!--defineOptions({ name: 'LoginForm' })-->
  536. <!--const { t } = useI18n()-->
  537. <!--const message = useMessage()-->
  538. <!--const iconHouse = useIcon({ icon: 'ep:house' })-->
  539. <!--const iconAvatar = useIcon({ icon: 'ep:avatar',size:26 })-->
  540. <!--const iconLock = useIcon({ icon: 'ep:lock',size:26 })-->
  541. <!--const formLogin = ref()-->
  542. <!--const { validForm } = useFormValid(formLogin)-->
  543. <!--const { setLoginState, getLoginState } = useLoginState()-->
  544. <!--const { currentRoute, push } = useRouter()-->
  545. <!--const permissionStore = usePermissionStore()-->
  546. <!--const redirect = ref<string>('')-->
  547. <!--const loginLoading = ref(false)-->
  548. <!--const verify = ref()-->
  549. <!--const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字-->
  550. <!--const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)-->
  551. <!--const LoginRules = {-->
  552. <!-- tenantName: [required],-->
  553. <!-- username: [required],-->
  554. <!-- password: [required]-->
  555. <!--}-->
  556. <!--const loginData = reactive({-->
  557. <!-- isShowPassword: false,-->
  558. <!-- captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,-->
  559. <!-- tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,-->
  560. <!-- loginForm: {-->
  561. <!-- tenantName: '瑞气能源',-->
  562. <!-- username: import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME || '',-->
  563. <!-- password: import.meta.env.VITE_APP_DEFAULT_LOGIN_PASSWORD || '',-->
  564. <!-- captchaVerification: '',-->
  565. <!-- rememberMe: true // 默认记录我。如果不需要,可手动修改-->
  566. <!-- }-->
  567. <!--})-->
  568. <!--// const socialList = [-->
  569. <!--// { icon: 'ant-design:wechat-filled', type: 30 },-->
  570. <!--// { icon: 'ant-design:dingtalk-circle-filled', type: 20 },-->
  571. <!--// { icon: 'ant-design:github-filled', type: 0 },-->
  572. <!--// { icon: 'ant-design:alipay-circle-filled', type: 0 }-->
  573. <!--// ]-->
  574. <!--// 获取验证码-->
  575. <!--const getCode = async () => {-->
  576. <!-- // 情况一,未开启:则直接登录-->
  577. <!-- if (loginData.captchaEnable === 'false') {-->
  578. <!-- await handleLogin({})-->
  579. <!-- } else {-->
  580. <!-- // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录-->
  581. <!-- // 弹出验证码-->
  582. <!-- verify.value.show()-->
  583. <!-- }-->
  584. <!--}-->
  585. <!--// 获取租户 ID-->
  586. <!--const getTenantId = async () => {-->
  587. <!-- if (loginData.tenantEnable === 'true') {-->
  588. <!-- const res = await LoginApi.getTenantIdByName(loginData.loginForm.tenantName)-->
  589. <!-- authUtil.setTenantId(res)-->
  590. <!-- }-->
  591. <!--}-->
  592. <!--// 记住我-->
  593. <!--const getLoginFormCache = () => {-->
  594. <!-- const loginForm = authUtil.getLoginForm()-->
  595. <!-- if (loginForm) {-->
  596. <!-- loginData.loginForm = {-->
  597. <!-- ...loginData.loginForm,-->
  598. <!-- username: loginForm.username ? loginForm.username : loginData.loginForm.username,-->
  599. <!-- password: loginForm.password ? loginForm.password : loginData.loginForm.password,-->
  600. <!-- rememberMe: loginForm.rememberMe,-->
  601. <!-- tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName-->
  602. <!-- }-->
  603. <!-- }-->
  604. <!--}-->
  605. <!--// 根据域名,获得租户信息-->
  606. <!--const getTenantByWebsite = async () => {-->
  607. <!-- const website = location.host-->
  608. <!-- const res = await LoginApi.getTenantByWebsite(website)-->
  609. <!-- if (res) {-->
  610. <!-- loginData.loginForm.tenantName = res.name-->
  611. <!-- authUtil.setTenantId(res.id)-->
  612. <!-- }-->
  613. <!--}-->
  614. <!--const loading = ref() // ElLoading.service 返回的实例-->
  615. <!--// 登录-->
  616. <!--const handleLogin = async (params: any) => {-->
  617. <!-- loginLoading.value = true-->
  618. <!-- try {-->
  619. <!-- await getTenantId()-->
  620. <!-- const data = await validForm()-->
  621. <!-- if (!data) {-->
  622. <!-- return-->
  623. <!-- }-->
  624. <!-- const loginDataLoginForm = { ...loginData.loginForm }-->
  625. <!-- loginDataLoginForm.captchaVerification = params.captchaVerification-->
  626. <!-- const res = await LoginApi.login(loginDataLoginForm)-->
  627. <!-- if (!res) {-->
  628. <!-- return-->
  629. <!-- }-->
  630. <!-- loading.value = ElLoading.service({-->
  631. <!-- lock: true,-->
  632. <!-- text: '正在加载系统中...',-->
  633. <!-- background: 'rgba(0, 0, 0, 0.7)'-->
  634. <!-- })-->
  635. <!-- if (loginDataLoginForm.rememberMe) {-->
  636. <!-- authUtil.setLoginForm(loginDataLoginForm)-->
  637. <!-- } else {-->
  638. <!-- authUtil.removeLoginForm()-->
  639. <!-- }-->
  640. <!-- authUtil.setToken(res)-->
  641. <!-- if (!redirect.value) {-->
  642. <!-- redirect.value = '/'-->
  643. <!-- }-->
  644. <!-- // 判断是否为SSO登录-->
  645. <!-- if (redirect.value.indexOf('sso') !== -1) {-->
  646. <!-- window.location.href = window.location.href.replace('/login?redirect=', '')-->
  647. <!-- } else {-->
  648. <!-- await push({ path: redirect.value || permissionStore.addRouters[0].path })-->
  649. <!-- }-->
  650. <!-- } finally {-->
  651. <!-- loginLoading.value = false-->
  652. <!-- loading.value.close()-->
  653. <!-- }-->
  654. <!--}-->
  655. <!--// 社交登录-->
  656. <!--watch(-->
  657. <!-- () => currentRoute.value,-->
  658. <!-- (route: RouteLocationNormalizedLoaded) => {-->
  659. <!-- redirect.value = route?.query?.redirect as string-->
  660. <!-- },-->
  661. <!-- {-->
  662. <!-- immediate: true-->
  663. <!-- }-->
  664. <!--)-->
  665. <!--onMounted(() => {-->
  666. <!-- getLoginFormCache()-->
  667. <!-- getTenantByWebsite()-->
  668. <!--})-->
  669. <!--</script>-->
  670. <!--<style lang="scss" scoped>-->
  671. <!--::v-deep .el-input__wrapper {-->
  672. <!-- background-color: transparent !important;-->
  673. <!-- height: 3.5em;-->
  674. <!-- color: white;-->
  675. <!-- box-shadow: none !important;-->
  676. <!-- border-radius: 0;-->
  677. <!-- border: none !important;-->
  678. <!-- border-bottom: 1px solid #bacde0 !important;-->
  679. <!-- outline: none;-->
  680. <!--}-->
  681. <!--:deep(.anticon) {-->
  682. <!-- &:hover {-->
  683. <!-- color: var(&#45;&#45;el-color-primary) !important;-->
  684. <!-- }-->
  685. <!--}-->
  686. <!--.login-code {-->
  687. <!-- float: right;-->
  688. <!-- width: 100%;-->
  689. <!-- height: 38px;-->
  690. <!-- img {-->
  691. <!-- width: 100%;-->
  692. <!-- height: auto;-->
  693. <!-- max-width: 100px;-->
  694. <!-- vertical-align: middle;-->
  695. <!-- cursor: pointer;-->
  696. <!-- }-->
  697. <!--}-->
  698. <!--::v-deep .rqinput .el-input__inner {-->
  699. <!-- background-color: transparent !important;-->
  700. <!-- border: none !important;-->
  701. <!-- border-bottom: 1px solid rgb(186, 205, 224) !important;-->
  702. <!-- border-radius: 0;-->
  703. <!-- height: 2.8em;-->
  704. <!-- //left: 18%;-->
  705. <!-- padding-left: 3em;-->
  706. <!-- color: white;-->
  707. <!--}-->
  708. <!--.clickable-image {-->
  709. <!-- cursor: pointer;-->
  710. <!-- position:absolute;-->
  711. <!-- //top: 2%;-->
  712. <!-- //right: 2%;-->
  713. <!-- width: 6%;-->
  714. <!-- margin-top: -9%;-->
  715. <!-- margin-left: 111%;-->
  716. <!--}-->
  717. <!--::v-deep .el-input__inner {-->
  718. <!-- color: white;-->
  719. <!--}-->
  720. <!--</style>-->