Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@youngbeen/angle-ctrl

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@youngbeen/angle-ctrl - npm Package Compare versions

Comparing version
1.0.2
to
1.0.3
+207
DebugCtrl.js
"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
// this controller is about to provide functions for debugging controll
var logCtrl = _interopRequire(require("./LogCtrl"));
// import System from '../models/System'
// import $ from 'jQuery'
var debug = false; // 是否开启debug模式
var cheatCounts = 0; // cheat debug点击的累计次数
var tcCheatDebug = null; // cheat debug time ctrl
module.exports = {
// system log -- 信息,[ 是否记录到log中,所在组件名,所在函数名,行数,附加信息 ]
// NOTE: log方法默认不会记录到日志中
log: function log(info, params) {
var isSave = false;
var line = "";
var compName = "";
var funcName = "";
var attach = "";
var msg = info;
if (params) {
if (params.isSave) {
isSave = params.isSave;
}
if (params.line) {
line = params.line;
msg += "[line:" + line + "]";
}
if (params.compName) {
compName = params.compName;
msg += "[comp:" + compName + "]";
}
if (params.funcName) {
funcName = params.funcName;
msg += "[func:" + funcName + "]";
}
if (params.attach) {
attach = params.attach;
}
}
console.log(msg);
if (isSave) {
logCtrl.saveLog(info, "info", line, compName, funcName, attach);
}
if (debug) {
// 调试模式打开,打开alert方式
window.alert(msg);
}
},
// system warn -- 信息,[ 所在组件名,所在函数名,行数,附加信息 ]
// NOTE: warn方法只自动记录日志,不主动发送到后台
warn: function warn(info, params) {
var line = "";
var compName = "";
var funcName = "";
var attach = "";
var msg = info;
if (params) {
if (params.line) {
line = params.line;
msg += "[line:" + line + "]";
}
if (params.compName) {
compName = params.compName;
msg += "[comp:" + compName + "]";
}
if (params.funcName) {
funcName = params.funcName;
msg += "[func:" + funcName + "]";
}
if (params.attach) {
attach = params.attach;
}
}
console.warn(msg);
logCtrl.saveLog(info, "warn", line, compName, funcName, attach);
if (debug) {
// 调试模式打开,打开alert方式
window.alert(msg);
}
},
// system error -- 信息,[ 所在组件名,所在函数名,行数,附加信息 ]
// NOTE: error方法会自动记录,并自动发送到后台
error: function error(info, params) {
var line = "";
var compName = "";
var funcName = "";
var attach = "";
var msg = info;
if (params) {
if (params.line) {
line = params.line;
msg += "[line:" + line + "]";
}
if (params.compName) {
compName = params.compName;
msg += "[comp:" + compName + "]";
}
if (params.funcName) {
funcName = params.funcName;
msg += "[func:" + funcName + "]";
}
if (params.attach) {
attach = params.attach;
}
}
console.warn(msg);
logCtrl.saveLog(info, "error", line, compName, funcName, attach);
// 发生错误,立即发送信息到日志系统
logCtrl.sendLog();
if (debug) {
// 调试模式打开,打开alert方式
window.alert(msg);
}
},
// // freeze background scroll
// freezeBgScroll() {
// System.isFreezeBgScroll = true
// // to be robust, we should add no-scroll in html and body tag as well
// $('html').addClass('no-scroll')
// $('body').addClass('no-scroll')
// },
// // resume background scroll
// resumeBgScroll() {
// System.isFreezeBgScroll = false
// $('html').removeClass('no-scroll')
// $('body').removeClass('no-scroll')
// },
// open debugging mode cheat -- trigger click counts, [interval]
cheatDebugClick: function cheatDebugClick(count) {
var interval = arguments[1] === undefined ? 1000 : arguments[1];
cheatCounts++;
if (cheatCounts >= count) {
// 切换 cheat debug
debug = !debug;
window.localStorage.debug = debug;
window.alert("debug模式调整为" + debug);
if (tcCheatDebug) {
clearTimeout(tcCheatDebug);
}
cheatCounts = 0;
} else {
// if (System.cheatCounts >= 2) window.alert(111)
// 还未达到cheat debug条件
if (tcCheatDebug) {
clearTimeout(tcCheatDebug);
}
tcCheatDebug = setTimeout(function () {
// 规定时间内没有重复操作,清除所有参数
cheatCounts = 0;
clearTimeout(tcCheatDebug);
}, interval);
}
}
// // open debugging mode cheat by maze clicking -- click index
// cheatMazeDebug(index) {
// // 设定maze cheat需要判定的个数
// console.log('进入maze check')
// const mazeCount = 3
// System.cheatMazeMap.push(index)
// let flag = true
// for (let i = 0; i < System.cheatMazeMap.length; i++) {
// if (System.cheatMazeMap[i] !== (i + 1)) {
// flag = false
// break
// }
// }
// if (!flag) {
// // 存在非法的maze code
// console.log('非法 maze code')
// System.cheatMazeMap = []
// } else {
// // 全部是合法的code
// if (System.cheatMazeMap.length === mazeCount) {
// // 输入的maze code已经达到标准
// System.cheatMazeMap = []
// System.debug = !System.debug
// localStorage.debug = System.debug
// window.alert('debug模式调整为' + System.debug)
// } else {
// // 输入的maze code还不到标准
// // do nothing
// console.log('maze code 正确,继续加油')
// }
// }
// }
};
"use strict";
var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } };
// this controller is about to provide functions for log controll
var dateUtil = require("@youngbeen/angle-util").dateUtil;
var logs = []; // 日志信息
var tagRandoms = Math.floor(Math.random() * 100000000000000); // 用于标识某访问的唯一标识符组成部分的随机数
var tagTime = new Date();
tagTime = tagTime.getTime(); // 用于标识某访问的唯一标识符组成部分的时间戳
module.exports = {
// 保存日志到历史记录 -- 信息内容,信息类型,[ 行数,所在组件名,所在函数名,附加信息 ]
saveLog: function saveLog(msg, type) {
var line = arguments[2] === undefined ? "" : arguments[2];
var compName = arguments[3] === undefined ? "" : arguments[3];
var funcName = arguments[4] === undefined ? "" : arguments[4];
var attach = arguments[5] === undefined ? "" : arguments[5];
if (msg && type) {
var now = new Date();
now = now.getTime();
now = dateUtil.getDateTime(now);
logs = [].concat(_toConsumableArray(logs), [{
msg: msg,
type: type,
clientTime: now,
compName: compName,
funcName: funcName,
line: line,
attach: attach
}]);
}
},
// 发送日志到日志系统 --
sendLog: function sendLog() {
if (logs.length) {
var tag = "" + tagTime + "-" + tagRandoms; // 组成该次访问的唯一标识符,用于日志筛选匹配对应使用
var now = new Date();
now = now.getTime();
now = dateUtil.getDateTime(now);
var params = {
url: window.location.href || "",
tag: tag,
ua: window.navigator.userAgent || "",
clientTime: now, // 格式形如 2017-01-01 10:00:00
historyLogs: logs
};
// window.tracking('UMS_FELOG_ERRORLOG', params)
var content = {
id: "UMS_FELOG_ERRORLOG",
params: params
};
// TODO 自有后台接收日志的地址后续需要调整
var url = "https://someurl?type=UMS_FELOG&content=LOGSTART>>" + encodeURIComponent(JSON.stringify(content)) + "<<LOGEND";
var oImage = new Image();
oImage.src = url;
oImage = null;
}
}
};
// this controller is about to provide functions for debugging controll
import logCtrl from './LogCtrl'
// import System from '../models/System'
// import $ from 'jQuery'
let debug = false // 是否开启debug模式
let cheatCounts = 0 // cheat debug点击的累计次数
let tcCheatDebug = null // cheat debug time ctrl
export default {
// system log -- 信息,[ 是否记录到log中,所在组件名,所在函数名,行数,附加信息 ]
// NOTE: log方法默认不会记录到日志中
log (info, params) {
let isSave = false
let line = ''
let compName = ''
let funcName = ''
let attach = ''
let msg = info
if (params) {
if (params.isSave) {
isSave = params.isSave
}
if (params.line) {
line = params.line
msg += `[line:${line}]`
}
if (params.compName) {
compName = params.compName
msg += `[comp:${compName}]`
}
if (params.funcName) {
funcName = params.funcName
msg += `[func:${funcName}]`
}
if (params.attach) {
attach = params.attach
}
}
console.log(msg)
if (isSave) {
logCtrl.saveLog(info, 'info', line, compName, funcName, attach)
}
if (debug) {
// 调试模式打开,打开alert方式
window.alert(msg)
}
},
// system warn -- 信息,[ 所在组件名,所在函数名,行数,附加信息 ]
// NOTE: warn方法只自动记录日志,不主动发送到后台
warn (info, params) {
let line = ''
let compName = ''
let funcName = ''
let attach = ''
let msg = info
if (params) {
if (params.line) {
line = params.line
msg += `[line:${line}]`
}
if (params.compName) {
compName = params.compName
msg += `[comp:${compName}]`
}
if (params.funcName) {
funcName = params.funcName
msg += `[func:${funcName}]`
}
if (params.attach) {
attach = params.attach
}
}
console.warn(msg)
logCtrl.saveLog(info, 'warn', line, compName, funcName, attach)
if (debug) {
// 调试模式打开,打开alert方式
window.alert(msg)
}
},
// system error -- 信息,[ 所在组件名,所在函数名,行数,附加信息 ]
// NOTE: error方法会自动记录,并自动发送到后台
error (info, params) {
let line = ''
let compName = ''
let funcName = ''
let attach = ''
let msg = info
if (params) {
if (params.line) {
line = params.line
msg += `[line:${line}]`
}
if (params.compName) {
compName = params.compName
msg += `[comp:${compName}]`
}
if (params.funcName) {
funcName = params.funcName
msg += `[func:${funcName}]`
}
if (params.attach) {
attach = params.attach
}
}
console.warn(msg)
logCtrl.saveLog(info, 'error', line, compName, funcName, attach)
// 发生错误,立即发送信息到日志系统
logCtrl.sendLog()
if (debug) {
// 调试模式打开,打开alert方式
window.alert(msg)
}
},
// // freeze background scroll
// freezeBgScroll() {
// System.isFreezeBgScroll = true
// // to be robust, we should add no-scroll in html and body tag as well
// $('html').addClass('no-scroll')
// $('body').addClass('no-scroll')
// },
// // resume background scroll
// resumeBgScroll() {
// System.isFreezeBgScroll = false
// $('html').removeClass('no-scroll')
// $('body').removeClass('no-scroll')
// },
// open debugging mode cheat -- trigger click counts, [interval]
cheatDebugClick (count, interval = 1000) {
cheatCounts++
if (cheatCounts >= count) {
// 切换 cheat debug
debug = !debug
window.localStorage.debug = debug
window.alert('debug模式调整为' + debug)
if (tcCheatDebug) {
clearTimeout(tcCheatDebug)
}
cheatCounts = 0
} else {
// if (System.cheatCounts >= 2) window.alert(111)
// 还未达到cheat debug条件
if (tcCheatDebug) {
clearTimeout(tcCheatDebug)
}
tcCheatDebug = setTimeout(() => {
// 规定时间内没有重复操作,清除所有参数
cheatCounts = 0
clearTimeout(tcCheatDebug)
}, interval)
}
}
// // open debugging mode cheat by maze clicking -- click index
// cheatMazeDebug(index) {
// // 设定maze cheat需要判定的个数
// console.log('进入maze check')
// const mazeCount = 3
// System.cheatMazeMap.push(index)
// let flag = true
// for (let i = 0; i < System.cheatMazeMap.length; i++) {
// if (System.cheatMazeMap[i] !== (i + 1)) {
// flag = false
// break
// }
// }
// if (!flag) {
// // 存在非法的maze code
// console.log('非法 maze code')
// System.cheatMazeMap = []
// } else {
// // 全部是合法的code
// if (System.cheatMazeMap.length === mazeCount) {
// // 输入的maze code已经达到标准
// System.cheatMazeMap = []
// System.debug = !System.debug
// localStorage.debug = System.debug
// window.alert('debug模式调整为' + System.debug)
// } else {
// // 输入的maze code还不到标准
// // do nothing
// console.log('maze code 正确,继续加油')
// }
// }
// }
}
// this controller is about to provide functions for log controll
import { dateUtil } from '@youngbeen/angle-util'
let logs = [] // 日志信息
const tagRandoms = Math.floor(Math.random() * 10e13) // 用于标识某访问的唯一标识符组成部分的随机数
let tagTime = new Date()
tagTime = tagTime.getTime() // 用于标识某访问的唯一标识符组成部分的时间戳
export default {
// 保存日志到历史记录 -- 信息内容,信息类型,[ 行数,所在组件名,所在函数名,附加信息 ]
saveLog (msg, type, line = '', compName = '', funcName = '', attach = '') {
if (msg && type) {
let now = new Date()
now = now.getTime()
now = dateUtil.getDateTime(now)
logs = [...logs, {
msg,
type,
clientTime: now,
compName,
funcName,
line,
attach
}]
}
},
// 发送日志到日志系统 --
sendLog () {
if (logs.length) {
const tag = `${tagTime}-${tagRandoms}` // 组成该次访问的唯一标识符,用于日志筛选匹配对应使用
let now = new Date()
now = now.getTime()
now = dateUtil.getDateTime(now)
let params = {
url: window.location.href || '',
tag,
ua: window.navigator.userAgent || '',
clientTime: now, // 格式形如 2017-01-01 10:00:00
historyLogs: logs
}
// window.tracking('UMS_FELOG_ERRORLOG', params)
let content = {
id: 'UMS_FELOG_ERRORLOG',
params
}
// TODO 自有后台接收日志的地址后续需要调整
let url = `https://someurl?type=UMS_FELOG&content=LOGSTART>>${encodeURIComponent(JSON.stringify(content))}<<LOGEND`
let oImage = new Image()
oImage.src = url
oImage = null
}
}
}
+9
-1

@@ -12,3 +12,11 @@ "use strict";

var LogCtrl = _interopRequire(require("./LogCtrl"));
var DebugCtrl = _interopRequire(require("./DebugCtrl"));
var timeCtrl = TimeCtrl;
exports.timeCtrl = timeCtrl;
exports.timeCtrl = timeCtrl;
var logCtrl = LogCtrl;
exports.logCtrl = logCtrl;
var debugCtrl = DebugCtrl;
exports.debugCtrl = debugCtrl;
+1
-1
{
"name": "@youngbeen/angle-ctrl",
"version": "1.0.2",
"version": "1.0.3",
"description": "The controllers used in angle-FE team",

@@ -5,0 +5,0 @@ "main": "index.js",

// entry js
import TimeCtrl from './TimeCtrl'
import LogCtrl from './LogCtrl'
import DebugCtrl from './DebugCtrl'
export const timeCtrl = TimeCtrl
export const logCtrl = LogCtrl
export const debugCtrl = DebugCtrl