text: import { ICON } from '../assets/icon/index'
  
  const BASE_URL = process.env.NODE_HOST
  
  const song = {
    state: {
      isPlay: false, // 播放状态
      playButtonUrl: ICON.BOFANG, // 播放状态的图标
      id: null, // 音乐ID
      url: '', // 歌曲URL
      duration: 0, //  音乐时长
      curTime: 0, // 当前音乐的播放位置
      changeTime: 0, //  指定播放时刻
      title: '', //  歌名
      artist: '', //  歌手名
      picUrl: '', // 歌曲图片
      autoNext: true, // 用于触发自动播放下一首
      lyric: [], // 未处理的歌词数据
      listOfSongs: [], // 当前歌单列表
      currentPlay: [], // 当前播放
      songDetails: {}, // 单个歌单信息
      listIndex: -1, // 当前歌曲在歌曲列表的位置
      volume: 50
    },
    getters: {
      isPlay: state => state.isPlay,
      playButtonUrl: state => {
        let playButtonUrl = state.playButtonUrl
        if (!playButtonUrl) {
          playButtonUrl = JSON.parse(window.sessionStorage.getItem('playButtonUrl') || null)
        }
        return playButtonUrl
      },
      id: state => {
        let id = state.id
        if (!id) {
          id = JSON.parse(window.sessionStorage.getItem('id') || null)
        }
        return id
      },
      url: state => {
        let url = state.url
        if (!url) {
          url = JSON.parse(window.sessionStorage.getItem('url') || null)
        }
        return url
      },
      duration: state => {
        let duration = state.duration
        if (!duration) {
          duration = JSON.parse(window.sessionStorage.getItem('duration') || 0)
        }
        return duration
      },
      curTime: state => {
        let curTime = state.curTime
        if (!curTime) {
          curTime = JSON.parse(window.sessionStorage.getItem('curTime') || 0)
        }
        return curTime
      },
      changeTime: state => {
        let changeTime = state.changeTime
        if (!changeTime) {
          changeTime = JSON.parse(window.sessionStorage.getItem('changeTime') || 0)
        }
        return changeTime
      },
      title: state => {
        let title = state.title
        if (!title) {
          title = JSON.parse(window.sessionStorage.getItem('title') || null)
        }
        return title
      },
      artist: state => {
        let artist = state.artist
        if (!artist) {
          artist = JSON.parse(window.sessionStorage.getItem('artist') || null)
        }
        return artist
      },
      picUrl: state => {
        let picUrl = state.picUrl
        if (!picUrl) {
          picUrl = JSON.parse(window.sessionStorage.getItem('picUrl')) || `${BASE_URL}/img/songPic/tubiao.jpg`
        }
        return picUrl
      },
      autoNext: state => {
        let autoNext = state.autoNext
        if (!autoNext) {
          autoNext = JSON.parse(window.sessionStorage.getItem('autoNext') || null)
        }
        return autoNext
      },
      lyric: state => {
        let lyric = state.lyric
        if (lyric.length === 0) {
          lyric = JSON.parse(window.sessionStorage.getItem('lyric') || null)
        }
        return lyric
      },
      songDetails: state => {
        let songDetails = state.songDetails
        if (JSON.stringify(songDetails) === '{}') {
          songDetails = JSON.parse(window.sessionStorage.getItem('songDetails') || null)
        }
        return songDetails
      },
      listOfSongs: state => {
        let listOfSongs = state.listOfSongs
        if (!listOfSongs.length) {
          listOfSongs = JSON.parse(window.sessionStorage.getItem('listOfSongs') || null)
        }
        return listOfSongs
      },
      currentPlay: state => {
        let currentPlay = state.currentPlay
        if (!currentPlay.length) {
          currentPlay = JSON.parse(window.sessionStorage.getItem('currentPlay') || null)
        }
        return currentPlay
      },
      listIndex: state => {
        let listIndex = state.listIndex
        if (!listIndex) {
          listIndex = JSON.parse(window.sessionStorage.getItem('listIndex') || null)
        }
        return listIndex
      },
      volume: state => {
        let volume = state.volume
        if (!volume) {
          volume = JSON.parse(window.sessionStorage.getItem('volume') || null)
        }
        return volume
      }
    },
    mutations: {
      setIsPlay: (state, isPlay) => {
        state.isPlay = isPlay
        window.sessionStorage.setItem('isPlay', JSON.stringify(isPlay))
      },
      setPlayButtonUrl: (state, playButtonUrl) => {
        state.playButtonUrl = playButtonUrl
        window.sessionStorage.setItem('playButtonUrl', JSON.stringify(playButtonUrl))
      },
      setId: (state, id) => {
        state.id = id
        window.sessionStorage.setItem('id', JSON.stringify(id))
      },
      setUrl: (state, url) => {
        state.url = url
        window.sessionStorage.setItem('url', JSON.stringify(url))
      },
      setDuration: (state, duration) => {
        state.duration = duration
        window.sessionStorage.setItem('duration', JSON.stringify(duration))
      },
      setCurTime: (state, curTime) => {
        state.curTime = curTime
        window.sessionStorage.setItem('curTime', JSON.stringify(curTime))
      },
      setChangeTime: (state, changeTime) => {
        state.changeTime = changeTime
        window.sessionStorage.setItem('changeTime', JSON.stringify(changeTime))
      },
      setTitle: (state, title) => {
        state.title = title
        window.sessionStorage.setItem('title', JSON.stringify(title))
      },
      setArtist: (state, artist) => {
        state.artist = artist
        window.sessionStorage.setItem('artist', JSON.stringify(artist))
      },
      setpicUrl: (state, picUrl) => {
        state.picUrl = picUrl
        window.sessionStorage.setItem('picUrl', JSON.stringify(picUrl))
      },
      setAutoNext: (state, autoNext) => {
        state.autoNext = autoNext
        window.sessionStorage.setItem('autoNext', JSON.stringify(autoNext))
      },
      setLyric: (state, lyric) => {
        state.lyric = lyric
        window.sessionStorage.setItem('lyric', JSON.stringify(lyric))
      },
      setSongDetails: (state, songDetails) => {
        state.songDetails = songDetails
        window.sessionStorage.setItem('songDetails', JSON.stringify(songDetails))
      },
      setListOfSongs: (state, listOfSongs) => {
        state.listOfSongs = listOfSongs
        window.sessionStorage.setItem('listOfSongs', JSON.stringify(listOfSongs))
      },
      setCurrentPlay: (state, currentPlay) => {
        state.currentPlay = currentPlay
        window.sessionStorage.setItem('currentPlay', JSON.stringify(currentPlay))
      },
      setListIndex: (state, listIndex) => {
        state.listIndex = listIndex
        window.sessionStorage.setItem('listIndex', JSON.stringify(listIndex))
      },
      setVolume: (state, volume) => {
        state.volume = volume
        window.sessionStorage.setItem('volume', JSON.stringify(volume))
      }
    },
    actions: {}
  }
  
  export default song
  