|
@@ -1,4 +1,12 @@
|
|
-import { defineComponent, toRefs, reactive, onMounted, ref } from 'vue'
|
|
|
|
|
|
+import {
|
|
|
|
+ defineComponent,
|
|
|
|
+ toRefs,
|
|
|
|
+ reactive,
|
|
|
|
+ onMounted,
|
|
|
|
+ ref,
|
|
|
|
+ watch,
|
|
|
|
+ nextTick
|
|
|
|
+} from 'vue'
|
|
import classes from './index.module.less'
|
|
import classes from './index.module.less'
|
|
import { ElButton, ElOption, ElSelect } from 'element-plus'
|
|
import { ElButton, ElOption, ElSelect } from 'element-plus'
|
|
import printIcon from './images/printIcon.png'
|
|
import printIcon from './images/printIcon.png'
|
|
@@ -14,8 +22,10 @@ import code from './images/code.png'
|
|
import musicItem from './modals/musicItem'
|
|
import musicItem from './modals/musicItem'
|
|
import request from '@/helpers/request'
|
|
import request from '@/helpers/request'
|
|
import { useRoute } from 'vue-router'
|
|
import { useRoute } from 'vue-router'
|
|
-import { getUserType } from '@/helpers/utils'
|
|
|
|
|
|
+import { getUserType, vaildTeachingUrl } from '@/helpers/utils'
|
|
|
|
+import { imgToCanvas, addWatermark, convasToImg } from '@/helpers/imageFunction'
|
|
import printJS from 'print-js'
|
|
import printJS from 'print-js'
|
|
|
|
+
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: 'muiscDetial',
|
|
name: 'muiscDetial',
|
|
props: {
|
|
props: {
|
|
@@ -43,7 +53,10 @@ export default defineComponent({
|
|
mp3Type: '',
|
|
mp3Type: '',
|
|
activeRow: {} as any,
|
|
activeRow: {} as any,
|
|
showCode: false,
|
|
showCode: false,
|
|
- userType: ''
|
|
|
|
|
|
+ userType: '',
|
|
|
|
+ accompanyUrl: '',
|
|
|
|
+ imgData: '',
|
|
|
|
+ imgUrl:''
|
|
})
|
|
})
|
|
const print = ref()
|
|
const print = ref()
|
|
const getMusicList = async () => {
|
|
const getMusicList = async () => {
|
|
@@ -60,6 +73,7 @@ export default defineComponent({
|
|
state.activeRow = res.data.background[0]
|
|
state.activeRow = res.data.background[0]
|
|
state.subjectId = res.data.background[0].id
|
|
state.subjectId = res.data.background[0].id
|
|
state.teacherDetail = res.data.teacher
|
|
state.teacherDetail = res.data.teacher
|
|
|
|
+ setAccompanyUrl()
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log(e)
|
|
console.log(e)
|
|
}
|
|
}
|
|
@@ -82,22 +96,84 @@ export default defineComponent({
|
|
state.id = val as string
|
|
state.id = val as string
|
|
getMusicList()
|
|
getMusicList()
|
|
}
|
|
}
|
|
|
|
+ watch(
|
|
|
|
+ () => state.accompanyUrl,
|
|
|
|
+ accompanyUrl => {
|
|
|
|
+ state.accompanyUrl = accompanyUrl
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ const setAccompanyUrl = () => {
|
|
|
|
+ let url = vaildTeachingUrl()
|
|
|
|
+ // state.accompanyUrl =
|
|
|
|
+ // url +
|
|
|
|
+ // `/accompany/colxiu-website.html?id=${state.id}&part-index=${state.subjectId}`
|
|
|
|
+ state.accompanyUrl = `http://192.168.3.8:3000/colxiu-website.html?id=${state.id}&part-index=${state.subjectId}`
|
|
|
|
+
|
|
|
|
+ // var iframe = document.getElementById('containerPrint') as any //获取id为svgframe的iframe对象
|
|
|
|
+ // if (iframe.attachEvent) {
|
|
|
|
+ // iframe.attachEvent('onload', function () {
|
|
|
|
+ // })
|
|
|
|
+ // } else {
|
|
|
|
+ // iframe.onload = function () {
|
|
|
|
+ // //这里获取svgDom
|
|
|
|
+ // console.log(iframe.contentWindow)
|
|
|
|
+ // var iframeSvg = document.getElementById('osmdSvgPage1')
|
|
|
|
+ // console.log(iframeSvg)
|
|
|
|
+ // //接下来就可以对svgDom进行操作,绑定元素点击事件,改变元素的属性等等
|
|
|
|
+ // //给svg上id为‘VKnife1’的元素绑定点击事件
|
|
|
|
+
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // document.getElementById('containerPrint').onload = function () {
|
|
|
|
+ // console.log(print)
|
|
|
|
+ // }
|
|
|
|
+ }
|
|
|
|
+ const setSvg = (val: any) => {
|
|
|
|
+ console.log(val)
|
|
|
|
+ }
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
|
+ // window.setSvg = (val)=>{
|
|
|
|
+ // setSvg(val)
|
|
|
|
+ // }
|
|
|
|
+ window.addEventListener(
|
|
|
|
+ 'message',
|
|
|
|
+ e => {
|
|
|
|
+ console.log(e)
|
|
|
|
+ state.imgData = e.data
|
|
|
|
+ // printHander()
|
|
|
|
+ // alert(e.data);
|
|
|
|
+ },
|
|
|
|
+ false
|
|
|
|
+ )
|
|
state.userType = getUserType()
|
|
state.userType = getUserType()
|
|
state.showCode = state.userType == 'STUDENT' ? true : false
|
|
state.showCode = state.userType == 'STUDENT' ? true : false
|
|
|
|
+ // 拼链接
|
|
getMusicList()
|
|
getMusicList()
|
|
})
|
|
})
|
|
- const printHander = () => {
|
|
|
|
- printJS({
|
|
|
|
- printable: 'containerPrint', // 元素id,不支持多个
|
|
|
|
- type: 'html',
|
|
|
|
- targetStyle: ['* '],
|
|
|
|
- targetStyles: ['*'],
|
|
|
|
- maxWidth: '', // 最大宽度,默认800,仅支持数字
|
|
|
|
- style:
|
|
|
|
- '@page{size:auto; margin: 0;}' +
|
|
|
|
- '@media print { @page {size: landscape } }' // landscape 默认横向打印
|
|
|
|
- } as any)
|
|
|
|
|
|
+ const printHander = async () => {
|
|
|
|
+ const tempCanvas = await imgToCanvas(state.imgData)
|
|
|
|
+ const canvas = addWatermark(tempCanvas, '酷乐秀')
|
|
|
|
+ const imgUrl = convasToImg(canvas)
|
|
|
|
+ const link = document.createElement('a')
|
|
|
|
+ link.setAttribute('download', state.musicDetail.musicSheetName)
|
|
|
|
+
|
|
|
|
+ // 添加时间戳,防止浏览器缓存图片
|
|
|
|
+ state.imgUrl = imgUrl
|
|
|
|
+ // return
|
|
|
|
+ link.href = imgUrl
|
|
|
|
+ link.click()
|
|
|
|
+ // printJS({
|
|
|
|
+ // printable: imgUrl, // 元素id,不支持多个
|
|
|
|
+ // type: 'image',
|
|
|
|
+ // targetStyle: ['* '],
|
|
|
|
+ // targetStyles: ['*'],
|
|
|
|
+ // maxWidth: '', // 最大宽度,默认800,仅支持数字
|
|
|
|
+ // style:
|
|
|
|
+ // '@page{size:auto; margin: 0;}'
|
|
|
|
+
|
|
|
|
+ // } as any)
|
|
|
|
+ // '@media print { @page {size: landscape } }' // landscape 默认横向打印
|
|
}
|
|
}
|
|
return () => (
|
|
return () => (
|
|
<>
|
|
<>
|
|
@@ -111,6 +187,9 @@ export default defineComponent({
|
|
class="w-full subjectChiose"
|
|
class="w-full subjectChiose"
|
|
v-model={state.subjectId}
|
|
v-model={state.subjectId}
|
|
placeholder="请选择声部"
|
|
placeholder="请选择声部"
|
|
|
|
+ onChange={() => {
|
|
|
|
+ setAccompanyUrl()
|
|
|
|
+ }}
|
|
>
|
|
>
|
|
{state.subjectList.map((item: any) => (
|
|
{state.subjectList.map((item: any) => (
|
|
<ElOption
|
|
<ElOption
|
|
@@ -121,13 +200,19 @@ export default defineComponent({
|
|
))}
|
|
))}
|
|
</ElSelect>
|
|
</ElSelect>
|
|
</div>
|
|
</div>
|
|
- <div class={classes.titleRight} onClick={() => printHander()}>
|
|
|
|
|
|
+ <div class={classes.titleRight} onClick={() => printHander()}>
|
|
<img src={printIcon} alt="" />
|
|
<img src={printIcon} alt="" />
|
|
- <p>打印乐谱</p>
|
|
|
|
|
|
+ <p>下载乐谱</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- <div class={classes.musicContent} id='containerPrint' ref="print">
|
|
|
|
- 123
|
|
|
|
|
|
+ <div class={classes.musicContent}>
|
|
|
|
+ {/* id="iframe" ref="iframe"*/}
|
|
|
|
+ <iframe
|
|
|
|
+ id="containerPrint"
|
|
|
|
+ ref="print"
|
|
|
|
+ style="width: 100%;height:750px;page-break-after:always;"
|
|
|
|
+ src={state.accompanyUrl}
|
|
|
|
+ />
|
|
</div>
|
|
</div>
|
|
{state.showCode ? (
|
|
{state.showCode ? (
|
|
<div class={classes.showCode}>
|
|
<div class={classes.showCode}>
|