123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898 |
- <template>
- <el-card>
- <div style="display: flex;flex-direction: column">
- <div style="margin-bottom: 10px">
- <el-button @click="$router.go(-1)" type="text" class="inline-16">返回模板列表</el-button>
- <el-button-group class="inline-16">
- <template v-for="(value,type) in paperTypes">
- <el-button size="small" :type="curPaperType === type ? 'primary' : 'default'" @click="setPaper(type,value)" :key="type">
- {{ type }}
- </el-button>
- </template>
- <el-popover
- placement="bottom"
- trigger="click"
- v-model="visible">
- <div class="flex-align-center flex-between normal-margin">
- <el-input size="small" type="number" v-model="paperWidth" style=" width: 100px; text-align: center"
- placeholder="宽(mm)"/>
- <p>-</p>
- <el-input size="small" type="number" v-model="paperHeight" style="width: 100px; text-align: center; border-left: 0"
- placeholder="高(mm)"/>
- <!-- <el-button type="primary" style="width: 100%" @click="otherPaper">确定</el-button> -->
- </div>
- <div style="text-align: right; margin: 0">
- <el-button size="mini" type="text" @click="visible = false">取消</el-button>
- <el-button type="primary" size="mini" @click="otherPaper">确定</el-button>
- </div>
- <el-button size="small" slot="reference">自定义纸张</el-button>
- </el-popover>
- </el-button-group>
- <el-button class="inline-16" size="small" type="primary" @click="onlyPrint">
- 打 印
- </el-button>
- <el-popconfirm
- title="确定删除吗?"
- @confirm="clearPaper">
- <el-button class="inline-16" slot="reference" size="small" type="danger">清空</el-button>
- </el-popconfirm>
- <bindData class="inline-16" ref="bind" :temp="jsonOut" :modeData="modeData"></bindData>
- <el-button size="small" type="primary" @click="exportJson">
- 保存
- </el-button>
- </div>
- <!-- <div style="margin-bottom: 10px">
- <el-button type="primary" @click="ippPrintAttr">
- ipp获取 打印机 参数情况
- </el-button>
- <el-button type="primary" @click="ippPrintTest">
- ipp打印测试
- </el-button>
- <el-button type="primary" @click="ippRequestTest">
- ipp请求 获取 打印机 参数情况
- </el-button>
- <el-button type="primary" @click="ippRequestPrint">
- ipp请求 打印测试
- </el-button>
- </div> -->
- <!-- <div style="margin-bottom: 10px">
- <a-textarea style="width:30vw" v-model:value="jsonIn" @pressEnter="updateJson" placeholder="复制json模板到此后 点击右侧更新"
- allow-clear/>
- <el-button type="primary" @click="updateJson">
- 更新json模板
- </el-button>
- <el-button type="primary" @click="exportJson">
- 导出json模板到 textArea
- </el-button>
- <a-textarea style="width:30vw" v-model:value="jsonOut" placeholder="点击左侧导出json" allow-clear/>
- </div>
- <div style="margin-bottom: 10px">
- <el-button type="primary" @click="getSelectEls">
- 获取选中元素
- </el-button>
- <el-button type="primary" @click="updateFontSize">
- 选中元素字体12pt
- </el-button>
- <el-button type="primary" @click="updateFontWeight">
- 选中元素字体Bolder
- </el-button>
- <el-button type="primary" @click="setElsSpace(true)"> 水平间距10
- </el-button>
- <el-button type="primary" @click="setElsSpace(false)"> 垂直间距10
- </el-button>
- <a-radio-group>
- <a-radio-button @click="setElsAlign('left')" title="左对齐">
- <span class="glyphicon glyphicon-object-align-left"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('vertical')" title="居中">
- <span class="glyphicon glyphicon-object-align-vertical"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('right')" title="右对齐">
- <span class="glyphicon glyphicon-object-align-right"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('top')" title="顶部对齐">
- <span class="glyphicon glyphicon-object-align-top"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('horizontal')" title="垂直居中">
- <span class="glyphicon glyphicon-object-align-horizontal"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('bottom')" title="底部对齐">
- <span class="glyphicon glyphicon-object-align-bottom"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('distributeHor')" title="横向分散">
- <span class="glyphicon glyphicon-resize-horizontal"></span>
- </a-radio-button>
- <a-radio-button @click="setElsAlign('distributeVer')" title="纵向分散">
- <span class="glyphicon glyphicon-resize-vertical"></span>
- </a-radio-button>
- </a-radio-group>
- </div> -->
- </div>
- <el-row :gutter="10">
- <el-col :span="4">
- <el-card style="height: 100vh">
- <el-row>
- <el-col :span="24" class="rect-printElement-types hiprintEpContainer">
- <el-row class="drag_item_title">拖拽组件列表</el-row>
- <el-row style="height: 100px;">
- <el-col :span="12" class="drag_item_box">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.text" style>
- <span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
- <p class="glyphicon-class">文本</p>
- </a>
- </div>
- </el-col>
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.image" style>
- <span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
- <p class="glyphicon-class">图片</p>
- </a>
- </div>
- </el-col>
- </el-row>
- <el-row style="height: 100px;">
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.longText">
- <span class="glyphicon glyphicon-subscript" aria-hidden="true"></span>
- <p class="glyphicon-class">长文</p>
- </a>
- </div>
- </el-col>
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.table" style>
- <span class="glyphicon glyphicon-th" aria-hidden="true"></span>
- <p class="glyphicon-class">表格</p>
- </a>
- </div>
- </el-col>
- </el-row>
- <el-row style="height: 100px;">
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.html" style="">
- <span class="glyphicon glyphicon-header" aria-hidden="true"></span>
- <p class="glyphicon-class">html</p>
- </a>
- </div>
- </el-col>
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.customTable" style>
- <span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
- <p class="glyphicon-class">简单表格</p>
- </a>
- </div>
- </el-col>
- </el-row>
- <el-row class="drag_item_title">辅助</el-row>
- <el-row style="height: 100px;">
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.hline" style>
- <span class="glyphicon glyphicon-resize-horizontal" aria-hidden="true"></span>
- <p class="glyphicon-class">横线</p>
- </a>
- </div>
- </el-col>
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.vline" style>
- <span class="glyphicon glyphicon-resize-vertical" aria-hidden="true"></span>
- <p class="glyphicon-class">竖线</p>
- </a>
- </div>
- </el-col>
- </el-row>
- <el-row style="height: 100px;">
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.rect">
- <span class="glyphicon glyphicon-unchecked" aria-hidden="true"></span>
- <p class="glyphicon-class">矩形</p>
- </a>
- </div>
- </el-col>
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.oval">
- <span class="glyphicon glyphicon-record" aria-hidden="true"></span>
- <p class="glyphicon-class">椭圆</p>
- </a>
- </div>
- </el-col>
- <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
- <div>
- <a class="ep-draggable-item" tid="defaultModule.customText" style>
- <span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
- <p class="glyphicon-class">描述文本</p>
- </a>
- </div>
- </el-col>
- </el-row>
- </el-col>
- </el-row>
- </el-card>
- </el-col>
- <el-col :span="15">
- <el-card class="card-design">
- <div id="hiprint-printTemplate" class="hiprint-printTemplate"></div>
- </el-card>
- </el-col>
- <el-col :span="5" class="params_setting_container">
- <el-card>
- <el-row class="hinnn-layout-sider">
- <div id="PrintElementOptionSetting"></div>
- </el-row>
- </el-card>
- </el-col>
- </el-row>
- </el-card>
- </template>
- <script>
- import {defaultElementTypeProvider, hiprint} from '@/index'
- import bindData from './components/bindData.vue'
- let hiprintTemplate;
- export default {
- name: "printDesign",
- components: {
- bindData
- },
- data() {
- return {
- visible:false,
- deactivated: false,
- curPaper: {
- type: 'A4',
- width: 210,
- height: 296.6
- },
- paperTypes: {
- 'A3': {
- width: 420,
- height: 296.6
- },
- 'A4': {
- width: 210,
- height: 296.6
- },
- 'A5': {
- width: 210,
- height: 147.6
- },
- 'B3': {
- width: 500,
- height: 352.6
- },
- 'B4': {
- width: 250,
- height: 352.6
- },
- 'B5': {
- width: 250,
- height: 175.6
- }
- },
- // 自定义纸张
- paperPopVisible: false,
- paperWidth: '220',
- paperHeight: '80',
- // 缩放
- scaleValue: 1,
- scaleMax: 5,
- scaleMin: 0.5,
- // 导入导出json
- jsonIn: '',
- jsonOut: '',
- panel:{},
- modeData:{}
- }
- },
- computed: {
- curPaperType() {
- let type = 'other'
- let types = this.paperTypes
- for (const key in types) {
- let item = types[key]
- let {width, height} = this.curPaper
- if (item.width === width && item.height === height) {
- type = key
- }
- }
- return type
- }
- },
- activated() {
- if (this.deactivated) {
- this.init();
- this.deactivated = false;
- }
- },
- deactivated() {
- this.deactivated = true;
- },
- mounted() {
- this.queryMode()
- var _this = this;
- document.onkeydown = function(e) {
- let key = window.event.keyCode;
- if (key == 83 && event.ctrlKey) {
- _this.exportJson()
- }
- };
- },
- methods: {
- async queryMode (id) {
- const res = await this.$api.requested({
- "id": 20221121155901,
- "content": {
- "sys_printmodelid":this.$route.query.id
- }
- })
- this.panel = JSON.parse(res.data.modeljson)
- this.modeData = res.data
- this.init()
- this.exportJson()
- },
- init() {
- hiprint.init({
- providers: [new defaultElementTypeProvider()]
- });
- // 还原配置
- hiprint.setConfig()
- // 替换配置
- hiprint.setConfig({
- optionItems: [
- function () {
- function t() {
- // json模板 options 对应键值
- this.name = "scale";
- }
- return t.prototype.css = function (t, e) { // t: 元素对象, e 参数值
- if (t && t.length) {
- if (e) return t.css('transform', 'scale(' + e + ')');
- }
- return null;
- }, t.prototype.createTarget = function (t, i, e) { // t: 元素对象,i: 元素options, e: 元素printElementType
- return this.target = $('<div class="hiprint-option-item">\n <div class="hiprint-option-item-label">\n 缩放\n </div>\n <div class="hiprint-option-item-field">\n <input type="number" class="auto-submit"/>\n </div>\n </div>'), this.target;
- }, t.prototype.getValue = function () {
- var t = this.target.find("input").val();
- if (t) return parseFloat(t.toString());
- }, t.prototype.setValue = function (t) { // t: options 对应键的值
- this.target.find("input").val(t);
- }, t.prototype.destroy = function () {
- this.target.remove();
- }, t;
- }(),
- function () {
- function t() {
- this.name = "zIndex";
- }
- return t.prototype.css = function (t, e) {
- if (t && t.length) {
- if (e) return t.css('z-index', e);
- }
- return null;
- }, t.prototype.createTarget = function () {
- return this.target = $('<div class="hiprint-option-item">\n <div class="hiprint-option-item-label">\n 元素层级2\n </div>\n <div class="hiprint-option-item-field">\n <input type="number" class="auto-submit"/>\n </div>\n </div>'), this.target;
- }, t.prototype.getValue = function () {
- var t = this.target.find("input").val();
- if (t) return parseInt(t.toString());
- }, t.prototype.setValue = function (t) {
- this.target.find("input").val(t);
- }, t.prototype.destroy = function () {
- this.target.remove();
- }, t;
- }(),
- ],
- movingDistance: 2.5,
- text: {
- tabs: [
- // 隐藏部分
- // {
- // name: '测试', options: [
- // {
- // name: 'title',
- // hidden: false
- // },
- // {
- // name: 'field',
- // hidden: true
- // },
- // ]
- // },
- {
- name: '样式', options: [
- {
- name: 'scale',
- after: 'transform', // 自定义参数,插入在 transform 之后
- hidden: false
- },
- ]
- }
- ],
- supportOptions: [
- {
- name: 'styler',
- hidden: true
- },
- {
- name: 'scale', // 自定义参数,supportOptions 必须得添加
- after: 'transform', // 自定义参数,插入在 transform 之后
- hidden: false
- },
- {
- name: 'formatter',
- hidden: true
- },
- ]
- },
- image: {
- tabs: [
- {
- // 整体替换
- replace: true,
- name: '基本', options: [
- {
- name: 'field',
- hidden: false
- },
- {
- name: 'src',
- hidden: false
- },
- {
- name: 'fit',
- hidden: false
- }
- ]
- },
- ],
- }
- })
- // eslint-disable-next-line no-undef
- hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
- $('#hiprint-printTemplate').empty()
- let that = this;
- hiprintTemplate = new hiprint.PrintTemplate({
- template: this.panel,
- // 图片选择功能
- onImageChooseClick: (target) => {
- // 测试 3秒后修改图片地址值
- setTimeout(() => {
- // target.refresh(url,options,callback)
- // callback(el, width, height) // 原元素,宽,高
- // target.refresh(url,false,(el,width,height)=>{
- // el.options.width = width;
- // el.designTarget.css('width', width + "pt");
- // el.designTarget.children('.resize-panel').trigger($.Event('click'));
- // })
- target.refresh("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtAAAAIIAQMAAAB99EudAAAABlBMVEUmf8vG2O41LStnAAABD0lEQVR42u3XQQqCQBSAYcWFS4/QUTpaHa2jdISWLUJjjMpclJoPGvq+1WsYfiJCZ4oCAAAAAAAAAAAAAAAAAHin6pL9c6H/fOzHbRrP0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0u/SY9LS0tLS0tLS0tLS0n+edm+UlpaWlpaWlpaWlpaW/tl0Ndyzbno7/+tPTJdd1wal69dNa6abx+Lq6TSeYtK7BX/Diek0XULSZZrakPRtV0i6Hu/KIt30q4fM0pvBqvR9mvsQkZaW9gyJT+f5lsnzjR54xAk8mAUeJyMPwYFH98ALx5Jr0kRLLndT7b64UX9QR/0eAAAAAAAAAAAAAAAAAAD/4gpryzr/bja4QgAAAABJRU5ErkJggg==",{
- // auto: true, // 根据图片宽高自动等比(宽>高?width:height)
- // width: true, // 按宽调整高
- // height: true, // 按高调整宽
- real: true // 根据图片实际尺寸调整(转pt)
- })
- }, 3000)
- // target.getValue()
- // target.refresh(url)
- },
- // 自定义可选字体
- // 或者使用 hiprintTemplate.setFontList([])
- // 或元素中 options.fontList: []
- fontList: [
- {title: '微软雅黑', value: 'Microsoft YaHei'},
- {title: '黑体', value: 'STHeitiSC-Light'},
- {title: '思源黑体', value: 'SourceHanSansCN-Normal'},
- {title: '王羲之书法体', value: '王羲之书法体'},
- {title: '宋体', value: 'SimSun'},
- {title: '华为楷体', value: 'STKaiti'},
- {title: 'cursive', value: 'cursive'},
- ],
- dataMode: 1, // 1:getJson 其他:getJsonTid 默认1
- history: true, // 是否需要 撤销重做功能
- onDataChanged: (type, json) => {
- console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转
- console.log(json); // 返回 template
- that.jsonOut = JSON.stringify(json)
- },
- onUpdateError: (e) => {
- console.log(e);
- },
- settingContainer: '#PrintElementOptionSetting',
- paginationContainer: '.hiprint-printPagination'
- });
- hiprintTemplate.design('#hiprint-printTemplate');
- console.log(hiprintTemplate);
- // 获取当前放大比例, 当zoom时传true 才会有
- this.scaleValue = hiprintTemplate.editingPanel.scale || 1;
- },
- /**
- * 设置纸张大小
- * @param type [A3, A4, A5, B3, B4, B5, other]
- * @param value {width,height} mm
- */
- setPaper(type, value) {
- try {
- if (Object.keys(this.paperTypes).includes(type)) {
- this.curPaper = {type: type, width: value.width, height: value.height}
- hiprintTemplate.setPaper(value.width, value.height)
- } else {
- this.curPaper = {type: 'other', width: value.width, height: value.height}
- hiprintTemplate.setPaper(value.width, value.height)
- }
- } catch (error) {
- this.$message.error(`操作失败: ${error}`)
- }
- },
- otherPaper() {
- let value = {}
- value.width = this.paperWidth
- value.height = this.paperHeight
- this.paperPopVisible = false
- this.setPaper('other', value)
- },
- changeScale(big) {
- let scaleValue = this.scaleValue;
- if (big) {
- scaleValue += 0.1;
- if (scaleValue > this.scaleMax) scaleValue = 5;
- } else {
- scaleValue -= 0.1;
- if (scaleValue < this.scaleMin) scaleValue = 0.5;
- }
- if (hiprintTemplate) {
- // scaleValue: 放大缩小值, false: 不保存(不传也一样), 如果传 true, 打印时也会放大
- hiprintTemplate.zoom(scaleValue);
- this.scaleValue = scaleValue;
- }
- },
- rotatePaper() {
- if (hiprintTemplate) {
- hiprintTemplate.rotatePaper()
- }
- },
- preView() {
- // 测试, 点预览更新拖拽元素
- hiprint.updateElementType('defaultModule.text', (type) => {
- type.title = '这是更新后的元素';
- return type
- })
- // 测试, 通过socket刷新打印机列表; 默认只有连接的时候才会获取到最新的打印机列表
- hiprint.refreshPrinterList((list) => {
- console.log('refreshPrinterList')
- console.log(list)
- });
- // 测试, 获取IP、IPV6、MAC地址、DNS
- // 参数格式:
- // 1. 类型(ip、ipv6、mac、dns、all、interface、vboxnet)
- // 2. 回调 data => {addr, e} addr: 返回的数据 e:错误信息
- // 3. 其他参数 ...args
- hiprint.getAddress('ip', (data) => {
- console.log('ip')
- console.log(data)
- })
- hiprint.getAddress('ipv6', (data) => {
- console.log('ipv6')
- console.log(data)
- })
- hiprint.getAddress('mac', (data) => {
- console.log('mac')
- console.log(data)
- })
- hiprint.getAddress('dns', (data) => {
- console.log('dns')
- console.log(data)
- })
- hiprint.getAddress('all', (data) => {
- console.log('all')
- console.log(data)
- })
- // 各个平台不一样, 用法见: https://www.npmjs.com/package/address
- hiprint.getAddress('interface', (data) => {
- console.log('interface')
- console.log(data)
- }, 'IPv4', 'eth1')
- this.$refs.preView.show(hiprintTemplate, printData)
- },
- onlyPrint() {
- let hiprintTemplate = this.$print(undefined, this.panel, {}, {}, {
- styleHandler: () => {
- let css = '<link href="http://hiprint.io/Content/hiprint/css/print-lock.css" media="print" rel="stylesheet">';
- return css
- }
- })
- console.log(hiprintTemplate);
- },
- onlyPrint2() {
- let that = this;
- if (window.hiwebSocket.opened) {
- let hiprintTemplate = this.$print2(undefined, panel, printData, {
- printer: '', title: 'Api单独打印',
- styleHandler: () => {
- // let css = '<link href="http://hiprint.io/Content/hiprint/css/print-lock.css" media="print" rel="stylesheet">';
- let css = '<style>.hiprint-printElement-text{color:red !important;}</style>'
- return css
- }
- })
- let key = 'Api单独直接打印';
- hiprintTemplate.on('printSuccess', function () {
- that.$notification.success({
- key: key,
- placement: 'topRight',
- message: key + ' 打印成功',
- description: 'Api单独直接打印回调',
- });
- });
- return;
- }
- this.$message.error('客户端未连接,无法直接打印')
- },
- print() {
- if (window.hiwebSocket.opened) {
- const printerList = hiprintTemplate.getPrinterList();
- console.log(printerList)
- hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'});
- return
- }
- this.$message.error('客户端未连接,无法直接打印')
- },
- clearPaper() {
- try {
- hiprintTemplate.clear();
- } catch (error) {
- this.$message.error(`操作失败: ${error}`);
- }
- },
- ippPrintAttr() {
- // 不知道打印机 ipp 情况, 可通过 '客户端' 获取一下
- const printerList = hiprintTemplate.getPrinterList();
- console.log(printerList)
- if (!printerList.length) return;
- let p = printerList[0];
- console.log(p)
- // 系统不同, 参数可能不同
- let url = p.options['printer-uri-supported'];
- // 测试 获取 ipp打印 支持参数
- hiprint.ippPrint({
- url: url,
- // 打印机参数: {version,uri,charset,language}
- opt: {},
- action: 'Get-Printer-Attributes', // 获取打印机支持参数
- // ipp参数
- message: null,
- }, (res) => {
- // 执行的ipp 任务回调 / 错误回调
- console.log(res)
- }, (printer) => {
- // ipp连接成功 回调 打印机信息
- console.log(printer)
- })
- },
- ippPrintTest() {
- // 不知道打印机 ipp 情况, 可通过 '客户端' 获取一下
- const printerList = hiprintTemplate.getPrinterList();
- console.log(printerList)
- if (!printerList.length) return;
- let p = printerList[0];
- console.log(p)
- // 系统不同, 参数可能不同
- let url = p.options['printer-uri-supported'];
- // 测试 打印文本
- hiprint.ippPrint({
- url: url,
- // 打印机参数: {version,uri,charset,language}
- opt: {},
- action: 'Print-Job',
- // ipp参数
- message: {
- "operation-attributes-tag": {
- "requesting-user-name": "hiPrint", // 用户名
- "job-name": "ipp Test Job", // 任务名
- "document-format": "text/plain" // 文档类型
- },
- // data 需为 Buffer (客户端简单处理了string 转 Buffer), 支持设置 encoding
- // data 需为 Buffer (客户端简单处理了string 转 Buffer), 支持设置 encoding
- // data 需为 Buffer (客户端简单处理了string 转 Buffer), 支持设置 encoding
- // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
- // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
- // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
- // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
- data: 'test test test test test test test',
- encoding: 'utf-8' // 默认可不传
- }
- }, (res) => {
- // 执行的ipp 任务回调 / 错误回调
- console.log(res)
- }, (printer) => {
- // ipp连接成功 回调 打印机信息
- console.log(printer)
- })
- },
- // 自定义 ipp 请求
- ippRequestTest() {
- const printerList = hiprintTemplate.getPrinterList();
- console.log(printerList)
- if (!printerList.length) return;
- let p = printerList[0];
- console.log(p)
- // 系统不同, 参数可能不同
- let url = p.options['printer-uri-supported'];
- // 详见: https://www.npmjs.com/package/ipp
- hiprint.ippRequest({
- url: url,
- // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
- // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
- // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
- data: {
- "operation": "Get-Printer-Attributes",
- "operation-attributes-tag": {
- // 测试发现 Request下列3个必须要有
- "attributes-charset": "utf-8",
- "attributes-natural-language": "zh-cn",
- "printer-uri": url
- }
- }
- }, (res) => {
- // 执行的ipp 任务回调 / 错误回调
- console.log(res)
- })
- },
- ippRequestPrint() {
- const printerList = hiprintTemplate.getPrinterList();
- console.log(printerList)
- if (!printerList.length) return;
- let p = printerList[0];
- console.log(p)
- // 系统不同, 参数可能不同
- let url = p.options['printer-uri-supported'];
- let str = "ippRequestPrint ippRequestPrint ippRequestPrint";
- let array = new Uint8Array(str.length);
- for (var i = 0; i < str.length; i++) {
- array[i] = str.charCodeAt(i);
- }
- let testData = array.buffer;
- // 详见: https://www.npmjs.com/package/ipp
- hiprint.ippRequest({
- url: url,
- // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
- // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
- // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
- data: {
- "operation": "Print-Job",
- "operation-attributes-tag": {
- // 测试发现 Request下列3个必须要有
- "attributes-charset": "utf-8",
- "attributes-natural-language": "zh-cn",
- "printer-uri": url,
- "requesting-user-name": "hiPrint", // 用户名
- "job-name": "ipp Request Job", // 任务名
- "document-format": "text/plain" // 文档类型
- },
- data: testData
- }
- }, (res) => {
- // 执行的ipp 任务回调 / 错误回调
- console.log(res)
- })
- },
- updateJson() {
- if (hiprintTemplate) {
- try {
- hiprintTemplate.update(JSON.parse(this.jsonIn))
- } catch (e) {
- this.$message.error(`更新失败: ${e}`)
- }
- }
- },
- exportJson() {
- if (hiprintTemplate) {
- this.jsonOut = JSON.stringify(hiprintTemplate.getJson() || {})
- setTimeout(() => {
- this.$refs['bind'].saveJson()
- }, 500);
- }
- },
- setElsAlign(e) {
- hiprintTemplate.setElsAlign(e)
- },
- setElsSpace(h) {
- hiprintTemplate.setElsSpace(10, h)
- },
- getSelectEls() {
- let els = hiprintTemplate.getSelectEls();
- console.log(els)
- },
- updateFontSize() {
- hiprintTemplate.updateOption('fontSize', 12);
- },
- updateFontWeight() {
- hiprintTemplate.updateOption('fontWeight', 'bolder');
- },
- test () {
- var hiprintTemplate = new hiprint.PrintTemplate();
- var panel = hiprintTemplate.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 });
- panel.addPrintTable({ options: { width: 252, height: 35, top: 130, left: 20, content: $('#testTable').html() } });
- }
- }
- }
- </script>
- <style scoped>
- .drag_item_box {
- height: 100%;
- padding: 6px;
- }
- .drag_item_box > div {
- height: 100%;
- width: 100%;
- background-color: #fff;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .drag_item_box > div > a {
- text-align: center;
- text-decoration-line: none;
- }
- .drag_item_box > div > a > span {
- font-size: 28px;
- }
- .drag_item_box > div > a > p {
- margin: 0;
- }
- .drag_item_title {
- font-size: 16px;
- padding: 12px 6px 0 6px;
- font-weight: bold;
- }
- <<<<<<< HEAD
- /* /deep/ .hiprint-printElement-image-content {
- img {
- // content: url("~@/assets/logo.png");
- }
- } */
- =======
- >>>>>>> xiaoqin
- /deep/ .toplineOfPosition {
- border: 0;
- border-top: 1px dashed purple;
- }
- /deep/ .bottomlineOfPosition {
- border: 0;
- border-top: 1px dashed purple;
- }
- /deep/ .leftlineOfPosition {
- border: 0;
- border-left: 1px dashed purple;
- }
- /deep/ .rightlineOfPosition {
- border: 0;
- border-left: 1px dashed purple;
- }
- .card-design {
- overflow: hidden;
- overflow-x: auto;
- overflow-y: auto;
- }
- </style>
|