sys.ts 804 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { defineStore } from 'pinia'
  2. interface SysState {
  3. /**
  4. * 搜索历史
  5. */
  6. searchHistory: string[]
  7. }
  8. export const useSysChargeStore = defineStore('system-charge', {
  9. state: (): SysState => ({
  10. searchHistory: [],
  11. }),
  12. actions: {
  13. /**
  14. * 获取搜索历史
  15. */
  16. getSearchHistory() {
  17. },
  18. /**
  19. * 添加到搜索历史
  20. * @param keyword 搜索关键词
  21. */
  22. addToSearchHistory(keyword: string) {
  23. if (keyword && !this.searchHistory.includes(keyword)) {
  24. this.searchHistory.unshift(keyword)
  25. if (this.searchHistory.length > 10) {
  26. this.searchHistory = this.searchHistory.slice(0, 10)
  27. }
  28. }
  29. },
  30. /**
  31. * 清空搜索历史
  32. */
  33. clearSearchHistory() {
  34. this.searchHistory = []
  35. },
  36. },
  37. })