fix(editor): 修改样式,修改代码块ID生成逻辑

This commit is contained in:
parisma 2022-09-16 17:24:01 +08:00 committed by jia000
parent 9e1fb42783
commit a452cecc44
6 changed files with 167 additions and 114 deletions

View File

@ -1,5 +1,7 @@
<template> <template>
<div class="m-fields-code-select" :key="fieldKey"> <div class="m-fields-code-select" :key="fieldKey">
<el-card>
<template #header>
<m-fields-select <m-fields-select
:config="selectConfig" :config="selectConfig"
:model="model" :model="model"
@ -8,6 +10,8 @@
:size="size" :size="size"
@change="changeHandler" @change="changeHandler"
></m-fields-select> ></m-fields-select>
</template>
<div class="tool-bar">
<el-button <el-button
type="primary" type="primary"
:icon="View" :icon="View"
@ -17,6 +21,8 @@
>查看</el-button >查看</el-button
> >
</div> </div>
</el-card>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>

View File

@ -1,13 +1,14 @@
<template> <template>
<el-dialog <el-dialog
v-model="isShowCodeBlockEditor" v-model="isShowCodeBlockEditor"
title="代码块编辑面板"
:fullscreen="true" :fullscreen="true"
:before-close="saveAndClose" :before-close="saveAndClose"
:append-to-body="true" :append-to-body="true"
custom-class="code-editor-dialog" custom-class="code-editor-dialog"
> >
<!-- 左侧列表 -->
<template v-if="mode === EditorMode.LIST"> <template v-if="mode === EditorMode.LIST">
<el-card class="code-editor-side-menu">
<el-tree <el-tree
v-if="!isEmpty(state.codeList)" v-if="!isEmpty(state.codeList)"
ref="tree" ref="tree"
@ -16,38 +17,38 @@
:data="state.codeList" :data="state.codeList"
:highlight-current="true" :highlight-current="true"
@node-click="selectHandler" @node-click="selectHandler"
class="code-editor-side-menu"
:current-node-key="state.codeList[0].id" :current-node-key="state.codeList[0].id"
class="side-tree"
> >
<template #default="{ data }"> <template #default="{ data }">
<div :id="data.id"> <div :id="data.id" class="list-container">
<div class="list-item"> <div class="list-item">
<div class="code-name">{{ data.name }}{{ data.id }}</div> <div class="code-name">{{ data.name }}{{ data.id }}</div>
</div> </div>
</div> </div>
</template> </template>
</el-tree> </el-tree>
</el-card>
</template> </template>
<!-- 右侧区域 -->
<div <div
v-if="!isEmpty(codeConfig)" v-if="!isEmpty(codeConfig)"
:class="[ :class="[
mode === EditorMode.LIST ? 'm-editor-code-block-editor-panel-list-mode' : '', mode === EditorMode.LIST ? 'm-editor-code-block-editor-panel-list-mode' : 'm-editor-code-block-editor-panel',
'm-editor-code-block-editor-panel',
]" ]"
> >
<slot name="code-block-edit-panel-header" :id="id"></slot> <slot name="code-block-edit-panel-header" :id="id"></slot>
<el-row class="code-name-wrapper" justify="start"> <el-card shadow="never">
<el-col :span="3"> <template #header>
<span>代码块名称</span> <div class="code-name-wrapper">
</el-col> <div class="code-name-label">代码块名称</div>
<el-col :span="6"> <el-input class="code-name-input" size="small" v-model="codeConfig.name" :disabled="!editable" />
<el-input size="small" v-model="codeConfig.name" :disabled="!editable" /> </div>
</el-col> </template>
</el-row> <div class="m-editor-wrapper">
<div class="m-editor-content">
<magic-code-editor <magic-code-editor
ref="codeEditor" ref="codeEditor"
class="m-editor-content" class="m-editor-container"
:init-values="`${codeConfig.content}`" :init-values="`${codeConfig.content}`"
@save="saveCode" @save="saveCode"
:options="{ :options="{
@ -57,14 +58,15 @@
readOnly: !editable, readOnly: !editable,
}" }"
></magic-code-editor> ></magic-code-editor>
<div class="m-editor-content-bottom clearfix" v-if="editable"> <div class="m-editor-content-bottom" v-if="editable">
<el-button type="primary" class="button" @click="saveCode">保存</el-button> <el-button type="primary" class="button" @click="saveCode">保存</el-button>
<el-button type="primary" class="button" @click="saveAndClose">保存并关闭</el-button> <el-button type="primary" class="button" @click="saveAndClose">关闭</el-button>
</div> </div>
<div class="m-editor-content-bottom clearfix" v-else> <div class="m-editor-content-bottom" v-else>
<el-button type="primary" class="button" @click="saveAndClose">关闭</el-button> <el-button type="primary" class="button" @click="saveAndClose">关闭</el-button>
</div> </div>
</div> </div>
</el-card>
</div> </div>
</el-dialog> </el-dialog>
</template> </template>

