From e491cdb48129752324c4e3764f99bd9203c56dec Mon Sep 17 00:00:00 2001
From: lgq <1015864684@qq.com>
Date: 星期二, 31 三月 2026 09:48:44 +0800
Subject: [PATCH] 1.新增VF205门禁机代码
---
vf205_access/dxmodules/dxLogger.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/vf205_access/dxmodules/dxLogger.js b/vf205_access/dxmodules/dxLogger.js
new file mode 100644
index 0000000..ed79322
--- /dev/null
+++ b/vf205_access/dxmodules/dxLogger.js
@@ -0,0 +1,59 @@
+/**
+ * dxLogger module
+ * To replace the `console.log` function, allowing logs to be viewed in the corresponding VSCode plugin during debugging,
+ * with support for three levels of logging: `debug`,`info`, and `error`.
+ * Supports printing various data types in JavaScript.
+ */
+import dxCommon from './dxCommon.js'
+const logger = {}
+
+logger.config = {
+ level: 0, // default is all,if<0,no print
+}
+logger.debug = function (...data) {
+ if (this.config.level === 0) {
+ log("DEBUG ", data)
+ }
+}
+logger.info = function (...data) {
+ if ([0, 1].includes(this.config.level)) {
+ log("INFO ", data)
+ }
+}
+logger.error = function (...data) {
+ if ([0, 1, 2].includes(this.config.level)) {
+ log("ERROR ", data)
+ }
+}
+//-----------------------------------private----------------------
+function log(level, messages) {
+ let message = messages.map(msg => getContent(msg)).join(' ');
+ let content = `[${level}${getTime()}]: ${message}`
+ dxCommon.systemBrief(`echo '${content}'`)
+}
+function getContent(message) {
+ if (message === undefined) {
+ return 'undefined'
+ } else if (message === null) {
+ return 'null'
+ }
+ if ((typeof message) == 'object') {
+ if (Object.prototype.toString.call(message) === '[object Error]') {
+ return message.message + '\n' + message.stack
+ }
+ return JSON.stringify(message)
+ }
+ return message
+}
+function getTime() {
+ const now = new Date();
+ const year = now.getFullYear();
+ const month = ('0' + (now.getMonth() + 1)).slice(-2);
+ const day = ('0' + now.getDate()).slice(-2);
+ const hours = ('0' + now.getHours()).slice(-2);
+ const minutes = ('0' + now.getMinutes()).slice(-2);
+ const seconds = ('0' + now.getSeconds()).slice(-2);
+ const milliseconds = ('0' + now.getMilliseconds()).slice(-3);
+ return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds + '.' + milliseconds;
+}
+export default logger
\ No newline at end of file
--
Gitblit v1.9.3