| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import React, { useState, useMemo } from 'react';
- import { Select, Button, Space, message } from 'antd';
- import { showNotImplemented } from '@/utils/notificationHelper';
- import { useAppSelector } from '@/states/store';
- import { getPrintManager } from '@/services/print';
- const PrintControl: React.FC = () => {
- const [selectedNode, setSelectedNode] = useState<string>('');
- const [selectedSize, setSelectedSize] = useState<string>('14IN×17IN');
- const [isPrinting, setIsPrinting] = useState(false);
- // 获取当前胶片信息
- const activeFilm = useAppSelector((state) => {
- const films = state.print.films;
- const activeId = state.print.activeFilmId;
- return films.find(f => f.id === activeId);
- });
- // 创建打印管理器实例
- const printManager = useMemo(() => getPrintManager(), []);
- // TODO: 打印节点需要从后端API获取
- const printNodes = [
- { value: 'node1', label: 'TestPrinter' },
- // { value: 'node2', label: '打印节点2' },
- ];
- const filmSizes = [
- { value: '14IN×17IN', label: '14IN×17IN' },
- { value: '14IN×14IN', label: '14IN×14IN' },
- { value: '17IN×17IN', label: '17IN×17IN' },
- ];
- const handleLocalPrint = async () => {
- if (isPrinting) {
- message.warning('打印正在进行中,请稍候');
- return;
- }
- try {
- setIsPrinting(true);
-
- console.log('[本地打印] 开始打印,胶片尺寸:', selectedSize);
-
- await printManager.print({
- elementId: 'film-print-area',
- filmSize: selectedSize,
- orientation: activeFilm?.orientation === 'horizontal' ? 'landscape' : 'portrait',
- });
- message.success('打印完成');
- } catch (error) {
- console.error('[本地打印] 打印失败:', error);
- message.error(`打印失败: ${error.message || '未知错误'}`);
- } finally {
- setIsPrinting(false);
- }
- };
- const handleDicomPrint = () => {
- showNotImplemented('DICOM打印');
- };
- return (
- <div>
- <div className="font-semibold">打印设置</div>
- <Space direction="vertical" style={{ width: '100%' }} size="middle">
- {/* 打印节点下拉框 */}
- <div>
- <div className="mb-1">打印节点</div>
- <Select
- style={{ width: '100%' }}
- placeholder="选择打印节点"
- value={selectedNode}
- onChange={setSelectedNode}
- options={printNodes}
- // TODO: 暂时disabled,等待后端API
- disabled={printNodes.length === 0}
- />
- {printNodes.length === 0 && (
- <div className="text-gray-400 mt-1">
- TODO: 等待后端API提供打印节点
- </div>
- )}
- </div>
- {/* 尺寸下拉框 */}
- <div>
- <div className="mb-1">胶片尺寸</div>
- <Select
- style={{ width: '100%' }}
- value={selectedSize}
- onChange={setSelectedSize}
- options={filmSizes}
- />
- </div>
- {/* 打印按钮 */}
- <div>
- <Space direction="vertical" style={{ width: '100%' }}>
- <Button
- type="primary"
- block
- onClick={handleLocalPrint}
- disabled={!selectedNode}
- >
- 本地打印
- </Button>
- <Button
- block
- onClick={handleDicomPrint}
- disabled={!selectedNode}
- >
- DICOM打印
- </Button>
- </Space>
- </div>
- </Space>
- </div>
- );
- };
- export default PrintControl;
|