All files / src/api commentAPI.js

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                                                                                   
import axios from 'axios'
import BACKURL from './backConfig'
 
const host = BACKURL
 
export default {
  /**
   * @msg: 添加评论
   * @param {String} type
   * @param {Number} id
   * @param {Number} userId
   * @param {String} content
   * @return: {Promise}
   */
  setComment (type, id, userId, content) {
    // 0 代表歌曲, 1 代表歌单
    var params = new URLSearchParams()
    if (type === 1) {
      params.append('songListId', id)
    } else if (type === 0) {
      params.append('songId', id)
    }
    params.append('userId', userId)
    params.append('type', type)
    params.append('content', content)
    return axios.post(`${host}/comment/add`, params)
  },
 
  /**
   * @msg: 点赞
   * @param {Number} id
   * @param {Number} up
   * @return: {Promise}
   */
  setLike (id, up) {
    var params = new URLSearchParams()
    params.append('id', id)
    params.append('up', up + 1)
    return axios.post(`${host}/comment/like`, params)
  },
 
  /**
   * @msg: 返回所有评论
   * @param {String} type
   * @param {Number} id
   * @return: {Promise}
   */
  getAllComment (type, id) {
    let url = ''
    if (type === 1) {
      url = '/comment/songList/detail?songListId='
    } else if (type === 0) {
      url = '/comment/song/detail?songId='
    }
    return axios.get(host + url + id)
  }
}