login.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="login_background">
  3. <div style="display: flex;width: 100%; height: 100%; justify-content: center; align-items: center">
  4. <a-card>
  5. <div style="margin-bottom: 20px">
  6. <span style="font-size: 20px;">教师登录</span>
  7. </div>
  8. <a-form ref="loginForm" :model="ruleForm" :rules="rules">
  9. <a-form-item name="account">
  10. <a-input
  11. v-model:value="ruleForm.account"
  12. :placeholder="$t('login.accountPlaceholder')"
  13. size="large"
  14. @keyup.enter="login"
  15. >
  16. <template #prefix>
  17. <UserOutlined class="login-icon-gray" />
  18. </template>
  19. </a-input>
  20. </a-form-item>
  21. <a-form-item name="password">
  22. <a-input-password
  23. v-model:value="ruleForm.password"
  24. :placeholder="$t('login.PWPlaceholder')"
  25. size="large"
  26. autocomplete="off"
  27. @keyup.enter="login"
  28. >
  29. <template #prefix>
  30. <LockOutlined class="login-icon-gray" />
  31. </template>
  32. </a-input-password>
  33. </a-form-item>
  34. <a-form-item name="validCode" v-if="captchaOpen === 'true'">
  35. <a-row :gutter="8">
  36. <a-col :span="17">
  37. <a-input
  38. v-model:value="ruleForm.validCode"
  39. :placeholder="$t('login.validLaceholder')"
  40. size="large"
  41. @keyup.enter="login"
  42. >
  43. <template #prefix>
  44. <verified-outlined class="login-icon-gray" />
  45. </template>
  46. </a-input>
  47. </a-col>
  48. <a-col :span="7">
  49. <img :src="validCodeBase64" class="login-validCode-img" @click="loginCaptcha" />
  50. </a-col>
  51. </a-row>
  52. </a-form-item>
  53. <a-form-item>
  54. <a-button style="position: absolute; width: 100%; buttom:0px " type="primary" :loading="loading" round size="large" @click="login"
  55. >{{ $t('login.signIn') }}
  56. </a-button>
  57. </a-form-item>
  58. </a-form>
  59. </a-card>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import loginApi from '@/api/auth/loginApi'
  65. import phoneLoginForm from './phoneLoginForm.vue'
  66. import threeLogin from './threeLogin.vue'
  67. import smCrypto from '@/utils/smCrypto'
  68. import { required } from '@/utils/formRules'
  69. import { afterLogin } from './util'
  70. import config from '@/config'
  71. import configApi from '@/api/dev/configApi'
  72. import tool from '@/utils/tool'
  73. import { globalStore, iframeStore, keepAliveStore, viewTagsStore } from '@/store'
  74. import { mapActions, mapState } from 'pinia'
  75. export default {
  76. name: 'Login',
  77. components: {
  78. phoneLoginForm,
  79. threeLogin
  80. },
  81. data() {
  82. return {
  83. activeKey: 'userAccount',
  84. captchaOpen: config.SYS_BASE_CONFIG.SNOWY_SYS_DEFAULT_CAPTCHA_OPEN,
  85. validCodeBase64: '',
  86. ruleForm: {
  87. account: 'superAdmin',
  88. password: '123456',
  89. validCode: '',
  90. validCodeReqNo: '',
  91. autologin: false
  92. },
  93. rules: {
  94. account: [required(this.$t('login.accountError'), 'blur')],
  95. password: [required(this.$t('login.PWError'), 'blur')]
  96. },
  97. loading: false,
  98. config: {
  99. lang: tool.data.get('APP_LANG') || this.$CONFIG.LANG,
  100. theme: tool.data.get('APP_THEME') || 'default'
  101. },
  102. lang: [
  103. {
  104. name: '简体中文',
  105. value: 'zh-cn'
  106. },
  107. {
  108. name: 'English',
  109. value: 'en'
  110. }
  111. ]
  112. }
  113. },
  114. computed: {
  115. ...mapState(globalStore, ['sysBaseConfig']),
  116. },
  117. watch: {
  118. 'config.theme': function (val) {
  119. document.body.setAttribute('data-theme', val)
  120. },
  121. 'config.lang': function (val) {
  122. this.$i18n.locale = val
  123. tool.data.set('APP_LANG', val)
  124. }
  125. },
  126. created() {
  127. this.clearViewTags()
  128. this.clearKeepLive()
  129. this.clearIframeList()
  130. },
  131. mounted() {
  132. let formData = ref(config.SYS_BASE_CONFIG)
  133. configApi.configSysBaseList().then((data) => {
  134. if (data) {
  135. data.forEach((item) => {
  136. formData.value[item.configKey] = item.configValue
  137. })
  138. this.captchaOpen = formData.value.SNOWY_SYS_DEFAULT_CAPTCHA_OPEN
  139. tool.data.set('SNOWY_SYS_BASE_CONFIG', formData.value)
  140. this.setSysBaseConfig(formData.value)
  141. this.refreshSwitch()
  142. }
  143. })
  144. },
  145. methods: {
  146. ...mapActions(keepAliveStore, ['clearKeepLive']),
  147. ...mapActions(viewTagsStore, ['clearViewTags']),
  148. ...mapActions(iframeStore, ['clearIframeList']),
  149. ...mapActions(globalStore, ['setSysBaseConfig']),
  150. // 通过开关加载内容
  151. refreshSwitch() {
  152. // 判断是否开启验证码
  153. if (this.captchaOpen === 'true') {
  154. // 加载验证码
  155. this.loginCaptcha()
  156. // 加入校验
  157. this.rules.validCode = [required(this.$t('login.validError'), 'blur')]
  158. }
  159. },
  160. // 获取验证码
  161. loginCaptcha() {
  162. loginApi.getPicCaptcha().then((data) => {
  163. this.validCodeBase64 = data.validCodeBase64
  164. this.ruleForm.validCodeReqNo = data.validCodeReqNo
  165. })
  166. },
  167. // 用户名密码登录
  168. async login() {
  169. this.$refs.loginForm.validate().then(async () => {
  170. this.loading = true
  171. const loginData = {
  172. account: this.ruleForm.account,
  173. // 密码进行SM2加密,传输过程中看到的只有密文,后端存储使用hash
  174. password: smCrypto.doSm2Encrypt(this.ruleForm.password),
  175. validCode: this.ruleForm.validCode,
  176. validCodeReqNo: this.ruleForm.validCodeReqNo,
  177. //根据平台不同传不同参0后台(管理员)1老师2学生
  178. eduIdentity : 1
  179. }
  180. // 获取token
  181. try {
  182. const loginToken = await loginApi.login(loginData)
  183. afterLogin(loginToken)
  184. } catch (err) {
  185. this.loading = false
  186. this.loginCaptcha()
  187. }
  188. })
  189. },
  190. configLang(key) {
  191. this.config.lang = key
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="less">
  197. @import 'login';
  198. </style>