feat: 配置编辑器,参数比较差异
This commit is contained in:
@@ -14,7 +14,11 @@
|
||||
"dependencies": {
|
||||
"@ant-design-vue/pro-layout": "^3.2.4",
|
||||
"@ant-design/icons-vue": "^6.1.0",
|
||||
"@codemirror/lang-javascript": "^6.2.1",
|
||||
"@codemirror/merge": "^6.1.2",
|
||||
"@codemirror/theme-one-dark": "^6.1.2",
|
||||
"ant-design-vue": "^3.2.20",
|
||||
"codemirror": "^6.0.1",
|
||||
"dayjs": "^1.11.8",
|
||||
"echarts": "^5.4.2",
|
||||
"file-saver": "^2.0.5",
|
||||
@@ -23,8 +27,9 @@
|
||||
"nprogress": "^0.2.0",
|
||||
"pinia": "^2.1.4",
|
||||
"vue": "^3.3.4",
|
||||
"vue-router": "^4.2.4",
|
||||
"vue-i18n": "^9.3.0"
|
||||
"vue-codemirror": "^6.1.1",
|
||||
"vue-i18n": "^9.3.0",
|
||||
"vue-router": "^4.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/file-saver": "^2.0.5",
|
||||
|
||||
61
src/components/CodemirrorEdite/index.vue
Normal file
61
src/components/CodemirrorEdite/index.vue
Normal file
@@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<codemirror
|
||||
:model-value="modelValue"
|
||||
:placeholder="props.placeholder"
|
||||
:style="props.editorStyle"
|
||||
:disabled="props.disabled"
|
||||
:autofocus="false"
|
||||
:indent-with-tab="true"
|
||||
:tab-size="props.tabSize"
|
||||
:extensions="[javascript(), oneDark]"
|
||||
@ready="fnReady"
|
||||
@change="fnChange"
|
||||
/>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { Codemirror } from 'vue-codemirror';
|
||||
import { javascript } from '@codemirror/lang-javascript';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
import { ref } from 'vue';
|
||||
|
||||
const emit = defineEmits(['update:value']);
|
||||
const props = defineProps({
|
||||
value: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: 'input context here...',
|
||||
},
|
||||
/**是否禁止输入 */
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
editorStyle: {
|
||||
type: Object,
|
||||
default: () => ({ height: '400px !important' }),
|
||||
},
|
||||
/**缩进2空格 */
|
||||
tabSize: {
|
||||
type: Number,
|
||||
default: 2,
|
||||
},
|
||||
});
|
||||
|
||||
// 绑定值
|
||||
const modelValue = ref<string>('');
|
||||
|
||||
/**变更时更新绑定值 */
|
||||
function fnChange(value: string, viewUpdate: any) {
|
||||
emit('update:value', value);
|
||||
}
|
||||
|
||||
/**组件渲染后 */
|
||||
function fnReady(payload: any) {
|
||||
modelValue.value = props.value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
118
src/components/CodemirrorEditeDiff/index.vue
Normal file
118
src/components/CodemirrorEditeDiff/index.vue
Normal file
@@ -0,0 +1,118 @@
|
||||
<template>
|
||||
<a-modal
|
||||
:title="props.title"
|
||||
width="80%"
|
||||
:visible="props.visible"
|
||||
:body-style="{ padding: '0 24px' }"
|
||||
:destroy-on-close="true"
|
||||
@cancel="fnCronModal(false)"
|
||||
@ok="fnCronModal(true)"
|
||||
>
|
||||
<!-- style="height: 600px; color: #abb2bf; background-color: #282c34" -->
|
||||
<div ref="mergeViewContainer" class="mergeViewContainer"></div>
|
||||
</a-modal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { javascript } from '@codemirror/lang-javascript';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
import { MergeView } from '@codemirror/merge';
|
||||
import { EditorView, basicSetup } from 'codemirror';
|
||||
import { EditorState } from '@codemirror/state';
|
||||
|
||||
import { watch, ref } from 'vue';
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
const emit = defineEmits(['cancel', 'ok', 'update:visible']);
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '内容比较',
|
||||
},
|
||||
newArea: {
|
||||
type: String,
|
||||
default: '当前内容',
|
||||
},
|
||||
oldArea: {
|
||||
type: String,
|
||||
default: '原始内容',
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '400px !important',
|
||||
},
|
||||
/**是否禁止输入 */
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
const mergeViewContainer = ref();
|
||||
|
||||
/**监听是否显示,初始cron属性 */
|
||||
watch(
|
||||
() => props.visible,
|
||||
val => {
|
||||
if (val) {
|
||||
// 开启时等待dom完成
|
||||
|
||||
nextTick(() => {
|
||||
console.log(mergeViewContainer.value.style);
|
||||
// 设置高度
|
||||
mergeViewContainer.value.style.height = props.height;
|
||||
// 实例到dom
|
||||
new MergeView({
|
||||
a: {
|
||||
doc: props.newArea,
|
||||
extensions: [
|
||||
javascript(),
|
||||
oneDark,
|
||||
basicSetup,
|
||||
EditorView.editable.of(!props.disabled),
|
||||
EditorState.readOnly.of(props.disabled),
|
||||
],
|
||||
},
|
||||
b: {
|
||||
doc: props.oldArea,
|
||||
extensions: [
|
||||
javascript(),
|
||||
oneDark,
|
||||
basicSetup,
|
||||
EditorView.editable.of(false),
|
||||
EditorState.readOnly.of(true),
|
||||
],
|
||||
},
|
||||
parent: mergeViewContainer.value,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* 窗口事件
|
||||
* @param val modal触发事件
|
||||
*/
|
||||
function fnCronModal(val: boolean) {
|
||||
emit('update:visible', false);
|
||||
if (val) {
|
||||
emit('ok', true);
|
||||
} else {
|
||||
emit('cancel');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.mergeViewContainer {
|
||||
height: 400px;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
color: #abb2bf;
|
||||
background-color: #282c34;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user