share-with-system.uvue 14.0 KB
Newer Older
M
mahaifeng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<template>
	<!-- #ifdef APP -->
	<scroll-view direction="vertical" style="flex:1; margin-bottom: 50px;">
	<!-- #endif -->
		<view id="viewshot">
			<button class="button" @click="shareText()">分享文本</button>
			<button class="button" @click="shareLink()">分享链接</button>
			<button class="button" @click="sharePrivateImg()">分享单个本地图片</button>
			<button class="button" @click="sharePrivateImgs()">分享多个本地图片</button>
			<button class="button" @click="shareAll()">分享链接、文本、一张图片</button>
			<button class="button" @click="sharePrivateVideo()">分享video文件(单个)</button>
			<button class="button" @click="sharePrivateVideos()">分享video文件(多个)</button>
			<button class="button" @click="sharePrivateAudio()">分享Audio文件(单个)</button>
			<button class="button" @click="sharePrivateAudios()">分享Audio文件(多个)</button>
			<button class="button" @click="sharePrivateFile()">分享文件(单个)</button>
			<button class="button" @click="sharePrivateFiles()">分享文件(多个)</button>

			<button class="button" type="primary" @click="sharePrivateErrorImg()">分享单个本地图片(错误路径)</button>
			<button class="button" type="primary" @click="sharePrivateErrorImgs()">分享多个本地图片(含有错误路径)</button>
zhaofengliang920817's avatar
zhaofengliang920817 已提交
20
			<button class="button" type="primary" @click="sharePrivateErrorVideos()">分享Video文件(错误路径)</button>
M
mahaifeng 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
			<button class="button" type="primary" @click="sharePrivateErrorAudios()">分享Audio文件(错误路径)</button>
			<button class="button" type="primary" @click="sharePrivateErrorFiles()">分享文件(错误路径)</button>

			<button class="button" type="warn" @click="sharePubImg()">选择图片并分享</button>
			<button class="button" type="warn" @click="sharePubMedias()">选择video并分享</button>
			<button class="button" type="warn" @click="shareSnapShot()">指定view截图并分享</button>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				summary: '欢迎使用hello uniapp-x'
			}
		},
