DiverseYouthNightSchool/public/assets/js/backend/famysql/table.js

119 lines
6.8 KiB
JavaScript
Raw Normal View History

2024-11-04 10:49:10 +08:00
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, selectPage) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'famysql/table/index',
add_url: Config.group ? 'famysql/table/table_add?group=' + Config.group : 'famysql/table/table_add',
},
showExport: false,//导出按钮导出整个表的所有行
showToggle: false,//切换卡片视图和表格视图
showColumns: false,//切换显示隐藏列
search: false,//关闭快速搜索
commonSearch: false,//关闭通用搜索
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{ field: 'id', title: __('Id') },
{ field: 'name', title: __('Name') },
{ field: 'engine', title: __('Engine'), width: '80px' },
{ field: 'charset', title: __('Charset'), width: '80px' },
{ field: 'collation', title: __('Collation'), width: '150px' },
{ field: 'comment', title: __('Comment') },
{ field: 'rows', title: __('Rows') },
{ field: 'createtime', title: __('Create time') },
{ field: 'updatetime', title: __('Update time') },
{
field: 'operate', title: __('Table Operate'), width: '400px', table: table, operate: false,
events: {
'click .btn-copy-1': function (e, value, row) {
Layer.prompt({
title: "请输入你需要新复制的数据表名",
success: function (layero) {
var name = row.name;
var name_arr = name.split("_");
if (row.is_has) {
name_arr.shift()
}
const str = name_arr.join('_');
$("input", layero).prop("placeholder", "例如test请不要加前缀").val(str);
}
}, function (value) {
Fast.api.ajax({
url: "famysql/table/copy?name=" + row.name + "&type=1",
data: { table: value },
}, function (data, ret) {
Layer.closeAll();
parent.location.reload();
return false;
});
});
},
'click .btn-copy-2': function (e, value, row) {
Layer.prompt({
title: "请输入你需要新复制的数据表名",
success: function (layero) {
var name = row.name;
var name_arr = name.split("_");
if (row.is_has) {
name_arr.shift()
}
const str = name_arr.join('_');
$("input", layero).prop("placeholder", "例如test请不要加前缀").val(str);
}
}, function (value) {
Fast.api.ajax({
url: "famysql/table/copy?name=" + row.name + "&type=2",
data: { table: value },
}, function (data, ret) {
Layer.closeAll();
parent.location.reload();
return false;
});
});
}
},
buttons: [
{
name: 'copy',
text: __('Copy 1'),
title: __('Copy 1'),
dropdown: __('Copy'),
classname: 'btn btn-xs btn-warning btn-copy-1',
icon: 'fa fa-copy',
},
{
name: 'copy-2',
text: __('Copy 2'),
title: function (row) {
return __('Copy 2') + "(" + row.rows + ")";
},
dropdown: __('Copy'),
classname: 'btn btn-xs btn-warning btn-copy-2',
icon: 'fa fa-copy',
},
{
name: 'truncate',
text: function (row) {
return __('Truncate') + "(" + row.rows + ")";
},
title: function (row) {
return __('Truncate') + "(" + row.rows + ")";
},
dropdown: __('More Table Operate'),
classname: 'btn btn-xs btn-danger btn-truncate',
icon: 'fa fa-minus-circle',
url: function (row) {
return Fast.api.fixurl("famysql/table/truncate?name=" + row.name);
},
classname: 'btn btn-xs btn-danger btn-ajax',