123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import Vue from 'vue';
- import Vuex from 'vuex';
- import MD5 from '@/assets/scripts/md5';
- import configs from '@/configs/env';
- import apis from '@/configs/http';
- import chart from '@/store/modules/chart';
- Vue.use(Vuex);
- const store = new Vuex.Store({
- strict: !configs.isProduction,
- modules: {
- chart
- },
- state: {
- loginUser: {},
- token: '',
- isLoading: false,
- },
- mutations: {
- setLoginUser(state, loginUser) {
- state.loginUser = loginUser;
- },
- setToken(state, token) {
- state.token = token;
- },
- setLoading(state, flag) {
- state.isLoading = flag;
- },
- },
- actions: {
- login({ commit }, { userName, password }) {
- commit('setLoading', true);
- // console.log(`login actions: `, arguments);
- const encryptPwd = MD5(password);
- const data = { userName, password: encryptPwd };
- return apis.sz.post('/TUser/userLogin', data)
- .then(res => {
- // const { token, userObj } = res.data;
- //用户名缓存
- uni.setStorageSync("name", res.data.name);
- const userObj = res.data;
- uni.setStorageSync("globalUser", res.data);
- uni.setStorageSync("token", res.token);
- uni.setStorageSync("level", res.data.level);
- // uni.setCookie(res.token);
- // uni.setToken(res.token);
- commit('setLoading', false);
- commit('setLoginUser', userObj);
- // commit('setToken', token);
- }, _ => {
- commit('setLoading', false);
- return Promise.reject();
- });
- },
- loginWXCZ({ commit },parm) {
- commit('setLoading', true);
- return apis.sz.post('/TUserWeixin/weiXinZhuce',parm)
- .then(res => {
- //用户名缓存
- uni.setStorageSync("name", res.data.name);
- const userObj = res.data;
- commit('setLoading', false);
- commit('setLoginUser', userObj);
-
- return res;
- }, _ => {
- commit('setLoading', false);
- return Promise.reject();
- });
- },
- loginWX({ commit },parm) {
- commit('setLoading', true);
- return apis.sz.post('/TUserWeixin/weiXinLogin',parm)
- .then(res => {
- //用户名缓存
- uni.setStorageSync("name", res.data.name);
- uni.setStorageSync("token", res.token);
- const userObj = res.data;
- commit('setLoading', false);
- commit('setLoginUser', userObj);
-
- return res;
- }, _ => {
- commit('setLoading', false);
- return Promise.reject();
- });
- },
- updataPassword({ commit }, { userName,password,oldPassword}) {
- commit('setLoading', true);
- const encryptPwd = MD5(password);
- const oldPwd = MD5(oldPassword);
- var oldUserName = uni.getStorageSync("globalUser").userName;
- const data = { userName,oldUserName,password:encryptPwd,oldPassword:oldPwd };
- return apis.sz.post('/TUser/updataPassword', data)
- .then(res => {
- //用户名缓存
- uni.setStorageSync("name", res.data.name);
- const userObj = res.data;
- uni.setStorageSync("globalUser", res.data);
- uni.setStorageSync("token", res.token);
- uni.setStorageSync("level", res.data.level);
- commit('setLoading', false);
- commit('setLoginUser', userObj);
- return res;
- }, _ => {
- commit('setLoading', false);
- // return Promise.reject();
- return null;
- });
- },
-
- add({ commit }, { userName,password,name,level}) {
- commit('setLoading', true);
- const encryptPwd = MD5(password);
- const data = { userName,name,level,password:encryptPwd };
- return apis.sz.post('/TUser/add', data)
- .then(res => {
- return res;
- }, _ => {
- commit('setLoading', false);
- // return Promise.reject();
- return null;
- });
- },
- list({ commit },{ userName,password,name,level}) {
- commit('setLoading', true);
- const encryptPwd = MD5(password);
- const data = { userName,name,level,password:encryptPwd };
- return apis.sz.post('/TUser/list',data)
- .then(res => {
- return res;
- }, _ => {
- commit('setLoading', false);
- return null;
- });
- },
- addCode({ commit },{ name,code,remark,flagCode}) {
- commit('setLoading', true);
- const coding = {name,code,remark,flagCode};
- return apis.sz.post('/TCoding/add',coding)
- .then(res => {
- return res;
- }, _ => {
- commit('setLoading', false);
- return null;
- });
- }
- }
- });
- export default store;
|