diff --git a/Front/src/assets/toolbox.json b/Front/src/assets/toolbox.json index 823e0b96fab22bf8e9ccc20756b8edb0d7d828e8..0c6dd2e77593e46ee7a34cc098cef3244703ae8d 100644 --- a/Front/src/assets/toolbox.json +++ b/Front/src/assets/toolbox.json @@ -24,6 +24,10 @@ } } }, + { + "kind": "block", + "type": "console_log" + }, { "kind": "block", "type": "controls_for", @@ -366,7 +370,10 @@ }, { "kind": "block", - "type": "dict_create" + "type": "dict_create", + "extraState": { + "hasPair": true + } }, { "kind": "block", @@ -431,8 +438,12 @@ { "kind": "category", "name": "Sqlite", - "categorystyle": "sqlite", + "categorystyle": "sqlite", "contents": [ + { + "kind": "block", + "type": "sqlite_import" + }, { "kind": "block", "type": "sqlite_open" @@ -450,6 +461,144 @@ "type": "sqlite_close" } ] + }, + { + "kind": "category", + "name": "io", + "categorystyle": "io", + "contents": [ + { + "kind": "block", + "type": "file_open" + }, + { + "kind": "block", + "type": "file_read" + }, + { + "kind": "block", + "type": "file_write" + } + ] + }, + { + "kind": "category", + "name": "数据编码", + "categorystyle": "data_encoding", + "contents": [ + { + "kind": "block", + "type": "base64_import" + }, + { + "kind": "block", + "type": "text_base64_encode" + }, + { + "kind": "block", + "type": "text_base64_decode" + }, + { + "kind": "block", + "type": "json_to_base64" + }, + { + "kind": "block", + "type": "md5_import" + }, + { + "kind": "block", + "type": "md5_hash" + } + ] + }, + { + "kind": "category", + "name": "JSON", + "categorystyle": "json", + "contents": [ + { + "kind": "block", + "type": "json_parse", + "inputs": { + "JSON_STRING": { + "block": { + "type": "text", + "fields": { + "TEXT": "{}" + } + } + } + } + }, + { + "kind": "block", + "type": "json_stringify", + "inline": "true", + "extraState": { + "itemCount": 1 + } + }, + { + "kind": "block", + "type": "json_keys" + }, + { + "kind": "sep", + "gap": "32" + }, + { + "kind": "block", + "type": "json_get_path", + "inputs": { + "PATH": { + "block": { + "type": "text", + "fields": { + "TEXT": "path.to.value" + } + } + } + } + }, + { + "kind": "block", + "type": "json_merge", + "inputs": { + "JSON1": { + "block": { "type": "text" } + }, + "JSON2": { + "block": { "type": "text" } + } + } + }, + { + "kind": "block", + "type": "json_to_base64" + } + ] + }, + { + "kind": "category", + "name": "threading", + "categorystyle": "threading", + "contents": [ + ] + }, + { + "kind": "category", + "name": "turtle", + "categorystyle": "turtle", + "contents": [ + ] + }, + { + "kind": "category", + "name": "subprocess", + "categorystyle": "subprocess", + "contents": [ + ] } ] -} +} \ No newline at end of file diff --git a/Front/src/blocks/boxy.js b/Front/src/blocks/boxy.js index 92f5edea62a30171be20bded9b8b14d1a6c80579..8c53f80171feaf71d9bc852726ceb979483006f0 100644 --- a/Front/src/blocks/boxy.js +++ b/Front/src/blocks/boxy.js @@ -387,15 +387,20 @@ Blockly.defineBlocksWithJsonArray([ }, { type: 'sqlite_query', - message0: '执行查询 %1', + message0: '执行查询 数据库:%1 SQL:%2', args0: [ { type: 'input_value', - name: 'QUERY', + name: 'DB', + check: 'sqlite3.Connection' + }, + { + type: 'input_value', + name: 'SQL', check: 'String' } ], - output: 'sqlite3.Cursor', + output: 'Array', style: 'sqlite', tooltip: '执行SQL查询。' }, @@ -483,7 +488,146 @@ Blockly.defineBlocksWithJsonArray([ style: 'http', tooltip: '发送POST请求。' }, + { //字典 + type: 'json_parse', + message0: '解析JSON字符串 %1', + args0: [ + { + type: 'input_value', + name: 'JSON_STRING', + check: 'String' + } + ], + output: 'Object', + style: 'json', + tooltip: '将JSON字符串解析为Python字典对象' + }, + { + type: 'json_stringify', + message0: '转为JSON字符串 键 %1 值 %2', + args0: [ + { + type: 'input_value', + name: 'KEY', + check: 'String' + }, + { + type: 'input_value', + name: 'VALUE' + } + ], + output: 'String', + style: 'json', + inline: true, + extraState: { + itemCount: 1 + }, + tooltip: '将键值对转换为JSON字符串' + }, + { + type: 'json_keys', + message0: '获取 %1 的所有键', + args0: [ + { + type: 'input_value', + name: 'DICT', + check: 'Object' + } + ], + output: 'Array', + style: 'json', + tooltip: '获取字典对象的所有键列表' + }, + { + type: 'json_get_path', + message0: '获取 %1 路径 %2 的值', + args0: [ + { + type: 'input_value', + name: 'DICT', + check: 'Object' + }, + { + type: 'input_value', + name: 'PATH', + check: 'String' + } + ], + output: 'Any', + style: 'json', + tooltip: '使用点路径语法获取嵌套字典的值' + }, + { + type: 'json_merge', + message0: '合并字典 %1 和 %2', + args0: [ + { + type: 'input_value', + name: 'JSON1', + check: ['Object', 'Array', 'String'] // 添加 Array 类型支持 + }, + { + type: 'input_value', + name: 'JSON2', + check: ['Object', 'Array','String'] // 添加 Array 类型支持 + } + ], + output: 'Object', + style: 'json', + tooltip: '合并两个字典对象' + }, + // 在 http_import 积木之后添加 + { + type: 'base64_import', + message0: '引入base64库', + previousStatement: null, + nextStatement: null, + style: 'json', + tooltip: '引入Base64编码库' + }, + { + type: 'json_to_base64', + message0: '将 %1 转为Base64', + args0: [ + { + type: 'input_value', + name: 'DICT', + check: 'Object' + } + ], + output: 'String', + style: 'json', + tooltip: '将字典对象序列化为Base64编码字符串' + }, + { + type: 'text_base64_encode', + message0: '将 %1 编码为Base64', + args0: [ + { + type: 'input_value', + name: 'TEXT', + check: 'String' + } + ], + output: 'String', + style: 'json', + tooltip: '将文本编码为Base64字符串' + }, + { + type: 'text_base64_decode', + message0: '解码Base64字符串 %1', + args0: [ + { + type: 'input_value', + name: 'BASE64', + check: 'String' + } + ], + output: 'String', + style: 'json', + tooltip: '将Base64字符串解码为原始文本' + }, { type: 'dict_get', message0: '获取字典 %1 的键 %2 的值', @@ -553,5 +697,86 @@ Blockly.defineBlocksWithJsonArray([ output: 'Array', style: 'dict', tooltip: '创建一个空字典。' + }, + { + type:'console_log', + message0: '打印 %1', + args0: [ + { + type: 'input_value', + name: 'VALUE' + } + ], + previousStatement: null, + nextStatement: null, + style: 'controller', + tooltip: '打印值到控制台。' + }, + { + type: 'sqlite_import', + message0: '引入sqlite3库', + previousStatement: null, + nextStatement: null, + style: 'sqlite', + tooltip: '引入sqlite3库。' + }, + // 在已有base64积木之后添加 + { + type: 'md5_import', + message0: '引入哈希库', + previousStatement: null, + nextStatement: null, + style: 'data_encoding', + tooltip: '引入哈希算法支持库' + }, + { + type: 'md5_hash', + message0: '生成MD5哈希 文本 %1', + args0: [ + { + type: 'input_value', + name: 'TEXT', + check: 'String' + } + ], + output: 'String', + style: 'data_encoding', + tooltip: '生成文本的MD5哈希值' + }, + + // 在Blockly.defineBlocksWithJsonArray数组中添加: + { + type: 'file_open', + message0: '打开文件 %1 模式 %2', + args0: [ + {type: 'input_value', name: 'FILENAME', check: 'String'}, + {type: 'field_dropdown', name: 'MODE', + options: [ + ['读取', 'r'], + ['写入', 'w'], + ['追加', 'a'] + ]} + ], + output: null, + style: 'io' + }, + { + type: 'file_read', + message0: '读取文件 %1', + args0: [{type: 'input_value', name: 'FILE', check: 'File'}], + output: 'String', + style: 'io' + }, + { + type: 'file_write', + message0: '写入文件 %1 内容 %2', + args0: [ + {type: 'input_value', name: 'FILE', check: 'File'}, + {type: 'input_value', name: 'CONTENT', check: 'String'} + ], + previousStatement: null, + nextStatement: null, + style: 'io' } + ]) diff --git a/Front/src/components/FilePanel.vue b/Front/src/components/FilePanel.vue index dd34196c4af5fda69294dae2d56c93f0ba5b4d9a..ef4e3c6fc64c8bf9922c5f00acb2538438bfcd41 100644 --- a/Front/src/components/FilePanel.vue +++ b/Front/src/components/FilePanel.vue @@ -2,6 +2,20 @@