guhongwei hace 4 años
padre
commit
ae1cb28452

+ 12 - 19
src/router/index.js

@@ -5,13 +5,6 @@ import store from '@/store/index';
 Vue.use(VueRouter);
 
 const routes = [
-  // 首页
-  // {
-  //   path: '/',
-  //   name: '',
-  //   meta: { title: '首页', isleftarrow: false },
-  //   component: () => import('../views/index.vue'),
-  // },
   // 直播大厅
   {
     path: '/live/index',
@@ -64,12 +57,12 @@ const routes = [
     meta: { title: '个人中心', isleftarrow: true },
     component: () => import('../views/user/index.vue'),
   },
-  // 错误
+  // 登录
   {
-    path: '/error',
-    name: 'error',
-    meta: { title: '错误页面', isleftarrow: false },
-    component: () => import('../views/error.vue'),
+    path: '/login',
+    name: 'login',
+    meta: { title: '登录', isleftarrow: true },
+    component: () => import('../views/login.vue'),
   },
   // // 绑定
   // {
@@ -375,21 +368,21 @@ const router = new VueRouter({
 });
 router.beforeEach((to, form, next) => {
   if (to.name === 'user_index') {
-    // store.commit('setUser');
-    // if (to.name === 'user_index') {
-    //   next();
-    //   return;
-    // }
     let user = store.state.user;
     if (user) {
       next();
+    } else {
+      next('/login');
     }
-    //下面是没登录的情况,需要跳转页面到用户未登录页
-    else next({ name: 'error' });
   } else {
     store.commit('setUser');
     next();
   }
 });
+const originalPush = VueRouter.prototype.push;
+VueRouter.prototype.push = function push(location, onResolve, onReject) {
+  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
+  return originalPush.call(this, location).catch(err => err);
+};
 
 export default router;

src/store/place.js → src/store/common/place.js


+ 7 - 39
src/store/index.js

@@ -3,30 +3,15 @@ import Vuex from 'vuex';
 //直播大厅
 import dock from './live/dock';
 import chat from './live/chat';
-import place from './place';
 // 科技超市
 import product from './market/product';
 import exportuser from './market/exportuser';
-// import login from '@common/store/login';
-// import marketproduct from '@common/store/market/marketproduct';
-// import expertsuser from '@common/store/market/exportuser';
-// import maarkettype from '@common/store/market/markettype';
-// import productpact from '@common/store/market/productpact';
-// import authUser from './user/auth-user';
-// import dock from '@common/store/live/dock';
-// import wxchattest from './user/wxchattest';
-// import market from '@common/store/market/market';
-// import apply from '@common/store/live/apply';
-// import transaction from '@common/store/market/transaction';
-// import expertsaudit from '@common/store/market/expertsaudit';
-// import exportuser from '@common/store/market/exportuser';
-// import user from './user';
-// import place from './place';
-// import onliveUser from './onlive/user';
-// import gensign from './onlive/gensign';
-// import room from './onlive/room';
+// 登录
+import login from './user/login';
+// 公共
 import * as ustate from '@/store/common/state';
 import * as umutations from '@/store/common/mutations';
+import place from './common/place';
 
 Vue.use(Vuex);
 
@@ -35,31 +20,14 @@ export default new Vuex.Store({
   mutations: { ...umutations },
   actions: {},
   modules: {
+    // 直播大厅
     dock,
     place,
     chat,
     // 科技超市
     product,
     exportuser,
-    // login,
-    // market,
-    // marketproduct,
-    // expertsuser,
-    // maarkettype,
-    // authUser,
-    // dock,
-    // wxchattest,
-    // apply,
-    // transaction,
-    // expertsaudit,
-    // productpact,
-    // exportuser,
-    // user,
-    // dock,
-    // place,
-    // onliveUser,
-    // room,
-    // gensign,
-    //chat,
+    // 登录
+    login,
   },
 });

+ 0 - 0
src/store/login.js


+ 0 - 23
src/store/onlive/gensign.js

@@ -1,23 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  gensignInfo: `/api/onlive/user/gensign`,
-};
-const state = () => ({});
-const mutations = {};
-
-const actions = {
-  async gensignFetch({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.gensignInfo}`, payload);
-    return res;
-  },
-};
-
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 0 - 57
src/store/onlive/room.js

@@ -1,57 +0,0 @@
-// 房间
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  roomInfo: `/api/onlive/room`,
-  lookuserInfo: `/api/onlive/lookuser`,
-};
-const state = () => ({});
-const mutations = {};
-
-const actions = {
-  async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
-    const res = await this.$axios.$get(api.roomInfo, {
-      skip,
-      limit,
-      ...info,
-    });
-    return res;
-  },
-  async create({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.roomInfo}`, payload);
-    return res;
-  },
-  // 记录观看
-  async lookuserFetch({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.lookuserInfo}`, payload);
-    return res;
-  },
-  // 名字查详情
-  async roomfetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.roomInfo}/roomname`, payload);
-    return res;
-  },
-  async fetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.roomInfo}/${payload}`);
-    return res;
-  },
-  async update({ commit }, { id, ...info } = {}) {
-    const res = await this.$axios.$post(`${api.roomInfo}/update/${id}`, {
-      ...info,
-    });
-    return res;
-  },
-  async delete({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.roomInfo}/${payload}`);
-    return res;
-  },
-};
-
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 0 - 39
src/store/onlive/user.js

