diff --git a/compoment/PullDownBox/PullDownBox.vue b/compoment/PullDownBox/PullDownBox.vue new file mode 100644 index 0000000..ef30c9d --- /dev/null +++ b/compoment/PullDownBox/PullDownBox.vue @@ -0,0 +1,62 @@ + + + + + \ No newline at end of file diff --git a/compoment/ScrollList/ScrollList.vue b/compoment/ScrollList/ScrollList.vue new file mode 100644 index 0000000..bb37529 --- /dev/null +++ b/compoment/ScrollList/ScrollList.vue @@ -0,0 +1,87 @@ + + + \ No newline at end of file diff --git a/pagesHome/pages/SearchTray/SearchTray.vue b/pagesHome/pages/SearchTray/SearchTray.vue new file mode 100644 index 0000000..2d44583 --- /dev/null +++ b/pagesHome/pages/SearchTray/SearchTray.vue @@ -0,0 +1,535 @@ + + + + + \ No newline at end of file diff --git a/pagesHome/pages/VehicleArrivalDetails/VehicleArrivalDetails.vue b/pagesHome/pages/VehicleArrivalDetails/VehicleArrivalDetails.vue new file mode 100644 index 0000000..84c6541 --- /dev/null +++ b/pagesHome/pages/VehicleArrivalDetails/VehicleArrivalDetails.vue @@ -0,0 +1,1046 @@ + + + + + \ No newline at end of file diff --git a/store/useSearchInfoStore.js b/store/useSearchInfoStore.js new file mode 100644 index 0000000..251c917 --- /dev/null +++ b/store/useSearchInfoStore.js @@ -0,0 +1,35 @@ +import { + defineStore +} from 'pinia'; +import { + ref +} from 'vue'; + +const useSearchInfoStore = defineStore('useSearchInfoStore', () => { + /** 搜索的值 */ + const searchInfo = ref({}) + + /** 新增需要缓存的搜索值 */ + const HANDLE_EDIT_INFO = (pageName, info) => { + searchInfo.value[pageName] = info + } + + /** 删除需要缓存的搜索值 */ + const HANDLE_DELETE = (pageName) => { + delete searchInfo.value[pageName] + } + + /** 清空搜索框的值 */ + const HANDLE_CLEAR = () => { + searchInfo.value = {} + } + + return { + searchInfo, + HANDLE_EDIT_INFO, + HANDLE_DELETE, + HANDLE_CLEAR + } +}) + +export default useSearchInfoStore \ No newline at end of file diff --git a/store/useStorageStore.js b/store/useStorageStore.js new file mode 100644 index 0000000..e13d03d --- /dev/null +++ b/store/useStorageStore.js @@ -0,0 +1,60 @@ +import { + defineStore +} from 'pinia'; + +import { + ref +} from 'vue'; + +import { + postFindAllAllocationId +} from '@/api/user.js'; + +const useStorageStore = defineStore('useStorageStore', () => { + /** 存储本仓库位信息 */ + const storageArr = ref([]) + + /** 请求本仓库位信息 */ + const HANDLE_GETSTORAGEINFO = async () => { + const response = await postFindAllAllocationId() + + const { + code, + data + } = response + + if (code !== 200) return + storageArr.value = data + } + + /** 清空库位信息 */ + const HANDLE_CLEARSTORAGE = () => { + storageArr.value.splice(0) + } + + /** + * 检测是否为库位码 + * @param {string} code 扫描的code码 + * @return {boolean} 是否为库位码的判断 + * */ + const HANDLE_ISSTORAGECODE = (code) => { + let _flag = false + for (let item of storageArr.value) { + if ((item + '') === (code + '')) { + _flag = true + // 退出循环 + break + } + } + return _flag + } + + return { + storageArr, + HANDLE_GETSTORAGEINFO, + HANDLE_CLEARSTORAGE, + HANDLE_ISSTORAGECODE + } +}) + +export default useStorageStore \ No newline at end of file diff --git a/utils/base64Log.js b/utils/base64Log.js new file mode 100644 index 0000000..4718c3b --- /dev/null +++ b/utils/base64Log.js @@ -0,0 +1,313 @@ +// +// THIS FILE IS AUTOMATICALLY GENERATED! DO NOT EDIT BY HAND! +// +;(function(global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' + ? module.exports = factory() + : typeof define === 'function' && define.amd + ? define(factory) : + // cf. https://github.com/dankogai/js-base64/issues/119 + (function() { + // existing version for noConflict() + const _Base64 = global.Base64; + const gBase64 = factory(); + gBase64.noConflict = () => { + global.Base64 = _Base64; + return gBase64; + }; + if (global.Meteor) { // Meteor.js + Base64 = gBase64; + } + global.Base64 = gBase64; + })(); +}((typeof self !== 'undefined' ? self + : typeof window !== 'undefined' ? window + : typeof global !== 'undefined' ? global + : this +), function() { + 'use strict'; + +/** + * base64.ts + * + * Licensed under the BSD 3-Clause License. + * http://opensource.org/licenses/BSD-3-Clause + * + * References: + * http://en.wikipedia.org/wiki/Base64 + * + * @author Dan Kogai (https://github.com/dankogai) + */ +const version = '3.6.0'; +/** + * @deprecated use lowercase `version`. + */ +const VERSION = version; +const _hasatob = typeof atob === 'function'; +const _hasbtoa = typeof btoa === 'function'; +const _hasBuffer = typeof Buffer === 'function'; +const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined; +const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined; +const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; +const b64chs = [...b64ch]; +const b64tab = ((a) => { + let tab = {}; + a.forEach((c, i) => tab[c] = i); + return tab; +})(b64chs); +const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/; +const _fromCC = String.fromCharCode.bind(String); +const _U8Afrom = typeof Uint8Array.from === 'function' + ? Uint8Array.from.bind(Uint8Array) + : (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn)); +const _mkUriSafe = (src) => src + .replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_') + .replace(/=+$/m, ''); +const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, ''); +/** + * polyfill version of `btoa` + */ +const btoaPolyfill = (bin) => { + // console.log('polyfilled'); + let u32, c0, c1, c2, asc = ''; + const pad = bin.length % 3; + for (let i = 0; i < bin.length;) { + if ((c0 = bin.charCodeAt(i++)) > 255 || + (c1 = bin.charCodeAt(i++)) > 255 || + (c2 = bin.charCodeAt(i++)) > 255) + throw new TypeError('invalid character found'); + u32 = (c0 << 16) | (c1 << 8) | c2; + asc += b64chs[u32 >> 18 & 63] + + b64chs[u32 >> 12 & 63] + + b64chs[u32 >> 6 & 63] + + b64chs[u32 & 63]; + } + return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc; +}; +/** + * does what `window.btoa` of web browsers do. + * @param {String} bin binary string + * @returns {string} Base64-encoded string + */ +const _btoa = _hasbtoa ? (bin) => btoa(bin) + : _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64') + : btoaPolyfill; +const _fromUint8Array = _hasBuffer + ? (u8a) => Buffer.from(u8a).toString('base64') + : (u8a) => { + // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326 + const maxargs = 0x1000; + let strs = []; + for (let i = 0, l = u8a.length; i < l; i += maxargs) { + strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs))); + } + return _btoa(strs.join('')); + }; +/** + * converts a Uint8Array to a Base64 string. + * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5 + * @returns {string} Base64 string + */ +const fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a); +// This trick is found broken https://github.com/dankogai/js-base64/issues/130 +// const utob = (src: string) => unescape(encodeURIComponent(src)); +// reverting good old fationed regexp +const cb_utob = (c) => { + if (c.length < 2) { + var cc = c.charCodeAt(0); + return cc < 0x80 ? c + : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6)) + + _fromCC(0x80 | (cc & 0x3f))) + : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f)) + + _fromCC(0x80 | ((cc >>> 6) & 0x3f)) + + _fromCC(0x80 | (cc & 0x3f))); + } + else { + var cc = 0x10000 + + (c.charCodeAt(0) - 0xD800) * 0x400 + + (c.charCodeAt(1) - 0xDC00); + return (_fromCC(0xf0 | ((cc >>> 18) & 0x07)) + + _fromCC(0x80 | ((cc >>> 12) & 0x3f)) + + _fromCC(0x80 | ((cc >>> 6) & 0x3f)) + + _fromCC(0x80 | (cc & 0x3f))); + } +}; +const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; +/** + * @deprecated should have been internal use only. + * @param {string} src UTF-8 string + * @returns {string} UTF-16 string + */ +const utob = (u) => u.replace(re_utob, cb_utob); +// +const _encode = _hasBuffer + ? (s) => Buffer.from(s, 'utf8').toString('base64') + : _TE + ? (s) => _fromUint8Array(_TE.encode(s)) + : (s) => _btoa(utob(s)); +/** + * converts a UTF-8-encoded string to a Base64 string. + * @param {boolean} [urlsafe] if `true` make the result URL-safe + * @returns {string} Base64 string + */ +const encode = (src, urlsafe = false) => urlsafe + ? _mkUriSafe(_encode(src)) + : _encode(src); +/** + * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5. + * @returns {string} Base64 string + */ +const encodeURI = (src) => encode(src, true); +// This trick is found broken https://github.com/dankogai/js-base64/issues/130 +// const btou = (src: string) => decodeURIComponent(escape(src)); +// reverting good old fationed regexp +const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g; +const cb_btou = (cccc) => { + switch (cccc.length) { + case 4: + var cp = ((0x07 & cccc.charCodeAt(0)) << 18) + | ((0x3f & cccc.charCodeAt(1)) << 12) + | ((0x3f & cccc.charCodeAt(2)) << 6) + | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000; + return (_fromCC((offset >>> 10) + 0xD800) + + _fromCC((offset & 0x3FF) + 0xDC00)); + case 3: + return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12) + | ((0x3f & cccc.charCodeAt(1)) << 6) + | (0x3f & cccc.charCodeAt(2))); + default: + return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6) + | (0x3f & cccc.charCodeAt(1))); + } +}; +/** + * @deprecated should have been internal use only. + * @param {string} src UTF-16 string + * @returns {string} UTF-8 string + */ +const btou = (b) => b.replace(re_btou, cb_btou); +/** + * polyfill version of `atob` + */ +const atobPolyfill = (asc) => { + // console.log('polyfilled'); + asc = asc.replace(/\s+/g, ''); + if (!b64re.test(asc)) + throw new TypeError('malformed base64.'); + asc += '=='.slice(2 - (asc.length & 3)); + let u24, bin = '', r1, r2; + for (let i = 0; i < asc.length;) { + u24 = b64tab[asc.charAt(i++)] << 18 + | b64tab[asc.charAt(i++)] << 12 + | (r1 = b64tab[asc.charAt(i++)]) << 6 + | (r2 = b64tab[asc.charAt(i++)]); + bin += r1 === 64 ? _fromCC(u24 >> 16 & 255) + : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255) + : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255); + } + return bin; +}; +/** + * does what `window.atob` of web browsers do. + * @param {String} asc Base64-encoded string + * @returns {string} binary string + */ +const _atob = _hasatob ? (asc) => atob(_tidyB64(asc)) + : _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary') + : atobPolyfill; +// +const _toUint8Array = _hasBuffer + ? (a) => _U8Afrom(Buffer.from(a, 'base64')) + : (a) => _U8Afrom(_atob(a), c => c.charCodeAt(0)); +/** + * converts a Base64 string to a Uint8Array. + */ +const toUint8Array = (a) => _toUint8Array(_unURI(a)); +// +const _decode = _hasBuffer + ? (a) => Buffer.from(a, 'base64').toString('utf8') + : _TD + ? (a) => _TD.decode(_toUint8Array(a)) + : (a) => btou(_atob(a)); +const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/')); +/** + * converts a Base64 string to a UTF-8 string. + * @param {String} src Base64 string. Both normal and URL-safe are supported + * @returns {string} UTF-8 string + */ +const decode = (src) => _decode(_unURI(src)); +/** + * check if a value is a valid Base64 string + * @param {String} src a value to check + */ +const isValid = (src) => { + if (typeof src !== 'string') + return false; + const s = src.replace(/\s+/g, '').replace(/=+$/, ''); + return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s); +}; +// +const _noEnum = (v) => { + return { + value: v, enumerable: false, writable: true, configurable: true + }; +}; +/** + * extend String.prototype with relevant methods + */ +const extendString = function () { + const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body)); + _add('fromBase64', function () { return decode(this); }); + _add('toBase64', function (urlsafe) { return encode(this, urlsafe); }); + _add('toBase64URI', function () { return encode(this, true); }); + _add('toBase64URL', function () { return encode(this, true); }); + _add('toUint8Array', function () { return toUint8Array(this); }); +}; +/** + * extend Uint8Array.prototype with relevant methods + */ +const extendUint8Array = function () { + const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body)); + _add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); }); + _add('toBase64URI', function () { return fromUint8Array(this, true); }); + _add('toBase64URL', function () { return fromUint8Array(this, true); }); +}; +/** + * extend Builtin prototypes with relevant methods + */ +const extendBuiltins = () => { + extendString(); + extendUint8Array(); +}; +const gBase64 = { + version: version, + VERSION: VERSION, + atob: _atob, + atobPolyfill: atobPolyfill, + btoa: _btoa, + btoaPolyfill: btoaPolyfill, + fromBase64: decode, + toBase64: encode, + encode: encode, + encodeURI: encodeURI, + encodeURL: encodeURI, + utob: utob, + btou: btou, + decode: decode, + isValid: isValid, + fromUint8Array: fromUint8Array, + toUint8Array: toUint8Array, + extendString: extendString, + extendUint8Array: extendUint8Array, + extendBuiltins: extendBuiltins, +}; + + // + // export Base64 to the namespace + // + // ES5 is yet to have Object.assign() that may make transpilers unhappy. + // gBase64.Base64 = Object.assign({}, gBase64); + gBase64.Base64 = {}; + Object.keys(gBase64).forEach(k => gBase64.Base64[k] = gBase64[k]); + return gBase64; +})); \ No newline at end of file diff --git a/utils/handleFile.js b/utils/handleFile.js new file mode 100644 index 0000000..0773ae1 --- /dev/null +++ b/utils/handleFile.js @@ -0,0 +1,170 @@ +/* + 使用该类应开启以下权限(读取和写入) + + + */ +/* + 文件编码 + ansi(ascii):英文标准码0-127,包括控制符和其他英文字符编码,这在后来一直统一没再变过,当然它只需要一个字节保存 + gb2312和gbk:这两个是ancii码加上汉字的扩展,汉字多达10万,在ancii编码基础上再加一个字节表示汉字,共可表示字符65535个,包括了繁体字。因此一个中文字符包含两个字节。eclipse中默认编码方式为gbk。在Windows中文系统中ANSI是默认的编码方式。对于英文文件是ASCII编码,对于简体中文文件是GB2312编码。 + Unicode编码:顾名思义,这是国际统一标准编码,在这之前各国标准编码不统一,微软等公司需要为各国的计算机系统定制符合不同编码标准的系统,显然,成本太高,并且互联网的出现让不同编码标准的计算机交互变得困难,如:两国的邮件系统,会因为使用不同的编码标准而导致接受方收到的邮件是乱码。 + utf-8和utf-16编码:UTF的意思是(UCS Transfer Format),显然是随着互联网的出现,需要解决Unicode在网络上的传输问题。顾名思义,UTF8就是每次8个位传输数据,而UTF16就是每次16个位,只不过为了传输时的可靠性,从UNICODE到UTF时并不是直接的对应,而是要过一些算法和规则来转换。UTF-8就是在互联网上使用最广的一种unicode的实现方式。 +*/ + +/** + * 获取手机内置存储的根路径 + * @return {String} + */ +const root = function() { + const environment = plus.android.importClass("android.os.Environment"); + return environment.getExternalStorageDirectory(); +} + +/** + * 获取指定文件夹下的所有文件和文件夹列表 + * @param {String} path 文件夹路径 + * @return {Array} 文件和文件夹列表 + */ +const filelist = function(dir = '') { + const File = plus.android.importClass("java.io.File"); + let list = []; + let file = new File(dir); + let tempList = file.listFiles(); + for (let i = 0; i < tempList.length; i++) { + let fileName = tempList[i].getName(); + list.push(fileName); + } + return list; +} + +/** + * 创建文件 + * @return {boolean} flase=失败(已存在、操作失败),true=成功 + */ +const createNewFile = function(path = '') { + const File = plus.android.importClass('java.io.File'); + let file = new File(path); + if (!file.exists()) { + return file.createNewFile(); + } + return false; +} + +/** + * 创建文件夹 + * @return {boolean} flase=失败(已存在、操作失败),true=成功 + */ +const mkdirs = function(path = ''){ + const File = plus.android.importClass('java.io.File'); + let file = new File(path); + if (!file.exists()) { + return file.mkdirs(); + } + return false; +} + +/** + * 读取文件 + * @param {String} path 文件路径 + * @param {String} charset 编码 + * @return {Array} 内容列表(按行读取),文件不存在或异常则返回false + */ +const readTxt = function(path = '', charset = 'utf-8') { + const File = plus.android.importClass('java.io.File'); + const InputStreamReader = plus.android.importClass('java.io.InputStreamReader'); + const BufferedReader = plus.android.importClass('java.io.BufferedReader'); + const FileInputStream = plus.android.importClass('java.io.FileInputStream'); + let file = new File(path); + let inputStreamReader = null; + let bufferedReader = null; + let list = []; + try { + if (!file.exists()) { + return false; + } + inputStreamReader = new InputStreamReader(new FileInputStream(file), charset); + bufferedReader = new BufferedReader(inputStreamReader); + let line = ''; + while (null != (line = bufferedReader.readLine())) { + list.push(line); + } + bufferedReader.close(); + inputStreamReader.close(); + } catch (e) { + if (null != bufferedReader) { + bufferedReader.close(); + } + if (null != inputStreamReader) { + inputStreamReader.close(); + } + return false; + } + return list; +} + +/** + * 写入文件内容 + * @param {String} path 文件路径 + * @param {String} content 内容 + * @param {boolean} append 内容写入类型,false=不追加(覆盖原有内容),true=追加(从内容尾部写入) + * @param {String} charset 编码 + * @return {boolean} true=成功,false=失败 + */ +const writeTxt = function(path = '', content = '', append = false, charset = 'utf-8') { + const File = plus.android.importClass('java.io.File'); + const FileOutputStream = plus.android.importClass('java.io.FileOutputStream'); + const OutputStreamWriter = plus.android.importClass('java.io.OutputStreamWriter'); + + let outputStreamWriter; + let file = new File(path); + try { + //不存在则创建新的文件 + if (!file.exists()) { + file.createNewFile(); + } + outputStreamWriter = new OutputStreamWriter(new FileOutputStream(path, append), charset); + outputStreamWriter.write(content); + outputStreamWriter.close(); + } catch (e) { + if (null != outputStreamWriter) { + outputStreamWriter.close(); + } + return false; + } + return true; +} + +/** + * 判断文件是否存在 + * @param path 文件路径 + * @return true=存在 false=不存在 + */ +const isFileExist = function(path = ''){ + const File = plus.android.importClass('java.io.File'); + return new File(path).exists() +} + +/** + * 删除文件 + * @param {String} path + */ +const deleteFile = function(path = ''){ + const File = plus.android.importClass('java.io.File'); + let file = new File(path); + if (file.exists()) { + return file.delete(); + } + return false +} + + +export default { + root, + filelist, + createNewFile, + mkdirs, + readTxt, + writeTxt, + isFileExist, + deleteFile +} \ No newline at end of file diff --git a/utils/log.js b/utils/log.js new file mode 100644 index 0000000..5f3fe07 --- /dev/null +++ b/utils/log.js @@ -0,0 +1,205 @@ +import +Base64 +from './base64.js' + +import handleFile from '@/utils/handleFile.js'; + +// #ifdef APP + +// 保存文字 +let logTextData = ''; + +const { + root +} = handleFile + +const file = `${root()}/scanLogs` +// #endif + +/** + * js 日期格式化 + * 传时间戳参数进行时间戳转换,不传时返回当前时间(返回年月日时分秒格式) + * @param {Object} timeStamp 时间戳参数 非必传 + * @param {Object} format 格式化样式 非必传 + */ +function getTimeStampDatetime(format = 'yyyy-MM-dd HH:mm:ss', timeStamp) { + let nowDatetime = new Date() + timeStamp ? nowDatetime = new Date(timeStamp) : nowDatetime = new Date() + return nowDatetime.Format(format) +} +Date.prototype.Format = function(fmt) { + var o = { + "M+": this.getMonth() + 1, //月份 + "d+": this.getDate(), //日 + "H+": this.getHours(), //小时 + "m+": this.getMinutes(), //分 + "s+": this.getSeconds(), //秒 + "q+": Math.floor((this.getMonth() + 3) / 3), //季度 + "S": this.getMilliseconds() //毫秒 + }; + if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); + for (var k in o) + if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (( + "00" + o[ + k]).substr(("" + o[k]).length))); + return fmt; +} + +// 获取日志文件名称 +function getLogFileName() { + // 今日日期 + let nowDate = getTimeStampDatetime("yyyy-MM-dd") + // 当前时间精确到秒 + let nowTime = getTimeStampDatetime("HH:mm:ss") + // 文件名称 + let fileName = 'app-log.txt' + // fileName = nowDate + 'log.txt' + fileName = nowDate + '.txt' + // 内容换行符(自定义) + let newLine = "\r\n" + "======================================" + "\r\n" + nowTime + " =>>>" + "\r\n" + + return { + nowDate: nowDate, + newLine: newLine, + fileName: fileName + } +} + +/** + * 日志内容写入 + * 文件写入手机地址,华为Android/data/应用包名/documents/app-log/2021-01-17log.text + * @param {Object} params 写入内容 + * @param {Object} encryption 是否加密 + */ +// 防抖 +let writelogtime = null; + +function writeLog(params, encryption) { + let text = JSON.stringify(params) + + if (encryption) { + logTextData += (getLogFileName().newLine + " " + Base64.encode(text)); + } else { + logTextData += (getLogFileName().newLine + " " + text); + } + if (writelogtime) { + clearTimeout(writelogtime) + } + //不然就创建新的定时器 3秒没有新日志再执行写入操作 + writelogtime = setTimeout(function() { + writeLogTxt() + }, 3000) +} + +function writeLogTxt() { + plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) { + // 可通过fs操作PUBLIC_DOCUMENTS文件系统 + // 创建日志文件夹 + fs.root.getDirectory("app-log", { + create: true, + exclusive: false + }, function(dir) { + dir.getDirectory(getLogFileName().nowDate, { + create: true, + exclusive: false + }, function(dir) { + // 创建或写入文件 + console.log("Directory Entry Name: " + dir.fullPath + getLogFileName().fileName); + dir.getFile(getLogFileName().fileName, { + create: true + }, function(fileEntry) { + // 找到文件准备写入操作 + fileEntry.file(function(file) { + // create a FileWriter to write to the file + fileEntry.createWriter(function(writer) { + // Write data to file. + writer.seek(file.size - 1) + // 换行插入日志文件 + writer.write(logTextData); + console.log('111 :>> ', 111); + logTextData = ''; + }, function(e) { + console.error("日志写入错误", error) + }); + }); + }); + }, function(err) { + console.error("文件夹创建失败", err) + }); + }, function(err) { + console.error("文件夹创建失败", err) + }); + + }, function(error) { + console.error("文件系统进入错误", error) + }); +} + +function delLogFile() { + console.log("日志删除") + plus.io.resolveLocalFileSystemURL( + file, //指定的目录 + function(entry) { + var directoryReader = entry.createReader(); //获取读取目录对象 + directoryReader.readEntries( + function(entries) { //历遍子目录即可 + for (var i = 0; i < entries.length; i++) { + console.log("文件信息:" + entries[i].name); + let twoDate = Date.parse(getLogFileName().nowDate) - (86400000 * 2); + console.log("保留三天内日志", twoDate) + if (Date.parse(entries[i].name) < twoDate) { + entries[i].removeRecursively(function(entry) { + writeLog("日志删除成功" + entries[i].name, false); + }, function(e) { + writeLog("日志删除成功" + e.message, false); + }); + } + } + }, + function(err) { + console.log("没有异常日志"); + }); + }, + function(err) { + console.log("没有异常日志"); + }); +} +// 查询本地日志文件(直接当前页面调用,该接口未使用) +function selectLogUrl() { + plus.io.resolveLocalFileSystemURL( + file, //指定的目录 + function(entry) { + var directoryReader = entry.createReader(); //获取读取目录对象 + directoryReader.readEntries( + function(entries) { //历遍子目录即可 + let isLog = false; + for (var i = 0; i < entries.length; i++) { + console.log("文件信息:" + entries[i].name); + if (entries[i].name == getLogFileName().nowDate) { + console.log("获取到当天文件为", entries[i].name) + var url = file + '/' + entries[i].name + '/' + getLogFileName().nowDate + '.txt'; + var path = plus.io.convertLocalFileSystemURL(url); + var newurl = plus.io.convertAbsoluteFileSystem(path); + isLog = true; + return newurl; + } + } + if (isLog) { + return ''; + } + }, + function(err) { + console.log("访问目录失败"); + }); + }, + function(err) { + console.log("访问目录失败"); + }); +} + +export default { + writeLog, + delLogFile, + getLogFileName, + selectLogUrl +} \ No newline at end of file