admin.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.editing = state.station = station;
  78. }
  79. }
  80. },
  81. reports: {
  82. namespaced: true,
  83. state: {
  84. report: {}
  85. },
  86. getters: {},
  87. actions: {
  88. viewReport: ({ commit }, report) => commit("viewReport", report)
  89. },
  90. mutations: {
  91. viewReport(state, report) {
  92. state.report = report;
  93. }
  94. }
  95. },
  96. punishments: {
  97. namespaced: true,
  98. state: {
  99. punishment: {}
  100. },
  101. getters: {},
  102. actions: {
  103. viewPunishment: ({ commit }, punishment) =>
  104. commit("viewPunishment", punishment)
  105. },
  106. mutations: {
  107. viewPunishment(state, punishment) {
  108. state.punishment = punishment;
  109. }
  110. }
  111. },
  112. users: {
  113. namespaced: true,
  114. state: {
  115. editing: {}
  116. },
  117. getters: {},
  118. actions: {
  119. editUser: ({ commit }, user) => commit("editUser", user)
  120. },
  121. mutations: {
  122. editUser(state, user) {
  123. state.editing = user;
  124. }
  125. }
  126. }
  127. };
  128. export default {
  129. namespaced: true,
  130. state,
  131. getters,
  132. actions,
  133. mutations,
  134. modules
  135. };