index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. uni.setStorageSync("globalUser", res.data);
  42. commit('setLoading', false);
  43. commit('setLoginUser', userObj);
  44. // commit('setToken', token);
  45. }, _ => {
  46. commit('setLoading', false);
  47. return Promise.reject();
  48. });
  49. },
  50. loginWXCZ({ commit },parm) {
  51. commit('setLoading', true);
  52. return apis.sz.post('/TWeixin/weiXinZhuce',parm)
  53. .then(res => {
  54. //用户名缓存
  55. uni.setStorageSync("name", res.data.name);
  56. const userObj = res.data;
  57. commit('setLoading', false);
  58. commit('setLoginUser', userObj);
  59. return res;
  60. }, _ => {
  61. commit('setLoading', false);
  62. return Promise.reject();
  63. });
  64. },
  65. loginWX({ commit },parm) {
  66. commit('setLoading', true);
  67. return apis.sz.post('/TWeixin/weiXinLogin',parm)
  68. .then(res => {
  69. //用户名缓存
  70. uni.setStorageSync("name", res.data.name);
  71. const userObj = res.data;
  72. commit('setLoading', false);
  73. commit('setLoginUser', userObj);
  74. return res;
  75. }, _ => {
  76. commit('setLoading', false);
  77. return Promise.reject();
  78. });
  79. }
  80. }
  81. });
  82. export default store;