This commit is contained in:
polv committed 2021-10-24 22:44:24 +07:00
1 parent d3fdba1139
commit 70066f3086
5 files changed
+82 -78

No files matched your search

+22 -43
View File
@@ -40,42 +40,39 @@
Remove from quiz
</a>
</li>
<li v-if="entries.length === 1" class="separator">
<li v-if="entry" class="separator">
<a></a>
</li>
<li v-if="entries.length === 1 && type === 'vocabulary'">
<a
role="button"
@click="openInNewTab('Vocabulary', { entry: entries[0] })"
>
<li v-if="entry && type === 'vocabulary'">
<a role="button" @click="openInNewTab('Vocabulary', { entry })">
Show details
</a>
</li>
<li v-if="entries.length === 1">
<a role="button" @click="openInNewTab('Character', { q: entries[0] })">
<li v-if="entry">
<a role="button" @click="openInNewTab('Character', { q: entry })">
{{ type === 'character' ? 'Show details' : 'Search for Hanzi' }}
</a>
</li>
<li v-if="entries.length === 1 && type !== 'character'">
<a role="button" @click="openInNewTab('Vocabulary', { q: entries[0] })">
<li v-if="entry && type !== 'character'">
<a role="button" @click="openInNewTab('Vocabulary', { q: entry })">
Search for vocabs
</a>
</li>
<li v-if="entries.length === 1">
<li v-if="entry">
<a
role="button"
:href="`https://jisho.org/word/${encodeURIComponent(entries[0])}`"
:href="`https://jisho.org/word/${encodeURIComponent(entry)}`"
target="_blank"
rel="noopener noreferrer"
>
Open in Jisho.org
</a>
</li>
<li v-if="entries.length === 1 && type !== 'sentence'">
<li v-if="entry && type !== 'sentence'">
<a
role="button"
:href="`https://dictionary.goo.ne.jp/srch/all/${encodeURIComponent(
entries[0]
entry
)}/m0u`"
target="_blank"
rel="noopener noreferrer"
@@ -98,19 +95,18 @@
<script lang="ts">
import { Vue, Component, Prop, Ref } from 'nuxt-property-decorator'
import { speak } from '@/assets/speak'
import { api } from '~/assets/api'
import { speak } from '~/assets/speak'
import { api, IType } from '~/assets/api'
@Component
export default class ContextMenu extends Vue {
@Prop() id?: string
@Prop() entry?: string | string[]
@Prop() type?: string
@Prop() entry?: string
@Prop() list?: string[]
@Prop() type?: IType
@Prop() source?: string
@Prop() direction?: string
@Prop() description?: string
@Prop({ default: () => ({}) }) pinyin!: Record<string, string>
@Prop({ default: () => ({}) }) english!: Record<string, string>
@Prop({ default: () => [] }) additional!: {
name: string
@@ -134,15 +130,11 @@ export default class ContextMenu extends Vue {
}
get entries() {
return Array.isArray(this.entry)
? this.entry
: this.entry
? [this.entry]
: []
return this.list || (this.entry ? [this.entry] : [])
}
async setQuiz() {
if (this.entry && this.type) {
if (this.entries.length && this.type) {
const { result } = await api.quiz_getMany({
entries: this.entries,
select: ['id', 'entry'],
@@ -168,21 +160,8 @@ export default class ContextMenu extends Vue {
}
open(evt: MouseEvent) {
this.$nextTick(async () => {
if (this.entry && this.type) {
if (
!(
this.quiz.of &&
this.quiz.of.type !== this.type &&
this.quiz.of.entries.length === this.entries.length &&
this.quiz.of.entries.every((el, i) => this.entries[i] === el)
)
) {
await this.setQuiz()
}
this.contextmenu.open(evt)
}
this.$nextTick(() => {
this.contextmenu.open(evt)
})
}
@@ -197,8 +176,8 @@ export default class ContextMenu extends Vue {
}
async doSpeak() {
if (this.entries.length === 1) {
await speak(this.entries[0])
if (this.entry) {
await speak(this.entry)
}
}