zhaofengliang920817's avatar
zhaofengliang920817 已提交
38
		methods: {
zhaofengliang920817's avatar
zhaofengliang920817 已提交
39
			sharePrivateErrorAudios() {
zhaofengliang920817's avatar
zhaofengliang920817 已提交
40
				uni.hideToast()
zhaofengliang920817's avatar
zhaofengliang920817 已提交
41
				const path1 : string = "/static/test-audio/ForElise.mp3";
zhaofengliang920817's avatar
zhaofengliang920817 已提交
42 43 44
				const path2 : string = "/static/test-audio/ForElise.mp32";

				uni.shareWithSystem({
zhaofengliang920817's avatar
zhaofengliang920817 已提交
45
					audioPaths: [path1, path2],
M
mahaifeng 已提交
46
					type:'audio',
zhaofengliang920817's avatar
zhaofengliang920817 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})

M
mahaifeng 已提交
62 63 64 65 66 67 68
			},
			sharePrivateErrorFiles() {
				uni.hideToast()
				const path1 : string = "/static/filemanager1/to.zip";
				const path2 : string = "/static/filemanager/11.txt.br";

				uni.shareWithSystem({
M
mahaifeng 已提交
69
					filePaths: [path1, path2],
M
mahaifeng 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
					type:'file',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateFile() {
				uni.hideToast()
				const path1 : string = "/static/filemanager/to.zip";

				uni.shareWithSystem({
M
mahaifeng 已提交
91
					filePaths: [path1],
M
mahaifeng 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
					type:'file',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateFiles() {
				uni.hideToast()
				const path1 : string = "/static/filemanager/to.zip";
				const path2 : string = "/static/filemanager/1.txt.br";

				uni.shareWithSystem({
M
mahaifeng 已提交
114
					filePaths: [path1, path2],
M
mahaifeng 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
					type:'file',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateAudio() {
				uni.hideToast()
				const path1 : string = "/static/test-audio/ForElise.mp3";

				uni.shareWithSystem({
M
mahaifeng 已提交
136
					audioPaths: [path1],
M
mahaifeng 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
					type:'audio',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateAudios() {
				uni.hideToast()
				const path1 : string = "/static/test-audio/ForElise.mp3";
				const path2 : string = "/static/test-audio/ForElise.mp3";

				uni.shareWithSystem({
M
mahaifeng 已提交
159
					audioPaths: [path1, path2],
M
mahaifeng 已提交
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
					type:'audio',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateErrorVideos() {
				uni.hideToast()
				const path1 : string = "/static/test-video/10second-demo.mp4";
				const path2 : string = "/static/test-video/10second-demo1.mp4";

				uni.shareWithSystem({
M
mahaifeng 已提交
182
					videoPaths: [path1, path2],
M
mahaifeng 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
					type:'video',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})

			},
			sharePrivateVideo() {
				uni.hideToast()
				const path1 : string = "/static/test-video/10second-demo.mp4";
				uni.shareWithSystem({
M
mahaifeng 已提交
204
					videoPaths: [path1],
M
mahaifeng 已提交
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
					type:'video',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})

			},
			sharePrivateVideos() {
				uni.hideToast()
				const path1 : string = "/static/test-video/10second-demo.mp4";
				const path2 : string = "/static/test-video/10second-demo.mp4";

				uni.shareWithSystem({
M
mahaifeng 已提交
228
					videoPaths: [path1, path2],
M
mahaifeng 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
					type:'video',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})

			},
			sharePubMedias() {
				uni.hideToast()

				uni.chooseVideo({
					success(res) {
						uni.shareWithSystem({
M
mahaifeng 已提交
252
							videoPaths: [res.tempFilePath],
M
mahaifeng 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
							type:'video',
							success(res) {
								console.log('Shared----------------------------success')
							},
							fail(res) {
								console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
								uni.showToast({
									icon: "error",
									title: "errorCode=" + res.errCode
								})
							},
							complete(res) {

							}
						})
					}

				})
			},
			shareText() {
				uni.hideToast()
				uni.shareWithSystem({
M
mahaifeng 已提交
275
					summary: this.summary,
M
mahaifeng 已提交
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
					type:'text',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			shareLink() {
				uni.hideToast()
				uni.shareWithSystem({
					type:'text',
					href: 'https://uniapp.dcloud.io',
					success(res) {
						console.log('Shared----------------------------success')
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateImg() {
				uni.hideToast()
				const imageSrc : string = "/static/test-image/logo.gif";
M
mahaifeng 已提交
315
				uni.shareWithSystem({
M
mahaifeng 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
					type:'image',
					imageUrl: imageSrc,
					success(res) {
						console.log('Shared----------------------------success')
						// 分享完成,请注意此时不一定是成功分享
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
						// 分享失败
					},
					complete(res) {

					}
				})
			},
			sharePrivateErrorImg() {
				uni.hideToast()
				const imageSrc : string = "/static/test-image/logo.jpg11";
M
mahaifeng 已提交
338 339
				uni.shareWithSystem({
					imageUrl: imageSrc,
M
mahaifeng 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
					type:'image',
					success(res) {
						console.log('Shared----------------------------success')
						// 分享完成,请注意此时不一定是成功分享
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
						// 分享失败
					},
					complete(res) {

					}
				})
			},
			sharePrivateImgs() {
				uni.hideToast()
				const errorImageSrc1 : string = "/static/test-image/logo.gif";
				const errorImageSrc2 : string = "/static/test-image/logo.png";
				const imageSrc : string = "/static/test-image/logo.jpg";
				let imageUrlList : string[] = Array()
				imageUrlList.push(errorImageSrc2)
				imageUrlList.push(imageSrc)
				// imageUrlList.push(errorImageSrc1)

				uni.shareWithSystem({
M
mahaifeng 已提交
369
					imagePaths: imageUrlList,
M
mahaifeng 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
					type:'image',
					success(res) {
						console.log('Shared----------------------------success')
						// 分享完成,请注意此时不一定是成功分享
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePrivateErrorImgs() {
				uni.hideToast()
				const errorImageSrc1 : string = "/static/test-image/logo.jpg1";
				const errorImageSrc2 : string = "/static/test-image/logo.jpg3";
				const imageSrc : string = "/static/test-image/logo.jpg";
				let imageUrlList : string[] = Array()
				imageUrlList.push(imageSrc)
				imageUrlList.push(errorImageSrc1)
				imageUrlList.push(errorImageSrc2)
				uni.shareWithSystem({
M
mahaifeng 已提交
397
					imagePaths: imageUrlList,
M
mahaifeng 已提交
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
					type:'image',
					success(res) {
						console.log('Shared----------------------------success')
						// 分享完成,请注意此时不一定是成功分享
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			shareAll() {
				uni.hideToast()
				const imageSrc : string = "/static/test-video/fast-forward.png";
				let imageUrlList : string[] = Array()
				imageUrlList.push(imageSrc)
				uni.shareWithSystem({
					summary: this.summary,
					href: 'https://uniapp.dcloud.io',
M
mahaifeng 已提交
423
					imagePaths: imageUrlList,
M
mahaifeng 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
					type:'image',
					success(res) {
						console.log('Shared----------------------------success')
						// 分享完成,请注意此时不一定是成功分享
					},
					fail(res) {
						console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)
						uni.showToast({
							icon: "error",
							title: "errorCode=" + res.errCode
						})
					},
					complete(res) {

					}
				})
			},
			sharePubImg() {
				uni.hideToast()
				uni.chooseImage({
					count: 3,
					sourceType: ['camera', 'album'],
					success(e) {
						console.log(e)
						console.log(JSON.stringify(e))
						uni.shareWithSystem({
							// summary: "aa",
							// href: 'https://uniapp.dcloud.io',
M
mahaifeng 已提交
452
							imagePaths: e.tempFilePaths,
M
mahaifeng 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
							type:'image',
							success(res) {
								console.log('Shared----------------------------success')
								// 分享完成,请注意此时不一定是成功分享
							},
							fail(res) {
								console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)

								uni.showToast({
									icon: "error",
									title: "errorCode=" + res.errCode
								})
							},
							complete(res) {

							}
						})
					}
				})
			},
			shareSnapShot() {
				uni.hideToast()
				uni.getElementById("viewshot")?.takeSnapshot(
					{
						success: function (res) {
							uni.shareWithSystem({
M
mahaifeng 已提交
479
								imageUrl: res.tempFilePath,
M
mahaifeng 已提交
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
								type:'image',
								success(res) {
									console.log('Shared----------------------------success')
									// 分享完成,请注意此时不一定是成功分享
								},
								fail(res) {
									console.log('Share failed, ' + "res.errCode =" + res.errCode + '---res.errMsg= ' + res.errMsg)

									uni.showToast({
										icon: "error",
										title: "errorCode=" + res.errCode
									})
								},
								complete(res) {

								}
							})

						},
						fail: function (res) {
							console.log(res)
							uni.showToast({
								icon: 'error',
								title: '截图失败'
							})
						}
					}
				)
			},

		}
	}
</script>

<style>
	.button {
		margin-left: 30px;
		margin-right: 30px;
		margin-bottom: 15px;
	}
W
wanganxp 已提交
520
</style>