admin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* eslint no-param-reassign: 0 */
  2. const state = {};
  3. const getters = {};
  4. const actions = {};
  5. const mutations = {};
  6. const modules = {
  7. songs: {
  8. namespaced: true,
  9. state: {
  10. video: {
  11. player: null,
  12. paused: true,
  13. playerReady: false,
  14. autoPlayed: false,
  15. currentTime: 0
  16. },
  17. editing: {}
  18. },
  19. getters: {},
  20. actions: {
  21. editSong: ({ commit }, song) => commit("editSong", song),
  22. stopVideo: ({ commit }) => commit("stopVideo"),
  23. loadVideoById: ({ commit }, id, skipDuration) =>
  24. commit("loadVideoById", id, skipDuration),
  25. pauseVideo: ({ commit }, status) => commit("pauseVideo", status),
  26. getCurrentTime: ({ commit, state }, fixedVal) => {
  27. return new Promise(resolve => {
  28. commit("getCurrentTime", fixedVal);
  29. resolve(state.video.currentTime);
  30. });
  31. }
  32. },
  33. mutations: {
  34. editSong(state, song) {
  35. state.editing = { ...song };
  36. },
  37. stopVideo(state) {
  38. state.video.player.stopVideo();
  39. },
  40. loadVideoById(state, id, skipDuration) {
  41. state.video.player.loadVideoById(id, skipDuration);
  42. },
  43. pauseVideo(state, status) {
  44. if (status) state.video.player.pauseVideo();
  45. else state.video.player.playVideo();
  46. state.video.paused = status;
  47. },
  48. getCurrentTime(state, fixedVal) {
  49. if (!state.playerReady) state.video.currentTime = 0;
  50. else {
  51. Promise.resolve(state.video.player.getCurrentTime()).then(
  52. time => {
  53. if (fixedVal)
  54. Promise.resolve(time.toFixed(fixedVal)).then(
  55. fixedTime => {
  56. state.video.currentTime = fixedTime;
  57. }
  58. );
  59. else state.video.currentTime = time;
  60. }
  61. );
  62. }
  63. }
  64. }
  65. },
  66. stations: {
  67. namespaced: true,
  68. state: {
  69. station: {},
  70. editing: {}
  71. },
  72. getters: {},
  73. actions: {
  74. editStation: ({ commit }, station) => commit("editStation", station)
  75. },
  76. mutations: {
  77. editStation(state, station) {
  78. state.station = station;
  79. state.editing = JSON.parse(JSON.stringify(station));
  80. }
  81. }
  82. },
  83. reports: {
  84. namespaced: true,
  85. state: {
  86. report: {}
  87. },
  88. getters: {},
  89. actions: {
  90. viewReport: ({ commit }, report) => commit("viewReport", report)
  91. },
  92. mutations: {
  93. viewReport(state, report) {
  94. state.report = report;
  95. }
  96. }
  97. },
  98. punishments: {
  99. namespaced: true,
  100. state: {
  101. punishment: {}
  102. },
  103. getters: {},
  104. actions: {
  105. viewPunishment: ({ commit }, punishment) =>
  106. commit("viewPunishment", punishment)
  107. },
  108. mutations: {
  109. viewPunishment(state, punishment) {
  110. state.punishment = punishment;
  111. }
  112. }
  113. },
  114. users: {
  115. namespaced: true,
  116. state: {
  117. editing: {}
  118. },
  119. getters: {},
  120. actions: {
  121. editUser: ({ commit }, user) => commit("editUser", user)
  122. },
  123. mutations: {
  124. editUser(state, user) {
  125. state.editing = user;
  126. }
  127. }
  128. }
  129. };
  130. export default {
  131. namespaced: true,
  132. state,
  133. getters,
  134. actions,
  135. mutations,
  136. modules
  137. };