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.
91 lines
1.9 KiB
91 lines
1.9 KiB
|
|
// import addApi from '@/api/add.js'; // 引入
|
|
|
|
const add = {
|
|
state: {
|
|
addList: []
|
|
},
|
|
mutations: {
|
|
// 更新广告列表
|
|
upDateAddList(state, list) {
|
|
state.addList = list
|
|
},
|
|
|
|
// 更新当前广告点击量
|
|
upDateViews(state, id) {
|
|
let add = state.addList.find(item=>item.id==id)
|
|
add.clicks ++
|
|
},
|
|
|
|
|
|
|
|
|
|
},
|
|
actions: {
|
|
// 点击广告
|
|
async addClick({commit, dispatch}, curAdd) {
|
|
// await dispatch('updateStatistics')
|
|
curAdd.clicks ++
|
|
if(!curAdd.adBannerDO.jumpUrl) {
|
|
return false
|
|
}
|
|
|
|
commit('updateWebVeiwUrl', curAdd.adBannerDO.jumpUrl)
|
|
uni.navigateTo({
|
|
url:'/pages/commeWebView/addWebView'
|
|
})
|
|
},
|
|
// 获取当前广告
|
|
getCurrentAdd({state},id) {
|
|
console.log(id)
|
|
console.log(state.addList)
|
|
let curAdd = state.addList.find(item=>item.id==id)
|
|
if(curAdd) {
|
|
curAdd.views ++
|
|
return curAdd
|
|
}else {
|
|
return {}
|
|
}
|
|
},
|
|
// // 广告
|
|
// async addPageFn({commit,state, dispatch}) {
|
|
// await dispatch('updateStatistics')
|
|
// let obj = {
|
|
// pageNo: 1,
|
|
// pageSize: 30,
|
|
// adClient: 1
|
|
// }
|
|
// const [err, res] = await addApi.addPage(obj)
|
|
// let list = res.data.records.map(item=>{
|
|
// item.views = 0
|
|
// item.clicks = 0
|
|
// return item
|
|
// })
|
|
// commit('upDateAddList', list)
|
|
// console.log('广告列表')
|
|
// console.log(list)
|
|
|
|
// },
|
|
// 更新广告点击量
|
|
async updateStatistics({ dispatch,state, commit }) {
|
|
let statistics = state.addList.filter(item=>item.views)
|
|
console.log('调用更新广告接口')
|
|
if(statistics.length) {
|
|
let stcsList = statistics.map(add=>{
|
|
let obj = {
|
|
"adPositionId": add.id,
|
|
"adId": add.adId,
|
|
"views": add.views,
|
|
"clicks": add.clicks
|
|
}
|
|
return obj
|
|
})
|
|
const [err, res] = await addApi.batchUpdate(stcsList)
|
|
console.log('更新广告点击量请求结果')
|
|
console.log(res)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default add
|