4 Commits

920 changed files with 1708 additions and 23539 deletions

View File

@@ -22,6 +22,11 @@ export default {
platform: null, // 系统
};
},
onShow: function() {
// #ifdef APP-PLUS
// screenshot.onAntiScreenshot()
// #endif
},
onLaunch: function (e) {
// 检测自动更新
// #ifdef APP-PLUS
@@ -88,7 +93,7 @@ export default {
success(res) {
Vue.prototype.winWidth = res.screenWidth;
Vue.prototype.winHeight = res.screenHeight;
Vue.prototype.statusBarHeight = res.statusBarHeight;
Vue.prototype.statusBarHeight = res.statusBarHeight || 0;
},
});
@@ -246,7 +251,6 @@ export default {
});
}
},
},
};
</script>

View File

@@ -3,14 +3,14 @@ let socketUrl = "";
if (process.env.NODE_ENV === 'development') {
// 开发环境
// baseUrl = "https://testapi.nuttyreading.com/"; // 线上测试
// baseUrl = "https://api.nuttyreading.com/"; //线上正式'
baseUrl = "https://api.nuttyreading.com/"; //线上正式'
// baseUrl = "http://192.168.110.100:9200/pb/"; //张川川
baseUrl = "http://192.168.110.131:9200/pb/"; // 王亚男
// baseUrl = "http://192.168.110.131:9200/pb/"; // 王亚男
} else if (process.env.NODE_ENV === 'production') {
// 生产环境11
baseUrl = "https://api.nuttyreading.com/"; //线上正式
//baseUrl = "https://testapi.nuttyreading.com/";
// baseUrl = "http://192.168.110.100:9200/pb/"; //张川川
// baseUrl = "https://testapi.nuttyreading.com/";
// baseUrl = "http://192.168.110.131:9200/pb/"; // 本地
}
const courtConfig = {
//微信公众号APPID1

View File

@@ -12,8 +12,8 @@
"src" : "图片路径"
}
],
"versionName" : "2.0.51",
"versionCode" : 2051,
"versionName" : "2.0.54",
"versionCode" : 2054,
"sassImplementationName" : "node-sass",
"app-plus" : {
"nvueCompiler" : "uni-app",

20
package-lock.json generated
View File

@@ -11,7 +11,7 @@
"dependencies": {
"animate.css": "^4.1.1",
"e-peanut": "file:",
"edu-core": "file:../edu-core",
"edu-core": "git+https://git.nuttyreading.com/chenghuan/edu-core.git#v1.0.15",
"element-plus": "^2.9.6",
"epubjs": "^0.3.93",
"jquery": "^2.2.4",
@@ -23,11 +23,6 @@
" ../edu-core": {
"extraneous": true
},
"../edu-core": {
"version": "1.0.13",
"license": "ISC",
"devDependencies": {}
},
"node_modules/@babel/helper-string-parser": {
"version": "7.27.1",
"resolved": "https://registry.npmmirror.com/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz",
@@ -440,8 +435,9 @@
"link": true
},
"node_modules/edu-core": {
"resolved": "../edu-core",
"link": true
"version": "1.0.15",
"resolved": "git+https://git.nuttyreading.com/chenghuan/edu-core.git#df2306c058445de44914622bf56459f76247f5b1",
"license": "ISC"
},
"node_modules/element-plus": {
"version": "2.11.5",
@@ -4177,7 +4173,7 @@
"requires": {
"animate.css": "^4.1.1",
"e-peanut": "file:",
"edu-core": "file:../edu-core",
"edu-core": "git+https://git.nuttyreading.com/chenghuan/edu-core.git#v1.0.15",
"element-plus": "^2.9.6",
"epubjs": "^0.3.93",
"jquery": "^2.2.4",
@@ -4498,7 +4494,8 @@
}
},
"edu-core": {
"version": "file:../edu-core"
"version": "git+https://git.nuttyreading.com/chenghuan/edu-core.git#df2306c058445de44914622bf56459f76247f5b1",
"from": "edu-core@git+https://git.nuttyreading.com/chenghuan/edu-core.git#v1.0.15"
},
"element-plus": {
"version": "2.11.5",
@@ -7259,7 +7256,8 @@
}
},
"edu-core": {
"version": "file:../edu-core"
"version": "git+https://git.nuttyreading.com/chenghuan/edu-core.git#df2306c058445de44914622bf56459f76247f5b1",
"from": "edu-core@git+https://git.nuttyreading.com/chenghuan/edu-core.git#v1.0.15"
},
"element-plus": {
"version": "2.11.5",

View File

@@ -7,7 +7,7 @@
"dependencies": {
"animate.css": "^4.1.1",
"e-peanut": "file:",
"edu-core": "file:../edu-core",
"edu-core": "git+https://git.nuttyreading.com/chenghuan/edu-core.git#v1.0.15",
"element-plus": "^2.9.6",
"epubjs": "^0.3.93",
"jquery": "^2.2.4",

View File

@@ -3,6 +3,12 @@
// "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
// },
"pages": [
// {
// "path": "pages/test/test",
// "style": {
// "navigationBarTitleText": "测试页"
// }
// },
{
"path": "pages/peanut/home",
"style": {
@@ -539,6 +545,13 @@
"enablePullDownRefresh": false
}
},
{
"path": "pages/medicaldes/medurl",
"style": {
"navigationBarTitleText": "详细介绍",
"enablePullDownRefresh": false
}
},
{
"path": "pages/medicaldes/recordDetail",
"style": {
@@ -813,7 +826,6 @@
"navigationBarTitleText" : "数据迁移"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",

View File

@@ -20,6 +20,7 @@
:course="{courseTitle:options.navTitle, chapterTitle: curriculumData.title, catalogueId: curriculumData.catalogueId || '', courseId: curriculumData.courseId || options.courseId || ''}"
:cover="options.curriculumImgUrl || ''"
:http="$http"
:user-info="userInfo"
/>
<view class="" style="border-top: 2px solid #2979ff;">
@@ -171,6 +172,7 @@
import {
mapState
} from "vuex";
export default {
components: {
courseDescription, //课程说明
@@ -327,11 +329,9 @@
this.hideNextVideo()
},
onUnload() {
},
onHide() {
console.log('回去了 .....................');
},
onPullDownRefresh() {
uni.stopPullDownRefresh();

View File

@@ -26,11 +26,14 @@
<view class="item" v-html="prescriptDetail.city_name">
</view>
</uni-section>
<uni-section class="mb-10" titleFontSize="18px" title="详细介绍" type="line"
<uni-section class="mb-10" titleFontSize="18px" title="说明" type="line"
v-if="prescriptDetail.content && prescriptDetail.content != ''">
<view class="item" v-html="prescriptDetail.content">
</view>
</uni-section>
<div class="detail-link-wrap" v-if="prescriptDetail.url && prescriptDetail.url != ''">
<text class="detail-link" @click="openDetailUrl">详细介绍&gt;&gt;</text>
</div>
<!-- <uni-section class="mb-10" titleFontSize="18px" title="配伍" type="line">
<view class="item" v-if="prescriptDetail.compatibility && prescriptDetail.compatibility != ''" v-html="prescriptDetail.compatibility">
@@ -92,6 +95,11 @@
}
});
},
openDetailUrl() {
uni.navigateTo({
url: '/pages/medicaldes/medurl?url=' + encodeURIComponent(this.prescriptDetail.url)
})
},
// 方剂详情
getDetail() {
$http.request({
@@ -168,6 +176,18 @@
display: flex;
}
.detail-link-wrap {
padding: 10rpx 20rpx;
padding-bottom: 20rpx;
.detail-link {
font-size: 14px;
font-weight: bold;
color: #007aff;
text-decoration: none;
}
}
/deep/ .uni-section-header__decoration.line {
background-color: #18bc37;
}

View File

@@ -23,7 +23,25 @@
};
},
onLoad(e) {
this.id = uni.getStorageSync('prescriptUrl')
this.id = e.url ? decodeURIComponent(e.url) : uni.getStorageSync('prescriptUrl')
// #ifdef APP-PLUS
const pages = getCurrentPages()
const page = pages[pages.length - 1];
const currentWebview = page.$getAppWebview()
currentWebview.setStyle({
titleNView: {
buttons: [{
float: 'right',
type: 'close',
onclick: function() {
uni.navigateBack({
delta: 1
});
}
}]
}
})
// #endif
},
computed: {

93
pages/test/test.vue Normal file
View File

@@ -0,0 +1,93 @@
<template>
<view class="content">
<view class="btn" @click="onAntiScreenshot"><text>开启防截屏</text></view>
<view class="btn" @click="onAntiScreenshot2"><text>开启防截屏</text></view>
<view class="btn" @click="offAntiScreenshot"><text>关闭防截屏</text></view>
<view class="btn" @click="offAntiScreenshot2"><text>关闭防截屏</text></view>
<view class="btn" @click="testCaptureScreen"><text>截屏测试</text></view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
onAntiScreenshot() {
console.log('点击了开启按钮')
// screenshot.onAntiScreenshot()
// screenGuard.onAntiScreenshot()
uni.setUserCaptureScreen({
enable: false,
success() {
console.log('截屏录屏功能已禁用');
},
fail(err) {
console.error('禁用截屏录屏功能失败', err);
}
});
},
offAntiScreenshot() {
console.log('点击了关闭按钮')
// screenshot.offAntiScreenshot()
// screenGuard.offAntiScreenshot()
uni.setUserCaptureScreen({
enable: true,
success() {
console.log('截屏录屏功能已启用');
},
fail(err) {
console.error('启用截屏录屏功能失败', err);
}
})
},
onAntiScreenshot2() {
console.log('点击了开启按钮')
// screenshot.onAntiScreenshot()
screenGuard.onAntiScreenshot()
},
offAntiScreenshot2() {
console.log('点击了关闭按钮')
// screenshot.offAntiScreenshot()
screenGuard.offAntiScreenshot()
},
testCaptureScreen() {
console.log('点击了截屏测试按钮')
// #ifdef APP-PLUS
this.$captureScreen({
success(res) {
console.log('截屏成功', res.base64 && res.base64.length)
},
fail(err) {
console.error('截屏失败', err)
}
})
// #endif
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.btn {
display: flex;
align-items: center;
justify-content: center;
background-color: antiquewhite;
border-radius: 8rpx;
width: 690rpx;
height: 80rpx;
margin-top: 40rpx;
}
</style>

View File

@@ -0,0 +1,16 @@
## 1.0.72026-06-16
- 新增 iOS setUserCaptureScreen 支持 antiRecordOnly 参数enable 为 false 且 antiRecordOnly 为 true 时,仅禁止录屏/投屏允许截屏。实现方式为进入时提前挂载安全层UITextField.isSecureTextEntry默认不保护、保留 field 实例),通过 UIScreen.isCaptured 监听录屏/投屏,仅在录屏期间翻转 isSecureTextEntry——实时显示正常、录制到的文件为黑屏平时不影响截屏录屏进行中截屏也为黑。Android/鸿蒙忽略该参数,仍为截屏+录屏一起禁止。
## 1.0.62024-11-22
- 修复 HarmonyOS Next 上调用 setUserCaptureScreen 报错的 Bug
## 1.0.52024-10-14
- 新增 支持 HarmonyOS Next 调用
## 1.0.42023-03-24
新增开启/关闭防截屏功能
## 1.0.32023-03-17
修复android平台 部分场景下js可能报错的问题
## 1.0.22023-03-16
修复Android平台在小米设备无法监听的问题 修复Android平台调用uni.onUserCaptureScreen必然会触发回调的问题
## 1.0.12022-10-27
修改插件描述
## 1.0.02022-10-26
支持安卓、iOS、微信小程序平台

View File

@@ -0,0 +1,163 @@
declare namespace UniNamespace {
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
*/
type OnUserCaptureScreenCallbackResult = {
/**
* 截屏文件路径仅Android返回
*/
path ?: string
}
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调函数定义
*/
type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.setUserCaptureScreen成功回调参数
*/
type SetUserCaptureScreenSuccess = {
}
/**
* uni.setUserCaptureScreen成功回调函数定义
*/
type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuccess) => void
/**
* 错误码
* - 12001 "setUserCaptureScreen:system not support"
* - 12010 "setUserCaptureScreen:system internal error"
*/
type SetUserCaptureScreenErrorCode = 12001 | 12010;
/**
* SetUserCaptureScreen 的错误回调参数
*/
interface SetUserCaptureScreenFail {
errCode : SetUserCaptureScreenErrorCode
}
/**
* uni.setUserCaptureScreen失败回调函数定义
*/
type SetUserCaptureScreenFailCallback = (res : SetUserCaptureScreenFail) => void
/**
* uni.setUserCaptureScreen完成回调函数定义
*/
type SetUserCaptureScreenCompleteCallback = (res : any) => void
/**
* uni.setUserCaptureScreen参数
*/
type SetUserCaptureScreenOptions = {
/**
* true: 允许用户截屏 false: 不允许用户截屏,防止用户截屏到应用页面内容
*/
enable : boolean;
/**
* 仅 iOS 生效。仅在 enable 为 false 时有意义:
* true: 仅禁止录屏/投屏(录屏时画面被遮挡),允许截屏;
* false/不传: 截屏与录屏一起禁止(默认行为)。
*/
antiRecordOnly ?: boolean;
/**
* 接口调用成功的回调函数
*/
// success : SetUserCaptureScreenSuccessCallback | null,
success ?: SetUserCaptureScreenSuccessCallback,
/**
* 接口调用失败的回调函数
*/
// fail : SetUserCaptureScreenFailCallback | null,
fail ?: SetUserCaptureScreenFailCallback,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
// complete : SetUserCaptureScreenSuccessCallback | SetUserCaptureScreenFailCallback | null
complete ?: SetUserCaptureScreenCompleteCallback
}
type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
}
declare interface Uni {
/**
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onUserCaptureScreen(callback : UniNamespace.UserCaptureScreenCallback | null) : void,
/**
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offUserCaptureScreen(callback : UniNamespace.UserCaptureScreenCallback | null) : void,
/**
* 设置防截屏
*
* @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "13.0",
* "uniVer": "3.7.7",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
*/
setUserCaptureScreen(options : UniNamespace.SetUserCaptureScreenOptions) : void
}

View File

@@ -0,0 +1,97 @@
{
"id": "uni-usercapturescreen",
"displayName": "uni-usercapturescreen",
"version": "1.0.7",
"description": "用户主动截屏事件监听",
"keywords": [
"截屏"
],
"repository": "",
"engines": {
"HBuilderX": "^3.7.7"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"uni-ext-api":{
"uni": {
"onUserCaptureScreen": {
"web": false
},
"offUserCaptureScreen": {
"web": false
},
"setUserCaptureScreen": {
"web": false,
"mp-weixin": false
}
}
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y",
"alipay": "n"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "y",
"app-harmony": "y"
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "y",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n",
"京东": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
# uni-usercapturescreen
用户主动截屏事件监听
### uni.onUserCaptureScreen
监听用户主动截屏事件,用户使用系统截屏按键截屏时触发此事件。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen)
### uni.offUserCaptureScreen
用户主动截屏事件。取消事件监听。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen)
### uni.setUserCaptureScreen
开启/关闭防截屏。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen)

View File

@@ -0,0 +1,139 @@
import { UTSAndroid } from "io.dcloud.uts";
import ActivityCompat from "androidx.core.app.ActivityCompat";
import Manifest from "android.Manifest";
import PackageManager from "android.content.pm.PackageManager";
import Build from "android.os.Build";
import FileObserver from "android.os.FileObserver";
import File from "java.io.File";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
import { OnUserCaptureScreenCallbackResult, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreenSuccess, SetUserCaptureScreenOptions, SetUserCaptureScreen } from "../interface.uts";
import string from 'android.R.string';
/**
* 文件监听器
*/
let observer : ScreenFileObserver | null = null;
/**
* 记录文件监听器上次监听的时间戳,避免重复监听
*/
let lastObserverTime : number = 0;
/**
* 截屏回调
*/
let listener : UserCaptureScreenCallback | null = null;
/**
* android 文件监听实现
*/
class ScreenFileObserver extends FileObserver {
/**
* 截屏文件目录
*/
private screenFile : File;
constructor(screenFileStr : string) {
super(screenFileStr);
this.screenFile = new File(screenFileStr);
}
override onEvent(event : Int, path : string | null) : void {
// 只监听文件新增事件
if (event == FileObserver.CREATE) {
if (path != null) {
const currentTime = System.currentTimeMillis();
if ((currentTime - lastObserverTime) < 1000) {
// 本地截屏行为比上一次超过1000ms, 才认为是一个有效的时间
return;
}
lastObserverTime = currentTime;
const screenShotPath = new File(this.screenFile, path).getPath();
const res : OnUserCaptureScreenCallbackResult = {
path: screenShotPath
}
listener?.(res);
}
}
}
}
/**
* 开启截图监听
*/
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
// 检查相关权限是否已授予
if (ActivityCompat.checkSelfPermission(UTSAndroid.getAppContext()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// 无权限,申请权限
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1001);
return;
}
// 更新监听
listener = callback;
let directory_screenshot : File;
if (Build.MANUFACTURER.toLowerCase() == "xiaomi") {
// @Suppress("DEPRECATION")
directory_screenshot = new File(new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM), "Screenshots");
} else {
// @Suppress("DEPRECATION")
directory_screenshot = new File(new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES), "Screenshots");
}
// 先结束监听 再开启监听
observer?.stopWatching();
observer = new ScreenFileObserver(directory_screenshot.getPath());
observer?.startWatching();
UTSAndroid.onAppActivityDestroy(function(){
observer?.stopWatching()
observer = null
})
}
/**
* 关闭截屏监听
*/
export const offUserCaptureScreen : OffUserCaptureScreen = function (_ : UserCaptureScreenCallback | null) {
// android10以上关闭监听通过移除文件监听器实现
observer?.stopWatching();
observer = null;
lastObserverTime = 0;
}
/**
* 设置是否禁止截屏
*/
export const setUserCaptureScreen : SetUserCaptureScreen = function (option : SetUserCaptureScreenOptions) {
// 切换到UI线程
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.enable));
const res : SetUserCaptureScreenSuccess = {}
option.success?.(res);
option.complete?.(res);
}
class SetUserCaptureScreenRunnable extends Runnable {
/**
* ture: 允许用户截屏
* false: 不允许用户截屏,防止用户截屏到应用页面内容
*/
private enable : boolean;
constructor(enable : boolean) {
super();
this.enable = enable;
}
override run() : void {
if (this.enable) {
UTSAndroid.getUniActivity()?.getWindow()?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
UTSAndroid.getUniActivity()?.getWindow()?.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
}

View File

@@ -0,0 +1,87 @@
import { display } from '@kit.ArkUI';
import { window } from '@kit.ArkUI';
import { Callback, BusinessError } from '@kit.BasicServicesKit';
import { getAbilityContext } from '@dcloudio/uni-runtime';
import {
OnUserCaptureScreen, UserCaptureScreenCallback,
OffUserCaptureScreen,
SetUserCaptureScreen, SetUserCaptureScreenOptions, SetUserCaptureScreenSuccess
} from '../interface.uts';
const onUserCaptureScreenCallbacks: Function[] = []
const harmonyCaptureStatusChange: Callback<boolean> = (captureStatus: boolean) => {
if (captureStatus) {
onUserCaptureScreenCallbacks.forEach(cb => {
typeof cb === 'function' && cb()
})
}
}
display.on('captureStatusChange', harmonyCaptureStatusChange)
export const onUserCaptureScreen: OnUserCaptureScreen = function (callback: UserCaptureScreenCallback | null) {
if (callback) {
onUserCaptureScreenCallbacks.push(callback)
}
}
export const offUserCaptureScreen: OffUserCaptureScreen = function (callback: UserCaptureScreenCallback | null) {
if (callback) {
const index = onUserCaptureScreenCallbacks.indexOf(callback)
if (index > -1) {
onUserCaptureScreenCallbacks.splice(index, 1)
}
}
}
export const setUserCaptureScreen: SetUserCaptureScreen = function (options: SetUserCaptureScreenOptions) {
const errSubject = 'uni-usercapturescreen'
const setUserCaptureScreenSuccess: SetUserCaptureScreenSuccess = {}
window.getLastWindow(getAbilityContext()!, (err, window) => {
const errCode: number = err.code;
if (errCode) {
options.fail?.({
errCode: (err as BusinessError).code,
errSubject,
errMsg: `setUserCaptureScreen:fail ${(err as BusinessError).message}`
} as IUniError)
options.complete?.(setUserCaptureScreenSuccess);
return;
} else {
try {
UTSHarmony.requestSystemPermission(['ohos.permission.PRIVACY_WINDOW'], (allRight: boolean, _grantedList: string[]) => {
if (allRight) {
window.setWindowPrivacyMode(!options.enable, (err: BusinessError) => {
const errCode: number = err.code;
if (errCode) {
options.fail?.({
errCode: err.code,
errSubject,
errMsg: `setUserCaptureScreen:fail ${err.message}`
} as IUniError)
options.complete?.(setUserCaptureScreenSuccess);
return;
}
options.success?.(setUserCaptureScreenSuccess);
options.complete?.(setUserCaptureScreenSuccess);
});
} else {
throw new Error('permission denied')
}
}, (_doNotAskAgain: boolean, _grantedList: string[]) => {
throw new Error('permission denied');
})
} catch (err) {
options.fail?.({
errCode: (err as BusinessError).code,
errSubject,
errMsg: `setUserCaptureScreen:fail ${(err as BusinessError).message}`
} as IUniError)
options.complete?.(setUserCaptureScreenSuccess);
}
}
})
}

View File

@@ -0,0 +1,324 @@
import { NotificationCenter } from 'Foundation';
import { CGRect } from "CoreFoundation";
import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit"
import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
import { SetUserCaptureScreenOptions, OnUserCaptureScreenCallbackResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen, UserCaptureScreenCallback, SetUserCaptureScreenSuccess } from "../interface.uts"
import { SetUserCaptureScreenFailImpl } from "../unierror.uts"
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener : UserCaptureScreenCallback | null;
static secureView : UIView | null;
// ===== 仅防录屏(动态切换)相关状态 =====
// 保留 UITextField使 isSecureTextEntry 可在录屏开始/结束时反复切换
static secureField : UITextField | null;
// field 的安全画布(已挂入视图层级,承载 App 根视图)
static secureCanvas : UIView | null;
// 被安全画布包裹的 App 根视图(用于卸载时还原)
static secureRootView : UIView | null;
// 是否已为"仅防录屏"挂载安全层
static recordWrapped : boolean = false;
// 监听截屏
static listenCaptureScreen(callback : UserCaptureScreenCallback | null) {
this.listener = callback
// 注册监听截屏事件及回调方法
// target-action 回调方法需要通过 Selector("方法名") 构建
const method = Selector("userDidTakeScreenshot")
NotificationCenter.default.addObserver(this, selector = method, name = UIApplication.userDidTakeScreenshotNotification, object = null)
}
// 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
// 回调
const res: OnUserCaptureScreenCallbackResult = {
}
this.listener?.(res)
}
// 移除监听事件
static removeListen(callback : UserCaptureScreenCallback | null) {
this.listener = null
NotificationCenter.default.removeObserver(this)
}
static createSecureView() : UIView | null {
let field = new UITextField(frame = CGRect.zero)
field.isSecureTextEntry = true
if (field.subviews.length > 0 && UIDevice.current.systemVersion != '15.1') {
let view = field.subviews[0]
view.subviews.forEach((item) => {
item.removeFromSuperview()
})
view.isUserInteractionEnabled = true
return view
}
return null
}
// 应用防截屏遮罩secureView实时显示正常但被截屏/录屏捕获到的内容为黑屏)
// 不触发回调,供内部复用;注意:需在主线程调用
static applySecureViewInternal() {
if (this.secureView != null) {
// 已应用,避免重复包裹
return
}
let secureView = this.createSecureView()
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (secureView != null && rootView != null) {
let rootSuperview = rootView!.superview
if (rootSuperview != null) {
this.secureView = secureView
rootSuperview!.addSubview(secureView!)
rootView!.removeFromSuperview()
secureView!.addSubview(rootView!)
// secureView 充满父视图并随父视图宽高自适应(横竖屏、全屏切换时自动跟随)
secureView!.frame = rootSuperview!.bounds
secureView!.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
// rootView 充满 secureView 并自适应,避免全屏时被固定在竖屏尺寸而缩到角落
rootView!.frame = secureView!.bounds
rootView!.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
}
}
}
// 开启防截屏
static onAntiScreenshot(option : SetUserCaptureScreenOptions) {
// uts方法默认会在子线程中执行涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute = () : void => {
this.applySecureViewInternal()
let res: SetUserCaptureScreenSuccess = {
}
option.success?.(res)
option.complete?.(res)
})
}
// ===== 仅防录屏:提前挂载安全层 + 翻转 isSecureTextEntry =====
// 提前挂载安全层(应在录屏开始前调用,例如进入页面时)。
// 挂载后默认不保护isSecureTextEntry = false→ 截屏正常、实时正常。
// 注意:需在主线程调用。
static setupRecordSecureWrapper() {
if (this.recordWrapped) {
return
}
let field = new UITextField(frame = CGRect.zero)
field.isSecureTextEntry = true
// 15.1 系统 secureView 不可用;拿不到安全画布则放弃
if (field.subviews.length == 0 || UIDevice.current.systemVersion == '15.1') {
return
}
let canvas = field.subviews[0]
canvas.subviews.forEach((item) => {
item.removeFromSuperview()
})
canvas.isUserInteractionEnabled = true
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (rootView == null) {
return
}
let rootSuperview = rootView!.superview
if (rootSuperview == null) {
return
}
// 把安全画布插入原层级,并把 App 根视图移入画布
rootSuperview!.addSubview(canvas)
rootView!.removeFromSuperview()
canvas.addSubview(rootView!)
canvas.frame = rootSuperview!.bounds
canvas.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
rootView!.frame = canvas.bounds
rootView!.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
// 关键:保留 field后续才能切换 isSecureTextEntry
this.secureField = field
this.secureCanvas = canvas
this.secureRootView = rootView
this.recordWrapped = true
// 默认不保护:允许截屏、实时正常
field.isSecureTextEntry = false
}
// 切换录屏保护true=保护录屏文件黑、实时正常、此刻截屏也黑false=不保护(允许截屏)
// 注意:需在主线程调用。
static setRecordSecure(secure : boolean) {
if (this.secureField != null) {
this.secureField!.isSecureTextEntry = secure
}
}
// 卸载安全层,恢复原始视图层级。注意:需在主线程调用。
static teardownRecordSecureWrapper() {
if (!this.recordWrapped) {
return
}
if (this.secureField != null) {
this.secureField!.isSecureTextEntry = false
}
if (this.secureCanvas != null && this.secureRootView != null) {
let rootSuperview = this.secureCanvas!.superview
if (rootSuperview != null) {
rootSuperview!.addSubview(this.secureRootView!)
this.secureRootView!.frame = rootSuperview!.bounds
this.secureCanvas!.removeFromSuperview()
}
}
this.secureField = null
this.secureCanvas = null
this.secureRootView = null
this.recordWrapped = false
}
// 移除防截屏遮罩视图(不触发回调,供内部复用)
// 注意:需在主线程调用
static removeSecureViewInternal() {
if (this.secureView != null) {
let window = UTSiOS.getKeyWindow()
let rootView = window.rootViewController == null ? null : window.rootViewController!.view
if (rootView != null && this.secureView!.superview != null) {
let rootSuperview = this.secureView!.superview
if (rootSuperview != null) {
rootSuperview!.addSubview(rootView!)
this.secureView!.removeFromSuperview()
}
}
this.secureView = null
}
}
// 关闭防截屏
static offAntiScreenshot(option : SetUserCaptureScreenOptions) {
DispatchQueue.main.async(execute = () : void => {
this.removeSecureViewInternal()
let res: SetUserCaptureScreenSuccess = {
}
option.success?.(res)
option.complete?.(res)
})
}
}
/**
* 防录屏工具类:基于 UIScreen.isCaptured 监听录屏/投屏状态,动态切换安全层。
* 截屏不会触发 isCaptured因此可做到"允许截屏、仅在录屏时保护"。
*
* 实现要点(避免实时画面变黑):
* 1) 进入时(录屏开始前)就提前挂好安全层,且默认不保护 → 截屏正常、实时正常;
* 2) 仅在录屏期间翻转 isSecureTextEntry = true → 录屏文件黑、实时正常、此刻截屏也黑;
* 3) 录屏结束翻回 false → 截屏恢复正常。
*/
class ScreenRecordTool {
// 是否已注册监听
static monitoring : boolean = false;
// 开启防录屏:提前挂载安全层并监听录屏状态变化
static onAntiScreenRecord() {
DispatchQueue.main.async(execute = () : void => {
// 关键:录屏开始前就把安全层挂好(默认不保护)
CaptureScreenTool.setupRecordSecureWrapper()
if (!this.monitoring) {
this.monitoring = true
const method = Selector("screenCaptureDidChange")
NotificationCenter.default.addObserver(this, selector = method, name = UIScreen.capturedDidChangeNotification, object = null)
}
// 进入时若已经在录屏,立即按当前状态保护
this.applyIfNeeded()
})
}
// 录屏状态变化回调
@objc static screenCaptureDidChange() {
DispatchQueue.main.async(execute = () : void => {
this.applyIfNeeded()
})
}
// 根据当前录屏状态翻转安全层开关
static applyIfNeeded() {
CaptureScreenTool.setRecordSecure(UIScreen.main.isCaptured)
}
// 关闭防录屏:移除监听并卸载安全层
static offAntiScreenRecord() {
DispatchQueue.main.async(execute = () : void => {
if (this.monitoring) {
NotificationCenter.default.removeObserver(this, name = UIScreen.capturedDidChangeNotification, object = null)
this.monitoring = false
}
CaptureScreenTool.teardownRecordSecureWrapper()
})
}
}
/**
* 开启截图监听
*/
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
CaptureScreenTool.listenCaptureScreen(callback)
}
/**
* 关闭截屏监听
*/
export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
CaptureScreenTool.removeListen(callback)
}
/**
* 开启/关闭防截屏
*/
export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOptions) {
const systemVersion = UIDevice.current.systemVersion
if (options.enable == true) {
// 允许截屏与录屏:无条件清理录屏遮罩,再移除防截屏遮罩。
// 清理动作不受版本限制,避免遗留监听/遮罩。
ScreenRecordTool.offAntiScreenRecord()
CaptureScreenTool.offAntiScreenshot(options)
return
}
if (options.antiRecordOnly == true) {
// 仅禁止录屏、允许截屏:进入页面时提前挂好安全层(默认不保护),
// 用 UIScreen.isCapturediOS 11+)监听录屏/投屏,仅在录屏期间翻转 isSecureTextEntry
// —— 实时显示正常、录到的画面为黑屏,且平时不影响截屏。
// 注意secureView 在 iOS 15.1 上不可用,该版本录屏保护会失效(属系统已知问题)。
if (systemVersion < "11.0") {
let res = new SetUserCaptureScreenFailImpl(12001)
options.fail?.(res)
options.complete?.(res)
return
}
ScreenRecordTool.onAntiScreenRecord()
let res: SetUserCaptureScreenSuccess = {
}
options.success?.(res)
options.complete?.(res)
return
}
// 默认截屏与录屏一起禁止secureView 方案,受系统版本限制)
if (systemVersion < "13.0") {
let res = new SetUserCaptureScreenFailImpl(12001)
options.fail?.(res)
options.complete?.(res)
} else if (systemVersion == "15.1") {
let res = new SetUserCaptureScreenFailImpl(12010)
options.fail?.(res)
options.complete?.(res)
} else {
CaptureScreenTool.onAntiScreenshot(options)
}
}

