江西小程序管理端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.9 KiB

1 year ago
  1. // import addApi from '@/api/add.js'; // 引入
  2. const add = {
  3. state: {
  4. addList: []
  5. },
  6. mutations: {
  7. // 更新广告列表
  8. upDateAddList(state, list) {
  9. state.addList = list
  10. },
  11. // 更新当前广告点击量
  12. upDateViews(state, id) {
  13. let add = state.addList.find(item=>item.id==id)
  14. add.clicks ++
  15. },
  16. },
  17. actions: {
  18. // 点击广告
  19. async addClick({commit, dispatch}, curAdd) {
  20. // await dispatch('updateStatistics')
  21. curAdd.clicks ++
  22. if(!curAdd.adBannerDO.jumpUrl) {
  23. return false
  24. }
  25. commit('updateWebVeiwUrl', curAdd.adBannerDO.jumpUrl)
  26. uni.navigateTo({
  27. url:'/pages/commeWebView/addWebView'
  28. })
  29. },
  30. // 获取当前广告
  31. getCurrentAdd({state},id) {
  32. console.log(id)
  33. console.log(state.addList)
  34. let curAdd = state.addList.find(item=>item.id==id)
  35. if(curAdd) {
  36. curAdd.views ++
  37. return curAdd
  38. }else {
  39. return {}
  40. }
  41. },
  42. // // 广告
  43. // async addPageFn({commit,state, dispatch}) {
  44. // await dispatch('updateStatistics')
  45. // let obj = {
  46. // pageNo: 1,
  47. // pageSize: 30,
  48. // adClient: 1
  49. // }
  50. // const [err, res] = await addApi.addPage(obj)
  51. // let list = res.data.records.map(item=>{
  52. // item.views = 0
  53. // item.clicks = 0
  54. // return item
  55. // })
  56. // commit('upDateAddList', list)
  57. // console.log('广告列表')
  58. // console.log(list)
  59. // },
  60. // 更新广告点击量
  61. async updateStatistics({ dispatch,state, commit }) {
  62. let statistics = state.addList.filter(item=>item.views)
  63. console.log('调用更新广告接口')
  64. if(statistics.length) {
  65. let stcsList = statistics.map(add=>{
  66. let obj = {
  67. "adPositionId": add.id,
  68. "adId": add.adId,
  69. "views": add.views,
  70. "clicks": add.clicks
  71. }
  72. return obj
  73. })
  74. const [err, res] = await addApi.batchUpdate(stcsList)
  75. console.log('更新广告点击量请求结果')
  76. console.log(res)
  77. }
  78. }
  79. }
  80. }
  81. export default add