contentStore.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 i = 0; i < state.sortKeys.length; i++) {
  82. let category = state.sortKeys[i]
  83. let rowItem = {
  84. category: category,
  85. categoryId: state.sortIds[i],
  86. name: state.sortValues[i],
  87. b_id: `b_${category}`,
  88. item: Object.values(response[category])
  89. }
  90. state.rows.push(rowItem)
  91. }
  92. // for(let key of state.sortKeys) {
  93. // // console.log(JSON.stringify(Object.values(response[key])))
  94. // let rowItem = {
  95. // categoty: 0,
  96. // key: response[key],
  97. // data: Object.values(response[key])
  98. // }
  99. // // state.rows.push(rowItem)
  100. // state.rows.push(Object.values(response[key]))
  101. // }
  102. },
  103. [TYPE.CONTENT_FAILURE] (state) {
  104. },
  105. // 排行榜信息
  106. [TYPE.CONTENT_RANK_REQUEST] (state) {
  107. },
  108. [TYPE.CONTENT_RANK_SUCCESS] (state, response) {
  109. state.ranks.push(response)
  110. state.rank = response
  111. },
  112. [TYPE.CONTENT_RANK_FAILURE] (state) {
  113. }
  114. }
  115. export default {
  116. state,
  117. getters,
  118. actions,
  119. mutations
  120. }