提交 19382f29 编写于 作者: d-u-a's avatar d-u-a

feat: 新增 ad-interactive

上级 11efa0b2
<template>
<view @click="onclick">
<slot
:options="options"
:data="adData"
/>
<slot :options="options" :data="adData" :loading="loading" :error="errorMessage" />
</view>
</template>
<script>
const AD_URL = 'https://wxac1.dcloud.net.cn/tuiaApplet/acs'
const AD_REPORT_URL = 'https://wxac1.dcloud.net.cn/tuiaApplet/acs'
const WEBVIEW_PATH = '/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive'
const AD_URL = 'https://wxac1.dcloud.net.cn/openPage/acs'
const AD_REPORT_URL = 'https://wxac1.dcloud.net.cn/openPage/acs'
//const WEBVIEW_PATH = '/uni_modules/uni-ad-interactive/pages/uni-ad-interactive/uni-ad-interactive'
const events = {
load: 'load',
close: 'close',
error: 'error'
}
const events = {
load: 'load',
close: 'close',
error: 'error'
}
const OpenTypes = {
Interactive: 'interactive'
}
const OpenTypes = {
Interactive: 'interactive'
}
export default {
name: 'AdInteractive',
props: {
options: {
type: [Object, Array],
default () {
return {}
export default {
name: 'AdInteractive',
props: {
options: {
type: [Object, Array],
default () {
return {}
}
},
disabled: {
type: [Boolean, String],
default: false
},
adpid: {
type: [Number, String],
default: ''
},
openType: {
type: String,
default: 'interactive'
},
openPagePath: {
type: String,
default: ""
}
},
adpid: {
type: [Number, String],
default: ''
},
openUrl: {
type: String,
default: WEBVIEW_PATH
}
},
data () {
return {
adData: {}
}
},
created () {
this._uniAdPlugin = null
this._interactiveUrl = null
if (this.openType === OpenTypes.Interactive) {
this.getAdData()
}
},
methods: {
show () {
if (this._uniAdPlugin === null) {
this._uniAdPlugin = this.selectComponent('.uni-ad-plugin')
data() {
return {
adData: null,
loading: false,
errorMessage: ""
}
this._uniAdPlugin.show()
},
getAdData () {
if (!this.adpid) {
this.$emit(events.error, {
code: -5002,
message: 'invalid adpid'
})
return
created() {
this._uniAdPlugin = null
this._interactiveUrl = null
if (this.openPagePath) {
this.getAdData()
}
},
methods: {
show() {
if (this._uniAdPlugin === null) {
this._uniAdPlugin = this.selectComponent('.uni-ad-plugin')
}
this._uniAdPlugin.show()
},
getAdData() {
if (!this.adpid) {
this.$emit(events.error, {
code: -5002,
message: 'invalid adpid'
})
return
}
uni.request({
url: AD_URL,
method: 'POST',
data: {
adpid: this.adpid
},
timeout: 5000,
dataType: 'json',
success: (res) => {
console.log(res.data)
this.loading = true
if (res.statusCode !== 200) {
this.$emit(events.error, {
code: res.statusCode,
message: res.statusCode
})
return
}
uni.request({
url: AD_URL,
method: 'POST',
data: {
adpid: this.adpid
},
timeout: 5000,
dataType: 'json',
success: (res) => {
if (res.statusCode !== 200) {
this.$emit(events.error, {
errCode: res.statusCode,
errMsg: res.statusCode
})
return
}
const responseData = res.data
if (responseData.ret === 0) {
this._interactiveUrl = responseData.data.adp_url
this.adData.imgUrl = responseData.data.icon_url
this.adData.openUrl = this.openUrl + '?url=' + encodeURIComponent(this._interactiveUrl)
this.$emit(events.load, {})
} else {
const responseData = res.data
if (responseData.ret === 0) {
this._interactiveUrl = responseData.data.adp_url
this.adData = {
imgUrl: responseData.data.icon_url,
openPath: this.openPagePath + '?url=' + encodeURIComponent(this._interactiveUrl)
}
this.$emit(events.load, this.adData)
} else {
const errMsg = {
errCode: responseData.ret,
errMsg: responseData.msg
}
this.errorMessage = errMsg
this.$emit(events.error, errMsg)
}
},
fail: (err) => {
this.$emit(events.error, {
code: responseData.ret,
message: responseData.msg
errCode: '',
errMsg: err.errMsg
})
},
complete: () => {
this.loading = false
}
},
fail: (err) => {
this.$emit(events.error, {
code: '',
message: err.errMsg
})
})
},
onclick() {
if (this.disabled) {
return
}
if (!this._interactiveUrl) {
return
}
})
},
onclick () {
if (this.openType !== OpenTypes.Interactive || !this._interactiveUrl) {
return
}
uni.navigateTo({
url: this.adData.openUrl
})
uni.navigateTo({
url: this.adData.openPath
})
this._report()
},
_report () {
uni.request({
url: AD_REPORT_URL,
data: {
adpid: this.adpid,
t: '10019'
},
timeout: 5000,
dataType: 'json'
})
this._report()
},
_report() {
uni.request({
url: AD_REPORT_URL,
data: {
adpid: this.adpid,
t: '10019'
},
timeout: 5000,
dataType: 'json'
})
}
}
}
}
</script>
<style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册