43 行
1.5 KiB
JavaScript
43 行
1.5 KiB
JavaScript
define(['jquery'], function ($) {
|
||
|
||
var Format = {
|
||
/**
|
||
* 列表序号(跨分页连续)
|
||
*/
|
||
serial: function (value, row, index) {
|
||
var table = this.table ? $(this.table) : null;
|
||
var pageSize = 0;
|
||
var pageNumber = 1;
|
||
if (table && table.length && table.data('bootstrap.table')) {
|
||
var options = table.bootstrapTable('getOptions') || {};
|
||
pageSize = parseInt(options.pageSize, 10) || 0;
|
||
pageNumber = parseInt(options.pageNumber, 10) || 1;
|
||
}
|
||
return pageSize > 0 ? (pageNumber - 1) * pageSize + index + 1 : index + 1;
|
||
},
|
||
/**
|
||
* 状态徽标
|
||
*/
|
||
status: function (text, tone) {
|
||
if (text === null || typeof text === 'undefined' || text === '') {
|
||
text = '-';
|
||
}
|
||
return '<span class="fc-status fc-status-' + (tone || 'default') + '">' + text + '</span>';
|
||
},
|
||
/**
|
||
* 生成状态字段的 formatter
|
||
* @param map 值 => 文案
|
||
* @param tones 值 => 颜色(success/warning/danger/info/default)
|
||
*/
|
||
statusFormatter: function (map, tones) {
|
||
tones = tones || {};
|
||
return function (value) {
|
||
var text = map[value] !== undefined ? map[value] : '-';
|
||
return Format.status(text, tones[value] || 'default');
|
||
};
|
||
}
|
||
};
|
||
|
||
return Format;
|
||
});
|