<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>