|
@@ -17,7 +17,7 @@ function IwbAjax(opt) {
|
|
|
if (opt.data === undefined) {
|
|
|
opt.data = {}
|
|
|
}
|
|
|
- opt = $.extend({}, { isAlert: true, }, opt)
|
|
|
+ opt = $.extend({}, {isAlert: true,}, opt)
|
|
|
fetch(opt.url, {
|
|
|
method: opt.method,
|
|
|
headers: opt.headers || {
|
|
@@ -74,6 +74,7 @@ function IwbTable(table, opts, isReload) {
|
|
|
rows: new Set(),
|
|
|
checkBoxWidth: 40,
|
|
|
checkBoxDisable: undefined,
|
|
|
+ canEdit: undefined,
|
|
|
pageSize: 15,
|
|
|
pageNum: 1,
|
|
|
search: {
|
|
@@ -92,7 +93,7 @@ function IwbTable(table, opts, isReload) {
|
|
|
}
|
|
|
$table.data('options', opt)
|
|
|
loading()
|
|
|
- const data = $.extend({}, opt.search, { pageNum: opt.pageNum, pageSize: opt.pageSize })
|
|
|
+ const data = $.extend({}, opt.search, {pageNum: opt.pageNum, pageSize: opt.pageSize})
|
|
|
fetch(opt.url, {
|
|
|
method: 'POST',
|
|
|
headers: {
|
|
@@ -153,42 +154,44 @@ function IwbTable(table, opts, isReload) {
|
|
|
}
|
|
|
if (rows && rows.length) {
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
- const row = rows[i]
|
|
|
- body_str += `<tr data-id="${row[opt.idFiled]}">`
|
|
|
+ const row = rows[i], canEdit = opt.canEdit && opt.canEdit(row)
|
|
|
+ let trStr = "", trClassStr = ""
|
|
|
if (opt.checkBox) {
|
|
|
const disabled_checkbox = opt.checkBoxDisable && opt.checkBoxDisable(row) ? 'disabled' : ''
|
|
|
if (opt.selected_ids.size && opt.selected_ids.has(row[opt.idFiled] + "")) {
|
|
|
if (disabled_checkbox === '') {
|
|
|
- body_str += `<td style="${opt.checkBoxWidth ? `width: ${opt.checkBoxWidth}px;` : ``}">${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `checked`)}</td>`
|
|
|
+ trStr += `<td style="${opt.checkBoxWidth ? `width: ${opt.checkBoxWidth}px;` : ``}">${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `checked`)}</td>`
|
|
|
} else {
|
|
|
- body_str += `<td style="${opt.checkBoxWidth ? `width: ${opt.checkBoxWidth}px;` : ``}">${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `${disabled_checkbox}`)}</td>`
|
|
|
+ trStr += `<td style="${opt.checkBoxWidth ? `width: ${opt.checkBoxWidth}px;` : ``}">${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `${disabled_checkbox}`)}</td>`
|
|
|
}
|
|
|
} else {
|
|
|
check_all = false
|
|
|
- body_str += `<td style="${opt.checkBoxWidth ? `width: ${opt.checkBoxWidth}px;` : ``}">${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `${disabled_checkbox}`)}</td>`
|
|
|
+ trStr += `<td style="${opt.checkBoxWidth ? `width: ${opt.checkBoxWidth}px;` : ``}">${checkBoxDiv.format(row[opt.idFiled], `${opt.tableCheckboxName}`, `${disabled_checkbox}`)}</td>`
|
|
|
}
|
|
|
}
|
|
|
for (let j = 0; j < opt.columns.length; j++) {
|
|
|
const col = opt.columns[j],
|
|
|
+ isEdit = col.isEdit && canEdit,
|
|
|
style = `${col.tdStyle ? `${col.tdStyle};` : ``}`,
|
|
|
- classStr = `${col.isEdit ? 'edit-td' : ''}`,
|
|
|
+ classStr = `${isEdit ? 'edit-td' : ''}`,
|
|
|
col_data = row[col.data] === undefined || row[col.data] === null ? '-' : row[col.data]
|
|
|
- body_str += `<td class="${classStr}" style="${style}" data-key="${col.data}" data-val="${col_data}">`
|
|
|
- let str = ''
|
|
|
+ trStr += `<td class="${classStr}" style="${style}" data-key="${col.data}" data-val="${col_data}" >`
|
|
|
+ let tdStr = ''
|
|
|
if (col.render) {
|
|
|
- str += col.render(row, rows)
|
|
|
+ tdStr += col.render(row, rows)
|
|
|
} else {
|
|
|
- str += col_data
|
|
|
+ tdStr += col_data
|
|
|
}
|
|
|
- if (col.isEdit) {
|
|
|
- body_str += col.render ? str : `<span class="edit-label"><span class="edit-text">${str}</span></span>`
|
|
|
- body_str += `<div class="edit-td-input"><input class="form-control form-control-sm" data-col="" value="${col_data}"/></div>`
|
|
|
+ if (isEdit) {
|
|
|
+ trStr += col.render ? tdStr : `<span class="edit-label"><span class="edit-text">${tdStr}</span></span>`
|
|
|
+ trStr += `<div class="edit-td-input"><input class="form-control form-control-sm" data-col="" value="${col_data}"/></div>`
|
|
|
} else {
|
|
|
- body_str += str
|
|
|
+ trStr += tdStr
|
|
|
}
|
|
|
- body_str += `</td>`
|
|
|
+ trStr += `</td>`
|
|
|
}
|
|
|
- body_str += '</tr>'
|
|
|
+ trClassStr = opt.trClass && typeof opt.trClass === 'function' ? opt.trClass(row) : typeof opt.trClass === 'string' ? opt.trClass : opt.trClass || ""
|
|
|
+ body_str += `<tr class="${trClassStr}" data-id="${row[opt.idFiled]}">${trStr}</tr>`
|
|
|
}
|
|
|
} else {
|
|
|
body_str += '<tr><td colspan="' + opt.columns.length + '" class="text-center">暂无数据</td></tr>'
|
|
@@ -314,9 +317,9 @@ function IwbTable(table, opts, isReload) {
|
|
|
|
|
|
str += `<div class="dt-info"><strong> 共 ${total} 条</strong>,当前第 ${pageNum}/${totalPages} 页,每页</div>`
|
|
|
str += `<div><select class="form-select form-select-solid form-select-sm" onchange="IwbTableChangePageSize(this)">`
|
|
|
- ;[15, 25, 50, 100].forEach((size) => {
|
|
|
- str += `<option value="${size}" ${pageSize === size ? ' selected' : ''}>${size}</option>`
|
|
|
- })
|
|
|
+ ;[15, 25, 50, 100].forEach((size) => {
|
|
|
+ str += `<option value="${size}" ${pageSize === size ? ' selected' : ''}>${size}</option>`
|
|
|
+ })
|
|
|
str += '</select>条</div>'
|
|
|
str += '</div>'
|
|
|
|
|
@@ -376,7 +379,7 @@ function IwbTable(table, opts, isReload) {
|
|
|
const $table = $(table), opt = $table.data('options'), tableEl = $table[0], rows = tableEl.rows,
|
|
|
header = rows[0],
|
|
|
col_length = header.cells.length, col_start = opt.checkBox ? 1 : 0;
|
|
|
- let self = { mouseDown: false }, tableX = header.clientWidth;
|
|
|
+ let self = {mouseDown: false}, tableX = header.clientWidth;
|
|
|
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
for (let j = col_start; j < col_length; j++) {
|
|
@@ -446,7 +449,7 @@ function IwbTableSearch(that) {
|
|
|
delete search[$(el).attr('name')]
|
|
|
}
|
|
|
})
|
|
|
- IwbTable($table, { search: search, pageNum: 1, selected_ids: new Set(), selected_rows: new Set() })
|
|
|
+ IwbTable($table, {search: search, pageNum: 1, selected_ids: new Set(), selected_rows: new Set()})
|
|
|
}
|
|
|
|
|
|
function IwbTableResetSearch(that) {
|
|
@@ -457,13 +460,13 @@ function IwbTableResetSearch(that) {
|
|
|
|
|
|
function IwbTableJumpPage(that, pageNum) {
|
|
|
const $table = $(that).closest('.table-box').find('.table')
|
|
|
- IwbTable($table, { pageNum: pageNum })
|
|
|
+ IwbTable($table, {pageNum: pageNum})
|
|
|
}
|
|
|
|
|
|
function IwbTableChangePageSize(that) {
|
|
|
const $table = $(that).closest('.table-box').find('.table')
|
|
|
const pageSize = parseInt($(that).val())
|
|
|
- IwbTable($table, { pageSize: pageSize })
|
|
|
+ IwbTable($table, {pageSize: pageSize})
|
|
|
}
|
|
|
|
|
|
function IwbTableGetSelectedIds(table) {
|