View File

@@ -0,0 +1,176 @@
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
*/
export type OnUserCaptureScreenCallbackResult = {
/**
* 截屏文件路径仅Android返回
*/
path ?: string
}
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调函数定义
*/
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.setUserCaptureScreen成功回调参数
*/
export type SetUserCaptureScreenSuccess = {
}
/**
* uni.setUserCaptureScreen成功回调函数定义
*/
export type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuccess) => void
/**
* uni.setUserCaptureScreen失败回调函数定义
*/
export type SetUserCaptureScreenFailCallback = (res : IUniError) => void
/**
* uni.setUserCaptureScreen完成回调函数定义
*/
export type SetUserCaptureScreenCompleteCallback = (res : any) => void
/**
* uni.setUserCaptureScreen参数
*/
export type SetUserCaptureScreenOptions = {
/**
* true: 允许用户截屏 false: 不允许用户截屏,防止用户截屏到应用页面内容
*/
enable : boolean;
/**
* 仅 iOS 生效。仅在 enable 为 false 时有意义:
* true: 仅禁止录屏/投屏(录屏时画面被遮挡),允许截屏;
* false/不传: 截屏与录屏一起禁止(默认行为)。
*/
antiRecordOnly ?: boolean;
/**
* 接口调用成功的回调函数
*/
// success : SetUserCaptureScreenSuccessCallback | null,
success ?: SetUserCaptureScreenSuccessCallback,
/**
* 接口调用失败的回调函数
*/
// fail : SetUserCaptureScreenFailCallback | null,
fail ?: SetUserCaptureScreenFailCallback,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
// complete : SetUserCaptureScreenSuccessCallback | SetUserCaptureScreenFailCallback | null
complete ?: SetUserCaptureScreenCompleteCallback
}
/**
* 错误码
* - 12001 "setUserCaptureScreen:system not support"
* - 12010 "setUserCaptureScreen:system internal error"
*/
export type SetUserCaptureScreenErrorCode = 12001 | 12010;
/**
* SetUserCaptureScreen 的错误回调参数
*/
export interface SetUserCaptureScreenFail extends IUniError {
errCode : SetUserCaptureScreenErrorCode
};
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
export interface Uni {
/**
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "3.7.7",
* "unixVer": "4.11"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
onUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void,
/**
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "3.7.7",
* "unixVer": "4.11"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",,
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
offUserCaptureScreen(callback : UserCaptureScreenCallback | null) : void,
/**
* 设置防截屏
*
* @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "13.0",
* "uniVer": "3.7.7",
* "unixVer": "4.11"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3 //支持的vue版本
*/
setUserCaptureScreen(options : SetUserCaptureScreenOptions) : void
}

