defIndex.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {store} from '/@/store';
  2. import {defineStore} from 'pinia';
  3. import {defHttp} from "@/utils/http/axios";
  4. interface DefIndexState {
  5. // 首页url
  6. url: string,
  7. // 首页组件
  8. component: string
  9. }
  10. export const useDefIndexStore = defineStore({
  11. id: 'defIndex',
  12. state: (): DefIndexState => ({
  13. url: '',
  14. component: '',
  15. }),
  16. getters: {},
  17. actions: {
  18. /**
  19. * 查询默认主页配置
  20. */
  21. async query() {
  22. const config = await defIndexApi.query();
  23. this.url = config.url;
  24. this.component = config.component;
  25. },
  26. /**
  27. * 更新默认主页配置
  28. * @param url 首页url
  29. * @param component 首页组件
  30. * @param isRoute 是否是路由
  31. */
  32. async update(url: string, component: string, isRoute: boolean) {
  33. await defIndexApi.update(url, component, isRoute);
  34. await this.query()
  35. },
  36. check(url: string) {
  37. return url === this.url;
  38. }
  39. }
  40. });
  41. // Need to be used outside the setup
  42. export function useDefIndexStoreWithOut() {
  43. return useDefIndexStore(store);
  44. }
  45. /**
  46. * 默认首页配置API
  47. */
  48. export const defIndexApi = {
  49. /**
  50. * 查询默认首页配置
  51. */
  52. async query() {
  53. const url = '/sys/sysRoleIndex/queryDefIndex'
  54. return await defHttp.get({url});
  55. },
  56. /**
  57. * 更新默认首页配置
  58. * @param url 首页url
  59. * @param component 首页组件
  60. * @param isRoute 是否是路由
  61. */
  62. async update(url: string, component: string, isRoute: boolean) {
  63. let apiUrl = '/sys/sysRoleIndex/updateDefIndex'
  64. apiUrl += '?url=' + url
  65. // 代码逻辑说明: 设置默认首页接口传参修改,增加encodeURIComponent,防止{{ window._CONFIG['domianURL'] }}/**保存不上
  66. apiUrl += '&component=' + encodeURIComponent(component)
  67. apiUrl += '&isRoute=' + isRoute
  68. return await defHttp.put({url: apiUrl});
  69. },
  70. }