index.js 2.2 KB

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