新增版本检测,合同记录,业绩账户调整

This commit is contained in:
唐明明
2023-04-24 15:48:36 +08:00
parent ef27f7d400
commit 598450e1a3
20 changed files with 969 additions and 41 deletions

View File

@@ -10,8 +10,8 @@ import router from '../router'
// 基础配置
const config = {
apiUrl : 'https://douhuo.douhuofalv.com/api/',
// apiUrl : 'https://api.douhuotest.douhuofalv.com/api/', //测试环境
// apiUrl : 'https://douhuo.douhuofalv.com/api/',
apiUrl : 'https://api.douhuotest.douhuofalv.com/api/', //测试环境
timeout : 60000
}

View File

@@ -157,6 +157,21 @@ const getTeamLogs = data => {
})
}
// 签约记录
const getSignLogs = data => {
return request({
url: 'business/flows',
data
})
}
// 获取签约合同
const getFlows = id => {
return request({
url: 'e-signs/flows/' + id
})
}
export {
relations,
code,
@@ -176,4 +191,6 @@ export {
submitTeamName,
getTeam,
getTeamLogs,
getSignLogs,
getFlows
}

View File

@@ -2,7 +2,7 @@
"name" : "抖火",
"appid" : "__UNI__C305C03",
"description" : "纵有疾风起,人生不言弃",
"versionName" : "1.4.1",
"versionName" : "1.4.2",
"versionCode" : 104,
"transformPx" : false,
/* 5+App */
@@ -43,7 +43,8 @@
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>"
],
"schemes" : "doufire"
"schemes" : "doufire",
"minSdkVersion" : 21
},
/* ios */
"ios" : {
@@ -92,6 +93,22 @@
}
}
}
},
"nativePlugins" : {
"Pdf-Plugin" : {
"__plugin_info__" : {
"name" : "Pdf-Plugin",
"description" : "此插件为uni小程序Android原生插件,用于加载网络pdf,支持水印和缩放",
"platforms" : "Android",
"url" : "https://ext.dcloud.net.cn/plugin?id=11384",
"android_package_name" : "io.douhuofalv.com",
"ios_bundle_id" : "io.douhuofalv.com",
"isCloud" : true,
"bought" : 1,
"pid" : "11384",
"parameters" : {}
}
}
}
},
/* */

View File

@@ -343,7 +343,7 @@
"navigationBarTitleText": "机构信息",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#446EFE",
"navigationBarTextStyle": "white"
"navigationBarTextStyle": "white"
}
}, {
"path": "pages/work/perfectBasis",
@@ -353,7 +353,7 @@
"navigationBarTitleText": "基础信息",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#446EFE",
"navigationBarTextStyle": "white"
"navigationBarTextStyle": "white"
}
}, {
"path": "pages/transfers/lists",
@@ -545,10 +545,26 @@
"navigationBarBackgroundColor": "#FFFFFF"
}
}, {
"path": "pages/im/msg",
"path": "pages/im/msg",
"name": "ImMsg",
"style": {
"style": {
"navigationBarTitleText": "消息",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#FFFFFF"
}
}, {
"path": "pages/user/signLog",
"name": "SignLog",
"style": {
"navigationBarTitleText": "合同记录",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#FFFFFF"
}
}, {
"path": "pages/user/contract",
"name": "SignContract",
"style": {
"navigationBarTitleText": "合同",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#FFFFFF"
}
@@ -590,4 +606,4 @@
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
},
"uniIdRouter": {}
}
}

146
pages/user/contract.vue Normal file
View File

