contents-pos.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { acceptHMRUpdate, defineStore } from 'pinia';
  2. interface ContentsPosition {
  3. [key: string]: any;
  4. /**
  5. * 定位方式
  6. */
  7. position: 'static' | 'fixed' | 'absolute' | 'relative' | 'sticky';
  8. /**
  9. * 顶部位置
  10. */
  11. top: string;
  12. /**
  13. * 左侧位置
  14. */
  15. left: string;
  16. /**
  17. * 宽
  18. */
  19. width: string;
  20. /**
  21. * 左边距
  22. */
  23. paddingLeft: string;
  24. }
  25. /**
  26. * @zh_CN 用户信息相关
  27. */
  28. export const useContentsPositionStore = defineStore('contents-position', {
  29. actions: {
  30. setPosition(position: 'static' | 'fixed' | 'absolute' | 'relative' | 'sticky') {
  31. this.position = position;
  32. },
  33. setTop(top: string) {
  34. this.top = top;
  35. },
  36. setLeft(left: string) {
  37. this.left = left;
  38. },
  39. setWidth(width: string) {
  40. this.width = width;
  41. },
  42. setPaddingLeft(paddingLeft: string) {
  43. this.paddingLeft = paddingLeft;
  44. },
  45. },
  46. state: (): ContentsPosition => ({
  47. position: 'static',
  48. top: 'unset',
  49. left: 'unset',
  50. width: '100%',
  51. paddingLeft: '0',
  52. }),
  53. });
  54. // 解决热更新问题
  55. const hot = import.meta.hot;
  56. if (hot) {
  57. hot.accept(acceptHMRUpdate(useContentsPositionStore, hot));
  58. }