editSong.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* eslint no-param-reassign: 0 */
  2. // import Vue from "vue";
  3. // import admin from "@/api/admin/index";
  4. export default {
  5. namespaced: true,
  6. state: {
  7. video: {
  8. player: null,
  9. paused: true,
  10. playerReady: false,
  11. autoPlayed: false,
  12. currentTime: 0
  13. },
  14. song: {},
  15. originalSong: {},
  16. reports: [],
  17. tab: "discogs"
  18. },
  19. getters: {},
  20. actions: {
  21. showTab: ({ commit }, tab) => commit("showTab", tab),
  22. editSong: ({ commit }, song) => commit("editSong", song),
  23. stopVideo: ({ commit }) => commit("stopVideo"),
  24. loadVideoById: ({ commit }, id, skipDuration) =>
  25. commit("loadVideoById", id, skipDuration),
  26. pauseVideo: ({ commit }, status) => commit("pauseVideo", status),
  27. getCurrentTime: ({ commit, state }, fixedVal) => {
  28. return new Promise(resolve => {
  29. commit("getCurrentTime", fixedVal);
  30. resolve(state.video.currentTime);
  31. });
  32. },
  33. updateSongField: ({ commit }, data) => commit("updateSongField", data),
  34. selectDiscogsInfo: ({ commit }, discogsInfo) =>
  35. commit("selectDiscogsInfo", discogsInfo),
  36. updateReports: ({ commit }, reports) => commit("updateReports", reports)
  37. },
  38. mutations: {
  39. showTab(state, tab) {
  40. state.tab = tab;
  41. },
  42. editSong(state, song) {
  43. if (song.discogs === undefined) song.discogs = null;
  44. state.originalSong = JSON.parse(JSON.stringify(song));
  45. state.song = { ...song };
  46. },
  47. stopVideo(state) {
  48. state.video.player.stopVideo();
  49. },
  50. loadVideoById(state, id, skipDuration) {
  51. state.video.player.loadVideoById(id, skipDuration);
  52. },
  53. pauseVideo(state, status) {
  54. if (status) state.video.player.pauseVideo();
  55. else state.video.player.playVideo();
  56. state.video.paused = status;
  57. },
  58. getCurrentTime(state, fixedVal) {
  59. if (!state.playerReady) state.video.currentTime = 0;
  60. else {
  61. Promise.resolve(state.video.player.getCurrentTime()).then(
  62. time => {
  63. if (fixedVal)
  64. Promise.resolve(time.toFixed(fixedVal)).then(
  65. fixedTime => {
  66. state.video.currentTime = fixedTime;
  67. }
  68. );
  69. else state.video.currentTime = time;
  70. }
  71. );
  72. }
  73. },
  74. updateSongField(state, data) {
  75. state.song[data.field] = data.value;
  76. },
  77. selectDiscogsInfo(state, discogsInfo) {
  78. state.song.discogs = discogsInfo;
  79. },
  80. updateReports(state, reports) {
  81. state.reports = reports;
  82. }
  83. }
  84. };