index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <div class="login-container">
  3. <template v-if="type == 1">
  4. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
  5. <div class="title-container flex-wrap">
  6. <div class="avitor"></div>
  7. <!-- <el-divider direction="vertical"></el-divider> -->
  8. <div class="content-box">
  9. <div class="title">国航行李数据整合及应用</div>
  10. <div class="title-en">AirChina.BDHUB</div>
  11. </div>
  12. </div>
  13. <el-form-item prop="username">
  14. <!-- <span class="svg-container">
  15. <svg-icon style="color:#606266;" icon-class="user" />
  16. </span> -->
  17. <el-input ref="username" v-model="loginForm.username" placeholder="用户名" name="username" type="text" tabindex="1" auto-complete="on" />
  18. </el-form-item>
  19. <el-form-item prop="password">
  20. <!-- <span class="svg-container">
  21. <svg-icon style="color:#606266;" icon-class="password" />
  22. </span> -->
  23. <el-input ref="password" v-model="loginForm.password" show-password placeholder="密码" name="password" tabindex="2" auto-complete="on" />
  24. </el-form-item>
  25. <div class="flex-wrap">
  26. <el-form-item class="flex1" prop="identify">
  27. <el-input ref="identify" v-model="loginForm.identify" placeholder="请输入验证码" name="identify" tabindex="3" auto-complete="on" @keyup.enter.native="handleLogin" />
  28. </el-form-item>
  29. <Identify @changeCode="changeCode" :identifyCode="loginForm.CheckCode" style="margin-left: 24px" />
  30. </div>
  31. <el-button :loading="loading" type="primary" style="
  32. width: 100%;
  33. margin-top: 18px;
  34. height: 42px;
  35. border-radius: 2px;
  36. " @click.native.prevent="handleLogin">登录</el-button>
  37. <div class="forgetPwd">
  38. <span @click="handleClick" class="fpwd">忘记密码</span>
  39. </div>
  40. </el-form>
  41. </template>
  42. <template v-else>
  43. <Dialog :flag="flag" customClass="dormancyDialog" width="496px">
  44. <div class="dormancy">
  45. <div class="title">忘记密码</div>
  46. <div class="content">
  47. <p style="font-size: 16px; font-weight: 400; color: #303133">
  48. {{ PwdMessage }}
  49. </p>
  50. <div style="display: flex; justify-content: flex-end">
  51. <el-button size="small" type="primary" @click="onSubmit">
  52. 确定
  53. </el-button>
  54. </div>
  55. </div>
  56. </div>
  57. </Dialog>
  58. </template>
  59. </div>
  60. </template>
  61. <script>
  62. import Identify from "./identify.vue";
  63. import Dialog from "@/layout/components/Dialog/index.vue";
  64. import { GetCheckCode, gettoken, GetSystemSet } from "@/api/newLogin";
  65. import { Query } from "@/api/dataIntegration";
  66. // import { GetCheckCode, gettoken,GetSystemSet } from "@/api/login";
  67. // import { GetSystemSet } from "@/api/systemConfiguration";
  68. import { setCodeToken, setToken, TokenKey, getCodeToken } from '@/utils/auth';
  69. import { getAuthListByUser } from '@/api/Account';
  70. import MD5 from 'blueimp-md5'
  71. export default {
  72. name: "Login",
  73. components: { Identify, Dialog },
  74. data () {
  75. return {
  76. text: `<a onclick='("XSS")'>链接</a>`,
  77. type: 1,
  78. flag: false,
  79. PwdMessage: null,
  80. loginForm: {
  81. username: "",
  82. password: "",
  83. identify: "",
  84. CheckCode: null,
  85. },
  86. loginRules: {
  87. username: [
  88. { required: true, trigger: "blur", message: "请输入用户名" },
  89. ],
  90. password: [{ required: true, trigger: "blur", message: "请输入密码" }],
  91. identify: [
  92. { required: true, trigger: "blur", message: "请输入验证码" },
  93. ],
  94. },
  95. loading: false,
  96. passwordType: "password",
  97. redirect: undefined,
  98. };
  99. },
  100. watch: {
  101. $route: {
  102. handler: function (route) {
  103. this.redirect = route.query && route.query.redirect;
  104. },
  105. immediate: true,
  106. },
  107. '$store.state.user.isLogin': {
  108. handler (val) {
  109. if (val) {
  110. this.noPwdLogin()
  111. }
  112. },
  113. deep: true
  114. }
  115. },
  116. async created () {
  117. // this.getCheckCode();
  118. // this.getSystemSet();
  119. try {
  120. const res = await gettoken({
  121. 'appid': PLATFROM_CONFIG.appId,
  122. 'appSecret': PLATFROM_CONFIG.appKeyString
  123. })
  124. if (res.code == 0 && res.data) {
  125. setCodeToken(res.data.appToken);
  126. setTimeout(() => {
  127. this.getCheckCode();
  128. this.getSystemSet();
  129. }, 100);
  130. } else {
  131. this.$message.error(res.message);
  132. }
  133. } catch (error) {
  134. this.$message.error(error.message);
  135. }
  136. },
  137. methods: {
  138. showPwd () {
  139. if (this.passwordType === "password") {
  140. this.passwordType = "";
  141. } else {
  142. this.passwordType = "password";
  143. }
  144. this.$nextTick(() => {
  145. this.$refs.password.focus();
  146. });
  147. },
  148. //免密登录
  149. noPwdLogin () {
  150. this.$store.dispatch("user/setPowerToken", "token");
  151. this.$store.dispatch("user/setPowerName", '匿名用户');
  152. this.$store.dispatch("app/toggleOutcheck", false);
  153. this.$store.dispatch('user/setPowerList', ['admin']);
  154. setToken(TokenKey, "token");
  155. setTimeout(() => {
  156. this.$store.dispatch('user/getInfo');
  157. sessionStorage.setItem('userAuthList', JSON.stringify(['admin']));
  158. sessionStorage.setItem("userName", '匿名用户');
  159. this.$router.push({ path: this.redirect || "/" });
  160. this.$store.dispatch("user/setIsLogin", false);
  161. }, 100);
  162. },
  163. // 登录
  164. handleLogin () {
  165. this.$refs.loginForm.validate((valid) => {
  166. if (valid) {
  167. this.loading = true;
  168. const params = {
  169. username: this.loginForm.username.replace(/\s+/g, ""),
  170. password: MD5(this.loginForm.password.replace(/\s+/g, "")),
  171. // password: this.loginForm.password.replace(/\s+/g, ""),
  172. verificationCode: this.loginForm.identify.replace(/\s+/g, ""),
  173. };
  174. this.$store
  175. .dispatch("user/login", params)
  176. .then(async () => {
  177. this.$store.dispatch("app/toggleOutcheck", false);
  178. sessionStorage.setItem("userName", params.username);
  179. this.$router.push({ path: this.redirect || "/" });
  180. // try {
  181. // const { roles } = await this.$store.dispatch('user/getInfo')
  182. // if (roles && roles.length) {
  183. // this.$router.push({ path: this.redirect || "/" });
  184. // } else {
  185. // this.$store.dispatch("user/logout");
  186. // this.$message.error('当前用户获取权限失败,请联系管理员');
  187. // }
  188. // } catch (error) {
  189. // this.$store.dispatch("user/logout");
  190. // this.$message.error('当前用户获取权限失败,请联系管理员');
  191. // }
  192. // setTimeout(async () => {
  193. // const UserType = this.$store.getters.UserType;
  194. // Query({
  195. // id: DATACONTENT_ID.loginId,
  196. // dataContent: [UserId]
  197. // }).then(res => {
  198. // if (res.code == 0) {
  199. // //res.returnData.push('account_menu');
  200. // const { listValues } = res.returnData
  201. // const datas = listValues
  202. // if (datas && datas.length) {
  203. // const arrs = [];
  204. // for (const item of datas) {
  205. // if (item.ident) {
  206. // arrs.push(item.ident);
  207. // }
  208. // }
  209. // // arrs.push('transit');
  210. // sessionStorage.setItem('userAuthList', JSON.stringify(arrs));
  211. // this.$store.dispatch('user/setPowerList', arrs);
  212. // } else {
  213. // sessionStorage.setItem('userAuthList', []);
  214. // this.$store.dispatch('user/setPowerList', []);
  215. // }
  216. // this.$router.push({ path: this.redirect || "/" });
  217. // } else {
  218. // this.loading = false;
  219. // this.$store.dispatch("user/logout");
  220. // this.$message.error('当前用户获取权限失败,请联系管理员');
  221. // }
  222. // }).catch(err => {
  223. // this.loading = false;
  224. // this.$store.dispatch("user/logout");
  225. // this.$message.error('当前用户获取权限失败,请联系管理员');
  226. // })
  227. // }, 100);
  228. this.loading = false;
  229. })
  230. .catch(() => {
  231. this.getCheckCode();
  232. this.loading = false;
  233. });
  234. } else {
  235. return false;
  236. }
  237. });
  238. },
  239. // 忘记密码确定
  240. onSubmit () {
  241. this.flag = false;
  242. this.type = 1;
  243. },
  244. //获取动态验证码
  245. async getCheckCode () {
  246. const res = await GetCheckCode({
  247. appToken: getCodeToken()
  248. });
  249. if (res.code == 0) {
  250. this.loginForm.CheckCode = res.data;
  251. } else {
  252. this.$message.error(res.message);
  253. }
  254. },
  255. //获取系统设置
  256. getSystemSet () {
  257. GetSystemSet({})
  258. .then((response) => {
  259. const { code, data } = response;
  260. if (code == 0) {
  261. this.$store.dispatch("app/getSystemSet", data);
  262. }
  263. this.PwdMessage = data.pwdMessage;
  264. })
  265. .catch((error) => {
  266. reject(error);
  267. });
  268. },
  269. // 忘记密码
  270. handleClick () {
  271. // this.flag = true;
  272. // this.type = 2;
  273. this.$message.warning('忘记密码,请联系管理员');
  274. },
  275. //验证码重新获取
  276. changeCode () {
  277. this.getCheckCode();
  278. },
  279. },
  280. };
  281. </script>
  282. <style lang="scss" scoped>
  283. $bg: #2d3a4b;
  284. $dark_gray: #889aa4;
  285. $light_gray: #eee;
  286. .login-container {
  287. min-height: 100%;
  288. width: 100%;
  289. background-color: $bg;
  290. overflow: hidden;
  291. background-image: url("../../assets/loginpage/bg_001.jpg");
  292. background-repeat: no-repeat;
  293. background-size: cover;
  294. display: flex;
  295. justify-content: flex-end;
  296. align-items: center;
  297. ::v-deep .login-form {
  298. position: relative;
  299. width: 416px;
  300. height: 424px;
  301. margin-right: 337px;
  302. background: #ffffff;
  303. box-shadow: 0px 7px 18px 0px rgba(0, 0, 0, 0.5);
  304. border-radius: 8px;
  305. padding: 40px 48px 27px 48px;
  306. .el-form-item__content {
  307. height: 40px;
  308. background: #fff;
  309. border-radius: 6px;
  310. .el-input {
  311. height: 40px;
  312. border-radius: 2px;
  313. input {
  314. height: 40px;
  315. border: 1px solid #d2d6df;
  316. color: #303133;
  317. }
  318. }
  319. }
  320. }
  321. .forgetPwd {
  322. display: flex;
  323. justify-content: flex-end;
  324. margin-top: 22px;
  325. font-size: 14px;
  326. font-family: Microsoft YaHei;
  327. font-weight: 400;
  328. text-decoration: underline;
  329. color: #2d67e3;
  330. .fpwd {
  331. cursor: pointer;
  332. }
  333. }
  334. .tips {
  335. font-size: 14px;
  336. color: #fff;
  337. margin-bottom: 10px;
  338. span {
  339. &:first-of-type {
  340. margin-right: 16px;
  341. }
  342. }
  343. }
  344. .svg-container {
  345. vertical-align: middle;
  346. width: 55px;
  347. display: inline-block;
  348. text-align: center;
  349. }
  350. .title-container {
  351. position: relative;
  352. margin-bottom: 39px;
  353. line-height: 32px;
  354. .title {
  355. // height: 16px;
  356. font-size: 16px;
  357. font-family: Microsoft YaHei;
  358. font-weight: bold;
  359. color: #303133;
  360. margin: 0;
  361. }
  362. .title-en {
  363. position: absolute;
  364. top: 23px;
  365. left: 0;
  366. font-size: 12px;
  367. }
  368. .content-box {
  369. position: relative;
  370. }
  371. .avitor {
  372. width: 36px;
  373. height: 36px;
  374. margin-right: 20px;
  375. background: url("../../assets/logo/pic_logo.png") no-repeat;
  376. // border-radius: 50%;
  377. position: relative;
  378. top: 7px;
  379. }
  380. .el-divider {
  381. height: 20px;
  382. background: #101116;
  383. margin: 0 16px;
  384. position: relative;
  385. top: 5px;
  386. }
  387. }
  388. .show-pwd {
  389. position: absolute;
  390. right: 10px;
  391. top: 7px;
  392. font-size: 16px;
  393. color: $dark_gray;
  394. cursor: pointer;
  395. user-select: none;
  396. }
  397. }
  398. </style>