Skip to content

Commit

Permalink
Merge pull request #20 from Nil-nil-zero/main
Browse files Browse the repository at this point in the history
新增函数:浏览器禁止切换页面
  • Loading branch information
chenbimo authored Jul 30, 2024
2 parents 3edafff + 3696af5 commit eed9cea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/yd_browser_denyChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 浏览器禁止切换页面
* @param {Function} 函数
* @param {number} number 切换次数,默认是3次
* @param {String} msg 切换次数,默认提示内容“切换次数超过限制”
* @author Nil <https://github.com/Nil-nil-zero>
* @summary 应用场景:线上考试场景
*/

export function browser_denyChange(number, msg) {
window.onblur = function () {
let i = number || 3;
i--;
if (i == 0) {
let res = msg || '切换次数超过限制';
alert(res);
}
};
return window.onblur;
}
15 changes: 15 additions & 0 deletions lib/yd_phone_Masking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 手机号脱敏
* @param {Function} 手机号脱敏的函数
* @param {number} 手机号
* @author Nil <https://github.com/Nil-nil-zero>
* @return {String}
* @summary 应用场景:用于数据安全合规,个人隐私保护
*/
export function phone_Masking(number) {
if (!/^\d{11,}$/.test(number)) {
return '手机号码必须是11位数字';
}
const result = number.substring(0, 3) + '****' + number.substring(7);
return result;
}

0 comments on commit eed9cea

Please sign in to comment.