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. const encryptPwd = MD5(password);
  33. // const encryptPwd = password;
  34. const data = { username, password: encryptPwd };
  35. return apis.sz.post('/TAdmin/userLogin', data)
  36. .then(res => {
  37. //用户名缓存
  38. uni.setStorageSync("name", res.data.name);
  39. const userObj = res.data;
  40. uni.setStorageSync("globalUser", res.data);
  41. uni.setStorageSync("token", res.token);
  42. commit('setLoading', false);
  43. commit('setLoginUser', userObj);
  44. }, _ => {
  45. commit('setLoading', false);
  46. return Promise.reject();
  47. });
  48. },
  49. loginWXCZ({ commit },parm) {
  50. commit('setLoading', true);
  51. return apis.sz.post('/TWeixin/weiXinZhuce',parm)
  52. .then(res => {
  53. //用户名缓存
  54. uni.setStorageSync("name", res.data.name);
  55. const userObj = res.data;
  56. commit('setLoading', false);
  57. commit('setLoginUser', userObj);
  58. return res;
  59. }, _ => {
  60. commit('setLoading', false);
  61. return Promise.reject();
  62. });
  63. },
  64. loginWX({ commit },parm) {
  65. commit('setLoading', true);
  66. return apis.sz.post('/TWeixin/weiXinLogin',parm)
  67. .then(res => {
  68. //用户名缓存
  69. uni.setStorageSync("name", res.data.name);
  70. uni.setStorageSync("token", res.token);
  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;