@@ -0,0 +1,146 @@
<template>
<view class="content">
<!-- 合同信息 -->
<view class="block">
<view class="block-flex">
<label>合同ID</label>
<view class="block-val">{{id}}</view>
</view>
<view class="block-flex">
<label>合同数量</label>
<view class="nowrap block-val">{{files.length}}</view>
</view>
<view class="block-flex">
<label>附件数量</label>
<view class="nowrap block-val">{{attachments.length}}</view>
</view>
<view class="block-flex">
<label>创建时间</label>
<view class="nowrap block-val">{{created_at || '-'}}</view>
</view>
<view class="block-flex">
<label>更新时间</label>
<view class="nowrap block-val">{{updated_at || '-'}}</view>
</view>
</view>
<!-- 合同文件 -->
<view class="files-title">合同文件列表</view>
<view class="files">
<view class="files-flex" v-for="(item, index) in files" :key="index" @click="onPdf(item.fileName, item.downloadUrl)">
<view class="files-flex-title">{{item.fileName}}</view>
<view class="files-flex-id">{{item.fileId}}</view>
<u-icon class="files-flex-icon" name="arrow-right" size="28rpx"></u-icon>
</view>
</view>
<!-- 附件文件 -->
<view class="files-title">附件文件列表</view>
<view class="files">
<view class="files-flex" v-for="(item, index) in attachments" :key="index" @click="onPdf(item.fileName, item.downloadUrl)">
<view class="files-flex-title">{{item.fileName}}</view>
<view class="files-flex-id">{{item.fileId}}</view>
<u-icon class="files-flex-icon" name="arrow-right" size="28rpx"></u-icon>
</view>
</view>
</view>
</template>
<script>
const plugin = uni.requireNativePlugin('Pdf-Plugin')
import { getFlows } from '@/apis/interfaces/user.js'
export default {
data() {
return {
user : { name: '', mobile: '' },
id : '',
created_at : '',
updated_at : '',
files : [],
attachments : []
};
},
onLoad() {
// #ifdef APP-PLUS
uni.setUserCaptureScreen({
enable: false,
})
// #endif
},
created() {
// 获取合同数据
uni.showLoading({
title: '加载中...',
mask : true
})
getFlows(this.$Route.query.id).then(res => {
const { sign_flow_id, files, attachments, created_at, updated_at, user } = res
this.user = user
this.id = sign_flow_id
this.created_at = created_at
this.updated_at = updated_at
this.files = files
this.attachments = attachments
uni.hideLoading()
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
methods: {
onPdf(name, url){
plugin.showPdf({
title : name,
url : url,
maxScale : '20',
waterMark : '河北抖火法律咨询服务有限公司',
// this.user.name + ' ' + this.user.mobile,
})
}
},
onUnload() {
// #ifdef APP-PLUS
uni.setUserCaptureScreen({
enable: true
})
// #endif
}
}
</script>
<style lang="scss">
.content{ padding: 10rpx 30rpx; }
// 合同信息统计
.block {
background: white;
margin-bottom: 30rpx;
margin-top: 20rpx;
padding: 30rpx;
border-radius: $radius;
&-flex{
display: flex;
justify-content: space-between;
font-size: 30rpx;
line-height: 60rpx;
label{ color: gray; }
.block-val{ width: calc(100% - 200rpx); text-align: right; word-break:break-all; word-wrap: break-word; }
}
}
// 合同列表
.files{
background: white;
margin-bottom: 30rpx;
padding: 30rpx;
border-radius: $radius;
&-flex{
position: relative;
padding-right: 40rpx;
.files-flex-title{ font-weight: bold; font-size: 32rpx; }
.files-flex-id{ font-size: 28rpx; color: gray; }
.files-flex-icon{ position: absolute; right: 0; top: 50%; margin-top: -14rpx;}
}
}
.files-title{ padding-bottom: 20rpx; color: gray; font-size: 28rpx; }
</style>

View File

@@ -99,7 +99,16 @@
</view>
<u-icon name="arrow-right" color="#cacaca" size="34rpx" bold></u-icon>
</view>
<view class="border-solid-empty"></view>
<view class="border-solid-empty"></view>
<view class="nav-flex" @click="updateApp">
<view class="nav-icon">
<image class="nav-icon-src" src="@/static/icons/user_nav_08.png"></image>版本检测
</view>
<view class="nav-text">
<text>V{{version}}</text>
<u-icon name="arrow-right" color="#cacaca" size="34rpx" bold></u-icon>
</view>
</view>
<view class="nav-flex" @click="onNav('UserSet')">
<view class="nav-icon">
<image class="nav-icon-src" src="@/static/icons/user_nav_05.png"></image>设置
@@ -160,23 +169,20 @@
</template>
<script>
import {
info,
relationsVerify,
relationsBind,
submitTeamName,
} from '@/apis/interfaces/user.js'
import { info, relationsVerify, relationsBind, submitTeamName } from '@/apis/interfaces/user.js'
import { getVersions } from '@/apis/interfaces/versions'
export default {
data() {
return {
isAuth: false,
nickname: '',
identity: '',
team_name:'',
avatar: '',
certification: '',
return {
version : plus.runtime.version,
isAuth : false,
nickname : '',
identity : '',
team_name :'',
avatar : '',
certification : '',
// 绑定关系
bindTypeArr: [{
bindTypeArr : [{
name: '手机号',
value: 'mobile'
},
@@ -185,22 +191,22 @@
value: 'verify'
},
],
bindTypeVal: 'mobile',
showBind: false,
isInvitation: true,
parent: '',
invitationUser: {
avatar: '',
nickname: '',
username: ''
bindTypeVal : 'mobile',
showBind : false,
isInvitation : true,
parent : '',
invitationUser : {
avatar : '',
nickname : '',
username : ''
},
invitation: '',
yunyingShow:false, // 运营中心是否展示
yunying_name:'', // 运营名称
team_status:'', // 状态 0 不展示运营中心 1可以申请但是没有完善2申请完审核中3已通过已修改
team_id:'',
region_status:'', // 状态 0 不展示 大区中心 1可以申请但是没有完善2申请完审核中3已通过已修改
region_id:'',
invitation : '',
yunyingShow :false, // 运营中心是否展示
yunying_name :'', // 运营名称
team_status :'', // 状态 0 不展示运营中心 1可以申请但是没有完善2申请完审核中3已通过已修改
team_id :'',
region_status :'', // 状态 0 不展示 大区中心 1可以申请但是没有完善2申请完审核中3已通过已修改
region_id :'',
};
},
onShow() {
@@ -421,7 +427,73 @@
icon: 'none'
})
})
},
},
// 检查版本更新
updateApp() {
uni.showLoading({
title: '检查更新'
})
//#ifdef APP-PLUS
// 获取系统版本号
getVersions({
platform: plus.os.name,
version : plus.runtime.version
}).then(res => {
uni.hideLoading()
if (res.update) {
uni.showModal({
title: "更新提示",
content: res.note || '版本更新信息',
confirmText: "更新",
success: modalRes => {
if (modalRes.confirm) {
if (plus.os.name == "Android") {
uni.showToast({
title: '新版本下载中,将在下载完成后自动为您安装更新包',
icon: 'none'
})
uni.downloadFile({
url: res.info.download,
success: apkPick => {
plus.runtime.install(apkPick
.tempFilePath, '',
installRES => {
// 安装完成用于提示新版本引导,暂时无用
}, installERR => {
// 安装失败
})
},
fail(err) {
uni.showToast({
title: '安装包下载失败,请检查您的网络或稍后重试',
icon: 'none'
})
}
})
} else {
uni.showToast({
title: '暂无ios版本这块留着后续用',
icon: 'none'
})
}
}
}
})
return
}
uni.showModal({
title: "提示",
content: "当前已是最新版本",
showCancel: false,
})
}).catch(err => {
uni.showToast({
title: err.message,
icon: 'none'
})
})
//#endif
}
}
}
</script>
@@ -446,7 +518,15 @@
margin-right: $margin;
margin-top: 5rpx;
}
}
}
.nav-text{
display: flex;
justify-content: flex-end;
align-items: center;
color: #999;
font-size: 30rpx;
text{ padding-right: 10rpx; }
}
}
// 用户信息