@@ -1,39 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  onliveInfo: `/api/onlive/user`,
-};
-const state = () => ({});
-const mutations = {};
-
-const actions = {
-  async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
-    const res = await this.$axios.$get(api.onliveInfo, { skip, limit, ...info });
-    return res;
-  },
-  async create({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.onliveInfo}`, payload);
-    return res;
-  },
-  async fetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.onliveInfo}/${payload}`);
-    return res;
-  },
-  async update({ commit }, { id, ...info } = {}) {
-    const res = await this.$axios.$post(`${api.onliveInfo}/${id}`, { ...info });
-    return res;
-  },
-  async delete({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.onliveInfo}/${payload}`);
-    return res;
-  },
-};
-
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 0 - 39
src/store/user.js

@@ -1,39 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  interface: `/api/market/user`,
-};
-const state = () => ({});
-const mutations = {};
-
-const actions = {
-  async query({ commit }, { skip = 0, limit = 10, ...info } = {}) {
-    const res = await this.$axios.$get(api.interface, { skip, limit, ...info });
-    return res;
-  },
-  async create({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.interface}`, payload);
-    return res;
-  },
-  async fetch({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.interface}/${payload}`);
-    return res;
-  },
-  async update({ commit }, { id, ...info } = {}) {
-    const res = await this.$axios.$post(`${api.interface}/${id}`, { ...info });
-    return res;
-  },
-  async delete({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
-    return res;
-  },
-};
-
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 0 - 54
src/store/user/auth-user.js

@@ -1,54 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-//用户的菜单选项增删改查
-Vue.use(Vuex);
-const api = {
-  interface: `/api/auth/user`,
-  getMenu: `/api/auth/user/menus`,
-  bindInfo: `/api/auth/user/bind`,
-  dockInfo: `/api/auth/wxbind`,
-};
-const state = () => ({});
-const mutations = {};
-
-const actions = {
-  async query({ commit }, { skip = 0, limit = undefined, ...info } = {}) {
-    const res = await this.$axios.$get(api.interface, { skip, limit, ...info });
-    return res;
-  },
-  async create({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.interface}`, payload);
-    return res;
-  },
-  async fetch({ commit }, payload) {
-    //特殊变化,查用户菜单
-    const res = await this.$axios.$get(`${api.getMenu}`, payload);
-    return res;
-  },
-  async update({ commit }, { id, ...info } = {}) {
-    const res = await this.$axios.$post(`${api.interface}/update/${id}`, {
-      ...info,
-    });
-    return res;
-  },
-  async delete({ commit }, payload) {
-    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
-    return res;
-  },
-  async bind({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.bindInfo}`, payload);
-    return res;
-  },
-  async dockInfos({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.dockInfo}`, payload);
-    return res;
-  },
-};
-
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 131 - 0
src/store/user/login.js

