1 | import { ComponentType } from 'react'
|
2 | import { StandardProps, CommonEventFunction } from './common'
|
3 |
|
4 | interface AdProps extends StandardProps {
|
5 | /** 广告单元id,可在[小程序管理后台](https://mp.weixin.qq.com/)的流量主模块新建
|
6 | * @supported weapp, tt
|
7 | */
|
8 | unitId: string
|
9 |
|
10 | /** 广告自动刷新的间隔时间,单位为秒,参数值必须大于等于30(该参数不传入时 Banner 广告不会自动刷新)
|
11 | * @supported weapp, tt
|
12 | */
|
13 | adIntervals?: number
|
14 |
|
15 | /** 广告类型,默认为展示`banner`,可通过设置该属性为`video`展示视频广告, `grid`为格子广告
|
16 | * @supported weapp
|
17 | */
|
18 | adType?: 'banner' | 'video' | 'grid'
|
19 |
|
20 | /** 广告主题样式设置
|
21 | * @supported weapp
|
22 | */
|
23 | adTheme?: 'white' | 'black'
|
24 |
|
25 | /** 广告加载成功的回调
|
26 | * @supported weapp, tt
|
27 | */
|
28 | onLoad?: CommonEventFunction
|
29 |
|
30 | /** 当广告发生错误时,触发的事件,可以通过该事件获取错误码及原因,事件对象event.detail = {errCode: 1002}
|
31 | * @supported weapp, tt
|
32 | */
|
33 | onError?: CommonEventFunction<AdProps.onErrorEventDetail>
|
34 |
|
35 | /** 广告关闭的回调
|
36 | * @supported weapp, tt
|
37 | */
|
38 | onClose?: CommonEventFunction
|
39 | }
|
40 |
|
41 | declare namespace AdProps {
|
42 | interface onErrorEventDetail {
|
43 | errCode: keyof AdErrCode
|
44 | }
|
45 | /**
|
46 | * 广告错误码
|
47 | *
|
48 | * 错误码是通过onError获取到的错误信息。调试期间,可以通过异常返回来捕获信息。
|
49 | * 在小程序发布上线之后,如果遇到异常问题,可以在[“运维中心“](https://mp.weixin.qq.com/)里面搜寻错误日志,还可以针对异常返回加上适当的监控信息。
|
50 | */
|
51 | interface AdErrCode {
|
52 | /**
|
53 | * @illustrate 后端错误调用失败
|
54 | * @reason 该项错误不是开发者的异常情况
|
55 | * @solution 一般情况下忽略一段时间即可恢复。
|
56 | */
|
57 | 1000
|
58 | /**
|
59 | * @illustrate 参数错误
|
60 | * @reason 使用方法错误
|
61 | * @solution 可以前往 developers.weixin.qq.com 确认具体教程(小程序和小游戏分别有各自的教程,可以在顶部选项中,“设计”一栏的右侧进行切换。
|
62 | */
|
63 | 1001
|
64 | /**
|
65 | * @illustrate 广告单元无效
|
66 | * @reason 可能是拼写错误、或者误用了其他APP的广告ID
|
67 | * @solution 请重新前往 mp.weixin.qq.com 确认广告位ID。
|
68 | */
|
69 | 1002
|
70 | /**
|
71 | * @illustrate 内部错误
|
72 | * @reason 该项错误不是开发者的异常情况
|
73 | * @solution 一般情况下忽略一段时间即可恢复。
|
74 | */
|
75 | 1003
|
76 | /**
|
77 | * @illustrate 无合适的广告
|
78 | * @reason 广告不是每一次都会出现,这次没有出现可能是由于该用户不适合浏览广告
|
79 | * @solution 属于正常情况,且开发者需要针对这种情况做形态上的兼容。
|
80 | */
|
81 | 1004
|
82 | /**
|
83 | * @illustrate 广告组件审核中
|
84 | * @reason 你的广告正在被审核,无法展现广告
|
85 | * @solution 请前往 mp.weixin.qq.com 确认审核状态,且开发者需要针对这种情况做形态上的兼容。
|
86 | */
|
87 | 1005
|
88 | /**
|
89 | * @illustrate 广告组件被驳回
|
90 | * @reason 你的广告审核失败,无法展现广告
|
91 | * @solution 请前往 mp.weixin.qq.com 确认审核状态,且开发者需要针对这种情况做形态上的兼容。
|
92 | */
|
93 | 1006
|
94 | /**
|
95 | * @illustrate 广告组件被封禁
|
96 | * @reason 你的广告能力已经被封禁,封禁期间无法展现广告
|
97 | * @solution 请前往 mp.weixin.qq.com 确认小程序广告封禁状态。
|
98 | */
|
99 | 1007
|
100 | /**
|
101 | * @illustrate 广告单元已关闭
|
102 | * @reason 该广告位的广告能力已经被关闭
|
103 | * @solution 请前往 mp.weixin.qq.com 重新打开对应广告位的展现。
|
104 | */
|
105 | 1008
|
106 | // [key: number]: string
|
107 | }
|
108 | }
|
109 |
|
110 | /** Banner 广告
|
111 | * @classification open
|
112 | * @supported weapp, tt
|
113 | * @example_react
|
114 | * ```tsx
|
115 | * class App extends Component {
|
116 | * render () {
|
117 | * return (
|
118 | * <Ad
|
119 | * unitId=''
|
120 | * adIntervals={60}
|
121 | * onLoad={() => console.log('ad onLoad')}
|
122 | * onError={() => console.log('ad onError')}
|
123 | * onClose={() => console.log('ad onClose')}
|
124 | * />
|
125 | * )
|
126 | * }
|
127 | * }
|
128 | * ```
|
129 | * @example_vue
|
130 | * ```html
|
131 | * <template>
|
132 | * <ad
|
133 | * unit-id=""
|
134 | * ad-intervals="60"
|
135 | * `@load="onLoad"
|
136 | * `@error="onError"
|
137 | * `@close="onClose"
|
138 | * />
|
139 | * </template>
|
140 | * ```
|
141 | * @see https://developers.weixin.qq.com/miniprogram/dev/component/ad.html
|
142 | */
|
143 | declare const Ad: ComponentType<AdProps>
|
144 |
|
145 | export { Ad, AdProps }
|