Skip to content

Commit 7f83c0b

Browse files
committed
拖放替换音频和曲绘
1 parent 9e9eb1c commit 7f83c0b

File tree

3 files changed

+71
-53
lines changed

3 files changed

+71
-53
lines changed

MaiChartManager/Front/src/components/DragDropDispatcher/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { useDropZone } from '@vueuse/core';
22
import { defineComponent, PropType, ref, computed, watch, shallowRef } from 'vue';
33
import { startProcess as startProcessMusicImport } from '@/components/ImportCreateChartButton/ImportChartButton';
44
import { uploadFlow as uploadFlowMovie } from '@/components/MusicEdit/SetMovieButton';
5+
import { uploadFlow as uploadFlowAcbAwb } from '@/components/MusicEdit/AcbAwb';
56
import { selectedADir, selectedMusic } from '@/store/refs';
7+
import { upload as uploadJacket } from '@/components/JacketBox';
68

79
export const mainDivRef = shallowRef<HTMLDivElement>();
810

@@ -35,6 +37,12 @@ export default defineComponent({
3537
if (file.kind === 'file' && (firstType.startsWith('video/') || ['dat', 'usm'].includes(file.name.toLowerCase().split('.').pop()!))) {
3638
uploadFlowMovie(file);
3739
}
40+
else if (file.kind === 'file' && (firstType.startsWith('audio/') || file.name.endsWith('.acb'))) {
41+
uploadFlowAcbAwb(file);
42+
}
43+
else if (file.kind === 'file' && (firstType.startsWith('image/') || file.name.endsWith('.jpeg') || file.name.endsWith('.jpg') || file.name.endsWith('.png'))) {
44+
uploadJacket(file);
45+
}
3846
}
3947
}
4048
const dropType = ref<DropType>(DropType.None);

MaiChartManager/Front/src/components/JacketBox.tsx

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { globalCapture, selectedADir, selectedMusic } from "@/store/refs";
66
import { MusicXmlWithABJacket } from "@/client/apiGen";
77
import { useI18n } from 'vue-i18n';
88

