index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import MD5 from '@/assets/scripts/md5';
  4. import configs from '@/configs/env';
  5. import apis from '@/configs/http';
  6. import chart from '@/store/modules/chart';
  7. Vue.use(Vuex);
  8. const store = new Vuex.Store({
  9. strict: !configs.isProduction,
  10. modules: {
  11. chart
  12. },
  13. state: {
  14. loginUser: {},
  15. token: '',
  16. isLoading: false,
  17. },
  18. mutations: {
  19. setLoginUser(state, loginUser) {
  20. state.loginUser = loginUser;
  21. },
  22. setToken(state, token) {
  23. state.token = token;
  24. },
  25. setLoading(state, flag) {
  26. state.isLoading = flag;
  27. },
  28. },
  29. actions: {
  30. login({ commit }, { username, password }) {
  31. commit('setLoading', true);
  32. console.log(`login actions: `, arguments);
  33. const encryptPwd = MD5(password);
  34. const data = { username, password: encryptPwd };
  35. return apis.sz.post('/TAdmin/userLogin', data)
  36. .then(res => {
  37. // const { token, userObj } = res.data;
  38. //用户名缓存
  39. uni.setStorageSync("name", res.data.name);
  40. const userObj = res.data;
  41. commit('setLoading', false);
  42. commit('setLoginUser', userObj);
  43. // commit('setToken', token);
  44. }, _ => {
  45. commit('setLoading', false);
  46. return Promise.reject();
  47. });
  48. }
  49. }
  50. });
  51. export default store;