This commit is contained in:
神仙都没用 2024-02-04 20:46:57 +08:00
parent 150498c25a
commit 65ddc0f000
3 changed files with 57 additions and 3 deletions

View File

@ -74,7 +74,22 @@
</cl-editor-preview>
<!-- 设置 -->
<cl-form ref="Form" />
<cl-form ref="Form">
<template #slot-upload>
<cl-row>
<cl-upload-space
:show-list="false"
:multiple="false"
text="选择文件"
@confirm="onFileConfirm"
/>
<el-text type="warning" :style="{ marginLeft: '10px' }"
>选择后会在光标后插入文件链接</el-text
>
</cl-row>
</template>
</cl-form>
</div>
</template>
@ -134,10 +149,18 @@ function toSet(item: Eps.PluginInfoEntity) {
component: {
name: "cl-editor",
props: {
name: "cl-editor-monaco"
name: "cl-editor-monaco",
ref: setRefs("editor")
}
}
},
{
label: " ",
flex: false,
component: {
name: "slot-upload"
}
},
{
label: "状态",
prop: "status",
@ -192,6 +215,11 @@ function toDel(item: Eps.PluginInfoEntity, index: number) {
.catch(() => null);
}
//
function onFileConfirm(arr: any[]) {
refs.editor.appendContent(arr[0]?.url);
}
//
function onStatusChange(item: Eps.PluginInfoEntity) {
service.plugin.info

View File

@ -4,7 +4,7 @@
<template v-if="showBtn">
<el-button @click="open">{{ text }}</el-button>
<div class="cl-upload-space__wrap-list" v-show="urls.length > 0">
<div class="cl-upload-space__wrap-list" v-show="urls.length > 0 && showList">
<cl-upload v-model="urls" disabled deletable draggable :multiple="multiple" />
</div>
</template>

View File

@ -73,6 +73,31 @@ function setContent(value: string = "") {
}
}
//
function appendContent(text: string = "") {
const position = editor?.getPosition();
if (position) {
editor?.executeEdits("", [
{
range: new monaco.Range(
position.lineNumber,
position.column,
position.lineNumber,
position.column
),
text
}
]);
editor?.setPosition({
lineNumber: position.lineNumber,
column: position.column + text.length
});
editor?.focus();
}
}
//
async function formatCode() {
await editor?.getAction("editor.action.formatDocument")?.run();
@ -164,6 +189,7 @@ onUnmounted(() => {
defineExpose({
editor,
setContent,
appendContent,
formatCode
});
</script>