login.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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=hmc&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.2.127:8066/oauth/callback",
  302. //uri:"?client_id=mestools&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.128.171:8066/oauth/callback",
  303. // uri:"?client_id=mestools&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.2.135:8066/oauth/callback",
  304. //uri:"?client_id=hmc&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.110.85:8066/oauth/callback",
  305. // uri:"?client_id=hmc&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.110.83:8066/oauth/callback",
  306. // uri:"?client_id=hmc&scope=basic&response_type=code&state=AB1357&redirect_uri=http://172.20.10.5:8066/oauth/callback",
  307. // uri:"?client_id=mestools&scope=basic&response_type=code&state=AB1357&redirect_uri=http://192.168.0.17:8066/oauth/callback",
  308. ...this.loginForm,
  309. tenantID: this.tenantId,
  310. };
  311. // 调用单点登录
  312. ssoLogin(form)
  313. .then((response) => {
  314. this.loading = false;
  315. if (response.code === 200) {
  316. // Message({message: response.msg, type: "success"});
  317. console.log("认证成功!", response);
  318. // response.msg 当前用户唯一标识 跳转其他系统使用
  319. // this.$store.dispatch("setoauthUUID", response.msg);
  320. window.localStorage.setItem(
  321. "setoauthUUID" + this.loginForm.username,
  322. response.msg
  323. );
  324. setTimeout(() => {
  325. global.window.location.href = response.data;
  326. }, 1000);
  327. }
  328. })
  329. .catch(() => {
  330. this.loading = false;
  331. if (this.captchaEnabled) {
  332. this.getCode();
  333. }
  334. });
  335. // this.$store
  336. // .dispatch("Login", form)
  337. // .then(() => {
  338. // changeDatasource(); //切换数据源
  339. // this.$router.push({ path: this.redirect || "/" }).catch(() => {});
  340. // })
  341. // .catch(() => {
  342. // this.loading = false;
  343. // if (this.captchaEnabled) {
  344. // this.getCode();
  345. // }
  346. // });
  347. }
  348. });
  349. },
  350. },
  351. };
  352. </script>
  353. <style rel="stylesheet/scss" lang="scss" scoped>
  354. ::v-deep.el-input--medium .el-input__inner {
  355. height: 54px;
  356. line-height: 54px;
  357. }
  358. .happy2{
  359. height: 624px;
  360. }
  361. .happy1{
  362. height: 540px;
  363. }
  364. .login {
  365. position: relative;
  366. .page-description {
  367. position: absolute;
  368. left: 10%;
  369. top: 50%;
  370. transform: translateY(-100%);
  371. display: flex;
  372. flex-direction: column;
  373. .description {
  374. display: block;
  375. font-size: 38px;
  376. font-weight: 800;
  377. color: #fff;
  378. width: 200px;
  379. display: -webkit-box;
  380. -webkit-box-orient: vertical;
  381. overflow: hidden;
  382. height: 120px;
  383. max-height: 120px;
  384. -webkit-line-clamp: 2;
  385. text-overflow: ellipsis;
  386. }
  387. .sub-description {
  388. font-size: 20px;
  389. color: #fff;
  390. font-weight: 400;
  391. }
  392. }
  393. }
  394. .logg {
  395. margin-top: 42px;
  396. margin-left: 196px;
  397. width: 240px;
  398. height: 54px;
  399. line-height: 54px;
  400. text-align: center;
  401. opacity: 1;
  402. border-radius: 27px;
  403. background: linear-gradient(
  404. 135deg,
  405. rgba(79, 138, 255, 1) 0%,
  406. rgba(75, 94, 255, 1) 100%
  407. );
  408. box-shadow: 0px 4px 16px rgba(179, 192, 231, 1);
  409. color: #fff;
  410. font-size: 20px;
  411. font-weight: 500;
  412. cursor: pointer;
  413. }
  414. .aaa {
  415. width: 248px;
  416. height: 24px;
  417. font-size: 16px !important;
  418. font-weight: 400;
  419. letter-spacing: 0px;
  420. line-height: 24px;
  421. color: rgba(58, 63, 99, 1);
  422. text-align: left;
  423. vertical-align: top;
  424. margin-top: 16px;
  425. }
  426. .bottomtext {
  427. margin-top: -5px !important;
  428. margin-left: 58px !important;
  429. }
  430. .rowww {
  431. width: 522px;
  432. height: 80px;
  433. margin-top: 25px;
  434. margin-left: 55px;
  435. }
  436. .roww {
  437. width: 522px;
  438. height: 80px;
  439. margin-top: 16px;
  440. margin-left: 55px;
  441. }
  442. .ppp {
  443. width: 522px;
  444. height: 24px;
  445. opacity: 1;
  446. /** 文本1 */
  447. font-size: 16px;
  448. font-weight: 400;
  449. letter-spacing: 0px;
  450. line-height: 24px;
  451. color: rgba(58, 63, 99, 1);
  452. text-align: left;
  453. vertical-align: top;
  454. }
  455. .el-input__inner {
  456. width: 522px;
  457. /* height: 54px !important; */
  458. }
  459. .inputt {
  460. /* height: 54px !important; */
  461. border-radius: 4px;
  462. background: rgba(255, 255, 255, 1);
  463. border: 1px solid rgba(218, 224, 242, 1);
  464. margin-top: 2px;
  465. }
  466. .inputt input {
  467. width: 100%;
  468. }
  469. .comlogo {
  470. margin-left: 26px;
  471. margin-top: 49px;
  472. width: 200px;
  473. height: 70px;
  474. background: url(../assets/images/mecos-logo1.jpg);
  475. // background: url(../assets/images/mes412.png); //工联院
  476. /* background: url(../assets/images/comp.png); */
  477. /* box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25); */
  478. opacity: 1;
  479. background-size: cover;
  480. // 工联院 样式
  481. // background-size: contain;
  482. // background-repeat: no-repeat;
  483. // background-position: center;
  484. }
  485. .login {
  486. display: flex;
  487. justify-content: center;
  488. align-items: center;
  489. height: 100%;
  490. background-image: url("../assets/images/background1.jpg");
  491. background-size: 100% 100%;
  492. /* padding-bottom: 55.19%; */
  493. background-position: center;
  494. background-repeat: no-repeat;
  495. }
  496. .title {
  497. width: 258px;
  498. height: 35px;
  499. margin-top: 70px;
  500. margin-left: 8px;
  501. font-size: 22px;
  502. font-weight: 400;
  503. letter-spacing: 2px;
  504. line-height: 38.4px;
  505. /* color: rgba(7, 68, 138, 1); */
  506. color: black;
  507. text-align: left;
  508. vertical-align: top;
  509. float: left;
  510. white-space: nowrap;
  511. overflow: hidden;
  512. text-overflow: ellipsis;
  513. }
  514. .login-form {
  515. margin-left: 44%;
  516. margin-top: 48px;
  517. width: 621px;
  518. //height: 624px;
  519. opacity: 1;
  520. border-radius: 39px;
  521. background: rgba(255, 255, 255, 1);
  522. float: left;
  523. }
  524. .login-code {
  525. width: 40px;
  526. height: 54px;
  527. opacity: 1;
  528. }
  529. .el-col-18 {
  530. width: 66%;
  531. }
  532. </style>