mxd před 3 roky
rodič
revize
3268bf5001

+ 60 - 0
src/components/panel/function/magic-function-info.vue

@@ -0,0 +1,60 @@
+<template>
+    <div class="magic-function-info">
+        <form>
+            <label>{{ $i('fn.returnValue') }}</label>
+            <magic-select width="100px" :options="$FUNCTION_RETURN_TYPES" :default-select="$DEFAULT_FUNCTION_RETURN_TYPE" v-model:value="info.method"/>
+            <label>{{ $i('fn.form.name') }}</label>
+            <magic-input v-model:value="info.name" :placeholder="$i('fn.form.placeholder.name')" width="200px"/>
+            <label>{{ $i('fn.form.path') }}</label>
+            <magic-input v-model:value="info.path" :placeholder="$i('fn.form.placeholder.path')" width="auto" style="flex:1"/>
+        </form>
+    </div>
+    <magic-navbar direction="horizontal" ref="navbar" style="flex:1" :allow-close="false">
+        <magic-navbar-item v-for="(navbar, key) in navbars" :key="key" :title="navbar.title">
+            <component :is="navbar.component" :info="info"/>
+        </magic-navbar-item>
+    </magic-navbar>
+</template>
+<script setup>
+import { inject, resolveDynamicComponent } from 'vue'
+import $i from '../../../scripts/i18n.js'
+const info = inject('info')
+const navbars = [{
+    title: $i('fn.parameter'),
+    component: resolveDynamicComponent('magic-function-parameter')
+},{
+    title: $i('fn.description'),
+    component: resolveDynamicComponent('magic-api-description')
+}]
+</script>
+<style scoped>
+.magic-function-info{
+    display: flex;
+    flex-direction: column;
+}
+.magic-function-info form{
+    display: flex;
+    padding: 5px;
+}
+.magic-function-info form label{
+    display: inline-block;
+    height: 22px;
+    line-height: 22px;
+    font-weight: 400;
+    text-align: right;
+    padding: 0 5px;
+    padding-left: 20px;
+}
+.magic-navbar{
+    flex-direction: column;
+    overflow: hidden;
+}
+.magic-navbar :deep(.magic-navbar-header){
+    border-bottom: 1px solid var(--main-border-color);
+}
+.magic-navbar :deep(.magic-navbar-body),
+.magic-navbar :deep(.magic-navbar-item){
+    width: 100%;
+    height: 100%;
+}
+</style>

+ 12 - 5
src/plugins/monaco-editor-nls.js

