feat: add printer config management API
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
# app/api/v1/common/print.py
|
# app/api/v1/common/print.py
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
from app.services.print.label_service import LabelPrintService
|
from app.services.print.label_service import LabelPrintService
|
||||||
|
from app.services.print.print_config import PrintConfigManager
|
||||||
from app.models.inbound.buy import StockBuy
|
from app.models.inbound.buy import StockBuy
|
||||||
# 引入其他模型 StockSemi, StockProduct
|
# 引入其他模型 StockSemi, StockProduct
|
||||||
import traceback
|
import traceback
|
||||||
@ -24,4 +25,25 @@ def execute_print():
|
|||||||
LabelPrintService.send_to_printer(data)
|
LabelPrintService.send_to_printer(data)
|
||||||
return jsonify({"code": 200, "msg": "指令已发送至打印机"})
|
return jsonify({"code": 200, "msg": "指令已发送至打印机"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@print_bp.route('/config', methods=['GET'])
|
||||||
|
def get_printer_config():
|
||||||
|
try:
|
||||||
|
label = PrintConfigManager.get_config('label_printer')
|
||||||
|
network = PrintConfigManager.get_config('network_printer')
|
||||||
|
config = {'label_printer': label, 'network_printer': network}
|
||||||
|
return jsonify({"code": 200, "msg": "success", "data": config})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@print_bp.route('/config', methods=['POST'])
|
||||||
|
def update_printer_config():
|
||||||
|
try:
|
||||||
|
data = request.get_json()
|
||||||
|
PrintConfigManager.save_config(data)
|
||||||
|
return jsonify({"code": 200, "msg": "配置保存成功"})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|||||||
@ -14,4 +14,19 @@ export function executePrint(data: any) {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPrinterConfig() {
|
||||||
|
return request({
|
||||||
|
url: '/common/print/config',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updatePrinterConfig(data: any) {
|
||||||
|
return request({
|
||||||
|
url: '/common/print/config',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user