| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import { defineStore } from 'pinia'
- interface SysState {
- /**
- * 搜索历史
- */
- searchHistory: string[]
- }
- export const useSysChargeStore = defineStore('system-charge', {
- state: (): SysState => ({
- searchHistory: [],
- }),
- actions: {
- /**
- * 获取搜索历史
- */
- getSearchHistory() {
- },
- /**
- * 添加到搜索历史
- * @param keyword 搜索关键词
- */
- addToSearchHistory(keyword: string) {
- if (keyword && !this.searchHistory.includes(keyword)) {
- this.searchHistory.unshift(keyword)
- if (this.searchHistory.length > 10) {
- this.searchHistory = this.searchHistory.slice(0, 10)
- }
- }
- },
- /**
- * 清空搜索历史
- */
- clearSearchHistory() {
- this.searchHistory = []
- },
- },
- })
|