npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

hjk-print-windows

v1.0.3

Published

hjk vue print-windows

Readme

HjkPrintWindows 打印组件

HjkPrintWindows 是一个基于 Vue.js 的打印组件,支持自定义打印模板和数据打印。

安装

npm install hjk-windows-print

使用

全局注册

import HjkPrintWindows from "hjk-windows-print";
Vue.use(HjkPrintWindows, { url: "http://www.xxx.com/xxx/" });

组件使用

<template>
	<div>
		<button @click="handlePrint">打印</button>
		<HjkPrintWindows></HjkPrintWindows>
	</div>
</template>

<script>
export default {
	methods: {
		handlePrint() {
			const data = [
				{
					receiptNumber: "CG20250213001",
					createTime: "2025-02-13 09:02:58",
					materialsSupplierName: "供应商名称",
					// ... 其他数据
				},
			];
			HjkPrintWindows.print(data, "打印模板URL 或者 html文件名称");
            HjkPrintWindows.open = (e)=>{
                console.log("window.print()调用成功后,执行此方法")
            }
            HjkPrintWindows.close = (e)=>{
                console.log("window.print()窗口关闭后,执行此方法")
            }
            HjkPrintWindows.error = (e)=>{
                console.error("HjkPrintWindows.print()执行报错后,执行此方法")
            }
		},
	},
};
</script>

html模版


<div style="padding: 10mm;width: 190mm;height: 120mm;" v-for="(item,index) in param">
    <div style="display: flex;justify-content: space-between;width: 190mm;">
        <div style="width: 40mm;"></div>
        <div style="font-size: 15px;font-weight: 700;">标题</div>
        <div style="width: 40mm;font-size: 12px;">姓名:{{ name }}</div>
    </div>
</div>

<script>
    // vueHandler名称固定,目前仅支持data、mounted、methods
    const vueHandler = {
        data: {
            name: "张三"
        },
        mounted() {
            console.log("name:", this.name)
            this.init();
        },
        methods: {
            init() {
                console.log("执行了init")
            }
        }
    }
</script>

注意事项

  1. 打印模板 URL 必须是可访问的
  2. 打印数据必须是数组格式
  3. 建议在打印前进行数据验证
  4. 可以通过事件监听处理打印过程中的状态变化
  5. vue.config.js 需开启 runtimeCompiler: true,或者如下配置
module.exports = {
  runtimeCompiler: false,  // 禁用运行时编译(默认)
  configureWebpack: {
    resolve: {
      alias: {
        'vue$': 'vue/dist/vue.runtime.esm.js'  // 强制使用运行时构建版本
      }
    }
  }
}

开发

项目结构

src/
  ├── lib/
  │   ├── HjkPrintWindows.vue      # 主组件
  │   ├── HjkPrintWindows.css      # 样式文件
  │   ├── HjkPrintWindows.scss     # SCSS样式文件
  │   ├── HjkPrintWindows.min.css  # 压缩后的样式文件
  │   ├── HjkPrintWindowsTools.js  # 工具函数
  │   └── index.js                 # 入口文件
  ├── App.vue                      # 示例应用
  └── main.js                      # 主入口文件

依赖

  • vue-print-nb: 打印功能依赖
  • Vue.js: 框架依赖

贡献

欢迎提交 Issue 和 Pull Request。

许可证

MIT