From 2327f9ef5a228bafb3e5ab51de0bf82e61d76772 Mon Sep 17 00:00:00 2001 From: yulixing Date: Mon, 29 Jul 2019 19:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=BF=E5=91=8A=E8=AF=A6=E6=83=85=E3=80=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/ad-data.js | 19 ++++++ src/views/ad/edit.vue | 121 +++++++++++++++++++++++++++++------- src/views/ad/list.vue | 54 +++++++++------- src/views/admin/ad-list.vue | 56 ++++++++++------- 4 files changed, 184 insertions(+), 66 deletions(-) create mode 100644 src/utils/ad-data.js diff --git a/src/utils/ad-data.js b/src/utils/ad-data.js new file mode 100644 index 0000000..85edced --- /dev/null +++ b/src/utils/ad-data.js @@ -0,0 +1,19 @@ +const areaList = { + '1': '首页', + '2': '游戏中', + '3': '结算页', + '4': '关闭', +} + +const typeList = { + '1': 'icon', + '2': 'banner', + '3': '浮窗', +} + +const modeList = { + '1': '单播', + '2': '轮播', +} + +export {areaList, typeList, modeList} diff --git a/src/views/ad/edit.vue b/src/views/ad/edit.vue index fca7cb7..cbf61c5 100644 --- a/src/views/ad/edit.vue +++ b/src/views/ad/edit.vue @@ -19,6 +19,25 @@ :disabled="!writeable" /> + + + + + import { getAdPos, getAd, addAd, updateAd } from '@/api/ad' import { getGameList } from '@/api/game' +import { areaList, typeList, modeList } from '@/utils/ad-data' import moment from 'moment' export default { @@ -218,24 +239,19 @@ export default { //common writeable: true, companyid: 0, + allGame: [], gameList: [], + platformList: [], locationList: [], - locationArea: { - '1': '首页', - '2': '游戏中', - '3': '结算页', - '4': '关闭' - }, - locationType: { - '1': 'icon', - '2': 'banner', - '3': '浮窗' - }, + areaList: {}, + typeList: {}, + modeList: {}, uploadUrl: `${process.env.VUE_APP_UPLOAD}`, // form adForm: { name: '', gameid: '', + channelid: '', locationid: '', ad_title: '', ad_body: '', @@ -255,6 +271,9 @@ export default { gameid: [ { required: true, message: '请选择投放游戏', trigger: 'blur' } ], + channelid: [ + { required: true, message: '请选择投放平台', trigger: 'blur' } + ], locationid: [ { required: true, message: '请选择投放位置', trigger: 'blur' }, { type: 'number', message: '投放位置必须是数值', trigger: 'blur' } @@ -272,33 +291,59 @@ export default { } }, async mounted() { - const gameList = await this.getGameList() + // 位置相关数据导入 + this.areaList = areaList + this.modeList = modeList + this.typeList = typeList - this.gameList = gameList.map(item => { + // 获取所有可投放游戏 + const allGame = await this.getGameList() + this.allGame = allGame + + // 获取所有平台 + this.platformList = this.allGame.map(item => { + return `${item.platform_id}-${item.platform_name}` + }) + this.platformList = [...new Set(this.platformList)] + this.platformList = this.platformList.map(item => { + const platform = item.split('-') return { - game: `${item.game}(${item.platform_name})`, - game_id: `${item.game_id}:${item.platform_id}` + platform_id: parseInt(platform[0]), + platform_name: platform[1] } }) - const pos = await this.getAdPos() - this.locationList = pos.message.map(item => { - item.label = `${this.locationArea[item.area]}-${ - this.locationType[item.type] - }` - return item - }) - + let hasAd = true const ad_id = this.$route.query.ad_id if (ad_id) { const ad = await this.getAd({ id: ad_id }) + if (ad.message.length === 0) { + hasAd = false + return + } const adData = JSON.parse(JSON.stringify(ad.message[0])) adData.dateRange = [ this.formDate(adData.begin_time), this.formDate(adData.end_time) ] - this.adForm = adData + const gameid = this.adForm.gameid + const locationid = this.adForm.locationid + this.changePlatform(this.adForm.channelid) + this.adForm.gameid = gameid + this.changeGame() + this.adForm.locationid = locationid + } else { + hasAd = false + } + + if (!hasAd) { + // 默认选择第一个平台 + this.adForm.channelid = this.platformList[0].platform_id + this.changePlatform(this.adForm.channelid) + // 默认选择第一个游戏 + this.adForm.gameid = this.gameList[0] ? this.gameList[0].game_id : '' + this.changeGame() } }, methods: { @@ -392,6 +437,34 @@ export default { .format('YYYY-MM-DD HH:mm:ss') }, // form + changePlatform(val) { + this.adForm.gameid = '' + this.adForm.locationid = '' + this.gameList = this.allGame.filter(item => { + return item.platform_id === val + }) + }, + async changeGame(val) { + this.adForm.locationid = '' + const location = await this.getAdPos({ + channelid: this.adForm.channelid, + gameid: this.adForm.gameid + }) + if (!location.message || location.message.length === 0) { + this.locationList = [] + return + } + + this.locationList = location.message.map(item => { + const area = item.area.split(',') + return { + id: item.id, + label: `${this.areaList[area[0]]}-(${area[1]},${area[2]})-${ + this.modeList[item.mode] + }` + } + }) + }, beforeUpload(file) { const isLt600k = file.size / 1024 / 1024 < 0.6 diff --git a/src/views/ad/list.vue b/src/views/ad/list.vue index 28a2354..02210d7 100644 --- a/src/views/ad/list.vue +++ b/src/views/ad/list.vue @@ -16,6 +16,10 @@ v-model="filterForm.status" placeholder="请选择审核状态" > + + import { getAd, updateAd, delAd, getAdPos } from '@/api/ad' import { getGameList } from '@/api/game' +import { areaList, typeList, modeList } from '@/utils/ad-data' import { Promise, reject } from 'q' import moment from 'moment' @@ -191,18 +202,11 @@ export default { return { // common gameList: {}, + platformList: {}, locationList: {}, - locationArea: { - '1': '首页', - '2': '游戏中', - '3': '结算页', - '4': '关闭' - }, - locationType: { - '1': 'icon', - '2': 'banner', - '3': '浮窗' - }, + areaList: {}, + typeList: {}, + modeList: {}, sortList: { '0': '按固定次数推广', '1': '个性化推荐', @@ -230,17 +234,18 @@ export default { } }, async mounted() { + // 位置相关数据导入 + this.areaList = areaList + this.modeList = modeList + this.typeList = typeList + const gameList = await this.getGameList() gameList.map(item => { - const key = `${item.game_id}:${item.platform_id}` - this.gameList[key] = `${item.game}(${item.platform_name})` - }) + const gameKey = `${item.game_id}` + this.gameList[gameKey] = `${item.game}` - const pos = await this.getAdPos() - pos.message.map(item => { - this.locationList[item.id] = `${this.locationArea[item.area]}-${ - this.locationType[item.type] - }` + const platformKey = `${item.platform_id}` + this.platformList[platformKey] = `${item.platform_name}` }) this.getData() @@ -369,8 +374,15 @@ export default { formSort(row, column, cellValue, index) { return `${this.sortList[cellValue]}` }, + formPlatform(row, column, cellValue, index) { + return `${this.platformList[cellValue]}` + }, formLocation(row, column, cellValue, index) { - return `${this.locationList[cellValue]}` + const area = cellValue.split(',') + + return `${this.areaList[area[0]]}-(${area[1]},${area[2]})-${ + this.modeList[row.mode] + }` }, formJump(row, column, cellValue, index) { return cellValue === 1 ? '是' : '否' diff --git a/src/views/admin/ad-list.vue b/src/views/admin/ad-list.vue index 8104a30..e15eaab 100644 --- a/src/views/admin/ad-list.vue +++ b/src/views/admin/ad-list.vue @@ -15,6 +15,10 @@ v-model="filterForm.status" placeholder="请选择审核状态" > + + import { getAd, updateAd, delAd, getAdPos } from '@/api/ad' import { getGameList } from '@/api/game' +import { areaList, typeList, modeList } from '@/utils/ad-data' import { Promise, reject } from 'q' import moment from 'moment' @@ -220,18 +231,11 @@ export default { return { // common gameList: {}, + platformList: {}, locationList: {}, - locationArea: { - '1': '首页', - '2': '游戏中', - '3': '结算页', - '4': '关闭' - }, - locationType: { - '1': 'icon', - '2': 'banner', - '3': '浮窗' - }, + areaList: {}, + typeList: {}, + modeList: {}, sortList: { '0': '按固定次数推广', '1': '个性化推荐', @@ -259,19 +263,21 @@ export default { } }, async mounted() { + // 位置相关数据导入 + this.areaList = areaList + this.modeList = modeList + this.typeList = typeList + const gameList = await this.getGameList() gameList.map(item => { - const key = `${item.game_id}:${item.platform_id}` - this.gameList[key] = `${item.game}(${item.platform_name})` + const gameKey = `${item.game_id}` + this.gameList[gameKey] = `${item.game}` + + const platformKey = `${item.platform_id}` + this.platformList[platformKey] = `${item.platform_name}` }) - const pos = await this.getAdPos() - pos.message.map(item => { - this.locationList[item.id] = `${this.locationArea[item.area]}-${ - this.locationType[item.type] - }` - }) this.getData() }, methods: { @@ -489,11 +495,19 @@ export default { formGame(row, column, cellValue, index) { return `${this.gameList[cellValue]}` }, + formPlatform(row, column, cellValue, index) { + return `${this.platformList[cellValue]}` + }, formSort(row, column, cellValue, index) { return `${this.sortList[cellValue]}` }, formLocation(row, column, cellValue, index) { - return `${this.locationList[cellValue]}` + const area = cellValue.split(',') + + console.log(this.areaList) + return `${this.areaList[area[0]]}-(${area[1]},${area[2]})-${ + this.modeList[row.mode] + }` }, formJump(row, column, cellValue, index) { return cellValue === 1 ? '是' : '否'