update lookup
This commit is contained in:
1 parent
b32007acd1
commit
7d5114953b
2 files changed
+79
-37
No files matched your search
+29
-16
@@ -23,7 +23,10 @@ export interface IEntry {
|
|||||||
id: string
|
id: string
|
||||||
list: string[]
|
list: string[]
|
||||||
reading: string[]
|
reading: string[]
|
||||||
audio: string[]
|
audio: {
|
||||||
|
mimetype?: string
|
||||||
|
url: string
|
||||||
|
}[]
|
||||||
translation: string[]
|
translation: string[]
|
||||||
type: IType
|
type: IType
|
||||||
description: string
|
description: string
|
||||||
@@ -215,21 +218,6 @@ class Api {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async character_getRadical(params: { entry: string }) {
|
|
||||||
return await this.axios
|
|
||||||
.get('/api/character/radical', { params })
|
|
||||||
.then(
|
|
||||||
(r) =>
|
|
||||||
r.data as {
|
|
||||||
sub: string[]
|
|
||||||
sup: string[]
|
|
||||||
variant: string[]
|
|
||||||
visual: string[]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.catch(() => null)
|
|
||||||
}
|
|
||||||
|
|
||||||
async character_getVocabulary(
|
async character_getVocabulary(
|
||||||
params: ILookup<{ entry: string; distinct?: 'id' }>
|
params: ILookup<{ entry: string; distinct?: 'id' }>
|
||||||
) {
|
) {
|
||||||
@@ -306,6 +294,31 @@ class Api {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async all_getComponent(params: { entry: string; type: IType }) {
|
||||||
|
return await this.axios
|
||||||
|
.get('/api/all/components', { params })
|
||||||
|
.then(
|
||||||
|
(r) =>
|
||||||
|
r.data as {
|
||||||
|
sub: string[]
|
||||||
|
sup: string[]
|
||||||
|
variant: string[]
|
||||||
|
visual: {
|
||||||
|
entry: string
|
||||||
|
}[]
|
||||||
|
amalgamation: {
|
||||||
|
entry: string
|
||||||
|
type?: IType
|
||||||
|
}[]
|
||||||
|
component: {
|
||||||
|
entry: string
|
||||||
|
type?: IType
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(() => null)
|
||||||
|
}
|
||||||
|
|
||||||
async all_tokenize(params: { entry: string }) {
|
async all_tokenize(params: { entry: string }) {
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.get('/api/all/tokenize', {
|
.get('/api/all/tokenize', {
|
||||||
|
|||||||
@@ -276,16 +276,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Prop, Ref, Vue, Watch } from 'nuxt-property-decorator'
|
import { Component, Prop, Ref, Vue, Watch } from 'nuxt-property-decorator'
|
||||||
import ContextMenu from '@/components/ContextMenu.vue'
|
import ContextMenu from '@/components/ContextMenu.vue'
|
||||||
import { api, IEntry } from '~/assets/api'
|
import { api, IEntry, IType } from '~/assets/api'
|
||||||
|
import { capitalize } from '~/assets/util'
|
||||||
|
|
||||||
const TITLE = 'Kanji'
|
@Component<LookupTab>({
|
||||||
|
|
||||||
@Component<CharacterTab>({
|
|
||||||
components: {
|
components: {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
this.$emit('title', TITLE)
|
this.$emit('title', this.title)
|
||||||
|
|
||||||
this.q = this.query.q || ''
|
this.q = this.query.q || ''
|
||||||
|
|
||||||
@@ -294,29 +293,48 @@ const TITLE = 'Kanji'
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class CharacterTab extends Vue {
|
export default class LookupTab extends Vue {
|
||||||
@Prop({ default: () => ({}) }) query!: {
|
@Prop({ default: () => ({}) }) query!: {
|
||||||
q?: string
|
q?: string
|
||||||
|
entry?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Prop() type!: 'character' | 'vocabulary'
|
||||||
|
|
||||||
@Ref() context!: ContextMenu
|
@Ref() context!: ContextMenu
|
||||||
|
|
||||||
|
title = this.type === 'character' ? 'Kanji' : capitalize(this.type)
|
||||||
|
|
||||||
entries: string[] = []
|
entries: string[] = []
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
sub: string[] = []
|
sub: string[] = []
|
||||||
sup: string[] = []
|
sup: string[] = []
|
||||||
variant: string[] = []
|
variant: string[] = []
|
||||||
visual: string[] = []
|
|
||||||
|
visual: {
|
||||||
|
entry: string
|
||||||
|
}[] = []
|
||||||
|
amalgamation: {
|
||||||
|
entry: string
|
||||||
|
type?: IType
|
||||||
|
}[] = []
|
||||||
|
component: {
|
||||||
|
entry: string
|
||||||
|
type?: IType
|
||||||
|
}[] = []
|
||||||
|
|
||||||
|
lookup: Record<IType, IEntry[]> = {
|
||||||
|
character: [],
|
||||||
|
vocabulary: [],
|
||||||
|
sentence: [],
|
||||||
|
}
|
||||||
|
|
||||||
reading: string[] = []
|
reading: string[] = []
|
||||||
translation: string[] = []
|
translation: string[] = []
|
||||||
tag: string[] = []
|
tag: string[] = []
|
||||||
level = 0
|
level = 0
|
||||||
|
|
||||||
vocabulary_lookup: IEntry[] = []
|
|
||||||
sentence_lookup: IEntry[] = []
|
|
||||||
|
|
||||||
selected: {
|
selected: {
|
||||||
entry: string
|
entry: string
|
||||||
type: string
|
type: string
|
||||||
@@ -359,7 +377,7 @@ export default class CharacterTab extends Vue {
|
|||||||
|
|
||||||
@Watch('q')
|
@Watch('q')
|
||||||
async onQChange(q: string) {
|
async onQChange(q: string) {
|
||||||
this.$emit('title', (q ? q + ' - ' : '') + TITLE)
|
this.$emit('title', (q ? q + ' - ' : '') + this.title)
|
||||||
|
|
||||||
if (/\p{sc=Han}/u.test(q)) {
|
if (/\p{sc=Han}/u.test(q)) {
|
||||||
const qs = q.split('').filter((h) => /\p{sc=Han}/u.test(h))
|
const qs = q.split('').filter((h) => /\p{sc=Han}/u.test(h))
|
||||||
@@ -390,14 +408,21 @@ export default class CharacterTab extends Vue {
|
|||||||
this.sub = []
|
this.sub = []
|
||||||
this.sup = []
|
this.sup = []
|
||||||
this.variant = []
|
this.variant = []
|
||||||
|
|
||||||
this.visual = []
|
this.visual = []
|
||||||
|
this.amalgamation = []
|
||||||
|
this.component = []
|
||||||
|
|
||||||
|
this.lookup = {
|
||||||
|
character: [],
|
||||||
|
vocabulary: [],
|
||||||
|
sentence: [],
|
||||||
|
}
|
||||||
|
|
||||||
this.reading = []
|
this.reading = []
|
||||||
this.translation = []
|
this.translation = []
|
||||||
this.tag = []
|
this.tag = []
|
||||||
this.level = 0
|
this.level = 0
|
||||||
this.vocabulary_lookup = []
|
|
||||||
this.sentence_lookup = []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,21 +441,25 @@ export default class CharacterTab extends Vue {
|
|||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
(async () => {
|
(async () => {
|
||||||
const r = await api.character_getRadical({
|
const r = await api.all_getComponent({
|
||||||
entry: this.current,
|
entry: this.current,
|
||||||
|
type: this.type,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.sub = r?.sub || []
|
this.sub = r?.sub || []
|
||||||
this.sup = r?.sup || []
|
this.sup = r?.sup || []
|
||||||
this.variant = r?.variant || []
|
this.variant = r?.variant || []
|
||||||
|
|
||||||
this.visual = r?.visual || []
|
this.visual = r?.visual || []
|
||||||
|
this.amalgamation = r?.amalgamation || []
|
||||||
|
this.component = r?.component || []
|
||||||
})(),
|
})(),
|
||||||
(async () => {
|
(async () => {
|
||||||
const {
|
const {
|
||||||
result: [r],
|
result: [r],
|
||||||
} = await api.all_getLookup({
|
} = await api.all_getLookup({
|
||||||
entry: this.current,
|
entry: this.current,
|
||||||
type: 'character',
|
type: this.type,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -443,8 +472,8 @@ export default class CharacterTab extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadVocab() {
|
async loadVocab() {
|
||||||
if (!/^\p{sc=Han}$/u.test(this.current)) {
|
if (this.type === 'character' && !/^\p{sc=Han}$/u.test(this.current)) {
|
||||||
this.vocabulary_lookup = []
|
this.lookup.vocabulary = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +482,7 @@ export default class CharacterTab extends Vue {
|
|||||||
distinct: 'id',
|
distinct: 'id',
|
||||||
})
|
})
|
||||||
|
|
||||||
this.vocabulary_lookup = await Promise.all(
|
this.lookup.vocabulary = await Promise.all(
|
||||||
result
|
result
|
||||||
.map((r) =>
|
.map((r) =>
|
||||||
api
|
api
|
||||||
@@ -465,8 +494,8 @@ export default class CharacterTab extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadSentences() {
|
async loadSentences() {
|
||||||
if (!/^\p{sc=Han}$/u.test(this.current)) {
|
if (this.type === 'character' && !/^\p{sc=Han}$/u.test(this.current)) {
|
||||||
this.sentence_lookup = []
|
this.lookup.sentence = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +504,7 @@ export default class CharacterTab extends Vue {
|
|||||||
distinct: 'id',
|
distinct: 'id',
|
||||||
})
|
})
|
||||||
|
|
||||||
this.vocabulary_lookup = await Promise.all(
|
this.lookup.vocabulary = await Promise.all(
|
||||||
result
|
result
|
||||||
.map((r) =>
|
.map((r) =>
|
||||||
api
|
api
|
||||||
Reference in new issue
Block a user