Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
17fe6c55
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6096
Star
97
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
17fe6c55
编写于
1月 23, 2024
作者:
张
张磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增激励视频广告和权限申请监听示例
上级
148c7128
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
207 addition
and
13 deletion
+207
-13
pages.json
pages.json
+17
-1
pages/API/create-request-permission-listener/create-request-permission-listener.uvue
...rmission-listener/create-request-permission-listener.uvue
+87
-0
pages/API/rewarded-video-ad/rewarded-video-ad.uvue
pages/API/rewarded-video-ad/rewarded-video-ad.uvue
+72
-0
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+31
-12
未找到文件。
pages.json
浏览文件 @
17fe6c55
...
...
@@ -1153,7 +1153,23 @@
"navigationBarTitleText"
:
"webview 截图测试"
,
"navigationStyle"
:
"custom"
}
}
},
//
#ifdef
APP
{
"path"
:
"pages/API/rewarded-video-ad/rewarded-video-ad"
,
"style"
:
{
"navigationBarTitleText"
:
"激励视频广告"
,
"enablePullDownRefresh"
:
false
}
},
{
"path"
:
"pages/API/create-request-permission-listener/create-request-permission-listener"
,
"style"
:
{
"navigationBarTitleText"
:
"权限申请监听"
,
"enablePullDownRefresh"
:
false
}
}
//
#endif
],
"globalStyle"
:
{
"pageOrientation"
:
"portrait"
,
...
...
pages/API/create-request-permission-listener/create-request-permission-listener.uvue
0 → 100644
浏览文件 @
17fe6c55
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<page-head title="权限申请监听"></page-head>
<view class="permission-alert" id="permission-alert" :style="{'transform':isPermissionAlertShow ? 'translateY(0)':'translateY(-110px)'}">
<text style="font-size: 20px;margin-bottom: 10px;margin-top: 5px;">手机状态权限申请说明:</text>
<text style="color: darkgray;">uni-app x正在申请手机状态权限,允许或拒绝均不会获取任何隐私信息。</text>
</view>
<button type="primary" style="margin: 10px;" @click="requestPermission">点击申请权限</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
isPermissionAlertShow: false,
permissionAlert: null as UniElement | null,
timeoutId: -1,
permissionListener: null as RequestPermissionListener | null
}
},
onReady() {
this.watchPermissionRRequest()
},
onUnload() {
this.permissionListener?.stop()
this.permissionListener = null
clearTimeout(this.timeoutId)
},
methods: {
watchPermissionRRequest() {
this.permissionListener = uni.createRequestPermissionListener()
this.permissionListener!.onConfirm((_) => {
this.timeoutId = setTimeout(() => {
this.isPermissionAlertShow = true
}, 100)
})
this.permissionListener!.onComplete((_) => {
clearTimeout(this.timeoutId)
this.isPermissionAlertShow = false
})
},
requestPermission() {
// #ifdef APP-ANDROID
if (UTSAndroid.checkSystemPermissionGranted(UTSAndroid.getUniActivity()!, ["android.permission.READ_PHONE_STATE"])) {
uni.showToast({
title: "权限已经同意了,不需要再申请",
position: "bottom"
})
return
}
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, ["android.permission.READ_PHONE_STATE"], (_ : boolean, p : string[]) => {
console.log(p)
}, (_ : boolean, p : string[]) => {
uni.showToast({
title: "权限被拒绝了",
position: "bottom"
})
console.log(p)
})
// #endif
}
}
}
</script>
<style>
.permission-alert {
width: 90%;
height: 100px;
margin: 10px 5%;
position: absolute;
top: 0px;
z-index: 3;
border-radius: 5px;
transition-property: transform;
transition-duration: 200ms;
background-color: white;
padding: 10px;
}
</style>
pages/API/rewarded-video-ad/rewarded-video-ad.uvue
0 → 100644
浏览文件 @
17fe6c55
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<page-head title="激励视频广告"></page-head>
<button :type="btnType" style="margin: 10px;" :disabled="btnDisable" @click="showAd()">{{btnText}}</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
btnText: "",
btnType: "primary",
btnDisable: false,
rewardAd: null as RewardedVideoAd | null,
isAdLoadSuccess:false
}
},
onReady() {
this.loadAd()
},
methods: {
loadAd() {
if (this.btnDisable)
return
this.btnDisable = true
this.btnText = "正在加载广告"
this.btnType = "primary"
if (this.rewardAd == null) {
this.rewardAd = uni.createRewardedVideoAd({
adpid: "1507000689"
})
this.rewardAd!.onError((_) => {
this.btnType = "warn"
this.btnText = "广告加载失败,点击重试"
this.btnDisable = false
})
this.rewardAd!.onLoad((_) => {
this.btnType = "primary"
this.btnText = "广告加载成功,点击观看"
this.btnDisable = false
this.isAdLoadSuccess = true
})
this.rewardAd!.onClose((e) => {
this.isAdLoadSuccess = false
uni.showToast({
title: "激励视频" + (e.isEnded ? "" : "未") + "播放完毕",
position: "bottom"
})
this.loadAd()
})
}
this.rewardAd!.load()
},
showAd(){
if(this.isAdLoadSuccess) {
this.rewardAd!.show()
} else {
this.loadAd()
}
}
}
}
</script>
<style>
</style>
pages/tabBar/API.uvue
浏览文件 @
17fe6c55
...
...
@@ -8,17 +8,14 @@
</view>
<view class="uni-text-box">
<text class="hello-text">以下将演示uni-app接口能力,详细文档见:</text>
<u-link :href="'https://uniapp.dcloud.io/uni-app-x/api/'" :text="'https://uniapp.dcloud.io/uni-app-x/api/'"
:inWhiteList="true"></u-link>
<u-link :href="'https://uniapp.dcloud.io/uni-app-x/api/'" :text="'https://uniapp.dcloud.io/uni-app-x/api/'" :inWhiteList="true"></u-link>
</view>
<uni-collapse>
<template v-for="item in list" :key="item.id">
<uni-collapse-item :title="item.name" class="item">
<view class="uni-navigate-item" :hover-class="page.enable == false?'':'is--active'"
v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(page)">
<text class="uni-navigate-text"
:class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
<view class="uni-navigate-item" :hover-class="page.enable == false?'':'is--active'" v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(page)">
<text class="uni-navigate-text" :class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
<image :src="arrowRightIcon" class="uni-icon-size"></image>
</view>
</uni-collapse-item>
...
...
@@ -455,6 +452,28 @@
] as Page[],
},
// #endif
// #ifdef APP-ANDROID
{
id: 'ad',
name: '广告',
pages: [
{
name: '激励视频广告',
url: 'rewarded-video-ad',
}
] as Page[],
},
{
id: 'permission-listener',
name: '权限申请监听',
pages: [
{
name: '权限申请监听',
url: 'create-request-permission-listener',
}
] as Page[]
},
// #endif
/* {
id: "rewarded-video-ad",
url: "rewarded-video-ad",
...
...
@@ -548,14 +567,14 @@
}
.popup {
width: 100%;
width: 100%;
/* #ifdef APP */
position: absolute;
height: 100%;
/* #else */
position: fixed;
top: var(--window-top);
bottom: var(--window-bottom);
height: 100%;
/* #else */
position: fixed;
top: var(--window-top);
bottom: var(--window-bottom);
/* #endif */
align-items: center;
justify-content: center;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录