@@ -0,0 +1,131 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import axios from 'axios';
+import _ from 'lodash';
+import { Notification } from 'element-ui';
+const jwt = require('jsonwebtoken');
+Vue.use(Vuex);
+const api = {
+  interface: `/api/auth/login`,
+  getUser: `/api/auth/token`,
+  logout: '/api/auth/logout',
+  getMenu: `/api/auth/user/menus`,
+  updatePassword: '/api/user/pwd_edit',
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  /**
+    user:Object required 登陆信息 
+    router:router 如果跳转就传
+    path:String 跳转到的路由位置
+    needReturn: Boolean 是否返回结果
+    typeCheck: Boolean 是否检查身份对应匹配的前端项目
+    isWx: Boolean 是否是微信登陆
+    needNotice:Boolean 是否需要提示
+   */
+  async login({ commit, dispatch }, { user, router, path = '/', needReturn = false, typeCheck = false, isWx = false, needNotice = true }) {
+    let res;
+    //wx登陆,openid存在,user中是openid和qrcode;正常登陆,user中是mobile和passwd
+    if (isWx) res = await this.$axios.$post(`${api.wxLogin}`, user);
+    else res = await this.$axios.$post(`${api.interface}`, user);
+    const setUser = async (token, commit) => {
+      localStorage.setItem('token', token);
+      let userInfo = await dispatch('toGetUser');
+      return userInfo;
+    };
+    let userInfo = {};
+    if (res.errcode == '0') {
+      userInfo = await setUser(res.data.key, commit);
+      Notification({
+        title: '登录成功',
+        // message: `欢迎,${user.user_name}`,
+        type: 'success',
+        duration: 2000,
+        offset: 50,
+      });
+      return userInfo;
+    } else {
+      if (needReturn) return res;
+      else {
+        Notification({
+          title: '登录失败',
+          message: `失败原因:${res.errmsg || '登陆失败'}`,
+          type: 'error',
+        });
+      }
+    }
+  },
+  async toGetUser({ commit }, payload) {
+    let key = localStorage.getItem('token');
+    if (!key) {
+      if (_.isFunction(payload)) {
+        payload();
+        return;
+      }
+      let user = localStorage.getItem('user');
+      if (user) {
+        commit('setUser', JSON.parse(user), { root: true });
+      } else {
+        let stamp = new Date().getTime();
+        let name = `游客${stamp}`;
+        let obj = { name, suid: stamp, role: '7' };
+        localStorage.setItem('user', JSON.stringify(obj));
+        commit('setUser', obj, { root: true });
+      }
+      return;
+    }
+    let res = await axios.post(api.getUser, { key: key });
+    let user = {};
+    if (res.data.errcode == '0') {
+      let token = _.get(res, `data.data.token`);
+      if (token) {
+        user = jwt.decode(token);
+        // console.log(user);
+        commit('setUser', user, { root: true });
+      }
+    }
+    return user;
+  },
+  async toGetMenu({ commit }, payload) {
+    const res = await this.$axios.$get(api.getMenu, payload);
+    return res;
+  },
+  async logout({ commit }, payload) {
+    let key = localStorage.removeItem('token');
+    const res = await this.$axios.$post(api.logout, { key: key });
+    commit('deleteUser');
+  },
+  async update({ commit }, payload) {
+    let res = await this.$axios.$post(`${api.updatePassword}`, {
+      data: payload,
+    });
+    return res;
+  },
+  async bind({ commit }, payload) {
+    let res = await this.$axios.$post(`${api.bind}`, payload);
+    return res;
+  },
+  async userBind({ commit }, payload) {
+    let res = await this.$axios.$post(`${api.userBind}`, payload);
+    return res;
+  },
+  async getQrcode({ commit }, payload) {
+    let res = await this.$axios.$get(`${api.connection}`);
+    if (res.errcode === 0) return res.data;
+    else {
+      console.warn('请求qrcode失败');
+    }
+  },
+  async wxCheck({ commit }, payload) {
+    let res = await this.$axios.$post(`${api.wxCheck}`, payload);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 0 - 34
src/store/user/wxchattest.js

@@ -1,34 +0,0 @@
-import Vue from 'vue';
-import Vuex from 'vuex';
-import _ from 'lodash';
-Vue.use(Vuex);
-const api = {
-  wxchattestInfo: `/api/auth/wxchattest`,
-};
-const state = () => ({});
-const mutations = {
-  setUser(state, payload) {
-    if (payload) {
-      state.user = payload;
-      sessionStorage.setItem('user', JSON.stringify(payload));
-    } else {
-      let user = sessionStorage.getItem('user');
-      if (user) state.user = JSON.parse(user);
-      else return false;
-    }
-  },
-};
-
-const actions = {
-  async login({ commit }, payload) {
-    const res = await this.$axios.$get(`${api.wxchattestInfo}`, payload);
-    return res;
-  },
-};
-
-export default {
-  namespaced: true,
-  state,
-  mutations,
-  actions,
-};

+ 145 - 0
src/views/login.vue

@@ -0,0 +1,145 @@
+<template>
+  <div id="index">
+    <el-row>
+      <el-col :span="24" class="style">
+        <el-col :span="24" class="top">
+          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
+        </el-col>
+        <el-col :span="24" class="main">
+          <van-tabs>
+            <van-tab title="平台登录">
+              <el-col :span="24">
+                <van-form>
+                  <van-field v-model="webform.phone" name="手机/统一社会信用代码" label="手机/统一社会信用代码" placeholder="手机/统一社会信用代码" />
+                  <van-field v-model="webform.passwd" type="password" name="密码" label="密码" placeholder="密码" />
+                  <van-field name="radio" label="用户类别">
+                    <template #input>
+                      <van-radio-group v-model="webform.role" direction="horizontal">
+                        <van-radio name="4">个人</van-radio>
+                        <van-radio name="5">机构</van-radio>
+                        <van-radio name="6">专家</van-radio>
+                        <van-radio name="2">VIP用户</van-radio>
+                      </van-radio-group>
+                    </template>
+                  </van-field>
+                  <div style="margin: 16px;">
+                    <van-button round block type="info" @click="onwebSubmit">
+                      登录
+                    </van-button>
+                  </div>
+                </van-form>
+              </el-col>
+            </van-tab>
+            <van-tab title="管理登录">
+              <el-col :span="24">
+                <van-form>
+                  <van-field v-model="form.phone" name="手机/机构代码" label="手机/机构代码" placeholder="手机/机构代码" />
+                  <van-field v-model="form.passwd" type="password" name="密码" label="密码" placeholder="密码" />
+                  <van-field name="radio" label="用户类别">
+                    <template #input>
+                      <van-radio-group v-model="form.role">
+                        <van-radio name="1">合作机构/业务管理员</van-radio>
+                      </van-radio-group>
+                    </template>
+                  </van-field>
+                  <div style="margin: 16px;">
+                    <van-button round block type="info" @click="onSubmit">
+                      登录
+                    </van-button>
+                  </div>
+                </van-form>
+              </el-col>
+            </van-tab>
+          </van-tabs>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import NavBar from '@/layout/common/topInfo.vue';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: login } = createNamespacedHelpers('login');
+export default {
+  name: 'index',
+  props: {},
+  components: {
+    NavBar,
+  },
+  data: function() {
+    return {
+      // 头部标题
+      title: '',
+      // meta为true
+      isleftarrow: '',
+      // 返回
+      navShow: true,
+      // 平台登录
+      webform: {},
+      // 管理登录
+      form: {},
+    };
+  },
+  created() {},
+  methods: {
+    ...login({ toLogin: 'login' }),
+    // 平台登录
+    async onwebSubmit() {
+      let data = this.webform;
+      const res = await this.toLogin({ user: data });
+      if (res.uid) {
+        this.$router.push({ path: '/user/index' });
+      }
+    },
+    // 管理登录
+    async onSubmit() {
+      let data = this.form;
+      if (data.role == null) {
+        data.role = '0';
+        const res = await this.toLogin({ user: data });
+        if (res.uid) {
+          this.$router.push({ path: '/user/index' });
+        }
+      } else {
+        const res = await this.toLogin({ user: data });
+        if (res.uid) {
+          this.$router.push({ path: '/user/index' });
+        }
+      }
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+  },
+  mounted() {
+    this.title = this.$route.meta.title;
+    this.isleftarrow = this.$route.meta.isleftarrow;
+  },
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.style {
+  width: 100%;
+  min-height: 667px;
+  position: relative;
+  background-color: #f9fafc;
+}
+.top {
+  height: 46px;
+  overflow: hidden;
+}
+.main {
+  min-height: 570px;
+}
+/deep/.van-field__label {
+  width: 7.2em;
+}
+/deep/.van-radio--horizontal {
+  margin: 0 15px 10px 0;
+}
+</style>