import { Notification } from 'element-ui' var plugin = null // 放在外面,解决销毁不掉的问题 export default { state: { // 返回的图片地址 doctorSignImg: '', // 主刀医生图片 index: 0, // 控制usb弹框提示执行次数 plugin: null, type: 1, // 1 验光师 2 医生 3 配戴者 4 监护人 // 签名按钮是否显示 // optomFlag: true, // wearerFlag: true, // guardianFlag: true, // readFlag: true, // lensFlag: true, // wearerOrGuardianFlag: true, // 返回的图片地址 optomSign: '', doctorSign: '', patientSign: '', guardianSign: '', optomSign2: '', doctorSign2: '', patientSign2: '', guardianSign2: '', operator: '', informedDocSign: '', informPatientSign: '', checkSign: '', fundusDocSign: '', kinSign: '', performerSign: '', checkerSign: '', conPatientSign: '', conKinSign: '', minorPatientSign: '', minorKinSign: '', minorPatientSignM: '', minorKinSignM: '', cornealPatientSign: '', cornealKinSign: '', puncturePatientSign: '', punctureKinSign: '', childrenSign: '' }, getters: { doctorSignImg: state => state.doctorSignImg, optomSign: state => state.optomSign, doctorSign: state => state.doctorSign, patientSign: state => state.patientSign, guardianSign: state => state.guardianSign, optomSign2: state => state.optomSign2, doctorSign2: state => state.doctorSign2, patientSign2: state => state.patientSign2, guardianSign2: state => state.guardianSign2, operator: state => state.operator, informedDocSign: state => state.informedDocSign, informPatientSign: state => state.informPatientSign, checkSign: state => state.checkSign, fundusDocSign: state => state.fundusDocSign, kinSign: state => state.kinSign, performerSign: state => state.performerSign, checkerSign: state => state.checkerSign, minorPatientSign: state => state.minorPatientSign, minorKinSign: state => state.minorKinSign, minorPatientSignM: state => state.minorPatientSignM, minorKinSignM: state => state.minorKinSignM, conPatientSign: state => state.conPatientSign, conKinSign: state => state.conKinSign, cornealPatientSign: state => state.cornealPatientSign, cornealKinSign: state => state.cornealKinSign, puncturePatientSign: state => state.puncturePatientSign, punctureKinSign: state => state.punctureKinSign, childrenSign: state => state.childrenSign }, mutations: { // 销毁签字笔 destroyPlugin(state) { if (plugin) { plugin.DestroyPlugin() } }, initPlugin(state) { state.index++ // console.log(state.index) if (plugin) { console.log('--------3333-------') plugin.DestroyPlugin() } plugin = new PluginNSV() plugin.InitPlugin((item) => { if (item === 1) { // set pen size plugin.setPenSizeRange(1, 5, null) // set pen color plugin.setPenColor(0, 0, 0, null) plugin.setDisplayMapMode(1, 0, 0, null) this.commit('checkDevice') console.log('succeeded') } else { console.log('fails') } }) /* confirm event*/ plugin.onConfirm = () => { this.commit('saveSignToBase64') this.commit('endSign') plugin.mouseControl(false, null) } // /*clear event*/ plugin.onClear = () => { this.commit('clearSign') } /* cancel event*/ plugin.onCancel = () => { this.commit('endSign') } // 监听插件连接服务的状态 plugin.onStateChange = (item) => {} // if (state.index === 1) { // 设备是否连接--use是否插上 plugin.onDevNotifyEvent = (item) => { if (item === 1) { Notification.success({ title: '成功', message: '签字笔已插入', showClose: false, duration: 800 }) } else { Notification.error({ title: '提示', message: '签字笔已拔出', showClose: false, duration: 800 }) } } }, checkDevice(state) { if (plugin) { plugin.isConnected((item, args) => { if (item) { var ret = parseInt(args[0]) if (ret === 1) { Notification.success({ title: 'Info', message: '设备已连接', showClose: false }) } else { Notification.success({ title: 'Info', message: '设备未连接', showClose: false }) } } else { alert('isConnected error,description:' + args[0]) } }) } }, beginSign(state, index) { state.type = index if (plugin) { plugin.beginSign((item, args) => {}) } // document.getElementById('img_sign_result').src = ''; }, clearSign(state, val) { if (plugin) { plugin.clearSign((item, args) => {}) } // Reset the image. state.doctorSignImg = '' }, endSign(state) { if (plugin) { /* plugin.endSign(null);*/ plugin.endSign((item, args) => {}) } }, saveSignToBase64(state) { if (plugin) { // Get the plugin's signature image data. plugin.saveSignToBase64(/* 615, 272*/0, 0, (item, args) => { if (item) { // console.log(args) const img_base64_data = args[0] // console.log(img_base64_data) const img_base64 = 'data:image/png;base64,' + img_base64_data // state.doctorSignImg = img_base64 if (state.type === 1) { this.commit('optomSign', img_base64) } else if (state.type === 2) { this.commit('doctorSign', img_base64) } else if (state.type === 3) { this.commit('patientSign', img_base64) } else if (state.type === 4) { this.commit('guardianSign', img_base64) } else if (state.type === 5) { this.commit('optomSign2', img_base64) } else if (state.type === 6) { this.commit('doctorSign2', img_base64) } else if (state.type === 7) { this.commit('patientSign2', img_base64) } else if (state.type === 8) { this.commit('guardianSign2', img_base64) } else if (state.type === 9) { this.commit('operator', img_base64) } else if (state.type === 10) { this.commit('informedDocSign', img_base64) } else if (state.type === 11) { this.commit('informPatientSign', img_base64) } else if (state.type === 12) { this.commit('fundusDocSign', img_base64) } else if (state.type === 13) { this.commit('kinSign', img_base64) } else if (state.type === 14) { this.commit('performerSign', img_base64) } else if (state.type === 15) { this.commit('checkerSign', img_base64) } else if (state.type === 16) { this.commit('checkSign', img_base64) } else if (state.type === 17) { this.commit('minorPatientSign', img_base64) } else if (state.type === 18) { this.commit('minorKinSign', img_base64) } else if (state.type === 19) { this.commit('conPatientSign', img_base64) } else if (state.type === 20) { this.commit('conKinSign', img_base64) } else if (state.type === 'M') { this.commit('minorPatientSignM', img_base64) } else if (state.type === 'MM') { this.commit('minorKinSignM', img_base64) } else if (state.type === 21) { this.commit('cornealPatientSign', img_base64) } else if (state.type === 22) { this.commit('cornealKinSign', img_base64) } else if (state.type === 23) { this.commit('puncturePatientSign', img_base64) } else if (state.type === 24) { this.commit('punctureKinSign', img_base64) } else if (state.type === 25) { this.commit('childrenSign', img_base64) } } else { // debugPrint("saveSignToBase64 error,description:" + args[0]); } }) } }, doctorSignImg(state, val) { state.doctorSignImg = val }, optomSign(state, val) { state.optomSign = val }, doctorSign(state, val) { state.doctorSign = val }, patientSign(state, val) { state.patientSign = val }, guardianSign(state, val) { state.guardianSign = val }, optomSign2(state, val) { state.optomSign2 = val }, doctorSign2(state, val) { state.doctorSign2 = val }, patientSign2(state, val) { state.patientSign2 = val }, guardianSign2(state, val) { state.guardianSign2 = val }, operator(state, val) { state.operator = val }, informedDocSign(state, val) { state.informedDocSign = val }, informPatientSign(state, val) { state.informPatientSign = val }, checkSign(state, val) { state.checkSign = val }, fundusDocSign(state, val) { state.fundusDocSign = val }, kinSign(state, val) { state.kinSign = val }, performerSign(state, val) { state.performerSign = val }, checkerSign(state, val) { state.checkerSign = val }, minorPatientSign(state, val) { state.minorPatientSign = val }, minorKinSign(state, val) { state.minorKinSign = val }, minorPatientSignM(state, val) { state.minorPatientSignM = val }, minorKinSignM(state, val) { state.minorKinSignM = val }, conPatientSign(state, val) { state.conPatientSign = val }, conKinSign(state, val) { state.conKinSign = val }, cornealPatientSign(state, val) { state.cornealPatientSign = val }, cornealKinSign(state, val) { state.cornealKinSign = val }, puncturePatientSign(state, val) { state.puncturePatientSign = val }, punctureKinSign(state, val) { state.punctureKinSign = val }, childrenSign(state, val) { state.childrenSign = val } } }