View File

@@ -30,6 +30,14 @@
</view>
</view>
</view>
<view class="set-nav-block">
<view class="set-nav" @click="onNav('SignLog')">
<label>合同记录</label>
<view class="value nowrap">
<uni-icons type="right" color="gray"></uni-icons>
</view>
</view>
</view>
<view class="set-nav-block">
<view class="set-nav" @click="onLogout">
<label>退出登录</label>

80
pages/user/signLog.vue Normal file
View File

@@ -0,0 +1,80 @@
<template>
<view class="content">
<view class="log-blcok" v-for="(item, index) in logs" :key="index" @click="onInfo(item.business_order_id)">
<view class="flex">
<label>订单编号</label>
<view class="val">{{item.order_no}}</view>
</view>
<view class="flex">
<label>业务类型</label>
<view class="val">
<text v-for="(titem, tindex) in item.item_type" :key="tindex">{{titem.title}}</text>
</view>
</view>
<view class="flex">
<label>签约时间</label>
<view class="val">{{item.created_at}}</view>
</view>
</view>
</view>
</template>
<script>
import { getSignLogs, getFlows } from '@/apis/interfaces/user.js'
export default {
data() {
return {
logs: [],
};
},
created() {
this.getLog()
},
methods: {
getLog(){
uni.showLoading({
title: '加载中...',
mask : true
})
getSignLogs({
page: 1
}).then(res => {
this.logs = res.data
this.page = res.page
uni.hideLoading()
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
onInfo(id){
this.$Router.push({
name : 'SignContract',
params : { id }
})
}
}
}
</script>
<style lang="scss">
.content{ padding: 30rpx 30rpx 10rpx; box-sizing: border-box; }
// 订单列表
.log-blcok{
background: white;
border-radius: $radius;
padding: $padding;
position: relative;
// .log-icon{ position: absolute; right: $margin; top: 50%; margin-top: -14rpx; }
.flex{
display: flex;
justify-content: space-between;
font-size: 30rpx;
line-height: 60rpx;
label{ color: gray; }
}
}
</style>

View File

@@ -19,6 +19,7 @@
<text class="identity identity-1" v-if="item.identity.order == 1">普通用户</text>
<text class="identity identity-3" v-if="item.identity.order == 3">顾问</text>
</view>
<view class="nowrap submit">团队业绩{{ item.show_perf ? item.perf: '身份不符暂无业绩' }}</view>
<view class="nowrap submit">联系电话{{item.username}}</view>
<view class="nowrap submit">注册时间{{item.created_at}}</view>
</view>
@@ -74,6 +75,8 @@
page : this.page.current
}).then(res => {
let { users, count } = res;
console.log(users)
let atList = users.page.current == 1 ? [] : this.users
this.count = count
this.users = atList.concat(users.data)

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@@ -0,0 +1,10 @@
## 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,18 @@
declare namespace UniNamespace {
type OnUserCaptureScreenCallback = (res?: { errMsg: string }) => void
}
declare interface Uni {
/**
* 监听用户主动截屏事件,用户使用系统截屏按键截屏时触发此事件。
*
* 文档: [https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen)
*/
onUserCaptureScreen(callback: UniNamespace.OnUserCaptureScreenCallback): void;
/**
* 用户主动截屏事件。取消事件监听。
*
* 文档: [https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen)
*/
offUserCaptureScreen(callback: UniNamespace.OnUserCaptureScreenCallback): void;
}

View File

@@ -0,0 +1,92 @@
{
"id": "uni-usercapturescreen",
"displayName": "uni-usercapturescreen",
"version": "1.0.4",
"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": "onUserCaptureScreen",
"offUserCaptureScreen": "offUserCaptureScreen",
"setUserCaptureScreen": "setUserCaptureScreen"
}
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": {
"minVersion": "19"
},
"app-ios": {
"minVersion": "9"
}
},
"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,3 @@
{
"minSdkVersion": "19"
}

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";
/**
* 文件监听器
*/
let observer : ScreenFileObserver | null = null;
/**
* 记录文件监听器上次监听的时间戳,避免重复监听
*/
let lastObserverTime : number = 0;
/**
* 截屏回调
*/
let listener : UserCaptureScreenCallback | null = null;
/**
* android 文件监听实现
*/
class ScreenFileObserver extends FileObserver {
/**
* 截屏文件目录
*/
private screenFile : File;
constructor(screenFile : File) {
super(screenFile);
this.screenFile = screenFile;
}
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);
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,3 @@
{
"deploymentTarget": "9"
}

View File

@@ -0,0 +1,146 @@
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, SetUserCaptureScreenFail } from "../interface.uts"
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener : UserCaptureScreenCallback | null;
static secureView : UIView | null;
// 监听截屏
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
}
// 开启防截屏
static onAntiScreenshot(option : SetUserCaptureScreenOptions) {
// uts方法默认会在子线程中执行涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute = () : void => {
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!)
let rect = rootView!.frame
secureView!.frame = UIScreen.main.bounds
rootView!.frame = rect
}
}
let res: SetUserCaptureScreenSuccess = {
}
option.success?.(res)
option.complete?.(res)
})
}
// 关闭防截屏
static offAntiScreenshot(option : SetUserCaptureScreenOptions) {
DispatchQueue.main.async(execute = () : void => {
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
}
let res: SetUserCaptureScreenSuccess = {
}
option.success?.(res)
option.complete?.(res)
})
}
}
/**
* 开启截图监听
*/
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) {
if (UIDevice.current.systemVersion < "13.0") {
let res: SetUserCaptureScreenFail = {
errCode: 12001,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system not support"
}
options.fail?.(res);
options.complete?.(res);
} else if (UIDevice.current.systemVersion == "15.1") {
let res: SetUserCaptureScreenFail = {
errCode: 12010,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system internal error"
}
options.fail?.(res);
options.complete?.(res);
} else {
if (options.enable == true) {
CaptureScreenTool.offAntiScreenshot(options)
} else {
CaptureScreenTool.onAntiScreenshot(options)
}
}
}

