微信小程序免费《短视频去水印》

分享一个uniapp开发的微信小程序免费《短视频去水印》小程序


html 复制代码
<template>
	<view class="content">
		<view class="area-wrap">
			<textarea name="" v-model="state.content" maxlength="800" id="" cols="30" rows="10" placeholder-class="plc"
				placeholder="请输入分享链接/分享内容"></textarea>
			<view class="count">
				{{state.content.length}}/800
			</view>
		</view>
		<uv-row customStyle="margin-bottom: 10px" justify="end">
			<uv-col span="3">
				<uv-button :text="state.content?'清空':'粘贴'" @click="clearOrpaste"></uv-button>
			</uv-col>
			<uv-col span="3" offset="1">
				<uv-button :disabled="state.resolved" :text="state.content?'开始解析':'粘贴并解析'" type="primary"
					@click="startAnalyzing"></uv-button>
			</uv-col>
		</uv-row>
		<view class="wrap">
			<view v-if="state.result.video_url">
				<view class="title">无水印视频</view>
				<video :src="state.result.video_url"></video>
				<uv-button style="margin-top: 20rpx;" type="primary" text="" @click="saveVideo(state.result.video_url)">
					<text class="iconfont icon-download"></text>
					<text>保存视频</text>
				</uv-button>
			</view>
			<view v-if="state.result.title">
				<view class="title">标题</view>
				<view class="title-content">{{state.result.title}}</view>
				<uv-button style="margin-top: 20rpx;" type="primary" text="" @click="copy(state.result.title)">
					<text class="iconfont icon-copy"></text>
					<text>复制标题</text>
				</uv-button>
			</view>
			<view v-if="state.result.cover_url">
				<view class="title">封面</view>
				<image @click="preview(state.result.cover_url)" class="cover_url" :src="state.result.cover_url"
					mode="aspectFill"></image>
				<uv-button icon-color="#fff" style="margin-top: 20rpx;" type="primary" text=""
					@click="saveImg(state.result.cover_url)">
					<text class="iconfont icon-download"></text>
					<text>保存封面</text>
				</uv-button>
			</view>

		</view>
	</view>
</template>
javascript 复制代码
<script setup>
import {
		getCurrentInstance,
		reactive,
		watch
	} from "vue"
	import {
		onLoad,
		onShareAppMessage,
		onShareTimeline
	} from "@dcloudio/uni-app"
	const {
		proxy,
		appContext
	} = getCurrentInstance()
	const {
		req
	} = appContext.config.globalProperties;
	const {
		toast,
		containsURL
	} = appContext.config.globalProperties._;
	const state = reactive({
		content: "",
		result: {
			cover_url: "",
			title: "",
			video_url: "",
			resolved: false
		}
	})
	watch(() => state.content, val => {
		if (val == "") {
			state.resolved = false
		}
	})
	onShareAppMessage(() => {
		return {
			title: "轻便短视频去水印",
			path: "/pages/index/index"
		}
	})
	onShareTimeline(() => {
		return {
			title: "轻便短视频去水印",
			path: "/pages/index/index"
		}
	})

	async function startAnalyzing() {
		if (state.resolved) return
		if (!state.content) {
			let data = await getClipboardData()
			if (data) {
				state.content = data
			}
		}
		if (!state.content) return toast("分享内容不能为空")
		const isUrl = containsURL(state.content)
		if (!isUrl) return toast("分享地址格式错误")
		uni.showLoading({
			title: "解析中...",
			mask: true
		})
		req.get("/video/share/url/parse", {
				params: {
					url: state.content
				}
			})
			.then(res => {
				uni.hideLoading()
				state.resolved = true
				const {
					cover_url,
					title,
					video_url
				} = res
				state.result.cover_url = cover_url
				state.result.title = title
				state.result.video_url = video_url
			})
	}

	function getClipboardData() {
		return new Promise((resolve, reject) => {
			uni.getClipboardData({
				success: function(res) {
					resolve(res.data)
				},
				fail() {
					reject(data)
				}
			});
		})

	}

	function clearOrpaste() {
		if (state.content) {
			// 清除操作
			state.content = ""
			state.resolved = false
		} else {
			// 粘贴操作
			uni.getClipboardData({
				success: function(res) {
					state.content = res.data
				}
			});
		}

	}

	function copy(content) {
		uni.setClipboardData({
			data: content,
			success() {
				toast("已复制")
			}
		})
	}

	function saveVideo(val) {
		uni.showLoading({
			title: "保存中..."
		})
		const downloadTask = uni.downloadFile({
			url: val,
			success(res) {
				uni.saveVideoToPhotosAlbum({
					filePath: res.tempFilePath,
					success(e) {
						toast("保存成功", "success")
					},
					fail(err) {
						if (err.errMsg == "saveVideoToPhotosAlbum:fail auth deny") {
							uni.showModal({
								title: "提示",
								content: "需要您授权保存相册",
								confirmText: "点击授权",
								success(res) {
									if (res.confirm) {
										uni.openSetting({
											success: setting => {
												if (setting.authSetting['scope.writePhotosAlbum']) {
													uni.showModal({
														title: '提示',
														content: '获取权限成功,再次点击下载即可保存',
														showCancel: false,
													})
												} else {
													uni.showModal({
														title: '提示',
														content: '获取权限失败,将无法保存到相册哦',
														showCancel: false,
													})
												}
											}
										})
									}
								},
							})
						} else {
							toast("保存失败")
						}
						req.post("/bugReport", {
							method: "saveVideoToPhotosAlbum",
							data: res.tempFilePath,
							error: JSON.stringify(err),
						})
					}
				})
			},
			fail(err) {
				req.post("/bugReport", {
					method: "downloadFile",
					data: val,
					error: JSON.stringify(err)
				})
				toast("保存失败")
			}
		})
		downloadTask.onProgressUpdate((res) => {
			// console.log('下载进度' + res.progress);
			if (res.progress >= 100) {
				uni.hideLoading()
			}
		});
	}

	function saveImg(val) {
		uni.downloadFile({
			url: val,
			success(res) {
				uni.saveImageToPhotosAlbum({
					filePath: res.tempFilePath,
					success() {
						toast("保存成功", "success")
					},
					fail(err) {
						if (err.errMsg == "saveImageToPhotosAlbum:fail auth deny") {
							uni.showModal({
								title: "提示",
								content: "需要您授权保存相册",
								confirmText: "点击授权",
								success(res) {
									if (res.confirm) {
										uni.openSetting({
											success: setting => {
												if (setting.authSetting['scope.writePhotosAlbum']) {
													uni.showModal({
														title: '提示',
														content: '获取权限成功,再次点击下载即可保存',
														showCancel: false,
													})
												} else {
													uni.showModal({
														title: '提示',
														content: '获取权限失败,将无法保存到相册哦',
														showCancel: false,
													})
												}
											}
										})
									}
								},
							})
						} else {
							toast("保存失败")
						}
						req.post("/bugReport", {
							method: "saveImageToPhotosAlbum",
							data: res.tempFilePath,
							error: JSON.stringify(err)
						})
					}
				})
			},
			fail(err) {
				req.post("/bugReport", {
					method: "downloadFile",
					data: val,
					error: JSON.stringify(err)
				})
				toast("保存失败")
			}
		})
	}

	function preview(url) {
		uni.previewImage({
			urls: [url]
		})
	}
	</script>
