123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- import msg from './message.js'
- import http from './http.js'
- import store from '../../store/index.js'
- import storage from './storage.js'
- import DateFormat from '../../js_sdk/xfl-DateFormat/DateFormat.js'
- export default {
-
- back(pageNum = 1) {
- uni.navigateBack({delta: pageNum})
- storage.setStorage('outTime', new Date().getTime())
- },
-
- open(url) {
- uni.navigateTo({
- url: url
- });
- storage.setStorage('outTime', new Date().getTime())
- },
-
- openNew(url) {
- uni.redirectTo({
- url: url
- });
- storage.setStorage('outTime', new Date().getTime())
- },
-
- openReLaunch(url) {
- uni.reLaunch({
- url: url
- });
- storage.setStorage('outTime', new Date().getTime())
- },
-
- async openMsg() {
-
-
-
-
-
-
-
-
-
-
-
-
- const msgRead = (id) => {
- store.commit('msg/REMOVE_ALERT_ID', id)
- http.msgRead({ id }).then(res => {
- console.log(res.msg, '消息已读utils');
- })
- }
- let alertList = []
- let roleKey = storage.getStorageSync('userInfo').roleKey
- await http.getStatus().then(response => {
- console.log('-----获取消息-----');
- console.log(response)
- let res = response.result
- alertList = res.alertList
- alertList.reverse()
- })
-
- for (let i in alertList) {
- let alert = alertList[i]
-
- if(store.getters.alertList.indexOf(alert.id) != -1) {
- console.log('-----------消息已存在-----------',alert.id);
- console.log(store.getters.alertList);
- continue;
- }else {
- store.commit('msg/SAVE_ALERT_ID', alert.id)
-
- try {
- if(alert.data && ((typeof alert.data) == 'string')) {
- alert.data = JSON.parse(alert.data)
- }
- }
- catch(err){
- msg.showToast({title: '消息格式错误!'})
- }
- if(alert.code == 0 || alert.code == 1) {
- console.log('弹出新订单----');
-
- if(['directInkPrinter', 'paperPrinter', 'heatPrinter', 'autoCut'].includes(roleKey)) {
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve()
- }, 1000)
- }).then(res => {
- this.open(`/pages/popup/popup?info=${ JSON.stringify(alert) }`)
- })
- }
- }
-
- else if(alert.code == 4 || alert.code == 15) {
-
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve()
- }, 1000)
- }).then(res => {
- this.open(`/pages/popup/popup?info=${ JSON.stringify(alert) }`)
- })
- }
-
- else if(alert.code == 6 || alert.code == 13) {
- console.log('放置成功 拿取成功 提示消息--------------');
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve()
- }, 1000)
- }).then(res => {
-
-
- store.commit('msg/SET_HIDDENT_ID', alert.data.dispatchNo)
- uni.$emit('printer-list-reflash')
- msgRead(alert.id)
- })
-
- }
- else if([3, 5, 20, 21, 23].includes(alert.code)) {
- console.log('其他异常消息--------------');
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve()
- }, 1000)
- }).then(res => {
- this.open(`/pages/popup/popup?info=${ JSON.stringify(alert) }`)
- })
- }
-
- else if([16, 17].includes(alert.code)) {
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve()
- }, 1000)
- }).then(res => {
- uni.$emit('photographer-working-order', {
- orderIDStr: alert.data.OrderIDStr,
- id: alert.id
- })
-
- if(alert.code === 16) {
- msgRead(alert.id)
- }
-
- })
- } else if([31].includes(alert.code)) {
- await new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve()
- }, 1000)
- }).then(res => {
- uni.$emit('printer-list-reflash')
- msgRead(alert.id)
- })
- } else {
- console.log('其他消息-----');
-
- }
- }
- }
-
- },
-
- getSystemInfo() {
- let info = {}
- uni.getSystemInfo({
- success(res) {
- console.log(res);
- info = res
- },
- fail() {
- msg.showToast({title: '获取设备信息失败!'})
- }
- })
- return info
- },
-
- formValidate(el) {
- return new Promise((resolve, reject) => {
- el.validate(valid => {
- if (valid) {
- resolve()
- } else {
- reject()
- }
- })
- })
- },
-
- getUniAppImgPath(count = 1) {
-
- return new Promise((resolve,reject) => {
- uni.chooseImage({
- count: count,
- sizeType: ['compressed'],
- sourceType: ['album','camera'],
- success: (res) => {
- count == 1? resolve(res.tempFilePaths[0]): resolve(res.tempFilePaths)
- },
- fail: (e) => {
- msg.hideLoading()
- }
- });
- })
-
-
- msg.showToast({title: '仅支持APP端'})
-
- },
-
- compressImage(path) {
- return new Promise((resolve,reject) => {
- uni.compressImage({
- src: path,
- quality: 50,
- width: '60%',
- height: '60%',
- success: res => {
- resolve(res.tempFilePath)
- }
- })
- })
- },
-
- async uploadFile(path) {
- let handlePath = path
-
- if(storage.getStorageSync('mobileInfo').platform == 'ios') {
- await this.compressImage(path).then(res => {
- handlePath = res
- })
- }
- return new Promise((resolve,reject) => {
- plus.io.resolveLocalFileSystemURL(handlePath,
- (entry) => {
- entry.file(file => {
- console.log(file.size, 'size--');
- let reader = new plus.io.FileReader();
- reader.onloadend = ( e ) => {
- resolve(e.target.result)
- };
- reader.readAsDataURL( file );
- })
- },
- (e) => {
- msg.hideLoading()
- msg.showToast({title: '读取文件失败:' + e})
- })
- })
- },
-
- uniScanCode() {
-
- return new Promise((resolve, reject) => {
- uni.scanCode({
- success: function (res) {
- resolve(res)
- },
- fail: function (err) {
- reject(err)
- }
- });
- })
-
-
- msg.showToast({title: '仅APP端支持扫码功能!'})
-
- },
-
- scanCodeLogin() {
- this.uniScanCode().then(res => {
- let resultCode = res.result
- if(resultCode.indexOf('deLogin:') !== -1){
- http.deviceLogin({
- mac: resultCode.replace('deLogin:','')
- }).then(res => {
- if(res.code == 0) {
- msg.showToast({title: '扫码成功!', success: 'success'})
- }else {
- msg.showToast({title: res.msg})
- }
- })
- }else if(resultCode.indexOf('station:') !== -1) {
-
- http.bindStation({id: resultCode.replace('station:', '')}).then(res => {
- console.log(res)
- if(res.code == 0) {
- msg.showToast({title: '绑定成功!'})
- }else {
- msg.showToast({title: res.msg})
- }
- })
- }else if(resultCode.indexOf('qrLogin:') !== -1) {
- let code = res.result.replace('qrLogin:','')
- http.scanCodeLogin({
- connectID: code.trim()
- }).then(res => {
- res.code === 0?
- msg.showToast({title: '扫码成功!', success: 'success'}):
- msg.showToast({title: res.msg || '扫码失败!'})
- })
- }else if(resultCode.indexOf('orReject:') !== -1) {
- let code = res.result.replace('orReject:','').split(':')
- this.open(`/pages/order/order-supplement?orderId=${ code[0] }`)
- } else {
- return msg.showToast({title: '二维码信息有误'})
- }
- })
- },
-
- handleData(data, handleData, filed, type) {
- if(handleData && handleData.length > 0) {
- let key = filed
- let obj = handleData.reduce((last,item)=>{
- if(type == 'date') {
- key = new DateFormat(new Date(item[filed])).toString('yyyy-mm-dd')
- }else {
- key = item[filed]
- }
- if(last[key]){
- last[key].push(item)
- }else{
- last[key]=[item]
- }
- return last
- },{})
- for (let key1 in data) {
- for (let key2 in obj) {
- if(key1 == key2) {
- obj[key2].push(...data[key1])
- }
- }
- }
- data = { ...data,...obj }
- return data
- }
- },
-
- getTimeDifference(time1, time2) {
- if(time1 && time2) {
- return parseInt(((new Date(time2).getTime() - new Date(time1).getTime())/1000/60)) + '分钟'
- } else {
- return ''
- }
- },
-
- setOnline() {
-
- let roleKey = storage.getStorageSync('userInfo').roleKey
- if(['directInkPrinter', 'paperPrinter', 'heatPrinter', 'autoCut', 'photoGrapher'].includes(roleKey)){
- http.updatePhoneOnline({onLineState: 1}).then(res => {
- console.log(res.msg, '在线')
-
- if(res.code !== 0) {
- this.setOutline()
- setTimeout(()=> {
- this.setOnline()
- },3000)
- }
- })
- }
- },
- setOutline() {
- let roleKey = storage.getStorageSync('userInfo').roleKey
- if(['directInkPrinter', 'paperPrinter', 'heatPrinter', 'autoCut', 'photoGrapher'].includes(roleKey)){
- http.updatePhoneOnline({onLineState: 0}).then(res => {
- console.log(res, '离线')
- if(res.code !== 0) {
-
- }
- })
- }
- },
-
- object2Code(obj) {
- return encodeURIComponent(JSON.stringify(obj))
- },
- code2Object(code) {
- return JSON.parse(decodeURIComponent(code))
- },
- utf8ByteToUnicodeStr(utf8Bytes) {
- var unicodeStr ='';
- for (var pos = 0; pos < utf8Bytes.length;){
- var flag= utf8Bytes[pos];
- var unicode = 0 ;
- if ((flag >>>7) === 0 ) {
- unicodeStr+= String.fromCharCode(utf8Bytes[pos]);
- pos += 1;
-
- } else if ((flag &0xFC) === 0xFC ){
- unicode = (utf8Bytes[pos] & 0x3) << 30;
- unicode |= (utf8Bytes[pos+1] & 0x3F) << 24;
- unicode |= (utf8Bytes[pos+2] & 0x3F) << 18;
- unicode |= (utf8Bytes[pos+3] & 0x3F) << 12;
- unicode |= (utf8Bytes[pos+4] & 0x3F) << 6;
- unicode |= (utf8Bytes[pos+5] & 0x3F);
- unicodeStr+= String.fromCodePoint(unicode) ;
- pos += 6;
-
- }else if ((flag &0xF8) === 0xF8 ){
- unicode = (utf8Bytes[pos] & 0x7) << 24;
- unicode |= (utf8Bytes[pos+1] & 0x3F) << 18;
- unicode |= (utf8Bytes[pos+2] & 0x3F) << 12;
- unicode |= (utf8Bytes[pos+3] & 0x3F) << 6;
- unicode |= (utf8Bytes[pos+4] & 0x3F);
- unicodeStr+= String.fromCodePoint(unicode) ;
- pos += 5;
-
- } else if ((flag &0xF0) === 0xF0 ){
- unicode = (utf8Bytes[pos] & 0xF) << 18;
- unicode |= (utf8Bytes[pos+1] & 0x3F) << 12;
- unicode |= (utf8Bytes[pos+2] & 0x3F) << 6;
- unicode |= (utf8Bytes[pos+3] & 0x3F);
- unicodeStr+= String.fromCodePoint(unicode) ;
- pos += 4;
-
- } else if ((flag &0xE0) === 0xE0 ){
- unicode = (utf8Bytes[pos] & 0x1F) << 12;;
- unicode |= (utf8Bytes[pos+1] & 0x3F) << 6;
- unicode |= (utf8Bytes[pos+2] & 0x3F);
- unicodeStr+= String.fromCharCode(unicode) ;
- pos += 3;
-
- } else if ((flag &0xC0) === 0xC0 ){
- unicode = (utf8Bytes[pos] & 0x3F) << 6;
- unicode |= (utf8Bytes[pos+1] & 0x3F);
- unicodeStr+= String.fromCharCode(unicode) ;
- pos += 2;
-
- } else{
- unicodeStr+= String.fromCharCode(utf8Bytes[pos]);
- pos += 1;
- }
- }
- return unicodeStr;
- },
-
- updateVersion () {
-
- http.DownloadApkFile().then(res => {
- console.log(res)
- if(res.code === 0) {
-
- plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
- console.log(res.result.version, wgtinfo.version)
- let version = storage.getStorageSync('version')
- if (res.result.version != wgtinfo.version) {
-
- uni.showLoading({
- title: '新版本下载中,请稍后',
- mask:true
- });
- let downloadTask = uni.downloadFile({
- url: res.result.ossUrl,
- success: (downloadResult) => {
- console.log('下载',downloadResult)
- if (downloadResult.statusCode === 200) {
- plus.runtime.install(downloadResult
- .tempFilePath, {
- force: true
- },
- function() {
- plus.runtime.quit();
-
-
-
-
-
-
-
-
-
- },
- function(e) {
- console.error('install fail...');
- });
- }
- },
- fail: (item => {
- uni.hideLoading();
- })
- })
-
-
-
-
-
-
-
-
-
- }else{
- }
- })
-
-
-
- }
- })
- },
-
- checkVersion(version, ossUrl) {
- if(version !== plus.runtime.version) {
- uni.showModal({
- title: '新版本',
- content: '是否下载更新版本',
- cancelText: '取消',
- confirmText: '下载',
- success: (res) => {
- if (res.confirm) {
- this.androidUpdate(ossUrl)
- }
- }
- })
- } else {
- storage.setStorageSync('version', version)
- }
- },
-
- androidUpdate(url) {
- uni.showLoading({
- title: '下载中...'
- })
- uni.downloadFile({
- url: url,
- success: downloadResult => {
- uni.hideLoading();
- if (downloadResult.statusCode == 200) {
- plus.runtime.install(
- downloadResult.tempFilePath, {
- force: true
- },
- function(res) {
- plus.runtime.quit();
-
- }
- );
- }
- },
- fail: err => {
- msg.showToast({ title: err })
- }
- })
- }
- }
|