xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 <!DOCTYPE html>
X 2 <html lang="zh">
3   <head>
4     <meta charset="utf-8">
5     <meta http-equiv="X-UA-Compatible" content="IE=edge">
6     <meta name="viewport" content="width=device-width,initial-scale=1.0">
7     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
8     <title>form-generator-preview</title>
9     <link href="https://lib.baomitu.com/element-ui/2.13.2/theme-chalk/index.css" rel="stylesheet">
10     <script src="https://lib.baomitu.com/vue/2.6.11/vue.min.js"></script>
11     <script src="https://lib.baomitu.com/vue-router/3.1.3/vue-router.min.js"></script>
12     <script src="https://lib.baomitu.com/axios/0.19.2/axios.min.js"></script>
13     <script src="https://lib.baomitu.com/element-ui/2.13.2/index.js"></script>
14     <style>
15       body{
16         margin: 0;
17         padding: 0;
18         overflow-x: hidden;
19         -moz-osx-font-smoothing: grayscale;
20         -webkit-font-smoothing: antialiased;
21         text-rendering: optimizeLegibility;
22         height: calc(100vh - 33px);
23         padding: 12px;
24         box-sizing: border-box;
25         font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;
26       }
27       input, textarea{
28         font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;
29       }
30     </style>
31   </head>
32   <body>
33     <noscript>
34       <strong>抱歉,javascript被禁用,请开启后重试。</strong>
35     </noscript>
36     <div id="previewApp"></div>
37     <script type="text/javascript">
38       Vue.prototype.$axios = axios
39       const childAttrs = {
40         file: '',
41         dialog: ' width="600px" class="dialog-width" v-if="visible" :visible.sync="visible" :modal-append-to-body="false" '
42       }
43
44       window.addEventListener('message', init, false)
45       function init(event) {
46         if (event.data.type === 'refreshFrame') {
47           const code = event.data.data
48           const attrs = childAttrs[code.generateConf.type]
49           let links = ''
50
51           if (Array.isArray(code.links) && code.links.length > 0) {
52             links = buildLinks(code.links)
53           }
54
55           document.getElementById('previewApp').innerHTML = `${links}<style>${code.css}</style><div id="app"></div>`
56
57           if (Array.isArray(code.scripts) && code.scripts.length > 0) {
58             this.loadScriptQueue(code.scripts, () => {
59               newVue(attrs, code.js, code.html)
60             })
61           } else {
62             newVue(attrs, code.js, code.html)
63           }
64         }
65       }
66       function buildLinks(links) {
67         let strs = ''
68         links.forEach(url => {
69           strs += `<link href="${url}" rel="stylesheet">`
70         })
71         return strs
72       }
73       function newVue(attrs, main, html) {
74         main = eval(`(${main})`)
75         main.template = `<div>${html}</div>`
76         new Vue({
77           components: {
78             child: main
79           },
80           data() {
81             return {
82               visible: true
83             }
84           },
85           template: `<div><child ${attrs}/></div>`
86         }).$mount('#app')
87       }
88     </script>
89   </body>
90 </html>