main.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { defineStore } from 'pinia'
  2. import { getInfo } from '@/api/module/editor'
  3. // import { watch } from 'vue'
  4. // useStore could be anything like useUser, useCart
  5. // the first argument is a unique id of the store across your application
  6. export const useMainStore = defineStore('main', {
  7. state: () => {
  8. return {
  9. sceneCode: '',
  10. counter: 0,
  11. showDrawer: false,
  12. sceneRef: null,
  13. sceneRefWidth: 0,
  14. digitalHumanList: [],
  15. sceneLink: '',
  16. sceneMode: 'pc',
  17. sceneConfig: {
  18. message: 'verify'
  19. },
  20. basicConfig: {
  21. mode: 'pc', //true pc false mobile
  22. themes: '',
  23. autoRotate: false, //true 自动播放
  24. joystick: {
  25. show: false,
  26. position: 'left'
  27. },
  28. age: 18
  29. },
  30. sceneInfo: {},
  31. aiSetting: [],
  32. navigation: []
  33. }
  34. },
  35. getters: {
  36. sceneURL: ({ sceneLink, sceneConfig, sceneMode }) => {
  37. if (sceneLink) {
  38. console.log(
  39. sceneLink +
  40. `&mobile=${sceneMode == 'mobile' ? 'true' : 'false'}&config=` +
  41. JSON.stringify(sceneConfig || {})
  42. )
  43. return (
  44. sceneLink +
  45. `&mobile=${sceneMode == 'mobile' ? 'true' : 'false'}&config=` +
  46. JSON.stringify(sceneConfig || {})
  47. )
  48. }
  49. },
  50. count: ({ counter }) => counter,
  51. getBasicConfig: ({ basicConfig }) => basicConfig,
  52. getDigitalHumanList: ({ digitalHumanList }) => digitalHumanList,
  53. getEditorData: ({ basicConfig, aiSetting, navigation, sceneCode }) => {
  54. return {
  55. baseSetting: basicConfig,
  56. navigation: navigation,
  57. aiSetting: aiSetting,
  58. num: sceneCode
  59. }
  60. }
  61. },
  62. actions: {
  63. incrementCounter(count: number) {
  64. this.counter += count
  65. },
  66. setSceneRef(sceneRef: any) {
  67. this.sceneRef = sceneRef
  68. },
  69. setWidthSceneRef(width: number) {
  70. if (this.sceneRef) {
  71. const sceneRef = this.sceneRef as never as HTMLElement
  72. sceneRef.style.width = `calc(100% - ${width || 0}px)`
  73. }
  74. },
  75. setSceneLink(link: string) {
  76. this.sceneLink = link
  77. },
  78. setSceneMode(mode: string) {
  79. this.sceneMode = mode
  80. },
  81. setSceneConfig(config: object) {
  82. this.sceneConfig = { ...this.sceneConfig, ...config }
  83. },
  84. setSceneCode(m: string) {
  85. this.sceneCode = m
  86. },
  87. async getSceneInfo() {
  88. const data = await getInfo(this.sceneCode)
  89. console.log('data', data)
  90. this.sceneInfo = data as any as {}
  91. }
  92. }
  93. })