index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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('/TUser/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.setStorageSync("level", res.data.level);
  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('/TUserWeixin/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('/TUserWeixin/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. updataPassword({ commit }, { userName,password,oldPassword}) {
  86. commit('setLoading', true);
  87. const encryptPwd = MD5(password);
  88. const oldPwd = MD5(oldPassword);
  89. var oldUserName = uni.getStorageSync("globalUser").userName;
  90. const data = { userName,oldUserName,password:encryptPwd,oldPassword:oldPwd };
  91. return apis.sz.post('/TUser/updataPassword', data)
  92. .then(res => {
  93. //用户名缓存
  94. uni.setStorageSync("name", res.data.name);
  95. const userObj = res.data;
  96. uni.setStorageSync("globalUser", res.data);
  97. uni.setStorageSync("token", res.token);
  98. uni.setStorageSync("level", res.data.level);
  99. commit('setLoading', false);
  100. commit('setLoginUser', userObj);
  101. return res;
  102. }, _ => {
  103. commit('setLoading', false);
  104. // return Promise.reject();
  105. return null;
  106. });
  107. },
  108. add({ commit }, { userName,password,name,level}) {
  109. commit('setLoading', true);
  110. const encryptPwd = MD5(password);
  111. const data = { userName,name,level,password:encryptPwd };
  112. return apis.sz.post('/TUser/add', data)
  113. .then(res => {
  114. return res;
  115. }, _ => {
  116. commit('setLoading', false);
  117. // return Promise.reject();
  118. return null;
  119. });
  120. },
  121. list({ commit },{ userName,password,name,level}) {
  122. commit('setLoading', true);
  123. const encryptPwd = MD5(password);
  124. const data = { userName,name,level,password:encryptPwd };
  125. return apis.sz.post('/TUser/list',data)
  126. .then(res => {
  127. return res;
  128. }, _ => {
  129. commit('setLoading', false);
  130. return null;
  131. });
  132. },
  133. addCode({ commit },{ name,code,remark,flagCode}) {
  134. commit('setLoading', true);
  135. const coding = {name,code,remark,flagCode};
  136. return apis.sz.post('/TCoding/add',coding)
  137. .then(res => {
  138. return res;
  139. }, _ => {
  140. commit('setLoading', false);
  141. return null;
  142. });
  143. }
  144. }
  145. });
  146. export default store;