From eec9b3f6137aec470f78adf1a4a850604b056bee Mon Sep 17 00:00:00 2001 From: CodeKpy <1942171924@qq.com> Date: Thu, 20 Mar 2025 02:40:00 +0000 Subject: [PATCH 01/33] =?UTF-8?q?todo=EF=BC=9A=E7=8E=AF=E5=A2=83=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: CodeKpy <1942171924@qq.com> --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 912d392..d15a4d8 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,8 @@ import os #from pipVersion import package_name +# TODO: 实现环境切换 + app = Flask(__name__, template_folder='dist', static_folder='dist/assets') # 判断是否存在project虚拟环境,不存在则创建 -- Gitee From b403ec9f464288833e176da6e5d4b9f609809a2f Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Fri, 28 Mar 2025 23:30:24 +0800 Subject: [PATCH 02/33] =?UTF-8?q?upd=EF=BC=9A=E6=9B=B4=E6=96=B0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=AE=A1=E7=90=86=20upd=EF=BC=9A=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/Navigator.vue | 31 ++++++++++++-- dist/index.html | 4 +- dist/sw.js | 2 +- main.py | 66 +++++++++++++----------------- pipList.py | 22 ++++++++-- 5 files changed, 79 insertions(+), 46 deletions(-) diff --git a/Front/src/components/Navigator.vue b/Front/src/components/Navigator.vue index adc9a9e..006c2cc 100644 --- a/Front/src/components/Navigator.vue +++ b/Front/src/components/Navigator.vue @@ -6,9 +6,11 @@ diff --git a/dist/index.html b/dist/index.html index 06acd44..88dcd45 100644 --- a/dist/index.html +++ b/dist/index.html @@ -11,8 +11,8 @@ Boxy - - + +
diff --git a/dist/sw.js b/dist/sw.js index d18a71f..4591b5f 100644 --- a/dist/sw.js +++ b/dist/sw.js @@ -1 +1 @@ -if(!self.define){let e,s={};const n=(n,i)=>(n=new URL(n+".js",i).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(i,t)=>{const o=e||("document"in self?document.currentScript.src:"")||location.href;if(s[o])return;let r={};const d=e=>n(e,o),l={module:{uri:o},exports:r,require:d};s[o]=Promise.all(i.map((e=>l[e]||d(e)))).then((e=>(t(...e),r)))}}define(["./workbox-bf1ed05b"],(function(e){"use strict";self.addEventListener("message",(e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()})),e.precacheAndRoute([{url:"assets/index-825ada8c.css",revision:null},{url:"assets/index-c7dda4ec.js",revision:null},{url:"assets/workbox-window.prod.es5-a7b12eab.js",revision:null},{url:"index.html",revision:"fcba879ad48e951ddbf02309fcba724d"},{url:"manifest.webmanifest",revision:"4fd5a74a9ab05dcb5196ecee501098a3"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html"))),e.registerRoute(/.*/i,new e.NetworkFirst({cacheName:"boxy-cache",plugins:[new e.ExpirationPlugin({maxEntries:10,maxAgeSeconds:2592e3}),new e.CacheableResponsePlugin({statuses:[0,200]})]}),"GET")})); +if(!self.define){let e,s={};const n=(n,i)=>(n=new URL(n+".js",i).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(i,t)=>{const o=e||("document"in self?document.currentScript.src:"")||location.href;if(s[o])return;let r={};const l=e=>n(e,o),c={module:{uri:o},exports:r,require:l};s[o]=Promise.all(i.map((e=>c[e]||l(e)))).then((e=>(t(...e),r)))}}define(["./workbox-bf1ed05b"],(function(e){"use strict";self.addEventListener("message",(e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()})),e.precacheAndRoute([{url:"assets/index-0a3c8d20.css",revision:null},{url:"assets/index-bd1bd066.js",revision:null},{url:"assets/workbox-window.prod.es5-a7b12eab.js",revision:null},{url:"index.html",revision:"9b07baf44f950c769998abf7ac15c1d0"},{url:"manifest.webmanifest",revision:"4fd5a74a9ab05dcb5196ecee501098a3"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html"))),e.registerRoute(/.*/i,new e.NetworkFirst({cacheName:"boxy-cache",plugins:[new e.ExpirationPlugin({maxEntries:10,maxAgeSeconds:2592e3}),new e.CacheableResponsePlugin({statuses:[0,200]})]}),"GET")})); diff --git a/main.py b/main.py index 912d392..34e9976 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ time: 2025 author: CodeKpy & Coconut Studio """ +import json #from click import command from flask import Flask, render_template, request, jsonify @@ -20,11 +21,6 @@ if not os.path.exists('project'): os.system('python -m venv project') venv_path = "/project" -# Windows系统 -activate_script = f"{venv_path}\\Scripts\\activate" - -# 执行激活虚拟环境的命令 -#subprocess.run(activate_script, shell=True) # 定义一个路由,当访问根目录时,返回editor.html模板 @app.route('/') @@ -42,39 +38,24 @@ def static_proxy(path): def api(api): if api == 'pipList': # 获取pip列表,调用cmd命令,进入project虚拟环境,获取内容, - result = pipList.main() - """result = subprocess.check_output(['pip', 'freeze']).decode('utf-8')""" - # 将内容按行分割制作JSON - # 按行分割输出 - lines = result.split('\n') - - # 解析每一行并存储为字典 - packages = [] - i = 0 - for line in lines: - if i >1: - if line.strip(): # 跳过空行 - parts = line.split() # 默认按空格分割 - if len(parts) >= 2: - package = parts[0] - version = parts[1] - packages.append({"Package": package, "Version": version}) - else: - i += 1 - - # 返回JSON - print(result) - return {'pipList': packages} + current_project_path = request.cookies.get('currentProjectPath') + result = pipList.main(current_project_path) + return {'pipList': result} elif api == 'pyVenv': + # 获取post参数name,path + name = request.args.get('name') + path = request.args.get('path') # 新建Python "project"虚拟环境 - - os.system('python -m venv project') + os.system('python -m venv '+path+'\\'+name) return {'pyVenv': 'success'} elif api == 'pipInstall': # 从 GET 请求中读取参数 package_name = request.args.get('packageName') install_source = request.args.get('installSource') + # 读取Cookie-currentProjectPath,若无则为'./project' + current_project_path = request.cookies.get('currentProjectPath') or './project' + # 检查参数是否为空 if not package_name: return jsonify({'error': 'packageName is required'}), 400 @@ -85,13 +66,7 @@ def api(api): print(f"Package Name: {package_name}") print(f"Install Source: {install_source}") - - # result = subprocess.run(['pip', 'install', package_name, '-i', install_source],shell=True, capture_output=True, text=True, encoding="utf-8") - - """# 使用 Popen 执行命令并捕获输出 - process = subprocess.Popen(r'.\project\Scripts\activate && && ' + f'pip install {package_name} -i {install_source}', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="cp936") - stdout, stderr = process.communicate()""" - command = r'.\project\Scripts\activate && pip install '+package_name+' -i ' + install_source + command = current_project_path+r'\Scripts\activate && pip install '+package_name+' -i ' + install_source print(command) process = subprocess.Popen( command, @@ -104,6 +79,23 @@ def api(api): return jsonify({'success': 'Package installed successfully'}) else: return jsonify({'error': 'Failed to install package'}), 500 + elif api == 'project_list': + # 读取project.json + with open('project.json', 'r') as f: + project_list = json.load(f) + return jsonify(project_list) + elif api == 'file_list': + # 获取Cookie-currentProjectPath,若无则为'./project' + current_project_path = request.cookies.get('currentProjectPath') or './project' + # 获取currentProjectPath下的所有后缀为.boxy文件列表,返回字段为name, path, time + file_list = [] + for file in os.listdir(current_project_path): + if file.endswith('.boxy'): + file_path = os.path.join(current_project_path, file) + file_time = os.path.getmtime(file_path) + file_list.append({'name': file, 'path': file_path, 'time': file_time}) + file_list.sort(key=lambda x: x['time'], reverse=True) + return jsonify(file_list) diff --git a/pipList.py b/pipList.py index f789d2b..ec2ee5b 100644 --- a/pipList.py +++ b/pipList.py @@ -1,6 +1,6 @@ import subprocess -venv_path = r".\project" +# venv_path = r".\project" # 激活虚拟环境并获取 pip 列表 def get_pip_list(venv_path): @@ -26,13 +26,29 @@ def get_pip_list(venv_path): # 主函数 -def main(): +def main(current_project_path): # 获取 pip 列表 + venv_path = current_project_path pip_list = get_pip_list(venv_path) # 打印 pip 列表 print(pip_list) - return pip_list + lines = pip_list.split('\n') + # 解析每一行并存储为字典 + packages = [] + i = 0 + for line in lines: + if i > 1: + if line.strip(): # 跳过空行 + parts = line.split() # 默认按空格分割 + if len(parts) >= 2: + package = parts[0] + version = parts[1] + packages.append({"Package": package, "Version": version}) + else: + i += 1 + print(packages) + return packages if __name__ == "__main__": -- Gitee From ff7ac2850390d02c7cd7990d3eab42f017ccb6ba Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Fri, 28 Mar 2025 23:30:46 +0800 Subject: [PATCH 03/33] =?UTF-8?q?upd=EF=BC=9A=E6=9B=B4=E6=96=B0gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 47f6893..8482d91 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ bin-release/ .idea/ ./node_modules/ +./project.json + # Executables *.swf *.air -- Gitee From 9b46f26b362afb8fccacfc1d54fa546305a1095c Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 00:48:32 +0800 Subject: [PATCH 04/33] =?UTF-8?q?upd=EF=BC=9A=E6=9B=B4=E6=96=B0=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/Navigator.vue | 85 ++++++++++++++++-------------- Front/src/main.js | 1 + dist/index.html | 4 +- dist/sw.js | 2 +- main.py | 34 +++++++++++- 5 files changed, 82 insertions(+), 44 deletions(-) diff --git a/Front/src/components/Navigator.vue b/Front/src/components/Navigator.vue index 006c2cc..f740e00 100644 --- a/Front/src/components/Navigator.vue +++ b/Front/src/components/Navigator.vue @@ -22,19 +22,19 @@ - + - + +
diff --git a/dist/sw.js b/dist/sw.js index 4591b5f..52307b5 100644 --- a/dist/sw.js +++ b/dist/sw.js @@ -1 +1 @@ -if(!self.define){let e,s={};const n=(n,i)=>(n=new URL(n+".js",i).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(i,t)=>{const o=e||("document"in self?document.currentScript.src:"")||location.href;if(s[o])return;let r={};const l=e=>n(e,o),c={module:{uri:o},exports:r,require:l};s[o]=Promise.all(i.map((e=>c[e]||l(e)))).then((e=>(t(...e),r)))}}define(["./workbox-bf1ed05b"],(function(e){"use strict";self.addEventListener("message",(e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()})),e.precacheAndRoute([{url:"assets/index-0a3c8d20.css",revision:null},{url:"assets/index-bd1bd066.js",revision:null},{url:"assets/workbox-window.prod.es5-a7b12eab.js",revision:null},{url:"index.html",revision:"9b07baf44f950c769998abf7ac15c1d0"},{url:"manifest.webmanifest",revision:"4fd5a74a9ab05dcb5196ecee501098a3"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html"))),e.registerRoute(/.*/i,new e.NetworkFirst({cacheName:"boxy-cache",plugins:[new e.ExpirationPlugin({maxEntries:10,maxAgeSeconds:2592e3}),new e.CacheableResponsePlugin({statuses:[0,200]})]}),"GET")})); +if(!self.define){let e,s={};const n=(n,i)=>(n=new URL(n+".js",i).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(i,t)=>{const o=e||("document"in self?document.currentScript.src:"")||location.href;if(s[o])return;let r={};const l=e=>n(e,o),d={module:{uri:o},exports:r,require:l};s[o]=Promise.all(i.map((e=>d[e]||l(e)))).then((e=>(t(...e),r)))}}define(["./workbox-bf1ed05b"],(function(e){"use strict";self.addEventListener("message",(e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()})),e.precacheAndRoute([{url:"assets/index-0a3c8d20.css",revision:null},{url:"assets/index-40d8fe94.js",revision:null},{url:"assets/workbox-window.prod.es5-a7b12eab.js",revision:null},{url:"index.html",revision:"64a1a205f98e21ffb9a6d72b226bdb01"},{url:"manifest.webmanifest",revision:"4fd5a74a9ab05dcb5196ecee501098a3"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html"))),e.registerRoute(/.*/i,new e.NetworkFirst({cacheName:"boxy-cache",plugins:[new e.ExpirationPlugin({maxEntries:10,maxAgeSeconds:2592e3}),new e.CacheableResponsePlugin({statuses:[0,200]})]}),"GET")})); diff --git a/main.py b/main.py index 6c865eb..f46080f 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ time: 2025 author: CodeKpy & Coconut Studio """ +import base64 import json #from click import command @@ -21,6 +22,10 @@ app = Flask(__name__, template_folder='dist', static_folder='dist/assets') if not os.path.exists('project'): import os os.system('python -m venv project') + # 写入project.json + with open('project.json', 'w') as f: + # 获取./project的绝对路径 + f.write(json.dumps({'title': 'project', 'path': './project'})) venv_path = "/project" @@ -36,7 +41,7 @@ def static_proxy(path): return app.send_static_file(path) # api -@app.route('/api/') +@app.route('/api/', methods=['GET', 'POST']) def api(api): if api == 'pipList': # 获取pip列表,调用cmd命令,进入project虚拟环境,获取内容, @@ -98,6 +103,33 @@ def api(api): file_list.append({'name': file, 'path': file_path, 'time': file_time}) file_list.sort(key=lambda x: x['time'], reverse=True) return jsonify(file_list) + elif api == 'get_file': + # 获取Cookie-currentFilePath + current_file_path = request.cookies.get('currentFilePath') + # 读取文件内容 + with open(current_file_path, 'r') as f: + file_content = f.read() + # 转换为base64 + file_content = base64.b64encode(file_content.encode('utf-8')).decode('utf-8') + return jsonify({'file_content': file_content}) + elif api == 'save_file': + data = request.json # 获取 JSON 数据 + path = data.get('path') + content = data.get('content') + code = data.get('code') + + # base64解码转换为utf-8 + file_content = base64.b64decode(content).decode('utf-8') + code = base64.b64decode(code).decode('utf-8') + try: + # 写入文件 + with open(path, 'w') as f: + f.write(file_content) + with open(path.replace('.boxy', '.py'), 'w') as f: + f.write(code) + return jsonify({'success': True}) + except Exception as e: + return jsonify({'success': False, 'error': str(e)}), 500 -- Gitee From e17b29f9097c5de44a460785dfea7155eee08546 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 11:59:52 +0800 Subject: [PATCH 05/33] =?UTF-8?q?upd=EF=BC=9A=E6=8E=A8=E9=80=81=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=AE=A1=E7=90=86=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/Pj.vue | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Front/src/components/Pj.vue diff --git a/Front/src/components/Pj.vue b/Front/src/components/Pj.vue new file mode 100644 index 0000000..edc1e41 --- /dev/null +++ b/Front/src/components/Pj.vue @@ -0,0 +1,82 @@ + + + + + \ No newline at end of file -- Gitee From ea6dc483cab19bd7a6a16f2e894404c1211195c7 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 12:02:07 +0800 Subject: [PATCH 06/33] =?UTF-8?q?upd=EF=BC=9A=E6=8E=A8=E9=80=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=AE=A1=E7=90=86=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/FilePanel.vue | 136 +++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Front/src/components/FilePanel.vue diff --git a/Front/src/components/FilePanel.vue b/Front/src/components/FilePanel.vue new file mode 100644 index 0000000..4bf8d79 --- /dev/null +++ b/Front/src/components/FilePanel.vue @@ -0,0 +1,136 @@ + + + + + -- Gitee From 117be929eccc94f02c97c92d0a40a7d87cc8c262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=8FXeLa?= Date: Sat, 29 Mar 2025 12:08:10 +0800 Subject: [PATCH 07/33] =?UTF-8?q?feat:=20=E5=9C=A8vite=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=8B=E4=BD=BF=E7=94=A8api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- Front/.gitignore | 2 ++ Front/vite.config.js | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8482d91..ad178b5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,8 @@ bin-release/ .idea/ ./node_modules/ -./project.json +project.json +__pycache__ # Executables *.swf diff --git a/Front/.gitignore b/Front/.gitignore index 135000e..bd223d3 100644 --- a/Front/.gitignore +++ b/Front/.gitignore @@ -28,3 +28,5 @@ coverage *.njsproj *.sln *.sw? + +pnpm-lock.yaml \ No newline at end of file diff --git a/Front/vite.config.js b/Front/vite.config.js index 70106ed..0279696 100644 --- a/Front/vite.config.js +++ b/Front/vite.config.js @@ -7,6 +7,11 @@ import viteCompression from 'vite-plugin-compression' import { VitePWA } from 'vite-plugin-pwa' export default defineConfig({ + server:{ + proxy:{ + '/api': 'http://localhost:5000/', + }, + }, plugins: [ vue(), vitePluginForArco({ theme: '@arco-themes/vue-boxy', style: true }), -- Gitee From 3e7bb9dde138bb802833b9d0efa817c0ab9ea69d Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 12:32:18 +0800 Subject: [PATCH 08/33] =?UTF-8?q?bugfix=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=9B=AE=E5=BD=95=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index f46080f..85c31bb 100644 --- a/main.py +++ b/main.py @@ -10,11 +10,26 @@ from flask import Flask, render_template, request, jsonify import pipList import subprocess import os +import sys #from urllib.parse import unquote #from pipVersion import package_name +# 默认环境 +venv_path = "./project" + # TODO: 实现环境切换 +# 获取当前程序的路径 +if getattr(sys, 'frozen', False): + # 打包后的可执行文件路径 + current_executable_path = sys.executable +else: + # 普通脚本文件路径 + current_executable_path = os.path.abspath(__file__) + +print(f"当前程序的路径: {current_executable_path}") +current_executable_dir = os.path.dirname(current_executable_path) +print(f"当前程序所在的目录: {current_executable_dir}") app = Flask(__name__, template_folder='dist', static_folder='dist/assets') @@ -22,12 +37,35 @@ app = Flask(__name__, template_folder='dist', static_folder='dist/assets') if not os.path.exists('project'): import os os.system('python -m venv project') - # 写入project.json - with open('project.json', 'w') as f: - # 获取./project的绝对路径 - f.write(json.dumps({'title': 'project', 'path': './project'})) -venv_path = "/project" + # 获取./project的绝对路径 + # 起始目录 + base_dir = current_executable_dir + # 相对路径 + relative_path = venv_path + # 获取绝对路径 + absolute_path = os.path.abspath(os.path.join(base_dir, relative_path)) + + # 读取project.json,若不存在则创建 + if not os.path.exists('project.json'): + with open('project.json', 'w') as f: + f.write(json.dumps([{'title': 'project', 'path': absolute_path}])) + else: + # 读取project.json + with open('project.json', 'r') as f: + data = json.load(f) + # 检查是否已经存在 + for item in data: + if item['path'] == absolute_path: + break + else: # 不存在则添加 + data.append({'title': 'project', 'path': absolute_path}) + + # 写入 + with open('project.json', 'w') as f: + f.write(json.dumps(data)) + + # 定义一个路由,当访问根目录时,返回editor.html模板 @app.route('/') -- Gitee From 30f9580907a33417599d4f32c6d44fcfaedc069f Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 12:38:40 +0800 Subject: [PATCH 09/33] =?UTF-8?q?bugfix=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 85c31bb..cf0be7c 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,13 @@ else: print(f"当前程序的路径: {current_executable_path}") current_executable_dir = os.path.dirname(current_executable_path) print(f"当前程序所在的目录: {current_executable_dir}") +# 获取./project的绝对路径 +# 起始目录 +base_dir = current_executable_dir +# 相对路径 +relative_path = venv_path +# 获取绝对路径 +absolute_path = os.path.abspath(os.path.join(base_dir, relative_path)) app = Flask(__name__, template_folder='dist', static_folder='dist/assets') @@ -38,14 +45,6 @@ if not os.path.exists('project'): import os os.system('python -m venv project') - # 获取./project的绝对路径 - # 起始目录 - base_dir = current_executable_dir - # 相对路径 - relative_path = venv_path - # 获取绝对路径 - absolute_path = os.path.abspath(os.path.join(base_dir, relative_path)) - # 读取project.json,若不存在则创建 if not os.path.exists('project.json'): with open('project.json', 'w') as f: @@ -66,7 +65,6 @@ if not os.path.exists('project'): f.write(json.dumps(data)) - # 定义一个路由,当访问根目录时,返回editor.html模板 @app.route('/') def index(): @@ -98,8 +96,8 @@ def api(api): package_name = request.args.get('packageName') install_source = request.args.get('installSource') - # 读取Cookie-currentProjectPath,若无则为'./project' - current_project_path = request.cookies.get('currentProjectPath') or './project' + # 读取Cookie-currentProjectPath,若无则为absolute_path + current_project_path = request.cookies.get('currentProjectPath') or absolute_path # 检查参数是否为空 if not package_name: @@ -131,7 +129,7 @@ def api(api): return jsonify(project_list) elif api == 'file_list': # 获取Cookie-currentProjectPath,若无则为'./project' - current_project_path = request.cookies.get('currentProjectPath') or './project' + current_project_path = request.cookies.get('currentProjectPath') or absolute_path # 获取currentProjectPath下的所有后缀为.boxy文件列表,返回字段为name, path, time file_list = [] for file in os.listdir(current_project_path): -- Gitee From ac34533d06820a2a970e0ad602a14b9cbaa15a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=8FXeLa?= Date: Sat, 29 Mar 2025 13:37:47 +0800 Subject: [PATCH 10/33] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 7 +++++-- pipList.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index cf0be7c..b89c042 100644 --- a/main.py +++ b/main.py @@ -81,7 +81,7 @@ def static_proxy(path): def api(api): if api == 'pipList': # 获取pip列表,调用cmd命令,进入project虚拟环境,获取内容, - current_project_path = request.cookies.get('currentProjectPath') + current_project_path = request.cookies.get('currentProjectPath') or absolute_path result = pipList.main(current_project_path) return {'pipList': result} elif api == 'pyVenv': @@ -109,7 +109,7 @@ def api(api): print(f"Package Name: {package_name}") print(f"Install Source: {install_source}") - command = current_project_path+r'\Scripts\activate && pip install '+package_name+' -i ' + install_source + command = os.path.join(current_project_path, 'Scripts', 'activate') + r' && pip install '+package_name+' -i ' + install_source print(command) process = subprocess.Popen( command, @@ -117,6 +117,9 @@ def api(api): stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="cp936") stdout, stderr = process.communicate() + print(stdout) + print(stderr) + # 检查命令是否成功执行 if process.returncode == 0: return jsonify({'success': 'Package installed successfully'}) diff --git a/pipList.py b/pipList.py index ec2ee5b..7fbaf77 100644 --- a/pipList.py +++ b/pipList.py @@ -1,11 +1,12 @@ import subprocess +import os # venv_path = r".\project" # 激活虚拟环境并获取 pip 列表 def get_pip_list(venv_path): # 构造激活虚拟环境和获取 pip 列表的命令 - activate_script = f"{venv_path}\\Scripts\\activate" + activate_script = os.path.join(venv_path, 'Scripts', 'activate') pip_list_command = "pip list" # 使用 shell 执行命令 -- Gitee From 6c54a75cd0104bd0979f1822b56769dfc0667bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=8FXeLa?= Date: Sat, 29 Mar 2025 13:38:08 +0800 Subject: [PATCH 11/33] =?UTF-8?q?upd:=20=E6=B7=BB=E5=8A=A0=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/Pip.vue | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Front/src/components/Pip.vue b/Front/src/components/Pip.vue index 1c10b12..2e5ef2e 100644 --- a/Front/src/components/Pip.vue +++ b/Front/src/components/Pip.vue @@ -3,20 +3,26 @@ + + + + + + + 新建文件 + + + \ No newline at end of file -- Gitee From d0ad13c929fcf41bce4c6c4f3a156c0a8e636887 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 14:28:13 +0800 Subject: [PATCH 27/33] =?UTF-8?q?bugfix=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=B7=B2=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/Navigator.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Front/src/components/Navigator.vue b/Front/src/components/Navigator.vue index f740e00..fab77fb 100644 --- a/Front/src/components/Navigator.vue +++ b/Front/src/components/Navigator.vue @@ -43,6 +43,8 @@ const pjModal = ref() const store = useStore() const Filepanel = ref() + + function handleIconClick() { Blockly.hideChaff() } -- Gitee From 3114e4e9ff35441ec36cb15a5abfcd86e3673e3e Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 14:28:36 +0800 Subject: [PATCH 28/33] =?UTF-8?q?upd=EF=BC=9A=E6=96=B0=E5=A2=9E/api/get=5F?= =?UTF-8?q?absolute=5Fpath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index cf0be7c..b6fa728 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ import base64 import json #from click import command -from flask import Flask, render_template, request, jsonify +from flask import Flask, render_template, request, jsonify, make_response import pipList import subprocess import os @@ -68,6 +68,13 @@ if not os.path.exists('project'): # 定义一个路由,当访问根目录时,返回editor.html模板 @app.route('/') def index(): + # 如果 Cookie 不存在或为空,设置一个默认值 + if not request.cookies.get('currentProjectPath'): + # 创建一个响应对象 + response = make_response(render_template('index.html')) + # 设置 Cookie + response.set_cookie('currentProjectPath', value='/default/path', max_age=3600*24*7) + return response return render_template('index.html') # dist/下的路径全部自动返回 @@ -79,6 +86,12 @@ def static_proxy(path): # api @app.route('/api/', methods=['GET', 'POST']) def api(api): + if not request.cookies.get('currentProjectPath'): + # 创建一个响应对象 + response = make_response(render_template('index.html')) + # 设置 Cookie + response.set_cookie('currentProjectPath', value='/default/path', max_age=3600*24*7) + return response if api == 'pipList': # 获取pip列表,调用cmd命令,进入project虚拟环境,获取内容, current_project_path = request.cookies.get('currentProjectPath') @@ -166,8 +179,11 @@ def api(api): return jsonify({'success': True}) except Exception as e: return jsonify({'success': False, 'error': str(e)}), 500 - - + elif api == 'get_absolute_path': + name = request.args.get('name') + current_project_path = request.cookies.get('currentProjectPath') or absolute_path + # os.path.abspath(os.path.join(current_project_path, name)) + return jsonify({'absolute_path': os.path.join(current_project_path, name)}) if __name__ == '__main__': app.run(debug=True) -- Gitee From e50d9f3eb046119c0e60beb0fe46d7d727c34140 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 29 Mar 2025 14:29:04 +0800 Subject: [PATCH 29/33] =?UTF-8?q?upd=EF=BC=9A=E6=96=B0=E5=A2=9E=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=8F=8D=E9=A6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/src/components/Pj.vue | 170 +++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 78 deletions(-) diff --git a/Front/src/components/Pj.vue b/Front/src/components/Pj.vue index edc1e41..d5e4dfd 100644 --- a/Front/src/components/Pj.vue +++ b/Front/src/components/Pj.vue @@ -1,82 +1,96 @@