update
This commit is contained in:
1 parent
7d5114953b
commit
cbc36d19f5
7 files changed
+215
-194
No files matched your search
+42
-35
@@ -19,7 +19,7 @@ export interface IUserSettings extends IUserLocalSettings {
|
|||||||
level: number
|
level: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEntry {
|
export interface IDictionaryLookup {
|
||||||
id: string
|
id: string
|
||||||
list: string[]
|
list: string[]
|
||||||
reading: string[]
|
reading: string[]
|
||||||
@@ -31,6 +31,25 @@ export interface IEntry {
|
|||||||
type: IType
|
type: IType
|
||||||
description: string
|
description: string
|
||||||
tag: string[]
|
tag: string[]
|
||||||
|
level?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IEntryLookup {
|
||||||
|
entry: string
|
||||||
|
sub: string[]
|
||||||
|
sup: string[]
|
||||||
|
variant: string[]
|
||||||
|
visual: {
|
||||||
|
entry: string
|
||||||
|
}[]
|
||||||
|
amalgamation: {
|
||||||
|
entry: string
|
||||||
|
type?: IType
|
||||||
|
}[]
|
||||||
|
component: {
|
||||||
|
entry: string
|
||||||
|
type?: IType
|
||||||
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ILibrary {
|
export interface ILibrary {
|
||||||
@@ -197,16 +216,16 @@ class Api {
|
|||||||
|
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.get('/api/extra/q', { params })
|
.get('/api/extra/q', { params })
|
||||||
.then((r) => r.data as ILookupResult<IEntry>)
|
.then((r) => r.data as ILookupResult<IDictionaryLookup>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async extra_create(payload: Omit<IEntry, 'id'>) {
|
async extra_create(payload: Omit<IDictionaryLookup, 'id'>) {
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.put('/api/extra', payload)
|
.put('/api/extra', payload)
|
||||||
.then((r) => r.data as { id: string })
|
.then((r) => r.data as { id: string })
|
||||||
}
|
}
|
||||||
|
|
||||||
async extra_update(payload: IEntry) {
|
async extra_update(payload: IDictionaryLookup) {
|
||||||
return await this.axios.patch('/api/extra', payload, {
|
return await this.axios.patch('/api/extra', payload, {
|
||||||
params: { id: payload.id },
|
params: { id: payload.id },
|
||||||
})
|
})
|
||||||
@@ -226,7 +245,7 @@ class Api {
|
|||||||
|
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.get('/api/character/vocabulary', { params })
|
.get('/api/character/vocabulary', { params })
|
||||||
.then((r) => r.data as ILookupResult<IEntry>)
|
.then((r) => r.data as ILookupResult<IDictionaryLookup>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async character_getSentence(
|
async character_getSentence(
|
||||||
@@ -237,7 +256,18 @@ class Api {
|
|||||||
|
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.get('/api/character/sentence', { params })
|
.get('/api/character/sentence', { params })
|
||||||
.then((r) => r.data as ILookupResult<IEntry>)
|
.then((r) => r.data as ILookupResult<IDictionaryLookup>)
|
||||||
|
}
|
||||||
|
|
||||||
|
async vocabulary_getVocabulary(
|
||||||
|
params: ILookup<{ entry: string; distinct?: 'id' }>
|
||||||
|
) {
|
||||||
|
params.offset = params.offset || 0
|
||||||
|
params.limit = params.limit || 5
|
||||||
|
|
||||||
|
return await this.axios
|
||||||
|
.get('/api/vocabulary/vocabulary', { params })
|
||||||
|
.then((r) => r.data as ILookupResult<IDictionaryLookup>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async vocabulary_getSentence(
|
async vocabulary_getSentence(
|
||||||
@@ -248,7 +278,7 @@ class Api {
|
|||||||
|
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.get('/api/vocabulary/sentence', { params })
|
.get('/api/vocabulary/sentence', { params })
|
||||||
.then((r) => r.data as ILookupResult<IEntry>)
|
.then((r) => r.data as ILookupResult<IDictionaryLookup>)
|
||||||
}
|
}
|
||||||
|
|
||||||
async all_getRandom(params: { type: IType }) {
|
async all_getRandom(params: { type: IType }) {
|
||||||
@@ -261,7 +291,9 @@ class Api {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async all_getQuery(params: ILookup<{ q: string }>) {
|
async all_getQuery(
|
||||||
|
params: ILookup<{ q: string; type?: IType; distinct?: 'id' }>
|
||||||
|
) {
|
||||||
params.offset = params.offset || 0
|
params.offset = params.offset || 0
|
||||||
params.limit = params.limit || 5
|
params.limit = params.limit || 5
|
||||||
|
|
||||||
@@ -284,38 +316,13 @@ class Api {
|
|||||||
.get('/api/all', {
|
.get('/api/all', {
|
||||||
params,
|
params,
|
||||||
})
|
})
|
||||||
.then(
|
.then((r) => r.data as ILookupResult<IDictionaryLookup>)
|
||||||
(r) =>
|
|
||||||
r.data as ILookupResult<
|
|
||||||
IEntry & {
|
|
||||||
level?: number
|
|
||||||
}
|
|
||||||
>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async all_getComponent(params: { entry: string; type: IType }) {
|
async all_getComponent(params: { entry: string; type: IType }) {
|
||||||
return await this.axios
|
return await this.axios
|
||||||
.get('/api/all/components', { params })
|
.get('/api/all/components', { params })
|
||||||
.then(
|
.then((r) => r.data as IEntryLookup)
|
||||||
(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)
|
.catch(() => null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -17,13 +17,15 @@ export async function speak(
|
|||||||
opts: {
|
opts: {
|
||||||
lang?: string
|
lang?: string
|
||||||
forceOffline?: boolean
|
forceOffline?: boolean
|
||||||
|
url?: string
|
||||||
} = {}
|
} = {}
|
||||||
) {
|
) {
|
||||||
if (!opts.forceOffline) {
|
if (!opts.forceOffline) {
|
||||||
const audio = new Audio(
|
const audio = new Audio(
|
||||||
`/api/tts?q=${encodeURIComponent(s)}&lang=${encodeURIComponent(
|
opts.url ||
|
||||||
opts.lang || 'ja'
|
`/api/tts?q=${encodeURIComponent(s)}&lang=${encodeURIComponent(
|
||||||
)}`
|
opts.lang || 'ja'
|
||||||
|
)}`
|
||||||
)
|
)
|
||||||
await audio.play().catch(() =>
|
await audio.play().catch(() =>
|
||||||
speak(s, {
|
speak(s, {
|
||||||
@@ -73,7 +75,6 @@ window.addEventListener('keydown', (ev) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ev.key === 's') {
|
if (ev.key === 's') {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
const s = window.getSelection()!.toString()
|
const s = window.getSelection()!.toString()
|
||||||
if (s) {
|
if (s) {
|
||||||
speak(s)
|
speak(s)
|
||||||
|
|||||||
@@ -102,6 +102,10 @@ import { api, IType } from '~/assets/api'
|
|||||||
export default class ContextMenu extends Vue {
|
export default class ContextMenu extends Vue {
|
||||||
@Prop() id?: string
|
@Prop() id?: string
|
||||||
@Prop() entry?: string
|
@Prop() entry?: string
|
||||||
|
@Prop() audio?: {
|
||||||
|
mimetype?: string
|
||||||
|
url: string
|
||||||
|
}[]
|
||||||
@Prop() list?: string[]
|
@Prop() list?: string[]
|
||||||
@Prop() type?: IType
|
@Prop() type?: IType
|
||||||
@Prop() source?: string
|
@Prop() source?: string
|
||||||
@@ -176,7 +180,7 @@ export default class ContextMenu extends Vue {
|
|||||||
|
|
||||||
async doSpeak() {
|
async doSpeak() {
|
||||||
if (this.entry) {
|
if (this.entry) {
|
||||||
await speak(this.entry)
|
await speak(this.entry, { url: this.audio?.[0]?.url })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,11 +149,11 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Vue, Component, Ref, Prop } from 'nuxt-property-decorator'
|
import { Vue, Component, Ref, Prop } from 'nuxt-property-decorator'
|
||||||
import { api, IEntry, IType } from '~/assets/api'
|
import { api, IDictionaryLookup, IType } from '~/assets/api'
|
||||||
import ContextMenu from '../ContextMenu.vue'
|
import ContextMenu from '../ContextMenu.vue'
|
||||||
|
|
||||||
type ILibraryEntry = Pick<
|
type ILibraryEntry = Pick<
|
||||||
IEntry,
|
IDictionaryLookup,
|
||||||
'list' | 'reading' | 'translation' | 'type'
|
'list' | 'reading' | 'translation' | 'type'
|
||||||
> & {
|
> & {
|
||||||
entry: string
|
entry: string
|
||||||
@@ -263,7 +263,7 @@ export default class LibraryCard extends Vue {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.allSettled(
|
||||||
[...listMap].map(([k, v]) =>
|
[...listMap].map(([k, v]) =>
|
||||||
api
|
api
|
||||||
.all_getLookup({
|
.all_getLookup({
|
||||||
@@ -288,7 +288,7 @@ export default class LibraryCard extends Vue {
|
|||||||
await this.reload([...listMap].flatMap(([, { entry }]) => entry))
|
await this.reload([...listMap].flatMap(([, { entry }]) => entry))
|
||||||
}
|
}
|
||||||
|
|
||||||
getTagClass(it: IEntry) {
|
getTagClass(it: IDictionaryLookup) {
|
||||||
const srsLevel = Math.min(
|
const srsLevel = Math.min(
|
||||||
...it.list.map((el) => this.srsLevel[el] || -Infinity)
|
...it.list.map((el) => this.srsLevel[el] || -Infinity)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -332,7 +332,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Vue, Component, Prop, Ref } from 'vue-property-decorator'
|
import { Vue, Component, Prop, Ref } from 'vue-property-decorator'
|
||||||
import { api, IEntry, IQuiz } from '~/assets/api'
|
import { api, IDictionaryLookup, IQuiz } from '~/assets/api'
|
||||||
import { shuffle } from '~/assets/util'
|
import { shuffle } from '~/assets/util'
|
||||||
import ContextMenu from '../ContextMenu.vue'
|
import ContextMenu from '../ContextMenu.vue'
|
||||||
|
|
||||||
@@ -358,17 +358,17 @@ export default class QuizCard extends Vue {
|
|||||||
} = {}
|
} = {}
|
||||||
|
|
||||||
dictionaryData = {
|
dictionaryData = {
|
||||||
character: {} as Record<string, IEntry>,
|
character: {} as Record<string, IDictionaryLookup>,
|
||||||
vocabulary: {} as Record<
|
vocabulary: {} as Record<
|
||||||
string,
|
string,
|
||||||
IEntry & {
|
IDictionaryLookup & {
|
||||||
sentence_set: Record<string, boolean>
|
sentence_set: string[]
|
||||||
}
|
}
|
||||||
>,
|
>,
|
||||||
sentence: {} as Record<
|
sentence: {} as Record<
|
||||||
string,
|
string,
|
||||||
IEntry & {
|
IDictionaryLookup & {
|
||||||
vocabulary_set: Record<string, boolean>
|
vocabulary_set: string[]
|
||||||
}
|
}
|
||||||
>,
|
>,
|
||||||
}
|
}
|
||||||
@@ -572,7 +572,7 @@ export default class QuizCard extends Vue {
|
|||||||
|
|
||||||
this.dictionaryData[subtype][r.list[0]!] = {
|
this.dictionaryData[subtype][r.list[0]!] = {
|
||||||
...r,
|
...r,
|
||||||
sentence_set: {},
|
sentence_set: [],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -595,7 +595,7 @@ export default class QuizCard extends Vue {
|
|||||||
|
|
||||||
this.dictionaryData[subtype][r.list[0]!] = {
|
this.dictionaryData[subtype][r.list[0]!] = {
|
||||||
...r,
|
...r,
|
||||||
vocabulary_set: {},
|
vocabulary_set: [],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -614,23 +614,18 @@ export default class QuizCard extends Vue {
|
|||||||
const subtype = 'sentence'
|
const subtype = 'sentence'
|
||||||
|
|
||||||
const { result } = await api.vocabulary_getSentence({ entry })
|
const { result } = await api.vocabulary_getSentence({ entry })
|
||||||
result.map((r) => {
|
this.dictionaryData[type][entry]!.sentence_set = result.map((r) => {
|
||||||
if (this.dictionaryData[subtype][r.list[0]!]) {
|
if (this.dictionaryData[subtype][r.list[0]!]) {
|
||||||
return
|
return r.id
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dictionaryData[subtype][r.list[0]!] = {
|
this.dictionaryData[subtype][r.list[0]!] = {
|
||||||
...r,
|
...r,
|
||||||
vocabulary_set: {},
|
vocabulary_set: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return r.id
|
||||||
})
|
})
|
||||||
this.dictionaryData[type][entry]!.sentence_set = result.reduce(
|
|
||||||
(prev, c) => ({
|
|
||||||
...prev,
|
|
||||||
[c.list[0]!]: true,
|
|
||||||
}),
|
|
||||||
{} as Record<string, boolean>
|
|
||||||
)
|
|
||||||
|
|
||||||
this.$set(this.dictionaryData, type, this.dictionaryData[type])
|
this.$set(this.dictionaryData, type, this.dictionaryData[type])
|
||||||
this.$set(this.dictionaryData, subtype, this.dictionaryData[subtype])
|
this.$set(this.dictionaryData, subtype, this.dictionaryData[subtype])
|
||||||
@@ -660,7 +655,7 @@ export default class QuizCard extends Vue {
|
|||||||
|
|
||||||
this.dictionaryData[subtype][entry] = {
|
this.dictionaryData[subtype][entry] = {
|
||||||
...r!,
|
...r!,
|
||||||
sentence_set: {},
|
sentence_set: [],
|
||||||
}
|
}
|
||||||
this.$set(
|
this.$set(
|
||||||
this.dictionaryData,
|
this.dictionaryData,
|
||||||
|
|||||||
@@ -180,6 +180,7 @@
|
|||||||
:id="selected.id"
|
:id="selected.id"
|
||||||
ref="context"
|
ref="context"
|
||||||
:entry="selected.entry"
|
:entry="selected.entry"
|
||||||
|
:audio="selected.audio"
|
||||||
:list="selected.list"
|
:list="selected.list"
|
||||||
:type="selected.type || 'vocabulary'"
|
:type="selected.type || 'vocabulary'"
|
||||||
:description="selected.description"
|
:description="selected.description"
|
||||||
@@ -193,7 +194,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Ref, Vue, Watch } from 'nuxt-property-decorator'
|
import { Component, 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, IDictionaryLookup } from '~/assets/api'
|
||||||
import { jsonClone } from '~/assets/util'
|
import { jsonClone } from '~/assets/util'
|
||||||
|
|
||||||
@Component<BrowseTab>({
|
@Component<BrowseTab>({
|
||||||
@@ -213,7 +214,7 @@ export default class BrowseTab extends Vue {
|
|||||||
count = 0
|
count = 0
|
||||||
perPage = 10
|
perPage = 10
|
||||||
page = 1
|
page = 1
|
||||||
tableData: IEntry[] = []
|
tableData: IDictionaryLookup[] = []
|
||||||
|
|
||||||
isEditModal = false
|
isEditModal = false
|
||||||
|
|
||||||
@@ -222,7 +223,7 @@ export default class BrowseTab extends Vue {
|
|||||||
type: 'desc',
|
type: 'desc',
|
||||||
}
|
}
|
||||||
|
|
||||||
selected: IEntry & {
|
selected: IDictionaryLookup & {
|
||||||
entry: string
|
entry: string
|
||||||
} = {
|
} = {
|
||||||
id: '',
|
id: '',
|
||||||
@@ -351,7 +352,10 @@ export default class BrowseTab extends Vue {
|
|||||||
this.isEditModal = true
|
this.isEditModal = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async onTableContextmenu(row: IEntry & { entry: string }, evt: MouseEvent) {
|
async onTableContextmenu(
|
||||||
|
row: IDictionaryLookup & { entry: string },
|
||||||
|
evt: MouseEvent
|
||||||
|
) {
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
|
|
||||||
this.selected = jsonClone(row)
|
this.selected = jsonClone(row)
|
||||||
|
|||||||
+137
-127
@@ -267,6 +267,7 @@
|
|||||||
<ContextMenu
|
<ContextMenu
|
||||||
ref="context"
|
ref="context"
|
||||||
:entry="selected.entry"
|
:entry="selected.entry"
|
||||||
|
:audio="selected.audio"
|
||||||
:type="selected.type"
|
:type="selected.type"
|
||||||
:additional="additionalContext"
|
:additional="additionalContext"
|
||||||
/>
|
/>
|
||||||
@@ -276,9 +277,11 @@
|
|||||||
<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, IType } from '~/assets/api'
|
import { api, IDictionaryLookup, IEntryLookup, IType } from '~/assets/api'
|
||||||
import { capitalize } from '~/assets/util'
|
import { capitalize } from '~/assets/util'
|
||||||
|
|
||||||
|
type ILookupEntry = Omit<IDictionaryLookup, 'id'> & IEntryLookup
|
||||||
|
|
||||||
@Component<LookupTab>({
|
@Component<LookupTab>({
|
||||||
components: {
|
components: {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
@@ -305,36 +308,15 @@ export default class LookupTab extends Vue {
|
|||||||
|
|
||||||
title = this.type === 'character' ? 'Kanji' : capitalize(this.type)
|
title = this.type === 'character' ? 'Kanji' : capitalize(this.type)
|
||||||
|
|
||||||
entries: string[] = []
|
entries: ILookupEntry[] = []
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
sub: string[] = []
|
lookup: Record<IType, IDictionaryLookup[]> = {
|
||||||
sup: string[] = []
|
|
||||||
variant: string[] = []
|
|
||||||
|
|
||||||
visual: {
|
|
||||||
entry: string
|
|
||||||
}[] = []
|
|
||||||
amalgamation: {
|
|
||||||
entry: string
|
|
||||||
type?: IType
|
|
||||||
}[] = []
|
|
||||||
component: {
|
|
||||||
entry: string
|
|
||||||
type?: IType
|
|
||||||
}[] = []
|
|
||||||
|
|
||||||
lookup: Record<IType, IEntry[]> = {
|
|
||||||
character: [],
|
character: [],
|
||||||
vocabulary: [],
|
vocabulary: [],
|
||||||
sentence: [],
|
sentence: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
reading: string[] = []
|
|
||||||
translation: string[] = []
|
|
||||||
tag: string[] = []
|
|
||||||
level = 0
|
|
||||||
|
|
||||||
selected: {
|
selected: {
|
||||||
entry: string
|
entry: string
|
||||||
type: string
|
type: string
|
||||||
@@ -347,7 +329,7 @@ export default class LookupTab extends Vue {
|
|||||||
q0 = ''
|
q0 = ''
|
||||||
|
|
||||||
get current() {
|
get current() {
|
||||||
return this.entries[this.i] || ' '
|
return this.entries[this.i]?.entry || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
get additionalContext() {
|
get additionalContext() {
|
||||||
@@ -356,7 +338,7 @@ export default class LookupTab extends Vue {
|
|||||||
{
|
{
|
||||||
name: 'Reload',
|
name: 'Reload',
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
const { result } = await api.all_getRandom({ type: 'character' })
|
const { result } = await api.all_getRandom({ type: this.type })
|
||||||
this.q0 = result
|
this.q0 = result
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -378,21 +360,66 @@ export default class LookupTab extends Vue {
|
|||||||
@Watch('q')
|
@Watch('q')
|
||||||
async onQChange(q: string) {
|
async onQChange(q: string) {
|
||||||
this.$emit('title', (q ? q + ' - ' : '') + this.title)
|
this.$emit('title', (q ? q + ' - ' : '') + this.title)
|
||||||
|
this.entries = []
|
||||||
|
|
||||||
if (/\p{sc=Han}/u.test(q)) {
|
if (this.type === 'character') {
|
||||||
const qs = q.split('').filter((h) => /\p{sc=Han}/u.test(h))
|
if (/\p{sc=Han}/u.test(q)) {
|
||||||
this.entries = qs.filter((h, i) => qs.indexOf(h) === i)
|
let qs = q.split('').filter((h) => /\p{sc=Han}/u.test(h))
|
||||||
} else {
|
qs = qs.filter((h, i) => qs.indexOf(h) === i)
|
||||||
if (!q.trim()) {
|
|
||||||
const { result } = await api.all_getRandom({ type: 'character' })
|
|
||||||
|
|
||||||
this.q0 = result
|
this.entries = qs.map(
|
||||||
this.q = result
|
(entry) =>
|
||||||
return
|
({
|
||||||
|
entry,
|
||||||
|
list: [],
|
||||||
|
type: this.type,
|
||||||
|
reading: [],
|
||||||
|
translation: [],
|
||||||
|
audio: [],
|
||||||
|
description: '',
|
||||||
|
tag: [],
|
||||||
|
sub: [],
|
||||||
|
sup: [],
|
||||||
|
variant: [],
|
||||||
|
visual: [],
|
||||||
|
amalgamation: [],
|
||||||
|
component: [],
|
||||||
|
} as ILookupEntry)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (!q.trim()) {
|
||||||
|
const { result } = await api.all_getRandom({ type: this.type })
|
||||||
|
|
||||||
|
this.q0 = result
|
||||||
|
this.q = result
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
const r = await api.all_getQuery({
|
||||||
|
q,
|
||||||
|
type: this.type,
|
||||||
|
distinct: 'id',
|
||||||
|
})
|
||||||
|
this.entries = r.result.map(
|
||||||
|
({ entry }) =>
|
||||||
|
({
|
||||||
|
entry,
|
||||||
|
list: [],
|
||||||
|
type: this.type,
|
||||||
|
reading: [],
|
||||||
|
translation: [],
|
||||||
|
audio: [],
|
||||||
|
description: '',
|
||||||
|
tag: [],
|
||||||
|
sub: [],
|
||||||
|
sup: [],
|
||||||
|
variant: [],
|
||||||
|
visual: [],
|
||||||
|
amalgamation: [],
|
||||||
|
component: [],
|
||||||
|
} as ILookupEntry)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = await api.all_getQuery({ q })
|
|
||||||
this.entries = r.result.map((r) => r.entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.i = 0
|
this.i = 0
|
||||||
@@ -401,118 +428,101 @@ export default class LookupTab extends Vue {
|
|||||||
@Watch('current')
|
@Watch('current')
|
||||||
load() {
|
load() {
|
||||||
if (this.current) {
|
if (this.current) {
|
||||||
this.loadCharacter()
|
this.loadComponents()
|
||||||
this.loadVocab()
|
this.loadVocabularies()
|
||||||
this.loadSentences()
|
this.loadSentences()
|
||||||
} else {
|
} else {
|
||||||
this.sub = []
|
|
||||||
this.sup = []
|
|
||||||
this.variant = []
|
|
||||||
|
|
||||||
this.visual = []
|
|
||||||
this.amalgamation = []
|
|
||||||
this.component = []
|
|
||||||
|
|
||||||
this.lookup = {
|
this.lookup = {
|
||||||
character: [],
|
character: [],
|
||||||
vocabulary: [],
|
vocabulary: [],
|
||||||
sentence: [],
|
sentence: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reading = []
|
|
||||||
this.translation = []
|
|
||||||
this.tag = []
|
|
||||||
this.level = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadCharacter() {
|
async loadComponents() {
|
||||||
if (!/^\p{sc=Han}$/u.test(this.current)) {
|
if (!this.current.trim()) return
|
||||||
this.sub = []
|
|
||||||
this.sup = []
|
|
||||||
this.variant = []
|
|
||||||
this.visual = []
|
|
||||||
|
|
||||||
this.translation = []
|
const [comp, dict] = await Promise.all([
|
||||||
this.tag = []
|
api.all_getComponent({
|
||||||
this.level = 0
|
entry: this.current,
|
||||||
return
|
type: this.type,
|
||||||
}
|
}),
|
||||||
|
api
|
||||||
await Promise.all([
|
.all_getLookup({
|
||||||
(async () => {
|
|
||||||
const r = await api.all_getComponent({
|
|
||||||
entry: this.current,
|
|
||||||
type: this.type,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.sub = r?.sub || []
|
|
||||||
this.sup = r?.sup || []
|
|
||||||
this.variant = r?.variant || []
|
|
||||||
|
|
||||||
this.visual = r?.visual || []
|
|
||||||
this.amalgamation = r?.amalgamation || []
|
|
||||||
this.component = r?.component || []
|
|
||||||
})(),
|
|
||||||
(async () => {
|
|
||||||
const {
|
|
||||||
result: [r],
|
|
||||||
} = await api.all_getLookup({
|
|
||||||
entry: this.current,
|
entry: this.current,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
|
.then(({ result: [r] }) => r),
|
||||||
this.reading = r?.reading || []
|
|
||||||
this.translation = r?.translation || []
|
|
||||||
this.tag = r?.tag || []
|
|
||||||
this.level = r?.level || 0
|
|
||||||
})(),
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
this.$set(this.entries, this.i, {
|
||||||
|
...(dict || {
|
||||||
|
entry: this.current,
|
||||||
|
list: [],
|
||||||
|
type: this.type,
|
||||||
|
reading: [],
|
||||||
|
translation: [],
|
||||||
|
audio: [],
|
||||||
|
description: '',
|
||||||
|
tag: [],
|
||||||
|
}),
|
||||||
|
...(comp || {
|
||||||
|
sub: [],
|
||||||
|
sup: [],
|
||||||
|
variant: [],
|
||||||
|
visual: [],
|
||||||
|
amalgamation: [],
|
||||||
|
component: [],
|
||||||
|
}),
|
||||||
|
} as ILookupEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadVocab() {
|
async loadVocabularies() {
|
||||||
if (this.type === 'character' && !/^\p{sc=Han}$/u.test(this.current)) {
|
if (this.type === 'character') {
|
||||||
this.lookup.vocabulary = []
|
if (!/^\p{sc=Han}$/u.test(this.current)) {
|
||||||
return
|
this.lookup.vocabulary = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lookup.vocabulary = await api
|
||||||
|
.character_getVocabulary({
|
||||||
|
entry: this.current,
|
||||||
|
distinct: 'id',
|
||||||
|
})
|
||||||
|
.then((r) => r.result)
|
||||||
|
} else {
|
||||||
|
this.lookup.vocabulary = await api
|
||||||
|
.vocabulary_getVocabulary({
|
||||||
|
entry: this.current,
|
||||||
|
distinct: 'id',
|
||||||
|
})
|
||||||
|
.then((r) => r.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result } = await api.character_getVocabulary({
|
|
||||||
entry: this.current,
|
|
||||||
distinct: 'id',
|
|
||||||
})
|
|
||||||
|
|
||||||
this.lookup.vocabulary = await Promise.all(
|
|
||||||
result
|
|
||||||
.map((r) =>
|
|
||||||
api
|
|
||||||
.all_getLookup({ entry: r.list[0]!, type: 'vocabulary', limit: 1 })
|
|
||||||
.then((r) => r.result[0]!)
|
|
||||||
)
|
|
||||||
.filter((r) => r)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadSentences() {
|
async loadSentences() {
|
||||||
if (this.type === 'character' && !/^\p{sc=Han}$/u.test(this.current)) {
|
if (this.type === 'character') {
|
||||||
this.lookup.sentence = []
|
if (!/^\p{sc=Han}$/u.test(this.current)) {
|
||||||
return
|
this.lookup.sentence = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lookup.sentence = await api
|
||||||
|
.character_getSentence({
|
||||||
|
entry: this.current,
|
||||||
|
distinct: 'id',
|
||||||
|
})
|
||||||
|
.then((r) => r.result)
|
||||||
|
} else {
|
||||||
|
this.lookup.sentence = await api
|
||||||
|
.vocabulary_getSentence({
|
||||||
|
entry: this.current,
|
||||||
|
distinct: 'id',
|
||||||
|
})
|
||||||
|
.then((r) => r.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result } = await api.character_getSentence({
|
|
||||||
entry: this.current,
|
|
||||||
distinct: 'id',
|
|
||||||
})
|
|
||||||
|
|
||||||
this.lookup.vocabulary = await Promise.all(
|
|
||||||
result
|
|
||||||
.map((r) =>
|
|
||||||
api
|
|
||||||
.all_getLookup({ entry: r.list[0]!, type: 'sentence', limit: 1 })
|
|
||||||
.then((r) => r.result[0]!)
|
|
||||||
)
|
|
||||||
.filter((r) => r)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user