index.js 2.3 KB

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