View File

@@ -0,0 +1,7 @@
export function onUserCaptureScreen (callback) {
return wx.onUserCaptureScreen(callback)
}
export function offUserCaptureScreen (callback) {
return wx.offUserCaptureScreen(callback)
}

View File

@@ -0,0 +1,35 @@
import { SetUserCaptureScreenErrorCode, SetUserCaptureScreenFail } from "./interface.uts"
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-usercapturescreen';
/**
* 错误信息
* @UniError
*/
export const UniErrors : Map<SetUserCaptureScreenErrorCode, string> = new Map([
/**
* 错误码及对应的错误信息
*/
[12001, 'setUserCaptureScreen:system not support'],
[12010, 'setUserCaptureScreen:system internal error'],
]);
/**
* 错误对象实现
*/
export class SetUserCaptureScreenFailImpl extends UniError implements SetUserCaptureScreenFail {
/**
* 错误对象构造函数
*/
constructor(errCode : SetUserCaptureScreenErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = UniErrors[errCode] ?? "";
}
}

View File

@@ -0,0 +1,29 @@
export type CaptureScreenSuccess = {
/**
* 截图结果,格式为 data URLdata:image/jpeg;base64,xxxx
*/
base64 : string
}
export type CaptureScreenSuccessCallback = (res : CaptureScreenSuccess) => void
export type CaptureScreenFail = {
errCode : number,
errMsg : string
}
export type CaptureScreenFailCallback = (res : CaptureScreenFail) => void
export type CaptureScreenCompleteCallback = (res : any) => void
export type CaptureScreenOptions = {
success ?: CaptureScreenSuccessCallback,
fail ?: CaptureScreenFailCallback,
complete ?: CaptureScreenCompleteCallback
}
/**
* 截取当前应用窗口画面(含视频等硬件加速渲染内容),通过 base64 返回。
* 仅 App-Android 生效,基于 Android PixelCopy 实现。
*/
export declare const captureScreen : (options : CaptureScreenOptions) => void

