ソースを参照

Merge branch 'dev'

mxd 3 年 前
コミット
a02d7f7d88
23 ファイル変更126 行追加51 行削除
  1. 1 1
      README.md
  2. 1 1
      magic-api-spring-boot-starter/pom.xml
  3. 17 7
      magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java
  4. 4 4
      magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicJsonAutoConfiguration.java
  5. 1 1
      magic-api/pom.xml
  6. 1 1
      magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicWorkbenchController.java
  7. 2 1
      magic-api/src/main/java/org/ssssssss/magicapi/modules/SQLModule.java
  8. 11 5
      magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java
  9. 13 8
      magic-api/src/main/java/org/ssssssss/magicapi/modules/table/Where.java
  10. 5 3
      magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java
  11. 1 1
      magic-editor/pom.xml
  12. 1 1
      magic-editor/src/console/package.json
  13. 28 10
      magic-editor/src/console/src/api/request.js
  14. 3 0
      magic-editor/src/console/src/components/editor/magic-history.vue
  15. 4 2
      magic-editor/src/console/src/components/editor/magic-script-editor.vue
  16. 3 0
      magic-editor/src/console/src/components/layout/magic-request.vue
  17. 3 0
      magic-editor/src/console/src/components/layout/magic-run.vue
  18. 4 1
      magic-editor/src/console/src/components/layout/magic-search.vue
  19. 6 0
      magic-editor/src/console/src/components/magic-editor.vue
  20. 2 0
      magic-editor/src/console/src/components/resources/magic-datasource-list.vue
  21. 2 0
      magic-editor/src/console/src/scripts/contants.js
  22. 11 2
      magic-editor/src/console/src/scripts/parsing/parser.js
  23. 2 2
      pom.xml

+ 1 - 1
README.md

@@ -52,7 +52,7 @@ magic-api 是一个基于Java的接口快速开发框架,编写接口将通过
 <dependency>
 	<groupId>org.ssssssss</groupId>
     <artifactId>magic-api-spring-boot-starter</artifactId>
