login.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="login flex col-center">
  3. </div>
  4. </template>
  5. <script>
  6. import {
  7. loginType,
  8. client
  9. } from '@/utils/type'
  10. import Cookies from 'js-cookie'
  11. import {
  12. mapMutations,
  13. mapActions,
  14. mapState
  15. } from 'vuex'
  16. import CountDown from '@/components/count-down'
  17. export default {
  18. head() {
  19. return {
  20. title: this.$store.getters.headTitle,
  21. link: [{
  22. rel: 'icon',
  23. type: 'image/x-icon',
  24. href: this.$store.getters.favicon,
  25. }, ],
  26. }
  27. },
  28. layout: 'main',
  29. components: {
  30. CountDown,
  31. },
  32. data() {
  33. return {
  34. token: null,
  35. loginUrl: 'https://www.jucai.gov.cn/mobile/auth/login/company?redirect_url='
  36. }
  37. },
  38. computed: {
  39. ...mapState(['config']),
  40. },
  41. methods: {
  42. ...mapMutations(['setToken', 'setPublic']),
  43. async authLoginJucai() {
  44. const {
  45. token
  46. } = this.$route.query
  47. console.log('token: ' + token)
  48. if (token || this.config.token) {
  49. // this.$message({
  50. // message: '登录中...',
  51. // iconClass: "loading",
  52. // });
  53. this.loginHandle(token || this.config.token)
  54. } else {
  55. this.$message({
  56. message: '仅对企业开放',
  57. iconClass: "loading",
  58. duration: '500',
  59. onClose: () => {
  60. location.href = this.loginUrl + encodeURIComponent(location.href)
  61. }
  62. });
  63. }
  64. },
  65. // 登录结果处理
  66. async loginHandle(token) {
  67. //保存token,获取用户
  68. let num = 2 //失效时间是几小时
  69. let time = new Date(new Date().getTime() + num * 60 * 60 * 1000);
  70. Cookies.set('token', token, {
  71. expires: time
  72. }); //保存2小时
  73. this.setToken(token)
  74. //获取聚才网用户信息
  75. let res = await this.$post('https://www.jucai.gov.cn/api/auth/getInfoByToken', {})
  76. //token 过期,重新登录
  77. if (res.code == 2) {
  78. this.$router.push({
  79. path: '/account/login'
  80. })
  81. return false;
  82. }
  83. if (res.code == 1) {
  84. //个人用户,拒绝访问
  85. if (res.data.type == 1) {
  86. this.$message({
  87. message: '仅对企业开放',
  88. type: "error",
  89. onClose: () => {
  90. this.$router.push({
  91. path: '/account/login'
  92. })
  93. }
  94. });
  95. return false;
  96. }
  97. //企业用户
  98. if (res.data.type == 2) {
  99. let {data} = await this.$post('auth/login', {
  100. ...res.data
  101. })
  102. //存储用户信息
  103. this.setPublic(data)
  104. }
  105. }
  106. //跳转逻辑
  107. Cookies.set('reload', true, {
  108. expires: time
  109. }); //保存2小时
  110. this.$router.replace({
  111. path: Cookies.get('back_url') || '/',
  112. })
  113. Cookies.remove('back_url')
  114. },
  115. async accountLogin() {
  116. let res = await this.$post('account/login', {
  117. mobile: this.account,
  118. password: this.password,
  119. client,
  120. })
  121. if (res.code == 1) {
  122. const token = res.data.token
  123. Cookies.set('token', token, {
  124. expires: 60
  125. })
  126. this.setToken(token)
  127. this.$router.replace({
  128. path: Cookies.get('back_url') || '/',
  129. })
  130. Cookies.remove('back_url')
  131. this.getPublicData()
  132. if (this.isRemember) {
  133. localStorage.setItem(
  134. 'ACCOUNT',
  135. JSON.stringify({
  136. account: this.account,
  137. })
  138. )
  139. } else {
  140. localStorage.setItem(
  141. 'ACCOUNT',
  142. JSON.stringify({
  143. account: '',
  144. })
  145. )
  146. }
  147. }
  148. },
  149. },
  150. created() {
  151. this.authLoginJucai();
  152. },
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .login {
  157. flex: 1;
  158. background-size: cover;
  159. background-repeat: no-repeat;
  160. background-position: 50%;
  161. min-width: 1180px;
  162. .login-container {
  163. margin: 0 auto;
  164. width: 1180px;
  165. height: 100%;
  166. position: relative;
  167. .login-banner {
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. width: 750px;
  172. margin-right: 30px;
  173. height: 440px;
  174. overflow: hidden;
  175. animation: loadimg 2s infinite;
  176. transition: background-color 2s;
  177. }
  178. @keyframes loadimg {
  179. 0% {
  180. background-color: #e4e4e4;
  181. }
  182. 50% {
  183. background-color: #f0f0f0;
  184. }
  185. 100% {
  186. background-color: #e4e4e4;
  187. }
  188. }
  189. .login-float-form-wrap {
  190. width: 400px;
  191. height: 440px;
  192. .login-box {
  193. background-color: white;
  194. height: 100%;
  195. display: flex;
  196. flex-direction: column;
  197. justify-content: space-between;
  198. .login-header-box {
  199. padding-top: 20px;
  200. .header-tabs {
  201. .header-tab {
  202. width: 160px;
  203. height: 35px;
  204. display: flex;
  205. flex-direction: column;
  206. align-items: center;
  207. cursor: pointer;
  208. }
  209. .active-tab {
  210. color: $--color-primary;
  211. text-align: center;
  212. &::after {
  213. content: "";
  214. height: 2px;
  215. width: 72px;
  216. margin-top: 8px;
  217. background-color: $--color-primary;
  218. }
  219. }
  220. }
  221. .login-form-box {
  222. padding: 0 30px;
  223. .login-form-item {
  224. margin-top: 24px;
  225. .input-phone-num {
  226. width: 340px;
  227. }
  228. .verify-code-img {
  229. width: 100px;
  230. height: 40px;
  231. margin-left: 20px;
  232. background-color: red;
  233. }
  234. .sms-btn {
  235. margin-left: 20px;
  236. height: 40px;
  237. }
  238. }
  239. }
  240. .option-box {
  241. padding: 0 30px;
  242. margin-top: 60px;
  243. ::v-deep .el-checkbox {
  244. color: #888;
  245. }
  246. }
  247. }
  248. .login-footer-box {
  249. height: 50px;
  250. padding: 15px;
  251. .login__other-item {
  252. cursor: pointer;
  253. }
  254. .login__weixin-icon {
  255. width: 1.5em;
  256. height: 1.5em;
  257. text-align: center;
  258. line-height: 1.5em;
  259. border-radius: 50%;
  260. background-color: #0abd5d;
  261. color: #ffffff;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. </style>