上传文件至 /
This commit is contained in:
parent
f60bd9f0da
commit
90bd27d95d
|
@ -0,0 +1,189 @@
|
|||
import sys
|
||||
import requests
|
||||
import json
|
||||
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QLabel, QLineEdit, QPushButton, QTextEdit, QMessageBox, QFileDialog)
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
|
||||
class TurbineAddWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("新增机组")
|
||||
self.setGeometry(100, 100, 500, 500)
|
||||
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
# 主窗口部件
|
||||
central_widget = QWidget()
|
||||
self.setCentralWidget(central_widget)
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# 项目ID
|
||||
project_id_layout = QHBoxLayout()
|
||||
project_id_layout.addWidget(QLabel("项目ID*:"))
|
||||
self.project_id_input = QLineEdit()
|
||||
project_id_layout.addWidget(self.project_id_input)
|
||||
layout.addLayout(project_id_layout)
|
||||
|
||||
# 机组名称
|
||||
turbine_name_layout = QHBoxLayout()
|
||||
turbine_name_layout.addWidget(QLabel("机组名称:"))
|
||||
self.turbine_name_input = QLineEdit()
|
||||
turbine_name_layout.addWidget(self.turbine_name_input)
|
||||
layout.addLayout(turbine_name_layout)
|
||||
|
||||
# 机组编码
|
||||
turbine_code_layout = QHBoxLayout()
|
||||
turbine_code_layout.addWidget(QLabel("机组编码:"))
|
||||
self.turbine_code_input = QLineEdit()
|
||||
turbine_code_layout.addWidget(self.turbine_code_input)
|
||||
layout.addLayout(turbine_code_layout)
|
||||
|
||||
# 机组描述
|
||||
turbine_desc_layout = QVBoxLayout()
|
||||
turbine_desc_layout.addWidget(QLabel("机组描述:"))
|
||||
self.turbine_desc_input = QTextEdit()
|
||||
self.turbine_desc_input.setMaximumHeight(80)
|
||||
turbine_desc_layout.addWidget(self.turbine_desc_input)
|
||||
layout.addLayout(turbine_desc_layout)
|
||||
|
||||
# 机组厂商
|
||||
turbine_manufacturer_layout = QHBoxLayout()
|
||||
turbine_manufacturer_layout.addWidget(QLabel("机组厂商:"))
|
||||
self.turbine_manufacturer_input = QLineEdit()
|
||||
turbine_manufacturer_layout.addWidget(self.turbine_manufacturer_input)
|
||||
layout.addLayout(turbine_manufacturer_layout)
|
||||
|
||||
# 机组型号
|
||||
turbine_model_layout = QHBoxLayout()
|
||||
turbine_model_layout.addWidget(QLabel("机组型号:"))
|
||||
self.turbine_model_input = QLineEdit()
|
||||
turbine_model_layout.addWidget(self.turbine_model_input)
|
||||
layout.addLayout(turbine_model_layout)
|
||||
|
||||
# 机组封面图
|
||||
self.cover_image_path = ""
|
||||
cover_image_layout = QHBoxLayout()
|
||||
cover_image_layout.addWidget(QLabel("机组封面图:"))
|
||||
self.cover_image_label = QLabel("未选择图片")
|
||||
self.cover_image_label.setStyleSheet("color: #666; font-style: italic;")
|
||||
cover_image_layout.addWidget(self.cover_image_label)
|
||||
self.select_image_btn = QPushButton("选择图片")
|
||||
self.select_image_btn.clicked.connect(self.select_image)
|
||||
cover_image_layout.addWidget(self.select_image_btn)
|
||||
layout.addLayout(cover_image_layout)
|
||||
|
||||
# 按钮区域
|
||||
button_layout = QHBoxLayout()
|
||||
button_layout.addStretch()
|
||||
|
||||
# 新增清空按钮
|
||||
self.clear_btn = QPushButton("清空表单")
|
||||
self.clear_btn.setFixedWidth(100)
|
||||
self.clear_btn.clicked.connect(self.clear_form)
|
||||
button_layout.addWidget(self.clear_btn)
|
||||
|
||||
# 提交按钮
|
||||
self.submit_btn = QPushButton("提交")
|
||||
self.submit_btn.setFixedWidth(100)
|
||||
self.submit_btn.clicked.connect(self.submit_data)
|
||||
button_layout.addWidget(self.submit_btn)
|
||||
|
||||
layout.addLayout(button_layout)
|
||||
|
||||
central_widget.setLayout(layout)
|
||||
|
||||
def select_image(self):
|
||||
options = QFileDialog.Options()
|
||||
file_path, _ = QFileDialog.getOpenFileName(
|
||||
self, "选择机组封面图", "",
|
||||
"图片文件 (*.jpg *.jpeg *.png *.gif);;所有文件 (*.*)",
|
||||
options=options
|
||||
)
|
||||
|
||||
if file_path:
|
||||
self.cover_image_path = file_path
|
||||
self.cover_image_label.setText(file_path.split('/')[-1])
|
||||
self.cover_image_label.setStyleSheet("color: #333; font-style: normal;")
|
||||
|
||||
def validate_inputs(self):
|
||||
if not self.project_id_input.text().strip():
|
||||
QMessageBox.warning(self, "输入错误", "项目ID不能为空!")
|
||||
return False
|
||||
return True
|
||||
|
||||
def submit_data(self):
|
||||
if not self.validate_inputs():
|
||||
return
|
||||
|
||||
# 构造请求数据
|
||||
turbine_data = {
|
||||
"projectId": self.project_id_input.text().strip(),
|
||||
"turbineName": self.turbine_name_input.text().strip(),
|
||||
"turbineCode": self.turbine_code_input.text().strip(),
|
||||
"turbineDesc": self.turbine_desc_input.toPlainText().strip(),
|
||||
"turbineManufacturer": self.turbine_manufacturer_input.text().strip(),
|
||||
"turbineModel": self.turbine_model_input.text().strip(),
|
||||
"turbineCoverUrl": self.cover_image_path if self.cover_image_path else ""
|
||||
}
|
||||
|
||||
# 确认对话框
|
||||
reply = QMessageBox.question(
|
||||
self, '确认提交',
|
||||
'确定要提交这些信息吗?',
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
|
||||
)
|
||||
|
||||
if reply == QMessageBox.No:
|
||||
return
|
||||
|
||||
# 提交数据
|
||||
url = "http://pms.dtyx.net:9158/turbine"
|
||||
headers = {
|
||||
"Authorization": "null",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=json.dumps(turbine_data))
|
||||
response.raise_for_status()
|
||||
|
||||
result = response.json()
|
||||
QMessageBox.information(
|
||||
self, "提交成功",
|
||||
f"数据提交成功!\n\n响应结果:\n{json.dumps(result, indent=2)}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
QMessageBox.critical(
|
||||
self, "提交失败",
|
||||
f"数据提交失败!\n\n错误信息:\n{str(e)}"
|
||||
)
|
||||
|
||||
def clear_form(self):
|
||||
"""手动清空表单的方法"""
|
||||
reply = QMessageBox.question(
|
||||
self, '确认清空',
|
||||
'确定要清空所有已填写的信息吗?',
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
|
||||
)
|
||||
|
||||
if reply == QMessageBox.Yes:
|
||||
self.project_id_input.clear()
|
||||
self.turbine_name_input.clear()
|
||||
self.turbine_code_input.clear()
|
||||
self.turbine_desc_input.clear()
|
||||
self.turbine_manufacturer_input.clear()
|
||||
self.turbine_model_input.clear()
|
||||
self.cover_image_path = ""
|
||||
self.cover_image_label.setText("未选择图片")
|
||||
self.cover_image_label.setStyleSheet("color: #666; font-style: italic;")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = TurbineAddWindow()
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
|
@ -0,0 +1,148 @@
|
|||
import sys
|
||||
import requests
|
||||
import json
|
||||
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QLabel, QLineEdit, QPushButton, QTextEdit, QMessageBox,
|
||||
QComboBox)
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
|
||||
class PartAddWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("新增部件")
|
||||
self.setGeometry(100, 100, 500, 500)
|
||||
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
# 主窗口部件
|
||||
central_widget = QWidget()
|
||||
self.setCentralWidget(central_widget)
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# 机组ID
|
||||
turbine_id_layout = QHBoxLayout()
|
||||
turbine_id_layout.addWidget(QLabel("机组ID*:"))
|
||||
self.turbine_id_input = QLineEdit()
|
||||
turbine_id_layout.addWidget(self.turbine_id_input)
|
||||
layout.addLayout(turbine_id_layout)
|
||||
|
||||
# 部件名称
|
||||
part_name_layout = QHBoxLayout()
|
||||
part_name_layout.addWidget(QLabel("部件名称:"))
|
||||
self.part_name_input = QLineEdit()
|
||||
part_name_layout.addWidget(self.part_name_input)
|
||||
layout.addLayout(part_name_layout)
|
||||
|
||||
# 部件编号
|
||||
part_code_layout = QHBoxLayout()
|
||||
part_code_layout.addWidget(QLabel("部件编号:"))
|
||||
self.part_code_input = QLineEdit()
|
||||
part_code_layout.addWidget(self.part_code_input)
|
||||
layout.addLayout(part_code_layout)
|
||||
|
||||
# 部件类型(下拉选择)
|
||||
part_type_layout = QHBoxLayout()
|
||||
part_type_layout.addWidget(QLabel("部件类型:"))
|
||||
self.part_type_combo = QComboBox()
|
||||
self.part_type_combo.addItems(["", "VANE-1", "VANE-2", "VANE-3"]) # 已知的部件类型
|
||||
part_type_layout.addWidget(self.part_type_combo)
|
||||
layout.addLayout(part_type_layout)
|
||||
|
||||
# 部件描述
|
||||
part_desc_layout = QVBoxLayout()
|
||||
part_desc_layout.addWidget(QLabel("部件描述:"))
|
||||
self.part_desc_input = QTextEdit()
|
||||
self.part_desc_input.setMaximumHeight(80)
|
||||
part_desc_layout.addWidget(self.part_desc_input)
|
||||
layout.addLayout(part_desc_layout)
|
||||
|
||||
# 部件厂商
|
||||
part_manufacturer_layout = QHBoxLayout()
|
||||
part_manufacturer_layout.addWidget(QLabel("部件厂商:"))
|
||||
self.part_manufacturer_input = QLineEdit()
|
||||
part_manufacturer_layout.addWidget(self.part_manufacturer_input)
|
||||
layout.addLayout(part_manufacturer_layout)
|
||||
|
||||
# 部件型号
|
||||
part_model_layout = QHBoxLayout()
|
||||
part_model_layout.addWidget(QLabel("部件型号:"))
|
||||
self.part_model_input = QLineEdit()
|
||||
part_model_layout.addWidget(self.part_model_input)
|
||||
layout.addLayout(part_model_layout)
|
||||
|
||||
# 按钮区域
|
||||
button_layout = QHBoxLayout()
|
||||
button_layout.addStretch()
|
||||
|
||||
# 提交按钮
|
||||
self.submit_btn = QPushButton("提交")
|
||||
self.submit_btn.setFixedWidth(100)
|
||||
self.submit_btn.clicked.connect(self.submit_data)
|
||||
button_layout.addWidget(self.submit_btn)
|
||||
|
||||
layout.addLayout(button_layout)
|
||||
|
||||
central_widget.setLayout(layout)
|
||||
|
||||
def validate_inputs(self):
|
||||
if not self.turbine_id_input.text().strip():
|
||||
QMessageBox.warning(self, "输入错误", "机组ID不能为空!")
|
||||
return False
|
||||
return True
|
||||
|
||||
def submit_data(self):
|
||||
if not self.validate_inputs():
|
||||
return
|
||||
|
||||
# 构造请求数据
|
||||
part_data = {
|
||||
"turbineId": self.turbine_id_input.text().strip(),
|
||||
"partName": self.part_name_input.text().strip(),
|
||||
"partCode": self.part_code_input.text().strip(),
|
||||
"partType": self.part_type_combo.currentText(),
|
||||
"partDesc": self.part_desc_input.toPlainText().strip(),
|
||||
"partManufacturer": self.part_manufacturer_input.text().strip(),
|
||||
"partModel": self.part_model_input.text().strip()
|
||||
}
|
||||
|
||||
# 确认对话框
|
||||
reply = QMessageBox.question(
|
||||
self, '确认提交',
|
||||
'确定要提交这些部件信息吗?',
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
|
||||
)
|
||||
|
||||
if reply == QMessageBox.No:
|
||||
return
|
||||
|
||||
# 提交数据
|
||||
url = "http://pms.dtyx.net:9158/part"
|
||||
headers = {
|
||||
"Authorization": "null",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=json.dumps(part_data))
|
||||
response.raise_for_status()
|
||||
|
||||
result = response.json()
|
||||
QMessageBox.information(
|
||||
self, "提交成功",
|
||||
f"部件信息提交成功!\n\n响应结果:\n{json.dumps(result, indent=2)}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
QMessageBox.critical(
|
||||
self, "提交失败",
|
||||
f"部件信息提交失败!\n\n错误信息:\n{str(e)}"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = PartAddWindow()
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
Loading…
Reference in New Issue