-    <version>1.4.3</version>
+    <version>1.4.4</version>
 </dependency>
 ```
 ## 修改application.properties

+ 1 - 1
magic-api-spring-boot-starter/pom.xml

@@ -6,7 +6,7 @@
     <parent>
         <groupId>org.ssssssss</groupId>
         <artifactId>magic-api-parent</artifactId>
-        <version>1.4.3</version>
+        <version>1.4.4</version>
     </parent>
     <artifactId>magic-api-spring-boot-starter</artifactId>
     <packaging>jar</packaging>

+ 17 - 7
magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java

@@ -12,7 +12,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.core.Ordered;
 import org.springframework.core.env.Environment;
 import org.springframework.http.MediaType;
@@ -28,7 +31,10 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
 import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-import org.springframework.web.socket.config.annotation.*;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
+import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration;
+import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
 import org.ssssssss.magicapi.adapter.ColumnMapperAdapter;
 import org.ssssssss.magicapi.adapter.DialectAdapter;
 import org.ssssssss.magicapi.adapter.Resource;
@@ -55,6 +61,7 @@ import org.ssssssss.magicapi.utils.PathUtils;
 import org.ssssssss.script.MagicResourceLoader;
 import org.ssssssss.script.MagicScript;
 import org.ssssssss.script.MagicScriptEngine;
+import org.ssssssss.script.exception.MagicScriptRuntimeException;
 import org.ssssssss.script.functions.ExtensionMethod;
 import org.ssssssss.script.parsing.ast.statement.AsyncCall;
 import org.ssssssss.script.reflection.JavaReflection;
@@ -196,7 +203,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
 
 	@Bean
 	@ConditionalOnMissingBean(HttpModule.class)
-	public HttpModule magicHttpModule(){
+	public HttpModule magicHttpModule() {
 		return new HttpModule(createRestTemplate());
 	}
 
@@ -269,7 +276,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
 
 	@Override
 	public void addInterceptors(InterceptorRegistry registry) {
-		if(!registerInterceptor){
+		if (!registerInterceptor) {
 			registerInterceptor = true;
 			registry.addInterceptor(new MagicWebRequestInterceptor(properties.isSupportCrossDomain() ? magicCorsFilter : null, authorizationInterceptorProvider.getIfAvailable(this::createAuthorizationInterceptor)))
 					.addPathPatterns("/**");
@@ -396,7 +403,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
 									PageProvider pageProvider,
 									SqlCache sqlCache) {
 		SQLModule sqlModule = new SQLModule(dynamicDataSource);
-		if(!dynamicDataSource.isEmpty()){
+		if (!dynamicDataSource.isEmpty()) {
 			sqlModule.setDataSourceNode(dynamicDataSource.getDataSource());
 		}
 		sqlModule.setResultProvider(resultProvider);
@@ -434,6 +441,9 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
 					clazz = Class.forName(className);
 					return applicationContext.getBean(clazz);
 				} catch (Exception ex) {
+					if (clazz == null) {
+						throw new MagicScriptRuntimeException(new ClassNotFoundException(className));
+					}
 					return clazz;
 				}
 			}
@@ -577,7 +587,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
 			Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
 				try {
 					long count = magicBackupService.removeBackupByTimestamp(System.currentTimeMillis() - interval);
-					if(count > 0){
+					if (count > 0) {
 						logger.info("已删除备份记录{}条", count);
 					}
 				} catch (Exception e) {
@@ -591,7 +601,7 @@ public class MagicAPIAutoConfiguration implements WebMvcConfigurer, WebSocketCon
 	private DefaultAuthorizationInterceptor defaultAuthorizationInterceptor;
 
 	public AuthorizationInterceptor createAuthorizationInterceptor() {
-		if(defaultAuthorizationInterceptor != null){
+		if (defaultAuthorizationInterceptor != null) {
 			return defaultAuthorizationInterceptor;
 		}
 		SecurityConfig securityConfig = properties.getSecurityConfig();

+ 4 - 4
magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicJsonAutoConfiguration.java

@@ -47,10 +47,10 @@ public class MagicJsonAutoConfiguration {
 
 	@ConditionalOnBean({ObjectMapper.class})
 	@Configuration
-	static class JacksonAutoConfiguration {
+	static class MagicJacksonAutoConfiguration {
 
 
-		JacksonAutoConfiguration(ObjectMapper objectMapper) {
+		MagicJacksonAutoConfiguration(ObjectMapper objectMapper) {
 			register(str -> {
 				try {
 					return objectMapper.readValue(str, Object.class);
@@ -82,9 +82,9 @@ public class MagicJsonAutoConfiguration {
 	@ConditionalOnMissingBean({ObjectMapper.class})
 	@ConditionalOnClass(JSON.class)
 	@Configuration
-	static class FastJsonAutoConfiguration {
+	static class MagicFastJsonAutoConfiguration {
 
-		FastJsonAutoConfiguration() {
+		MagicFastJsonAutoConfiguration() {
 			register(JSON::parse, JSON::parse, JSON::toJSONString);
 		}
 	}

+ 1 - 1
magic-api/pom.xml

@@ -6,7 +6,7 @@
     <parent>
         <groupId>org.ssssssss</groupId>
         <artifactId>magic-api-parent</artifactId>
-        <version>1.4.3</version>
+        <version>1.4.4</version>
     </parent>
     <artifactId>magic-api</artifactId>
     <packaging>jar</packaging>

+ 1 - 1
magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicWorkbenchController.java

@@ -86,7 +86,7 @@ public class MagicWorkbenchController extends MagicController implements MagicEx
 	 */
 	@RequestMapping("/class")
 	@ResponseBody
-	public JsonBean<List<ScriptClass>> clazz(String className) {
+	public JsonBean<Set<ScriptClass>> clazz(String className) {
 		return new JsonBean<>(MagicScriptEngine.getScriptClass(className));
 	}
 

+ 2 - 1
magic-api/src/main/java/org/ssssssss/magicapi/modules/SQLModule.java

@@ -407,7 +407,8 @@ public class SQLModule extends HashMap<String, SQLModule> implements MagicModule
 		return page(boundSql, page);
 	}
 
-	private Object page(BoundSql boundSql, Page page) {
+	@UnableCall
+	public Object page(BoundSql boundSql, Page page) {
 		assertDatasourceNotNull();
 		Dialect dialect = dataSourceNode.getDialect(dialectAdapter);
 		BoundSql countBoundSql = boundSql.copy(dialect.getCountSql(boundSql.getSql()));

+ 11 - 5
magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java

@@ -2,6 +2,7 @@ package org.ssssssss.magicapi.modules.table;
 
 import org.apache.commons.lang3.StringUtils;
 import org.ssssssss.magicapi.exception.MagicAPIException;
+import org.ssssssss.magicapi.model.Page;
 import org.ssssssss.magicapi.modules.BoundSql;
 import org.ssssssss.magicapi.modules.SQLModule;
 import org.ssssssss.script.annotation.Comment;
@@ -109,7 +110,7 @@ public class NamedTable {
 	@Comment("设置要排除的列")
 	public NamedTable exclude(String column) {
 		if (column != null) {
-			excludeColumns.add(column);
+			excludeColumns.add(rowMapColumnMapper.apply(column));
 		}
 		return this;
 	}
@@ -117,7 +118,7 @@ public class NamedTable {
 	@Comment("设置要排除的列")
 	public NamedTable excludes(String... columns) {
 		if (columns != null) {
-			excludeColumns.addAll(Arrays.asList(columns));
+			excludeColumns.addAll(Arrays.stream(columns).map(rowMapColumnMapper).collect(Collectors.toList()));
 		}
 		return this;
 	}
@@ -125,7 +126,7 @@ public class NamedTable {
 	@Comment("设置要排除的列")
 	public NamedTable excludes(List<String> columns) {
 		if (columns != null) {
-			excludeColumns.addAll(columns);
+			excludeColumns.addAll(columns.stream().map(rowMapColumnMapper).collect(Collectors.toList()));
 		}
 		return this;
 	}
@@ -148,7 +149,7 @@ public class NamedTable {
 
 	@Comment("拼接`order by xxx asc/desc`")
 	public NamedTable orderBy(@Comment("要排序的列") String column, @Comment("`asc`或`desc`") String sort) {
-		this.orders.add(column + " " + sort);
+		this.orders.add(rowMapColumnMapper.apply(column) + " " + sort);
 		return this;
 	}
 
@@ -164,7 +165,7 @@ public class NamedTable {
 
 	@Comment("拼接`group by`")
 	public NamedTable groupBy(@Comment("要分组的列") String... columns) {
-		this.groups.addAll(Arrays.asList(columns));
+		this.groups.addAll(Arrays.stream(columns).map(rowMapColumnMapper).collect(Collectors.toList()));
 		return this;
 	}
 
@@ -328,6 +329,11 @@ public class NamedTable {
 		return sqlModule.page(buildSelect());
 	}
 
+	@Comment("执行分页查询,分页条件手动传入")
+	public Object page(@Comment("限制条数") long limit, @Comment("跳过条数") long offset) {
+		return sqlModule.page(buildSelect(), new Page(limit, offset));
+	}
+
 	@Comment("执行update语句")
 	public int update() {
 		return update(null);

+ 13 - 8
magic-api/src/main/java/org/ssssssss/magicapi/modules/table/Where.java

@@ -100,7 +100,7 @@ public class Where {
 
 	@Comment("是否过滤`blank`的参数")
 	public Where notBlank(boolean flag) {
-		this.notNull = flag;
+		this.notBlank = flag;
 		return this;
 	}
 
@@ -119,7 +119,7 @@ public class Where {
 	@Comment("等于`=`,如:`eq('name', '老王') ---> name = '老王'`")
 	public Where eq(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
 		if (condition && filterNullAndBlank(value)) {
-			tokens.add(column);
+			tokens.add(namedTable.rowMapColumnMapper.apply(column));
 			if (value == null) {
 				append(" is null");
 			} else {
@@ -139,7 +139,7 @@ public class Where {
 	@Comment("不等于`<>`,如:`ne('name', '老王') ---> name <> '老王'`")
 	public Where ne(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column, @Comment("值") Object value) {
 		if (condition && filterNullAndBlank(value)) {
-			append(column);
+			append(namedTable.rowMapColumnMapper.apply(column));
 			if (value == null) {
 				append("is not null");
 			} else {
@@ -153,7 +153,7 @@ public class Where {
 
 	private Where append(boolean append, String column, String condition, Object value) {
 		if (append && filterNullAndBlank(value)) {
-			append(column);
+			append(namedTable.rowMapColumnMapper.apply(column));
 			append(condition);
 			appendAnd();
 			params.add(value);
@@ -211,7 +211,7 @@ public class Where {
 		if (condition && value != null) {
 			List<Object> objects = StreamExtension.arrayLikeToList(value);
 			if (objects.size() > 0) {
-				append(column);
+				append(namedTable.rowMapColumnMapper.apply(column));
 				append(" in (");
 				append(String.join(",", Collections.nCopies(objects.size(), "?")));
 				append(")");
@@ -232,7 +232,7 @@ public class Where {
 		if (condition && value != null) {
 			List<Object> objects = StreamExtension.arrayLikeToList(value);
 			if (objects.size() > 0) {
-				append(column);
+				append(namedTable.rowMapColumnMapper.apply(column));
 				append("not in (");
 				append(String.join(",", Collections.nCopies(objects.size(), "?")));
 				append(")");
@@ -271,7 +271,7 @@ public class Where {
 	@Comment("`is null`,如:`isNull('name') ---> name is null")
 	public Where isNull(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column) {
 		if (condition) {
-			append(column);
+			append(namedTable.rowMapColumnMapper.apply(column));
 			append("is null");
 			appendAnd();
 		}
@@ -286,7 +286,7 @@ public class Where {
 	@Comment("`is not null`,如:`isNotNull('name') ---> name is not null")
 	public Where isNotNull(@Comment("判断表达式,当为true时拼接条件") boolean condition, @Comment("数据库中的列名") String column) {
 		if (condition) {
-			append(column);
+			append(namedTable.rowMapColumnMapper.apply(column));
 			append("is not null");
 			appendAnd();
 		}
@@ -399,6 +399,11 @@ public class Where {
 		return namedTable.page();
 	}
 
+	@Comment("执行分页查询,分页条件手动传入")
+	public Object page(@Comment("限制条数") long limit, @Comment("跳过条数") long offset) {
+		return namedTable.page(limit, offset);
+	}
+
 	@Comment("执行select查询")
 	public List<Map<String, Object>> select() {
 		return namedTable.select();

+ 5 - 3
magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java

@@ -43,6 +43,7 @@ import org.ssssssss.script.MagicScriptContext;
 import org.ssssssss.script.exception.MagicExitException;
 import org.ssssssss.script.functions.ObjectConvertExtension;
 import org.ssssssss.script.runtime.ExitValue;
+import org.ssssssss.script.runtime.function.MagicScriptLambdaFunction;
 
 import javax.script.ScriptContext;
 import javax.script.SimpleScriptContext;
@@ -50,7 +51,6 @@ import javax.sql.DataSource;
 import java.io.*;
 import java.sql.Connection;
 import java.util.*;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.zip.ZipEntry;
@@ -116,10 +116,12 @@ public class DefaultMagicAPIService implements MagicAPIService, JsonCodeConstant
 				String path = name.substring(index + 1);
 				ApiInfo info = this.mappingHandlerMapping.getApiInfo(method, path);
 				if (info != null) {
-					return (Function<Object[], Object>) objects -> {
+					return (MagicScriptLambdaFunction) (variables, args) -> {
 						MagicScriptContext context = MagicScriptContext.get();
 						MagicScriptContext newContext = new MagicScriptContext();
-						newContext.putMapIntoContext(context.getVariables());
+						Map<String, Object> varMap = new LinkedHashMap<>(context.getRootVariables());
+						varMap.putAll(variables.getVariables());
+						newContext.putMapIntoContext(varMap);
 						MagicScriptContext.set(newContext);
 						try {
 							Object value = ScriptManager.executeScript(info.getScript(), newContext);

+ 1 - 1
magic-editor/pom.xml

@@ -6,7 +6,7 @@
     <parent>
         <groupId>org.ssssssss</groupId>
         <artifactId>magic-api-parent</artifactId>
-        <version>1.4.3</version>
+        <version>1.4.4</version>
     </parent>
     <artifactId>magic-editor</artifactId>
     <packaging>jar</packaging>

+ 1 - 1
magic-editor/src/console/package.json

@@ -1,6 +1,6 @@
 {
   "name": "magic-editor",
-  "version": "1.4.3",
+  "version": "1.4.4",
   "private": false,
   "description": "magic-editor for magic-api",
   "main": "dist/magic-editor.umd.min.js",

+ 28 - 10
magic-editor/src/console/src/api/request.js

@@ -140,21 +140,39 @@ class HttpRequest {
         requestConfig.baseURL = config.baseURL
         let httpResponse = new HttpResponse()
         let successed = false;
+        let processResult = (data, response) => {
+            if(data instanceof Blob){
+                successed = true
+                httpResponse.successHandle && httpResponse.successHandle(data, response)
+            } else if (data.code === 1) {
+                successed = true
+                httpResponse.successHandle && httpResponse.successHandle(data.data, response)
+            } else {
+                if (data.code === 401) {
+                    bus.$emit('showLogin')
+                }
+                httpResponse.exceptionHandle && httpResponse.exceptionHandle(data.code, data.message, response)
+            }
+        }
         this.execute(requestConfig)
             .then(response => {
                 let data = response.data
-                if(data instanceof Blob){
-                    successed = true
-                    httpResponse.successHandle && httpResponse.successHandle(data, response)
-                } else if (data.code === 1) {
-                    successed = true
-                    httpResponse.successHandle && httpResponse.successHandle(data.data, response)
-                } else {
-                    if (data.code === 401) {
-                        bus.$emit('showLogin')
+                let isJson = response.headers['content-type'] && response.headers['content-type'].startsWith('application/json')
+                if(data instanceof Blob && isJson){
+                    let reader = new FileReader()
+                    reader.readAsText(data)
+                    reader.onload = function() {
+                        try{
+                            data = JSON.parse(this.result)
+                            processResult(data, response)
+                        }catch(e){
+                            console.error(e);
+                            processResult(data, response)
+                        }
                     }
-                    httpResponse.exceptionHandle && httpResponse.exceptionHandle(data.code, data.message, response)
+                    return;
                 }
+                processResult(data, response)
             })
             .catch((error) => {
                 if (typeof httpResponse.errorHandle === 'function') {

+ 3 - 0
magic-editor/src/console/src/components/editor/magic-history.vue

@@ -19,6 +19,7 @@ import * as monaco from 'monaco-editor'
 import bus from '@/scripts/bus.js'
 import {formatDate, isVisible} from '@/scripts/utils.js'
 import request from '@/api/request.js'
+import contants from "@/scripts/contants";
 
 export default {
   name: 'MagicHistory',
@@ -43,6 +44,8 @@ export default {
       folding: false,
       lineDecorationsWidth: 20,
       fixedOverflowWidgets: false,
+      fontFamily: contants.EDITOR_FONT_FAMILY,
+      fontSize: contants.EDITOR_FONT_SIZE,
     })
     bus.$on('update-window-size', this.layout)
   },

+ 4 - 2
magic-editor/src/console/src/components/editor/magic-script-editor.vue

@@ -109,6 +109,8 @@ export default {
       lineDecorationsWidth: 35,
       wordWrap: 'on',
       theme: store.get('skin') || 'default',
+      fontFamily: contants.EDITOR_FONT_FAMILY,
+      fontSize: contants.EDITOR_FONT_SIZE,
       // 自动调整大小
       automaticLayout: true
     })
@@ -489,11 +491,11 @@ export default {
           content: '请打开接口在执行测试'
         })
       } else {
-        bus.$emit('switch-tab','request')
         if (this.info.running || this.info._type !== 'api') {
           return
         }
-        if (contants.AUTO_SAVE) {
+        bus.$emit('switch-tab','request')
+        if (contants.AUTO_SAVE && this.info.lock !== '1') {
           // 自动保存
           let resp = this.doSave()
           resp && resp.end((successed) => {

+ 3 - 0
magic-editor/src/console/src/components/layout/magic-request.vue

@@ -188,6 +188,7 @@
   import bus from '@/scripts/bus.js'
   import store from '@/scripts/store.js'
   import {parseJson} from '@/scripts/parsing/parser.js'
+  import contants from "@/scripts/contants";
   let timeout = null;
   export default {
     name: 'MagicRequest',
@@ -345,6 +346,8 @@
             folding: true,
             wordWrap: 'on',
             lineDecorationsWidth: 35,
+            fontFamily: contants.EDITOR_FONT_FAMILY,
+            fontSize: contants.EDITOR_FONT_SIZE,
             theme: store.get('skin') || 'default',
             value: formatJson(this.info.requestBody) || '{\r\n\t\r\n}'
           })

+ 3 - 0
magic-editor/src/console/src/components/layout/magic-run.vue

@@ -19,6 +19,7 @@ import * as monaco from 'monaco-editor'
 import store from '@/scripts/store.js'
 import {isVisible, deepClone, download as downloadFile} from '@/scripts/utils.js'
 import {parseJson} from '@/scripts/parsing/parser.js'
+import contants from "@/scripts/contants";
 
 export default {
   name: 'MagicRun',
@@ -92,6 +93,8 @@ export default {
         readOnly: true, //只读模式
         lineDecorationsWidth: 35,
         wordWrap: 'on',
+        fontFamily: contants.EDITOR_FONT_FAMILY,
+        fontSize: contants.EDITOR_FONT_SIZE,
         value: this.info.responseBody || '',
         theme: store.get('skin') || 'default'
       })

+ 4 - 1
magic-editor/src/console/src/components/layout/magic-search.vue

@@ -35,6 +35,7 @@ import request from '@/api/request.js'
 import bus from '@/scripts/bus.js'
 import { TokenizationRegistry } from 'monaco-editor/esm/vs/editor/common/modes.js'
 import { tokenizeToString } from 'monaco-editor/esm/vs/editor/common/modes/textToHtmlTokenizer.js'
+import contants from "@/scripts/contants";
 export default {
   name: 'MagicSearch',
   components: {
@@ -76,6 +77,8 @@ export default {
           wordWrap: 'on',
           readOnly: true,
           scrollBeyondLastLine: false,
+          fontFamily: contants.EDITOR_FONT_FAMILY,
+          fontSize: contants.EDITOR_FONT_SIZE,
           theme: store.get('skin') || 'default'
         })
       }
@@ -128,7 +131,7 @@ export default {
       this.searchList.forEach(async item => {
         // 增加关键字高亮
         //item.text = item.text.replace(new RegExp(text, 'g'), `<span class="keyword">${text}</span>`)
-        item.text = (await this.getHighlight(item.text)).replaceAll(/(?<=>)(.|\s)*?(?=<\/?\w+[^<]*>)/g, it=> it.replaceAll(text, `<span class="keyword">${text}</span>`))
+        item.text = (await this.getHighlight(item.text)).replaceAll(/>(.|\s)*?(?=<\/?\w+[^<]*>)/g, it=> it.replaceAll(text, `<span class="keyword">${text}</span>`))
         if (item.type === 1) {
           item.cache = $parent.apiList.getItemById(item.id)
         } else if (item.type === 2) {

+ 6 - 0
magic-editor/src/console/src/components/magic-editor.vue

@@ -117,6 +117,12 @@ export default {
     contants.JDBC_DRIVERS = this.config.jdbcDrivers || []
     contants.DATASOURCE_TYPES = this.config.datasourceTypes || []
     contants.OPTIONS = this.config.options || []
+    if(this.config.editorFontFamily !== undefined){
+      contants.EDITOR_FONT_FAMILY = this.config.editorFontFamily
+    }
+    if(this.config.editorFontSize !== undefined){
+      contants.EDITOR_FONT_SIZE = this.config.editorFontSize
+    }
     this.config.version = contants.MAGIC_API_VERSION_TEXT
     this.config.title = this.config.title || 'magic-api'
     this.config.themes = this.config.themes || {}

+ 2 - 0
magic-editor/src/console/src/components/resources/magic-datasource-list.vue

@@ -313,6 +313,8 @@ export default {
             fixedOverflowWidgets: true,
             folding: true,
             wordWrap: 'on',
+            fontFamily: contants.EDITOR_FONT_FAMILY,
+            fontSize: contants.EDITOR_FONT_SIZE,
             theme: store.get('skin') || 'default',
             value: formatJson(temp) || '{\r\n\t\r\n}'
           })

+ 2 - 0
magic-editor/src/console/src/scripts/contants.js

@@ -25,6 +25,8 @@ const contants = {
   JDBC_DRIVERS: [],
   DATASOURCE_TYPES: [],
   OPTIONS: [],
+  EDITOR_FONT_FAMILY: 'Consolas, "Courier New", monospace',
+  EDITOR_FONT_SIZE: 14,
   config: {}
 }
 

+ 11 - 2
magic-editor/src/console/src/scripts/parsing/parser.js

@@ -790,12 +790,18 @@ export class Parser {
                         expression = value;
                     }
                 } else if (token.getTokenType() === TokenType.Identifier) {
-                    if (['var','let','const'].indexOf(token.getText()) > -1 ) {
+                    let defineName = token.getText()
+                    let define = ['var','let','const'].indexOf(token.getText()) > -1;
+                    if (define || (this.stream.hasMore() && this.stream.getToken().type === TokenType.Identifier)) {
                         let varName = this.stream.consume().getText();
                         if (this.stream.match(TokenType.Assignment, true)) {
                             let isAsync = this.stream.match("async", true);
                             let value = this.parseExpression();
-                            env[varName] = isAsync ? "java.util.concurrent.Future" : await value.getJavaType(env);
+                            if(!define){
+                                env[varName] = env[defineName]
+                            }else{
+                                env[varName] = isAsync ? "java.util.concurrent.Future" : await value.getJavaType(env);
+                            }
                             if (!this.stream.hasMore()) {
                                 expression = value;
                             }
@@ -812,6 +818,9 @@ export class Parser {
 
         }
         if (returnJavaType) {
+            if(expression instanceof VariableAccess){
+                return env[expression.getVariable()];
+            }
             return expression && await expression.getJavaType(env);
         }
         return env;

+ 2 - 2
pom.xml

@@ -5,7 +5,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.ssssssss</groupId>
     <artifactId>magic-api-parent</artifactId>
-    <version>1.4.3</version>
+    <version>1.4.4</version>
     <packaging>pom</packaging>
     <name>magic-api-parent</name>
     <description>auto generate http api</description>
@@ -30,7 +30,7 @@
     </scm>
     <properties>
         <spring-boot.version>2.4.5</spring-boot.version>
-        <magic-script.version>1.5.3</magic-script.version>
+        <magic-script.version>1.5.4</magic-script.version>
         <commons-compress.version>1.21</commons-compress.version>
         <commons-io.version>2.7</commons-io.version>
         <commons-text.version>1.6</commons-text.version>