|
| 1 | +import { t } from '@/locales'; |
| 2 | +import { globalCapture, selectedADir, selectedLevel, selectedMusic, selectMusicId, updateMusicList } from '@/store/refs'; |
| 3 | +import { NButton, NFlex, NModal, useMessage } from 'naive-ui'; |
| 4 | +import { defineComponent, PropType, ref, computed, watch, shallowRef } from 'vue'; |
| 5 | +import JacketBox from '../JacketBox'; |
| 6 | +import { DIFFICULTY, LEVEL_COLOR } from '@/consts'; |
| 7 | +import api from '@/client/api'; |
| 8 | + |
| 9 | +export const replaceChartFileHandle = shallowRef<FileSystemFileHandle | null>(null); |
| 10 | + |
| 11 | +export default defineComponent({ |
| 12 | + // props: { |
| 13 | + // }, |
| 14 | + setup(props, { emit }) { |
| 15 | + const message = useMessage(); |
| 16 | + |
| 17 | + const replaceChart = async () => { |
| 18 | + if (!replaceChartFileHandle.value) return; |
| 19 | + try { |
| 20 | + const file = await replaceChartFileHandle.value.getFile(); |
| 21 | + replaceChartFileHandle.value = null; |
| 22 | + await api.ReplaceChart(selectMusicId.value, selectedLevel.value, selectedADir.value, { file }); |
| 23 | + message.success(t('music.edit.replaceChartSuccess')); |
| 24 | + await updateMusicList(); |
| 25 | + } catch (error) { |
| 26 | + globalCapture(error, t('music.edit.replaceChartFailed')); |
| 27 | + console.error(error); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + return () => <NModal |
| 32 | + preset="card" |
| 33 | + class="w-[min(90vw,50em)]" |
| 34 | + title={t('music.edit.replaceChart')} |
| 35 | + show={replaceChartFileHandle.value !== null} |
| 36 | + onUpdateShow={() => replaceChartFileHandle.value = null} |
| 37 | + >{{ |
| 38 | + default: () => <div class="flex flex-col gap-2"> |
| 39 | + {t('music.edit.replaceChartConfirm', { level: DIFFICULTY[selectedLevel.value!] })} |
| 40 | + <div class="text-4.5 text-center">{replaceChartFileHandle.value?.name}</div> |
| 41 | + <div class="text-6 text-center">↓</div> |
| 42 | + <div class="flex justify-center gap-2"> |
| 43 | + <JacketBox info={selectedMusic.value!} class="h-8em w-8em" upload={false} /> |
| 44 | + <div class="flex flex-col gap-1 max-w-24em justify-end"> |
| 45 | + <div class="text-3.5 op-70">#{selectMusicId.value}</div> |
| 46 | + <div class="text-2xl overflow-hidden text-ellipsis whitespace-nowrap">{selectedMusic.value!.name}</div> |
| 47 | + <div class="flex"> |
| 48 | + <div class="c-white rounded-full px-2" style={{ backgroundColor: LEVEL_COLOR[selectedLevel.value!] }}> |
| 49 | + {selectedMusic.value!.charts![selectedLevel.value!]?.level}.{selectedMusic.value!.charts![selectedLevel.value!]?.levelDecimal} |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + </div>, |
| 55 | + footer: () => <NFlex justify="end"> |
| 56 | + <NButton onClick={() => replaceChartFileHandle.value = null}>{t('common.cancel')}</NButton> |
| 57 | + <NButton onClick={replaceChart} type="primary">{t('common.confirm')}</NButton> |
| 58 | + </NFlex> |
| 59 | + }}</NModal>; |
| 60 | + }, |
| 61 | +}); |
0 commit comments