Browse Source

更新登录

guhongwei 5 years ago
parent
commit
465d57caff

+ 1 - 0
package.json

@@ -11,6 +11,7 @@
     "axios": "^0.19.2",
     "core-js": "^3.6.4",
     "element-ui": "^2.13.0",
+    "jsonwebtoken": "^8.5.1",
     "loadsh": "0.0.4",
     "naf-core": "^0.1.2",
     "vue": "^2.6.11",

BIN
src/assets/back.png


BIN
src/assets/框.png


+ 20 - 6
src/layout/layout-part/heads.vue

@@ -7,9 +7,9 @@
         </el-col>
         <el-col :span="6" class="admin">
           <i class="el-icon-user icon"></i>
-          <span class="name">管理员:admin</span>
+          <span class="name">管理员:{{ user.name }}</span>
           <span class="shu">|</span>
-          <el-link :underline="false" class="out">退出</el-link>
+          <el-link :underline="false" class="out" @click="toLogout()">退出</el-link>
         </el-col>
       </el-col>
     </el-row>
@@ -17,8 +17,7 @@
 </template>
 
 <script>
-import { mapActions, mapState, mapMutations } from 'vuex';
-
+import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
 export default {
   name: 'heads',
   props: {},
@@ -26,8 +25,23 @@ export default {
   data: () => ({}),
   created() {},
   watch: {},
-  computed: {},
-  methods: {},
+  computed: {
+    ...mapState(['user']),
+  },
+  methods: {
+    ...mapMutations(['deleteUser']),
+    async toLogout() {
+      this.deleteUser();
+      this.$message({
+        message: '注销成功',
+        type: 'success',
+      });
+      this.toLogin();
+    },
+    async toLogin() {
+      this.$router.push({ name: 'login' });
+    },
+  },
 };
 </script>
 

+ 148 - 130
src/router/index.js

@@ -1,136 +1,154 @@
 import Vue from 'vue';
-import Router from 'vue-router';
-Vue.use(Router);
+import VueRouter from 'vue-router';
+import store from '@/store/index';
 
-export default new Router({
-  mode: 'history',
-  base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
-  routes: [
-    {
-      path: '/home',
-      component: () => import('../views/home/index.vue'),
-    },
-    // 金融数字超市-债权产品
-    {
-      path: '/supermarket/debt',
-      component: () => import('../views/supermarket/debt.vue'),
-    },
-    {
-      path: '/supermarket/debtdetail',
-      component: () => import('../views/supermarket/debtdetail.vue'),
-    },
-    {
-      path: '/supermarket/debtdetails',
-      component: () => import('../views/supermarket/debtdetails.vue'),
-    },
-    {
-      path: '/finance/index',
-      component: () => import('../views/finance/index.vue'),
-    },
-    //新闻中心
-    {
-      path: '/news/index',
-      component: () => import('../views/news/index.vue'),
-    },
-    //新闻中心详情
-    {
-      path: '/news/detail',
-      component: () => import('../views/news/detail.vue'),
-    },
-    // 金融数字超市 - 股权产品
-    {
-      path: '/supermarket/stock',
-      component: () => import('../views/supermarket/stock.vue'),
-    },
-    // 金融机构
-    {
-      path: '/institution/index/:status',
-      component: () => import('../views/institution/index.vue'),
-    },
-    // 金融机构添加
-    {
-      path: '/institution/detail',
-      component: () => import('../views/institution/detail.vue'),
-    },
-    // 其他用户管理-列表
-    {
-      path: '/otheruser/index',
-      component: () => import('../views/otheruser/index.vue'),
-    },
-    // 其他用户管理-添加
-    {
-      path: '/otheruser/detail',
-      component: () => import('../views/otheruser/detail.vue'),
-    },
-    // 企业用户管理-详情
-    {
-      path: '/companyuser/index',
-      component: () => import('../views/companyuser/index.vue'),
-    },
-    //指导单位
-    {
-      path: '/zhidao/index',
-      component: () => import('../views/zhidao/index.vue'),
-    },
-    {
-      path: '/zhidao/detail',
-      component: () => import('../views/zhidao/detail.vue'),
-    },
+Vue.use(VueRouter);
+const routes = [
+  {
+    path: '/home',
+    component: () => import('../views/home/index.vue'),
+  },
+  // 金融数字超市-债权产品
+  {
+    path: '/supermarket/debt',
+    component: () => import('../views/supermarket/debt.vue'),
+  },
+  {
+    path: '/supermarket/debtdetail',
+    component: () => import('../views/supermarket/debtdetail.vue'),
+  },
+  {
+    path: '/supermarket/debtdetails',
+    component: () => import('../views/supermarket/debtdetails.vue'),
+  },
+  {
+    path: '/finance/index',
+    component: () => import('../views/finance/index.vue'),
+  },
+  //新闻中心
+  {
+    path: '/news/index',
+    component: () => import('../views/news/index.vue'),
+  },
+  //新闻中心详情
+  {
+    path: '/news/detail',
+    component: () => import('../views/news/detail.vue'),
+  },
+  // 金融数字超市 - 股权产品
+  {
+    path: '/supermarket/stock',
+    component: () => import('../views/supermarket/stock.vue'),
+  },
+  // 金融机构
+  {
+    path: '/institution/index/:status',
+    component: () => import('../views/institution/index.vue'),
+  },
+  // 金融机构添加
+  {
+    path: '/institution/detail',
+    component: () => import('../views/institution/detail.vue'),
+  },
+  // 其他用户管理-列表
+  {
+    path: '/otheruser/index',
+    component: () => import('../views/otheruser/index.vue'),
+  },
+  // 其他用户管理-添加
+  {
+    path: '/otheruser/detail',
+    component: () => import('../views/otheruser/detail.vue'),
+  },
+  // 企业用户管理-详情
+  {
+    path: '/companyuser/index',
+    component: () => import('../views/companyuser/index.vue'),
+  },
+  //指导单位
+  {
+    path: '/zhidao/index',
+    component: () => import('../views/zhidao/index.vue'),
+  },
+  {
+    path: '/zhidao/detail',
+    component: () => import('../views/zhidao/detail.vue'),
+  },
 
-    // 企业信息管理-列表
-    {
-      path: '/companyup/index',
-      component: () => import('../views/companyup/index.vue'),
-    },
-    // 企业信息管理-详情
-    {
-      path: '/companyup/detail',
-      component: () => import('../views/companyup/detail.vue'),
-    },
-    // 企业认证管理
-    {
-      path: '/companyidentify/index',
-      component: () => import('../views/companyidentify/index.vue'),
-    },
-    // 企业认证管理-审核
-    {
-      path: '/companyidentify/detail',
-      component: () => import('../views/companyidentify/detail.vue'),
-    },
-    // 角色管理-列表
-    {
-      path: '/character/index',
-      component: () => import('../views/character/index.vue'),
-    },
-    // 角色管理-详情
-    {
-      path: '/character/detail',
-      component: () => import('../views/character/detail.vue'),
-    },
-    // 地区管理-列表
-    {
-      path: '/region/index',
-      component: () => import('../views/region/index.vue'),
-    },
-    // 地区管理-详情
-    {
-      path: '/region/detail',
-      component: () => import('../views/region/detail.vue'),
-    },
+  // 企业信息管理-列表
+  {
+    path: '/companyup/index',
+    component: () => import('../views/companyup/index.vue'),
+  },
+  // 企业信息管理-详情
+  {
+    path: '/companyup/detail',
+    component: () => import('../views/companyup/detail.vue'),
+  },
+  // 企业认证管理
+  {
+    path: '/companyidentify/index',
+    component: () => import('../views/companyidentify/index.vue'),
+  },
+  // 企业认证管理-审核
+  {
+    path: '/companyidentify/detail',
+    component: () => import('../views/companyidentify/detail.vue'),
+  },
+  // 角色管理-列表
+  {
+    path: '/character/index',
+    component: () => import('../views/character/index.vue'),
+  },
+  // 角色管理-详情
+  {
+    path: '/character/detail',
+    component: () => import('../views/character/detail.vue'),
+  },
+  // 地区管理-列表
+  {
+    path: '/region/index',
+    component: () => import('../views/region/index.vue'),
+  },
+  // 地区管理-详情
+  {
+    path: '/region/detail',
+    component: () => import('../views/region/detail.vue'),
+  },
 
-    //融资专家
-    {
-      path: '/specialist/index',
-      component: () => import('../views/specialist/index.vue'),
-    },
-    {
-      path: '/specialist/detail',
-      component: () => import('../views/specialist/detail.vue'),
-    },
+  //融资专家
+  {
+    path: '/specialist/index',
+    component: () => import('../views/specialist/index.vue'),
+  },
+  {
+    path: '/specialist/detail',
+    component: () => import('../views/specialist/detail.vue'),
+  },
 
-    {
-      path: '/login',
-      component: () => import('../views/login.vue'),
-    },
-  ],
+  {
+    path: '/login',
+    name: 'login',
+    component: () => import('../views/login.vue'),
+  },
+];
+const router = new VueRouter({
+  mode: 'history',
+  base: process.env.NODE_ENV === 'development' ? '' : '',
+  routes,
 });
+router.beforeEach((to, form, next) => {
+  store.commit('setUser');
+  if (to.name === 'login') {
+    next();
+    return;
+  }
+  let user = store.state.user;
+  if (user) {
+    next();
+  }
+  //下面是没登录的情况,需要跳转页面到用户未登录页
+  else next({ name: 'login' });
+});
+
+export default router;

+ 6 - 2
src/store/index.js

@@ -9,6 +9,9 @@ import character from './character';
 import menurole from './menurole';
 import region from './region';
 import profession from './profession';
+import login from './login';
+import * as muta from './user/mutations';
+import * as states from './user/state';
 
 Vue.use(Vuex);
 
@@ -23,8 +26,9 @@ export default new Vuex.Store({
     menurole,
     region,
     profession,
+    login,
   },
-  state: {},
-  mutations: {},
+  state: { ...states },
+  mutations: { ...muta },
   actions: {},
 });

+ 23 - 0
src/store/login.js

@@ -0,0 +1,23 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  otheruserLogin: `/api/financial/otheruser/login`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  //用户信息
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.otheruserLogin}`, payload);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 26 - 0
src/store/user/mutations.js

@@ -0,0 +1,26 @@
+const jwt = require('jsonwebtoken');
+export const setUser = (state, payload) => {
+  let res = true;
+  //登陆时
+  if (payload) state.user = payload;
+  else {
+    //已经登陆,切换路由时取出用户信息放在总store中
+    let token = sessionStorage.getItem('token');
+    let user;
+    if (token) {
+      user = jwt.decode(token);
+    }
+    if (user) state.user = user;
+    else {
+      res = false;
+      state.user = undefined;
+      console.warn('用户未登录');
+    }
+  }
+  return res;
+};
+
+export const deleteUser = (state, payload) => {
+  state.user = undefined;
+  sessionStorage.removeItem('user');
+};

+ 1 - 0
src/store/user/state.js

@@ -0,0 +1 @@
+export const user = {};

+ 53 - 42
src/views/login.vue

@@ -4,25 +4,19 @@
       <el-col :span="24" class="login" :style="'background: url(' + loginBei + ')no-repeat center center;'">
         <el-col :span="12" class="info">
           <el-col :span="24" class="topTitle">
-            后台登录系统
+            <p>吉林省小微企业金融</p>
+            <p>综合服务管理平台</p>
           </el-col>
-          <el-col :span="24">
-            <el-form ref="form" :model="form" label-width="80px">
-              <el-form-item label="登录名称">
-                <el-input v-model="form.name" placeholder="请输入名称"></el-input>
+          <el-col :span="24" class="kuang" :style="'background: url(' + kuang + ')no-repeat center center;'">
+            <el-form ref="form" :model="form">
+              <el-form-item>
+                <el-input placeholder="请输入手机号" prefix-icon="el-icon-user" v-model="form.phone"> </el-input>
               </el-form-item>
-              <el-form-item label="登录密码">
-                <el-input v-model="form.password" placeholder="请输入密码" show-password></el-input>
-              </el-form-item>
-              <el-form-item label="用户类型">
-                <el-select v-model="form.type" placeholder="请选择用户类型">
-                  <el-option label="金控集团" value="0"></el-option>
-                  <el-option label="金融机构" value="1"></el-option>
-                  <el-option label="政府机构" value="2"></el-option>
-                </el-select>
+              <el-form-item>
+                <el-input placeholder="请输入密码" prefix-icon="el-icon-lock" v-model="form.passwd" show-password> </el-input>
               </el-form-item>
               <el-row class="btn">
-                <el-button type="success" @click="onSubmit">登录</el-button>
+                <el-button @click="onSubmit">登录</el-button>
               </el-row>
             </el-form>
           </el-col>
@@ -33,59 +27,76 @@
 </template>
 
 <script>
+import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
+const { mapActions: login } = createNamespacedHelpers('login');
+const jwt = require('jsonwebtoken');
 export default {
   name: 'login',
   props: {},
   components: {},
   data: () => ({
-    loginBei: require('@/assets/logo.jpg'),
+    loginBei: require('@/assets/back.png'),
+    kuang: require('@/assets/框.png'),
     form: {},
   }),
   created() {},
   computed: {},
   methods: {
-    onSubmit(form) {
-      console.log(this.form);
+    ...login(['create']),
+    async onSubmit() {
+      this.form.type = '0';
+      let data = this.form;
+      console.log(data);
+      const result = await this.create(data);
+      this.$message({
+        type: `${result.errcode}` === '0' ? 'success' : 'error',
+        message: `${result.errcode}` === '0' ? '登录成功' : result.errmsg,
+      });
+      if (`${result.errcode}` === '0') {
+        sessionStorage.setItem('token', result.data);
+        this.$router.push({ path: '/' });
+      }
     },
   },
 };
 </script>
 
 <style lang="less" scoped>
+p {
+  padding: 0;
+  margin: 0;
+}
 .login {
   height: 100vh;
 }
-.info {
+.topTitle {
   position: absolute;
-  top: 20%;
-  left: 32%;
-  width: 600px;
-  height: 500px;
-  background-color: #ffffff5f;
-  border: 1px solid #ccc;
-  border-radius: 10px;
+  top: 340px;
 }
-.topTitle {
-  padding: 50px 0;
+.topTitle p {
   text-align: center;
   font-size: 30px;
-  color: #fff;
-}
-.el-form {
-  padding: 0 60px;
+  font-family: Source Han Sans CN;
+  font-weight: bold;
+  color: rgba(255, 255, 255, 1);
 }
-/deep/.el-form-item__label {
-  color: #fff;
-  font-size: 16px;
+.kuang {
+  width: 411px;
+  height: 290px;
+  position: absolute;
+  top: 420px;
+  left: 39%;
+  padding: 77px 56px;
 }
-/deep/.el-form-item {
-  margin-bottom: 40px;
-}
-.btn {
-  text-align: center;
-  padding: 15px 0;
+/deep/.el-input__inner {
+  border-radius: 20px;
 }
 .btn .el-button {
-  width: 50%;
+  width: 300px;
+  height: 40px;
+  background: rgba(233, 2, 29, 1);
+  border-radius: 20px;
+  border: none;
+  color: #fff;
 }
 </style>