123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- <template>
- <!-- #ifdef APP -->
- <scroll-view direction="vertical" style="flex:1;">
- <!-- #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" @click="sharePubImg()">选择图片并分享</button>
- <button class="button" @click="sharePubMedias()">选择video并分享</button>
- <button class="button" @click="shareSnapShot()">指定view截图并分享</button>
- <button class="button" type="warn" @click="sharePrivateErrorImg()">分享单个本地图片(错误路径)</button>
- <button class="button" type="warn" @click="sharePrivateErrorImgs()">分享多个本地图片(含有错误路径)</button>
- <button class="button" type="warn" @click="sharePrivateErrorVideos()">分享Video文件(错误路径)</button>
- <button class="button" type="warn" @click="sharePrivateErrorAudios()">分享Audio文件(错误路径)</button>
- <button class="button" type="warn" @click="sharePrivateErrorFiles()">分享文件(错误路径)</button>
- </view>
- </scroll-view>
- </template>
- <script>
- export default {
- data() {
- return {
- summary: '欢迎使用hello uniapp-x'
- }
- },
- methods: {
- sharePrivateErrorAudios() {
- uni.hideToast()
- const path1 : string = "/static/test-audio/ForElise.mp3";
- const path2 : string = "/static/test-audio/ForElise.mp32";
- uni.shareWithSystem({
- audioPaths: [path1, path2],
- type:'audio',
- success() {
- 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(_) {
- }
- })
- },
- sharePrivateErrorFiles() {
- uni.hideToast()
- const path1 : string = "/static/filemanager1/to.zip";
- const path2 : string = "/static/filemanager/11.txt.br";
- uni.shareWithSystem({
- filePaths: [path1, path2],
- type:'file',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateFile() {
- uni.hideToast()
- const path1 : string = "/static/filemanager/to.zip";
- uni.shareWithSystem({
- filePaths: [path1],
- type:'file',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateFiles() {
- uni.hideToast()
- const path1 : string = "/static/filemanager/to.zip";
- const path2 : string = "/static/filemanager/1.txt.br";
- uni.shareWithSystem({
- filePaths: [path1, path2],
- type:'file',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateAudio() {
- uni.hideToast()
- const path1 : string = "/static/test-audio/ForElise.mp3";
- uni.shareWithSystem({
- audioPaths: [path1],
- type:'audio',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateAudios() {
- uni.hideToast()
- const path1 : string = "/static/test-audio/ForElise.mp3";
- const path2 : string = "/static/test-audio/ForElise.mp3";
- uni.shareWithSystem({
- audioPaths: [path1, path2],
- type:'audio',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateErrorVideos() {
- uni.hideToast()
- const path1 : string = "/static/test-video/10second-demo.mp4";
- const path2 : string = "/static/test-video/10second-demo1.mp4";
- uni.shareWithSystem({
- videoPaths: [path1, path2],
- type:'video',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateVideo() {
- uni.hideToast()
- const path1 : string = "/static/test-video/10second-demo.mp4";
- uni.shareWithSystem({
- videoPaths: [path1],
- type:'video',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateVideos() {
- uni.hideToast()
- const path1 : string = "/static/test-video/10second-demo.mp4";
- const path2 : string = "/static/test-video/10second-demo.mp4";
- uni.shareWithSystem({
- videoPaths: [path1, path2],
- type:'video',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePubMedias() {
- uni.hideToast()
- uni.chooseVideo({
- success(res) {
- uni.shareWithSystem({
- videoPaths: [res.tempFilePath],
- type:'video',
- success(_) {
- 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(_) {
- }
- })
- }
- })
- },
- shareText() {
- uni.hideToast()
- uni.shareWithSystem({
- summary: this.summary,
- type:'text',
- success(_) {
- 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(_) {
- }
- })
- },
- shareLink() {
- uni.hideToast()
- uni.shareWithSystem({
- type:'text',
- href: 'https://uniapp.dcloud.io',
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateImg() {
- uni.hideToast()
- const imageSrc : string = "/static/test-image/logo.gif";
- uni.shareWithSystem({
- type:'image',
- imageUrl: imageSrc,
- success(_) {
- 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(_) {
- }
- })
- },
- sharePrivateErrorImg() {
- uni.hideToast()
- const imageSrc : string = "/static/test-image/logo.jpg11";
- uni.shareWithSystem({
- imageUrl: imageSrc,
- type:'image',
- success(_) {
- 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(_) {
- }
- })
- },
- 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[] = new Array()
- imageUrlList.push(errorImageSrc2)
- imageUrlList.push(imageSrc)
- // imageUrlList.push(errorImageSrc1)
- uni.shareWithSystem({
- imagePaths: imageUrlList,
- type:'image',
- success(_) {
- 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(_) {
- }
- })
- },
- 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[] =new Array()
- imageUrlList.push(imageSrc)
- imageUrlList.push(errorImageSrc1)
- imageUrlList.push(errorImageSrc2)
- uni.shareWithSystem({
- imagePaths: imageUrlList,
- type:'image',
- success(_) {
- 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(_) {
- }
- })
- },
- shareAll() {
- uni.hideToast()
- const imageSrc : string = "/static/test-video/fast-forward.png";
- let imageUrlList : string[] = new Array()
- imageUrlList.push(imageSrc)
- uni.shareWithSystem({
- summary: this.summary,
- href: 'https://uniapp.dcloud.io',
- imagePaths: imageUrlList,
- type:'image',
- success(_) {
- 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(_) {
- }
- })
- },
- 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',
- imagePaths: e.tempFilePaths,
- type:'image',
- success(_) {
- 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(_) {
- }
- })
- }
- })
- },
- shareSnapShot() {
- uni.hideToast()
- uni.getElementById("viewshot")?.takeSnapshot(
- {
- success: function (res) {
- uni.shareWithSystem({
- imageUrl: res.tempFilePath,
- type:'image',
- success(_) {
- 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(_) {
- }
- })
- },
- fail: function (res) {
- console.log(res)
- uni.showToast({
- icon: 'error',
- title: '截图失败'
- })
- }
- }
- )
- },
- }
- }
- </script>
- <style>
- .button {
- margin-left: 30px;
- margin-right: 30px;
- margin-bottom: 15px;
- }
- </style>
|