9+
export let upload = async (fileHandle?: FileSystemFileHandle) => {
10+
}
11+
912
export default defineComponent({
1013
props: {
11-
info: {type: Object as PropType<MusicXmlWithABJacket>, required: true},
12-
upload: {type: Boolean, default: true}
14+
info: { type: Object as PropType<MusicXmlWithABJacket>, required: true },
15+
upload: { type: Boolean, default: true }
1316
},
1417
setup(props) {
1518
const dialog = useDialog();
@@ -18,47 +21,49 @@ export default defineComponent({
1821
getUrl(`GetJacketApi/${props.info.assetDir}/${props.info.id}?${updateTime.value}`) : noJacket)
1922
const { t } = useI18n();
2023

21-
const upload = async () => {
22-
if (!props.upload) return;
23-
try {
24-
const [fileHandle] = await window.showOpenFilePicker({
25-
id: 'jacket',
26-
startIn: 'downloads',
27-
types: [
28-
{
29-
description: t('genre.imageDescription'),
30-
accept: {
31-
"application/jpeg": [".jpeg", ".jpg"],
32-
"application/png": [".png"],
33-
},
34-
},
35-
],
36-
});
37-
38-
if (!fileHandle) return;
39-
const file = await fileHandle.getFile();
24+
if (props.upload)
25+
upload = async (fileHandle?: FileSystemFileHandle) => {
26+
if (!props.upload) return;
27+
try {
28+
if (!fileHandle) {
29+
[fileHandle] = await window.showOpenFilePicker({
30+
id: 'jacket',
31+
startIn: 'downloads',
32+
types: [
33+
{
34+
description: t('genre.imageDescription'),
35+
accept: {
36+
"application/jpeg": [".jpeg", ".jpg"],
37+
"application/png": [".png"],
38+
},
39+
},
40+
],
41+
});
42+
}
43+
if (!fileHandle) return;
44+
const file = await fileHandle.getFile();
4045

41-
const res = await api.SetMusicJacket(props.info.id!, selectedADir.value, {file});
42-
if (res.error) {
43-
const error = res.error as any;
44-
dialog.warning({title: t('jacket.setFailed'), content: error.message || error});
45-
return;
46-
}
47-
if (res.data) {
48-
dialog.info({title: t('jacket.setFailed'), content: res.data})
49-
return;
46+
const res = await api.SetMusicJacket(props.info.id!, selectedADir.value, { file });
47+
if (res.error) {
48+
const error = res.error as any;
49+
dialog.warning({ title: t('jacket.setFailed'), content: error.message || error });
50+
return;
51+
}
52+
if (res.data) {
53+
dialog.info({ title: t('jacket.setFailed'), content: res.data })
54+
return;
55+
}
56+
updateTime.value = Date.now()
57+
props.info.hasJacket = true;
58+
selectedMusic.value!.hasJacket = true;
59+
(selectedMusic.value as any).updateTime = updateTime.value
60+
} catch (e: any) {
61+
if (e.name === 'AbortError') return
62+
console.log(e)
63+
globalCapture(e, t('jacket.replaceFailed'))
5064
}
51-
updateTime.value = Date.now()
52-
props.info.hasJacket = true;
53-
selectedMusic.value!.hasJacket = true;
54-
(selectedMusic.value as any).updateTime = updateTime.value
55-
} catch (e: any) {
56-
if (e.name === 'AbortError') return
57-
console.log(e)
58-
globalCapture(e, t('jacket.replaceFailed'))
5965
}
60-
}
6166

62-
return () => <img src={jacketUrl.value} class={`object-fill rounded-lg ${props.upload && 'cursor-pointer'}`} onClick={upload}/>
67+
return () => <img src={jacketUrl.value} class={`object-fill rounded-lg ${props.upload && 'cursor-pointer'}`} onClick={() => upload()} />
6368
}
6469
})

MaiChartManager/Front/src/components/MusicEdit/AcbAwb.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import AudioPreviewEditorButton from "@/components/MusicEdit/AudioPreviewEditorB
88
import SetMovieButton from "@/components/MusicEdit/SetMovieButton";
99
import { t } from "@/locales";
1010

11+
export let uploadFlow = async (fileHandle?: FileSystemFileHandle) => {
12+
}
13+
1114
export default defineComponent({
1215
props: {
1316
song: { type: Object as PropType<MusicXmlWithABJacket>, required: true },
@@ -26,21 +29,23 @@ export default defineComponent({
2629
const cueIdNotMatch = computed(() => props.song.nonDxId !== props.song.cueId)
2730
const movieIdNotMatch = computed(() => props.song.nonDxId !== props.song.movieId)
2831

29-
const uploadFlow = async () => {
32+
uploadFlow = async (fileHandle?: FileSystemFileHandle) => {
3033
tipShow.value = true
3134
try {
32-
const [fileHandle] = await window.showOpenFilePicker({
33-
id: 'acbawb',
34-
startIn: 'downloads',
35-
types: [
36-
{
37-
description: t('music.edit.supportedFileTypes'),
38-
accept: {
39-
"application/x-supported": [".mp3", ".wav", ".ogg", ".acb"],
35+
if (!fileHandle) {
36+
[fileHandle] = await window.showOpenFilePicker({
37+
id: 'acbawb',
38+
startIn: 'downloads',
39+
types: [
40+
{
41+
description: t('music.edit.supportedFileTypes'),
42+
accept: {
43+
"application/x-supported": [".mp3", ".wav", ".ogg", ".acb"],
44+
},
4045
},
41-
},
42-
],
43-
});
46+
],
47+
});
48+
}
4449
tipShow.value = false;
4550
if (!fileHandle) return;
4651
const file = await fileHandle.getFile() as File;
@@ -99,7 +104,7 @@ export default defineComponent({
99104
{props.song.isAcbAwbExist && <audio controls src={url.value} class="w-0 grow"/>}
100105
{selectedADir.value !== 'A000' &&
101106
<NPopover trigger="hover" disabled={!cueIdNotMatch.value}>{{
102-
trigger: () => <NButton secondary class={`${!props.song.isAcbAwbExist && "w-full"}`} onClick={uploadFlow} loading={load.value} disabled={cueIdNotMatch.value}>{props.song.isAcbAwbExist ? t('music.edit.replaceAudio') : t('music.edit.setAudio')}</NButton>,
107+
trigger: () => <NButton secondary class={`${!props.song.isAcbAwbExist && "w-full"}`} onClick={() => uploadFlow()} loading={load.value} disabled={cueIdNotMatch.value}>{props.song.isAcbAwbExist ? t('music.edit.replaceAudio') : t('music.edit.setAudio')}</NButton>,
103108
default: () => t('music.edit.cueIdNotMatch')
104109
}}</NPopover>
105110
}

0 commit comments

Comments
 (0)