login.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <div class="login">
  3. <div class="page-description" v-if="config.pageDescription">
  4. <span class="description" v-html="config.pageDescription"> </span>
  5. <span class="sub-description"> 登录并开始管理您的智能引擎账户 </span>
  6. </div>
  7. <el-form
  8. ref="loginForm"
  9. :model="loginForm"
  10. :rules="loginRules"
  11. class="login-form"
  12. :class="formHeightClass"
  13. >
  14. <el-row>
  15. <el-col :span="12" class="comlogo"></el-col>
  16. <el-col :span="12">
  17. <div class="grid-content bg-purple-dark title">
  18. <!-- 铨一生产协同管理系统-->
  19. 生产协同管理系统
  20. <!-- · 智能制造平台 -->
  21. </div>
  22. </el-col>
  23. </el-row>
  24. <el-row class="rowww">
  25. <el-col :span="12" class="text" prop="username">用户名</el-col>
  26. <el-input
  27. v-model="loginForm.username"
  28. type="text"
  29. auto-complete="off"
  30. placeholder="账号"
  31. class="inputt"
  32. />
  33. </el-row>
  34. <el-row class="roww">
  35. <el-col :span="12" class="text" prop="password">密码</el-col>
  36. <el-input
  37. v-model="loginForm.password"
  38. type="password"
  39. auto-complete="off"
  40. placeholder="密码"
  41. @keyup.enter.native="handleLogin"
  42. show-password
  43. class="inputt"
  44. >
  45. </el-input>
  46. </el-row>
  47. <el-row class="roww" v-if="this.loginForm.isYanMa=='yes'">
  48. <el-row>
  49. <el-col class="text" prop="code">验证码</el-col>
  50. </el-row>
  51. <el-row>
  52. <el-col :span="18">
  53. <el-input
  54. v-model="loginForm.code"
  55. auto-complete="off"
  56. placeholder="验证码"
  57. @keyup.enter.native="handleLogin"
  58. class="inputt"
  59. >
  60. </el-input>
  61. </el-col>
  62. <el-col :span="4" :offset="1">
  63. <div class="login-code">
  64. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  65. </div>
  66. </el-col>
  67. </el-row>
  68. </el-row>
  69. <el-row class="bottomtext">
  70. <!-- <div class="login-code">
  71. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  72. </div> -->
  73. <el-checkbox v-model="loginForm.rememberMe" class="aaa"
  74. >在这个设备上记住我
  75. </el-checkbox>
  76. </el-row>
  77. <el-row>
  78. <el-col
  79. class="logg"
  80. :loading="loading"
  81. @click.native.prevent="handleLogin"
  82. >登录
  83. </el-col>
  84. </el-row>
  85. </el-form>
  86. </div>
  87. </template>
  88. <script>
  89. import { getCodeImg, isTenantExist, ssoLogin } from "@/api/login";
  90. import { changeDatasource } from "@/api/dataEngine";
  91. import Cookies from "js-cookie";
  92. import { encrypt, decrypt } from "@/utils/jsencrypt";
  93. export default {
  94. name: "Login",
  95. data() {
  96. return {
  97. codeUrl: "",
  98. tenantId: "",
  99. loginForm: {
  100. tenantCode: "", //租户编号
  101. username: "",
  102. password: "",
  103. // username: "admin",
  104. // password: "admin123",
  105. rememberMe: false,
  106. code: "",
  107. uuid: "",
  108. tenantID: "",
  109. isYanMa:"",
  110. },
  111. formHeightClass: 'happy2', // 初始类名
  112. loginRules: {
  113. username: [
  114. {required: true, trigger: "blur", message: "请输入您的账号"},
  115. ],
  116. password: [
  117. {required: true, trigger: "blur", message: "请输入您的密码"},
  118. ],
  119. code: [{required: true, trigger: "blur", message: "请输入验证码"}],
  120. },
  121. loading: true,
  122. // 验证码开关
  123. captchaEnabled: false,
  124. // 注册开关
  125. register: false,
  126. redirect: undefined,
  127. // 页面配置数据
  128. config: {},
  129. };
  130. },
  131. watch: {
  132. $route: {
  133. handler: function (route) {
  134. this.redirect = route.query && route.query.redirect;
  135. },
  136. immediate: true,
  137. },
  138. 'loginForm.isYanMa': {
  139. handler(newVal) {
  140. console.log('isYanMa changed:', newVal);
  141. // 可以在这里执行一些额外的操作
  142. if(newVal=="yes"){
  143. this.formHeightClass="happy2"
  144. }else {
  145. this.formHeightClass="happy1"
  146. console.log("hmc")
  147. }
  148. },
  149. immediate: true, // 立即触发一次
  150. deep: true
  151. }
  152. },
  153. created() {
  154. this.validateTenantId();
  155. },
  156. computed: {
  157. },
  158. methods: {
  159. // client_id=x3qwrgrO1wYdz72joZ8YyIuD&scope=basic&response_type=code&state=AB1357&redirect_uri=http://127.0.0.1:8001/login
  160. // 校验url
  161. validateTenantId() {
  162. let tenantCode = this.$route.query["tenantCode"];
  163. if (tenantCode != null) {
  164. // 得到tenantId 查询裤中是否存在该租户
  165. isTenantExist({tenantCode: tenantCode}).then((res) => {
  166. if (res == undefined) {
  167. this.$message.warning("请访问正确地址!");
  168. this.$router.push({path: "/401"});
  169. } else if (res.data?.tenantId) {
  170. // 判断当前编号是否存在库中
  171. this.tenantId = res.data.tenantId;
  172. this.loginForm.tenantID = this.tenantId;
  173. if (res.data.loginPageConfiguration != null) {
  174. // 得到租户的信息
  175. this.config = res.data.loginPageConfiguration;
  176. this.setConfig();
  177. }
  178. this.getCode();
  179. this.getCookie();
  180. } else {
  181. // 当前访问链接中的租户编号不存在
  182. this.$router.push({ path: "/401" });
  183. }
  184. });
  185. } else {
  186. this.$router.push({ path: "/401" });
  187. }
  188. },
  189. setConfig() {
  190. let {
  191. loginPageTitle,
  192. loginPageDescription,
  193. loginPageLogo,
  194. loginPageBackgroundImage,
  195. windowTitle,
  196. windowLogo,
  197. } = this.config;
  198. // 设置背景图
  199. if (loginPageBackgroundImage) {
  200. let loginBgDom = document.getElementsByClassName("login");
  201. if (loginBgDom.length > 0) {
  202. loginBgDom[0].style.backgroundImage = `url(${
  203. process.env.VUE_APP_BASE_IMG_API + loginPageBackgroundImage
  204. })`;
  205. console.log(
  206. "" +
  207. `url(${
  208. process.env.VUE_APP_BASE_IMG_API + loginPageBackgroundImage
  209. })`
  210. );
  211. }
  212. }
  213. // 设置logo
  214. if (loginPageLogo) {
  215. let loginLogoDom = document.getElementsByClassName("comlogo");
  216. if (loginLogoDom.length > 0) {
  217. loginLogoDom[0].style.backgroundImage = `url(${
  218. process.env.VUE_APP_BASE_IMG_API + loginPageLogo
  219. })`;
  220. }
  221. window.sessionStorage.setItem("logo", loginPageLogo);
  222. }
  223. // 设置title
  224. if (loginPageTitle) {
  225. let titleDom = document.getElementsByClassName("title");
  226. console.log(titleDom);
  227. if (titleDom.length > 0) {
  228. titleDom[0].innerHTML = loginPageTitle;
  229. }
  230. window.sessionStorage.setItem("title", loginPageTitle);
  231. }
  232. // 设置meta信息
  233. if (windowTitle) {
  234. document.title = windowTitle;
  235. console.dir(document);
  236. }
  237. // 设置页面描述
  238. if (loginPageDescription) {
  239. this.config.pageDescription = loginPageDescription;
  240. }
  241. // 更换favicon.ico
  242. // if (windowLogo) {
  243. // // let url = process.env.VUE_APP_BASE_API + windowLogo;
  244. // let url = "@/assets/images/favicon1.ico";
  245. // console.log(url);
  246. // var link = document.createElement("link"),
  247. // oldLink = document.getElementById("dynamic-favicon");
  248. // link.id = "dynamic-favicon";
  249. // link.rel = "shortcut icon";
  250. // link.href = url;
  251. // if (oldLink) {
  252. // document.head.removeChild(oldLink);
  253. // }
  254. // document.head.appendChild(link);
  255. // }
  256. },
  257. getCode() {
  258. getCodeImg().then((res) => {
  259. this.captchaEnabled =
  260. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  261. if (this.captchaEnabled) {
  262. this.codeUrl = "data:image/gif;base64," + res.img;
  263. this.loginForm.uuid = res.uuid;
  264. this.$set(this.loginForm, 'isYanMa', 'yes'); // 使用 this.$set
  265. console.log("设置是否显示验证码")
  266. }else {
  267. console.log("设置是否显示验证码")
  268. this.$set(this.loginForm, 'isYanMa', 'no'); // 使用 this.$set
  269. }
  270. });
  271. },
  272. getCookie() {
  273. const username = Cookies.get("username");
  274. const password = Cookies.get("password");
  275. const rememberMe = Cookies.get("rememberMe");
  276. this.loginForm = {
  277. username: username === undefined ? this.loginForm.username : username,
  278. password:
  279. password === undefined ? this.loginForm.password : decrypt(password),
  280. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  281. };
  282. },
  283. handleLogin() {
  284. this.$refs.loginForm.validate((valid) => {
  285. if (valid) {
  286. this.loading = true;
  287. if (this.loginForm.rememberMe) {
  288. Cookies.set("username", this.loginForm.username, { expires: 30 });
  289. Cookies.set("password", encrypt(this.loginForm.password), {
  290. expires: 30,
  291. });
  292. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  293. expires: 30,
  294. });
  295. } else {
  296. Cookies.remove("username");
  297. Cookies.remove("password");
  298. Cookies.remove("rememberMe");
  299. }
  300. let form = {
  301. // uri:"?client_id=mestools&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.128.171:8066/oauth/callback",//实验室
  302. // uri:"?client_id=mestools&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.2.135:8066/oauth/callback",//铨一
  303. // uri:"?client_id=mestools&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.3.17:8066/oauth/callback",//化纤
  304. uri:"?client_id=hmc&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.10.6:8066/oauth/callback",//hmc
  305. //uri:"?client_id=hmc&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.110.182:8066/oauth/callback",//lth
  306. ...this.loginForm,
  307. tenantID: this.tenantId,
  308. };
  309. // 调用单点登录
  310. ssoLogin(form)
  311. .then((response) => {
  312. this.loading = false;
  313. if (response.code === 200) {
  314. // Message({message: response.msg, type: "success"});
  315. console.log("认证成功!", response);
  316. // response.msg 当前用户唯一标识 跳转其他系统使用
  317. // this.$store.dispatch("setoauthUUID", response.msg);
  318. window.localStorage.setItem(
  319. "setoauthUUID" + this.loginForm.username,
  320. response.msg
  321. );
  322. setTimeout(() => {
  323. global.window.location.href = response.data;
  324. }, 1000);
  325. }
  326. })
  327. .catch(() => {
  328. this.loading = false;
  329. if (this.captchaEnabled) {
  330. this.getCode();
  331. }
  332. });
  333. // this.$store
  334. // .dispatch("Login", form)
  335. // .then(() => {
  336. // changeDatasource(); //切换数据源
  337. // this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  338. // })
  339. // .catch(() => {
  340. // this.loading = false;
  341. // if (this.captchaEnabled) {
  342. // this.getCode();
  343. // }
  344. // });
  345. }
  346. });
  347. },
  348. },
  349. };
  350. </script>
  351. <style rel="stylesheet/scss" lang="scss" scoped>
  352. ::v-deep.el-input--medium .el-input__inner {
  353. height: 54px;
  354. line-height: 54px;
  355. }
  356. .happy2{
  357. height: 624px;
  358. }
  359. .happy1{
  360. height: 540px;
  361. }
  362. .login {
  363. position: relative;
  364. .page-description {
  365. position: absolute;
  366. left: 10%;
  367. top: 50%;
  368. transform: translateY(-100%);
  369. display: flex;
  370. flex-direction: column;
  371. .description {
  372. display: block;
  373. font-size: 38px;
  374. font-weight: 800;
  375. color: #fff;
  376. width: 200px;
  377. display: -webkit-box;
  378. -webkit-box-orient: vertical;
  379. overflow: hidden;
  380. height: 120px;
  381. max-height: 120px;
  382. -webkit-line-clamp: 2;
  383. text-overflow: ellipsis;
  384. }
  385. .sub-description {
  386. font-size: 20px;
  387. color: #fff;
  388. font-weight: 400;
  389. }
  390. }
  391. }
  392. .logg {
  393. margin-top: 42px;
  394. margin-left: 196px;
  395. width: 240px;
  396. height: 54px;
  397. line-height: 54px;
  398. text-align: center;
  399. opacity: 1;
  400. border-radius: 27px;
  401. background: linear-gradient(
  402. 135deg,
  403. rgba(79, 138, 255, 1) 0%,
  404. rgba(75, 94, 255, 1) 100%
  405. );
  406. box-shadow: 0px 4px 16px rgba(179, 192, 231, 1);
  407. color: #fff;
  408. font-size: 20px;
  409. font-weight: 500;
  410. cursor: pointer;
  411. }
  412. .aaa {
  413. width: 248px;
  414. height: 24px;
  415. font-size: 16px !important;
  416. font-weight: 400;
  417. letter-spacing: 0px;
  418. line-height: 24px;
  419. color: rgba(58, 63, 99, 1);
  420. text-align: left;
  421. vertical-align: top;
  422. margin-top: 16px;
  423. }
  424. .bottomtext {
  425. margin-top: -5px !important;
  426. margin-left: 58px !important;
  427. }
  428. .rowww {
  429. width: 522px;
  430. height: 80px;
  431. margin-top: 25px;
  432. margin-left: 55px;
  433. }
  434. .roww {
  435. width: 522px;
  436. height: 80px;
  437. margin-top: 16px;
  438. margin-left: 55px;
  439. }
  440. .ppp {
  441. width: 522px;
  442. height: 24px;
  443. opacity: 1;
  444. /** 文本1 */
  445. font-size: 16px;
  446. font-weight: 400;
  447. letter-spacing: 0px;
  448. line-height: 24px;
  449. color: rgba(58, 63, 99, 1);
  450. text-align: left;
  451. vertical-align: top;
  452. }
  453. .el-input__inner {
  454. width: 522px;
  455. /* height: 54px !important; */
  456. }
  457. .inputt {
  458. /* height: 54px !important; */
  459. border-radius: 4px;
  460. background: rgba(255, 255, 255, 1);
  461. border: 1px solid rgba(218, 224, 242, 1);
  462. margin-top: 2px;
  463. }
  464. .inputt input {
  465. width: 100%;
  466. }
  467. .comlogo {
  468. margin-left: 26px;
  469. margin-top: 49px;
  470. width: 200px;
  471. height: 70px;
  472. background: url(../assets/images/mecos-logo1.jpg);
  473. // background: url(../assets/images/mes412.png); //工联院
  474. /* background: url(../assets/images/comp.png); */
  475. /* box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25); */
  476. opacity: 1;
  477. background-size: cover;
  478. // 工联院 样式
  479. // background-size: contain;
  480. // background-repeat: no-repeat;
  481. // background-position: center;
  482. }
  483. .login {
  484. display: flex;
  485. justify-content: center;
  486. align-items: center;
  487. height: 100%;
  488. background-image: url("../assets/images/background1.jpg");
  489. background-size: 100% 100%;
  490. /* padding-bottom: 55.19%; */
  491. background-position: center;
  492. background-repeat: no-repeat;
  493. }
  494. .title {
  495. width: 258px;
  496. height: 35px;
  497. margin-top: 70px;
  498. margin-left: 8px;
  499. font-size: 22px;
  500. font-weight: 400;
  501. letter-spacing: 2px;
  502. line-height: 38.4px;
  503. /* color: rgba(7, 68, 138, 1); */
  504. color: black;
  505. text-align: left;
  506. vertical-align: top;
  507. float: left;
  508. white-space: nowrap;
  509. overflow: hidden;
  510. text-overflow: ellipsis;
  511. }
  512. .login-form {
  513. margin-left: 44%;
  514. margin-top: 48px;
  515. width: 621px;
  516. //height: 624px;
  517. opacity: 1;
  518. border-radius: 39px;
  519. background: rgba(255, 255, 255, 1);
  520. float: left;
  521. }
  522. .login-code {
  523. width: 40px;
  524. height: 54px;
  525. opacity: 1;
  526. }
  527. .el-col-18 {
  528. width: 66%;
  529. }
  530. </style>