contentStore.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { contentApi, contentrankApi } from 'api'
  2. import * as TYPE from '../actionType/contentType'
  3. // douga 动画 1
  4. // bangumi 番剧 13
  5. // music 音乐 3
  6. // dance 舞蹈 129
  7. // game 游戏 4
  8. // technology 科技 36
  9. // life 生活 160
  10. // kichiku 鬼畜 119
  11. // fashion 时尚 155
  12. // ad 广告 165
  13. // ent 娱乐 5
  14. // movie 电影 23
  15. // teleplay TV剧 11
  16. const state = {
  17. // 默认排序
  18. sortKeys: ['douga', 'bangumi', 'music', 'dance', 'game', 'technology', 'life', 'kichiku', 'fashion', 'ad', 'ent', 'movie', 'teleplay'],
  19. sortIds: [1, 13, 3, 129, 4, 36, 160, 119, 155, 165, 5, 23, 11],
  20. sortValues: ['直播', '动画', '番剧', '音乐', '舞蹈', '游戏', '科技', '生活', '鬼畜', '时尚', '广告', '娱乐', '电影', 'TV剧'],
  21. rows: [],
  22. ranks: [],
  23. rank: {}
  24. }
  25. const getters = {
  26. rows: state => state.rows,
  27. sortKeys: state => state.sortKeys,
  28. sortIds: state => state.sortIds,
  29. ranks: state => state.ranks,
  30. rank: state => state.rank,
  31. sortValues: state => state.sortValues
  32. }
  33. const actions = {
  34. getContentRows({commit, state, rootState}) {
  35. rootState.requesting = true
  36. commit(TYPE.CONTENT_REQUEST)
  37. contentApi.content().then((response) => {
  38. rootState.requesting = false
  39. commit(TYPE.CONTENT_SUCCESS, response)
  40. }, (error) => {
  41. rootState.requesting = false
  42. commit(TYPE.CONTENT_FAILURE)
  43. })
  44. },
  45. getContentRank({commit, state, rootState}, categoryId) {
  46. console.log(categoryId)
  47. rootState.requesting = true
  48. commit(TYPE.CONTENT_RANK_REQUEST)
  49. let param = {
  50. categoryId: categoryId
  51. }
  52. contentrankApi.contentrank(param).then((response) => {
  53. rootState.requesting = false
  54. if (categoryId === 1) {
  55. console.log(response)
  56. }
  57. commit(TYPE.CONTENT_RANK_SUCCESS, response)
  58. }, (error) => {
  59. rootState.requesting = false
  60. commit(TYPE.CONTENT_RANK_FAILURE)
  61. })
  62. }
  63. }
  64. // 1 douga 动画
  65. // 2 bangumi 番剧
  66. // 3 music 音乐
  67. // 4 dance 舞蹈
  68. // 5 game 游戏
  69. // 6 technology 科技
  70. // 7 life 生活
  71. // 8 kichiku 鬼畜
  72. // 9 fashion 时尚
  73. // 10 ad 广告
  74. // 11 ent 娱乐
  75. // 12 movie 电影
  76. // 13 teleplay TV剧
  77. const mutations = {
  78. [TYPE.CONTENT_REQUEST] (state) {
  79. },
  80. [TYPE.CONTENT_SUCCESS] (state, response) {
  81. for(let key of state.sortKeys) {
  82. // console.log(JSON.stringify(Object.values(response[key])))
  83. // let rowItem = {
  84. // key: response[key],
  85. // data: Object.values(response[key])
  86. // }
  87. // state.rows.push(rowItem)
  88. state.rows.push(Object.values(response[key]))
  89. }
  90. },
  91. [TYPE.CONTENT_FAILURE] (state) {
  92. },
  93. // 排行榜信息
  94. [TYPE.CONTENT_RANK_REQUEST] (state) {
  95. },
  96. [TYPE.CONTENT_RANK_SUCCESS] (state, response) {
  97. state.ranks.push(response)
  98. state.rank = response
  99. },
  100. [TYPE.CONTENT_RANK_FAILURE] (state) {
  101. }
  102. }
  103. export default {
  104. state,
  105. getters,
  106. actions,
  107. mutations
  108. }