浏览代码

优化插件机制

mxd 3 年之前
父节点
当前提交
afc0efde8f

+ 10 - 8
src/components/common/icon/magic-text-icon.vue

@@ -6,25 +6,27 @@
 <script setup>
 import { computed } from 'vue'
 const props = defineProps({
-    icon: String
+    icon: String | Array
 })
 const colors = {
     GET: '#0cbb52',
     POST: '#FFB400',
     DELETE: ['DEL', '#EB2013'],
     PUT: '#097BED',
-    'function': ['Fn', '#9012FE'],
-    'websocket': ['WS', '#6B6B6B'],
-    'task': ['TASK', '#9012FE'],
-    'resource': ['RES', '#9012FE']
+    'function': ['Fn', '#9012FE']
 }
 const item = computed(() => {
-  let values = colors[props.icon]
-  const isArray = values !== undefined && Array.isArray(values)
+  let values = props.icon
+  let isArray = Array.isArray(values)
+  if(!isArray) {
+    values = colors[props.icon]
+    isArray = values !== undefined && Array.isArray(values)
+  }
   const text = isArray ? values[0] : props.icon
   const width = text.length * 9
   const color = isArray ? values[1] : (values || 'var(--main-icon-color)')
+  console.log({ width, color, text})
   return { width, color, text}
 })
 
-</script>
+</script>

+ 5 - 1
src/components/magic-editor.vue

@@ -26,6 +26,7 @@ import { getCurrentInstance, nextTick, onMounted, onUnmounted, provide, reactive
 import { initializeMagicScript } from '../scripts/editor/magic-script.js'
 import JavaClass from '../scripts/editor/java-class.js'
 import MagicWebSocket from '../scripts/websocket.js'
+import modal from './common/dialog/magic-modal.js'
 import Socket from '../scripts/constants/socket.js'
 import Message from '../scripts/constants/message.js'
 import { loadPlugin, randomString, replaceURL } from '../scripts/utils.js'
@@ -82,7 +83,10 @@ const installPlugin = () => {
 					request,
 					constants,
 					Message,
-					bus
+					bus,
+					modal,
+					JavaClass,
+					monaco
 				}))
 				bus.status('plugin.loaded', true, plugin.name)
 				r();

+ 4 - 1
src/components/panel/header/magic-search.vue

@@ -25,6 +25,7 @@ import { tokenizeToString } from 'monaco-editor/esm/vs/editor/common/modes/textT
 const keyword = ref('')
 const show = ref(false)
 const findResource = inject('findResource')
+const services = inject('service')
 const results = ref([])
 const selectedItem = ref({})
 const displayText = computed(() => selectedItem.value.name + (selectedItem.value.path ? `(${selectedItem.value.path})` : ''))
@@ -121,10 +122,12 @@ watch(keyword, (val) => {
 		timer = setTimeout(()=>{
 			request.send('/search', { keyword: text} ,{ method: 'POST'}).success(async data => {
 				const list = []
-				const tokenizer = await TokenizationRegistry.getPromise('magicscript')
+				
 				for (let index = 0; index < data.length; index++) {
 					const item = data[index];
 					const find = findResource(item.id)
+					const config = services[find.type]
+					const tokenizer = await TokenizationRegistry.getPromise(config.language || 'magicscript')
 					list.push({
 						...item,
 						text: replaceKeywords(await tokenizeToString(item.text, tokenizer), text),

+ 1 - 0
src/components/panel/main/magic-resource.vue

@@ -165,6 +165,7 @@ const onItemClick = item => {
 				opened = reactive({
 					type: props.type,
 					title: props.title,
+					language: config.language || 'magicscript',
 					item: config.merge(item),
 					path: () => getFullPath(item),
 					requestPath: () => {

+ 1 - 1
src/components/panel/main/magic-script-editor.vue

@@ -24,7 +24,7 @@
 			</magic-tab>
 			<magic-loading :loading="loading">
 				<div class="magic-monaco-editor-wrapper">
-					<magic-monaco-editor ref="editor" v-model:value="selectTab.item.script" v-model:decorations="selectTab.decorations" language="magicscript" :support-breakpoint="true"/>
+					<magic-monaco-editor ref="editor" v-model:value="selectTab.item.script" v-model:decorations="selectTab.decorations" :language="selectTab.language" :support-breakpoint="true"/>
 				</div>
 			</magic-loading>
 		</template>