import { defineComponent } from 'vue' import { Button, Field, Form, Tag, Radio, RadioGroup, Popup, Empty, Toast, CellGroup } from 'vant' import { state as appState } from '@/state' import { teachershowAudiType, teacherPaymentType } from '@/constant/music' import { getXmlInfo, FormatXMLInfo } from '@/helpers/music-xml' import Upload from './upload' import styles from './index.module.less' import { browser } from '@/helpers/utils' import { postMessage } from '@/helpers/native-message' import request from '@/helpers/request' import requestOrigin from 'umi-request' import UploadIcon from './images/music-icon.png' import btnBg from './images/btn-bg.png' import iconBrid from './images/icon-brid.png' import iconTitleUpload from './images/icon-title-upload.png' import iconTitleUpdate from './images/icon-title-update.png' import ColUpload from '@/components/col-upload' import { verifiyNumberInteger, verifyNumberIntegerAndFloat } from '@/helpers/toolsValidate' import ColHeader from '@/components/col-header' import ColSticky from '@/components/col-sticky' import MessageTip from './message-tip' import SelectTag from './select-tag' import ListenAudio from './listen-audio' export type BackgroundMp3 = { url?: string id?: string trackName?: string track?: string loading?: boolean } // 校验函数返回 true 表示校验通过,false 表示不通过 export const validator = val => { if (Number(val) <= 0) { return '收费金额必须大于0' } else { return true } } export default defineComponent({ name: 'MusicUpload', data() { return { reason: '', playMode: 'MP3', xmlFileUrl: '', xmlFileLoading: false, midiFileUrl: '', midiLoading: false, mp3Url: '', bgmp3Url: '', mp3Loading: false, name: '', composer: '', remark: '', // repeatedBeats: 0, playSpeed: '' as any, // hasBeat: 0, musicCover: '', paymentType: 'FREE', // showFingering: 1, // canEvaluate: 1, // notation: 1, musicPrice: '', // subJectIndex: 0, // subjectIds: [] as any, // 可用声部 musicalInstrumentIdList: [] as any, // 可用乐器 selectTagVisible: false, subJectVisible: false, instrumentVisible: false, tags: [] as any[], tagsNames: [] as Array<{ [id in string]: string }>, formated: {} as FormatXMLInfo, tagVisibility: false, listenAudioShow: false, // subjectListres: [] as any[], // subjectListNames: {} as any, // selectedSubjectList: null as any, // vlewSubjectList: null as any, submitLoading: false, // showPicker: false, music_sheet_service_fee: 0, music_account_period: 0, // exquisiteFlag: 0, backgroundMp3s: [] as BackgroundMp3[], // checked: false, auditStatus: '' as any, messageTipStatus: false, messageTipTitle: '上传须知', messageTipType: 'upload' as 'upload' | 'error' | 'origin', cbsInstrumentList: [] as any, tagList: [] as any, musicSheetAuthRecordId: null as any, fileInfo: { url: '', name: '' as any } } }, watch: { formated() { this.mergeXmlData(this.formated) } }, computed: { auditDisabled(): boolean { return this.auditStatus === 'DOING' } }, async mounted() { const isCatchTip = localStorage.getItem('isCatchTip') if (!isCatchTip) { this.messageTipStatus = true } // 获取基础数据 request .get('/api-teacher/sysConfig/queryByParamNameList', { params: { paramNames: 'music_sheet_service_fee,music_account_period' } }) .then((res: any) => { const data = res.data || [] data.forEach((item: any) => { if (item.paramName === 'music_sheet_service_fee') { this.music_sheet_service_fee = item.paramValue } else if (item.paramName === 'music_account_period') { this.music_account_period = item.paramValue } }) }) const prefix = appState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher' request(prefix + '/MusicTag/tree').then((res: any) => { this.tagList = res.data || [] }) if (this.$route.params.id) { this.setDetail(this.$route.params.id as string) } request .post('/api-teacher/musicalInstrument/list') .then((response: any) => { const data = response.data || [] data.forEach((item: any) => { this.cbsInstrumentList.push({ id: item.id, name: item.name, code: item.code, loading: false }) }) }) }, methods: { async setDetail(id: string) { try { const { data } = await request.get( `/api-teacher/music/sheet/detail/${id}` ) this.musicSheetAuthRecordId = data.musicSheetAuthRecordId // 审核编号 this.auditStatus = data.auditStatus console.log(this.musicSheetAuthRecordId) this.playMode = data.audioType || 'MP3' this.xmlFileUrl = data.xmlFileUrl this.name = data.musicSheetName this.composer = data.composer this.playSpeed = data.playSpeed // this.tags = data.musicTag?.split(',') const names = data.musicTagNames.split(',') this.tags = data.musicTag.split(',') this.tags = this.tags .filter((el: any) => { return el != '' }) .map(e => Number(e)) for (let i = 0; i < names.length; i++) { this.tagsNames[this.tags[i]] = names[i] } this.musicCover = data.titleImg this.midiFileUrl = data.midiUrl this.mp3Url = data.metronomeUrl this.remark = data.remark this.paymentType = data.paymentType this.musicPrice = data.musicPrice || 0 // this.extConfigJson = data.extConfigJson this.backgroundMp3s = data.background.map((item: any) => { return { url: item.audioFileUrl, trackName: item.musicalInstrumentName, id: item.musicalInstrumentId, track: item.track, loading: false } }) } catch (error) { console.log(error) } }, onComfirm(tags: any) { const names: any = [] this.tagList.forEach(tag => { if (tags.includes(tag.id)) { names[tag.id] = tag.name } }) this.tagsNames = names this.tagVisibility = false const data = Object.values(tags).flat().filter(Boolean) as string[] console.log(data) this.tags = data }, readerFile(file: File) { const reader = new FileReader() reader.onload = () => { const xml = reader.result as string const formated = getXmlInfo(xml) let resultIndexStatus = false const partNames = formated.partNames || [] const tempMp3s: BackgroundMp3[] = [] for (const i of partNames) { let index = -1 this.cbsInstrumentList.forEach((item: any, j: number) => { const code = item.code ? item.code.split(',') : '' for (const p of code) { if (i.indexOf(p) > -1) { index = j } } }) if (index === -1) { resultIndexStatus = true break } const currentItem = this.cbsInstrumentList[index] if (currentItem) { tempMp3s.push({ url: '', id: currentItem.id, trackName: currentItem.name, track: i, loading: currentItem.loading }) } } if (partNames.length <= 0 || resultIndexStatus) { this.messageTipStatus = true this.messageTipTitle = '解析失败' this.messageTipType = 'error' this.xmlFileUrl = '' return } this.formated = formated this.backgroundMp3s = tempMp3s } reader.readAsText(file) }, mergeXmlData(data: FormatXMLInfo) { this.formated = data // this.backgroundMp3s = data.partNames.map((partName: string) => ({ // track: partName // })) if (!this.name) { this.name = data.title } if (!this.composer) { this.composer = data.composer } if (!this.playSpeed && data.speed) { this.playSpeed = '' + data.speed } else { this.playSpeed = '100' } }, naiveXMLFile() { this.xmlFileLoading = true postMessage( { api: 'chooseFile', content: { type: 'xml', bucket: 'cloud-coach' } }, evt => { // @ts-ignore this.xmlFileUrl = evt?.fileUrl || this.xmlFileUrl || '' this.xmlFileLoading = false if (this.xmlFileUrl) { requestOrigin(this.xmlFileUrl).then(res => { // this.formated = getXmlInfo(res) const formated = getXmlInfo(res) let resultIndexStatus = false const partNames = formated.partNames || [] const tempMp3s: BackgroundMp3[] = [] for (const i of partNames) { let index = -1 this.cbsInstrumentList.forEach((item: any, j: number) => { const code = item.code ? item.code.split(',') : '' for (const p of code) { if (i.indexOf(p) > -1) { index = j } } }) if (index === -1) { resultIndexStatus = true break } const currentItem = this.cbsInstrumentList[index] if (currentItem) { console.log(currentItem, 'currentItem') tempMp3s.push({ url: '', id: currentItem.id, trackName: currentItem.name, track: i, loading: currentItem.loading }) } } if (partNames.length <= 0 || resultIndexStatus) { this.messageTipStatus = true this.messageTipTitle = '解析失败' this.messageTipType = 'error' this.xmlFileUrl = '' return } this.formated = formated this.backgroundMp3s = tempMp3s }) } } ) }, naiveMidFile() { this.midiLoading = true postMessage( { api: 'chooseFile', content: { type: 'midi', bucket: 'cloud-coach' } }, evt => { // @ts-ignore this.midiFileUrl = evt?.fileUrl || this.midiFileUrl || '' this.midiLoading = false // this.midiFileUrl = path } ) }, naiveMp3File() { this.mp3Loading = true postMessage( { api: 'chooseFile', content: { type: 'mp3', bucket: 'cloud-coach' } }, evt => { // @ts-ignore this.mp3Url = evt?.fileUrl || this.mp3Url || '' this.mp3Loading = false // this.midiFileUrl = path } ) }, naiveBGMp3File(index) { this.backgroundMp3s[index].loading = true postMessage( { api: 'chooseFile', content: { type: 'mp3', bucket: 'cloud-coach' } }, evt => { // @ts-ignore const url = evt?.fileUrl || this.backgroundMp3s[index].url || '' this.backgroundMp3s[index].url = url this.backgroundMp3s[index].loading = false } ) }, onFormatter(val: any) { return verifyNumberIntegerAndFloat(val) }, onFormatter2(val: any) { const num = verifiyNumberInteger(val) // if (num && Number(num) > 270) { // return '270' // } // if (num && Number(num) < 45) { // return '45' // } return num }, fileName(name = '') { return name?.split('/').pop() }, createSubmitData() { return { musicSheetJson: { playMode: this.playMode, // 播放模式 xmlFileUrl: this.xmlFileUrl, // XML name: this.name, // 曲目名称 composer: this.composer, // 音乐人 playSpeed: this.playSpeed, // 曲目速度 remark: this.remark, musicTagIds: this.tags?.join(','), musicCover: this.musicCover, // 曲目封面 multiTracksSelection: this.backgroundMp3s .map(item => item.track) ?.join(','), // 声轨名 midiFileUrl: this.midiFileUrl, // MID文件 musicSheetAccompanimentList: [ { audioFileUrl: this.mp3Url, sortNumber: 1, audioPlayType: 'PLAY' } ], // 伴奏 musicPrice: this.musicPrice, paymentType: this.paymentType, // audioType: 'HOMEMODE', // HOMEMODE 默认自制 musicSheetSoundList: this.backgroundMp3s.map(item => ({ musicalInstrumentId: item.id, musicalInstrumentName: item.trackName, track: item.track, audioFileUrl: item.url, audioPlayType: 'PLAY' // SING })), // 原音 musicalInstrumentIds: this.backgroundMp3s .map(item => item.id) ?.join(','), // 乐器编号 extConfigJson: '{"repeatedBeats":0,"gradualTimes":{},"isEvxml":0}' } } }, async onSubmit(vals: any) { console.log(vals, this.createSubmitData()) this.submitLoading = true try { if (this.$route.params.id) { await request.post('/api-teacher/musicSheetAuthRecord/update', { data: { ...this.createSubmitData(), id: this.musicSheetAuthRecordId } }) } else { await request.post('/api-teacher/musicSheetAuthRecord/save', { data: this.createSubmitData() }) } Toast('上传成功') setTimeout(() => { postMessage({ api: 'back' }) }, 800) } catch (error) { // } finally { setTimeout(() => { this.submitLoading = false }, 800) } console.log(vals) }, onFailed(e: any) { console.log('failed', e) } }, render() { return (
) } })