|
@@ -0,0 +1,90 @@
|
|
|
|
+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/count/user/login`,
|
|
|
|
+ logout: '/api/count/user/logout',
|
|
|
|
+ updatePassword: '/api/count/user/uppasswd',
|
|
|
|
+};
|
|
|
|
+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
|
|
|
|
+ res = await this.$axios.$post(`${api.interface}`, user);
|
|
|
|
+ const setUser = async (token, commit) => {
|
|
|
|
+ localStorage.setItem('token', token);
|
|
|
|
+ };
|
|
|
|
+ let userInfo = {};
|
|
|
|
+ if (res.errcode == '0') {
|
|
|
|
+ setUser(res.data, commit);
|
|
|
|
+ Notification({
|
|
|
|
+ title: '登录成功',
|
|
|
|
+ type: 'success',
|
|
|
|
+ duration: 2000,
|
|
|
|
+ });
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ if (needReturn) return res;
|
|
|
|
+ else {
|
|
|
|
+ Notification({
|
|
|
|
+ title: '登录失败',
|
|
|
|
+ message: `失败原因:${res.errmsg || '登陆失败'}`,
|
|
|
|
+ type: 'error',
|
|
|
|
+ });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ 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,
|
|
|
|
+};
|