Skip to content

Commit badcf1c

Browse files
authored
Merge pull request #84 from tolerious/feat/refactor-app
Feat/refactor app
2 parents 0bda2ba + 8e4d386 commit badcf1c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.env.development

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ VITE_ROUTER_HISTORY = 'hash'
88

99
## 开发环境地址前缀(一般 '/','./' 都可以)
1010
VITE_PUBLIC_PATH = '/'
11+
12+
VITE_BACKEND_URL="http://localhost:3000"

.env.production

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ VITE_ROUTER_HISTORY = 'hash'
88

99
## 开发环境地址前缀(一般 '/','./' 都可以)
1010
VITE_PUBLIC_PATH = '/'
11+
12+
VITE_BACKEND_URL="https://api.stylishreader.com"

src/views/FlashCard.vue

+23-1
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@
4545
<template v-else>
4646
<el-empty description="默认词组中没有收藏单词" />
4747
</template>
48+
<audio autoplay ref="audioPlayer" :src="audioUrl">123</audio>
4849
</template>
4950

5051
<script setup lang="ts">
5152
import Header from '@/components/Header.vue';
5253
import type { ResponseData, Word } from '@/types';
5354
import { request } from '@/utils/service';
5455
import { Refresh } from '@element-plus/icons-vue';
56+
import axios from 'axios';
5557
import { ElNotification } from 'element-plus';
5658
import { computed, onMounted, ref, type Ref } from 'vue';
5759
import { useRoute, useRouter } from 'vue-router';
5860
59-
const buttonTexts = ['上一个', '文章链接', '下一个'];
61+
const buttonTexts = ['文章链接', '发音', '上一个', '下一个'];
6062
6163
const route = useRoute();
6264
const router = useRouter();
@@ -66,6 +68,8 @@ const wordList: Ref<Word[]> = ref([]);
6668
const currentIndex = ref(0);
6769
const currentTranslation = ref();
6870
const originalPageUrl = ref('');
71+
const audioUrl = ref('');
72+
const audioPlayer: Ref<HTMLAudioElement | null> = ref(null);
6973
7074
const currentWord = computed(() => wordList.value[currentIndex.value] ?? { en: '' });
7175
@@ -78,6 +82,21 @@ onMounted(async () => {
7882
await getGroupDetail();
7983
});
8084
85+
async function handleClick() {
86+
console.log(currentWord.value.en);
87+
const response: any = await axios({
88+
url: `${import.meta.env.VITE_BACKEND_URL}/youdao/`, // 后端 API
89+
method: 'POST',
90+
data: { word: currentWord.value.en },
91+
responseType: 'blob', // 获取音频为 Blob
92+
});
93+
console.log(response.data);
94+
const audioBlob = response.data;
95+
const u = URL.createObjectURL(audioBlob);
96+
audioUrl.value = u;
97+
audioPlayer.value?.play();
98+
}
99+
81100
async function getWordList() {
82101
const t: ResponseData = await request({ url: '/word/bygroup', method: 'post', data: { groupId: groupId.value } });
83102
@@ -120,6 +139,9 @@ function navigateWord(text: string) {
120139
window.open(`http://${originalPageUrl.value}`, '_blank');
121140
}
122141
}
142+
if (text === '发音') {
143+
handleClick();
144+
}
123145
isTranslationVisible.value = false;
124146
}
125147
</script>

0 commit comments

Comments
 (0)