index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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">
  6. <h3 class="title">佛山交科4A统一身份安全管理平台</h3>
  7. </div>
  8. <el-form-item prop="username">
  9. <span class="svg-container">
  10. <svg-icon style="color:#606266;" icon-class="user" />
  11. </span>
  12. <el-input ref="username" v-model.trim="loginForm.username" placeholder="请输入账号" name="username" type="text" tabindex="1" auto-complete="on" />
  13. </el-form-item>
  14. <el-form-item prop="password">
  15. <span class="svg-container">
  16. <svg-icon style="color:#606266;" icon-class="password" />
  17. </span>
  18. <el-input ref="password" v-model="loginForm.password" show-password placeholder="请输入密码" name="password" tabindex="1" auto-complete="on" />
  19. </el-form-item>
  20. <div class="flex-wrap">
  21. <el-form-item class="flex1" prop="identify">
  22. <el-input ref="identify" v-model.trim="loginForm.identify" placeholder="请输入验证码" name="identify" tabindex="1" auto-complete="on" @keyup.enter.native="handleLogin" />
  23. </el-form-item>
  24. <Identify @changeCode="changeCode" :identifyCode="loginForm.CheckCode" style="margin-left: 24px;" />
  25. </div>
  26. <el-button :loading="loading" type="primary" style="width:100%;margin-top:18px;height:42px;" @click.native.prevent="handleLogin">登录</el-button>
  27. <div class="forgetPwd">
  28. <span @click="handleClick" class="fpwd">忘记密码</span>
  29. </div>
  30. </el-form>
  31. </template>
  32. <template v-else>
  33. <Dialog :flag="flag" customClass="dormancyDialog" width="496px">
  34. <div class="dormancy">
  35. <div class="title">忘记密码</div>
  36. <div class="content">
  37. <p style="font-size: 16px;font-weight: 400;color: #303133;">{{PwdMessage}}</p>
  38. <div style="display: flex;justify-content: flex-end;">
  39. <el-button size="small" type="primary" @click="onSubmit">
  40. 确定
  41. </el-button>
  42. </div>
  43. </div>
  44. </div>
  45. </Dialog>
  46. </template>
  47. </div>
  48. </template>
  49. <script>
  50. import Identify from './identify.vue';
  51. import Dialog from "@/layout/components/Dialog/index.vue";
  52. import { GetCheckCode, getToken } from '@/api/login';
  53. import { GetSystemSet } from "@/api/systemConfiguration";
  54. import { setCodeToken, getCodeToken } from '@/utils/auth';
  55. import { getAuthListByUser } from '@/api/Account';
  56. export default {
  57. name: 'Login',
  58. components: { Identify, Dialog },
  59. data () {
  60. return {
  61. type: 1,
  62. flag: false,
  63. PwdMessage: null,
  64. loginForm: {
  65. username: '',
  66. password: '',
  67. identify: '',
  68. CheckCode: null
  69. },
  70. loginRules: {
  71. username: [{ required: true, trigger: 'blur', message: '请输入账号' }],
  72. password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
  73. identify: [{ required: true, trigger: 'blur', message: '请输入验证码' }]
  74. },
  75. loading: false,
  76. passwordType: 'password',
  77. redirect: undefined
  78. }
  79. },
  80. watch: {
  81. $route: {
  82. handler: function (route) {
  83. this.redirect = route.query && route.query.redirect;
  84. },
  85. immediate: true
  86. }
  87. },
  88. async created () {
  89. // this.getCheckCode();
  90. // this.getSystemSet();
  91. try {
  92. const res = await getToken({
  93. 'appID': PLATFROM_CONFIG.appId
  94. })
  95. if (res.code == 0 && res.returnData.token) {
  96. setCodeToken(res.returnData.token);
  97. setTimeout(() => {
  98. this.getCheckCode();
  99. this.getSystemSet();
  100. }, 100);
  101. } else {
  102. this.$message.error(res.message);
  103. }
  104. } catch (error) {
  105. console.log(error);
  106. }
  107. },
  108. methods: {
  109. showPwd () {
  110. if (this.passwordType === 'password') {
  111. this.passwordType = '';
  112. } else {
  113. this.passwordType = 'password';
  114. }
  115. this.$nextTick(() => {
  116. this.$refs.password.focus();
  117. })
  118. },
  119. // 登录
  120. handleLogin () {
  121. this.$refs.loginForm.validate(valid => {
  122. if (valid) {
  123. this.loading = true
  124. const params = {
  125. LoginName: this.loginForm.username,
  126. LoginPwd: this.loginForm.password,
  127. CheckCode: this.loginForm.identify,
  128. token: getCodeToken()
  129. }
  130. this.$store
  131. .dispatch("user/login", params)
  132. .then(() => {
  133. this.$store.dispatch("app/toggleOutcheck", false);
  134. sessionStorage.setItem("userName", params.LoginName);
  135. setTimeout(() => {
  136. const UserId = this.$store.getters.UserId;
  137. const UserType = this.$store.getters.UserType;
  138. getAuthListByUser({
  139. UserId: UserId,
  140. UserType: UserType
  141. }).then(res => {
  142. if (res.code == 0) {
  143. //res.returnData.push('account_menu');
  144. const datas = res.returnData
  145. if (datas && datas.length) {
  146. const arrs = [];
  147. for (const item of datas) {
  148. if (item.AuthIdent) {
  149. arrs.push(item.AuthIdent);
  150. }
  151. }
  152. arrs.push('dashboard'); //进入首页手动添加权限
  153. sessionStorage.setItem('userAuthList', JSON.stringify(arrs));
  154. this.$store.dispatch('user/setPowerList', arrs);
  155. this.$router.push({ path: '/dashboard' || "/" });
  156. } else {
  157. sessionStorage.setItem('userAuthList', []);
  158. this.$store.dispatch('user/setPowerList', []);
  159. this.$router.push('/');
  160. }
  161. } else {
  162. this.loading = false;
  163. this.$store.dispatch("user/logout");
  164. this.$message.error('当前用户获取权限失败,请联系管理员');
  165. }
  166. }).catch(err => {
  167. this.loading = false;
  168. this.$store.dispatch("user/logout");
  169. this.$message.error('当前用户获取权限失败,请联系管理员');
  170. })
  171. }, 100);
  172. this.loading = false;
  173. })
  174. .catch((res) => {
  175. if (res.message) {
  176. this.$message.error(res.message);
  177. }
  178. this.getCheckCode();
  179. this.loginForm.password = '';
  180. this.loginForm.identify = '';
  181. this.loading = false;
  182. });
  183. } else {
  184. console.log('error submit!!')
  185. return false
  186. }
  187. })
  188. },
  189. // 忘记密码确定
  190. onSubmit () {
  191. this.flag = false;
  192. this.type = 1;
  193. this.getCheckCode();
  194. },
  195. //获取动态验证码
  196. async getCheckCode () {
  197. const res = await GetCheckCode({
  198. token: getCodeToken()
  199. });
  200. if (res.code === 0) {
  201. this.loginForm.CheckCode = res.returnData;
  202. } else {
  203. this.$message.error(res.message);
  204. }
  205. },
  206. //获取系统设置
  207. getSystemSet () {
  208. GetSystemSet({}).then(response => {
  209. const { returnData } = response;
  210. const { PwdMessage } = returnData
  211. this.PwdMessage = PwdMessage
  212. this.$store.dispatch("app/getSystemSet", returnData);
  213. }).catch(error => {
  214. reject(error)
  215. })
  216. },
  217. // 忘记密码
  218. handleClick () {
  219. this.flag = true
  220. this.type = 2
  221. },
  222. //验证码重新获取
  223. changeCode () {
  224. this.getCheckCode()
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. /* 修复input 背景不协调 和光标变色 */
  231. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  232. $bg: #283443;
  233. $light_gray: #fff;
  234. $cursor: #fff;
  235. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  236. .login-container .el-input input {
  237. color: $cursor;
  238. }
  239. }
  240. /* reset element-ui css */
  241. .login-container {
  242. .el-input {
  243. display: inline-block;
  244. height: 47px;
  245. width: 85%;
  246. input {
  247. background: transparent;
  248. border: 0px;
  249. -webkit-appearance: none;
  250. border-radius: 0px;
  251. padding: 12px 5px 12px 15px;
  252. color: $light_gray;
  253. // caret-color: $cursor;
  254. &:-webkit-autofill {
  255. box-shadow: 0 0 0px 1000px #f5f7fa inset !important;
  256. }
  257. }
  258. }
  259. .el-form-item {
  260. border: 1px solid rgba(255, 255, 255, 0.1);
  261. background: rgba(0, 0, 0, 0.1);
  262. border-radius: 5px;
  263. color: #454545;
  264. }
  265. }
  266. </style>
  267. <style lang="scss" scoped>
  268. $bg: #2d3a4b;
  269. $dark_gray: #889aa4;
  270. $light_gray: #eee;
  271. .login-container {
  272. min-height: 100%;
  273. width: 100%;
  274. background-color: $bg;
  275. overflow: hidden;
  276. background-image: url("../../assets/loginpage/bg.jpg");
  277. background-repeat: no-repeat;
  278. background-size: cover;
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. ::v-deep .login-form {
  283. position: relative;
  284. width: 496px;
  285. max-width: 100%;
  286. height: 463px;
  287. padding: 48px;
  288. margin: 0 auto;
  289. overflow: hidden;
  290. background: #ffffff;
  291. box-shadow: 0px 7px 18px 0px rgba(0, 0, 0, 0.5);
  292. border-radius: 16px;
  293. .el-form-item__content {
  294. height: 40px;
  295. background: #f5f7fa;
  296. border-radius: 6px;
  297. .el-input {
  298. height: 40px;
  299. input {
  300. height: 40px;
  301. color: #303133;
  302. }
  303. }
  304. }
  305. }
  306. .forgetPwd {
  307. display: flex;
  308. justify-content: flex-end;
  309. margin-top: 22px;
  310. font-size: 14px;
  311. font-family: Microsoft YaHei;
  312. font-weight: 400;
  313. text-decoration: underline;
  314. color: #6f81bc;
  315. .fpwd {
  316. cursor: pointer;
  317. }
  318. }
  319. .tips {
  320. font-size: 14px;
  321. color: #fff;
  322. margin-bottom: 10px;
  323. span {
  324. &:first-of-type {
  325. margin-right: 16px;
  326. }
  327. }
  328. }
  329. .svg-container {
  330. vertical-align: middle;
  331. width: 55px;
  332. display: inline-block;
  333. text-align: center;
  334. }
  335. .title-container {
  336. position: relative;
  337. .title {
  338. font-size: 24px;
  339. font-family: Microsoft YaHei;
  340. font-weight: bold;
  341. color: #303133;
  342. margin: 0;
  343. margin-bottom: 44px;
  344. }
  345. }
  346. .show-pwd {
  347. position: absolute;
  348. right: 10px;
  349. top: 7px;
  350. font-size: 16px;
  351. color: $dark_gray;
  352. cursor: pointer;
  353. user-select: none;
  354. }
  355. }
  356. </style>