fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createApp, defineComponent } from "vue"
import Application from "./App.vue"
import MarsUIInstall from "@mars/components/mars-ui"
import { injectState, getInjectKey } from "@mars/widgets/common/store/widget"
import { getExampleId, getQueryString } from "@mars/utils/mars-util"
import { cloneDeep } from "lodash"
import store from "@mars/widgets/widget-store"
import { Editor as MarsgisEditor } from "@marsgis/editor"
import "@marsgis/editor/dist/style.css"
 
// https跳转处理
const protocol = window.location.protocol
if (protocol === "https:") {
  window.location.href = window.location.href.replace("https", "http")
}
document.oncontextmenu = function (e) {
  e.preventDefault()
}
 
const marsEditor = new MarsgisEditor({
  baseUrl: process.env.BASE_URL,
  code: getQueryString("code"),
  configLibs: window.configLibs,
  resourcePublicPath: process.env.EXAMPLE_SOURCE_PATH,
  thumbnailPublicPath: "/config/",
  libPublicPath: "/lib/",
  framework: "vue",
  configSourceUrl: `${process.env.BASE_URL}config/example.json`,
  UIFile: "{main}/index.vue"
})
window.marsEditor = marsEditor
 
let inited = false
marsEditor.on("loaded", (exampleConfig) => {
  if (inited) {
    destoryUI()
  }
  initUI(!exampleConfig.hasPannel)
  inited = true
})
 
let vueApp
 
function initUI(simple: boolean) {
  if (simple) {
    vueApp = createApp(
      defineComponent({
        template: "<div><div>"
      })
    )
  } else {
    vueApp = createApp(Application)
    const key = getInjectKey()
 
    vueApp.use(injectState(cloneDeep(store)), key)
  }
 
  MarsUIInstall(vueApp, {
    dialog: {
      position: {
        left: 50,
        bottom: 50
      }
    }
  })
 
  vueApp.mount("#mars-main-view")
}
 
function destoryUI() {
  vueApp.unmount()
  vueApp = null
}
 
marsEditor.render(document.getElementById("root"), getExampleId(), getQueryString("name"))