feat(editor): 增加代码块搜索,代码编辑器同步设置是否可编辑属性,修复不可编辑状态下弹窗无法关闭的问题

This commit is contained in:
parisma 2022-09-16 12:48:53 +08:00 committed by jia000
parent 071619b9bd
commit 9e1fb42783
3 changed files with 45 additions and 9 deletions

View File

@ -54,6 +54,7 @@
tabSize: 2, tabSize: 2,
fontSize: 16, fontSize: 16,
formatOnPaste: true, formatOnPaste: true,
readOnly: !editable,
}" }"
></magic-code-editor> ></magic-code-editor>
<div class="m-editor-content-bottom clearfix" v-if="editable"> <div class="m-editor-content-bottom clearfix" v-if="editable">
@ -115,7 +116,7 @@ watchEffect(async () => {
// //
const saveCode = async (): Promise<boolean> => { const saveCode = async (): Promise<boolean> => {
if (!codeEditor.value || !codeConfig.value || !editable.value) return false; if (!codeEditor.value || !codeConfig.value || !editable.value) return true;
try { try {
// //

View File

@ -1,10 +1,19 @@
<template> <template>
<div class="m-editor-code-block-list"> <div class="m-editor-code-block-list">
<slot name="code-block-panel-header"> <slot name="code-block-panel-header">
<div class="create-code-button"> <div class="code-header-wrapper">
<el-button type="primary" size="small" @click="createCodeBlock" :disabled="!editable">新增代码块</el-button> <el-input
:class="[editable ? 'code-filter-input' : 'code-filter-input-no-btn']"
size="small"
placeholder="输入关键字进行过滤"
clearable
v-model="filterText"
@change="filterTextChangeHandler"
></el-input>
<el-button class="create-code-button" type="primary" size="small" @click="createCodeBlock" v-if="editable"
>新增</el-button
>
</div> </div>
<el-divider class="divider" />
</slot> </slot>
<!-- 代码块列表 --> <!-- 代码块列表 -->
@ -15,6 +24,7 @@
empty-text="暂无代码块" empty-text="暂无代码块"
:data="state.codeList" :data="state.codeList"
:highlight-current="true" :highlight-current="true"
:filter-node-method="filterNode"
> >
<template #default="{ data }"> <template #default="{ data }">
<div :id="data.id" class="list-container"> <div :id="data.id" class="list-container">
@ -44,14 +54,14 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, inject, reactive, watchEffect } from 'vue'; import { computed, inject, reactive, ref, watchEffect } from 'vue';
import { Close, Edit, View } from '@element-plus/icons-vue'; import { Close, Edit, View } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { flattenDeep, forIn, isEmpty, values } from 'lodash-es'; import { flattenDeep, forIn, isEmpty, values } from 'lodash-es';
import Icon from '../../../components/Icon.vue'; import Icon from '../../../components/Icon.vue';
import type { CodeBlockContent, Services } from '../../../type'; import type { CodeBlockContent, Services } from '../../../type';
import { EditorMode, ListState } from '../../../type'; import { CodeDslList, EditorMode, ListState } from '../../../type';
import codeBlockEditor from './CodeBlockEditor.vue'; import codeBlockEditor from './CodeBlockEditor.vue';
@ -124,4 +134,18 @@ const deleteCode = (key: string) => {
} }
} }
}; };
const filterText = ref('');
const tree = ref();
const filterNode = (value: string, data: CodeDslList): boolean => {
if (!value) {
return true;
}
return `${data.name}${data.id}`.indexOf(value) !== -1;
};
const filterTextChangeHandler = (val: string) => {
tree.value?.filter(val);
};
</script> </script>

View File

@ -1,9 +1,20 @@
.m-editor-code-block-list { .m-editor-code-block-list {
padding-top: 20px; margin-top: 5px;
.create-code-button { .code-header-wrapper {
display: flex; display: flex;
justify-content: center;
align-items: center; align-items: center;
justify-content: center;
.code-filter-input {
margin: 0 5px;
}
.code-filter-input-no-btn {
margin-left: 5px;
margin-right: 10px;
}
.create-code-button {
margin-left: 2px;
margin-right: 10px;
}
} }
.divider { .divider {