当前位置:   article > 正文

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

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

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

请添加图片描述
在这里插入图片描述

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/992603
推荐阅读
相关标签
  

闽ICP备14008679号