login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="backdrop" :style="{backgroundImage: 'url('+(this.BackgroundImg ? this.BackgroundImg : this.baseImg)+')'}">
  3. <el-container>
  4. <el-header style="display:block;position:relative;margin:auto;">
  5. <!-- logo -->
  6. <img :src="this.logo ? this.logo : this.baseLogo" alt="" class="rightulliimg" />
  7. </el-header>
  8. <el-main>
  9. <!-- 中间部分 -->
  10. <div class="login">
  11. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  12. <el-tabs v-model="activeName" @tab-click="handleClick" style="margin-left: -61px;margin-top:-45px">
  13. <el-tab-pane label="账号密码登录" name="first">
  14. <el-form-item prop="username">
  15. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  16. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item prop="password">
  20. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin" style=" width: 260px; ">
  21. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  22. </el-input>
  23. </el-form-item>
  24. <el-form-item prop="code">
  25. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 53%;" @keyup.enter.native="handleLogin">
  26. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  27. </el-input>
  28. <div class="login-code">
  29. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  30. </div>
  31. </el-form-item>
  32. <el-checkbox v-model="loginForm.rememberMe">记住密码</el-checkbox>
  33. <el-form-item style="width:100%;">
  34. <el-button :loading="loading" size="medium" type="primary" @click.native.prevent="handleLogin" style="width: 190px;border-radius: 50px;margin-left:10%">
  35. <span v-if="!loading">登 录</span>
  36. <span v-else>登 录 中...</span>
  37. </el-button>
  38. </el-form-item>
  39. <el-divider class="divider_left"><span style="font-size:10px;word-break: keep-all;">第三方快捷登录</span></el-divider>
  40. <el-form-item style="width:100%;">
  41. <img :src="wxSrc" @mouseover="changeImg" @mouseleave="returnImg" @click="getWeChatImg" style="width:30px;margin-left: 77px;">
  42. </el-form-item>
  43. </el-tab-pane>
  44. <el-tab-pane label="手机验证码" name="second">
  45. <el-form-item prop="phone">
  46. <el-input v-model="loginForm.phone" type="tel" maxlength="11" auto-complete="off" placeholder="手机号" style=" width: 260px; ">
  47. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  48. </el-input>
  49. </el-form-item>
  50. <el-form-item prop="cade">
  51. <el-input v-model="loginForm.cade" type="text" maxlength="6" auto-complete="off" placeholder="短信验证码" id="" onkeydown="enterHandler(event)" style=" width: 120px; ">
  52. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  53. </el-input>
  54. <el-button :loading="loading" size="min" type="primary" style="width: 120px; margin-left:12px">
  55. <span >获取动态密码 </span>
  56. </el-button>
  57. </el-form-item>
  58. <el-button :loading="loading" size="medium" type="primary" @click.native.prevent="handleLogin" style="width: 190px;border-radius: 50px;margin-left:10%;margin-top:10%">
  59. <span v-if="!loading">登 录</span>
  60. <span v-else>登 录 中...</span>
  61. </el-button>
  62. </el-tab-pane>
  63. </el-tabs>
  64. </el-form>
  65. <!-- 底部 -->
  66. </div>
  67. </el-main>
  68. </el-container>
  69. <el-footer></el-footer>
  70. </div>
  71. </template>
  72. <script>
  73. import { getCodeImg, listSscDomain } from "@/api/login";
  74. import { wxImg } from "@/api/system/weChat";
  75. import Cookies from "js-cookie";
  76. import { encrypt, decrypt } from "@/utils/jsencrypt";
  77. export default {
  78. name: "Login",
  79. data() {
  80. return {
  81. //默认背景图
  82. activeName: "first",
  83. baseImg: require('../assets/images/logi_bg1.jpg'),
  84. BackgroundImg : require('../assets/images/logi_bg1.jpg'),
  85. logo: '',
  86. baseLogo: require('../assets/images/lgo.png'),
  87. codeUrl: "",
  88. cookiePassword: "",
  89. loginForm: {
  90. username: "",
  91. password: "",
  92. phone: "",
  93. rememberMe: false,
  94. code: "",
  95. cade: "",
  96. uuid: "",
  97. },
  98. loginRules: {
  99. username: [
  100. {
  101. required: true,
  102. trigger: "blur",
  103. message: "用户名不能为空",
  104. },
  105. ],
  106. // phone: [
  107. // {
  108. // required: true,
  109. // trigger: "blur",
  110. // message: "手机号不能为空",
  111. // },
  112. // ],
  113. code: [
  114. {
  115. required: true,
  116. trigger: "change",
  117. message: "验证码不能为空",
  118. },
  119. ],
  120. // cade: [
  121. // {
  122. // required: true,
  123. // trigger: "change",
  124. // message: "验证码不能为空",
  125. // },
  126. // ],
  127. },
  128. loading: false,
  129. redirect: undefined,
  130. wxSrc: require("../assets/images/wx1.png"),
  131. };
  132. },
  133. watch: {
  134. $route: {
  135. handler: function (route) {
  136. this.redirect = route.query && route.query.redirect;
  137. },
  138. immediate: true,
  139. },
  140. },
  141. created() {
  142. this.getCode();
  143. this.getCookie();
  144. this.getlistDomain();
  145. },
  146. methods: {
  147. changeImg(){
  148. this.wxSrc = require("../assets/images/wx.png")
  149. },
  150. returnImg(){
  151. this.wxSrc = require("../assets/images/wx1.png")
  152. },
  153. getCode() {
  154. getCodeImg().then((res) => {
  155. this.codeUrl = "data:image/gif;base64," + res.img;
  156. this.loginForm.uuid = res.uuid;
  157. });
  158. },
  159. getCookie() {
  160. const username = Cookies.get("username");
  161. const password = Cookies.get("password");
  162. const rememberMe = Cookies.get("rememberMe");
  163. this.loginForm = {
  164. username:
  165. username === undefined ? this.loginForm.username : username,
  166. password:
  167. password === undefined
  168. ? this.loginForm.password
  169. : decrypt(password),
  170. rememberMe:
  171. rememberMe === undefined ? false : Boolean(rememberMe),
  172. };
  173. },
  174. // 查询域名
  175. getlistDomain() {
  176. var sscDomain = document.location.hostname;
  177. this.loginForm.sscDomain = document.location.hostname;
  178. listSscDomain(sscDomain).then(response => {
  179. if(response && response.data.lenth > 0){
  180. const sscConfig = response.data[0].sscConfig;
  181. const companyId = response.data[0].sscCompanyId;
  182. console.log(companyId)
  183. const imgForm = JSON.parse(sscConfig);
  184. if(imgForm){
  185. this.BackgroundImg = imgForm.BackgroundImg;
  186. this.logo = imgForm.logo;
  187. }
  188. console.log(this.logo)
  189. }
  190. });
  191. },
  192. handleLogin() {
  193. this.$refs.loginForm.validate((valid) => {
  194. if (valid) {
  195. this.loading = true;
  196. if (this.loginForm.rememberMe) {
  197. Cookies.set("username", this.loginForm.username, {
  198. expires: 30,
  199. });
  200. Cookies.set(
  201. "password",
  202. encrypt(this.loginForm.password),
  203. { expires: 30 }
  204. );
  205. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  206. expires: 30,
  207. });
  208. } else {
  209. Cookies.remove("username");
  210. Cookies.remove("password");
  211. Cookies.remove("rememberMe");
  212. }
  213. this.$store
  214. .dispatch("Login", this.loginForm)
  215. .then(() => {
  216. if(this.redirect == '/index'){
  217. this.$router.push({ path: "/homePage"+this.redirect || "/" });
  218. }else{
  219. this.$router.push({ path: this.redirect || "/" });
  220. }
  221. })
  222. .catch(() => {
  223. this.loading = false;
  224. this.getCode();
  225. });
  226. }
  227. });
  228. },
  229. getUrlKey(name) {
  230. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  231. },
  232. getWeChatImg(){
  233. const origin = document.location.origin.toString();
  234. let params = {}
  235. params.state = origin
  236. wxImg(params).then((res) => {
  237. // console.log(res)
  238. location.href = res
  239. })
  240. },
  241. },
  242. };
  243. </script>
  244. <style rel="stylesheet/scss" lang="scss">
  245. .login {
  246. display: flex;
  247. justify-content: center;
  248. align-items: center;
  249. height: 100%;
  250. background-size: cover;
  251. }
  252. // 中间背景图
  253. .login-form {
  254. border-radius: 6px;
  255. width: 935px;
  256. height: 434px;
  257. padding: 73px 138px 103px 597px;
  258. background-image: url("../assets/images/login_bg2.png");
  259. background-size: 935px 434px;
  260. background-repeat: no-repeat;
  261. margin-top: 40px;
  262. // 输入框大小
  263. .el-input {
  264. height: 40px;
  265. width: 100%;
  266. input {
  267. height: 40px;
  268. width: 100%;
  269. }
  270. }
  271. .input-icon {
  272. height: 39px;
  273. width: 14px;
  274. margin-left: 2px;
  275. }
  276. }
  277. .login-tip {
  278. font-size: 13px;
  279. text-align: center;
  280. }
  281. // 验证码
  282. .login-code {
  283. width: 33%;
  284. height: 38px;
  285. float: right;
  286. margin-right: 6%;
  287. img {
  288. cursor: pointer;
  289. vertical-align: middle;
  290. }
  291. }
  292. .login-code-img {
  293. height: 38px;
  294. }
  295. // 大背景图
  296. .backdrop {
  297. background-repeat: no-repeat;
  298. background-size: 1536px 752px;
  299. background-size: cover;
  300. width: 100%;
  301. height: 100%;
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. background-position: right top;
  306. background-attachment: fixed;
  307. }
  308. .rightulliimg{
  309. width: 860px;
  310. }
  311. .divider_left{
  312. margin-left: -40px;
  313. }
  314. </style>