Commit 7cc15289 authored by 张海景's avatar 张海景

update:修改pdf打印方法

parent 1e7d8f9b
...@@ -15,6 +15,10 @@ const install = (Vue, vm) => { ...@@ -15,6 +15,10 @@ const install = (Vue, vm) => {
vm.$u.get(config.adminPath + '/mobile/index', params), vm.$u.get(config.adminPath + '/mobile/index', params),
getUserInfo: (params = {}) => getUserInfo: (params = {}) =>
vm.$u.get(config.adminPath + '/mobile/user/getUserInfo', params), vm.$u.get(config.adminPath + '/mobile/user/getUserInfo', params),
getUserPrintInfo: () =>
vm.$u.get(config.adminPath + '/system/print/printer'),
getPrintDown: (params) =>
vm.$u.postJson(config.adminPath + '/common/printDown', params),
login: (params = {}) => login: (params = {}) =>
vm.$u.post(config.adminPath + '/mobile/login/loginByPassword', params), vm.$u.post(config.adminPath + '/mobile/login/loginByPassword', params),
sendCode: (params = {}) => sendCode: (params = {}) =>
...@@ -108,7 +112,7 @@ const install = (Vue, vm) => { ...@@ -108,7 +112,7 @@ const install = (Vue, vm) => {
vm.$u.postJson(config.adminPath + '/mes/qc/ipqc', params), vm.$u.postJson(config.adminPath + '/mes/qc/ipqc', params),
//切换检验单状态 //切换检验单状态
changeState: (params = {}) => changeState: (params = {}) =>
vm.$u.postJson(config.adminPath + '/mes/qc/ipqc/changeState', params), vm.$u.postJson(config.adminPath + '/mes/qc/ipqc/changeState', params),
//根据字典类型查询字典数据信息 //根据字典类型查询字典数据信息
getDicts: (params = {}) => getDicts: (params = {}) =>
vm.$u.get(config.adminPath + '/system/dict/data/type/' + params), vm.$u.get(config.adminPath + '/system/dict/data/type/' + params),
...@@ -151,8 +155,6 @@ const install = (Vue, vm) => { ...@@ -151,8 +155,6 @@ const install = (Vue, vm) => {
config.adminPath + '/mobile/pro/taskissue/getReserveIssueList', config.adminPath + '/mobile/pro/taskissue/getReserveIssueList',
params params
), ),
//人员绑定打印机 //人员绑定打印机
getUserPrint:(params = {}) => getUserPrint:(params = {}) =>
vm.$u.get(config.adminPath + '/system/printerConfig/userList', params), vm.$u.get(config.adminPath + '/system/printerConfig/userList', params),
......
This diff is collapsed.
...@@ -83,6 +83,13 @@ ...@@ -83,6 +83,13 @@
this.$u.toast(res.msg); this.$u.toast(res.msg);
} }
if (res.code == '200') { if (res.code == '200') {
this.$u.api.getUserPrintInfo().then(res=> {
// console.log(res, 'res888')
if (res.code === 200) {
this.$u.vuex('vuex_printerHostUrl', 'http://'+ res.data.printerIp +':'+ res.data.printerPort);
this.$u.vuex('vuex_printerName', res.data.printerName);
}
})
setTimeout(() => { setTimeout(() => {
uni.reLaunch({ uni.reLaunch({
url: '/pages/index/index' url: '/pages/index/index'
......
<template> <template>
<view> <view>
<u-button @click="exportPDF">预览pdf</u-button> <u-button @click="exportPDF">预览pdf</u-button>
<u-button @click="handlePrint">打印pdf</u-button> <u-button @click="printPdfSocket">打印pdf</u-button>
</view> </view>
</template> </template>
<script> <script>
import io from '@hyoga/uni-socket.io';
// import { SOCKET_IO_CLIENT, OPTIONS } from '@/uni_modules/bunny-socket-io-client';
import uButton from '../../uview-ui/components/u-button/u-button.vue'; import uButton from '../../uview-ui/components/u-button/u-button.vue';
export default { export default {
components: { uButton }, components: { uButton },
data() { data() {
return { return {
socket: {},
url: 'http://192.168.3.91:8082/static/123.pdf' url: 'http://192.168.3.91:8082/static/123.pdf'
}; };
}, },
created() {
this.socket = io('http://192.168.21.104:17521', {
transports: ['websocket'],
auth: {
token: 'Bearer ' + this.vuex_token // 在此处填入你 client 设置的 token,缺省可留空
}
});
this.socket.on('connect', () => {
globalThis.connect = true;
console.log('连接成功444');
// TODO: Do something for your project
});
this.socket.on('clients', (clients) => {
globalThis.clients = clients;
console.log(clients, 'clients');
});
this.socket.on('printerList', (printerList) => {
globalThis.printerList = printerList;
console.log(printerList, 'printerList');
});
},
methods: { methods: {
handlePrint() { handlePrint() {
console.log(this.socket, 'this.$socket'); console.log(this.socket, 'this.$socket');
......
import { mapState } from 'vuex' import { mapState } from 'vuex'
import store from "@/store" import store from "@/store"
import io from '@hyoga/uni-socket.io';
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中 // 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
let $uStoreKey = []; let $uStoreKey = [];
...@@ -20,8 +21,64 @@ module.exports = { ...@@ -20,8 +21,64 @@ module.exports = {
}) })
} }
}, },
data() {
return {
pdfSocket: null
}
},
computed: { computed: {
// 将vuex的state中的所有变量,解构到全局混入的mixin中 // 将vuex的state中的所有变量,解构到全局混入的mixin中
...mapState($uStoreKey) ...mapState($uStoreKey)
},
methods: {
createSocket() {
this.pdfSocket = io(this.vuex_printerHostUrl, {
transports: ['websocket'],
auth: {
token: 'Bearer ' + this.vuex_token, // 在此处填入你 client 设置的 token,缺省可留空
},
});
this.pdfSocket.on('connect', () => {
globalThis.connect = true;
console.log('连接成功444');
// TODO: Do something for your project
});
this.pdfSocket.on('clients', (clients) => {
globalThis.clients = clients;
console.log(clients, 'clients');
});
this.pdfSocket.on('printerList', (printerList) => {
globalThis.printerList = printerList;
console.log(printerList, 'printerList');
});
},
printPdfSocket() {
console.log(this.pdfSocket, 'pdfSocket')
if (!this.pdfSocket) {
this.createSocket()
}
this.$u.api
.getPrintDown({
reportName: 'mysql:qrcode-100*100',
values: {
detail: [
{
qrcode: 'qqq',
},
],
},
})
.then((res) => {
if (res.code === 200) {
this.pdfSocket.emit('news', {
client: null,
printer: this.vuex_printerName,
type: 'url_pdf',
// pdf_path: 'http://192.168.3.91:8082/static/123.pdf',
pdf_path: res.fileUrl,
});
}
});
}
} }
} }
\ No newline at end of file
...@@ -8,92 +8,100 @@ Vue.use(Vuex) ...@@ -8,92 +8,100 @@ Vue.use(Vuex)
let lifeData = {}; let lifeData = {};
try{ try {
// 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的 // 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的
lifeData = uni.getStorageSync('lifeData'); lifeData = uni.getStorageSync('lifeData');
}catch(e){ } catch (e) {
} }
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名 // 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = ['vuex_user', 'vuex_token', 'vuex_remember', 'vuex_locale','vuex_isAgent','vuex_workstation','vuex_task']; let saveStateKeys = ['vuex_user', 'vuex_token', 'vuex_remember', 'vuex_locale', 'vuex_isAgent', 'vuex_workstation',
'vuex_task', 'vuex_printerHostUrl', 'vuex_printerName'
];
// 保存变量到本地存储中 // 保存变量到本地存储中
const saveLifeData = function(key, value){ const saveLifeData = function(key, value) {
// 判断变量名是否在需要存储的数组中 // 判断变量名是否在需要存储的数组中
if(saveStateKeys.indexOf(key) != -1) { if (saveStateKeys.indexOf(key) != -1) {
// 获取本地存储的lifeData对象,将变量添加到对象中 // 获取本地存储的lifeData对象,将变量添加到对象中
let tmp = uni.getStorageSync('lifeData'); let tmp = uni.getStorageSync('lifeData');
// 第一次打开APP,不存在lifeData变量,故放一个{}空对象 // 第一次打开APP,不存在lifeData变量,故放一个{}空对象
tmp = tmp ? tmp : {}; tmp = tmp ? tmp : {};
tmp[key] = value; tmp[key] = value;
// 执行这一步后,所有需要存储的变量,都挂载在本地的lifeData对象中 // 执行这一步后,所有需要存储的变量,都挂载在本地的lifeData对象中
uni.setStorageSync('lifeData', tmp); uni.setStorageSync('lifeData', tmp);
} }
} }
// 简化 vuex 操作,文档:https://uviewui.com/components/vuexDetail.html // 简化 vuex 操作,文档:https://uviewui.com/components/vuexDetail.html
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量 // 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
// 加上vuex_前缀,是防止变量名冲突,也让人一目了然 // 加上vuex_前缀,是防止变量名冲突,也让人一目了然
vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {userName: 'Aidex'}, vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {
vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '', userName: 'Aidex'
vuex_remember: lifeData.vuex_remember ? lifeData.vuex_remember : '', },
vuex_locale: lifeData.vuex_locale ? lifeData.vuex_locale : '', vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
vuex_isAgent: lifeData.vuex_isAgent ? lifeData.vuex_isAgent : '', vuex_remember: lifeData.vuex_remember ? lifeData.vuex_remember : '',
vuex_locale: lifeData.vuex_locale ? lifeData.vuex_locale : '',
vuex_isAgent: lifeData.vuex_isAgent ? lifeData.vuex_isAgent : '',
// 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式 // 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式
vuex_config: config, vuex_config: config,
//当前设备绑定的工作站 //当前设备绑定的工作站
vuex_workstation: null, vuex_workstation: null,
vuex_workunit: null, vuex_workunit: null,
//当前工作站正在进行的生产任务 //当前工作站正在进行的生产任务
vuex_task: null, vuex_task: null,
// 打印机服务器地址
vuex_printerHostUrl: lifeData.vuex_printerHostUrl ? lifeData.vuex_printerHostUrl : '',
// 打印机名称s
vuex_printerName: lifeData.vuex_printerName ? lifeData.vuex_printerName : '',
// 自定义tabbar数据 // 自定义tabbar数据
// vuex_tabbar: [{ // vuex_tabbar: [{
// iconPath: "/static/uview/example/component.png", // iconPath: "/static/uview/example/component.png",
// selectedIconPath: "/static/uview/example/component_select.png", // selectedIconPath: "/static/uview/example/component_select.png",
// text: '组件', // text: '组件',
// pagePath: '/pages/example/components' // pagePath: '/pages/example/components'
// }, // },
// { // {
// iconPath: "/static/uview/example/js.png", // iconPath: "/static/uview/example/js.png",
// selectedIconPath: "/static/uview/example/js_select.png", // selectedIconPath: "/static/uview/example/js_select.png",
// text: '工具', // text: '工具',
// midButton: true, // midButton: true,
// pagePath: '/pages/example/js' // pagePath: '/pages/example/js'
// }, // },
// { // {
// iconPath: "/static/uview/example/template.png", // iconPath: "/static/uview/example/template.png",
// selectedIconPath: "/static/uview/example/template_select.png", // selectedIconPath: "/static/uview/example/template_select.png",
// text: '模板', // text: '模板',
// pagePath: '/pages/example/template' // pagePath: '/pages/example/template'
// } // }
// ] // ]
}, },
mutations: { mutations: {
$uStore(state, payload) { $uStore(state, payload) {
// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1 // 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
let nameArr = payload.name.split('.'); let nameArr = payload.name.split('.');
let saveKey = ''; let saveKey = '';
let len = nameArr.length; let len = nameArr.length;
if(len >= 2) { if (len >= 2) {
let obj = state[nameArr[0]]; let obj = state[nameArr[0]];
for(let i = 1; i < len - 1; i ++) { for (let i = 1; i < len - 1; i++) {
obj = obj[nameArr[i]]; obj = obj[nameArr[i]];
} }
obj[nameArr[len - 1]] = payload.value; obj[nameArr[len - 1]] = payload.value;
saveKey = nameArr[0]; saveKey = nameArr[0];
} else { } else {
// 单层级变量,在state就是一个普通变量的情况 // 单层级变量,在state就是一个普通变量的情况
state[payload.name] = payload.value; state[payload.name] = payload.value;
saveKey = payload.name; saveKey = payload.name;
} }
// 保存变量到本地,见顶部函数定义 // 保存变量到本地,见顶部函数定义
saveLifeData(saveKey, state[saveKey]) saveLifeData(saveKey, state[saveKey])
} }
} }
}) })
export default store export default store
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment