admin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* eslint no-param-reassign: 0 */
  2. import Vue from "vue";
  3. import admin from "../../api/admin/index";
  4. const state = {};
  5. const getters = {};
  6. const actions = {};
  7. const mutations = {};
  8. const modules = {
  9. songs: {
  10. namespaced: true,
  11. state: {
  12. songs: []
  13. },
  14. getters: {},
  15. actions: {
  16. addSong: ({ commit }, song) => commit("addSong", song),
  17. removeSong: ({ commit }, songId) => commit("removeSong", songId),
  18. updateSong: ({ commit }, updatedSong) =>
  19. commit("updateSong", updatedSong)
  20. },
  21. mutations: {
  22. addSong(state, song) {
  23. state.songs.push(song);
  24. },
  25. removeSong(state, songId) {
  26. state.songs = state.songs.filter(song => {
  27. return song._id !== songId;
  28. });
  29. },
  30. updateSong(state, updatedSong) {
  31. state.songs.forEach((song, index) => {
  32. if (song._id === updatedSong._id)
  33. Vue.set(state.songs, index, updatedSong);
  34. });
  35. }
  36. }
  37. },
  38. stations: {
  39. namespaced: true,
  40. state: {
  41. stations: []
  42. },
  43. getters: {},
  44. actions: {
  45. loadStations: ({ commit }, stations) =>
  46. commit("loadStations", stations),
  47. stationRemoved: ({ commit }, stationId) =>
  48. commit("stationRemoved", stationId),
  49. stationAdded: ({ commit }, station) =>
  50. commit("stationAdded", station)
  51. },
  52. mutations: {
  53. loadStations(state, stations) {
  54. state.stations = stations;
  55. },
  56. stationAdded(state, station) {
  57. state.stations.push(station);
  58. },
  59. stationRemoved(state, stationId) {
  60. state.stations = state.stations.filter(station => {
  61. return station._id !== stationId;
  62. });
  63. }
  64. }
  65. },
  66. reports: {
  67. namespaced: true,
  68. state: {
  69. report: {}
  70. },
  71. getters: {},
  72. actions: {
  73. viewReport: ({ commit }, report) => commit("viewReport", report),
  74. /* eslint-disable-next-line no-unused-vars */
  75. resolveReport: ({ commit }, reportId) => {
  76. return new Promise((resolve, reject) => {
  77. return admin.reports
  78. .resolve(reportId)
  79. .then(res => {
  80. return resolve(res);
  81. })
  82. .catch(err => {
  83. return reject(new Error(err.message));
  84. });
  85. });
  86. }
  87. },
  88. mutations: {
  89. viewReport(state, report) {
  90. state.report = report;
  91. }
  92. }
  93. },
  94. users: {
  95. namespaced: true,
  96. state: {},
  97. getters: {},
  98. actions: {},
  99. mutations: {}
  100. },
  101. news: {
  102. namespaced: true,
  103. state: {
  104. news: []
  105. },
  106. getters: {},
  107. actions: {
  108. addNews: ({ commit }, news) => commit("addNews", news),
  109. removeNews: ({ commit }, newsId) => commit("removeNews", newsId),
  110. updateNews: ({ commit }, updatedNews) =>
  111. commit("updateNews", updatedNews)
  112. },
  113. mutations: {
  114. addNews(state, news) {
  115. state.news.push(news);
  116. },
  117. removeNews(state, newsId) {
  118. state.news = state.news.filter(news => {
  119. return news._id !== newsId;
  120. });
  121. },
  122. updateNews(state, updatedNews) {
  123. state.news.forEach((news, index) => {
  124. if (news._id === updatedNews._id)
  125. Vue.set(state.news, index, updatedNews);
  126. });
  127. }
  128. }
  129. }
  130. };
  131. export default {
  132. namespaced: true,
  133. state,
  134. getters,
  135. actions,
  136. mutations,
  137. modules
  138. };