@@ -21,8 +21,11 @@ const initLanguage = (rstObj, en, langObj) => {
 const dir = './node_modules/monaco-editor/dev/vs/editor/editor.main.nls'
 const language = {}
 const fs = require('fs')
-const read = path => eval('(' + fs.readFileSync(path, 'utf8').replace(/[\s\S]+define\("[a-zA-Z/\.\-]+", ({[\s\S]+})\);$/g, '$1').replace(/,\s+]/g, ']') + ')')
-initLanguage(language, read(`${dir}.js`), read(`${dir}.zh-cn.js`))
+const read = path => eval('(' + fs.readFileSync(path, 'utf8').replace(/[\s\S]+define\("[a-zA-Z/\.\-]+", ({[\s\S]+})\);$/g, '$1').replace(/,\s+]/g, ']') + ')');
+['zh-cn'].forEach(it => {
+	language[`${it}`] = {}
+	initLanguage(language[`${it}`], read(`${dir}.js`), read(`${dir}.${it}.js`))
+})
 export function MonacoEditorNls(esbuild) {
 	if(esbuild){
 		return {
@@ -50,6 +53,7 @@ function getLocalizeCode(){
 	return `
 		const mapLangIdx = ${JSON.stringify(mapLangIdx)};
 		const mapNlsLang = ${JSON.stringify(language)};
+		const locale = localStorage.getItem('magic-locale') || 'zh-cn'
 		function _format(message, args) {
 			let result;
 			if (args.length === 0) {
@@ -64,9 +68,12 @@ function getLocalizeCode(){
 			return result;
 		}
 		export function localize(data, message) {
-			let idx = mapLangIdx[message] || -1;
-			if(idx in mapNlsLang){
-				message = mapNlsLang[idx]; 
+			if (locale !== 'en') {
+				let idx = mapLangIdx[message] || -1;
+				const lang = mapNlsLang[locale]
+				if(idx in lang){
+					message = lang[idx]; 
+				}	
 			}
 			const args = []
 			for(var i = 0, len = arguments.length; i < len; ++i){

+ 23 - 1
src/scripts/i18n.js

@@ -7,7 +7,7 @@ if(localeName === 'en'){
     locale = en
 }
 
-export default function(key, ...args){
+export default function doLocale(key, ...args){
     try{
         const msg = key.split('.').reduce((val, k) => val[k], locale);
         if(msg && args.length > 0){
@@ -18,3 +18,25 @@ export default function(key, ...args){
         return key
     }
 }
+
+
+export function translateCode(code, message){
+    if(zhCN === locale){
+        return message
+    }
+    const src = zhCN.code[`${code}`]
+    const target = locale.code[`${code}`]
+    if(src && target){
+        const regex = src.replace(/([()\[\]\.])/g, '\\$1').replace(/{\d+}/g, '(.*?)')
+        if(regex){
+            const result = []
+            const exp = new RegExp(regex, 'g')
+            let str
+            while((str = exp.exec(message)) != null){
+                result.push(str)
+            }
+            return doLocale(`code.${code}`, result.splice(0, 1))
+        }
+    }
+    return message
+}

+ 43 - 1
src/scripts/i18n/en.js

@@ -80,7 +80,7 @@ export default {
 
         newVersionRelease: 'New Version {0} available',
         versionLastest: 'Current Version is Lastese',
-        versionUpdate: 'New Version {0} available, Upgrade?',
+        versionUpdate: 'New Version {0} available<br>Do you want Upgrade?',
         changelog: 'CHANGELOG',
         versionConflict: 'Version does not matched frontend: {0}, backend: {1}, Please Check!',
         versionCheck: 'Version Check',
@@ -307,6 +307,48 @@ export default {
     log: {
         hide: 'Click to hide multiline log',
         show: '{0} lines of log are hidden, Click to show'
+    },
+    code: {
+        'error': 'Error({0})',
+        'invalid': 'Error,HttpStatus({0})',
+        'httpError': 'Error',
+        '-2': 'Current is Readonly, Cannot be Operated',
+        '-10': 'Unauthorized Operation',
+        '1001': 'Group Not Found',
+        '1002': 'Not Support the Group Type',
+        '1003': 'Remote Cannot be empty',
+        '1004': 'secretKey Cannot be empty',
+        '1005': 'The name will repeat after moving. Please modify the name and try again.',
+        '1006': 'Source object and grouping cannot be consistent',
+        '1007': 'Resoirce Not Found',
+        '1008': 'The current resource has been locked. Please operate after unlocking',
+        '1009': 'This path has been used. Please try another path',
+        '1010': 'There are conflicts in resource [{0}], please check',
+        '1011': 'The path will conflict after moving. Please try another path',
+        '1012': 'Request Method Cannot be empty',
+        '1013': 'Reqeust Path Cannot be empty',
+        '1014': 'Function Path Cannot be empty',
+        '1015': 'The configured file path does not exist, please check',
+        '1016': 'The Api [{0} ({1})] conflicts with the application and cannot be registered',
+        '1017': 'Script Cannot be empty',
+        '1018': 'Name Cannot be empty',
+        '1019': 'Path Cannot be empty',
+        '1020': 'jdbcURL Cannot be empty',
+        '1021': 'key Cannot be empty',
+        '1022': 'The data source key has been used. Please replace it and try again',
+        '1023': 'Please Choose Group',
+        '1024': 'Cron Expression Cannot be empty',
+        '1025': 'The name cannot contain special characters. Only Chinese, numbers, letters and +-.() and . cannot be start',
+        '1026': 'The data source key cannot contain special characters, only Chinese, numbers, letters, _',
+        '1027': 'Failed to save. The group name under the same group cannot be duplicate and cannot contain special characters.',
+        '1028': 'Parameter validation failed',
+        '1029': 'Header validation failed',
+        '1030': 'PathVariable validation failed',
+        '1031': 'RequestBody validation failed',
+        '1032': '请上传文件',
+        '1033': 'Failed to validate Signature. Please check whether the secret key is correct',
+        '1034': 'Backup is not enabled and cannot be operated',
+        '1035': 'Api Not Found'
     }
 
 }

+ 42 - 0
src/scripts/i18n/zh-cn.js

@@ -311,4 +311,46 @@ export default {
         hide: '点击隐藏多行日志',
         show: '有 {0} 行日志被隐藏,点击显示'
     },
+    code: {
+        'error': '请求出错,异常代码({0})',
+        'invalid': '请求出错,HttpStatus({0})',
+        'httpError': '请求出错',
+        '-2': '当前为只读模式,无法操作',
+        '-10': '无权限操作。',
+        '1001': '找不到分组信息',
+        '1002': '不支持该分组类型',
+        '1003': '目标网址不能为空',
+        '1004': 'secretKey不能为空',
+        '1005': '移动后名称会重复,请修改名称后在试。',
+        '1006': '源对象和分组不能一致',
+        '1007': '找不到对应文件或分组',
+        '1008': '当前资源已被锁定,请解锁后在操作。',
+        '1009': '该路径已被使用,请换一个路径在试',
+        '1010': '资源中[{0}]有冲突,请检查',
+        '1011': '移动后路径会冲突,请换一个路径在试',
+        '1012': '请求方法不能为空',
+        '1013': '请求路径不能为空',
+        '1014': '函数路径不能为空',
+        '1015': '配置的文件路径不存在,请检查',
+        '1016': '接口[{0}({1})]与应用冲突,无法注册',
+        '1017': '脚本内容不能为空',
+        '1018': '名称不能为空',
+        '1019': '路径不能为空',
+        '1020': 'jdbcURL不能为空',
+        '1021': 'key不能为空',
+        '1022': '数据源key已被使用,请更换后在试',
+        '1023': '请选择分组',
+        '1024': 'cron表达式不能为空',
+        '1025': '名称不能包含特殊字符,只允许中文、数字、字母以及+_-.()的组合且不能.开头',
+        '1026': '数据源Key不能包含特殊字符,只允许中文、数字、字母以及_组合',
+        '1027': '保存失败,同一组下分组名称不能重复且不能包含特殊字符。',
+        '1028': '参数验证失败',
+        '1029': 'header验证失败',
+        '1030': '路径变量验证失败',
+        '1031': 'body验证失败',
+        '1032': '请上传文件',
+        '1033': '签名验证失败,请检查秘钥是否正确',
+        '1034': '未启用备份,无法操作',
+        '1035': '找不到接口'
+    }
 }

+ 4 - 3
src/scripts/request.js

@@ -2,6 +2,7 @@ import axios from 'axios'
 import Qs from 'qs'
 import constants from './constants.js'
 import modal from '../components/common/dialog/magic-modal.js'
+import { default as $i, translateCode } from './i18n.js'
 const config = {
 	// 请求路径
 	baseURL: '',
@@ -56,7 +57,7 @@ class HttpResponse {
 
 	// 异常回调,实际上的code != 1的
 	exceptionHandle = (code, message) => {
-		modal.alert(message, `请求出错,异常代码(${code})`)
+		modal.alert(translateCode(code, message), $i('code.error', code))
 	}
 
 	// 调用返回成功需要注入的变量
@@ -109,9 +110,9 @@ class HttpRequest {
 
 	processError(error) {
 		if (error.response) {
-			modal.alert(JSON.stringify(error.response.data || '') || `请求出错HttpStatus:(${error.response.status})`, `请求出错HttpStatus:(${error.response.status})`)
+			modal.alert(JSON.stringify(error.response.data || '') || $i('code.invalid', error.response.status), $i('code.invalid', error.response.status))
 		} else {
-			modal.alert(error.message, `请求出错`)
+			modal.alert(error.message, $i('code.httpError'))
 		}
 		console.error(error)
 	}