admin.js 2.9 KB

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