View File

@@ -0,0 +1,85 @@
{
"id": "yb-screen-capture",
"displayName": "yb-screen-capture",
"version": "1.0.0",
"description": "截取当前应用窗口(含硬件加速渲染的视频画面),返回 base64",
"keywords": [
"截图",
"截屏",
"PixelCopy"
],
"repository": "",
"engines": {
"HBuilderX": "^3.7.7"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y",
"alipay": "n"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "n",
"app-harmony": "n"
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n",
"京东": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
}
}
}
}
}

View File

@@ -0,0 +1,22 @@
# yb-screen-capture
截取当前应用窗口画面(含视频等硬件加速渲染内容),通过 base64 返回。
-**App-Android** 生效,基于 Android `PixelCopy` 实现Android 8.0 及以上能正确截取视频画面;低于 8.0 降级为 View 截图,视频区域可能为黑屏)。
- 截图范围为「当前屏幕可见区域」,不是长页面截图。
## 使用
```js
uni.captureScreen({
success: (res) => {
// res.base64 形如data:image/jpeg;base64,xxxx
console.log(res.base64)
},
fail: (err) => {
console.error(err.errCode, err.errMsg)
}
})
```
> 注意UTS 插件需要打自定义基座(标准基座无法运行)才能调试/运行。

View File

