This commit is contained in:
zyronon
2023-11-30 01:13:18 +08:00
parent 3b653811ac
commit 5a3f4445dc
7 changed files with 195 additions and 35 deletions

View File

@@ -39,7 +39,8 @@ useWindowClick((e: PointerEvent) => {
.base-input {
border: 1px solid var(--color-second-bg);
border-radius: 4rem;
border-radius: 6rem;
overflow: hidden;
padding: 3rem 5rem;
transition: all .3s;
display: flex;

View File

@@ -107,7 +107,7 @@ function onPaste(event: ClipboardEvent) {
() => {
appendTranslate(paste)
renewSections()
},
},null,
{
confirmButtonText: '需要',
cancelButtonText: '关闭',

View File

@@ -0,0 +1,133 @@
<script setup lang="ts">
import Input from "@/components/Input.vue";
import {$computed, $ref} from "vue/macros";
import {Article, Word} from "@/types.ts";
import ListItem from "@/components/list/ListItem.vue";
import {useSettingStore} from "@/stores/setting.ts";
import {onMounted, useAttrs, watch} from "vue";
import VolumeIcon from "@/components/icon/VolumeIcon.vue";
import BaseList from "@/components/list2/BaseList.vue";
const props = withDefaults(defineProps<{
list: Article[],
isActive?: boolean
showTranslate?: boolean
}>(), {
list: [],
activeIndex: -1,
isActive: false,
showTranslate: true
})
const emit = defineEmits<{
click: [val: { data: Article, index: number }],
delSelectItem: [],
'update:searchKey': [val: string],
'update:list': [list: Article[]],
}>()
let searchKey = $ref('')
let localList = $computed({
get() {
if (searchKey) {
return props.list.filter((item: Article) => {
//把搜索内容,分词之后,判断是否有这个词,比单纯遍历包含体验更好
return searchKey.toLowerCase().split(' ').filter(v => v).some(value => {
return item.title.toLowerCase().includes(value) || item.titleTranslate.toLowerCase().includes(value)
})
})
} else {
return props.list
}
},
set(newValue) {
emit('update:list', newValue)
}
})
const settingStore = useSettingStore()
const listRef: HTMLElement = $ref(null as any)
// function scrollViewToCenter(index: number) {
// if (index === -1) return
// listRef.children[index + 1]?.scrollIntoView({block: 'center', behavior: 'smooth'})
// }
//
// watch(() => props.activeIndex, (n: any) => {
// if (settingStore.showPanel) {
// scrollViewToCenter(n)
// }
// })
//
// watch(() => props.isActive, (n: boolean) => {
// setTimeout(() => {
// if (n) scrollViewToCenter(props.activeIndex)
// }, 300)
// })
// watch(() => props.list, () => {
// // listRef.scrollTo(0, 0)
// })
function scrollToBottom() {
listRef?.scrollToBottom()
}
function scrollToItem(index: number) {
listRef?.scrollToItem(index)
}
let attr = useAttrs()
onMounted(() => {
console.log('atr', attr)
})
defineExpose({scrollToBottom, scrollToItem})
</script>
<template>
<div class="list">
<div class="search">
<Input v-model="searchKey"/>
</div>
<BaseList :list="localList"
v-bind="$attrs">
<template v-slot:prefix="{ item, index, active }">
<slot name="prefix" :item="item" :index="index"></slot>
</template>
<template v-slot="{ item, index, active }">
<div class="item-title">
<div class="name"> {{ `${index + 1}. ${item.title}` }}</div>
</div>
<div class="item-sub-title" v-if="item.titleTranslate && showTranslate">
<div class="item-translate"> {{ ` ${item.titleTranslate}` }}</div>
</div>
</template>
<template v-slot:suffix="{ item, index, active }">
<slot name="suffix" :item="item" :index="index"></slot>
</template>
</BaseList>
</div>
</template>
<style scoped lang="scss">
.list {
display: flex;
flex-direction: column;
gap: 15rem;
flex: 1;
overflow: hidden;
.search {
box-sizing: border-box;
width: 100%;
padding: 0 var(--space);
}
.translate {
font-size: 16rem;
}
}
</style>

View File

@@ -6,20 +6,26 @@ import {usePlayWordAudio} from "@/hooks/sound.ts";
import {watch} from 'vue'
const props = withDefaults(defineProps<{
list: Word[],
list?: any[],
activeIndex?: number,
activeId?: string,
isActive?: boolean
showTranslate?: boolean
showWord?: boolean
}>(), {
list: [],
activeIndex: -1,
activeId: '',
isActive: false,
showTranslate: true,
showWord: true
})
const emit = defineEmits<{
click: [val: { word: Word, index: number }],
click: [val: {
item: any,
index: number
}],
}>()
const settingStore = useSettingStore()
@@ -30,18 +36,18 @@ function scrollViewToCenter(index: number) {
listRef.scrollToIndex(index)
// listRef.children[index]?.scrollIntoView({block: 'center', behavior: 'smooth'})
}
watch(() => props.activeIndex, (n: any) => {
if (settingStore.showPanel) {
scrollViewToCenter(n)
}
})
watch(() => props.isActive, (n: boolean) => {
setTimeout(() => {
if (n) scrollViewToCenter(props.activeIndex)
}, 300)
})
//
// watch(() => props.activeIndex, (n: any) => {
// if (settingStore.showPanel) {
// scrollViewToCenter(n)
// }
// })
//
// watch(() => props.isActive, (n: boolean) => {
// setTimeout(() => {
// if (n) scrollViewToCenter(props.activeIndex)
// }, 300)
// })
// watch(() => props.list, () => {
// listRef.scrollTo(0, 0)
@@ -61,6 +67,12 @@ function scrollToItem(index: number) {
listRef.scrollToItem(index)
}
function itemIsActive(item: any, index: number) {
return props.activeId ?
props.activeId === item.id
: props.activeIndex === index
}
defineExpose({scrollToBottom, scrollToItem})
</script>
@@ -83,24 +95,17 @@ defineExpose({scrollToBottom, scrollToItem})
>
<div class="list-item-wrapper">
<div class="common-list-item"
:class="{active:activeIndex === index}"
@click="emit('click',{data:item,index})"
:class="{active:itemIsActive(item,index)}"
@click="emit('click',{item,index})"
>
<div class="left">
<slot name="prefix" :word="item" :index="index"></slot>
<slot name="prefix" :item="item" :index="index"></slot>
<div class="title-wrapper">
<div class="item-title">
<span class="word" :class="!showWord && 'text-shadow'">{{ item.name }}</span>
<span class="phonetic">{{ item.usphone }}</span>
<VolumeIcon class="volume" @click="playWordAudio(item.name)"></VolumeIcon>
</div>
<div class="item-sub-title" v-if="item.trans.length && showTranslate">
<div v-for="tran in item.trans">{{ tran }}</div>
</div>
<slot :item="item" :index="index"></slot>
</div>
</div>
<div class="right">
<slot :word="item" :index="index"></slot>
<slot name="suffix" :item="item" :index="index"></slot>
</div>
</div>
</div>
@@ -113,7 +118,7 @@ defineExpose({scrollToBottom, scrollToItem})
@import "@/assets/css/variable";
.scroller {
height: 100%;
flex: 1;
padding: 0 var(--space);
}

View File

@@ -20,6 +20,7 @@ import {useSettingStore} from "@/stores/setting.ts";
import ArticleList2 from "@/components/list/ArticleList2.vue";
import BaseIcon from "@/components/BaseIcon.vue";
import {useArticleOptions} from "@/hooks/dict.ts";
import ArticleList4 from "@/components/list2/ArticleList4.vue";
const store = useBaseStore()
const practiceStore = usePracticeStore()
@@ -109,7 +110,7 @@ function getCurrentPractice() {
renewSectionTexts(tempArticle)
tempArticle.useTranslateType = TranslateType.none
setArticle(tempArticle)
},
}, null,
{
confirmButtonText: '去编辑',
cancelButtonText: '不需要翻译',
@@ -128,7 +129,7 @@ function getCurrentPractice() {
renewSectionTexts(tempArticle)
tempArticle.useTranslateType = TranslateType.none
setArticle(tempArticle)
},
}, null,
{
confirmButtonText: '去编辑',
cancelButtonText: '不需要翻译',
@@ -274,7 +275,29 @@ const {
{{ store.currentDict.articles.length }}篇文章
</div>
</div>
<ArticleList4
v-if="true"
:isActive="active"
:show-translate="settingStore.translate"
:active-id="articleData.article.id"
:list="store.currentDict.articles">
<template v-slot:suffix="{item,index}">
<BaseIcon
v-if="!isArticleCollect(item)"
class-name="collect"
@click="toggleArticleCollect(item)"
title="收藏" icon="ph:star"/>
<BaseIcon
v-else
class-name="fill"
@click="toggleArticleCollect(item)"
title="取消收藏" icon="ph:star-fill"/>
</template>
</ArticleList4>
<ArticleList2
v-else
:isActive="active"
:show-translate="settingStore.translate"
@select-item="changePracticeArticle"

View File

@@ -154,7 +154,6 @@ export const useBaseStore = defineStore('base', {
}
return [
DictType.article,
DictType.customArticle
].includes(this.currentDict.type)
},
currentDict(): Dict {