update Dictionary
This commit is contained in:
1 parent
86a558dfb5
commit
427fac4936
2 files changed
+26
-130
No files matched your search
@@ -1,31 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<section>
|
<section>
|
||||||
<div class="CharacterTab">
|
<div class="CharacterTab">
|
||||||
<form class="field" @submit.prevent="q = q0">
|
|
||||||
<label for="q" class="label">
|
|
||||||
Search
|
|
||||||
<b-tooltip label="How to?" position="is-right">
|
|
||||||
<a
|
|
||||||
href="https://github.com/zhquiz/zhquiz/wiki/How-to-search-or-filter"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
<b-icon icon="info-circle"></b-icon>
|
|
||||||
</a>
|
|
||||||
</b-tooltip>
|
|
||||||
</label>
|
|
||||||
<div class="control">
|
|
||||||
<input
|
|
||||||
v-model="q0"
|
|
||||||
class="input"
|
|
||||||
type="search"
|
|
||||||
name="q"
|
|
||||||
placeholder="Type here to search."
|
|
||||||
aria-label="search"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column is-6 entry-display">
|
<div class="column is-6 entry-display">
|
||||||
<div
|
<div
|
||||||
@@ -234,7 +209,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Prop, Ref, Vue, Watch } from 'nuxt-property-decorator'
|
import { Component, Prop, Ref, Vue } from 'nuxt-property-decorator'
|
||||||
import ContextMenu from '@/components/ContextMenu.vue'
|
import ContextMenu from '@/components/ContextMenu.vue'
|
||||||
import { api, IDictionaryLookup, IEntryLookup, IType } from '~/assets/api'
|
import { api, IDictionaryLookup, IEntryLookup, IType } from '~/assets/api'
|
||||||
|
|
||||||
@@ -262,33 +237,26 @@ const makeLookupEntry = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component<LookupTab>({
|
@Component<DictionaryTab>({
|
||||||
components: {
|
components: {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
this.$emit('title', this.title)
|
this.$emit('title', `${this.query.entry} - ${this.query.type}`)
|
||||||
|
this.loadComponents()
|
||||||
this.q = this.query.q || ''
|
this.loadVocabularies()
|
||||||
|
this.loadSentences()
|
||||||
if (this.additionalContext[0]) {
|
|
||||||
await this.additionalContext[0].handler()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class LookupTab extends Vue {
|
export default class DictionaryTab extends Vue {
|
||||||
@Prop({ default: () => ({}) }) query!: {
|
@Prop() query!: {
|
||||||
q?: string
|
entry: string
|
||||||
entry?: string
|
type: IType
|
||||||
type?: 'character' | 'vocabulary'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ref() context!: ContextMenu
|
@Ref() context!: ContextMenu
|
||||||
|
|
||||||
title = 'Lookup'
|
entry = makeLookupEntry(this.query.entry, this.query.type)
|
||||||
|
|
||||||
entries: ILookupEntry[] = []
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
lookup: Record<IType, IDictionaryLookup[]> = {
|
lookup: Record<IType, IDictionaryLookup[]> = {
|
||||||
character: [],
|
character: [],
|
||||||
@@ -305,91 +273,30 @@ export default class LookupTab extends Vue {
|
|||||||
type: '',
|
type: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
q = ''
|
|
||||||
q0 = ''
|
|
||||||
|
|
||||||
get entry() {
|
|
||||||
return this.entries[this.i] || makeLookupEntry()
|
|
||||||
}
|
|
||||||
|
|
||||||
get additionalContext() {
|
|
||||||
if (!(this.q || '').trim()) {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
name: 'Reload',
|
|
||||||
handler: async () => {
|
|
||||||
const { result } = await api.all_getRandom({ type: 'vocabulary' })
|
|
||||||
this.q0 = result
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
openContext(evt: MouseEvent, entry = this.selected) {
|
openContext(evt: MouseEvent, entry = this.selected) {
|
||||||
this.selected = entry
|
this.selected = entry
|
||||||
this.context.open(evt)
|
this.context.open(evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Watch('q')
|
|
||||||
async onQChange(q: string) {
|
|
||||||
this.$emit('title', (q ? q + ' - ' : '') + this.title)
|
|
||||||
this.entries = []
|
|
||||||
|
|
||||||
if (q.trim()) {
|
|
||||||
const r = await api.all_getQuery({
|
|
||||||
q,
|
|
||||||
type: this.query.type,
|
|
||||||
distinct: 'id',
|
|
||||||
})
|
|
||||||
this.entries = r.result.map(({ entry, type }) =>
|
|
||||||
makeLookupEntry(entry, type)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.i = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@Watch('entry.entry')
|
|
||||||
load() {
|
|
||||||
if (this.entry.entry) {
|
|
||||||
this.loadComponents()
|
|
||||||
this.loadVocabularies()
|
|
||||||
this.loadSentences()
|
|
||||||
} else {
|
|
||||||
this.lookup = {
|
|
||||||
character: [],
|
|
||||||
vocabulary: [],
|
|
||||||
sentence: [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadComponents() {
|
async loadComponents() {
|
||||||
const entry = this.entries[this.i]
|
|
||||||
if (!entry) return
|
|
||||||
|
|
||||||
const [comp, dict] = await Promise.all([
|
const [comp, dict] = await Promise.all([
|
||||||
api.all_getComponent({
|
api.all_getComponent({
|
||||||
entry: entry.entry,
|
entry: this.query.entry,
|
||||||
type: entry.type,
|
type: this.query.type,
|
||||||
}),
|
}),
|
||||||
api
|
api
|
||||||
.all_getLookup({
|
.all_getLookup({
|
||||||
entry: entry.entry,
|
entry: this.query.entry,
|
||||||
type: entry.type,
|
type: this.query.type,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
.then(({ result: [r] }) => r),
|
.then(({ result: [r] }) => r),
|
||||||
])
|
])
|
||||||
|
|
||||||
this.$set(this.entries, this.i, {
|
this.entry = {
|
||||||
|
...this.query,
|
||||||
...(dict || {
|
...(dict || {
|
||||||
entry: entry.entry,
|
|
||||||
list: [],
|
list: [],
|
||||||
type: entry.type,
|
|
||||||
reading: [],
|
reading: [],
|
||||||
translation: [],
|
translation: [],
|
||||||
audio: [],
|
audio: [],
|
||||||
@@ -404,29 +311,26 @@ export default class LookupTab extends Vue {
|
|||||||
amalgamation: [],
|
amalgamation: [],
|
||||||
component: [],
|
component: [],
|
||||||
}),
|
}),
|
||||||
} as ILookupEntry)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadVocabularies() {
|
async loadVocabularies() {
|
||||||
const entry = this.entries[this.i]
|
if (this.query.type === 'character') {
|
||||||
if (!entry) return
|
if (!/^\p{sc=Han}$/u.test(this.query.entry)) {
|
||||||
|
|
||||||
if (entry.type === 'character') {
|
|
||||||
if (!/^\p{sc=Han}$/u.test(entry.entry)) {
|
|
||||||
this.lookup.vocabulary = []
|
this.lookup.vocabulary = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lookup.vocabulary = await api
|
this.lookup.vocabulary = await api
|
||||||
.character_getVocabulary({
|
.character_getVocabulary({
|
||||||
entry: entry.entry,
|
entry: this.query.entry,
|
||||||
distinct: 'id',
|
distinct: 'id',
|
||||||
})
|
})
|
||||||
.then((r) => r.result)
|
.then((r) => r.result)
|
||||||
} else {
|
} else {
|
||||||
this.lookup.vocabulary = await api
|
this.lookup.vocabulary = await api
|
||||||
.vocabulary_getVocabulary({
|
.vocabulary_getVocabulary({
|
||||||
entry: entry.entry,
|
entry: this.query.entry,
|
||||||
distinct: 'id',
|
distinct: 'id',
|
||||||
})
|
})
|
||||||
.then((r) => r.result)
|
.then((r) => r.result)
|
||||||
@@ -434,25 +338,22 @@ export default class LookupTab extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadSentences() {
|
async loadSentences() {
|
||||||
const entry = this.entries[this.i]
|
if (this.query.type === 'character') {
|
||||||
if (!entry) return
|
if (!/^\p{sc=Han}$/u.test(this.query.entry)) {
|
||||||
|
|
||||||
if (entry.type === 'character') {
|
|
||||||
if (!/^\p{sc=Han}$/u.test(entry.entry)) {
|
|
||||||
this.lookup.sentence = []
|
this.lookup.sentence = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lookup.sentence = await api
|
this.lookup.sentence = await api
|
||||||
.character_getSentence({
|
.character_getSentence({
|
||||||
entry: entry.entry,
|
entry: this.query.entry,
|
||||||
distinct: 'id',
|
distinct: 'id',
|
||||||
})
|
})
|
||||||
.then((r) => r.result)
|
.then((r) => r.result)
|
||||||
} else {
|
} else {
|
||||||
this.lookup.sentence = await api
|
this.lookup.sentence = await api
|
||||||
.vocabulary_getSentence({
|
.vocabulary_getSentence({
|
||||||
entry: entry.entry,
|
entry: this.query.entry,
|
||||||
distinct: 'id',
|
distinct: 'id',
|
||||||
})
|
})
|
||||||
.then((r) => r.result)
|
.then((r) => r.result)
|
||||||
|
|||||||
@@ -158,11 +158,6 @@ export default class AppPage extends Vue {
|
|||||||
component: 'Search',
|
component: 'Search',
|
||||||
icon: 'search',
|
icon: 'search',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
component: 'Dictionary',
|
|
||||||
text: '字',
|
|
||||||
className: 'font-han',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
component: 'Level',
|
component: 'Level',
|
||||||
text: this.level,
|
text: this.level,
|
||||||
|
|||||||
Reference in new issue
Block a user