@@ -0,0 +1,127 @@
import { UTSAndroid } from "io.dcloud.uts";
import PixelCopy from "android.view.PixelCopy";
import OnPixelCopyFinishedListener from "android.view.PixelCopy.OnPixelCopyFinishedListener";
import Bitmap from "android.graphics.Bitmap";
import Canvas from "android.graphics.Canvas";
import Handler from "android.os.Handler";
import Looper from "android.os.Looper";
import Build from "android.os.Build";
import ByteArrayOutputStream from "java.io.ByteArrayOutputStream";
import Base64 from "android.util.Base64";
import {
CaptureScreen,
CaptureScreenOptions,
CaptureScreenSuccess,
CaptureScreenFail
} from "../interface.uts";
/**
* 将 Bitmap 压缩为 JPEG 并编码为 data URL 形式的 base64
*/
function encodeBitmapToBase64(bitmap : Bitmap) : string {
const baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos);
const bytes = baos.toByteArray();
const base64 = Base64.encodeToString(bytes, Base64.NO_WRAP);
bitmap.recycle();
return "data:image/jpeg;base64," + base64;
}
/**
* PixelCopy 完成监听器
*/
class PixelCopyListener extends OnPixelCopyFinishedListener {
private bitmap : Bitmap;
private options : CaptureScreenOptions;
constructor(bitmap : Bitmap, options : CaptureScreenOptions) {
super();
this.bitmap = bitmap;
this.options = options;
}
override onPixelCopyFinished(copyResult : Int) : void {
if (copyResult == PixelCopy.SUCCESS) {
const base64 = encodeBitmapToBase64(this.bitmap);
const res : CaptureScreenSuccess = { base64: base64 };
this.options.success?.(res);
this.options.complete?.(res);
} else {
this.bitmap.recycle();
const res : CaptureScreenFail = {
errCode: 12010,
errMsg: "captureScreen:fail PixelCopy copyResult=" + copyResult
};
this.options.fail?.(res);
this.options.complete?.(res);
}
}
}
/**
* 在 UI 线程执行实际截图
*/
class CaptureRunnable extends Runnable {
private options : CaptureScreenOptions;
constructor(options : CaptureScreenOptions) {
super();
this.options = options;
}
override run() : void {
try {
const activity = UTSAndroid.getUniActivity();
if (activity == null) {
const res : CaptureScreenFail = { errCode: 12010, errMsg: "captureScreen:fail activity is null" };
this.options.fail?.(res);
this.options.complete?.(res);
return;
}
// 注意UTS 中 getWindow() 返回可空类型,必须用 ! 断言,否则编译失败
const window = activity!.getWindow()!;
const decorView = window.getDecorView()!;
const width = decorView.getWidth();
const height = decorView.getHeight();
if (width <= 0 || height <= 0) {
const res : CaptureScreenFail = { errCode: 12010, errMsg: "captureScreen:fail invalid window size" };
this.options.fail?.(res);
this.options.complete?.(res);
return;
}
const bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Android 8.0+:使用 PixelCopy 可以正确截取 SurfaceView/视频等硬件加速画面
const handler = new Handler(Looper.getMainLooper());
PixelCopy.request(window, bitmap, new PixelCopyListener(bitmap, this.options), handler);
} else {
// 低版本降级:仅能截取 View 层级内容,视频区域可能为黑屏
const canvas = new Canvas(bitmap);
decorView.draw(canvas);
const base64 = encodeBitmapToBase64(bitmap);
const res : CaptureScreenSuccess = { base64: base64 };
this.options.success?.(res);
this.options.complete?.(res);
}
} catch (e) {
const res : CaptureScreenFail = { errCode: 12010, errMsg: "captureScreen:fail " + e.toString() };
this.options.fail?.(res);
this.options.complete?.(res);
}
}
}
export const captureScreen : CaptureScreen = function (options : CaptureScreenOptions) {
const activity = UTSAndroid.getUniActivity();
if (activity == null) {
const res : CaptureScreenFail = { errCode: 12010, errMsg: "captureScreen:fail activity is null" };
options.fail?.(res);
options.complete?.(res);
return;
}
activity!.runOnUiThread(new CaptureRunnable(options));
}

