神仙都没用 1 жил өмнө
parent
commit
65ddc0f000

+ 30 - 2
src/modules/helper/views/plugins/serve.vue

@@ -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

+ 1 - 1
src/modules/space/components/space.vue

@@ -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>

+ 26 - 0
src/plugins/editor-monaco/components/monaco.vue

@@ -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>