-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
169 lines (160 loc) · 5.15 KB
/
index.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<!-- import CSS -->
<title>Vue SFC 转换工具</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./static/css/index.css" />
<link rel="stylesheet" href="./static/css/recet.css" />
<link rel="stylesheet" href="./static/editor/codemirror.css" />
<link rel="stylesheet" href="./static/editor/theme_material-palenight.css" />
<link rel="stylesheet" href="./static/css/editor.css" />
<script src="./static/js/vue.js"></script>
<script src="./static/js/index.js"></script>
<link rel="stylesheet" href="./static/css/element-theme-2.7.0.min.css" />
<!-- <script src="static/js/tool.js"></script> -->
<script src="./static/js/vue-template-compiler@2.7.14_browser.js"></script>
<script src="./static/editor/codemirror.min.js"></script>
<script src="./static/editor/mode_javascript_javascript.js"></script>
</head>
<body>
<div id="app">
<div>
<el-row class="p-4" :gutter="20">
<h2 class="page-title">Vue SFC 转换工具 <el-button type="primary" @click="handleFile"> 选择文件 </el-button></h2>
<el-col :span="12">
<div>
<el-alert title="输入区域" type="info" :closable="false"> </el-alert>
<input v-show="false" type="file" ref="fileSelect" accept=".vue" @change="handleFileChange" />
<div id="inputEditor" spellcheck="false"></div>
<!-- <el-input v-model="inputdate" type="textarea" :autosize="{ minRows: 20, maxRows: 20 }" placeholder="请粘贴.vue文件代码到这里"></el-input> -->
<div class="my-2 text-right">
<el-button type="primary" @click="manualtoDate">转换</el-button>
</div>
</div>
</el-col>
<el-col :span="12">
<div>
<el-alert title="结果" type="info" :closable="false"></el-alert>
<!-- 代码块 -->
<div id="editor" spellcheck="false"></div>
<!-- <el-input :value="outputdate" type="textarea" :autosize="{ minRows: 20, maxRows: 20 }"></el-input> -->
<div class="my-2 text-right">
<el-button class="mr-4" type="primary" @click="copyToClipboard">复制</el-button>
</div>
</div>
</el-col>
</el-row>
</div>
</div>
<!-- Code injected by live-server -->
</body>
<script type="module">
import { convertVueSFC } from "./tool.js";
new Vue({
el: "#app",
data: function () {
return {
inputdate: "",
outputdate: "",
cssEditor: null,
codeEditor: null,
inputEditor: null,
};
},
created() {},
mounted() {
this.codeEditor = CodeMirror(editor, {
mode: {
name: "javascript",
json: true,
},
// 高度
height: "auto",
lineNumbers: true,
theme: "material-palenight",
// 自动换行
lineWrapping: true,
});
this.inputEditor = CodeMirror(inputEditor, {
mode: {
name: "javascript",
json: true,
},
// 高度
height: "auto",
lineNumbers: true,
lineWrapping: true,
theme: "material-palenight",
});
},
methods: {
// 选择文件
handleFile() {
this.$refs.fileSelect.click();
},
handleFileChange(e) {
let file = e.target.files[0];
let reader = new FileReader();
reader.readAsText(file);
reader.onload = (e) => {
console.log(e.target.result);
this.inputdate = e.target.result;
this.inputEditor.setValue(this.inputdate);
this.toDate();
this.copyToClipboard();
};
},
toDate() {
// 分割换行 转换数组
const { component, style } = convertVueSFC(this.inputdate);
this.outputdate = ` ${component}\n <style> \n ${style} \n</style> `;
this.codeEditor.setValue(this.outputdate);
},
manualtoDate() {
this.outputdate = "";
this.inputdate = this.inputEditor.getValue();
this.toDate();
},
copyToClipboard(text = this.outputdate) {
var textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("copy");
textArea.remove();
this.$message.success("复制成功!");
},
},
});
</script>
</html>
<style>
#app,
body {
background-color: #252f69;
color: #fff;
}
.page-title {
font-size: 22px;
height: 40px;
line-height: 40px;
padding: 15px 20px;
}
.top {
display: flex;
padding: 20px 10vw;
/* text-align: center; */
align-items: center;
justify-content: center;
}
.title {
text-align: center;
margin: 10px 0;
}
#inputEditor,
#editor {
height: calc(100vh - 220px);
}
</style>