当前位置:   article > 正文

Vue3使用vue-print-nb插件打印功能_vue3-print-nb

vue3-print-nb

 插件官网地址https://www.npmjs.com/package/vue-print-nb

 效果展示:

打印效果

  1.  根据不同的Vue版本安装插件

    1. //Vue2.0版本安装方法
    2. npm install vue-print-nb --save
    3. pnpm install vue-print-nb --save
    4. yarn add vue-print-nb
    5. //Vue3.0版本安装方法:
    6. npm install vue3-print-nb --save
    7. pnpm install vue3-print-nb --save
    8. yarn add vue3-print-nb
  2. 全局挂载

    1. //在mian.ts文件中加入
    2. import Print from 'vue-print-nb'
    3. Vue.use(Print)
  3. 打印页面的样式

    1. <!-- 打印的内容-->
    2. <div id="printTest">
    3. <div class="box_printTest">
    4. <el-row>
    5. <el-col :span="13"
    6. ><div class="grid-content ep-bg-purple"
    7. /></el-col>
    8. <el-col
    9. :span="11"
    10. style="
    11. font-size: 25px;
    12. color: rgb(51, 51, 153);
    13. font-weight: 600;
    14. "
    15. >COMMERCIAL INVOICE
    16. </el-col>
    17. </el-row>
    18. <el-row>
    19. <el-col
    20. :span="24"
    21. style="font-size: 15px; color: #000000; font-weight: bold"
    22. >XIAMEN VIGORTEAM TRADING CO.,LTD</el-col
    23. >
    24. </el-row>
    25. <el-row>
    26. <el-col :span="14" style="font-size: 13px; color: #303133"
    27. >1501-1502 GOLDEN COAST PLAZA,NO.99 LUJIANG
    28. ROAD,XIAMEN,CHINA</el-col
    29. >
    30. <el-col :span="5">
    31. <el-row>Date:</el-row>
    32. <el-row>Invoice #:</el-row>
    33. <el-row>Purchase Order #</el-row>
    34. <el-row>L/C #</el-row>
    35. </el-col>
    36. <el-col :span="5">
    37. <el-row class="demo">July 24,2023</el-row>
    38. <el-row class="demo">WBG-123456</el-row>
    39. <el-row class="demo">JDG-123456</el-row>
    40. <el-row class="demo">BLG-123456</el-row>
    41. </el-col>
    42. </el-row>
    43. <br />
    44. <el-row>
    45. <el-col :span="10">
    46. <div style="background-color: rgb(51, 51, 153)">
    47. <span style="color: white; font-weight: bold">Bill To:</span>
    48. </div>
    49. </el-col>
    50. <el-col :span="4" />
    51. <el-col :span="10"
    52. ><div style="background-color: rgb(51, 51, 153)">
    53. <span style="color: white; font-weight: bold">Ship To:</span>
    54. </div></el-col
    55. >
    56. </el-row>
    57. <el-row>
    58. <el-col
    59. :span="10"
    60. style="font-size: 15px; color: #000000; font-weight: bold"
    61. >MR PRICE HOME ,A DIVISION OF MR PRICE GROUP LIM</el-col
    62. >
    63. <el-col :span="4" />
    64. <el-col
    65. :span="10"
    66. style="font-size: 15px; color: #000000; font-weight: bold"
    67. >MR PRICE HOME ,A DIVISION OF MR PRICE GROUP Wen</el-col
    68. >
    69. </el-row>
    70. <div style="height: 10px" />
    71. <el-row>
    72. <el-col :span="10" style="font-size: 13px; color: #303133"
    73. >HEAD OFFICE,UPPER LEVEL NORTH CONCOURSE DURBAN STATION ,65
    74. MASABALALA YENGWA AVENUE DURBAN,SOUTH AFRICA</el-col
    75. >
    76. <el-col :span="4" />
    77. <el-col :span="10" style="font-size: 13px; color: #303133"
    78. >HEAD OFFICE,UPPER LEVEL NORTH CONCOURSE,DURBAN STATION ,65
    79. MASABALALA YENGWA AVENUE DURBAN SOUTH AFRICA</el-col
    80. >
    81. </el-row>
    82. <br />
    83. <br />
    84. <el-row>
    85. <el-col :span="24">
    86. <div style="background-color: rgb(51, 51, 153)">
    87. <span style="color: white; font-weight: bold"
    88. >Shipment Information</span
    89. >
    90. </div>
    91. </el-col>
    92. </el-row>
    93. <div style="height: 10px" />
    94. <el-row>
    95. <el-col :span="6" style="font-size: 13px; color: #303133"
    96. >Country of Origin</el-col
    97. >
    98. <el-col
    99. :span="18"
    100. style="font-size: 13px; color: #303133; border: 1px solid #333"
    101. >China</el-col
    102. >
    103. </el-row>
    104. <div style="height: 10px" />
    105. <el-row>
    106. <el-col :span="6" style="font-size: 13px; color: #303133"
    107. >Port of Loading</el-col
    108. >
    109. <el-col
    110. :span="5"
    111. style="font-size: 13px; color: #303133; border: 1px solid #333"
    112. >TIANJIN,CHINA</el-col
    113. >
    114. <el-col :span="1" />
    115. <el-col :span="6" style="font-size: 13px; color: #303133"
    116. >Port of Destination</el-col
    117. >
    118. <el-col
    119. :span="6"
    120. style="font-size: 13px; color: #303133; border: 1px solid #333"
    121. >DURBAN,SOUTH,AFRICA</el-col
    122. >
    123. </el-row>
    124. <div style="height: 10px" />
    125. <el-row>
    126. <el-col :span="6" style="font-size: 13px; color: #303133"
    127. >Shiping Method</el-col
    128. >
    129. <el-col
    130. :span="5"
    131. style="font-size: 13px; color: #303133; border: 1px solid #333"
    132. >FOB</el-col
    133. >
    134. </el-row>
    135. <!-- 打印的表格-->
    136. <div>
    137. <el-table
    138. :data="baseProperty.tableData"
    139. :span-method="arraySpanMethod"
    140. border
    141. :header-cell-style="{
    142. background: '#333399',
    143. color: '#ffffff'
    144. }"
    145. :cell-style="{ color: '#000000' }"
    146. style="width: 100%; margin-top: 20px"
    147. >
    148. <el-table-column
    149. prop="id"
    150. align="center"
    151. style="color: black"
    152. label="SHIPPING MARKS"
    153. width="150"
    154. />
    155. <el-table-column
    156. prop="name"
    157. align="center"
    158. label="DESCRIPTION OF GOODS"
    159. width="210"
    160. />
    161. <el-table-column
    162. prop="amount1"
    163. align="center"
    164. label="QTY"
    165. width="120"
    166. />
    167. <el-table-column
    168. align="center"
    169. prop="amount2"
    170. label="UNIT PRICE"
    171. width="120"
    172. />
    173. <el-table-column
    174. prop="amount3"
    175. align="center"
    176. label="AMOUNT"
    177. width="120"
    178. />
    179. </el-table>
    180. </div>
    181. <el-row>
    182. <el-col :span="5" />
    183. <el-col :span="11" style="font-size: 13px; color: #303133"
    184. >产地: 廊坊</el-col
    185. >
    186. <el-col
    187. :span="5"
    188. style="
    189. font-size: 13px;
    190. color: white;
    191. background-color: #003366;
    192. font-weight: bold;
    193. "
    194. >Total</el-col
    195. >
    196. <el-col
    197. :span="3"
    198. style="
    199. font-size: 13px;
    200. color: white;
    201. background-color: #003366;
    202. font-weight: bold;
    203. "
    204. >USD 10920.00</el-col
    205. >
    206. </el-row>
    207. <br />
    208. <el-row>
    209. <el-col :span="24">
    210. <div style="background-color: rgb(51, 51, 153)">
    211. <span style="color: white; font-weight: bold"
    212. >Summary Information</span
    213. >
    214. </div>
    215. </el-col>
    216. </el-row>
    217. <el-row>
    218. <el-col
    219. :span="16"
    220. style="
    221. font-size: 13px;
    222. color: #303133;
    223. border-bottom: 1px solid #333;
    224. border-right: 1px solid #333;
    225. border-left: 1px solid #333;
    226. "
    227. >
    228. <div
    229. style="height: 100%; text-align: center; line-height: 100px"
    230. >
    231. TOTAL: U.SDOLLARS TEN THOUSAND NINE HUNDRED AND TWENTY ONLY
    232. </div>
    233. </el-col>
    234. <el-col
    235. :span="8"
    236. style="
    237. font-size: 13px;
    238. color: #303133;
    239. border-bottom: 1px solid #333;
    240. border-right: 1px solid #333;
    241. "
    242. >
    243. <el-row style="border-bottom: 1px solid #333">
    244. <el-col :span="12"
    245. ><span style="font-weight: bold"> Total QTY </span></el-col
    246. >
    247. <el-col :span="12">
    248. <div style="text-align: center">1680PCS</div>
    249. </el-col>
    250. </el-row>
    251. <el-row style="border-bottom: 1px solid #333">
    252. <el-col :span="12"
    253. ><span style="font-weight: bold"> Total CBM </span></el-col
    254. >
    255. <el-col
    256. :span="12"
    257. style="background-color: rgb(192, 192, 192)"
    258. >
    259. <div style="text-align: center">60.06CBM</div>
    260. </el-col>
    261. </el-row>
    262. <el-row>
    263. <el-col :span="12"
    264. ><span style="font-weight: bold"> Container </span></el-col
    265. >
    266. <el-col :span="12">
    267. <div style="text-align: right">*20°FCL</div>
    268. </el-col>
    269. </el-row>
    270. <el-row>
    271. <el-col :span="12" />
    272. <el-col
    273. :span="12"
    274. style="background-color: rgb(192, 192, 192)"
    275. >
    276. <div style="text-align: right">*40°FCL</div>
    277. </el-col>
    278. </el-row>
    279. <el-row>
    280. <el-col :span="12" />
    281. <el-col :span="12">
    282. <div style="text-align: right">*40°HQ&nbsp;</div>
    283. </el-col>
    284. </el-row>
    285. <el-row>
    286. <el-col :span="12" />
    287. <el-col
    288. :span="12"
    289. style="background-color: rgb(192, 192, 192)"
    290. >
    291. <div style="text-align: right">*45°HQ&nbsp;</div>
    292. </el-col>
    293. </el-row>
    294. </el-col>
    295. </el-row>
    296. </div>
    297. </div>
    298. //表格数据
    299. const baseProperty = reactive({
    300. userCode: "",
    301. dragBtnBC1: "#e5e4e9",
    302. dragBtnBC2: "#e5e4e9",
    303. searchTab: "Regular Data",
    304. openSearch: false,
    305. topDivShow: true,
    306. buttonTab: "Split Shipping Plan",
    307. topDivShowFull: false,
    308. loading: false,
    309. subSkuList: [],
    310. warehouseList: [],
    311. overseasWarehouseList: [],
    312. shippingPlanMethodList: [],
    313. fobPortList: [],
    314. leftStyle: "width: 73%-10px",
    315. rightStyle: "width: 27%; height: 100%",
    316. rightShow: false,
    317. show: false,
    318. searchForm: {
    319. shippingPlanOrder: "",
    320. status: "",
    321. page: 1,
    322. limit: 10
    323. },
    324. tableData: [
    325. {
    326. id: "12987122",
    327. name: "A03-01-PP001\n" + "H.S.CODE:9401690090\n" + "产品尺寸:53*53*51",
    328. amount1: "682PCS",
    329. amount2: "USD 6.50",
    330. amount3: "USD 4420.00"
    331. },
    332. {
    333. id: "12987123",
    334. name: "A03-01-PP001\n" + "H.S.CODE:9401690090\n" + "产品尺寸:53*53*51",
    335. amount1: "700PCS",
    336. amount2: "USD 6.50",
    337. amount3: "USD 4550.00"
    338. },
    339. {
    340. id: "12987124",
    341. name: "A03-01-PP001\n" + "H.S.CODE:9401690090\n" + "产品尺寸:53*53*51",
    342. amount1: "300PCS",
    343. amount2: "USD 6.50",
    344. amount3: "USD 1950.00"
    345. },
    346. ]
    347. });

  4. 打印按钮

    1. // printTest是需要打印内容的div的id ,并在前面加上#
    2. <el-button
    3. @click="toPrint(row)"
    4. v-print="'#printTest'"
    5. size="default"
    6. link
    7. type="primary"
    8. >COMMERCIAL INVOICE
    9. </el-button>

  5. 关于颜色存在偏差的问题

    1. @media print {
    2. // 强制打印背景(这样才能打印出背景颜色) Kris_wen
    3. * {
    4. -webkit-print-color-adjust: exact !important;
    5. }
    6. }
  6. 去掉页眉页脚

    1. /* 去掉页眉页脚 */
    2. @page {
    3. size: auto;
    4. margin: 0mm;
    5. }
  7. 表格最好使用原生的HTML原生的表格,使用element-table会出现分页割断的问题。

  8. 有些数据是要先通过ajax从后端取出,在调用打印方法的。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/934916
推荐阅读
相关标签
  

闽ICP备14008679号