guhongwei 4 tahun lalu
induk
melakukan
10fa6be5f8

+ 1 - 1
src/components/common/Header.vue

@@ -49,7 +49,7 @@ export default {
     // 用户名下拉菜单选择事件
     handleCommand(command) {
       if (command == 'loginout') {
-        localStorage.removeItem('user');
+        localStorage.removeItem('token');
         this.$router.push('/login');
       }
     },

+ 6 - 4
src/main.js

@@ -18,7 +18,7 @@ import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
 import './assets/css/icon.css';
 import './components/common/directives';
 import 'babel-polyfill';
-
+const jwt = require('jsonwebtoken');
 Vue.config.productionTip = false;
 Vue.use(VueI18n);
 Vue.use(ElementUI, {
@@ -32,11 +32,13 @@ const i18n = new VueI18n({
 //使用钩子函数对路由进行权限跳转
 router.beforeEach((to, from, next) => {
   document.title = `${to.meta.title} `;
-  const user = localStorage.getItem('user');
-  if (!user && to.path !== '/login') {
+  const token = localStorage.getItem('token');
+  if (!token && to.path !== '/login') {
     next('/login');
   } else {
-    store.commit('setUser', JSON.parse(user), { root: true });
+    let user = jwt.decode(token);
+    console.log(user);
+    store.commit('setUser', user, { root: true });
     next();
   }
 });

+ 1 - 1
src/plugins/check-res.js

@@ -29,7 +29,7 @@ const Plugin = {
       if (_.isFunction(_errText)) {
         return _errText();
       }
-      Message.error(_errText || errmsg);
+      // Message.error(_errText || errmsg);
       Message({ message: _errText || errmsg, duration: 2000 });
       return false;
     };

+ 52 - 0
src/store/adminLogin.js

@@ -0,0 +1,52 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+const jwt = require('jsonwebtoken');
+Vue.use(Vuex);
+const api = {
+  adminLoginInfo: `/api/live/v0/users/admin`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.adminLoginInfo}`, {
+      skip,
+      limit,
+      ...info,
+    });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.adminLoginInfo}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.adminLoginInfo}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.adminLoginInfo}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.adminLoginInfo}/${payload}`);
+    return res;
+  },
+  async login({ commit }, { user }) {
+    const res = await this.$axios.$post(`${api.adminLoginInfo}/login`, user);
+    if (res.errcode === 0) {
+      localStorage.setItem('token', res.data);
+      user = jwt.decode(res.data);
+      commit('setUser', user, { root: true });
+    }
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 2 - 2
src/store/index.js

@@ -2,7 +2,7 @@ import Vue from 'vue';
 import Vuex from 'vuex';
 import * as ustate from './user/state';
 import * as umutations from './user/mutations';
-import login from './login';
+import adminLogin from './adminLogin';
 import place from '@common/src/store/place';
 
 Vue.use(Vuex);
@@ -12,7 +12,7 @@ export default new Vuex.Store({
   mutations: { ...umutations },
   actions: {},
   modules: {
-    login,
+    adminLogin,
     place,
   },
 });

+ 0 - 47
src/store/login.js

@@ -1,47 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  loginInfo: `/api/jh/v1/login`,
-};
-const state = () => ({});
-const mutations = {};
-
-const actions = {
-  async query({ commit }, { skip = 0, limit, ...info } = {}) {
-    const res = await this.$axios.$get(`${api.loginInfo}`, {
-      skip,
-      limit,
-      ...info,
-    });
-    return res;
-  },
-  async login({ commit }, { user }) {
-    const res = await this.$axios.$post(`${api.loginInfo}`, user);
-    if (res.errcode === 0) {
-      localStorage.setItem('user', JSON.stringify(res.data));
-      commit('setUser', res.data, { root: true });
-    }
-    return res;
-  },
-  async fetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.loginInfo}/${payload}`);
-    return res;
-  },
-  async update({ commit }, { id, ...data }) {
-    const res = await this.$axios.$post(`${api.loginInfo}/${id}`, data);
-    return res;
-  },
-
-  async delete({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.loginInfo}/${payload}`);
-    return res;
-  },
-};
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 9 - 10
src/views/Login.vue

@@ -9,12 +9,12 @@
                 <div class="ms-title">后台管理系统</div>
                 <el-form :model="form" :rules="rules" ref="login" label-width="0px" class="ms-content">
                   <el-form-item prop="username">
-                    <el-input v-model="form.tel" placeholder="请输入手机号">
+                    <el-input v-model="form.code_phone" placeholder="请输入手机号">
                       <el-button slot="prepend" icon="el-icon-user"></el-button>
                     </el-input>
                   </el-form-item>
                   <el-form-item prop="password">
-                    <el-input type="password" placeholder="请输入密码" v-model="form.pwd">
+                    <el-input type="password" placeholder="请输入密码" v-model="form.passwd">
                       <el-button slot="prepend" icon="el-icon-lock"></el-button>
                     </el-input>
                   </el-form-item>
@@ -33,7 +33,7 @@
 
 <script>
 import { mapState, createNamespacedHelpers } from 'vuex';
-const { mapActions: login } = createNamespacedHelpers('login');
+const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
 export default {
   metaInfo: { title: '登录' },
   name: 'login',
@@ -50,16 +50,15 @@ export default {
   },
   created() {},
   methods: {
-    ...login(['login']),
+    ...adminLogin(['login']),
     submitForm() {
       this.$refs.login.validate(async valid => {
         if (valid) {
-          // let res = await this.login({ user: this.form });
-          // if (this.$checkRes(res)) {
-          localStorage.setItem('user', JSON.stringify(this.form));
-          this.$message.success('登录成功');
-          this.$router.push('/homeIndex');
-          // }
+          let res = await this.login({ user: this.form });
+          if (this.$checkRes(res)) {
+            this.$message.success('登录成功');
+            this.$router.push('/homeIndex');
+          }
         } else {
           this.$message.error('请输入账号和密码');
           console.log('error submit!!');

+ 38 - 4
src/views/gly/detail.vue

@@ -16,6 +16,7 @@
 <script>
 import dataForm from '@common/src/components/frame/form.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
 export default {
   metaInfo() {
     return { title: this.$route.meta.title };
@@ -39,15 +40,45 @@ export default {
         code: [{ required: true, message: '请输入机构代码或邀请码' }],
         name: [{ required: true, message: '请输入姓名' }],
         phone: [{ required: true, message: '请输入手机号' }],
-        passwd: [{ required: true, message: '请输入密码' }],
+        passwd: [{ required: false, message: '请输入密码' }],
       },
     };
   },
-  created() {},
+  async created() {
+    if (this.id) await this.search();
+  },
   methods: {
+    ...adminLogin(['fetch', 'create', 'update']),
+    // 查询详情
+    async search() {
+      let res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `form`, res.data);
+      }
+    },
     // 提交
-    toSave({ data }) {
-      console.log(data);
+    async toSave({ data }) {
+      data.role = '1';
+      data.pid = this.user.id;
+      if (data.id) {
+        let res = await this.update(data);
+        if (this.$checkRes(res)) {
+          this.$message({
+            message: '信息修改成功',
+            type: 'success',
+          });
+          this.back();
+        }
+      } else {
+        let res = await this.create(data);
+        if (this.$checkRes(res)) {
+          this.$message({
+            message: '信息创建成功',
+            type: 'success',
+          });
+          this.back();
+        }
+      }
     },
     // 返回
     back() {
@@ -56,6 +87,9 @@ export default {
   },
   computed: {
     ...mapState(['user']),
+    id() {
+      return this.$route.query.id;
+    },
   },
   watch: {},
 };

+ 18 - 5
src/views/gly/index.vue

@@ -16,6 +16,7 @@
 <script>
 import dataTable from '@common/src/components/frame/filter-page-table.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: adminLogin } = createNamespacedHelpers('adminLogin');
 export default {
   metaInfo() {
     return { title: this.$route.meta.title };
@@ -51,17 +52,29 @@ export default {
     await this.search();
   },
   methods: {
+    ...adminLogin(['query', 'delete']),
     // 查询列表
-    search({ skip = 0, limit = 10, ...info } = {}) {
-      console.log('列表');
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      let res = await this.query({ skip, limit, role: '1', ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
     },
     // 修改
     toEdit({ data }) {
-      console.log('修改');
+      this.$router.push({ path: '/gly/detail', query: { id: data.id } });
     },
     // 删除
-    toDelete({ data }) {
-      console.log('删除');
+    async toDelete({ data }) {
+      let res = await this.delete(data.id);
+      if (this.$checkRes(res)) {
+        this.$message({
+          message: '信息修改成功',
+          type: 'success',
+        });
+        this.search();
+      }
     },
     // 添加数据
     add() {

+ 1 - 1
vue.config.js

@@ -25,7 +25,7 @@ module.exports = {
         target: 'http://free.liaoningdoupo.com',
       },
       '/api': {
-        target: 'http://free.liaoningdoupo.com',
+        target: 'http://192.168.1.118:9101',
         changeOrigin: true,
         ws: true,
       },