0

我正在开发一个证书管理系统,在完成所有流程后,用户可以打印证书。

我正在努力实现,以便在单击打印按钮时,将打开一个新选项卡,其中包含准备打印的 HTML 证书,以便用户只需 CTRL + P 即可打印证书。

如何在新窗口中呈现我的反应证书组件?这样我只会传递要放入证书中的数据的道具,例如姓名,日期等。像<Certificate name={john} />

我已经尝试实现 npm react-new-window但它不适用于

<Button onclick={() => { 
<NewWindow>
  <CertificateComponent>
</NewWindow>
}}
>
PRINT BUTTON 
</Button>

我已经研究过反应门户,但大多数用例都是针对模态的,这是我的“打印”按钮呈现的地方。

抱歉英语/解释不好。谢谢!

4

1 回答 1

0
There can be multiple approaches for this,

Approach 1:
create a new route and map the certificateComponent to it, make sure it doesn't have any authentication or any dependency to it.

store the required data for certificateComponent either in session storage or local storage

when the user clicks on print button, redirect the user to this new route using window.open("http://localhost:port/newroute")

in certificateComponent read the values stored in session/local storage and map it accordingly.



Approach2:

Make the certificate component as a overlay which occupies the entire screen which shows up when the user click on print button.
if any ui elements needs to be hided you can do something as shown below,

printFn = function() {
    //show the certificate component 
    // hide the ui elements not required
   // window.print()
}
于 2021-07-21T06:56:29.393 回答