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: 'searchIcons/baidu.svg', show: true }, { name: '必应', url: 'https://cn.bing.com/search?q=', icon: 'searchIcons/bing.svg', show: true }, { name: '谷歌', url: 'https://www.google.com/search?q=', icon: 'searchIcons/google.svg', show: true }, { name: '360', url: 'https://www.so.com/s?q=', icon: 'searchIcons/360.svg', show: true }, { name: '搜狗', url: 'https://www.sogou.com/sogou?&query=', icon: 'searchIcons/sougou.svg', show: true } ] 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([]) 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) } return { current, customList, defaultList, history, addHistory, removeHistory } }, { persist: true } )