综合办公系统
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

login.vue 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2024-01-03 09:23:11
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2024-03-05 17:52:02
  6. -->
  7. <template>
  8. <el-row class="login-wrapper">
  9. <el-col :xs="0" class="login-bg">
  10. <div class="logo-title">
  11. <div class="logo-img"></div>
  12. <div class="logo-text">四川中水成勘院测绘工程有限责任公司</div>
  13. </div>
  14. </el-col>
  15. <el-col :xs="18" class="login-box">
  16. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  17. <h3 class="title">CMC综合办公系统</h3>
  18. <el-form-item prop="username">
  19. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  20. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
  25. @keyup.enter.native="handleLogin">
  26. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  27. </el-input>
  28. </el-form-item>
  29. <!-- <el-form-item prop="code" v-if="captchaEnabled">
  30. <el-input
  31. v-model="loginForm.code"
  32. auto-complete="off"
  33. placeholder="验证码"
  34. style="width: 63%"
  35. @keyup.enter.native="handleLogin"
  36. >
  37. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  38. </el-input>
  39. <div class="login-code">
  40. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  41. </div>
  42. </el-form-item> -->
  43. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  44. <el-form-item style="width:100%;">
  45. <el-button :loading="loading" size="medium" type="primary" style="width:100%;border-radius: 30px;box-shadow: 0 5px 10px rgba(0,0,0,0.3);"
  46. @click.native.prevent="handleLogin">
  47. <span v-if="!loading">登 录</span>
  48. <span v-else>登 录 中...</span>
  49. </el-button>
  50. <div style="float: right;" v-if="register">
  51. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  52. </div>
  53. </el-form-item>
  54. </el-form>
  55. <!-- <div class="el-login-footer">
  56. <span>Copyright © 2023-2024 四川中水成勘院测绘工程有限责任公司 All Rights Reserved.</span>
  57. </div> -->
  58. </el-col>
  59. </el-row>
  60. </template>
  61. <script>
  62. import { getCodeImg } from "@/api/login";
  63. import Cookies from "js-cookie";
  64. import { encrypt, decrypt } from '@/utils/jsencrypt'
  65. export default {
  66. name: "Login",
  67. data() {
  68. return {
  69. codeUrl: "",
  70. loginForm: {
  71. username: "admin",
  72. password: "admin123",
  73. rememberMe: false,
  74. code: "",
  75. uuid: ""
  76. },
  77. loginRules: {
  78. username: [
  79. { required: true, trigger: "blur", message: "请输入您的账号" }
  80. ],
  81. password: [
  82. { required: true, trigger: "blur", message: "请输入您的密码" }
  83. ],
  84. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  85. },
  86. loading: false,
  87. // 验证码开关
  88. captchaEnabled: true,
  89. // 注册开关
  90. register: false,
  91. redirect: undefined
  92. };
  93. },
  94. watch: {
  95. $route: {
  96. handler: function (route) {
  97. this.redirect = route.query && route.query.redirect;
  98. },
  99. immediate: true
  100. }
  101. },
  102. created() {
  103. // this.getCode();
  104. this.getCookie();
  105. },
  106. methods: {
  107. getCode() {
  108. getCodeImg().then(res => {
  109. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  110. if (this.captchaEnabled) {
  111. this.codeUrl = "data:image/gif;base64," + res.img;
  112. this.loginForm.uuid = res.uuid;
  113. }
  114. });
  115. },
  116. getCookie() {
  117. const username = Cookies.get("username");
  118. const password = Cookies.get("password");
  119. const rememberMe = Cookies.get('rememberMe')
  120. this.loginForm = {
  121. username: username === undefined ? this.loginForm.username : username,
  122. password: password === undefined ? this.loginForm.password : decrypt(password),
  123. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  124. };
  125. },
  126. handleLogin() {
  127. this.$refs.loginForm.validate(valid => {
  128. if (valid) {
  129. this.loading = true;
  130. if (this.loginForm.rememberMe) {
  131. Cookies.set("username", this.loginForm.username, { expires: 30 });
  132. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  133. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  134. } else {
  135. Cookies.remove("username");
  136. Cookies.remove("password");
  137. Cookies.remove('rememberMe');
  138. }
  139. this.$store.dispatch("Login", this.loginForm).then(() => {
  140. this.$router.push({ path: this.redirect || "/" }).catch(() => { });
  141. }).catch(() => {
  142. this.loading = false;
  143. if (this.captchaEnabled) {
  144. this.getCode();
  145. }
  146. });
  147. }
  148. });
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .login-wrapper {
  155. width: 100%;
  156. height: 100vh;
  157. display: flex;
  158. .login-bg {
  159. flex: 1.8;
  160. min-width: 0%;
  161. background: url('../assets/images/xizang02.jpg') no-repeat;
  162. position: relative;
  163. }
  164. // .login-bg::after {
  165. // content: '';
  166. // position: absolute;
  167. // left: 0;
  168. // top: 0;
  169. // width: 100%;
  170. // height: 100%;
  171. // background-color: rgba($color: #2144b4, $alpha: 0.3);
  172. // }
  173. .login-box {
  174. flex: 1.5;
  175. min-width: 45%;
  176. position: relative;
  177. }
  178. .login-box::before {
  179. content: '';
  180. position: absolute;
  181. top: 0;
  182. left: -166px;
  183. width: 100%;
  184. height: 100%;
  185. background-color: #fff;
  186. transform: skew(-15deg);
  187. transform-origin: 0;
  188. }
  189. }
  190. .login-form {
  191. position: absolute;
  192. top: 50%;
  193. left: 50%;
  194. transform: translate(-50%, -55%);
  195. width: 380px;
  196. height: 500px;
  197. padding: 0 20px;
  198. .title {
  199. font-size: 40px;
  200. margin-bottom: 40px;
  201. color: #504d4d;
  202. font-family: 'CMCTitle';
  203. }
  204. .el-login-footer {
  205. position: absolute;
  206. left: 50%;
  207. bottom: 10px;
  208. transform: translate(-50%, -0%);
  209. height: 40px;
  210. line-height: 40px;
  211. position: fixed;
  212. bottom: 0;
  213. text-align: center;
  214. color: #2e9de7;
  215. font-family: Arial;
  216. font-size: 12px;
  217. letter-spacing: 1px;
  218. }
  219. }
  220. .login-bg {
  221. .logo-title {
  222. z-index: 999;
  223. vertical-align: middle;
  224. display: flex;
  225. align-items: center;
  226. padding-top: 20px;
  227. padding-left: 20px;
  228. .logo-img{
  229. background: url('~@/assets/images/logo.png')no-repeat;
  230. background-size: 100% 100%;
  231. width: 74px;
  232. height: 64px;
  233. }
  234. .logo-text{
  235. padding-left: 10px;
  236. color: #fff;
  237. font-weight: bold;
  238. font-size: 25px;
  239. }
  240. }
  241. }
  242. </style>