提交 665894f9 编写于 作者: Anne_LXM's avatar Anne_LXM

uni-sign-in签到组件style加上scoped

上级 3254f020
## 1.0.5(2021-12-09)
修复插件没自动安装依赖的`uni-popup``uni-icons`组件的问题
## 1.0.4(2021-11-29)
修复在某些情况下,签到不连续7天,也获得60积分的问题
## 1.0.3(2021-11-20)
新增支持看激励视频广告签到
## 1.0.2(2021-08-25)
修复时区问题
## 1.0.1(2021-08-23)
调整签到逻辑,支持查出积分的收入支出历史记录
## 1.0.0(2021-08-05)
1.0.0版本发布
## 1.0.6(2024-03-26)
支持支付宝小程序云
## 1.0.5(2021-12-09)
修复插件没自动安装依赖的`uni-popup``uni-icons`组件的问题
## 1.0.4(2021-11-29)
修复在某些情况下,签到不连续7天,也获得60积分的问题
## 1.0.3(2021-11-20)
新增支持看激励视频广告签到
## 1.0.2(2021-08-25)
修复时区问题
## 1.0.1(2021-08-23)
调整签到逻辑,支持查出积分的收入支出历史记录
## 1.0.0(2021-08-05)
1.0.0版本发布
......@@ -82,7 +82,10 @@
let res = await this.getSignedInInfo();
console.log(res);
if (res && res.length == 0) {
let userId= uniCloud.getCurrentUserInfo().uid
let {
_id: userId
} = uni.getStorageSync('userInfo')
console.log(userId, uni.getStorageSync('userInfo'));
if (!userId) {
return uni.navigateTo({
url: "/pages/ucenter/login-page/index/index"
......@@ -181,7 +184,7 @@
}
</script>
<style lang="scss">
<style lang="scss" scoped>
view {
display: flex;
box-sizing: border-box;
......
{
"id": "uni-sign-in",
"displayName": "uni-starter签到插件 提升留存,激励视频变现",
"version": "1.0.5",
"description": "培养用户习惯,提升用户粘性,支持广告流量变现的签到得积分功能",
"keywords": [
"uni-sign-in",
"签到",
"营销",
"变现",
"积分"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"category": [
"uniCloud",
"云端一体页面模板"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": ["uni-popup","uni-icons"],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "y",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "y",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
}
{
"id": "uni-sign-in",
"displayName": "uni-starter签到插件 提升留存,激励视频变现",
"version": "1.0.6",
"description": "培养用户习惯,提升用户粘性,支持广告流量变现的签到得积分功能",
"keywords": [
"uni-sign-in",
"签到",
"营销",
"变现",
"积分"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "",
"type": "unicloud-template-page"
},
"uni_modules": {
"dependencies": ["uni-popup","uni-icons"],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y",
"alipay": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "y",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "y",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
}
}
\ No newline at end of file
#### 简介:培养用户习惯,提升用户粘性,支持广告流量变现的签到得积分功能。
#### 功能支持:
1. 每日签到奖励 (支持:普通签到、看广告签到)
2. 周期性连续7日签到,奖励翻倍
### 使用看广告签到功能必读
1.`普通签到`是通过clientDb实现,如果你要使用`看广告签到`的方式,
为了防止刷量需要修改`opendb-sign-in.schema``permission` -> `create` 的值设置为`false`
> 文件路径 :`uni_modules/uni-sign-in/uniCloud/database/opendb-sign-in.schema.json`
示例:
```javascript
{
"bsonType": "object",
"required": [],
"permission": {
"read": "auth.uid == doc.user_id",
"create": false,
"update": false,
"delete": false
}
}
```
2. 你需要看激励视频广告相关文档
详情:[https://uniapp.dcloud.net.cn/api/a-d/rewarded-video](https://uniapp.dcloud.net.cn/api/a-d/rewarded-video)
##### 使用方式
```js
<template>
<view>
<uni-sign-in ref="signIn"></uni-sign-in>
<button type="default" @click="signIn">普通签到</button>
<button type="default" @click="signInByAd">看广告签到</button>
</view>
</template>
<script>
export default {
methods: {
signIn() { //普通签到
#### 简介:培养用户习惯,提升用户粘性,支持广告流量变现的签到得积分功能。
#### 功能支持:
1. 每日签到奖励 (支持:普通签到、看广告签到)
2. 周期性连续7日签到,奖励翻倍
### 使用看广告签到功能必读
1.`普通签到`是通过clientDb实现,如果你要使用`看广告签到`的方式,
为了防止刷量需要修改`opendb-sign-in.schema``permission` -> `create` 的值设置为`false`
> 文件路径 :`uni_modules/uni-sign-in/uniCloud/database/opendb-sign-in.schema.json`
示例:
```javascript
{
"bsonType": "object",
"required": [],
"permission": {
"read": "auth.uid == doc.user_id",
"create": false,
"update": false,
"delete": false
}
}
```
2. 你需要看激励视频广告相关文档
详情:[https://uniapp.dcloud.net.cn/api/a-d/rewarded-video](https://uniapp.dcloud.net.cn/api/a-d/rewarded-video)
##### 使用方式
```js
<template>
<view>
<uni-sign-in ref="signIn"></uni-sign-in>
<button type="default" @click="signIn">签到</button>
</view>
</template>
<script>
export default {
methods: {
signIn() { //签到
this.$refs.signIn.open()
},
signInByAd(){ //看激励视频广告签到
this.$refs.signIn.showRewardedVideoAd()
},
}
}
</script>
```
> 详情参考[uni-starter](https://ext.dcloud.net.cn/plugin?id=5057)
##### 插件组成
1. 前端组件
<img style="margin-left:30px;width:60vw;max-width:300px;" src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-f184e7c3-1912-41b2-b81f-435d1b37c7b4/ff94178d-6d67-4408-8dde-b06eee8212c9.jpg" />
2. `DB Schema`表结构,
- 描述签到表字段及含义以及读写权限。
- 路径:`/uniCloud/database/opendb-sign-in.schema.json`
> 更多表结构说明详情:[https://uniapp.dcloud.io/uniCloud/schema](https://uniapp.dcloud.io/uniCloud/schema)
3. `uni-clientDB-actions` 一个可编程的 `clientDB` 前置后置操作
- 前置操作,添加操作时检查今日是否未签到,否则拦截
- 后置操作,判断是否已经连续签到7天,决定本次签到用户可得积分
- 后置操作,输出本轮已签到几天,当前积分,已签到的日期数组,本轮签到可得多少分
4. 两个api接口
普通签到`this.$refs.signIn.open()`
看激励视频广告签到`this.$refs.signIn.showRewardedVideoAd()`
#### 常见问题
1. 是否支持配置积分数
答:暂不支持,今后的版本有计划支持
2. 有没有更多玩法
答:计划今后推出
(2.1)需要看广告才能签到 --- 已支持
}
}
}
</script>
```
> 详情参考[uni-starter](https://ext.dcloud.net.cn/plugin?id=5057)
##### 插件组成
1. 前端组件
<img style="margin-left:30px;width:60vw;max-width:300px;" src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-f184e7c3-1912-41b2-b81f-435d1b37c7b4/ff94178d-6d67-4408-8dde-b06eee8212c9.jpg" />
2. `DB Schema`表结构,
- 描述签到表字段及含义以及读写权限。
- 路径:`/uniCloud/database/opendb-sign-in.schema.json`
> 更多表结构说明详情:[https://uniapp.dcloud.io/uniCloud/schema](https://uniapp.dcloud.io/uniCloud/schema)
3. `uni-clientDB-actions` 一个可编程的 `clientDB` 前置后置操作
- 前置操作,添加操作时检查今日是否未签到,否则拦截
- 后置操作,判断是否已经连续签到7天,决定本次签到用户可得积分
- 后置操作,输出本轮已签到几天,当前积分,已签到的日期数组,本轮签到可得多少分
4. 两个api接口
普通签到`this.$refs.signIn.open()`
看激励视频广告签到`this.$refs.signIn.showRewardedVideoAd()`
#### 常见问题
1. 是否支持配置积分数
答:暂不支持,今后的版本有计划支持
2. 有没有更多玩法
答:计划今后推出
(2.1)需要看广告才能签到 --- 已支持
(2.2)补签的玩法
\ No newline at end of file
{
"name": "rewarded-video-ad-notify-url",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sign-in": "file:../common/sign-in",
"uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
}
}
{
"name": "rewarded-video-ad-notify-url",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sign-in": "file:../common/sign-in",
"uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
}
}
// 开发文档:https://uniapp.dcloud.io/uniCloud/clientdb?id=action
const db = uniCloud.database();
const dbCmd = db.command
const signInTable = db.collection('opendb-sign-in');
const scoresTable = db.collection('uni-id-scores');
module.exports = {
before: async (state, event) => {
// console.log({state});
if(state.type == 'create'){
let date = todayTimestamp()
let {total} = await signInTable.where({
user_id:state.auth.uid,
date,
isDelete:false
}).count()
console.log(total);
if(total){
throw new Error("今天已经签到")
}
state.newData.date = date
state.newData.isDelete = false
}
},
after: async (state, event, error, result) => {
if (error) {
throw error
}
let date = todayTimestamp()
//查最近7天的签到情况
let {data:signInData} = await signInTable.where({
user_id:state.auth.uid,
date:dbCmd.gte(date-3600*24*6*1000),
isDelete:false
}).get()
let allDate = signInData.map(item=>item.date)
//今天是本轮签到的第几天
const n = ( date - Math.min(...allDate) )/3600/24/1000+1;
//换成数字--第几天
let days = signInData.map(item=>{
return (n*10000 - (date - item.date)/3600/24/1000*10000)/10000 -1
})
//查出来用户当前有多少积分
let {data: [userScore]} = await scoresTable
.where({user_id:state.auth.uid})
.orderBy("create_date", "desc")
.limit(1)
.get()
let balance = 0
if(userScore){
balance = userScore.balance
}
if(state.type == 'create'){
if(n == 7){ //如果已经满一轮就软删除之前的内容
let setIsDeleteRes = await signInTable.where({
user_id:state.auth.uid,
date:dbCmd.neq(date)
}).update({isDelete:true})
console.log({setIsDeleteRes});
}
//给加积分
let score = n+days.length==14?60:10 //如果连续签到7天就多加50分,也就是60分
balance += score
let addScores = await scoresTable.add({
user_id:state.auth.uid,
balance,
score,
type:1,
create_date:Date.now()
})
console.log({addScores});
}
return {...result,score:balance,signInData,n,days}
}
}
function todayTimestamp(){
//时区
let timeZone = new Date().getTimezoneOffset()/60
//获得相对于北京时间的时间戳
let timestamp = Date.now()+3600*1000*(8+timeZone)
//一天一共多少毫秒
const D = 3600*24*1000
//去掉余数,再减去东8区的8小时 得到当天凌晨的时间戳
return parseInt(timestamp/D)*D - 3600*1000*8
// 开发文档:https://uniapp.dcloud.io/uniCloud/clientdb?id=action
const db = uniCloud.database();
const dbCmd = db.command
const signInTable = db.collection('opendb-sign-in');
const scoresTable = db.collection('uni-id-scores');
module.exports = {
before: async (state, event) => {
// console.log({state});
if(state.type == 'create'){
let date = todayTimestamp()
let {total} = await signInTable.where({
user_id:state.auth.uid,
date,
isDelete:false
}).count()
console.log(total);
if(total){
throw new Error("今天已经签到")
}
state.newData.date = date
state.newData.isDelete = false
}
},
after: async (state, event, error, result) => {
if (error) {
throw error
}
let date = todayTimestamp()
//查最近7天的签到情况
let {data:signInData} = await signInTable.where({
user_id:state.auth.uid,
date:dbCmd.gte(date-3600*24*6*1000),
isDelete:false
}).get()
let allDate = signInData.map(item=>item.date)
//今天是本轮签到的第几天
const n = ( date - Math.min(...allDate) )/3600/24/1000+1;
//换成数字--第几天
let days = signInData.map(item=>{
return (n*10000 - (date - item.date)/3600/24/1000*10000)/10000 -1
})
//查出来用户当前有多少积分
let {data: [userScore]} = await scoresTable
.where({user_id:state.auth.uid})
.orderBy("create_date", "desc")
.limit(1)
.get()
let balance = 0
if(userScore){
balance = userScore.balance
}
if(state.type == 'create'){
if(n == 7){ //如果已经满一轮就软删除之前的内容
let setIsDeleteRes = await signInTable.where({
user_id:state.auth.uid,
date:dbCmd.neq(date)
}).update({isDelete:true})
console.log({setIsDeleteRes});
}
//给加积分
let score = n+days.length==14?60:10 //如果连续签到7天就多加50分,也就是60分
balance += score
let addScores = await scoresTable.add({
user_id:state.auth.uid,
balance,
score,
type:1,
create_date:Date.now()
})
console.log({addScores});
}
return {...result,score:balance,signInData,n,days}
}
}
function todayTimestamp(){
//时区
let timeZone = new Date().getTimezoneOffset()/60
//获得相对于北京时间的时间戳
let timestamp = Date.now()+3600*1000*(8+timeZone)
//一天一共多少毫秒
const D = 3600*24*1000
//去掉余数,再减去东8区的8小时 得到当天凌晨的时间戳
return parseInt(timestamp/D)*D - 3600*1000*8
}
\ No newline at end of file
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": "auth.uid == doc.user_id",
"create": "auth.uid != null && 'signIn' in action", //如果你要使用`看广告签到`的方式请将这里的值改为:false
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id":{
"forceDefaultValue":{
"$env":"uid"
}
},
"date":{
"bsonType":"timestamp",
"description":"签到的日期时间戳",
"permission":{
"write":false
}
},
"create_date":{
"bsonType":"timestamp",
"description":"签到的时间戳",
"forceDefaultValue":{
"$env":"now"
}
},
"ip":{
"bsonType":"string",
"forceDefaultValue":{
"$env":"clientIP"
}
}
}
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": "auth.uid == doc.user_id",
"create": "auth.uid != null && 'signIn' in action", //如果你要使用`看广告签到`的方式请将这里的值改为:false
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id":{
"forceDefaultValue":{
"$env":"uid"
}
},
"date":{
"bsonType":"timestamp",
"description":"签到的日期时间戳",
"permission":{
"write":false
}
},
"create_date":{
"bsonType":"timestamp",
"description":"签到的时间戳",
"forceDefaultValue":{
"$env":"now"
}
},
"ip":{
"bsonType":"string",
"forceDefaultValue":{
"$env":"clientIP"
}
}
}
}
\ No newline at end of file
// ad.js
const ADType = {
RewardedVideo: "RewardedVideo",
FullScreenVideo: "FullScreenVideo"
}
class AdHelper {
constructor() {
this._ads = {}
}
load(options, onload, onerror) {
let ops = this._fixOldOptions(options)
let {
adpid
} = ops
if (!adpid || this.isBusy(adpid)) {
return
}
this.get(ops).load(onload, onerror)
}
show(options, onsuccess, onfail) {
let ops = this._fixOldOptions(options)
let {
adpid
} = ops
if (!adpid) {
return
}
uni.showLoading({
mask: true
})
var ad = this.get(ops)
ad.load(() => {
uni.hideLoading()
ad.show((e) => {
onsuccess && onsuccess(e)
})
}, (err) => {
uni.hideLoading()
onfail && onfail(err)
})
}
isBusy(adpid) {
return (this._ads[adpid] && this._ads[adpid].isLoading)
}
get(options) {
const {
adpid,
singleton = true
} = options
if (singleton === false) {
if (this._ads[adpid]) {
this._ads[adpid].destroy()
delete this._ads[adpid]
}
}
delete options.singleton
if (!this._ads[adpid]) {
this._ads[adpid] = this._createAdInstance(options)
}
return this._ads[adpid]
}
_createAdInstance(options) {
const adType = options.adType || ADType.RewardedVideo
delete options.adType
let ad = null;
if (adType === ADType.RewardedVideo) {
ad = new RewardedVideo(options)
} else if (adType === ADType.FullScreenVideo) {
ad = new FullScreenVideo(options)
}
return ad
}
_fixOldOptions(options) {
return (typeof options === "string") ? {
adpid: options
} : options
}
}
const EXPIRED_TIME = 1000 * 60 * 30
const ProviderType = {
CSJ: 'csj',
GDT: 'gdt'
}
const RETRY_COUNT = 1
class AdBase {
constructor(adInstance, options = {}) {
this._isLoad = false
this._isLoading = false
this._lastLoadTime = 0
this._lastError = null
this._retryCount = 0
this._loadCallback = null
this._closeCallback = null
this._errorCallback = null
const ad = this._ad = adInstance
ad.onLoad((e) => {
this._isLoading = false
this._isLoad = true
this._lastLoadTime = Date.now()
this.onLoad()
})
ad.onClose((e) => {
this._isLoad = false
this.onClose(e)
})
ad.onVerify && ad.onVerify((e) => {
// e.isValid
})
ad.onError(({
code,
message
}) => {
this._isLoading = false
const data = {
code: code,
errMsg: message
}
if (code === -5008) {
this._loadAd()
return
}
if (this._retryCount < RETRY_COUNT) {
this._retryCount += 1
this._loadAd()
return
}
this._lastError = data
this.onError(data)
})
}
get isExpired() {
return (this._lastLoadTime !== 0 && (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME))
}
get isLoading() {
return this._isLoading
}
getProvider() {
return this._ad.getProvider()
}
load(onload, onerror) {
this._loadCallback = onload
this._errorCallback = onerror
if (this._isLoading) {
return
}
if (this._isLoad) {
this.onLoad()
return
}
this._retryCount = 0
this._loadAd()
}
show(onclose) {
this._closeCallback = onclose
if (this._isLoading || !this._isLoad) {
return
}
if (this._lastError !== null) {
this.onError(this._lastError)
return
}
const provider = this.getProvider()
if (provider === ProviderType.CSJ && this.isExpired) {
this._loadAd()
return
}
this._ad.show()
}
onLoad(e) {
if (this._loadCallback != null) {
this._loadCallback()
}
}
onClose(e) {
if (this._closeCallback != null) {
this._closeCallback({
isEnded: e.isEnded
})
}
}
onError(e) {
if (this._errorCallback != null) {
this._errorCallback(e)
}
}
destroy() {
this._ad.destroy()
}
_loadAd() {
this._isLoad = false
this._isLoading = true
this._lastError = null
this._ad.load()
}
}
class RewardedVideo extends AdBase {
constructor(options = {}) {
super(plus.ad.createRewardedVideoAd(options), options)
}
}
class FullScreenVideo extends AdBase {
constructor(options = {}) {
super(plus.ad.createFullScreenVideoAd(options), options)
}
}
// ad.js
const ADType = {
RewardedVideo: "RewardedVideo",
FullScreenVideo: "FullScreenVideo"
}
class AdHelper {
constructor() {
this._ads = {}
}
load(options, onload, onerror) {
let ops = this._fixOldOptions(options)
let {
adpid
} = ops
if (!adpid || this.isBusy(adpid)) {
return
}
this.get(ops).load(onload, onerror)
}
show(options, onsuccess, onfail) {
let ops = this._fixOldOptions(options)
let {
adpid
} = ops
if (!adpid) {
return
}
uni.showLoading({
mask: true
})
var ad = this.get(ops)
ad.load(() => {
uni.hideLoading()
ad.show((e) => {
onsuccess && onsuccess(e)
})
}, (err) => {
uni.hideLoading()
onfail && onfail(err)
})
}
isBusy(adpid) {
return (this._ads[adpid] && this._ads[adpid].isLoading)
}
get(options) {
const {
adpid,
singleton = true
} = options
if (singleton === false) {
if (this._ads[adpid]) {
this._ads[adpid].destroy()
delete this._ads[adpid]
}
}
delete options.singleton
if (!this._ads[adpid]) {
this._ads[adpid] = this._createAdInstance(options)
}
return this._ads[adpid]
}
_createAdInstance(options) {
const adType = options.adType || ADType.RewardedVideo
delete options.adType
let ad = null;
if (adType === ADType.RewardedVideo) {
ad = new RewardedVideo(options)
} else if (adType === ADType.FullScreenVideo) {
ad = new FullScreenVideo(options)
}
return ad
}
_fixOldOptions(options) {
return (typeof options === "string") ? {
adpid: options
} : options
}
}
const EXPIRED_TIME = 1000 * 60 * 30
const ProviderType = {
CSJ: 'csj',
GDT: 'gdt'
}
const RETRY_COUNT = 1
class AdBase {
constructor(adInstance, options = {}) {
this._isLoad = false
this._isLoading = false
this._lastLoadTime = 0
this._lastError = null
this._retryCount = 0
this._loadCallback = null
this._closeCallback = null
this._errorCallback = null
const ad = this._ad = adInstance
ad.onLoad((e) => {
this._isLoading = false
this._isLoad = true
this._lastLoadTime = Date.now()
this.onLoad()
})
ad.onClose((e) => {
this._isLoad = false
this.onClose(e)
})
ad.onVerify && ad.onVerify((e) => {
// e.isValid
})
ad.onError(({
code,
message
}) => {
this._isLoading = false
const data = {
code: code,
errMsg: message
}
if (code === -5008) {
this._loadAd()
return
}
if (this._retryCount < RETRY_COUNT) {
this._retryCount += 1
this._loadAd()
return
}
this._lastError = data
this.onError(data)
})
}
get isExpired() {
return (this._lastLoadTime !== 0 && (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME))
}
get isLoading() {
return this._isLoading
}
getProvider() {
return this._ad.getProvider()
}
load(onload, onerror) {
this._loadCallback = onload
this._errorCallback = onerror
if (this._isLoading) {
return
}
if (this._isLoad) {
this.onLoad()
return
}
this._retryCount = 0
this._loadAd()
}
show(onclose) {
this._closeCallback = onclose
if (this._isLoading || !this._isLoad) {
return
}
if (this._lastError !== null) {
this.onError(this._lastError)
return
}
const provider = this.getProvider()
if (provider === ProviderType.CSJ && this.isExpired) {
this._loadAd()
return
}
this._ad.show()
}
onLoad(e) {
if (this._loadCallback != null) {
this._loadCallback()
}
}
onClose(e) {
if (this._closeCallback != null) {
this._closeCallback({
isEnded: e.isEnded
})
}
}
onError(e) {
if (this._errorCallback != null) {
this._errorCallback(e)
}
}
destroy() {
this._ad.destroy()
}
_loadAd() {
this._isLoad = false
this._isLoading = true
this._lastError = null
this._ad.load()
}
}
class RewardedVideo extends AdBase {
constructor(options = {}) {
super(plus.ad.createRewardedVideoAd(options), options)
}
}
class FullScreenVideo extends AdBase {
constructor(options = {}) {
super(plus.ad.createFullScreenVideoAd(options), options)
}
}
export default new AdHelper()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册