|
@@ -1,5 +1,5 @@
|
|
|
import { Button, Cell, Swipe, SwipeItem, Toast } from 'vant'
|
|
|
-import { defineComponent } from 'vue'
|
|
|
+import { defineComponent, PropType } from 'vue'
|
|
|
import styles from './index.module.less'
|
|
|
import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
|
|
|
import html2canvas from 'html2canvas'
|
|
@@ -15,6 +15,11 @@ export default defineComponent({
|
|
|
shareUrl: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
+ },
|
|
|
+ shareType: {
|
|
|
+ // 分享类型
|
|
|
+ type: String as PropType<'' | 'video' | 'music' | 'live'>,
|
|
|
+ default: ''
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
@@ -33,60 +38,64 @@ export default defineComponent({
|
|
|
// })
|
|
|
// this.codeUrl = shortRes.data
|
|
|
this.codeUrl = this.shareUrl
|
|
|
-
|
|
|
- this.$nextTick(async () => {
|
|
|
- const container: any = document.getElementById(
|
|
|
- 'share-preview-container'
|
|
|
- )
|
|
|
- html2canvas(container, { allowTaint: true, useCORS: true }).then(
|
|
|
- canvas => {
|
|
|
- const url = canvas.toDataURL('image/png')
|
|
|
- this.image = url
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
} catch {
|
|
|
//
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
async onSaveImg() {
|
|
|
- const res = await promisefiyPostMessage({
|
|
|
- api: 'savePicture',
|
|
|
- content: {
|
|
|
- base64: this.image
|
|
|
+ const container: any = document.getElementById('share-preview-container')
|
|
|
+ html2canvas(container, { allowTaint: true, useCORS: true }).then(
|
|
|
+ async canvas => {
|
|
|
+ const url = canvas.toDataURL('image/png')
|
|
|
+ this.image = url
|
|
|
+
|
|
|
+ const res = await promisefiyPostMessage({
|
|
|
+ api: 'savePicture',
|
|
|
+ content: {
|
|
|
+ base64: this.image
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (res?.content?.status === 'success') {
|
|
|
+ Toast.success('保存成功')
|
|
|
+ } else {
|
|
|
+ Toast.fail('保存失败')
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- if (res?.content?.status === 'success') {
|
|
|
- Toast.success('保存成功')
|
|
|
- } else {
|
|
|
- Toast.fail('保存失败')
|
|
|
- }
|
|
|
+ )
|
|
|
},
|
|
|
async shareShow() {
|
|
|
- const image = this.image
|
|
|
- if (image) {
|
|
|
- postMessage(
|
|
|
- {
|
|
|
- api: 'shareAchievements',
|
|
|
- content: {
|
|
|
- title: '我在酷乐秀使用小酷Ai练习乐器',
|
|
|
- desc: '酷乐秀小酷Ai帮助我自主练习乐器,真的太好用啦!每天都要坚持练习哦~',
|
|
|
- image,
|
|
|
- video: '',
|
|
|
- type: 'image'
|
|
|
- }
|
|
|
- },
|
|
|
- (res: any) => {
|
|
|
- if (res && res.content) {
|
|
|
- Toast(
|
|
|
- res.content.message ||
|
|
|
- (res.content.status ? '分享成功' : '分享失败')
|
|
|
- )
|
|
|
- }
|
|
|
+ const container: any = document.getElementById('share-preview-container')
|
|
|
+ html2canvas(container, { allowTaint: true, useCORS: true }).then(
|
|
|
+ async canvas => {
|
|
|
+ const url = canvas.toDataURL('image/png')
|
|
|
+ this.image = url
|
|
|
+
|
|
|
+ const image = this.image
|
|
|
+ if (image) {
|
|
|
+ postMessage(
|
|
|
+ {
|
|
|
+ api: 'shareAchievements',
|
|
|
+ content: {
|
|
|
+ title: '我在酷乐秀使用小酷Ai练习乐器',
|
|
|
+ desc: '酷乐秀小酷Ai帮助我自主练习乐器,真的太好用啦!每天都要坚持练习哦~',
|
|
|
+ image,
|
|
|
+ video: '',
|
|
|
+ type: 'image'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ (res: any) => {
|
|
|
+ if (res && res.content) {
|
|
|
+ Toast(
|
|
|
+ res.content.message ||
|
|
|
+ (res.content.status ? '分享成功' : '分享失败')
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
- )
|
|
|
- }
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
},
|
|
|
render() {
|
|
@@ -94,7 +103,7 @@ export default defineComponent({
|
|
|
<>
|
|
|
{this.codeUrl && (
|
|
|
<>
|
|
|
- <div class={styles.shareContainer}>
|
|
|
+ <div class={styles.shareContainer} id="share-preview-container">
|
|
|
<Swipe showIndicators={false} loop={false}>
|
|
|
<SwipeItem>
|
|
|
<ShareItem teacherId={this.teacherId} shareUrl={this.codeUrl}>
|