index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. <template>
  2. <el-card>
  3. <div style="display: flex;flex-direction: column">
  4. <div style="margin-bottom: 10px">
  5. <el-button @click="$router.go(-1)" type="text" class="inline-16">返回模板列表</el-button>
  6. <el-button-group class="inline-16">
  7. <template v-for="(value,type) in paperTypes">
  8. <el-button size="small" :type="curPaperType === type ? 'primary' : 'default'" @click="setPaper(type,value)" :key="type">
  9. {{ type }}
  10. </el-button>
  11. </template>
  12. <el-popover
  13. placement="bottom"
  14. trigger="click"
  15. v-model="visible">
  16. <div class="flex-align-center flex-between normal-margin">
  17. <el-input size="small" type="number" v-model="paperWidth" style=" width: 100px; text-align: center"
  18. placeholder="宽(mm)"/>
  19. <p>-</p>
  20. <el-input size="small" type="number" v-model="paperHeight" style="width: 100px; text-align: center; border-left: 0"
  21. placeholder="高(mm)"/>
  22. <!-- <el-button type="primary" style="width: 100%" @click="otherPaper">确定</el-button> -->
  23. </div>
  24. <div style="text-align: right; margin: 0">
  25. <el-button size="mini" type="text" @click="visible = false">取消</el-button>
  26. <el-button type="primary" size="mini" @click="otherPaper">确定</el-button>
  27. </div>
  28. <el-button size="small" slot="reference">自定义纸张</el-button>
  29. </el-popover>
  30. </el-button-group>
  31. <el-button class="inline-16" size="small" type="primary" @click="onlyPrint">
  32. 打 印
  33. </el-button>
  34. <el-popconfirm
  35. title="确定删除吗?"
  36. @confirm="clearPaper">
  37. <el-button class="inline-16" slot="reference" size="small" type="danger">清空</el-button>
  38. </el-popconfirm>
  39. <bindData class="inline-16" ref="bind" :temp="jsonOut" :modeData="modeData"></bindData>
  40. <el-button size="small" type="primary" @click="exportJson">
  41. 保存
  42. </el-button>
  43. </div>
  44. <!-- <div style="margin-bottom: 10px">
  45. <el-button type="primary" @click="ippPrintAttr">
  46. ipp获取 打印机 参数情况
  47. </el-button>
  48. <el-button type="primary" @click="ippPrintTest">
  49. ipp打印测试
  50. </el-button>
  51. <el-button type="primary" @click="ippRequestTest">
  52. ipp请求 获取 打印机 参数情况
  53. </el-button>
  54. <el-button type="primary" @click="ippRequestPrint">
  55. ipp请求 打印测试
  56. </el-button>
  57. </div> -->
  58. <!-- <div style="margin-bottom: 10px">
  59. <a-textarea style="width:30vw" v-model:value="jsonIn" @pressEnter="updateJson" placeholder="复制json模板到此后 点击右侧更新"
  60. allow-clear/>
  61. <el-button type="primary" @click="updateJson">
  62. 更新json模板
  63. </el-button>
  64. <el-button type="primary" @click="exportJson">
  65. 导出json模板到 textArea
  66. </el-button>
  67. <a-textarea style="width:30vw" v-model:value="jsonOut" placeholder="点击左侧导出json" allow-clear/>
  68. </div>
  69. <div style="margin-bottom: 10px">
  70. <el-button type="primary" @click="getSelectEls">
  71. 获取选中元素
  72. </el-button>
  73. <el-button type="primary" @click="updateFontSize">
  74. 选中元素字体12pt
  75. </el-button>
  76. <el-button type="primary" @click="updateFontWeight">
  77. 选中元素字体Bolder
  78. </el-button>
  79. <el-button type="primary" @click="setElsSpace(true)"> 水平间距10
  80. </el-button>
  81. <el-button type="primary" @click="setElsSpace(false)"> 垂直间距10
  82. </el-button>
  83. <a-radio-group>
  84. <a-radio-button @click="setElsAlign('left')" title="左对齐">
  85. <span class="glyphicon glyphicon-object-align-left"></span>
  86. </a-radio-button>
  87. <a-radio-button @click="setElsAlign('vertical')" title="居中">
  88. <span class="glyphicon glyphicon-object-align-vertical"></span>
  89. </a-radio-button>
  90. <a-radio-button @click="setElsAlign('right')" title="右对齐">
  91. <span class="glyphicon glyphicon-object-align-right"></span>
  92. </a-radio-button>
  93. <a-radio-button @click="setElsAlign('top')" title="顶部对齐">
  94. <span class="glyphicon glyphicon-object-align-top"></span>
  95. </a-radio-button>
  96. <a-radio-button @click="setElsAlign('horizontal')" title="垂直居中">
  97. <span class="glyphicon glyphicon-object-align-horizontal"></span>
  98. </a-radio-button>
  99. <a-radio-button @click="setElsAlign('bottom')" title="底部对齐">
  100. <span class="glyphicon glyphicon-object-align-bottom"></span>
  101. </a-radio-button>
  102. <a-radio-button @click="setElsAlign('distributeHor')" title="横向分散">
  103. <span class="glyphicon glyphicon-resize-horizontal"></span>
  104. </a-radio-button>
  105. <a-radio-button @click="setElsAlign('distributeVer')" title="纵向分散">
  106. <span class="glyphicon glyphicon-resize-vertical"></span>
  107. </a-radio-button>
  108. </a-radio-group>
  109. </div> -->
  110. </div>
  111. <el-row :gutter="10">
  112. <el-col :span="4">
  113. <el-card style="height: 100vh">
  114. <el-row>
  115. <el-col :span="24" class="rect-printElement-types hiprintEpContainer">
  116. <el-row class="drag_item_title">拖拽组件列表</el-row>
  117. <el-row style="height: 100px;">
  118. <el-col :span="12" class="drag_item_box">
  119. <div>
  120. <a class="ep-draggable-item" tid="defaultModule.text" style>
  121. <span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
  122. <p class="glyphicon-class">文本</p>
  123. </a>
  124. </div>
  125. </el-col>
  126. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  127. <div>
  128. <a class="ep-draggable-item" tid="defaultModule.image" style>
  129. <span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
  130. <p class="glyphicon-class">图片</p>
  131. </a>
  132. </div>
  133. </el-col>
  134. </el-row>
  135. <el-row style="height: 100px;">
  136. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  137. <div>
  138. <a class="ep-draggable-item" tid="defaultModule.longText">
  139. <span class="glyphicon glyphicon-subscript" aria-hidden="true"></span>
  140. <p class="glyphicon-class">长文</p>
  141. </a>
  142. </div>
  143. </el-col>
  144. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  145. <div>
  146. <a class="ep-draggable-item" tid="defaultModule.table" style>
  147. <span class="glyphicon glyphicon-th" aria-hidden="true"></span>
  148. <p class="glyphicon-class">表格</p>
  149. </a>
  150. </div>
  151. </el-col>
  152. </el-row>
  153. <el-row style="height: 100px;">
  154. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  155. <div>
  156. <a class="ep-draggable-item" tid="defaultModule.html" style="">
  157. <span class="glyphicon glyphicon-header" aria-hidden="true"></span>
  158. <p class="glyphicon-class">html</p>
  159. </a>
  160. </div>
  161. </el-col>
  162. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  163. <div>
  164. <a class="ep-draggable-item" tid="defaultModule.customTable" style>
  165. <span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
  166. <p class="glyphicon-class">简单表格</p>
  167. </a>
  168. </div>
  169. </el-col>
  170. </el-row>
  171. <el-row class="drag_item_title">辅助</el-row>
  172. <el-row style="height: 100px;">
  173. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  174. <div>
  175. <a class="ep-draggable-item" tid="defaultModule.hline" style>
  176. <span class="glyphicon glyphicon-resize-horizontal" aria-hidden="true"></span>
  177. <p class="glyphicon-class">横线</p>
  178. </a>
  179. </div>
  180. </el-col>
  181. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  182. <div>
  183. <a class="ep-draggable-item" tid="defaultModule.vline" style>
  184. <span class="glyphicon glyphicon-resize-vertical" aria-hidden="true"></span>
  185. <p class="glyphicon-class">竖线</p>
  186. </a>
  187. </div>
  188. </el-col>
  189. </el-row>
  190. <el-row style="height: 100px;">
  191. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  192. <div>
  193. <a class="ep-draggable-item" tid="defaultModule.rect">
  194. <span class="glyphicon glyphicon-unchecked" aria-hidden="true"></span>
  195. <p class="glyphicon-class">矩形</p>
  196. </a>
  197. </div>
  198. </el-col>
  199. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  200. <div>
  201. <a class="ep-draggable-item" tid="defaultModule.oval">
  202. <span class="glyphicon glyphicon-record" aria-hidden="true"></span>
  203. <p class="glyphicon-class">椭圆</p>
  204. </a>
  205. </div>
  206. </el-col>
  207. <el-col :span="12" class="drag_item_box" tid="defaultModule.text">
  208. <div>
  209. <a class="ep-draggable-item" tid="defaultModule.customText" style>
  210. <span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
  211. <p class="glyphicon-class">描述文本</p>
  212. </a>
  213. </div>
  214. </el-col>
  215. </el-row>
  216. </el-col>
  217. </el-row>
  218. </el-card>
  219. </el-col>
  220. <el-col :span="15">
  221. <el-card class="card-design">
  222. <div id="hiprint-printTemplate" class="hiprint-printTemplate"></div>
  223. </el-card>
  224. </el-col>
  225. <el-col :span="5" class="params_setting_container">
  226. <el-card>
  227. <el-row class="hinnn-layout-sider">
  228. <div id="PrintElementOptionSetting"></div>
  229. </el-row>
  230. </el-card>
  231. </el-col>
  232. </el-row>
  233. </el-card>
  234. </template>
  235. <script>
  236. import {defaultElementTypeProvider, hiprint} from '@/index'
  237. import bindData from './components/bindData.vue'
  238. let hiprintTemplate;
  239. export default {
  240. name: "printDesign",
  241. components: {
  242. bindData
  243. },
  244. data() {
  245. return {
  246. visible:false,
  247. deactivated: false,
  248. curPaper: {
  249. type: 'A4',
  250. width: 210,
  251. height: 296.6
  252. },
  253. paperTypes: {
  254. 'A3': {
  255. width: 420,
  256. height: 296.6
  257. },
  258. 'A4': {
  259. width: 210,
  260. height: 296.6
  261. },
  262. 'A5': {
  263. width: 210,
  264. height: 147.6
  265. },
  266. 'B3': {
  267. width: 500,
  268. height: 352.6
  269. },
  270. 'B4': {
  271. width: 250,
  272. height: 352.6
  273. },
  274. 'B5': {
  275. width: 250,
  276. height: 175.6
  277. }
  278. },
  279. // 自定义纸张
  280. paperPopVisible: false,
  281. paperWidth: '220',
  282. paperHeight: '80',
  283. // 缩放
  284. scaleValue: 1,
  285. scaleMax: 5,
  286. scaleMin: 0.5,
  287. // 导入导出json
  288. jsonIn: '',
  289. jsonOut: '',
  290. panel:{},
  291. modeData:{}
  292. }
  293. },
  294. computed: {
  295. curPaperType() {
  296. let type = 'other'
  297. let types = this.paperTypes
  298. for (const key in types) {
  299. let item = types[key]
  300. let {width, height} = this.curPaper
  301. if (item.width === width && item.height === height) {
  302. type = key
  303. }
  304. }
  305. return type
  306. }
  307. },
  308. activated() {
  309. if (this.deactivated) {
  310. this.init();
  311. this.deactivated = false;
  312. }
  313. },
  314. deactivated() {
  315. this.deactivated = true;
  316. },
  317. mounted() {
  318. this.queryMode()
  319. var _this = this;
  320. document.onkeydown = function(e) {
  321. let key = window.event.keyCode;
  322. if (key == 83 && event.ctrlKey) {
  323. _this.exportJson()
  324. }
  325. };
  326. },
  327. methods: {
  328. async queryMode (id) {
  329. const res = await this.$api.requested({
  330. "id": 20221121155901,
  331. "content": {
  332. "sys_printmodelid":this.$route.query.id
  333. }
  334. })
  335. this.panel = JSON.parse(res.data.modeljson)
  336. this.modeData = res.data
  337. this.init()
  338. this.exportJson()
  339. },
  340. init() {
  341. hiprint.init({
  342. providers: [new defaultElementTypeProvider()]
  343. });
  344. // 还原配置
  345. hiprint.setConfig()
  346. // 替换配置
  347. hiprint.setConfig({
  348. optionItems: [
  349. function () {
  350. function t() {
  351. // json模板 options 对应键值
  352. this.name = "scale";
  353. }
  354. return t.prototype.css = function (t, e) { // t: 元素对象, e 参数值
  355. if (t && t.length) {
  356. if (e) return t.css('transform', 'scale(' + e + ')');
  357. }
  358. return null;
  359. }, t.prototype.createTarget = function (t, i, e) { // t: 元素对象,i: 元素options, e: 元素printElementType
  360. 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;
  361. }, t.prototype.getValue = function () {
  362. var t = this.target.find("input").val();
  363. if (t) return parseFloat(t.toString());
  364. }, t.prototype.setValue = function (t) { // t: options 对应键的值
  365. this.target.find("input").val(t);
  366. }, t.prototype.destroy = function () {
  367. this.target.remove();
  368. }, t;
  369. }(),
  370. function () {
  371. function t() {
  372. this.name = "zIndex";
  373. }
  374. return t.prototype.css = function (t, e) {
  375. if (t && t.length) {
  376. if (e) return t.css('z-index', e);
  377. }
  378. return null;
  379. }, t.prototype.createTarget = function () {
  380. 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;
  381. }, t.prototype.getValue = function () {
  382. var t = this.target.find("input").val();
  383. if (t) return parseInt(t.toString());
  384. }, t.prototype.setValue = function (t) {
  385. this.target.find("input").val(t);
  386. }, t.prototype.destroy = function () {
  387. this.target.remove();
  388. }, t;
  389. }(),
  390. ],
  391. movingDistance: 2.5,
  392. text: {
  393. tabs: [
  394. // 隐藏部分
  395. // {
  396. // name: '测试', options: [
  397. // {
  398. // name: 'title',
  399. // hidden: false
  400. // },
  401. // {
  402. // name: 'field',
  403. // hidden: true
  404. // },
  405. // ]
  406. // },
  407. {
  408. name: '样式', options: [
  409. {
  410. name: 'scale',
  411. after: 'transform', // 自定义参数,插入在 transform 之后
  412. hidden: false
  413. },
  414. ]
  415. }
  416. ],
  417. supportOptions: [
  418. {
  419. name: 'styler',
  420. hidden: true
  421. },
  422. {
  423. name: 'scale', // 自定义参数,supportOptions 必须得添加
  424. after: 'transform', // 自定义参数,插入在 transform 之后
  425. hidden: false
  426. },
  427. {
  428. name: 'formatter',
  429. hidden: true
  430. },
  431. ]
  432. },
  433. image: {
  434. tabs: [
  435. {
  436. // 整体替换
  437. replace: true,
  438. name: '基本', options: [
  439. {
  440. name: 'field',
  441. hidden: false
  442. },
  443. {
  444. name: 'src',
  445. hidden: false
  446. },
  447. {
  448. name: 'fit',
  449. hidden: false
  450. }
  451. ]
  452. },
  453. ],
  454. }
  455. })
  456. // eslint-disable-next-line no-undef
  457. hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
  458. $('#hiprint-printTemplate').empty()
  459. let that = this;
  460. hiprintTemplate = new hiprint.PrintTemplate({
  461. template: this.panel,
  462. // 图片选择功能
  463. onImageChooseClick: (target) => {
  464. // 测试 3秒后修改图片地址值
  465. setTimeout(() => {
  466. // target.refresh(url,options,callback)
  467. // callback(el, width, height) // 原元素,宽,高
  468. // target.refresh(url,false,(el,width,height)=>{
  469. // el.options.width = width;
  470. // el.designTarget.css('width', width + "pt");
  471. // el.designTarget.children('.resize-panel').trigger($.Event('click'));
  472. // })
  473. target.refresh("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtAAAAIIAQMAAAB99EudAAAABlBMVEUmf8vG2O41LStnAAABD0lEQVR42u3XQQqCQBSAYcWFS4/QUTpaHa2jdISWLUJjjMpclJoPGvq+1WsYfiJCZ4oCAAAAAAAAAAAAAAAAAHin6pL9c6H/fOzHbRrP0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0u/SY9LS0tLS0tLS0tLS0n+edm+UlpaWlpaWlpaWlpaW/tl0Ndyzbno7/+tPTJdd1wal69dNa6abx+Lq6TSeYtK7BX/Diek0XULSZZrakPRtV0i6Hu/KIt30q4fM0pvBqvR9mvsQkZaW9gyJT+f5lsnzjR54xAk8mAUeJyMPwYFH98ALx5Jr0kRLLndT7b64UX9QR/0eAAAAAAAAAAAAAAAAAAD/4gpryzr/bja4QgAAAABJRU5ErkJggg==",{
  474. // auto: true, // 根据图片宽高自动等比(宽>高?width:height)
  475. // width: true, // 按宽调整高
  476. // height: true, // 按高调整宽
  477. real: true // 根据图片实际尺寸调整(转pt)
  478. })
  479. }, 3000)
  480. // target.getValue()
  481. // target.refresh(url)
  482. },
  483. // 自定义可选字体
  484. // 或者使用 hiprintTemplate.setFontList([])
  485. // 或元素中 options.fontList: []
  486. fontList: [
  487. {title: '微软雅黑', value: 'Microsoft YaHei'},
  488. {title: '黑体', value: 'STHeitiSC-Light'},
  489. {title: '思源黑体', value: 'SourceHanSansCN-Normal'},
  490. {title: '王羲之书法体', value: '王羲之书法体'},
  491. {title: '宋体', value: 'SimSun'},
  492. {title: '华为楷体', value: 'STKaiti'},
  493. {title: 'cursive', value: 'cursive'},
  494. ],
  495. dataMode: 1, // 1:getJson 其他:getJsonTid 默认1
  496. history: true, // 是否需要 撤销重做功能
  497. onDataChanged: (type, json) => {
  498. console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转
  499. console.log(json); // 返回 template
  500. that.jsonOut = JSON.stringify(json)
  501. },
  502. onUpdateError: (e) => {
  503. console.log(e);
  504. },
  505. settingContainer: '#PrintElementOptionSetting',
  506. paginationContainer: '.hiprint-printPagination'
  507. });
  508. hiprintTemplate.design('#hiprint-printTemplate');
  509. console.log(hiprintTemplate);
  510. // 获取当前放大比例, 当zoom时传true 才会有
  511. this.scaleValue = hiprintTemplate.editingPanel.scale || 1;
  512. },
  513. /**
  514. * 设置纸张大小
  515. * @param type [A3, A4, A5, B3, B4, B5, other]
  516. * @param value {width,height} mm
  517. */
  518. setPaper(type, value) {
  519. try {
  520. if (Object.keys(this.paperTypes).includes(type)) {
  521. this.curPaper = {type: type, width: value.width, height: value.height}
  522. hiprintTemplate.setPaper(value.width, value.height)
  523. } else {
  524. this.curPaper = {type: 'other', width: value.width, height: value.height}
  525. hiprintTemplate.setPaper(value.width, value.height)
  526. }
  527. } catch (error) {
  528. this.$message.error(`操作失败: ${error}`)
  529. }
  530. },
  531. otherPaper() {
  532. let value = {}
  533. value.width = this.paperWidth
  534. value.height = this.paperHeight
  535. this.paperPopVisible = false
  536. this.setPaper('other', value)
  537. },
  538. changeScale(big) {
  539. let scaleValue = this.scaleValue;
  540. if (big) {
  541. scaleValue += 0.1;
  542. if (scaleValue > this.scaleMax) scaleValue = 5;
  543. } else {
  544. scaleValue -= 0.1;
  545. if (scaleValue < this.scaleMin) scaleValue = 0.5;
  546. }
  547. if (hiprintTemplate) {
  548. // scaleValue: 放大缩小值, false: 不保存(不传也一样), 如果传 true, 打印时也会放大
  549. hiprintTemplate.zoom(scaleValue);
  550. this.scaleValue = scaleValue;
  551. }
  552. },
  553. rotatePaper() {
  554. if (hiprintTemplate) {
  555. hiprintTemplate.rotatePaper()
  556. }
  557. },
  558. preView() {
  559. // 测试, 点预览更新拖拽元素
  560. hiprint.updateElementType('defaultModule.text', (type) => {
  561. type.title = '这是更新后的元素';
  562. return type
  563. })
  564. // 测试, 通过socket刷新打印机列表; 默认只有连接的时候才会获取到最新的打印机列表
  565. hiprint.refreshPrinterList((list) => {
  566. console.log('refreshPrinterList')
  567. console.log(list)
  568. });
  569. // 测试, 获取IP、IPV6、MAC地址、DNS
  570. // 参数格式:
  571. // 1. 类型(ip、ipv6、mac、dns、all、interface、vboxnet)
  572. // 2. 回调 data => {addr, e} addr: 返回的数据 e:错误信息
  573. // 3. 其他参数 ...args
  574. hiprint.getAddress('ip', (data) => {
  575. console.log('ip')
  576. console.log(data)
  577. })
  578. hiprint.getAddress('ipv6', (data) => {
  579. console.log('ipv6')
  580. console.log(data)
  581. })
  582. hiprint.getAddress('mac', (data) => {
  583. console.log('mac')
  584. console.log(data)
  585. })
  586. hiprint.getAddress('dns', (data) => {
  587. console.log('dns')
  588. console.log(data)
  589. })
  590. hiprint.getAddress('all', (data) => {
  591. console.log('all')
  592. console.log(data)
  593. })
  594. // 各个平台不一样, 用法见: https://www.npmjs.com/package/address
  595. hiprint.getAddress('interface', (data) => {
  596. console.log('interface')
  597. console.log(data)
  598. }, 'IPv4', 'eth1')
  599. this.$refs.preView.show(hiprintTemplate, printData)
  600. },
  601. onlyPrint() {
  602. let hiprintTemplate = this.$print(undefined, this.panel, {}, {}, {
  603. styleHandler: () => {
  604. let css = '<link href="http://hiprint.io/Content/hiprint/css/print-lock.css" media="print" rel="stylesheet">';
  605. return css
  606. }
  607. })
  608. console.log(hiprintTemplate);
  609. },
  610. onlyPrint2() {
  611. let that = this;
  612. if (window.hiwebSocket.opened) {
  613. let hiprintTemplate = this.$print2(undefined, panel, printData, {
  614. printer: '', title: 'Api单独打印',
  615. styleHandler: () => {
  616. // let css = '<link href="http://hiprint.io/Content/hiprint/css/print-lock.css" media="print" rel="stylesheet">';
  617. let css = '<style>.hiprint-printElement-text{color:red !important;}</style>'
  618. return css
  619. }
  620. })
  621. let key = 'Api单独直接打印';
  622. hiprintTemplate.on('printSuccess', function () {
  623. that.$notification.success({
  624. key: key,
  625. placement: 'topRight',
  626. message: key + ' 打印成功',
  627. description: 'Api单独直接打印回调',
  628. });
  629. });
  630. return;
  631. }
  632. this.$message.error('客户端未连接,无法直接打印')
  633. },
  634. print() {
  635. if (window.hiwebSocket.opened) {
  636. const printerList = hiprintTemplate.getPrinterList();
  637. console.log(printerList)
  638. hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'});
  639. return
  640. }
  641. this.$message.error('客户端未连接,无法直接打印')
  642. },
  643. clearPaper() {
  644. try {
  645. hiprintTemplate.clear();
  646. } catch (error) {
  647. this.$message.error(`操作失败: ${error}`);
  648. }
  649. },
  650. ippPrintAttr() {
  651. // 不知道打印机 ipp 情况, 可通过 '客户端' 获取一下
  652. const printerList = hiprintTemplate.getPrinterList();
  653. console.log(printerList)
  654. if (!printerList.length) return;
  655. let p = printerList[0];
  656. console.log(p)
  657. // 系统不同, 参数可能不同
  658. let url = p.options['printer-uri-supported'];
  659. // 测试 获取 ipp打印 支持参数
  660. hiprint.ippPrint({
  661. url: url,
  662. // 打印机参数: {version,uri,charset,language}
  663. opt: {},
  664. action: 'Get-Printer-Attributes', // 获取打印机支持参数
  665. // ipp参数
  666. message: null,
  667. }, (res) => {
  668. // 执行的ipp 任务回调 / 错误回调
  669. console.log(res)
  670. }, (printer) => {
  671. // ipp连接成功 回调 打印机信息
  672. console.log(printer)
  673. })
  674. },
  675. ippPrintTest() {
  676. // 不知道打印机 ipp 情况, 可通过 '客户端' 获取一下
  677. const printerList = hiprintTemplate.getPrinterList();
  678. console.log(printerList)
  679. if (!printerList.length) return;
  680. let p = printerList[0];
  681. console.log(p)
  682. // 系统不同, 参数可能不同
  683. let url = p.options['printer-uri-supported'];
  684. // 测试 打印文本
  685. hiprint.ippPrint({
  686. url: url,
  687. // 打印机参数: {version,uri,charset,language}
  688. opt: {},
  689. action: 'Print-Job',
  690. // ipp参数
  691. message: {
  692. "operation-attributes-tag": {
  693. "requesting-user-name": "hiPrint", // 用户名
  694. "job-name": "ipp Test Job", // 任务名
  695. "document-format": "text/plain" // 文档类型
  696. },
  697. // data 需为 Buffer (客户端简单处理了string 转 Buffer), 支持设置 encoding
  698. // data 需为 Buffer (客户端简单处理了string 转 Buffer), 支持设置 encoding
  699. // data 需为 Buffer (客户端简单处理了string 转 Buffer), 支持设置 encoding
  700. // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
  701. // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
  702. // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
  703. // 其他 Uint8Array/ArrayBuffer 默认仅 使用 Buffer.from(data)
  704. data: 'test test test test test test test',
  705. encoding: 'utf-8' // 默认可不传
  706. }
  707. }, (res) => {
  708. // 执行的ipp 任务回调 / 错误回调
  709. console.log(res)
  710. }, (printer) => {
  711. // ipp连接成功 回调 打印机信息
  712. console.log(printer)
  713. })
  714. },
  715. // 自定义 ipp 请求
  716. ippRequestTest() {
  717. const printerList = hiprintTemplate.getPrinterList();
  718. console.log(printerList)
  719. if (!printerList.length) return;
  720. let p = printerList[0];
  721. console.log(p)
  722. // 系统不同, 参数可能不同
  723. let url = p.options['printer-uri-supported'];
  724. // 详见: https://www.npmjs.com/package/ipp
  725. hiprint.ippRequest({
  726. url: url,
  727. // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
  728. // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
  729. // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
  730. data: {
  731. "operation": "Get-Printer-Attributes",
  732. "operation-attributes-tag": {
  733. // 测试发现 Request下列3个必须要有
  734. "attributes-charset": "utf-8",
  735. "attributes-natural-language": "zh-cn",
  736. "printer-uri": url
  737. }
  738. }
  739. }, (res) => {
  740. // 执行的ipp 任务回调 / 错误回调
  741. console.log(res)
  742. })
  743. },
  744. ippRequestPrint() {
  745. const printerList = hiprintTemplate.getPrinterList();
  746. console.log(printerList)
  747. if (!printerList.length) return;
  748. let p = printerList[0];
  749. console.log(p)
  750. // 系统不同, 参数可能不同
  751. let url = p.options['printer-uri-supported'];
  752. let str = "ippRequestPrint ippRequestPrint ippRequestPrint";
  753. let array = new Uint8Array(str.length);
  754. for (var i = 0; i < str.length; i++) {
  755. array[i] = str.charCodeAt(i);
  756. }
  757. let testData = array.buffer;
  758. // 详见: https://www.npmjs.com/package/ipp
  759. hiprint.ippRequest({
  760. url: url,
  761. // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
  762. // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
  763. // 传入的数据 ipp.serialize 后 未做任何处理 打印内容 需要 Buffer
  764. data: {
  765. "operation": "Print-Job",
  766. "operation-attributes-tag": {
  767. // 测试发现 Request下列3个必须要有
  768. "attributes-charset": "utf-8",
  769. "attributes-natural-language": "zh-cn",
  770. "printer-uri": url,
  771. "requesting-user-name": "hiPrint", // 用户名
  772. "job-name": "ipp Request Job", // 任务名
  773. "document-format": "text/plain" // 文档类型
  774. },
  775. data: testData
  776. }
  777. }, (res) => {
  778. // 执行的ipp 任务回调 / 错误回调
  779. console.log(res)
  780. })
  781. },
  782. updateJson() {
  783. if (hiprintTemplate) {
  784. try {
  785. hiprintTemplate.update(JSON.parse(this.jsonIn))
  786. } catch (e) {
  787. this.$message.error(`更新失败: ${e}`)
  788. }
  789. }
  790. },
  791. exportJson() {
  792. if (hiprintTemplate) {
  793. this.jsonOut = JSON.stringify(hiprintTemplate.getJson() || {})
  794. setTimeout(() => {
  795. this.$refs['bind'].saveJson()
  796. }, 500);
  797. }
  798. },
  799. setElsAlign(e) {
  800. hiprintTemplate.setElsAlign(e)
  801. },
  802. setElsSpace(h) {
  803. hiprintTemplate.setElsSpace(10, h)
  804. },
  805. getSelectEls() {
  806. let els = hiprintTemplate.getSelectEls();
  807. console.log(els)
  808. },
  809. updateFontSize() {
  810. hiprintTemplate.updateOption('fontSize', 12);
  811. },
  812. updateFontWeight() {
  813. hiprintTemplate.updateOption('fontWeight', 'bolder');
  814. },
  815. test () {
  816. var hiprintTemplate = new hiprint.PrintTemplate();
  817. var panel = hiprintTemplate.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 });
  818. panel.addPrintTable({ options: { width: 252, height: 35, top: 130, left: 20, content: $('#testTable').html() } });
  819. }
  820. }
  821. }
  822. </script>
  823. <style scoped>
  824. .drag_item_box {
  825. height: 100%;
  826. padding: 6px;
  827. }
  828. .drag_item_box > div {
  829. height: 100%;
  830. width: 100%;
  831. background-color: #fff;
  832. display: flex;
  833. justify-content: center;
  834. align-items: center;
  835. }
  836. .drag_item_box > div > a {
  837. text-align: center;
  838. text-decoration-line: none;
  839. }
  840. .drag_item_box > div > a > span {
  841. font-size: 28px;
  842. }
  843. .drag_item_box > div > a > p {
  844. margin: 0;
  845. }
  846. .drag_item_title {
  847. font-size: 16px;
  848. padding: 12px 6px 0 6px;
  849. font-weight: bold;
  850. }
  851. <<<<<<< HEAD
  852. /* /deep/ .hiprint-printElement-image-content {
  853. img {
  854. // content: url("~@/assets/logo.png");
  855. }
  856. } */
  857. =======
  858. >>>>>>> xiaoqin
  859. /deep/ .toplineOfPosition {
  860. border: 0;
  861. border-top: 1px dashed purple;
  862. }
  863. /deep/ .bottomlineOfPosition {
  864. border: 0;
  865. border-top: 1px dashed purple;
  866. }
  867. /deep/ .leftlineOfPosition {
  868. border: 0;
  869. border-left: 1px dashed purple;
  870. }
  871. /deep/ .rightlineOfPosition {
  872. border: 0;
  873. border-left: 1px dashed purple;
  874. }
  875. .card-design {
  876. overflow: hidden;
  877. overflow-x: auto;
  878. overflow-y: auto;
  879. }
  880. </style>