index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div :style="{'background':backgroundImg ? 'url('+backgroundImg+')' :'url('+defaultBgImg+')'}" class="login-container">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
  4. <div class="title-container flex-wrap">
  5. <el-avatar :size="36" :src="imgSrc" @error="errorHandler">
  6. <img src="@/assets/logo/error.png">
  7. </el-avatar>
  8. <!-- <el-divider direction="vertical"></el-divider> -->
  9. <div class="content-box">
  10. <div class="title">{{ pageTitle }}</div>
  11. </div>
  12. </div>
  13. <el-form-item prop="username">
  14. <el-input ref="username" v-model="loginForm.username" placeholder="用户名" name="username" type="text" tabindex="1" auto-complete="on" />
  15. </el-form-item>
  16. <el-form-item prop="password">
  17. <el-input ref="password" v-model="loginForm.password" show-password placeholder="密码" name="password" tabindex="2" auto-complete="on" />
  18. </el-form-item>
  19. <div v-if="isCode" class="flex-wrap">
  20. <el-form-item class="flex1" prop="identify">
  21. <el-input ref="identify" v-model="loginForm.identify" placeholder="请输入验证码" name="identify" tabindex="3" auto-complete="on" @keyup.enter.native="handleLogin" />
  22. </el-form-item>
  23. <img @click="changeCode" style="width: 116px;height: 40px;margin-left: 18px;cursor: pointer;" :src="baseImg" alt="验证码">
  24. </div>
  25. <el-button :loading="loading" type="primary" style="width: 100%;margin-top: 18px;height: 42px;border-radius: 2px;" @click.native.prevent="handleLogin">登录</el-button>
  26. </el-form>
  27. </div>
  28. </template>
  29. <script>
  30. import { isValue } from "@/utils/validate";
  31. import { getVCode, getToken, getKey, forceLogin } from "@/api/login";
  32. import { setToken, TokenKey, getUserId, setCodeToken } from '@/utils/auth';
  33. import MD5 from 'blueimp-md5'
  34. import JSEncrypt from "jsencrypt";
  35. const defaultBgImg = require('@/assets/loginpage/bg.jpg')
  36. export default {
  37. name: "Login",
  38. data () {
  39. return {
  40. flag: false,
  41. PwdMessage: null,
  42. loginForm: {
  43. username: "",
  44. password: "",
  45. identify: "",
  46. },
  47. loginRules: {
  48. username: [
  49. { required: true, trigger: "blur", message: "请输入用户名" },
  50. ],
  51. password: [{ required: true, trigger: "blur", message: "请输入密码" }],
  52. identify: [
  53. { required: true, trigger: "blur", message: "请输入验证码" },
  54. ],
  55. },
  56. loading: false,
  57. passwordType: "password",
  58. redirect: undefined,
  59. isCode: false,
  60. pageTitle: '',
  61. imgSrc: '',
  62. baseImg: '',
  63. appId: '',
  64. backgroundImg: '',
  65. defaultBgImg
  66. };
  67. },
  68. async created () {
  69. try {
  70. const { code, returnData, message } = await getToken({
  71. 'appid': PLATFROM_CONFIG.appId,
  72. 'appsecret': PLATFROM_CONFIG.appKeyString
  73. })
  74. if (code == 0 && isValue(returnData)) {
  75. const { appname, background, logo, securitycoderule, smalllogo, token } = returnData;
  76. this.imgSrc = logo
  77. this.pageTitle = appname ?? '行李全流程跟踪系统'
  78. this.isCode = securitycoderule
  79. this.backgroundImg = background
  80. setToken(TokenKey, token);
  81. sessionStorage.setItem('appConfig', JSON.stringify({ ...returnData }))
  82. // setToken('active_duration', active_duration);
  83. sessionStorage.setItem('appLog', logo)
  84. sessionStorage.setItem('appName', this.pageTitle)
  85. if (securitycoderule) {
  86. this.getCheckCode()
  87. }
  88. } else {
  89. this.$router.push('/404')
  90. }
  91. } catch (error) {
  92. this.$message.error(error.message);
  93. }
  94. },
  95. methods: {
  96. showPwd () {
  97. if (this.passwordType === "password") {
  98. this.passwordType = "";
  99. } else {
  100. this.passwordType = "password";
  101. }
  102. this.$nextTick(() => {
  103. this.$refs.password.focus();
  104. });
  105. },
  106. // 登录前获取公匙
  107. handleLogin () {
  108. this.$refs.loginForm.validate(async (valid) => {
  109. if (valid) {
  110. const { code, message, returnData } = await getKey();
  111. if (code == 0 && isValue(returnData)) {
  112. const { pubKeyStr } = returnData
  113. sessionStorage.setItem('pubKeyStr', pubKeyStr)
  114. this.qdLogin(pubKeyStr)
  115. } else {
  116. this.$message.error(message);
  117. }
  118. } else {
  119. return false;
  120. }
  121. });
  122. },
  123. //确认登录
  124. qdLogin (pubKeyStr) {
  125. this.loading = true;
  126. const jse = new JSEncrypt()
  127. jse.setPublicKey(pubKeyStr)
  128. const params = {
  129. account: this.loginForm.username.replace(/\s+/g, ""),
  130. password: jse.encrypt(this.loginForm.password.replace(/\s+/g, "")),
  131. };
  132. if (this.isCode) {
  133. params.verifycode = jse.encrypt(this.loginForm.identify.replace(/\s+/g, ""))
  134. }
  135. this.$store
  136. .dispatch("user/login", params)
  137. .then(async (res) => {
  138. if (res==1) {
  139. this.dialogOpen()
  140. } else {
  141. this.userLogin()
  142. }
  143. this.loading = false;
  144. })
  145. .catch(() => {
  146. this.getCheckCode();
  147. this.loading = false;
  148. });
  149. },
  150. //账号已经登录弹框
  151. dialogOpen () {
  152. this.$confirm('该账号已登录, 是否强制登录?', '提示', {
  153. confirmButtonText: '确定',
  154. cancelButtonText: '取消',
  155. type: 'warning'
  156. }).then(() => {
  157. this.userLogin()
  158. }).catch(() => {
  159. this.$message({
  160. type: 'info',
  161. message: '已取消登录'
  162. });
  163. });
  164. },
  165. //账号强制登录
  166. async userLogin () {
  167. const { code, message, returnData } = await forceLogin({
  168. userid: getUserId()
  169. });
  170. if (code == 0 && isValue(returnData)) {
  171. setToken('usertoken', returnData.usertoken)
  172. setCodeToken(returnData.usertoken)
  173. this.$store.dispatch("app/toggleOutcheck", false);
  174. sessionStorage.setItem("userName", this.loginForm.username.replace(/\s+/g, ""));
  175. this.$router.push({ path: this.redirect || "/" });
  176. } else {
  177. this.$message.error(message);
  178. }
  179. },
  180. //获取动态验证码
  181. async getCheckCode () {
  182. const { code, message, returnData } = await getVCode();
  183. if (code == 0 && isValue(returnData)) {
  184. const { verifyCodeImage } = returnData;
  185. this.loginForm.identify="";
  186. this.baseImg = verifyCodeImage;
  187. } else {
  188. this.$message.error(message);
  189. }
  190. },
  191. //验证码重新获取
  192. changeCode () {
  193. this.getCheckCode();
  194. },
  195. errorHandler () {
  196. return true
  197. }
  198. },
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. $bg: #2d3a4b;
  203. $dark_gray: #889aa4;
  204. $light_gray: #eee;
  205. .login-container {
  206. min-height: 100%;
  207. width: 100%;
  208. background-color: $bg;
  209. overflow: hidden;
  210. //background-image: url("../../assets/loginpage/bg.jpg");
  211. background-repeat: no-repeat;
  212. background-size: cover;
  213. display: flex;
  214. justify-content: center;
  215. align-items: center;
  216. ::v-deep .login-form {
  217. position: relative;
  218. width: 416px;
  219. height: 424px;
  220. background: #ffffff;
  221. box-shadow: 0px 7px 18px 0px rgba(0, 0, 0, 0.5);
  222. border-radius: 8px;
  223. padding: 40px 48px 27px 48px;
  224. .el-form-item__content {
  225. height: 40px;
  226. background: #fff;
  227. border-radius: 6px;
  228. .el-input {
  229. height: 40px;
  230. border-radius: 2px;
  231. input {
  232. height: 40px;
  233. border: 1px solid #d2d6df;
  234. color: #303133;
  235. }
  236. }
  237. }
  238. }
  239. .forgetPwd {
  240. display: flex;
  241. justify-content: flex-end;
  242. margin-top: 22px;
  243. font-size: 14px;
  244. font-family: Microsoft YaHei;
  245. font-weight: 400;
  246. text-decoration: underline;
  247. color: #2d67e3;
  248. .fpwd {
  249. cursor: pointer;
  250. }
  251. }
  252. .tips {
  253. font-size: 14px;
  254. color: #fff;
  255. margin-bottom: 10px;
  256. span {
  257. &:first-of-type {
  258. margin-right: 16px;
  259. }
  260. }
  261. }
  262. .svg-container {
  263. vertical-align: middle;
  264. width: 55px;
  265. display: inline-block;
  266. text-align: center;
  267. }
  268. .title-container {
  269. position: relative;
  270. margin-bottom: 39px;
  271. line-height: 32px;
  272. .title {
  273. // height: 16px;
  274. font-size: 16px;
  275. font-family: Microsoft YaHei;
  276. font-weight: bold;
  277. color: #303133;
  278. margin-left: 15px;
  279. }
  280. .title-en {
  281. position: absolute;
  282. top: 23px;
  283. left: 0;
  284. font-size: 12px;
  285. }
  286. .content-box {
  287. position: relative;
  288. }
  289. .avitor {
  290. width: 36px;
  291. height: 36px;
  292. margin-right: 20px;
  293. background: url("../../assets/logo/pic_logo.png") no-repeat;
  294. // border-radius: 50%;
  295. position: relative;
  296. top: 7px;
  297. }
  298. .el-divider {
  299. height: 20px;
  300. background: #101116;
  301. margin: 0 16px;
  302. position: relative;
  303. top: 5px;
  304. }
  305. }
  306. .show-pwd {
  307. position: absolute;
  308. right: 10px;
  309. top: 7px;
  310. font-size: 16px;
  311. color: $dark_gray;
  312. cursor: pointer;
  313. user-select: none;
  314. }
  315. }
  316. </style>