refactor: 增加 saftHtml 方法判断

#Comment
仅对字符串类型数据进行安全转换
This commit is contained in:
Argo Zhang 2019-07-12 12:35:59 +08:00
parent ee07113dfc
commit d025bc3221
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 19 additions and 6 deletions

View File

@ -209,7 +209,7 @@
crossDomain: true crossDomain: true
}); });
if ($.isArray($.logData) && !$.isEmptyObject(options.data)) $.logData.push({ url: url, data: options.method === 'delete' ? options.logData : options.data }); if ($.isArray($.logData) && !$.isEmptyObject(options.data)) $.logData.push({ url: url, data: options.method === 'delete' ? options.logData : options.data });
if (options.method === 'delete') $.logData.log(); if (options.method === 'delete' && $.logData && $.isFunction($.logData.log)) $.logData.log();
$.ajax(ajaxSettings); $.ajax(ajaxSettings);
}, },
lgbSwal: function (options) { lgbSwal: function (options) {
@ -235,7 +235,7 @@
return base + url; return base + url;
}, },
safeHtml: function (text) { safeHtml: function (text) {
return $('<div>').text(text).html(); return (text && typeof text === "string") ? $('<div>').text(text).html() : text;
}, },
syntaxHighlight: function (json) { syntaxHighlight: function (json) {
if (typeof (json) === 'string') { if (typeof (json) === 'string') {
@ -412,8 +412,21 @@
return this; return this;
}, },
getTextByValue: function (value) { getTextByValue: function (value) {
var text = this.children().filter(function () { return $(this).val() === value; }).text(); // 通过value获取select控件的text属性
var text = "";
if (this.attr('data-toggle') === 'lgbSelect') {
if (value === this.val()) text = this.attr('data-text');
else {
var data = [];
this.lgbSelect('get', function (source) { data = source; });
var find = data.filter(function () { return this.value === value; });
if (find.length === 1) text = find[0].text;
}
}
else {
text = this.children().filter(function () { return $(this).val() === value; }).text();
if (text === "") text = value; if (text === "") text = value;
}
return text; return text;
}, },
lgbInfo: function (option) { lgbInfo: function (option) {
@ -472,7 +485,7 @@
}); });
$(function () { $(function () {
// fix bug bootstrap-table 1.12.1 showToggle // fix bug bootstrap-table 1.14.2 showToggle
if ($.fn.bootstrapTable) { if ($.fn.bootstrapTable) {
$.extend($.fn.bootstrapTable.defaults.icons, { $.extend($.fn.bootstrapTable.defaults.icons, {
refresh: 'fa-refresh' refresh: 'fa-refresh'
@ -521,7 +534,7 @@
$("#gotoTop").on('click', function (e) { $("#gotoTop").on('click', function (e) {
e.preventDefault(); e.preventDefault();
$('html, body, .main-content').animate({ $('html, body, body > section:first').animate({
scrollTop: 0 scrollTop: 0
}, 200); }, 200);
}); });