login.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div class="login-container" id="particles-js">
  3. <div class="bg-logo anim"></div>
  4. <el-form
  5. ref="loginForm"
  6. :model="loginForm"
  7. :rules="loginRules"
  8. class="login-form"
  9. autocomplete="on"
  10. label-position="left">
  11. <div class="title-container">
  12. <!-- <h3 class="title">{{appName}}</h3> -->
  13. <img class="csms-logo" src="../../icons/logo.png"/>
  14. <p class="title">CSMS LOGIN</p>
  15. </div>
  16. <el-form-item prop="email">
  17. <div class="form-login-input">
  18. <span class="svg-container">
  19. <svg-icon icon-class="email" />
  20. </span>
  21. <el-input
  22. ref="username"
  23. v-model="loginForm.email"
  24. name="email"
  25. type="text"
  26. tabindex="1"
  27. autocomplete="on"
  28. clearable
  29. maxlength="50"
  30. @focus="() => focusFiled.email = true"
  31. @blur="() => focusFiled.email = false"/>
  32. <label :class='isNameValid ? "focus" : ""'>Email</label>
  33. </div>
  34. </el-form-item>
  35. <el-form-item prop="password">
  36. <div class="form-login-input">
  37. <span class="svg-container">
  38. <svg-icon icon-class="password" />
  39. </span>
  40. <el-input
  41. ref="password"
  42. v-model="loginForm.password"
  43. :type="passwordType"
  44. name="password"
  45. tabindex="2"
  46. autocomplete="off"
  47. clearable
  48. maxlength="20"
  49. @keyup.enter.native="handleLogin"
  50. @focus="() => focusFiled.password = true"
  51. @blur="() => focusFiled.password = false"
  52. />
  53. <span class="show-pwd" @click="showPwd">
  54. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  55. </span>
  56. <label :class='isPsdValid ? "focus" : ""'>Password</label>
  57. </div>
  58. </el-form-item>
  59. <el-button
  60. :loading="loading"
  61. type="primary"
  62. class="login-button"
  63. @click.native.prevent="handleLogin">
  64. Login
  65. </el-button>
  66. </el-form>
  67. <div class="copyinfo">©{{copyYear}}&nbsp; {{company}}</div>
  68. </div>
  69. </template>
  70. <script>
  71. import VueRouter from 'vue-router'
  72. import { Message } from 'element-ui'
  73. import settings from '../../settings.js'
  74. import {getEmail} from '../../utils/auth.js'
  75. import particles from 'particles.js'
  76. import animateJson from './animate.json'
  77. const { isNavigationFailure, NavigationFailureType } = VueRouter
  78. export default {
  79. name: 'Login',
  80. data() {
  81. const validatePassword = (rule, value, callback) => {
  82. if (value.length < 6) {
  83. callback(new Error('The password can not be less than 6 digits'))
  84. } else {
  85. callback()
  86. }
  87. }
  88. return {
  89. year: 2023,
  90. appName: settings.title,
  91. company: settings.company,
  92. loginForm: {
  93. email: '',
  94. password: ''
  95. },
  96. loginRules: {
  97. email: [{
  98. required: true,
  99. trigger: 'blur',
  100. message: "Please type email"
  101. }, {
  102. pattern: /^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/,
  103. trigger: 'blur',
  104. message: 'Please type a correct email'
  105. }],
  106. password: [{
  107. required: true,
  108. trigger: 'blur',
  109. message: "Please type password"
  110. //validator: validatePassword
  111. }]
  112. },
  113. passwordType: 'password',
  114. loading: false,
  115. redirect: undefined,
  116. otherQuery: {},
  117. focusFiled: {
  118. email: false,
  119. password: false
  120. }
  121. }
  122. },
  123. watch: {
  124. $route: {
  125. handler: function(route) {
  126. const query = route.query
  127. if (query) {
  128. this.redirect = query.redirect
  129. this.otherQuery = this.getOtherQuery(query)
  130. }
  131. },
  132. immediate: true
  133. }
  134. },
  135. computed: {
  136. copyYear() {
  137. const year = new Date().getFullYear();
  138. if (year > this.year) {
  139. return this.year + "-" + year;
  140. } else {
  141. return this.year;
  142. }
  143. },
  144. isNameValid() {
  145. return (this.loginForm.email !== "" || this.focusFiled.email)
  146. },
  147. isPsdValid() {
  148. return (this.loginForm.password !== "" || this.focusFiled.password)
  149. }
  150. },
  151. created() {
  152. // window.addEventListener('storage', this.afterQRScan)
  153. const user = getEmail()
  154. if (user) {
  155. this.loginForm.email = user;
  156. }
  157. //console.log(animateJson);
  158. //
  159. },
  160. beforeMount() {
  161. this.$nextTick(() => {
  162. //const sss = document.getElementById("particles-js");
  163. particlesJS('particles-js', animateJson);
  164. })
  165. },
  166. mounted() {
  167. if (this.loginForm.email === '') {
  168. this.$refs.username.focus()
  169. } else if (this.loginForm.password === '') {
  170. this.$refs.password.focus()
  171. }
  172. },
  173. destroyed() {
  174. // window.removeEventListener('storage', this.afterQRScan)
  175. },
  176. methods: {
  177. showPwd() {
  178. if (this.passwordType === 'password') {
  179. this.passwordType = ''
  180. } else {
  181. this.passwordType = 'password'
  182. }
  183. this.$nextTick(() => {
  184. this.$refs.password.focus()
  185. })
  186. },
  187. handleLogin() {
  188. this.$refs.loginForm.validate(valid => {
  189. if (valid) {
  190. this.loading = true
  191. this.$store.dispatch('user/login', this.loginForm).then((response) => {
  192. let path = this.redirect || '/'
  193. if (response.data.roleName === "MCST") {
  194. path = '/site-management'
  195. } else if (response.data.resources.length > 0) {
  196. let validPath = false;
  197. for (let _route of response.data.resources) {
  198. if (path.indexOf(_route.resourcePath) >= 0) {
  199. validPath = true;
  200. break
  201. }
  202. }
  203. if (!validPath) {
  204. path = response.data.resources[0].resourcePath;
  205. }
  206. }
  207. this.$router.push({
  208. path: path,
  209. query: this.otherQuery,
  210. }).catch((failure) => {
  211. if (!isNavigationFailure(failure, NavigationFailureType.redirected)) {
  212. throw failure
  213. }
  214. })
  215. this.loading = false
  216. }).catch((error) => {
  217. Message.error(error.message)
  218. this.loading = false
  219. });
  220. } else {
  221. console.log('error submit!!')
  222. return false
  223. }
  224. })
  225. },
  226. getOtherQuery(query) {
  227. return Object.keys(query).reduce((acc, cur) => {
  228. if (cur !== 'redirect') {
  229. acc[cur] = query[cur]
  230. }
  231. return acc
  232. }, {})
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="scss" scoped>
  238. /* reset element-ui css */
  239. .login-container {
  240. width: 100%;
  241. display: flex;
  242. overflow: hidden;
  243. min-height: 100%;
  244. user-select: none;
  245. align-items: center;
  246. justify-content: center;
  247. background: linear-gradient(0deg, #333333 0%, #A1A1A1 100%);
  248. .login-form {
  249. width: 100%;
  250. z-index: 2;
  251. margin: 0 auto;
  252. max-width: 420px;
  253. overflow: hidden;
  254. background: #fff;
  255. position: relative;
  256. border-radius: 3px;
  257. padding: 30px 40px 50px;
  258. box-shadow: 1px 1px 5px 3px rgba(0,0,0,.2);
  259. }
  260. .title-container {
  261. text-align: center;
  262. position: relative;
  263. padding: 20px 0 0;
  264. .title {
  265. font-size: 18px;
  266. color: #333;
  267. margin: 20px 0;
  268. text-align: center;
  269. font-weight: bold;
  270. }
  271. .csms-logo {
  272. max-width: 200px;
  273. }
  274. }
  275. .form-login-input {
  276. width: 100%;
  277. display: flex;
  278. padding: 0 10px;
  279. margin-top: 20px;
  280. position: relative;
  281. align-items: center;
  282. border-bottom: 1px solid #999;
  283. label {
  284. top: 0;
  285. left: 0;
  286. color: #aaa;
  287. font-size: 14px;
  288. position:absolute;
  289. padding-top: 7px;
  290. padding-left: 45px;
  291. font-weight: normal;
  292. pointer-events: none;
  293. transition: all 0.3s;
  294. }
  295. label.focus {
  296. top: -30px;
  297. color: #333;
  298. font-size: 15px;
  299. font-weight: bold;
  300. padding-left: 5px;
  301. }
  302. .svg-container {
  303. width: 30px;
  304. color: #333;
  305. font-size: 16px;
  306. padding: 6px 6px 6px 5px;
  307. }
  308. .el-input {
  309. flex: 1;
  310. height: 42px;
  311. &::v-deep input {
  312. color: #333;
  313. height: 42px;
  314. border: none;
  315. font-size: 14px;
  316. padding: 0 5px;
  317. border-radius: 0px;
  318. -webkit-appearance: none;
  319. background: transparent;
  320. }
  321. }
  322. }
  323. .show-pwd {
  324. color: #999;
  325. cursor: pointer;
  326. font-size: 16px;
  327. user-select: none;
  328. }
  329. .login-button {
  330. width:100%;
  331. color: #fff;
  332. padding: 15px;
  333. margin-top: 40px;
  334. margin-bottom: 30px;
  335. font-weight: bold;
  336. }
  337. .copyinfo {
  338. left: 0;
  339. right: 0;
  340. bottom: 10px;
  341. color: #e0e0e0;
  342. font-size: 12px;
  343. user-select: none;
  344. text-align: center;
  345. position: absolute;
  346. transform: scale(.8);
  347. }
  348. .bg-logo {
  349. top: 0;
  350. left: 0;
  351. right: 0;
  352. bottom: 0;
  353. z-index: 1;
  354. opacity: .3;
  355. position: fixed;
  356. filter: blur(30px);
  357. pointer-events: none;
  358. background-size: contain;
  359. background-position: center;
  360. background-repeat: no-repeat;
  361. background-image: url(../../assets/logo.png);
  362. }
  363. .bg-logo.anim {
  364. animation: moveBg 10s infinite;
  365. background-origin: content-box;
  366. }
  367. }
  368. @keyframes moveBg {
  369. 0% {
  370. padding: 0;
  371. filter: blur(30px);
  372. }
  373. 50% {
  374. padding: 0 200px;
  375. filter: blur(20px);
  376. }
  377. 100% {
  378. padding: 0;
  379. filter: blur(30px);
  380. }
  381. }
  382. </style>
  383. <style>
  384. .particles-js-canvas-el {
  385. z-index: 1;
  386. position: fixed;
  387. }
  388. </style>