View File

@@ -0,0 +1,73 @@
/**
* uni.captureScreen 成功回调参数
*/
export type CaptureScreenSuccess = {
/**
* 截图结果,格式为 data URLdata:image/jpeg;base64,xxxx
*/
base64 : string
}
/**
* uni.captureScreen 成功回调函数定义
*/
export type CaptureScreenSuccessCallback = (res : CaptureScreenSuccess) => void
/**
* uni.captureScreen 失败回调参数
*/
export type CaptureScreenFail = {
errCode : number,
errMsg : string
}
/**
* uni.captureScreen 失败回调函数定义
*/
export type CaptureScreenFailCallback = (res : CaptureScreenFail) => void
/**
* uni.captureScreen 完成回调函数定义(成功、失败都会执行)
*/
export type CaptureScreenCompleteCallback = (res : any) => void
/**
* uni.captureScreen 参数
*/
export type CaptureScreenOptions = {
/**
* 接口调用成功的回调函数
*/
success ?: CaptureScreenSuccessCallback,
/**
* 接口调用失败的回调函数
*/
fail ?: CaptureScreenFailCallback,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete ?: CaptureScreenCompleteCallback
}
export type CaptureScreen = (options : CaptureScreenOptions) => void
export interface Uni {
/**
* 截取当前应用窗口画面(含视频等硬件加速渲染内容),通过 base64 返回。
* 仅 App-Android 生效,基于 Android PixelCopy 实现。
*
* @param {CaptureScreenOptions} options
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "8.0",
* "uniVer": "3.7.7",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVersion 3.7.7
* @uniVueVersion 2,3
*/
captureScreen(options : CaptureScreenOptions) : void
}

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,25 +0,0 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<script>
var __UniViewStartTime__ = Date.now();
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<title>View</title>
<link rel="stylesheet" href="view.css" />
</head>
<body>
<div id="app"></div>
<script src="__uniappes6.js"></script>
<script src="view.umd.min.js"></script>
<script src="app-view.js"></script>
</body>
</html>

