You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div class="site-wrapper site-page--login">
  3. <div style="display: flex;height: 100vh">
  4. <div class="login-bg"></div>
  5. <div style="width: 35%">
  6. <div style="height: 27vh;">
  7. <div style="text-align: right;padding: 0px 20px">
  8. <img width="60%" height="72" style="object-fit: contain" src="~@/assets/img/ckp.png">
  9. </div>
  10. </div>
  11. <div style="padding: 30px 130px">
  12. <h3 class="login-title">用户登陆</h3>
  13. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" status-icon>
  14. <el-form-item prop="userName">
  15. <el-input v-model="dataForm.userName" placeholder="帐号" size="large"></el-input>
  16. </el-form-item>
  17. <el-form-item prop="password" style="margin-top: 20px">
  18. <el-input v-model="dataForm.password" type="password" placeholder="密码" size="large"></el-input>
  19. </el-form-item>
  20. <el-form-item style="margin-top: 20px">
  21. <el-button style="width: 100%" type="primary" @click="dataFormSubmit()">登录</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import {getConfigParams} from '@/api/sysConfig.js'
  31. import { getUUID } from '@/utils'
  32. export default {
  33. data () {
  34. return {
  35. src: 'http://127.0.0.1/upload/ifs.png',
  36. dataForm: {
  37. userName: '',
  38. password: '',
  39. uuid: '',
  40. captcha: ''
  41. },
  42. dataRule: {
  43. userName: [
  44. { required: true, message: '帐号不能为空', trigger: 'blur' }
  45. ],
  46. password: [
  47. { required: true, message: '密码不能为空', trigger: 'blur' }
  48. ]
  49. },
  50. captchaPath: ''
  51. }
  52. },
  53. computed: {
  54. multiLanguage: {
  55. get() {
  56. return this.$store.state.user.multiLanguage
  57. },
  58. set(val) {
  59. this.$store.commit('user/updateMultiLanguage', val)
  60. }
  61. },
  62. authControl: {
  63. get() {
  64. return this.$store.state.user.authControl
  65. },
  66. set(val) {
  67. this.$store.commit('user/updateAuthControl', val)
  68. }
  69. }
  70. },
  71. mounted() {
  72. // 仅当 redirectPath 为空时设置
  73. const redirectPath = this.$route.query.redirect || '/home';
  74. if (!localStorage.getItem('redirectPath')) {
  75. localStorage.setItem('redirectPath', redirectPath);
  76. }
  77. },
  78. created () {
  79. this.userName();
  80. // 如果 redirectPath 已经存在,不要覆盖它
  81. const currentPath = localStorage.getItem('redirectPath');
  82. if (!currentPath) {
  83. localStorage.setItem('redirectPath', this.$route.fullPath);
  84. }
  85. },
  86. methods: {
  87. // 获取上次登陆的用户名
  88. userName(){
  89. this.dataForm.userName = localStorage.getItem('userName')
  90. },
  91. // 提交表单
  92. dataFormSubmit () {
  93. this.$refs['dataForm'].validate((valid) => {
  94. if (valid) {
  95. this.$http({
  96. url: this.$http.adornUrl('/sys/login'),
  97. method: 'post',
  98. data: this.$http.adornData({
  99. 'username': this.dataForm.userName,
  100. 'password': this.dataForm.password,
  101. 'uuid': this.dataForm.uuid
  102. })
  103. }).then(({data}) => {
  104. if (data && data.code === 0) {
  105. console.log('跳转前路径:', localStorage.getItem('redirectPath')); // 检查路径是否正确
  106. this.$cookie.set('token', data.token)
  107. // 动态跳转逻辑
  108. const redirectPath = localStorage.getItem('redirectPath') || '';
  109. // 设置需要判断的路径
  110. const pathsToRedirect = ['/auth-authQuote', '/auth-authInquiry'];
  111. if (pathsToRedirect.some(path => redirectPath.indexOf(path) !== -1)) {
  112. this.$router.replace(redirectPath);
  113. } else {
  114. this.$router.replace({ name: 'home' });
  115. }
  116. console.log('Redirecting to:', redirectPath); // 调试输出
  117. this.$i18n.locale=data.language
  118. localStorage.setItem('locale', data.language)
  119. localStorage.setItem('refresh', "0")
  120. localStorage.setItem('userName', this.dataForm.userName)
  121. this.getConfigParams()
  122. } else {
  123. this.$message.error(data.msg)
  124. }
  125. })
  126. }
  127. })
  128. },
  129. // 获取全局参数变量
  130. getConfigParams() {
  131. getConfigParams().then(({data}) => {
  132. if (data && data.code == 0) {
  133. localStorage.setItem('configParams', JSON.stringify(data.data))
  134. // this.multiLanguage = JSON.parse(localStorage.getItem('configParams')).multiLanguage
  135. // this.authControl = JSON.parse(localStorage.getItem('configParams')).authControl
  136. }
  137. })
  138. },
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .site-wrapper.site-page--login {
  144. .login-title {
  145. font-size: 30px;
  146. }
  147. .login-main .el-input__inner{
  148. margin-top: 10px;
  149. height: 45px;
  150. }
  151. .el-button--medium {
  152. margin-top: 0px;
  153. padding: 5px 11px;
  154. font-size: 16px;
  155. border-radius: 4px;
  156. }
  157. .el-form-item {
  158. margin-bottom: 5px;
  159. }
  160. }
  161. .login-bg{
  162. background-image: url(~@/assets/img/login_bg.jpg);
  163. background-size: cover;
  164. width: 65%;
  165. }
  166. </style>