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', confirm: function (row) { return '是否确定清空该“' + row.name + '”数据表?'; }, success: function (data, ret) { $(".btn-refresh").trigger("click"); //刷新数据 }, visible: function (row) { return row.is_admin !== 0; }, error: function (data, ret) { Layer.alert(ret.msg); return false; } }, { name: 'optimize', text: __('Optimize'), title: __('Optimize'), dropdown: __('More Table Operate'), classname: 'btn btn-xs btn-danger btn-optimize', icon: 'fa fa-exclamation-triangle', url: function (row) { return Fast.api.fixurl("famysql/table/optimize?name=" + row.name); }, classname: 'btn btn-xs btn-danger btn-ajax', confirm: function (row) { return '是否确定优化该“' + row.name + '”数据表?'; }, success: function (data, ret) { $(".btn-refresh").trigger("click"); //刷新数据 }, visible: function (row) { return row.is_admin !== 0; }, error: function (data, ret) { Layer.alert(ret.msg); return false; } }, { name: 'repair', text: __('Repair'), title: __('Repair'), dropdown: __('More Table Operate'), classname: 'btn btn-xs btn-danger btn-repair', icon: 'fa fa-check-circle-o', url: function (row) { return Fast.api.fixurl("famysql/table/repair?name=" + row.name); }, classname: 'btn btn-xs btn-danger btn-ajax', confirm: function (row) { return '是否确定修复该“' + row.name + '”数据表?'; }, success: function (data, ret) { $(".btn-refresh").trigger("click"); //刷新数据 }, visible: function (row) { return row.is_admin !== 0; }, error: function (data, ret) { Layer.alert(ret.msg); return false; } }, { name: 'editone', icon: 'fa fa-pencil', text: __('Edit'), title: __('Edit'), dropdown: __('More Table Operate'), extend: 'data-toggle="tooltip"', url: function (row) { return Fast.api.fixurl("famysql/table/table_edit?name=" + row.name); }, visible: function (row) { return row.is_admin !== 0; }, classname: 'btn btn-xs btn-success btn-dialog' }, { name: 'delone', icon: 'fa fa-trash', text: __('Del'), title: __('Del'), dropdown: __('More Table Operate'), extend: 'data-toggle="tooltip"', url: function (row) { return Fast.api.fixurl("famysql/table/table_del?name=" + row.name); }, classname: 'btn btn-xs btn-danger btn-ajax', confirm: function (row) { return '是否确定删除该“' + row.name + '”数据表,不可恢复?'; }, success: function (data, ret) { if (ret.data == 0) { parent.location.reload(); } else { $(".btn-refresh").trigger("click"); //刷新数据 } }, visible: function (row) { return row.is_admin !== 0; }, error: function (data, ret) { Layer.alert(ret.msg); return false; } }, { name: 'crud', text: 'CRUD', title: function (row) { return "(表" + row.name + ")" + __('CRUD'); }, extend: 'data-area=\'["90%", "90%"]\'', dropdown: __('More Table Operate'), classname: 'btn btn-warning btn-xs btn-primary btn-dialog ', visible: function (row) { return row.group !== 'system'; }, url: function (row) { return Fast.api.fixurl('famysql/table/check?addon_name=' + row.group + '&table_name=' + row.name); }, icon: 'fa fa-terminal', }, { name: 'indexs', title: __('Index manager'), text: __('Index manager'), extend: 'data-area=\'["90%", "90%"]\'', url: function (row) { return Fast.api.fixurl("famysql/index/indexs?name=" + row.name + "&is_admin=" + row.is_admin); }, icon: 'fa fa-list-ol', classname: 'btn btn-xs btn-danger btn-dialog' }, { name: 'fields', title: function (row) { return "(" + row.name + ")" + __('Field manager'); }, text: function (row) { return __('Field manager') + "(" + row.field_nums + ")"; }, extend: 'data-area=\'["90%", "90%"]\'', url: function (row) { return Fast.api.fixurl("famysql/field/fields?name=" + row.name + "&is_admin=" + row.is_admin); }, icon: 'fa fa-table', classname: 'btn btn-success btn-xs btn-execute btn-dialog' }, ], formatter: Table.api.formatter.operate }, ] ], //启用固定列 fixedColumns: true, //固定右侧列数 fixedRightNumber: 1, queryParams: function (params) { if (Config.group) { params.group = Config.group; } return params; }, }); // 绑定TAB事件 $('.panel-heading a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var value = $(this).data("value"); var options = table.bootstrapTable('getOptions'); options.queryParams = function (params) { params.group = value; return params; }; return false; }); // 为表格绑定事件 Table.api.bindevent(table); }, backuplist: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'famysql/table/backuplist' } }); var table = $("#table"); table.on('load-success.bs.table', function (e, json) { if (json && typeof json.rows != 'undefined' && $(".nav-addon li").size() == 1) { var addons = []; $.each(json.rows, function (i, j) { if (addons.indexOf(j.addon) == -1 && j.addon != 'all') { $(".nav-addon").append("