122 lines
2.6 KiB
TypeScript
122 lines
2.6 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
|
|
export interface SearchInfo {
|
|
name: string
|
|
icon: string
|
|
url: string
|
|
show: boolean
|
|
}
|
|
|
|
const defaultSearchList: SearchInfo[] = [
|
|
{
|
|
name: '百度',
|
|
url: 'https://www.baidu.com/s?wd=',
|
|
icon: 'tab/searchIcons/baidu.png',
|
|
show: true
|
|
},
|
|
{
|
|
name: '必应',
|
|
url: 'https://cn.bing.com/search?q=',
|
|
icon: 'tab/searchIcons/bing.png',
|
|
show: true
|
|
},
|
|
{
|
|
name: '谷歌',
|
|
url: 'https://www.google.com/search?q=',
|
|
icon: 'tab/searchIcons/google.png',
|
|
show: true
|
|
},
|
|
{
|
|
name: '360',
|
|
url: 'https://www.so.com/s?q=',
|
|
icon: 'tab/searchIcons/360.png',
|
|
show: true
|
|
}
|
|
|
|
|
|
]
|
|
|
|
const defaultCustomSearchList: SearchInfo[] = [
|
|
|
|
|
|
]
|
|
// const defaultCustomSearchList: SearchInfo[] = [
|
|
// {
|
|
// name: '知乎',
|
|
// url: 'https://www.zhihu.com/search?type=content&q=',
|
|
// icon: 'searchIcons/zhihu.svg',
|
|
// show: true
|
|
// },
|
|
// {
|
|
// name: 'GitHub',
|
|
// url: 'https://github.com/search?q=',
|
|
// icon: 'searchIcons/GitHub.svg',
|
|
// show: true
|
|
// },
|
|
// {
|
|
// name: 'F搜',
|
|
// url: 'https://fsoufsou.com/search?q=',
|
|
// icon: 'searchIcons/F.svg',
|
|
// show: true
|
|
// },
|
|
// {
|
|
// name: '豆瓣',
|
|
// url: 'https://www.douban.com/search?q=',
|
|
// icon: 'searchIcons/douban.svg',
|
|
// show: true
|
|
// },
|
|
// {
|
|
// name: 'Yandex',
|
|
// url: 'https://yandex.com/search/?text=',
|
|
// icon: 'searchIcons/yandex.svg',
|
|
// show: true
|
|
// },
|
|
// {
|
|
// name: '开发者',
|
|
// url: 'https://kaifa.baidu.com/searchPage?wd=',
|
|
// icon: 'searchIcons/kaifa.svg',
|
|
// show: true
|
|
// },
|
|
// {
|
|
// name: 'B站',
|
|
// url: 'https://search.bilibili.com/all?keyword=',
|
|
// icon: 'searchIcons/bilibili.svg',
|
|
// show: true
|
|
// }
|
|
// ]
|
|
export default defineStore(
|
|
'searchConfig',
|
|
() => {
|
|
const current = ref({ ...defaultSearchList[0] })
|
|
const defaultList = ref(defaultSearchList)
|
|
const customList = ref(defaultCustomSearchList)
|
|
const history = ref<string[]>([])
|
|
const addHistory = (str: string) => {
|
|
history.value.unshift(str)
|
|
if (history.value.length > 10) {
|
|
history.value.pop()
|
|
}
|
|
}
|
|
const removeHistory = (idx: number) => {
|
|
history.value.splice(idx, 1)
|
|
}
|
|
const selectSearchByName = (name: string) => {
|
|
const search = defaultList.value.find((item) => item.name === name)
|
|
if (search) {
|
|
current.value = search
|
|
}
|
|
}
|
|
return {
|
|
current,
|
|
customList,
|
|
defaultList,
|
|
history,
|
|
addHistory,
|
|
removeHistory,
|
|
selectSearchByName
|
|
}
|
|
},
|
|
{ persist: true }
|
|
)
|