View File

@ -8,7 +8,7 @@
placeholder="输入关键字进行过滤" placeholder="输入关键字进行过滤"
clearable clearable
v-model="filterText" v-model="filterText"
@change="filterTextChangeHandler" @input="filterTextChangeHandler"
></el-input> ></el-input>
<el-button class="create-code-button" type="primary" size="small" @click="createCodeBlock" v-if="editable" <el-button class="create-code-button" type="primary" size="small" @click="createCodeBlock" v-if="editable"
>新增</el-button >新增</el-button

View File

@ -278,7 +278,7 @@ class CodeBlock extends BaseService {
* @returns {string} id * @returns {string} id
*/ */
public async getUniqueId(): Promise<string> { public async getUniqueId(): Promise<string> {
const newId = (Date.now().toString(36) + Math.random().toString(36).substring(2)).padEnd(19, '0'); const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
// 判断是否重复 // 判断是否重复
const dsl = await this.getCodeDsl(); const dsl = await this.getCodeDsl();
const existedIds = keys(dsl); const existedIds = keys(dsl);

View File

@ -50,6 +50,82 @@
} }
} }
} }
.m-fields-code-select {
width: 100%;
.el-card__body {
padding: 10px;
}
.tool-bar {
display: flex;
align-items: center;
justify-content: end;
}
}
.code-editor-dialog {
.el-dialog__body {
height: 90%;
}
.el-card {
height: 100%;
background: #fff;
.el-card__body {
height: 80%;
background: #fff;
}
}
.code-editor-side-menu {
width: 20%;
position: absolute;
top: 0;
left: 0;
background: #fff;
.side-tree {
margin-top: 10px;
.list-container {
width: 100%;
overflow: hidden;
margin-left: -20px;
.list-item {
width: 100%;
margin: 10px 0;
line-height: 30px;
.code-name {
width: 100%;
font-size: 14px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
}
}
.code-name-wrapper {
margin: 10px 0 10px 10px;
display: flex;
align-items: center;
.code-name-label {
width: 80px;
}
.code-name-input {
width: 300px;
}
}
.m-editor-code-block-editor-panel-list-mode {
position: absolute;
top: 0;
left: 20%;
width: 80%;
height: 100%;
z-index: 10;
background: #fff;
}
.m-editor-code-block-editor-panel { .m-editor-code-block-editor-panel {
position: absolute; position: absolute;
top: 0; top: 0;
@ -58,59 +134,28 @@
height: 100%; height: 100%;
z-index: 10; z-index: 10;
background: #fff; background: #fff;
.code-name-wrapper {
padding: 10px 20px;
display: flex;
align-items: center;
} }
.m-editor-wrapper {
height: 100%;
.m-editor-container {
height: 100%;
}
.m-editor-content-bottom { .m-editor-content-bottom {
text-align: right; text-align: right;
padding-right: 20px;
height: 40px; height: 40px;
padding-right: 20px;
position: absolute; position: absolute;
width: 100%; width: calc(100% - 30px);
display: flex; display: flex;
justify-content: center; justify-content: end;
bottom: 0; bottom: 20px;
right: 0; right: 0;
background: #fff; background: #fff;
> button { > button {
height: 30px; height: 30px;
margin-top: 4px; margin-top: 5px;
} }
} }
} }
.m-fields-code-select {
display: flex;
width: 100%;
align-items: center;
}
.code-editor-dialog {
.el-dialog__body {
height: 90%;
}
.code-editor-side-menu {
width: 18%;
height: 90%;
overflow: auto;
margin-left: -25px;
.list-item {
width: 100%;
margin: 10px 0;
.code-name {
width: 100%;
font-size: 14px;
}
}
}
.m-editor-code-block-editor-panel-list-mode {
width: 80%;
position: absolute;
height: 90%;
left: 20%;
top: 60px;
}
} }

View File

@ -21,7 +21,7 @@ export default {
name: 'test', name: 'test',
type: 'app', type: 'app',
methods: { methods: {
l7znj1q24wilb357ay6: { code_5336: {
name: 'getData', name: 'getData',
// eslint-disable-next-line no-eval // eslint-disable-next-line no-eval
content: eval(`(vm) => {\n console.log("this is getData function")\n}`), content: eval(`(vm) => {\n console.log("this is getData function")\n}`),
@ -51,7 +51,7 @@ export default {
fontWeight: '', fontWeight: '',
}, },
events: [], events: [],
created: ['l7znj1q24wilb357ay6'], created: ['code_5336'],
items: [ items: [
{ {
type: 'text', type: 'text',