feat:修改数据结构
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Article, ArticleWord, DefaultArticleWord, DictType, Sentence} from "@/types.ts";
|
||||
import {Article, ArticleWord, DictType, getDefaultArticleWord, Sentence} from "@/types.ts";
|
||||
import {cloneDeep} from "lodash-es";
|
||||
import nlp from "compromise/one";
|
||||
import {usePlayWordAudio} from "@/hooks/sound.ts";
|
||||
@@ -82,13 +82,12 @@ export function genArticleSectionData(article: Article): number {
|
||||
})
|
||||
}
|
||||
|
||||
let word3: ArticleWord = {
|
||||
...DefaultArticleWord,
|
||||
let word3: ArticleWord = getDefaultArticleWord({
|
||||
word: pre,
|
||||
nextSpace: false,
|
||||
isSymbol: true,
|
||||
symbolPosition: ''
|
||||
};
|
||||
});
|
||||
// console.log('rrr', item)
|
||||
// console.log('nearSymbolPosition', nearSymbolPosition)
|
||||
if (nearSymbolPosition === 'end' || nearSymbolPosition === null) {
|
||||
@@ -126,8 +125,7 @@ export function genArticleSectionData(article: Article): number {
|
||||
case keyboardMap.Slash:
|
||||
case keyboardMap.Exclamation:
|
||||
sentence.words[sentence.words.length - 1].nextSpace = false
|
||||
let word2 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
let word2 = getDefaultArticleWord({
|
||||
word: post,
|
||||
isSymbol: true,
|
||||
nextSpace
|
||||
@@ -155,8 +153,7 @@ export function genArticleSectionData(article: Article): number {
|
||||
//所以需要检测一下
|
||||
if (sentence.words.length) {
|
||||
sentence.words[sentence.words.length - 1].nextSpace = true
|
||||
let word3 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
let word3 = getDefaultArticleWord({
|
||||
word: 'placeholder',
|
||||
isSymbol: true,
|
||||
nextSpace: false,
|
||||
@@ -173,8 +170,7 @@ export function genArticleSectionData(article: Article): number {
|
||||
})
|
||||
} else {
|
||||
sentence.words[sentence.words.length - 1].nextSpace = false
|
||||
let word3 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
let word3 = getDefaultArticleWord({
|
||||
word: post,
|
||||
isSymbol: true,
|
||||
nextSpace: false,
|
||||
@@ -193,7 +189,7 @@ export function genArticleSectionData(article: Article): number {
|
||||
checkQuote(pre, index)
|
||||
}
|
||||
|
||||
let word = cloneDeep({...DefaultArticleWord, word: v.text, nextSpace: true});
|
||||
let word = getDefaultArticleWord({word: v.text, nextSpace: true});
|
||||
sentence.words.push(word)
|
||||
|
||||
let post: string = v.post
|
||||
@@ -346,13 +342,12 @@ Its none of your business, the young man said rudely. This is a private conversa
|
||||
})
|
||||
}
|
||||
|
||||
let word3: ArticleWord = {
|
||||
...DefaultArticleWord,
|
||||
let word3: ArticleWord = getDefaultArticleWord({
|
||||
word: pre,
|
||||
nextSpace: false,
|
||||
isSymbol: true,
|
||||
symbolPosition: ''
|
||||
};
|
||||
});
|
||||
// console.log('rrr', item)
|
||||
// console.log('nearSymbolPosition', nearSymbolPosition)
|
||||
if (nearSymbolPosition === 'end' || nearSymbolPosition === null) {
|
||||
@@ -390,8 +385,7 @@ Its none of your business, the young man said rudely. This is a private conversa
|
||||
case keyboardMap.Slash:
|
||||
case keyboardMap.Exclamation:
|
||||
sentence.words[sentence.words.length - 1].nextSpace = false
|
||||
let word2 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
let word2 = getDefaultArticleWord({
|
||||
word: post,
|
||||
isSymbol: true,
|
||||
nextSpace
|
||||
@@ -419,8 +413,7 @@ Its none of your business, the young man said rudely. This is a private conversa
|
||||
//所以需要检测一下
|
||||
if (sentence.words.length) {
|
||||
sentence.words[sentence.words.length - 1].nextSpace = true
|
||||
let word3 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
let word3 = getDefaultArticleWord({
|
||||
word: 'placeholder',
|
||||
isSymbol: true,
|
||||
nextSpace: false,
|
||||
@@ -437,8 +430,7 @@ Its none of your business, the young man said rudely. This is a private conversa
|
||||
})
|
||||
} else {
|
||||
sentence.words[sentence.words.length - 1].nextSpace = false
|
||||
let word3 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
let word3 = getDefaultArticleWord({
|
||||
word: post,
|
||||
isSymbol: true,
|
||||
nextSpace: false,
|
||||
@@ -457,7 +449,7 @@ Its none of your business, the young man said rudely. This is a private conversa
|
||||
checkQuote(pre, index)
|
||||
}
|
||||
|
||||
let word = cloneDeep({...DefaultArticleWord, word: v.text, nextSpace: true});
|
||||
let word = getDefaultArticleWord({word: v.text, nextSpace: true});
|
||||
sentence.words.push(word)
|
||||
|
||||
let post: string = v.post
|
||||
|
||||
@@ -56,10 +56,9 @@ onMounted(() => {
|
||||
isAdd = true
|
||||
}else {
|
||||
if (!runtimeStore.editDict.id) {
|
||||
router.push("/")
|
||||
router.push("/article")
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
function formClose() {
|
||||
|
||||
@@ -35,7 +35,7 @@ let list = $computed({
|
||||
|
||||
onMounted(() => {
|
||||
if (!runtimeStore.editDict.id) {
|
||||
router.push("/")
|
||||
router.push("/word")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import {getDefaultWord2, ShortcutKey, Word2} from "@/types.ts";
|
||||
import {getDefaultWord, ShortcutKey, Word} from "@/types.ts";
|
||||
import VolumeIcon from "@/components/icon/VolumeIcon.vue";
|
||||
import {useSettingStore} from "@/stores/setting.ts";
|
||||
import {usePlayBeep, usePlayCorrect, usePlayKeyboardAudio, usePlayWordAudio, useTTsPlayAudio} from "@/hooks/sound.ts";
|
||||
@@ -9,11 +9,11 @@ import Tooltip from "@/pages/pc/components/Tooltip.vue";
|
||||
import SentenceHightLightWord from "@/pages/pc/word/components/SentenceHightLightWord.vue";
|
||||
|
||||
interface IProps {
|
||||
word: Word2,
|
||||
word: Word,
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<IProps>(), {
|
||||
word: () => getDefaultWord2(),
|
||||
word: () => getDefaultWord(),
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
77
src/types.ts
77
src/types.ts
@@ -5,52 +5,9 @@ import deFlag from "@/assets/img/flags/de.png";
|
||||
import codeFlag from "@/assets/img/flags/code.png";
|
||||
import myFlag from "@/assets/img/flags/my.png";
|
||||
|
||||
export type WordTrans = {
|
||||
pos: string,
|
||||
cn: string,
|
||||
en: string
|
||||
}
|
||||
export type Word = {
|
||||
id?: any,
|
||||
"word": string,
|
||||
"phonetic0": string,
|
||||
"phonetic1": string,
|
||||
"trans": WordTrans[]
|
||||
sentences?: { v: string, tran: string }[],
|
||||
relWords?: { w: string, tran: string }[],
|
||||
phrases?: { v: string, tran: string } [],
|
||||
synos?: { w: string, tran: string } [],
|
||||
memory?: string,
|
||||
}
|
||||
|
||||
export function getDefaultWord(val?: any): Word {
|
||||
return {
|
||||
id: '',
|
||||
word: '',
|
||||
phonetic0: '',
|
||||
phonetic1: '',
|
||||
trans: [],
|
||||
sentences: [],
|
||||
relWords: [],
|
||||
phrases: [],
|
||||
synos: [],
|
||||
memory: '',
|
||||
...val
|
||||
}
|
||||
}
|
||||
|
||||
export type StudyWord = {
|
||||
type: 'new' | 'repeat' | 'wrong'
|
||||
word: Word
|
||||
}
|
||||
|
||||
export const PronunciationApi = 'https://dict.youdao.com/dictvoice?audio='
|
||||
|
||||
export type TranslateLanguageType = 'en' | 'zh-CN' | 'ja' | 'de' | 'common' | ''
|
||||
export type LanguageType = 'en' | 'ja' | 'de' | 'code'
|
||||
|
||||
|
||||
export interface Word2 {
|
||||
id?: string,
|
||||
custom?: boolean,
|
||||
word: string,
|
||||
phonetic0: string,
|
||||
phonetic1: string,
|
||||
@@ -87,7 +44,7 @@ export interface Word2 {
|
||||
}[],
|
||||
}
|
||||
|
||||
export function getDefaultWord2(val?: any): Word2 {
|
||||
export function getDefaultWord(val?: any): Word {
|
||||
return {
|
||||
"word": "",
|
||||
"phonetic0": "",
|
||||
@@ -100,10 +57,16 @@ export function getDefaultWord2(val?: any): Word2 {
|
||||
"root": "",
|
||||
"rels": []
|
||||
},
|
||||
"etymology": []
|
||||
"etymology": [],
|
||||
...val
|
||||
}
|
||||
}
|
||||
|
||||
export const PronunciationApi = 'https://dict.youdao.com/dictvoice?audio='
|
||||
|
||||
export type TranslateLanguageType = 'en' | 'zh-CN' | 'ja' | 'de' | 'common' | ''
|
||||
export type LanguageType = 'en' | 'ja' | 'de' | 'code'
|
||||
|
||||
export type DictResource = {
|
||||
id: string
|
||||
name: string
|
||||
@@ -117,7 +80,6 @@ export type DictResource = {
|
||||
language: LanguageType
|
||||
}
|
||||
|
||||
|
||||
export enum DictType {
|
||||
collect = 'collect',
|
||||
simple = 'simple',
|
||||
@@ -128,22 +90,21 @@ export enum DictType {
|
||||
article = 'article',
|
||||
}
|
||||
|
||||
export const DefaultArticleWord: ArticleWord = {
|
||||
word: '',
|
||||
phonetic0: '',
|
||||
phonetic1: '',
|
||||
trans: [],
|
||||
nextSpace: true,
|
||||
isSymbol: false,
|
||||
symbolPosition: ''
|
||||
}
|
||||
|
||||
export interface ArticleWord extends Word {
|
||||
nextSpace: boolean,
|
||||
isSymbol: boolean,
|
||||
symbolPosition: 'start' | 'end' | '',
|
||||
}
|
||||
|
||||
export function getDefaultArticleWord(val?: any): ArticleWord {
|
||||
return getDefaultWord({
|
||||
nextSpace: true,
|
||||
isSymbol: false,
|
||||
symbolPosition: '',
|
||||
...val
|
||||
}) as ArticleWord
|
||||
}
|
||||
|
||||
export interface Sentence {
|
||||
text: string,
|
||||
translate: string,
|
||||
|
||||
Reference in New Issue
Block a user