chore(editor): ts type error

This commit is contained in:
roymondchen 2022-09-22 16:57:59 +08:00 committed by jia000
parent 765c0a227d
commit 00cd237f61
3 changed files with 10 additions and 7 deletions

View File

@ -45,11 +45,12 @@
<template #header> <template #header>
<div class="code-name-wrapper"> <div class="code-name-wrapper">
<div class="code-name-label">代码块名称</div> <div class="code-name-label">代码块名称</div>
<el-input class="code-name-input" v-model="codeConfig.name" :disabled="!editable" /> <el-input v-if="codeConfig" class="code-name-input" v-model="codeConfig.name" :disabled="!editable" />
</div> </div>
</template> </template>
<div class="m-editor-wrapper"> <div class="m-editor-wrapper">
<magic-code-editor <magic-code-editor
v-if="codeConfig"
ref="codeEditor" ref="codeEditor"
class="m-editor-container" class="m-editor-container"
:init-values="`${codeConfig.content}`" :init-values="`${codeConfig.content}`"
@ -80,6 +81,7 @@
import { computed, inject, reactive, ref, watchEffect } from 'vue'; import { computed, inject, reactive, ref, watchEffect } from 'vue';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { forIn, isEmpty } from 'lodash-es'; import { forIn, isEmpty } from 'lodash-es';
import type * as monaco from 'monaco-editor';
import type { CodeBlockContent, CodeDslList, ListState, Services } from '../../../type'; import type { CodeBlockContent, CodeDslList, ListState, Services } from '../../../type';
import { CodeEditorMode } from '../../../type'; import { CodeEditorMode } from '../../../type';
@ -132,7 +134,7 @@ const saveCode = async (): Promise<boolean> => {
try { try {
// //
const codeContent = codeEditor.value.getEditor()?.getValue(); const codeContent = (codeEditor.value.getEditor() as monaco.editor.IStandaloneCodeEditor)?.getValue();
/* eslint no-eval: "off" */ /* eslint no-eval: "off" */
codeConfig.value.content = eval(codeContent); codeConfig.value.content = eval(codeContent);
} catch (e: any) { } catch (e: any) {

View File

@ -243,9 +243,9 @@ class CodeBlock extends BaseService {
try { try {
diffCodeIds.forEach((codeId) => { diffCodeIds.forEach((codeId) => {
const compsContent = codeDsl[codeId].comps; const compsContent = codeDsl[codeId].comps;
const index = compsContent[compId].findIndex((item) => item === hook); const index = compsContent?.[compId].findIndex((item) => item === hook);
if (index !== -1) { if (typeof index !== 'undefined' && index !== -1) {
compsContent[compId].splice(index, 1); compsContent?.[compId].splice(index, 1);
} }
}); });
} catch (e) { } catch (e) {
@ -265,7 +265,7 @@ class CodeBlock extends BaseService {
}; };
} else { } else {
// 往已有的关系中添加hook // 往已有的关系中添加hook
existHooks.push(hook); existHooks?.push(hook);
} }
}); });
} catch (e) { } catch (e) {

3
pnpm-lock.yaml generated
View File

@ -146,11 +146,11 @@ importers:
dependencies: dependencies:
'@tmagic/schema': link:../schema '@tmagic/schema': link:../schema
events: 3.3.0 events: 3.3.0
lodash-es: 4.17.21
devDependencies: devDependencies:
'@types/events': 3.0.0 '@types/events': 3.0.0
'@types/lodash-es': 4.17.6 '@types/lodash-es': 4.17.6
'@types/node': 15.14.9 '@types/node': 15.14.9
lodash-es: 4.17.21
rimraf: 3.0.2 rimraf: 3.0.2
typescript: 4.7.4 typescript: 4.7.4
vite: 3.1.3 vite: 3.1.3
@ -5563,6 +5563,7 @@ packages:
/lodash-es/4.17.21: /lodash-es/4.17.21:
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
dev: false
/lodash-unified/1.0.2_3ib2ivapxullxkx3xftsimdk7u: /lodash-unified/1.0.2_3ib2ivapxullxkx3xftsimdk7u:
resolution: {integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g==} resolution: {integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g==}