View File

@@ -0,0 +1,122 @@
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
*/
export type OnUserCaptureScreenCallbackResult = {
/**
* 截屏文件路径仅Android返回
*/
path ?: string
}
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调函数定义
*/
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
/**
* uni.onUserCaptureScreen函数定义
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^4.4
* @since 3.7.7
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.offUserCaptureScreen函数定义
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^4.4
* @since 3.7.7
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.setUserCaptureScreen成功回调参数
*/
export type SetUserCaptureScreenSuccess = {
}
/**
* uni.setUserCaptureScreen失败回调参数
*/
export type SetUserCaptureScreenFail = {
/**
* 错误码
* 12001:system not support
* 12010:system internal error
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
errMsg : string,
}
/**
* uni.setUserCaptureScreen成功回调函数定义
*/
export type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuccess) => void
/**
* uni.setUserCaptureScreen失败回调函数定义
*/
export type SetUserCaptureScreenFailCallback = (res : SetUserCaptureScreenFail) => void
/**
* uni.setUserCaptureScreen完成回调函数定义
*/
export type SetUserCaptureScreenCompleteCallback = (res : any) => void
/**
* uni.setUserCaptureScreen参数
*/
export type SetUserCaptureScreenOptions = {
/**
* true: 允许用户截屏 false: 不允许用户截屏,防止用户截屏到应用页面内容
*/
enable : boolean;
/**
* 接口调用成功的回调函数
*/
// success : SetUserCaptureScreenSuccessCallback | null,
success ?: SetUserCaptureScreenSuccessCallback,
/**
* 接口调用失败的回调函数
*/
// fail : SetUserCaptureScreenFailCallback | null,
fail ?: SetUserCaptureScreenFailCallback,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
// complete : SetUserCaptureScreenSuccessCallback | SetUserCaptureScreenFailCallback | null
complete ?: SetUserCaptureScreenCompleteCallback
}
/**
* * uni.setUserCaptureScreen函数定义
* 设置防截屏
*
* @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @platforms APP-IOS = ^13.0,APP-ANDROID = ^4.4
* @since 3.7.7
*/
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
export interface Uni {
onUserCaptureScreen : OnUserCaptureScreen,
offUserCaptureScreen : OffUserCaptureScreen,
setUserCaptureScreen : SetUserCaptureScreen
}

View File

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