search.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import '@/utils/objects'
  2. import { defineStore } from 'pinia'
  3. export const searchStore = defineStore({
  4. id: 'search',
  5. state: () => ({
  6. active: false,
  7. hotkey: {
  8. open: 's',
  9. close: 'esc'
  10. },
  11. pool: []
  12. }),
  13. getters: {},
  14. actions: {
  15. toggleActive() {
  16. this.active = !this.active
  17. },
  18. setActive(active) {
  19. this.active = active
  20. },
  21. init(menu) {
  22. const pool = []
  23. const getFullName = function (meta) {
  24. if (meta.breadcrumb) {
  25. let list = []
  26. meta.breadcrumb.forEach((item) => {
  27. list.push(item.meta.title)
  28. })
  29. return list.join(' / ')
  30. }
  31. return meta.title
  32. }
  33. const push = function (menu) {
  34. menu.forEach((m) => {
  35. if ('menu' === m.meta.type) {
  36. if (m.children) {
  37. push(m.children)
  38. } else if (m.children === null) {
  39. pool.push({
  40. icon: m.meta.icon,
  41. path: m.path,
  42. fullPath: m.path,
  43. name: m.meta.title,
  44. fullName: getFullName(m.meta),
  45. namePinyin: m.meta.title.toPinyin(),
  46. namePinyinFirst: m.meta.title.toPinyin(true)
  47. })
  48. }
  49. }
  50. })
  51. }
  52. push(menu)
  53. this.pool = pool
  54. }
  55. }
  56. })