feat: 移除对智慧分词的支持 减小插件体积 改为跳转插件

This commit is contained in:
ZiuChen 2022-09-12 12:16:40 +08:00
parent 99edbaa907
commit 09468449fe

View File

@ -7,15 +7,10 @@
<div
class="clip-full-operate-list-item"
v-if="
(id !== 'word-split' && id !== 'copy-select' && id !== 'clear-select') ||
id !== 'word-split' ||
(id === 'word-split' &&
fullData.type !== 'file' &&
fullData?.data?.length <= '\u0035\u0030\u0030' &&
splitWords.length === 0) ||
(id === 'copy-select' &&
splitWords.filter((item) => item.checked !== false).length !== 0) ||
(id === 'clear-select' &&
splitWords.filter((item) => item.checked !== false).length !== 0)
fullData?.data?.length <= '\u0035\u0030\u0030')
"
@click="handleBtnClick(id)"
>
@ -29,10 +24,6 @@
<div v-else-if="fullData.type === 'file'" class="clip-full-content">
<FileList :data="JSON.parse(fullData.data)"></FileList>
</div>
<ClipWordBreak
v-if="fullData.type === 'text' && splitWords.length !== 0"
:words="splitWords"
></ClipWordBreak>
</div>
</Transition>
<div class="clip-overlay" v-show="isShow" @click="onOverlayClick"></div>
@ -41,8 +32,7 @@
<script setup>
import FileList from './FileList.vue'
import ClipWordBreak from './ClipWordBreak.vue'
import { ref, onMounted } from 'vue'
import { onMounted } from 'vue'
const props = defineProps({
isShow: {
@ -65,19 +55,9 @@ const btns = [
{
id: 'word-split',
name: '🎁 智慧分词'
},
{
id: 'copy-select',
name: '📑 复制选中'
},
{
id: 'clear-select',
name: '💣 清空选中'
}
]
const splitWords = ref([])
const handleBtnClick = (id) => {
switch (id) {
case 'copy-all':
@ -86,71 +66,14 @@ const handleBtnClick = (id) => {
window.toTop()
break
case 'word-split':
fetchWordBreakResult(props.fullData.data)
break
case 'copy-select':
const checkedList = splitWords.value.filter((item) => item.checked !== false)
if (checkedList.length !== 0) {
window.copy({
type: 'text',
data: checkedList.map((item) => item.value).join('')
})
emit('onOverlayClick')
window.toTop()
} else {
window.showNotify('尚未选中任何内容')
}
break
case 'clear-select':
splitWords.value.map((item) => (item.checked = false))
utools.redirect('超级分词', props.fullData.data)
// fetchWordBreakResult(props.fullData.data)
break
}
}
const fetchUserInfo = async () => {
return window.fetchToken().then(({ token, expired_at }) => {
return {
token,
expired_at
}
})
}
const fetchWordBreakResult = async (origin) => {
const baseUrl = 'https://service-nlkfov43-1304937021.sh.apigw.tencentcs.com/release'
// const baseUrl = 'http://localhost:9000'
const url = baseUrl + '/v1/word-break'
const info = await fetchUserInfo()
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
domain: 'clipboard-manager',
word: origin,
...info
})
})
.then((res) => res.json())
.then(({ code, data, msg }) => {
if (code !== 0) {
window.showNotify(msg)
} else {
//
splitWords.value = data.splitWord
.filter((w) => w !== '' && w !== ' ' && w.indexOf('\n') === -1)
.map((item) => ({
value: item,
checked: false
}))
}
})
}
const onOverlayClick = () => {
emit('onOverlayClick')
splitWords.value = []
}
onMounted(() => {