index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*login*/
  2. <template>
  3. <div class="login">
  4. <div class="container">
  5. <div class="content">
  6. <div class="text">
  7. <div class="back">
  8. <p>&nbsp;犀工网</p>
  9. <p>引领创新</p>
  10. </div>
  11. <div class="face">
  12. <p>&nbsp;犀工网</p>
  13. <p>引领创新</p>
  14. </div>
  15. </div>
  16. <el-form
  17. ref="loginForm"
  18. class="login-form"
  19. :model="loginForm"
  20. :rules="loginRules"
  21. auto-complete="on"
  22. label-position="left"
  23. >
  24. <h3 class="title active">账户登录</h3>
  25. <el-form-item prop="username">
  26. <el-input
  27. ref="username"
  28. v-model="loginForm.username"
  29. type="text"
  30. size="small"
  31. name="username"
  32. placeholder="邮箱/用户名"
  33. auto-complete="on"
  34. />
  35. </el-form-item>
  36. <el-form-item prop="password">
  37. <el-input
  38. ref="password"
  39. v-model="loginForm.password"
  40. :type="passwordType"
  41. size="small"
  42. name="password"
  43. placeholder="请输入密码"
  44. auto-complete="on"
  45. @keyup.enter.native="Login"
  46. >
  47. <svg-icon
  48. slot="suffix"
  49. :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
  50. @click="showPwd"
  51. />
  52. </el-input>
  53. </el-form-item>
  54. <el-button
  55. type="danger"
  56. size="small"
  57. class="login-btn"
  58. :loading="loading"
  59. @click.native.prevent="Login"
  60. >登录</el-button
  61. >
  62. <div class="link">
  63. <router-link class="link-item" to="/forget">忘记密码</router-link>
  64. <router-link class="link-item" to="/register">免费注册</router-link>
  65. <!-- <span class="link-item" @click="toPage('forget')">忘记密码</span>
  66. <span class="link-item" @click="toPage('register')">免费注册</span> -->
  67. </div>
  68. </el-form>
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import { request, enPassword, dePassword } from '@/utils/request'
  75. import { setToken } from '@/utils/token'
  76. import { validPwd } from '@/utils/validate'
  77. export default {
  78. name: 'Login',
  79. data() {
  80. const validatePwd = (rule, value, callback) => {
  81. if (value) {
  82. if (!validPwd(value)) {
  83. callback(new Error('6~18位,只能包含字母、数字和下划线'))
  84. } else {
  85. callback()
  86. }
  87. } else {
  88. callback(new Error('请输入密码'))
  89. }
  90. }
  91. return {
  92. loginForm: {
  93. username: '', // zhaochangjun
  94. password: '', // 密码(zhao1234)
  95. },
  96. loginRules: {
  97. username: [
  98. { required: true, message: '请输入邮箱/用户名', trigger: 'blur' },
  99. ],
  100. password: [{ required: true, trigger: 'blur', validator: validatePwd }],
  101. },
  102. loading: false,
  103. passwordType: 'password',
  104. redirect: undefined,
  105. }
  106. },
  107. watch: {
  108. $route: {
  109. handler: function (route) {
  110. this.redirect = route.query && route.query.redirect
  111. },
  112. immediate: true,
  113. },
  114. },
  115. created() {
  116. let messageBoxArr = document.getElementsByClassName(
  117. 'el-message-box__wrapper'
  118. ) //获取页面所有已经存在的messageBox
  119. if (messageBoxArr.length > 0) {
  120. this.$msgbox.close() //关闭messageBox弹框
  121. }
  122. },
  123. methods: {
  124. showPwd() {
  125. this.passwordType = this.passwordType === 'password' ? 'text' : 'password'
  126. this.$nextTick(() => {
  127. this.$refs.password.focus()
  128. })
  129. },
  130. Login() {
  131. this.$refs.loginForm.validate((valid) => {
  132. if (valid) {
  133. this.loading = true
  134. const params = {
  135. transCode: 'A00002',
  136. userName: this.loginForm.username,
  137. authCode: '',
  138. password: enPassword(this.loginForm.password),
  139. type: '',
  140. }
  141. request(params)
  142. .then((res) => {
  143. console.log(res.userId);
  144. this.$store.dispatch('user/changeState', {
  145. key: 'token',
  146. value: res.clientToken,
  147. })
  148. this.$store.dispatch('user/changeState', {
  149. key: 'name',
  150. value: res.nickName,
  151. })
  152. this.$store.dispatch('user/changeState', {
  153. key: 'userId',
  154. value: res.userId,
  155. })
  156. this.$store.dispatch('user/changeState', {
  157. key: 'userType',
  158. value: res.userType,
  159. })
  160. this.$store.dispatch('user/changeState', {
  161. key: 'realStatus',
  162. value: res.authenticationState,
  163. })
  164. this.$store.dispatch('user/changeState', {
  165. key: 'cfdUrl',
  166. value: res.cfdUrl,
  167. })
  168. this.$store.dispatch('user/changeState', {
  169. key: 'userRole',
  170. value: res.userRole,
  171. })
  172. this.$store.dispatch('user/changeState', {
  173. key: 'backgroundFileid',
  174. value: res.backgroundFileid,
  175. })
  176. this.$store.dispatch('user/changeState', {
  177. key: 'loginStatus',
  178. value: true,
  179. })
  180. this.$message.success('登录成功!')
  181. this.loading = false
  182. setToken(res.clientToken)
  183. setTimeout(() => {
  184. this.$router.replace({
  185. path: this.$route.query.redirect || '/indexLayout',
  186. })
  187. }, 1000)
  188. })
  189. .catch((err) => {
  190. this.loading = false
  191. })
  192. } else {
  193. return false
  194. }
  195. })
  196. },
  197. toPage(type) {
  198. this.$router.push({
  199. path: '/' + type,
  200. })
  201. },
  202. },
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. @import '@/styles/variables.scss';
  207. @import '@/styles/mixin.scss';
  208. .login {
  209. padding: 50px 0;
  210. // @include w_h(100%, calc(100% - 80px));
  211. @include w_h(100%, 800px);
  212. .container {
  213. @include w_h(100%, 100%);
  214. background: #6bb3f1;
  215. // background: $color_b url('../../assets/img/login.png') no-repeat center;
  216. // background-size: cover;
  217. .content {
  218. padding: 0 120px;
  219. @include flex();
  220. @include w_h(100%, 100%);
  221. .text {
  222. @include w_h(440px, 280px);
  223. @include position();
  224. font-size: 100px;
  225. font-weight: 700;
  226. line-height: 105px;
  227. white-space: nowrap;
  228. .back {
  229. @include w_h(440px, 280px);
  230. @include position(absolute, 30px, 0, 0, 0, 1);
  231. color: rgba(255, 255, 255, 1);
  232. text-shadow: 2px 5px 6px rgba(4, 92, 160, 0.75);
  233. }
  234. .face {
  235. @include w_h(440px, 280px);
  236. @include position(absolute, 30px, 0, 0, 0, 2);
  237. color: rgba(255, 255, 255, 0.12);
  238. background: linear-gradient(
  239. 0deg,
  240. rgba(177, 226, 247, 1) 0%,
  241. rgba(247, 251, 255, 1) 100%
  242. );
  243. -webkit-background-clip: text;
  244. -webkit-text-fill-color: transparent;
  245. }
  246. }
  247. .login-form {
  248. padding: 35px 15px;
  249. @include w_h(30%);
  250. max-width: 360px;
  251. min-width: 300px;
  252. background: $color_f;
  253. .title {
  254. margin-bottom: 30px;
  255. font-size: 20px;
  256. text-align: center;
  257. color: $color_3;
  258. }
  259. .login-btn {
  260. margin: 10px auto 30px;
  261. @include w_h();
  262. }
  263. .link {
  264. @include flex(center);
  265. font-size: 12px;
  266. color: $color_9;
  267. .link-item {
  268. margin: 0 10px;
  269. &:hover {
  270. cursor: pointer;
  271. color: $color_on;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. }
  279. </style>
  280. <style lang="scss">
  281. @import '@/styles/variables.scss';
  282. @supports (-webkit-mask: none) and (not (cater-color: $color_9)) {
  283. .login-form .el-input input {
  284. font-size: 12px;
  285. color: $color_9;
  286. }
  287. }
  288. .login-form {
  289. .el-input {
  290. &__inner:focus {
  291. border-color: $color_9;
  292. }
  293. }
  294. }
  295. </style>