Commit a60e6ba1 by 1127071993@qq.com

feat:1.排查处理web编辑器在v-modle的模式下输入后,无法再次输入的问题

2.添加expose暴露子组件方法格式化提供父组件调用
3.添加校验web编辑器的内容的功能,以及保存时候的成功失败提示信息
4.添加变价内容格式化功能,保存按钮功能
5.添加编辑器清楚功能
1 parent 5534f2aa
window.onerror = function (message, source, lineno, colno, error) {
console.log("arguments", arguments);
console.log("message", message);
console.log("source", source);
console.log("lineno", lineno);
console.log("colno", colno);
console.log("error", error);
window.aceError = arguments;
return true;
};
// window.onerror = function (message, source, lineno, colno, error) {
// console.log("arguments", arguments);
// console.log("message", message);
// console.log("source", source);
// console.log("lineno", lineno);
// console.log("colno", colno);
// console.log("error", error);
// window.aceError = arguments;
// return true;
// };
......@@ -13,10 +13,11 @@
}
html,
body {
// height: 100%;
height: 100%;
// min-height: 100%;
}
#app {
height: 100%;
// min-height: 100%;
}
</style>
<template>
<div>
<div id="editor"></div>
<el-button @click="codeFormat">格式化代码</el-button>
<el-button @click="getCode">获取内容</el-button>
<div id="editor" :style="{ height: winHeight + 'px' }"></div>
<!-- <el-button @click="codeFormat">格式化代码</el-button>
<el-button @click="getCode">获取内容</el-button> -->
</div>
</template>
......@@ -13,11 +13,12 @@ export default defineComponent({
props: {
content: {
type: String as PropType<string>, //转为ts类型
default: "{name: 'jack', age: '20'}",
default: "",
},
},
emits: ["update:content"],
setup(props, { emit, expose }) {
const winHeight = ref<number>();
const editorRef = ref();
let beautify: any;
const codeFormat = () => {
......@@ -26,16 +27,27 @@ export default defineComponent({
// 获取内容
const getCode = () => {
const content = editorRef.value.getValue();
console.log("content: ", content);
// console.log("content: ", content);
emit("update:content", content);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// const contentObj = eval("(" + content + ")");
};
//清空输入
const setValue = () => {
editorRef.value.setValue("");
};
// 获取浏览器窗口的可视区域的高度
const getViewPortHeight = () => {
return (
document.documentElement.clientHeight || document.body.clientHeight
);
};
winHeight.value = getViewPortHeight();
expose({
codeFormat,
getCode,
setValue,
});
onMounted(() => {
......@@ -76,11 +88,15 @@ export default defineComponent({
getCode();
});
}
//设置web编辑器内容
// console.log(editorRef.value);
editorRef.value.setValue(props.content);
});
return {
codeFormat,
getCode,
winHeight,
};
},
});
......@@ -88,8 +104,9 @@ export default defineComponent({
<style lang="scss">
#editor {
// width: 500px;
width: 100%;
height: 400px;
// width: 100%;
// height: 920px;
// height: 400px;
.ace_print-margin {
// display: none;
}
......
......@@ -4,10 +4,10 @@ import HomeView from "../views/HomeView.vue";
const routes: Array<RouteRecordRaw> = [
{
path: "/",
redirect: "/addapi",
redirect: "/project",
},
{
path: "/",
path: "/home",
name: "home",
component: HomeView,
},
......
......@@ -52,6 +52,7 @@ export default defineComponent({
remark: "",
});
//获取路由参数
let routerParams = route.params;
let keysLength = Object.keys(routerParams).length;
if (keysLength > 0) {
......
......@@ -9,7 +9,7 @@
<div class="name">methods</div>
<div class="wrap">
<el-select
v-model="methodsVal"
v-model="methods"
class="m-2"
placeholder="Select type methods"
>
......@@ -36,22 +36,39 @@
<el-input v-model="remark" placeholder="请输入描述"> </el-input>
</div>
</div>
<div class="option">
<div class="name">操作</div>
<div class="wrap">
<el-button type="primary" @click="beautifulCodeFn"
>美化代码</el-button
>
<el-button type="info" @click="saveCodeFn">保存代码</el-button>
<el-button type="danger" @click="clearCodeFn">清空代码</el-button>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, watch } from "vue";
import { defineComponent, ref } from "vue";
import AceEditor from "@/components/AceEditor.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import "element-plus/theme-chalk/el-message.css";
import "element-plus/theme-chalk/el-message-box.css";
import { useRoute } from "vue-router";
export default defineComponent({
name: "AddApi",
setup() {
const editorDom = ref(null);
//获取路由对象
const route = useRoute();
const editorDom = ref();
const editorContent = ref("123");
const remark = ref("");
const url = ref("");
const methodsVal = ref("");
const methods = ref("");
const methodsOptions = [
{
value: "get",
......@@ -74,17 +91,72 @@ export default defineComponent({
label: "patch",
},
];
watch(editorContent, (newVal, prevCount) => {
console.log("newVal: ", newVal);
// console.log("prevCount: ", prevCount);
});
//获取路由参数
let routerParams = route.params;
editorContent.value = routerParams.content as string;
remark.value = routerParams.remark as string;
url.value = routerParams.url as string;
methods.value = routerParams.methods as string;
// 格式化代码
const beautifulCodeFn = () => {
editorDom.value?.codeFormat();
};
//保存代码
const saveCodeFn = () => {
// 校验代码的有效性
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const contentObj = eval("(" + editorContent.value + ")");
ElMessage({
type: "success",
message: "保存成功",
});
// 发提交请求
} catch (error) {
// console.log(window.aceError);
ElMessage({
message: error as string,
type: "error",
});
}
};
//清空代码
const clearCodeFn = () => {
ElMessageBox.confirm("您确定要删除吗?", "Warning", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
editorDom.value?.setValue();
ElMessage({
type: "success",
message: "删除成功",
});
})
.catch(() => {
ElMessage({
type: "info",
message: "取消删除",
});
});
};
// watch(editorContent, (newVal, prevCount) => {
// console.log("newVal: ", newVal);
// // console.log("prevCount: ", prevCount);
// });
return {
methodsOptions,
methodsVal,
methods,
remark,
url,
editorContent,
editorDom,
beautifulCodeFn,
saveCodeFn,
clearCodeFn,
};
},
components: {
......@@ -96,6 +168,7 @@ export default defineComponent({
<style lang="scss">
.add-api {
display: flex;
height: 100%;
.lf-content {
flex: 1;
background: #282c34;
......
<template>
<div class="api-list">
<h3>test 测试环境项目</h3>
<el-table border :data="tableData" style="width: 100%">
<el-table border :data="tableData" stripe style="width: 100%">
<el-table-column prop="methods" label="methods" />
<el-table-column prop="url" label="url" />
<el-table-column prop="remark" label="remark" />
<el-table-column label="操作">
<template #default="scope">
<el-button text size="small" @click.prevent="editorRow(scope.$index)">
<el-button text size="small" @click.prevent="editorRow(scope.row)">
编辑
</el-button>
<el-button text size="small" @click.prevent="deleteRow(scope.$index)">
......@@ -28,8 +28,10 @@ import "element-plus/theme-chalk/el-message-box.css";
import router from "@/router";
interface EditorRow {
id: string;
methods: string;
url: string;
content: string;
remark: string;
}
......@@ -38,18 +40,24 @@ export default {
setup() {
const tableData = ref([
{
id: "",
methods: "get",
url: "/baseurl",
url: "baseurl",
content: "huwei",
remark: "California remark",
},
{
id: "",
methods: "post",
url: "/baseurl",
url: "baseurl",
content: "wejhgnv87",
remark: "California remark",
},
{
id: "",
methods: "get",
url: "/baseurl",
url: "baseurl",
content: "{name: 'jack', age: '20'}",
remark: "California remark",
},
]);
......@@ -65,6 +73,7 @@ export default {
};
const editorRow = (editorRow: EditorRow) => {
console.log("editorRow: ", editorRow);
addFn(false, editorRow);
};
const deleteRow = (editorRow: EditorRow) => {
console.log("editorRow: ", editorRow);
......@@ -74,6 +83,8 @@ export default {
type: "warning",
})
.then(() => {
//删除接口
ElMessage({
type: "success",
message: "删除成功",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!