moderinze js

Current JavaScript [standards](https://medium.com/@codingsam/awesome-javascript-no-more-var-working-title-999428999994) encourage us to use of let and const instead.
This commit is contained in:
ShalokShalom 2022-02-19 21:35:15 +01:00 committed by GitHub
parent 5b0fca8468
commit 8507d6d3c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 20 deletions

View File

@ -1,9 +1,9 @@
// 包装ajax请求 // 包装ajax请求
function callVtoy(p1, p2, p3) { function callVtoy(p1, p2, p3) {
var url = '/vtoy/json'; const url = '/vtoy/json';
var data = {}; const data = {};
var func = function(data) {}; const func = function(data) {};
if (typeof(p1) === 'string') { if (typeof(p1) === 'string') {
url = p1; url = p1;
@ -134,16 +134,16 @@ function callVtoySync(data, func) {
data: JSON.stringify(data), data: JSON.stringify(data),
success: function VtoyCallFuncWrapper(data) { success: function VtoyCallFuncWrapper(data) {
if (data.result === 'tokenerror') { if (data.result === 'tokenerror') {
var titlestr = '<span class="fa fa-minus-circle" style="color:#dd4b39; font-weight:bold;"> ' + vtoy_cur_language.STR_ERROR + '</span>'; const titlestr = '<span class="fa fa-minus-circle" style="color:#dd4b39; font-weight:bold;"> ' + vtoy_cur_language.STR_ERROR + '</span>';
var msgstr = '<span style="font-size:14px; font-weight:bold;"> ' + vtoy_cur_language.STR_WEB_TOKEN_MISMATCH + '</span>'; const msgstr = '<span style="font-size:14px; font-weight:bold;"> ' + vtoy_cur_language.STR_WEB_TOKEN_MISMATCH + '</span>';
Modal.alert({title:titlestr, msg:msgstr, btnok:vtoy_cur_language.STR_BTN_OK }).on(function(e) { Modal.alert({title:titlestr, msg:msgstr, btnok:vtoy_cur_language.STR_BTN_OK }).on(function(e) {
window.location.reload(true); window.location.reload(true);
}); });
} }
else if (data.result === 'busy') { else if (data.result === 'busy') {
var titlestr = '<span class="fa fa-check-circle" style="color:green; font-weight:bold;"> ' + vtoy_cur_language.STR_INFO + '</span>'; const titlestr = '<span class="fa fa-check-circle" style="color:green; font-weight:bold;"> ' + vtoy_cur_language.STR_INFO + '</span>';
var msgstr = '<span style="font-size:14px; font-weight:bold;"> ' + vtoy_cur_language.STR_WEB_SERVICE_BUSY + '</span>'; const msgstr = '<span style="font-size:14px; font-weight:bold;"> ' + vtoy_cur_language.STR_WEB_SERVICE_BUSY + '</span>';
Modal.alert({title:titlestr, msg:msgstr, btnok:vtoy_cur_language.STR_BTN_OK }); Modal.alert({title:titlestr, msg:msgstr, btnok:vtoy_cur_language.STR_BTN_OK });
}else { }else {
func(data); func(data);
@ -193,7 +193,7 @@ function callVtoySync(data, func) {
}); });
} }
var vtoy = { const vtoy = {
baseurl : '', baseurl : '',
status: '', status: '',
scan: { scan: {
@ -213,23 +213,23 @@ String.prototype.endsWith = function(str) {
} }
window.Message = function() { window.Message = function() {
var _showMsg = function(type, msg, time) { const _showMsg = function(type, msg, time) {
var o = {type : type, msg : msg }; const o = {type : type, msg : msg };
if(time) { if(time) {
o.time = time; o.time = time;
} }
_show(o); _show(o);
} }
var _show = function(options) { const _show = function(options) {
var ops = { const ops = {
msg : "提示内容", msg : "提示内容",
type: 'S', type: 'S',
time: 3000 time: 3000
}; };
$.extend(ops, options); $.extend(ops, options);
var msg_class = 'alert-success'; const msg_class = 'alert-success';
if('S' === ops.type || 's' === ops.type) { if('S' === ops.type || 's' === ops.type) {
msg_class = 'alert-success'; msg_class = 'alert-success';
} else if ('E' === ops.type || 'e' === ops.type) { } else if ('E' === ops.type || 'e' === ops.type) {
@ -242,29 +242,29 @@ window.Message = function() {
alert("未知的类型,请使用: w-警告;s-成功;e-失败;i-提示"); alert("未知的类型,请使用: w-警告;s-成功;e-失败;i-提示");
return; return;
} }
var $messageContainer = $("#fcss_message"); const $messageContainer = $("#fcss_message");
if($messageContainer.length === 0) { if($messageContainer.length === 0) {
$messageContainer = $('<div id="fcss_message" style="position:fixed; left: 20%; right: 20%; top:0px; z-index:99999999"></div>'); $messageContainer = $('<div id="fcss_message" style="position:fixed; left: 20%; right: 20%; top:0px; z-index:99999999"></div>');
$messageContainer.appendTo($('body')); $messageContainer.appendTo($('body'));
} }
var $div = $('<div class="alert ' + msg_class + ' alert-dismissible fade in" role="alert" style="margin-bottom: 0; padding-top:10px; padding-bottom: 10px;"></div>'); const $div = $('<div class="alert ' + msg_class + ' alert-dismissible fade in" role="alert" style="margin-bottom: 0; padding-top:10px; padding-bottom: 10px;"></div>');
var $btn = $('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'); const $btn = $('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>');
$div.append($btn).append(ops.msg).appendTo($messageContainer); $div.append($btn).append(ops.msg).appendTo($messageContainer);
setTimeout(function() { setTimeout(function() {
$div.remove(); $div.remove();
}, ops.time); }, ops.time);
} }
var _success = function(msg, time) { const _success = function(msg, time) {
_showMsg('s', msg, time); _showMsg('s', msg, time);
} }
var _error = function(msg, time) { const _error = function(msg, time) {
_showMsg('e', msg, time || 5000); _showMsg('e', msg, time || 5000);
} }
var _warn = function(msg, time) { const _warn = function(msg, time) {
_showMsg('w', msg, time); _showMsg('w', msg, time);
} }
var _info = function(msg, time) { const _info = function(msg, time) {
_showMsg('i', msg, time); _showMsg('i', msg, time);
} }