Commit 25c76511 by luyt

other:调整代码编辑器格式化方式

1 parent f29ce9b7
// Generated by 'unplugin-auto-import' // Generated by 'unplugin-auto-import'
// We suggest you to commit this file into source control // We suggest you to commit this file into source control
declare global { declare global {
const ElButton: typeof import("element-plus/es")["ElButton"]; const ElButton: typeof import('element-plus/es')['ElButton']
const ElCard: typeof import("element-plus/es")["ElCard"]; const ElCard: typeof import('element-plus/es')['ElCard']
const ElCol: typeof import("element-plus/es")["ElCol"]; const ElCol: typeof import('element-plus/es')['ElCol']
const ElDialog: typeof import("element-plus/es")["ElDialog"]; const ElDialog: typeof import('element-plus/es')['ElDialog']
const ElDropdown: typeof import("element-plus/es")["ElDropdown"]; const ElDropdown: typeof import('element-plus/es')['ElDropdown']
const ElDropdownItem: typeof import("element-plus/es")["ElDropdownItem"]; const ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
const ElDropdownMenu: typeof import("element-plus/es")["ElDropdownMenu"]; const ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
const ElForm: typeof import("element-plus/es")["ElForm"]; const ElForm: typeof import('element-plus/es')['ElForm']
const ElFormItem: typeof import("element-plus/es")["ElFormItem"]; const ElFormItem: typeof import('element-plus/es')['ElFormItem']
const ElInput: typeof import("element-plus/es")["ElInput"]; const ElInput: typeof import('element-plus/es')['ElInput']
const ElOption: typeof import("element-plus/es")["ElOption"]; const ElOption: typeof import('element-plus/es')['ElOption']
const ElRow: typeof import("element-plus/es")["ElRow"]; const ElRow: typeof import('element-plus/es')['ElRow']
const ElSelect: typeof import("element-plus/es")["ElSelect"]; const ElSelect: typeof import('element-plus/es')['ElSelect']
const ElTable: typeof import("element-plus/es")["ElTable"]; const ElTable: typeof import('element-plus/es')['ElTable']
const ElTableColumn: typeof import("element-plus/es")["ElTableColumn"]; const ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
} }
export {}; export {}
// generated by unplugin-vue-components // generated by unplugin-vue-components
// We suggest you to commit this file into source control // We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/vue-next/pull/3399 // Read more: https://github.com/vuejs/vue-next/pull/3399
import "@vue/runtime-core"; import '@vue/runtime-core'
declare module "@vue/runtime-core" { declare module '@vue/runtime-core' {
export interface GlobalComponents { export interface GlobalComponents {
AceEditor: typeof import("./src/components/AceEditor.vue")["default"]; AceEditor: typeof import('./src/components/AceEditor.vue')['default']
AddButton: typeof import("./src/components/AddButton.vue")["default"]; AddButton: typeof import('./src/components/AddButton.vue')['default']
BackButton: typeof import("./src/components/BackButton.vue")["default"]; BackButton: typeof import('./src/components/BackButton.vue')['default']
ElButton: typeof import("element-plus/es")["ElButton"]; ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import("element-plus/es")["ElCard"]; ElCard: typeof import('element-plus/es')['ElCard']
ElCol: typeof import("element-plus/es")["ElCol"]; ElCol: typeof import('element-plus/es')['ElCol']
ElDialog: typeof import("element-plus/es")["ElDialog"]; ElDialog: typeof import('element-plus/es')['ElDialog']
ElDropdown: typeof import("element-plus/es")["ElDropdown"]; ElDropdown: typeof import('element-plus/es')['ElDropdown']
ElDropdownItem: typeof import("element-plus/es")["ElDropdownItem"]; ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
ElDropdownMenu: typeof import("element-plus/es")["ElDropdownMenu"]; ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
ElForm: typeof import("element-plus/es")["ElForm"]; ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import("element-plus/es")["ElFormItem"]; ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElInput: typeof import("element-plus/es")["ElInput"]; ElInput: typeof import('element-plus/es')['ElInput']
ElOption: typeof import("element-plus/es")["ElOption"]; ElOption: typeof import('element-plus/es')['ElOption']
ElRow: typeof import("element-plus/es")["ElRow"]; ElRow: typeof import('element-plus/es')['ElRow']
ElSelect: typeof import("element-plus/es")["ElSelect"]; ElSelect: typeof import('element-plus/es')['ElSelect']
ElTable: typeof import("element-plus/es")["ElTable"]; ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import("element-plus/es")["ElTableColumn"]; ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
HelloWorld: typeof import("./src/components/HelloWorld.vue")["default"]; HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
RouterLink: typeof import("vue-router")["RouterLink"]; RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import("vue-router")["RouterView"]; RouterView: typeof import('vue-router')['RouterView']
} }
} }
export {}; export {}
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"axios": "^0.27.2", "axios": "^0.27.2",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"element-plus": "^2.1.11", "element-plus": "^2.1.11",
"js-beautify": "^1.14.3",
"qs": "^6.10.3", "qs": "^6.10.3",
"vue": "^3.2.13", "vue": "^3.2.13",
"vue-router": "^4.0.3", "vue-router": "^4.0.3",
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.1", "@types/jest": "^27.0.1",
"@types/js-beautify": "^1.13.3",
"@typescript-eslint/eslint-plugin": "^5.4.0", "@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0", "@typescript-eslint/parser": "^5.4.0",
"@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-babel": "~5.0.0",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import beautify_js from "js-beautify";
import { defineComponent, nextTick, onMounted, PropType, ref } from "vue"; import { defineComponent, nextTick, onMounted, PropType, ref } from "vue";
export default defineComponent({ export default defineComponent({
name: "AceEditor", name: "AceEditor",
...@@ -22,12 +23,18 @@ export default defineComponent({ ...@@ -22,12 +23,18 @@ export default defineComponent({
const editorRef = ref(); const editorRef = ref();
// let beautify: any; // let beautify: any;
const codeFormat = () => { const codeFormat = () => {
const formatCode = beautify_js(editorRef.value.getValue());
editorRef.value.session.setValue(formatCode);
// 1
// beautify.beautify(editorRef.value.session); // beautify.beautify(editorRef.value.session);
// ace beautify 格式化不完全 使用浏览器内置的json格式化程序 // ace beautify 格式化不完全 使用浏览器内置的json格式化程序
var val = editorRef.value.getValue();
var o = JSON.parse(val); // may throw if json is malformed // 2
val = JSON.stringify(o, null, 2); // 4 is the indent size // var val = editorRef.value.getValue();
editorRef.value.session.setValue(val); // var o = JSON.parse(val); // may throw if json is malformed
// val = JSON.stringify(o, null, 2); // 4 is the indent size
// editorRef.value.session.setValue(val);
}; };
// 获取内容 // 获取内容
const getCode = () => { const getCode = () => {
......
...@@ -4,6 +4,12 @@ declare module '*.vue' { ...@@ -4,6 +4,12 @@ declare module '*.vue' {
const component: DefineComponent<{}, {}, any> const component: DefineComponent<{}, {}, any>
export default component export default component
} }
declare module 'js-beautify' {
// beautify_js:any
const beautify_js:(a:any) => any
export default beautify_js
}
// declare var beautify_js:any
// declare var ace:any // declare var ace:any
interface Window { interface Window {
ace: any, ace: any,
......
...@@ -1502,6 +1502,11 @@ ...@@ -1502,6 +1502,11 @@
"jest-matcher-utils" "^27.0.0" "jest-matcher-utils" "^27.0.0"
"pretty-format" "^27.0.0" "pretty-format" "^27.0.0"
"@types/js-beautify@^1.13.3":
"integrity" "sha512-ucIPw5gmNyvRKi6mpeojlqp+T+6ZBJeU+kqMDnIEDlijEU4QhLTon90sZ3cz9HZr+QTwXILjNsMZImzA7+zuJA=="
"resolved" "https://registry.npmjs.org/@types/js-beautify/-/js-beautify-1.13.3.tgz"
"version" "1.13.3"
"@types/json-schema@*", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9": "@types/json-schema@*", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9":
"integrity" "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==" "integrity" "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ=="
"resolved" "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.11.tgz" "resolved" "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.11.tgz"
...@@ -5369,9 +5374,9 @@ ...@@ -5369,9 +5374,9 @@
"@sideway/formula" "^3.0.0" "@sideway/formula" "^3.0.0"
"@sideway/pinpoint" "^2.0.0" "@sideway/pinpoint" "^2.0.0"
"js-beautify@^1.6.12": "js-beautify@^1.14.3", "js-beautify@^1.6.12":
"integrity" "sha512-f1ra8PHtOEu/70EBnmiUlV8nJePS58y9qKjl4JHfYWlFH6bo7ogZBz//FAZp7jDuXtYnGYKymZPlrg2I/9Zo4g==" "integrity" "sha512-f1ra8PHtOEu/70EBnmiUlV8nJePS58y9qKjl4JHfYWlFH6bo7ogZBz//FAZp7jDuXtYnGYKymZPlrg2I/9Zo4g=="
"resolved" "https://registry.npmmirror.com/js-beautify/-/js-beautify-1.14.3.tgz" "resolved" "https://registry.npmjs.org/js-beautify/-/js-beautify-1.14.3.tgz"
"version" "1.14.3" "version" "1.14.3"
dependencies: dependencies:
"config-chain" "^1.1.13" "config-chain" "^1.1.13"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!