login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. >
  13. <el-row>
  14. <el-col :span="12" class="comlogo"></el-col>
  15. <el-col :span="12">
  16. <div class="grid-content bg-purple-dark title">
  17. 工业应用操作系统
  18. <!-- 智能制造平台 -->
  19. </div>
  20. </el-col
  21. >
  22. </el-row>
  23. <el-row class="rowww">
  24. <el-col :span="12" class="text" prop="username">用户名</el-col>
  25. <el-input
  26. v-model="loginForm.username"
  27. type="text"
  28. auto-complete="off"
  29. placeholder="账号"
  30. class="inputt"
  31. />
  32. </el-row>
  33. <el-row class="roww">
  34. <el-col :span="12" class="text" prop="password">密码</el-col>
  35. <el-input
  36. v-model="loginForm.password"
  37. type="password"
  38. auto-complete="off"
  39. placeholder="密码"
  40. @keyup.enter.native="handleLogin"
  41. show-password
  42. class="inputt"
  43. >
  44. </el-input>
  45. </el-row>
  46. <el-row class="roww">
  47. <el-row>
  48. <el-col class="text" prop="code">验证码</el-col>
  49. </el-row>
  50. <el-row>
  51. <el-col :span="18">
  52. <el-input
  53. v-model="loginForm.code"
  54. auto-complete="off"
  55. placeholder="验证码"
  56. @keyup.enter.native="handleLogin"
  57. class="inputt"
  58. >
  59. </el-input>
  60. </el-col>
  61. <el-col :span="4" :offset="1">
  62. <div class="login-code">
  63. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  64. </div>
  65. </el-col>
  66. </el-row>
  67. </el-row>
  68. <el-row class="bottomtext">
  69. <!-- <div class="login-code">
  70. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  71. </div> -->
  72. <el-checkbox v-model="loginForm.rememberMe" class="aaa"
  73. >在这个设备上记住我
  74. </el-checkbox
  75. >
  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. >
  85. </el-row>
  86. </el-form>
  87. </div>
  88. </template>
  89. <script>
  90. import {getCodeImg, isTenantExist} from "@/api/login";
  91. import {changeDatasource} from "@/api/dataEngine";
  92. import Cookies from "js-cookie";
  93. import {encrypt, decrypt} from "@/utils/jsencrypt";
  94. export default {
  95. name: "Login",
  96. data() {
  97. return {
  98. codeUrl: "",
  99. tenantId: "",
  100. loginForm: {
  101. tenantCode: "", //租户编号
  102. username: "",
  103. password: "",
  104. // username: "admin",
  105. // password: "admin123",
  106. rememberMe: false,
  107. code: "",
  108. uuid: "",
  109. tenantID: ""
  110. },
  111. loginRules: {
  112. username: [
  113. {required: true, trigger: "blur", message: "请输入您的账号"},
  114. ],
  115. password: [
  116. {required: true, trigger: "blur", message: "请输入您的密码"},
  117. ],
  118. code: [{required: true, trigger: "blur", message: "请输入验证码"}],
  119. },
  120. loading: true,
  121. // 验证码开关
  122. captchaEnabled: true,
  123. // 注册开关
  124. register: false,
  125. redirect: undefined,
  126. // 页面配置数据
  127. config: {},
  128. };
  129. },
  130. watch: {
  131. $route: {
  132. handler: function (route) {
  133. this.redirect = route.query && route.query.redirect;
  134. },
  135. immediate: true,
  136. },
  137. },
  138. created() {
  139. this.validateTenantId()
  140. },
  141. methods: {
  142. // 校验url
  143. validateTenantId() {
  144. let tenantCode = this.$route.query['tenantCode']
  145. if (tenantCode != null) {
  146. // 得到tenantId 查询裤中是否存在该租户
  147. isTenantExist({tenantCode: tenantCode}).then(res => {
  148. if (res.data?.tenantId) { // 判断当前编号是否存在库中
  149. this.tenantId = res.data.tenantId;
  150. this.loginForm.tenantID = this.tenantId;
  151. // 得到租户的信息
  152. this.config = res.data.loginPageConfiguration
  153. this.setConfig();
  154. // 如果当前租户没有配置登录页面则不可访问
  155. if (this.config == null && this.config == undefined) {
  156. // this.$router.push({path: "/404"})
  157. this.getCode();
  158. this.getCookie();
  159. } else {
  160. this.getCode();
  161. this.getCookie();
  162. }
  163. } else {
  164. // 当前访问链接中的租户编号不存在
  165. this.$router.push({path: "/404"})
  166. }
  167. })
  168. } else {
  169. console.log('跳转')
  170. this.$router.push({path: "/404"})
  171. }
  172. },
  173. setConfig() {
  174. let {
  175. loginPageTitle,
  176. loginPageDescription,
  177. loginPageLogo,
  178. loginPageBackgroundImage,
  179. windowTitle,
  180. windowLogo,
  181. } = this.config;
  182. // 设置背景图
  183. if (loginPageBackgroundImage) {
  184. let loginBgDom = document.getElementsByClassName("login");
  185. if (loginBgDom.length > 0) {
  186. loginBgDom[0].style.backgroundImage = `url(${
  187. process.env.VUE_APP_BASE_IMG_API + loginPageBackgroundImage
  188. })`;
  189. console.log("" + `url(${
  190. process.env.VUE_APP_BASE_IMG_API + loginPageBackgroundImage
  191. })`)
  192. }
  193. }
  194. // 设置logo
  195. if (loginPageLogo) {
  196. let loginLogoDom = document.getElementsByClassName("comlogo");
  197. if (loginLogoDom.length > 0) {
  198. loginLogoDom[0].style.backgroundImage = `url(${
  199. process.env.VUE_APP_BASE_IMG_API + loginPageLogo
  200. })`;
  201. }
  202. window.sessionStorage.setItem("logo", loginPageLogo);
  203. }
  204. // 设置title
  205. if (loginPageTitle) {
  206. let titleDom = document.getElementsByClassName("title");
  207. console.log(titleDom);
  208. if (titleDom.length > 0) {
  209. titleDom[0].innerHTML = loginPageTitle;
  210. }
  211. window.sessionStorage.setItem("title", loginPageTitle);
  212. }
  213. // 设置meta信息
  214. if (windowTitle) {
  215. document.title = windowTitle;
  216. console.dir(document);
  217. }
  218. // 设置页面描述
  219. if (loginPageDescription) {
  220. this.config.pageDescription = loginPageDescription;
  221. }
  222. // 更换favicon.ico
  223. // if (windowLogo) {
  224. // // let url = process.env.VUE_APP_BASE_API + windowLogo;
  225. // let url = "@/assets/images/favicon1.ico";
  226. // console.log(url);
  227. // var link = document.createElement("link"),
  228. // oldLink = document.getElementById("dynamic-favicon");
  229. // link.id = "dynamic-favicon";
  230. // link.rel = "shortcut icon";
  231. // link.href = url;
  232. // if (oldLink) {
  233. // document.head.removeChild(oldLink);
  234. // }
  235. // document.head.appendChild(link);
  236. // }
  237. },
  238. getCode() {
  239. getCodeImg().then((res) => {
  240. this.captchaEnabled =
  241. res.captchaEnabled === undefined ? true : res.captchaEnabled;
  242. if (this.captchaEnabled) {
  243. this.codeUrl = "data:image/gif;base64," + res.img;
  244. this.loginForm.uuid = res.uuid;
  245. }
  246. });
  247. },
  248. getCookie() {
  249. const username = Cookies.get("username");
  250. const password = Cookies.get("password");
  251. const rememberMe = Cookies.get("rememberMe");
  252. this.loginForm = {
  253. username: username === undefined ? this.loginForm.username : username,
  254. password:
  255. password === undefined ? this.loginForm.password : decrypt(password),
  256. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  257. };
  258. },
  259. handleLogin() {
  260. this.$refs.loginForm.validate((valid) => {
  261. if (valid) {
  262. this.loading = true;
  263. if (this.loginForm.rememberMe) {
  264. Cookies.set("username", this.loginForm.username, {expires: 30});
  265. Cookies.set("password", encrypt(this.loginForm.password), {
  266. expires: 30,
  267. });
  268. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  269. expires: 30,
  270. });
  271. } else {
  272. Cookies.remove("username");
  273. Cookies.remove("password");
  274. Cookies.remove("rememberMe");
  275. }
  276. let form = {
  277. ...this.loginForm,
  278. tenantID: this.tenantId
  279. }
  280. this.$store.dispatch("Login", form).then(() => {
  281. changeDatasource(); //切换数据源
  282. this.$router.push({path: this.redirect || "/"}).catch(() => {
  283. });
  284. }).catch(() => {
  285. this.loading = false;
  286. if (this.captchaEnabled) {
  287. this.getCode();
  288. }
  289. });
  290. }
  291. });
  292. },
  293. },
  294. };
  295. </script>
  296. <style rel="stylesheet/scss" lang="scss" scoped>
  297. ::v-deep.el-input--medium .el-input__inner {
  298. height: 54px;
  299. line-height: 54px;
  300. }
  301. .login {
  302. position: relative;
  303. .page-description {
  304. position: absolute;
  305. left: 10%;
  306. top: 50%;
  307. transform: translateY(-100%);
  308. display: flex;
  309. flex-direction: column;
  310. .description {
  311. display: block;
  312. font-size: 38px;
  313. font-weight: 800;
  314. color: #fff;
  315. width: 200px;
  316. display: -webkit-box;
  317. -webkit-box-orient: vertical;
  318. overflow: hidden;
  319. height: 120px;
  320. max-height: 120px;
  321. -webkit-line-clamp: 2;
  322. text-overflow: ellipsis;
  323. }
  324. .sub-description {
  325. font-size: 20px;
  326. color: #fff;
  327. font-weight: 400;
  328. }
  329. }
  330. }
  331. .logg {
  332. margin-top: 42px;
  333. margin-left: 196px;
  334. width: 240px;
  335. height: 54px;
  336. line-height: 54px;
  337. text-align: center;
  338. opacity: 1;
  339. border-radius: 27px;
  340. background: linear-gradient(
  341. 135deg,
  342. rgba(79, 138, 255, 1) 0%,
  343. rgba(75, 94, 255, 1) 100%
  344. );
  345. box-shadow: 0px 4px 16px rgba(179, 192, 231, 1);
  346. color: #fff;
  347. font-size: 20px;
  348. font-weight: 500;
  349. cursor: pointer;
  350. }
  351. .aaa {
  352. width: 248px;
  353. height: 24px;
  354. font-size: 16px !important;
  355. font-weight: 400;
  356. letter-spacing: 0px;
  357. line-height: 24px;
  358. color: rgba(58, 63, 99, 1);
  359. text-align: left;
  360. vertical-align: top;
  361. margin-top: 16px;
  362. }
  363. .bottomtext {
  364. margin-top: -5px !important;
  365. margin-left: 58px !important;
  366. }
  367. .rowww {
  368. width: 522px;
  369. height: 80px;
  370. margin-top: 25px;
  371. margin-left: 55px;
  372. }
  373. .roww {
  374. width: 522px;
  375. height: 80px;
  376. margin-top: 16px;
  377. margin-left: 55px;
  378. }
  379. .ppp {
  380. width: 522px;
  381. height: 24px;
  382. opacity: 1;
  383. /** 文本1 */
  384. font-size: 16px;
  385. font-weight: 400;
  386. letter-spacing: 0px;
  387. line-height: 24px;
  388. color: rgba(58, 63, 99, 1);
  389. text-align: left;
  390. vertical-align: top;
  391. }
  392. .el-input__inner {
  393. width: 522px;
  394. /* height: 54px !important; */
  395. }
  396. .inputt {
  397. /* height: 54px !important; */
  398. border-radius: 4px;
  399. background: rgba(255, 255, 255, 1);
  400. border: 1px solid rgba(218, 224, 242, 1);
  401. margin-top: 2px;
  402. }
  403. .inputt input {
  404. width: 100%;
  405. }
  406. .comlogo {
  407. margin-left: 28px;
  408. margin-top: 57px;
  409. width: 194px;
  410. height: 64px;
  411. background: url(../assets/images/mec_logo_login.png);
  412. // background: url(../assets/images/comp.png);
  413. /* box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25); */
  414. opacity: 1;
  415. background-size: cover;
  416. }
  417. .login {
  418. display: flex;
  419. justify-content: center;
  420. align-items: center;
  421. height: 100%;
  422. background-image: url("../assets/images/background.jpg");
  423. background-size: cover;
  424. }
  425. .title {
  426. width: 258px;
  427. height: 35px;
  428. margin-top: 69px;
  429. margin-left: 17px;
  430. font-size: 32px;
  431. font-weight: 400;
  432. letter-spacing: 0px;
  433. line-height: 38.4px;
  434. color: rgba(7, 68, 138, 1);
  435. text-align: left;
  436. vertical-align: top;
  437. float: left;
  438. white-space: nowrap;
  439. overflow: hidden;
  440. text-overflow: ellipsis;
  441. }
  442. .login-form {
  443. margin-left: 44%;
  444. margin-top: 48px;
  445. width: 621px;
  446. height: 624px;
  447. opacity: 1;
  448. border-radius: 39px;
  449. background: rgba(255, 255, 255, 1);
  450. float: left;
  451. }
  452. .login-code {
  453. width: 40px;
  454. height: 54px;
  455. opacity: 1;
  456. }
  457. .el-col-18 {
  458. width: 66%;
  459. }
  460. </style>