mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-06-10 19:26:53 +08:00
del py
This commit is contained in:
@@ -49,17 +49,7 @@ module.exports = {
|
||||
directory: './go',
|
||||
cmd: 'go',
|
||||
args: ['build', '-o=../build/extraResources/goapp'],
|
||||
},
|
||||
python_w: {
|
||||
directory: './python',
|
||||
cmd: 'pyinstaller',
|
||||
args: ['-n=pyapp', '-F', './main.py'],
|
||||
},
|
||||
python_m: {
|
||||
directory: './python',
|
||||
cmd: 'pyinstaller',
|
||||
args: ['-n=pyapp', '-F', './main.py'],
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -87,10 +77,6 @@ module.exports = {
|
||||
dist: './public/images',
|
||||
target: './go/public/images'
|
||||
},
|
||||
python_dist: {
|
||||
dist: './python/dist',
|
||||
target: './build/extraResources/py'
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -138,12 +124,6 @@ module.exports = {
|
||||
directory: './',
|
||||
cmd: 'npm',
|
||||
args: ['-v'],
|
||||
},
|
||||
python: {
|
||||
directory: './python',
|
||||
cmd: 'python',
|
||||
args: ['./main.py', '--port=7074'],
|
||||
stdio: "inherit", // ignore
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -127,15 +127,7 @@ module.exports = (appInfo) => {
|
||||
name: 'goapp',
|
||||
args: ['--port=7073'],
|
||||
appExit: true,
|
||||
},
|
||||
python: {
|
||||
enable: false,
|
||||
name: 'pyapp',
|
||||
cmd: './py/pyapp',
|
||||
directory: './py',
|
||||
args: ['--port=7074'],
|
||||
appExit: true,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,16 +41,7 @@ module.exports = (appInfo) => {
|
||||
directory: './go',
|
||||
args: ['run', './main.go', '--env=dev','--basedir=../', '--port=7073'],
|
||||
appExit: true,
|
||||
},
|
||||
python: {
|
||||
enable: true,
|
||||
name: 'pyapp',
|
||||
cmd: 'python',
|
||||
directory: './python',
|
||||
args: ['./main.py', '--port=7074'],
|
||||
stdio: "inherit",
|
||||
appExit: true,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -67,8 +67,6 @@ class CrossController extends Controller {
|
||||
Services.get('cross').createGoServer();
|
||||
} else if (program == 'java') {
|
||||
Services.get('cross').createJavaServer();
|
||||
} else if (program == 'python') {
|
||||
Services.get('cross').createPythonServer();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -71,33 +71,6 @@ class CrossService extends Service {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* create python service
|
||||
* In the default configuration, services can be started with applications.
|
||||
* Developers can turn off the configuration and create it manually.
|
||||
*/
|
||||
async createPythonServer() {
|
||||
// method 1: Use the default Settings
|
||||
//const entity = await Cross.run(serviceName);
|
||||
|
||||
// method 2: Use custom configuration
|
||||
const serviceName = "python";
|
||||
const opt = {
|
||||
name: 'pyapp',
|
||||
cmd: path.join(Ps.getExtraResourcesDir(), 'py', 'pyapp'),
|
||||
directory: path.join(Ps.getExtraResourcesDir(), 'py'),
|
||||
args: ['--port=7074'],
|
||||
windowsExtname: true,
|
||||
appExit: true,
|
||||
}
|
||||
const entity = await Cross.run(serviceName, opt);
|
||||
Log.info('server name:', entity.name);
|
||||
Log.info('server config:', entity.config);
|
||||
Log.info('server url:', entity.getUrl());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CrossService.toString = () => '[class CrossService]';
|
||||
|
||||
@@ -171,12 +171,7 @@ const constantRouterMap = [
|
||||
path: '/cross/java/index',
|
||||
name: 'CrossJavaIndex',
|
||||
component: () => import('@/views/cross/java/Index.vue')
|
||||
},
|
||||
{
|
||||
path: '/cross/python/index',
|
||||
name: 'CrossPythonIndex',
|
||||
component: () => import('@/views/cross/python/Index.vue')
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
@@ -142,12 +142,6 @@ export default {
|
||||
title: 'java服务',
|
||||
pageName: 'CrossJavaIndex',
|
||||
params: {}
|
||||
},
|
||||
'menu_120' : {
|
||||
icon: 'profile',
|
||||
title: 'python服务',
|
||||
pageName: 'CrossPythonIndex',
|
||||
params: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
<template>
|
||||
<div id="app-cross-python">
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
1. 基础控制
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-space>
|
||||
<a-button @click="create()"> 启动 </a-button>
|
||||
<a-button @click="getUrl()"> 获取地址 </a-button>
|
||||
<a-button @click="kill()"> kill </a-button>
|
||||
<a-button @click="info()"> test </a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
2. 发送http请求
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-space>
|
||||
<a-button @click="request(1)"> 前端发送 </a-button>
|
||||
<a-button @click="request(2)"> 主进程发送 </a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
3. 多个服务
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-space>
|
||||
<a-button @click="create()"> 启动 </a-button>
|
||||
<a-button @click="killAll()"> kill all </a-button>
|
||||
</a-space>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { ipcApiRoute } from '@/api/main';
|
||||
import { ipc } from '@/utils/ipcRenderer';
|
||||
import axios from 'axios';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
type: 1,
|
||||
serverUrl: ''
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
info() {
|
||||
ipc.invoke(ipcApiRoute.crossInfo, {}).then(res => {
|
||||
console.log('res:', res);
|
||||
})
|
||||
},
|
||||
getUrl() {
|
||||
ipc.invoke(ipcApiRoute.getCrossUrl, {name: 'pyapp'}).then(url => {
|
||||
this.serverUrl = url;
|
||||
this.$message.info(`服务地址: ${url}`);
|
||||
})
|
||||
},
|
||||
kill() {
|
||||
// name参数是 进程对象上的name,这里仅作为参照
|
||||
ipc.invoke(ipcApiRoute.killCrossServer, {type: 'one', name: 'pyapp'})
|
||||
},
|
||||
killAll() {
|
||||
ipc.invoke(ipcApiRoute.killCrossServer, {type: 'all', name: 'pyapp'})
|
||||
},
|
||||
create() {
|
||||
ipc.invoke(ipcApiRoute.createCrossServer, { program: 'python' })
|
||||
},
|
||||
request(type) {
|
||||
if (type == 1 && this.serverUrl == "") {
|
||||
this.$message.info("请先获取服务地址");
|
||||
return
|
||||
}
|
||||
if (type == 1) {
|
||||
const testApi = this.serverUrl + '/api/hello';
|
||||
const cfg = {
|
||||
method: 'get',
|
||||
url: testApi,
|
||||
params: { id: '111'},
|
||||
timeout: 1000,
|
||||
}
|
||||
axios(cfg).then(res => {
|
||||
console.log('res:', res);
|
||||
const data = res.data || null;
|
||||
this.$message.info(`服务返回: ${JSON.stringify(data)}`);
|
||||
})
|
||||
} else {
|
||||
ipc.invoke(ipcApiRoute.requestApi, {name: 'pyapp', urlPath: '/api/hello'}).then(res => {
|
||||
console.log('res:', res);
|
||||
const data = res || null;
|
||||
this.$message.info(`服务返回: ${JSON.stringify(data)}`);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
#app-cross-python {
|
||||
padding: 0px 10px;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
.one-block-1 {
|
||||
font-size: 16px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
.one-block-2 {
|
||||
padding-top: 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -8,13 +8,10 @@
|
||||
"dev-frontend": "ee-bin dev --serve=frontend",
|
||||
"dev-electron": "ee-bin dev --serve=electron",
|
||||
"dev-go": "ee-bin dev --serve=go",
|
||||
"dev-python": "ee-bin exec --cmds=python",
|
||||
"build-frontend": "ee-bin build --cmds=frontend && ee-bin move --flag=frontend_dist",
|
||||
"build-go-w": "ee-bin build --cmds=go_w",
|
||||
"build-go-m": "ee-bin build --cmds=go_m",
|
||||
"build-go-l": "ee-bin build --cmds=go_l",
|
||||
"build-python-w": "ee-bin build --cmds=python_w && ee-bin move --flag=python_dist",
|
||||
"build-python-m": "ee-bin build --cmds=python_m && ee-bin move --flag=python_dist",
|
||||
"start": "ee-bin start",
|
||||
"move": "ee-bin move --flag=go_static,go_config,go_package,go_images",
|
||||
"rd": "ee-bin move --flag=frontend_dist",
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import argparse
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# argparse
|
||||
parser = argparse.ArgumentParser(description='Process some integers.')
|
||||
parser.add_argument('--port', type=int, default=7074, help='The port number.')
|
||||
args = parser.parse_args()
|
||||
|
||||
@app.get("/")
|
||||
async def index():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
@app.get("/api/hello")
|
||||
async def hello():
|
||||
return {
|
||||
"app_name": "FastAPI框架学习",
|
||||
"app_version": "v0.0.1"
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
# uvicorn会多创建一个进程,并且stdio独立于控制台,如果(开发时)出现进程没有关闭,可尝试关闭终端
|
||||
uvicorn.run(app, host="127.0.0.1", port=args.port)
|
||||
|
||||
# 控制台默认关闭输出信息,如果想要查看控制台输出,请单独启动服务 npm run dev-python
|
||||
print("python server is running at port:", args.port)
|
||||
@@ -1,57 +0,0 @@
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_cors import CORS
|
||||
import argparse
|
||||
import signal
|
||||
import sys
|
||||
|
||||
# flask-demo
|
||||
|
||||
# argparse
|
||||
parser = argparse.ArgumentParser(description='Process some integers.')
|
||||
parser.add_argument('--port', type=int, default=7074, help='The port number.')
|
||||
args = parser.parse_args()
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# 配置 CORS,允许所有来源
|
||||
CORS(app)
|
||||
|
||||
# 定义路由和处理器
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
name = request.args.get('name', 'World')
|
||||
return jsonify({'message': f'Hello, {name}!'}), 200
|
||||
|
||||
|
||||
@app.route('/api/hello', methods=['GET'])
|
||||
def hello():
|
||||
name = request.args.get('name', 'World')
|
||||
return jsonify({'message': f'Hello, {name}!'}), 200
|
||||
|
||||
# 通过信号来退出服务,否则会出现终端显示退出后,实际进程仍在运行
|
||||
# 定义信号处理函数
|
||||
def signal_handler(sig, frame):
|
||||
print("[python] [flask] Received signal to terminate the server:", sig)
|
||||
sys.exit(0)
|
||||
|
||||
# 关闭 Flask 应用
|
||||
# func = request.environ.get('werkzeug.server.shutdown')
|
||||
# if func is None:
|
||||
# func = lambda: None
|
||||
# func()
|
||||
|
||||
# 退出主线程
|
||||
# threading.main_thread().exit()
|
||||
|
||||
# 注册信号处理函数
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 以api方式启动服务会出现警告,请忽略
|
||||
app.run(port=args.port)
|
||||
|
||||
# 或许flask内置的stdio与node.js stdio有冲突,导致控制台无法显示信息。
|
||||
# 如果想要查看控制台输出,请单独启动服务 npm run dev-python
|
||||
print("python server is running at port:", args.port)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
Flask==3.0.2
|
||||
Flask_Cors==4.0.0
|
||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Reference in New Issue
Block a user