View File

@@ -1,3 +0,0 @@
{
"prompt" : "template"
}

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
(function(e){function r(r){for(var n,l,i=r[0],p=r[1],a=r[2],c=0,s=[];c<i.length;c++)l=i[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in p)Object.prototype.hasOwnProperty.call(p,n)&&(e[n]=p[n]);f&&f(r);while(s.length)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var p=t[i];0!==o[p]&&(n=!1)}n&&(u.splice(r--,1),e=l(l.s=t[0]))}return e}var n={},o={"app-config":0},u=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return l.d(r,"a",r),r},l.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},l.p="/";var i=this["webpackJsonp"]=this["webpackJsonp"]||[],p=i.push.bind(i);i.push=r,i=i.slice();for(var a=0;a<i.length;a++)r(i[a]);var f=p;t()})([]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__48F690A","name":"E-peanut","version":{"name":"1.1.0","code":110},"description":"E-peanut-案例","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"Payment":{},"OAuth":{},"Messaging":{},"VideoPlayer":{},"Share":{},"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"autoclose":false,"waiting":true},"popGesture":"close","launchwebview":{"id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#FFFFFF"},"compatible":{"ignoreVersion":true},"privacy":{"prompt":"template","template":{"title":"用户协议和隐私政策","message":"请你务必审慎阅读、充分理解“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/>  你可阅读<a href='https://www.twin-ui.com'>《用户协议》</a>和<a href='https://www.twin-ui.com'>《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。","buttonAccept":"同意","buttonRefuse":"暂不同意"}},"compilerVersion":3,"allowsInlineMediaPlayback":true,"safearea":{"background":"#ffffff","bottom":{"offset":"auto"}},"uni-app":{"compilerVersion":"3.5.3","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"fast"},"tabBar":{"color":"#444444","selectedColor":"#079307","borderStyle":"rgba(0,0,0,0.4)","backgroundColor":"#ffffff","list":[{"pagePath":"pages/peanut/home","iconPath":"static/icon/tab/icon1_n.png","selectedIconPath":"static/icon/tab/icon1_y.png","text":"首页"},{"pagePath":"pages/peanut/shopping","iconPath":"static/icon/tab/icon2_n.png","selectedIconPath":"static/icon/tab/icon2_y.png","text":"购物车"},{"pagePath":"pages/peanut/bookshelf","iconPath":"static/icon/tab/icon3_n.png","selectedIconPath":"static/icon/tab/icon3_y.png","text":"我的书架"},{"pagePath":"pages/peanut/mine","iconPath":"static/icon/tab/icon4_n.png","selectedIconPath":"static/icon/tab/icon4_y.png","text":"我的"}],"height":"50px","child":["lauchwebview"],"selected":0},"launch_path":"__uniappview.html"}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 757 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 804 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 944 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 853 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 547 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Some files were not shown because too many files have changed in this diff Show More