因为wps js编辑器无法调用BarcodeX控件的缘故,所以捣鼓了node.js搭建本地服务器,通过url发送请求来获取条形码。逛了一圈npm发现bwip-js库可以实现想要的功能。
一、安装bwip-js
npm i bwip-js
二、搭建简易的http服务器
// 使用bwip-js呈现条形码图像的简单HTTP服务器
//访问链接即可查看效果:http://localhost:3030/?bcid=isbn&text=978-1-56581-231-4+52250&includetext&guardwhitespace
const http = require('http');
const bwipjs = require('bwip-js');
http.createServer(function(req, res) {
// If the url does not begin /?bcid= then 404. Otherwise, we end up
// returning 400 on requests like favicon.ico.
if (req.url.indexOf('/?bcid=') != 0) {
res.writeHead(404, { 'Content-Type':'text/plain' });
res.end('BWIPJS: Unknown request format.', 'utf8');
} else {
bwipjs.request(req, res); // Executes asynchronously
}
}).listen(3030);
三、添加入站规则
打开控制面板,选择防火墙→高级设置→选择入站规则→新建规则
在路由器设置固定IP后,即可通过ip地址 + 端口号在局域网中使用