login.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="login_background">
  3. <div class="login_background_front"></div>
  4. <div class="login_main">
  5. <div class="login_config">
  6. <a-dropdown>
  7. <global-outlined />
  8. <template #overlay>
  9. <a-menu>
  10. <a-menu-item
  11. v-for="item in lang"
  12. :key="item.value"
  13. :command="item"
  14. :class="{ selected: config.lang === item.value }"
  15. @click="configLang(item.value)"
  16. >
  17. {{ item.name }}
  18. </a-menu-item>
  19. </a-menu>
  20. </template>
  21. </a-dropdown>
  22. </div>
  23. <div class="login-form">
  24. <a-card>
  25. <div class="login-header">
  26. <div class="logo">
  27. <img :alt="sysBaseConfig.SNOWY_SYS_NAME" :src="sysBaseConfig.SNOWY_SYS_LOGO" />
  28. <label>{{ sysBaseConfig.SNOWY_SYS_NAME }}</label>
  29. </div>
  30. <!--<h2>{{ $t('login.signInTitle') }}</h2>-->
  31. </div>
  32. <a-tabs v-model:activeKey="activeKey">
  33. <a-tab-pane key="userAccount" :tab="$t('login.accountPassword')">
  34. <a-form ref="loginForm" :model="ruleForm" :rules="rules">
  35. <a-form-item name="account">
  36. <a-input
  37. v-model:value="ruleForm.account"
  38. :placeholder="$t('login.accountPlaceholder')"
  39. size="large"
  40. @keyup.enter="login"
  41. >
  42. <template #prefix>
  43. <UserOutlined class="login-icon-gray" />
  44. </template>
  45. </a-input>
  46. </a-form-item>
  47. <a-form-item name="password">
  48. <a-input-password
  49. v-model:value="ruleForm.password"
  50. :placeholder="$t('login.PWPlaceholder')"
  51. size="large"
  52. autocomplete="off"
  53. @keyup.enter="login"
  54. >
  55. <template #prefix>
  56. <LockOutlined class="login-icon-gray" />
  57. </template>
  58. </a-input-password>
  59. </a-form-item>
  60. <a-form-item name="validCode" v-if="captchaOpen === 'true'">
  61. <a-row :gutter="8">
  62. <a-col :span="17">
  63. <a-input
  64. v-model:value="ruleForm.validCode"
  65. :placeholder="$t('login.validLaceholder')"
  66. size="large"
  67. @keyup.enter="login"
  68. >
  69. <template #prefix>
  70. <verified-outlined class="login-icon-gray" />
  71. </template>
  72. </a-input>
  73. </a-col>
  74. <a-col :span="7">
  75. <img :src="validCodeBase64" class="login-validCode-img" @click="loginCaptcha" />
  76. </a-col>
  77. </a-row>
  78. </a-form-item>
  79. <a-form-item>
  80. <a href="/findpwd" style="color: #0d84ff">{{ $t('login.forgetPassword') }}?</a>
  81. </a-form-item>
  82. <a-form-item>
  83. <a-button type="primary" class="w-full" :loading="loading" round size="large" @click="login"
  84. >{{ $t('login.signIn') }}
  85. </a-button>
  86. </a-form-item>
  87. </a-form>
  88. </a-tab-pane>
  89. <a-tab-pane key="userSms" :tab="$t('login.phoneSms')" force-render>
  90. <phone-login-form />
  91. </a-tab-pane>
  92. </a-tabs>
  93. <three-login />
  94. </a-card>
  95. </div>
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. import loginApi from '@/api/auth/loginApi'
  101. import phoneLoginForm from './phoneLoginForm.vue'
  102. import threeLogin from './threeLogin.vue'
  103. import smCrypto from '@/utils/smCrypto'
  104. import { required } from '@/utils/formRules'
  105. import { afterLogin } from './util'
  106. import config from '@/config'
  107. import configApi from '@/api/dev/configApi'
  108. import tool from '@/utils/tool'
  109. import { globalStore, iframeStore, keepAliveStore, viewTagsStore } from '@/store'
  110. import { mapActions, mapState } from 'pinia'
  111. export default {
  112. name: 'Login',
  113. components: {
  114. phoneLoginForm,
  115. threeLogin
  116. },
  117. data() {
  118. return {
  119. activeKey: 'userAccount',
  120. captchaOpen: config.SYS_BASE_CONFIG.SNOWY_SYS_DEFAULT_CAPTCHA_OPEN,
  121. validCodeBase64: '',
  122. ruleForm: {
  123. account: '',
  124. password: '',
  125. validCode: '',
  126. validCodeReqNo: '',
  127. autologin: false,
  128. eduIdentity: '0'
  129. },
  130. rules: {
  131. account: [required(this.$t('login.accountError'), 'blur')],
  132. password: [required(this.$t('login.PWError'), 'blur')]
  133. },
  134. loading: false,
  135. config: {
  136. lang: tool.data.get('APP_LANG') || this.$CONFIG.LANG,
  137. theme: tool.data.get('APP_THEME') || 'default'
  138. },
  139. lang: [
  140. {
  141. name: '简体中文',
  142. value: 'zh-cn'
  143. },
  144. {
  145. name: 'English',
  146. value: 'en'
  147. }
  148. ]
  149. }
  150. },
  151. computed: {
  152. ...mapState(globalStore, ['sysBaseConfig']),
  153. },
  154. watch: {
  155. 'config.theme': function (val) {
  156. document.body.setAttribute('data-theme', val)
  157. },
  158. 'config.lang': function (val) {
  159. this.$i18n.locale = val
  160. tool.data.set('APP_LANG', val)
  161. }
  162. },
  163. created() {
  164. this.clearViewTags()
  165. this.clearKeepLive()
  166. this.clearIframeList()
  167. },
  168. mounted() {
  169. let formData = ref(config.SYS_BASE_CONFIG)
  170. configApi.configSysBaseList().then((data) => {
  171. if (data) {
  172. data.forEach((item) => {
  173. formData.value[item.configKey] = item.configValue
  174. })
  175. this.captchaOpen = formData.value.SNOWY_SYS_DEFAULT_CAPTCHA_OPEN
  176. tool.data.set('SNOWY_SYS_BASE_CONFIG', formData.value)
  177. this.setSysBaseConfig(formData.value)
  178. this.refreshSwitch()
  179. }
  180. })
  181. },
  182. methods: {
  183. ...mapActions(keepAliveStore, ['clearKeepLive']),
  184. ...mapActions(viewTagsStore, ['clearViewTags']),
  185. ...mapActions(iframeStore, ['clearIframeList']),
  186. ...mapActions(globalStore, ['setSysBaseConfig']),
  187. // 通过开关加载内容
  188. refreshSwitch() {
  189. // 判断是否开启验证码
  190. if (this.captchaOpen === 'true') {
  191. // 加载验证码
  192. this.loginCaptcha()
  193. // 加入校验
  194. this.rules.validCode = [required(this.$t('login.validError'), 'blur')]
  195. }
  196. },
  197. // 获取验证码
  198. loginCaptcha() {
  199. loginApi.getPicCaptcha().then((data) => {
  200. this.validCodeBase64 = data.validCodeBase64
  201. this.ruleForm.validCodeReqNo = data.validCodeReqNo
  202. })
  203. },
  204. // 用户名密码登录
  205. async login() {
  206. this.$refs.loginForm.validate().then(async () => {
  207. this.loading = true
  208. const loginData = {
  209. account: this.ruleForm.account,
  210. // 密码进行SM2加密,传输过程中看到的只有密文,后端存储使用hash
  211. password: smCrypto.doSm2Encrypt(this.ruleForm.password),
  212. validCode: this.ruleForm.validCode,
  213. validCodeReqNo: this.ruleForm.validCodeReqNo,
  214. eduIdentity: this.ruleForm.eduIdentity
  215. }
  216. // 获取token
  217. try {
  218. const loginToken = await loginApi.login(loginData)
  219. afterLogin(loginToken)
  220. } catch (err) {
  221. this.loading = false
  222. this.loginCaptcha()
  223. }
  224. })
  225. },
  226. configLang(key) {
  227. this.config.lang = key
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="less">
  233. @import 'login';
  234. </style>