css 复制代码
<style lang="scss">
	.iconfont {
		margin-right: 20rpx;
		font-size: 40rpx;
	}

	.title-content {
		border-radius: 5rpx;
		padding: 10rpx;
		width: 100%;
		box-sizing: border-box;
		border: 1rpx dashed #999;
		margin-bottom: 20rpx;
	}

	.cover_url {
		width: 100%;
		height: 600rpx;
	}

	video {
		width: 100%;
	}

	.title {
		font-size: 36rpx;
		font-weight: bold;
		margin: 40rpx 0;
		padding-left: 30rpx;
		position: relative;

		&::before {
			content: "";
			position: absolute;
			width: 14rpx;
			height: 40rpx;
			background-color: $theme-color;
			left: 0;
			top: 50%;
			border-radius: 10rpx;
			transform: translateY(-50%);
		}
	}

	.plc {
		font-size: 28rpx;
	}

	.area-wrap {
		background-color: #fff;
		width: 100%;
		padding: 20rpx;
		padding-bottom: 10rpx;
		border-radius: 5rpx;
		box-sizing: border-box;
		margin-bottom: 20rpx;

		textarea {![请添加图片描述](https://i-blog.csdnimg.cn/direct/714d26ef190e4715a33978b157197fd3.png)

			font-size: 28rpx;
			width: 100%;
		}

		.count {
			margin-top: 10rpx;
			font-size: 24rpx;
			color: #999;
			text-align: right;
		}
	}

	page {
		padding: 24rpx;
		box-sizing: border-box;
	}
</style>
相关推荐
计算机-秋大田4 小时前
基于微信小程序的电子竞技信息交流平台设计与实现(LW+源码+讲解)
spring boot·后端·微信小程序·小程序·课程设计
struggle20258 小时前
2025开源DouyinLiveRecorder全平台直播间录制工具整合包,多直播同时录制、教学直播录制、教学视频推送、简单易用不占内存
图像处理·计算机视觉·开源·音视频·语音识别
Stanford_110611 小时前
C++中常用的十大排序方法之4——希尔排序
c++·算法·微信小程序·排序算法·微信公众平台·twitter·微信开放平台
林涧泣12 小时前
【Uniapp-Vue3】解决uni-popup弹窗在安全区显示透明问题
前端·vue.js·uni-app
Colinnian15 小时前
微信小程序中在一个大边框里给每个小边框均匀分配空间
微信小程序·小程序·notepad++
一 乐15 小时前
基于微信小程序的酒店管理系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·微信小程序·酒店管理系统
烛阴1 天前
Go 语言进阶:打造可复用的模块,导出你的专属包
后端·go
硬件学长森哥1 天前
音视频多媒体编解码器基础-codec
驱动开发·嵌入式硬件·音视频
小镇拾光1 天前
PPT演示设置:插入音频&同步切换&播放时长计算
powerpoint·音视频·ppt播放设置
程序猿玖月柒1 天前
全志 视频输入组件的使用
音视频