actionCreators.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import * as constants from './constants';
  2. import axios from 'axios';
  3. import {fromJS} from 'immutable';
  4. const changeCategory = (data) => ({
  5. type: constants.GET_CATEGORY,
  6. data: fromJS(data),
  7. });
  8. export const getCategory = () => {
  9. return (dispatch) => {
  10. axios.get('/category/category/v1/list').then((res) => {
  11. if (res.success === 1) {
  12. dispatch(changeCategory(res.models));
  13. }
  14. })
  15. }
  16. };
  17. export const getUser = () => {
  18. return (dispatch) => {
  19. axios.get('/auth/master/v1/get').then((res) => {
  20. if (res.success === 1) {
  21. dispatch({
  22. type: constants.GET_USER,
  23. data: fromJS(res.model)
  24. });
  25. }
  26. })
  27. }
  28. };
  29. export const getConfing = () => {
  30. return (dispatch) => {
  31. axios.get('/config/config-base/v1/list').then((res) => {
  32. if (res.success === 1) {
  33. const {models} = res;
  34. let data = {};
  35. models.forEach(item => {
  36. if (item.configKey === "name") {
  37. data.title = item.configValue;
  38. }
  39. if (item.configKey === "keywords") {
  40. data.keywords = item.configValue;
  41. let oMeta = document.createElement('meta');
  42. oMeta.name = 'keywords';
  43. oMeta.content = item.configValue;
  44. document.getElementsByTagName('head')[0].appendChild(oMeta);
  45. }
  46. if (item.configKey === "description") {
  47. data.description = item.configValue;
  48. let Meta = document.createElement('meta');
  49. Meta.name = 'description';
  50. Meta.content = item.configValue;
  51. document.getElementsByTagName('head')[0].appendChild(Meta);
  52. }
  53. if (item.configKey === "domain") {
  54. data.domain = item.configValue;
  55. }
  56. if (item.configKey === "copyright") {
  57. data.copyright = item.configValue;
  58. }
  59. if (item.configKey === "metas") {
  60. data.metas = item.configValue;
  61. }
  62. if (item.configKey === "icp") {
  63. data.icp = item.configValue;
  64. }
  65. });
  66. dispatch({
  67. type: constants.GET_CONFING,
  68. data: fromJS(data)
  69. });
  70. }
  71. })
  72. }
  73. };