first commit
This commit is contained in:
1
衣莎项目/源码/gc_nwjs/src/utils/.pydio
Normal file
1
衣莎项目/源码/gc_nwjs/src/utils/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
0feac996-cd60-4ced-a233-680f85e85da3
|
||||
27
衣莎项目/源码/gc_nwjs/src/utils/nw.js
Normal file
27
衣莎项目/源码/gc_nwjs/src/utils/nw.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/* eslint-disable */
|
||||
let win = nw.Window.get() || '';
|
||||
|
||||
export default {
|
||||
big() {
|
||||
win.toggleFullscreen();
|
||||
},
|
||||
/**
|
||||
* 打开新窗口跳转
|
||||
* @param {*} url
|
||||
* @param {*} option
|
||||
* @param {*} callback
|
||||
*/
|
||||
openWin(url, option, callback) {
|
||||
let baseUrl = window.location
|
||||
nw.Window.open(`${baseUrl.origin}${baseUrl.pathname}#${url}`, { fullscreen: true, frame: true }, () => {
|
||||
// And listen to new window's focus event
|
||||
// callback(win)
|
||||
// win.on('focus', () => {
|
||||
// win.toggleFullscreen();
|
||||
// });
|
||||
});
|
||||
},
|
||||
close() {
|
||||
win.close();
|
||||
}
|
||||
}
|
||||
101
衣莎项目/源码/gc_nwjs/src/utils/printing.js
Normal file
101
衣莎项目/源码/gc_nwjs/src/utils/printing.js
Normal file
@@ -0,0 +1,101 @@
|
||||
var ws;
|
||||
var wsUrl = 'ws://localhost:2012';//打印后台地址与
|
||||
var isWx = true;
|
||||
function connection() {
|
||||
if ('WebSocket' in window) {
|
||||
ws = new WebSocket(wsUrl);
|
||||
}
|
||||
else if ('MozWebSocket' in window) {
|
||||
ws = new MozWebSocket(wsUrl);
|
||||
} else {
|
||||
alert('当前浏览器不支持');
|
||||
|
||||
}
|
||||
|
||||
//注册各类回调
|
||||
ws.onopen = function () {
|
||||
// alert('连接打印后台成功');
|
||||
isWx = true
|
||||
}
|
||||
|
||||
ws.onclose = function () {
|
||||
// alert('与打印后台断开连接');
|
||||
isWx = false
|
||||
}
|
||||
ws.onerror = function () {
|
||||
alert('数据传输发生错误');
|
||||
isWx = false
|
||||
}
|
||||
ws.onmessage = function (receiveMsg) {
|
||||
if (receiveMsg.data.split("|")[0] == "A_GetPrinterStatus") {
|
||||
|
||||
var ret = receiveMsg.data.split("|")[1];
|
||||
if (ret == 0) {
|
||||
document.getElementById("status").value = "无返回值";
|
||||
return;
|
||||
}
|
||||
else if (ret == 1) {
|
||||
document.getElementById("status").value = "打印机命令解析器忙碌中!";
|
||||
return;
|
||||
}
|
||||
else if (ret == 2) {
|
||||
document.getElementById("status").value = "2 纸张用完或安装错误!"; //纸张用完或安装错误!
|
||||
return;
|
||||
}
|
||||
else if (ret == 4) {
|
||||
document.getElementById("status").value = "4 碳带用完或安装错误!"; //碳带用完或安装错误!";
|
||||
return;
|
||||
}
|
||||
else if (ret == 8) {
|
||||
document.getElementById("status").value = "8 打印批次文档中!"; //打印批次文档中!";
|
||||
return;
|
||||
}
|
||||
else if (ret == 16) {
|
||||
document.getElementById("status").value = "16 正在打印文件!"; //正在打印文件!
|
||||
return;
|
||||
}
|
||||
else if (ret == 32) {
|
||||
document.getElementById("status").value = "32 打印机暂停!"; //打印机暂停!
|
||||
return;
|
||||
}
|
||||
else if (ret == 64) {
|
||||
document.getElementById("status").value = "64 正在送出标签纸!"; //正在送出标签纸!
|
||||
return;
|
||||
}
|
||||
else if (ret == 9) {
|
||||
document.getElementById("status").value = "9 打印机待机中!"; //打印机待机中!
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
function sendMessage(data) {
|
||||
//尝试向打印后台发送消息
|
||||
if (!isWx) return;
|
||||
ws.send('A_EnumUSB');
|
||||
ws.send('A_CreateUSBPort|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|0|35|宋体|1|600|0|0|0|AA|' + data.code_num + '|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|20|34|宋体|1|900|0|800|0|BB|' + data.shopName + '|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|40|28|宋体|1|600|0|0|0|DD|' + data.username + '|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|60|24|宋体|1|600|0|0|0|HH|' + data.appendix + '|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|80|28|宋体|1|600|0|0|0|CC|' + data.color + ' ' + '共' + data.total_count + '件|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|100|28|宋体|1|600|0|0|0|EE|' + data.name + '|1');
|
||||
ws.send('A_Prn_Text_TrueType|5|120|24|宋体|1|600|0|0|0|FF|' + data.shop_order_no + '|1');
|
||||
|
||||
ws.send('A_Prn_Barcode|110|134|2|o|2|3|60|B|1|' + data.code_num + '');
|
||||
ws.send('A_Prn_Text_TrueType|170|30|32|宋体|4|600|0|0|0|GG|' + data.telnum + '|1');
|
||||
ws.send('A_Print_Out|1|1|1|1');
|
||||
ws.send('A_ClosePrn');
|
||||
}
|
||||
|
||||
// function getStatus() {
|
||||
// ws.send('A_EnumUSB');
|
||||
// ws.send('A_CreateUSBPort|1');
|
||||
// ws.send('A_GetPrinterStatus');
|
||||
// ws.send('A_ClosePrn');
|
||||
// }
|
||||
export default {
|
||||
sendMessage: sendMessage,
|
||||
connection: connection
|
||||
}
|
||||
144
衣莎项目/源码/gc_nwjs/src/utils/utils.js
Normal file
144
衣莎项目/源码/gc_nwjs/src/utils/utils.js
Normal file
@@ -0,0 +1,144 @@
|
||||
import config from '@/config/index';
|
||||
|
||||
export default {
|
||||
/**
|
||||
* 使用百度api,把文字转换成语音并播放
|
||||
* @param {string} str 需要转换成语音的字符串
|
||||
*/
|
||||
voiceText(str) {
|
||||
var url = "http://tsn.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + encodeURI(str);
|
||||
var audio = new Audio(url);
|
||||
audio.src = url;
|
||||
audio.play();
|
||||
},
|
||||
/**
|
||||
* 获取扫码枪扫码的内容
|
||||
* @param {Function} cell 回调函数返回扫码结果
|
||||
*/
|
||||
sweepCode(cell) {
|
||||
window.onload = function () {
|
||||
var code = "";
|
||||
var lastTime, nextTime;
|
||||
var lastCode, nextCode;
|
||||
document.onkeypress = function (e) {
|
||||
nextCode = e.which;
|
||||
nextTime = new Date().getTime();
|
||||
if (lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
|
||||
code += String.fromCharCode(lastCode);
|
||||
} else if (lastCode != null && lastTime != null && nextTime - lastTime > 100) {
|
||||
code = "";
|
||||
}
|
||||
lastCode = nextCode;
|
||||
lastTime = nextTime;
|
||||
}
|
||||
this.onkeypress = function (e) {
|
||||
if (e.which == 13) {
|
||||
cell(code)
|
||||
code = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 判断是字符且存在
|
||||
* @param {*} str
|
||||
*/
|
||||
isString(str) {
|
||||
if (Object.prototype.toString.call(str) !== '[object String]' && str.length <= 0) return true;
|
||||
return false
|
||||
},
|
||||
/**
|
||||
* 获取本地缓存
|
||||
* @param {string} key 需要获取缓存中的名字
|
||||
*/
|
||||
getStorage(key) {
|
||||
if (this.isString(key)) return;
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem(`${config.prefix}${key}`));
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 存储本地缓存
|
||||
* @param {string} key 需要缓存的名字
|
||||
* @param {any} value 需要set的值
|
||||
*/
|
||||
setStorage(key, value) {
|
||||
if (this.isString(key)) return;
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
return 'ok'
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 获取本地缓存
|
||||
* @param {string} key 需要获取缓存中的名字
|
||||
*/
|
||||
getSession(key) {
|
||||
if (this.isString(key)) return;
|
||||
console.log(key);
|
||||
try {
|
||||
return JSON.parse(sessionStorage.getItem(`${config.prefix}${key}`));
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 存储本地缓存
|
||||
* @param {string} key 需要缓存的名字
|
||||
* @param {any} value 需要set的值
|
||||
*/
|
||||
setSession(key, value) {
|
||||
if (this.isString(key)) return;
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value))
|
||||
return 'ok'
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 删除指定key
|
||||
* @param {string} key
|
||||
*/
|
||||
removeItemSession(key) {
|
||||
if (this.isString(key)) return;
|
||||
try {
|
||||
sessionStorage.removeItem(`${config.prefix}${key}`)
|
||||
return 'ok'
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
// 格式化日期,如月、日、时、分、秒保证为2位数
|
||||
formatNumber(n) {
|
||||
n = n.toString()
|
||||
return n[1] ? n : '0' + n;
|
||||
},
|
||||
/**
|
||||
* 用法formatTime(1545903266795, 'Y-M-D h:m:s')
|
||||
* @param {number} number 毫秒时间戳
|
||||
* @param {string} format 日期格式
|
||||
*/
|
||||
formatTime(number, format) {
|
||||
if (typeof number !== 'number') {
|
||||
number = parseInt(number)
|
||||
}
|
||||
let time = new Date(number)
|
||||
let newArr = []
|
||||
let formatArr = ['Y', 'M', 'D', 'h', 'm', 's']
|
||||
newArr.push(time.getFullYear())
|
||||
newArr.push(this.formatNumber(time.getMonth() + 1))
|
||||
newArr.push(this.formatNumber(time.getDate()))
|
||||
newArr.push(this.formatNumber(time.getHours()))
|
||||
newArr.push(this.formatNumber(time.getMinutes()))
|
||||
newArr.push(this.formatNumber(time.getSeconds()))
|
||||
for (let i in newArr) {
|
||||
format = format.replace(formatArr[i], newArr[i])
|
||||
}
|
||||
return format;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user