123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
- var Controller = {
- index: function () {
-
- Table.api.init({
- extend: {
- index_url: 'example/bootstraptable/index',
- add_url: '',
- edit_url: 'example/bootstraptable/edit',
- del_url: 'example/bootstraptable/del',
- multi_url: '',
- }
- });
- var table = $("#table");
-
- table.on('common-search.bs.table', function (event, table, query) {
-
- console.log(query);
- });
-
- table.on('post-common-search.bs.table', function (event, table) {
- var form = $("form", table.$commonsearch);
- $("input[name='title']", form).addClass("selectpage").data("source", "auth/adminlog/selectpage").data("primaryKey", "title").data("field", "title").data("orderBy", "id desc");
- $("input[name='username']", form).addClass("selectpage").data("source", "auth/admin/index").data("primaryKey", "username").data("field", "username").data("orderBy", "id desc");
- Form.events.cxselect(form);
- Form.events.selectpage(form);
- });
-
- table.on('post-body.bs.table', function (e, settings, json, xhr) {
- console.log(e, settings, json, xhr);
- });
-
- table.on('load-success.bs.table', function (e, data) {
-
- console.log(data);
-
- $("#money").text(data.extend.money);
- $("#price").text(data.extend.price);
- });
-
-
-
- table.bootstrapTable({
-
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- columns: [
- [
-
-
- {field: 'state', checkbox: true,},
-
- {field: 'id', title: 'ID', sortable: true, operate: false},
-
- {field: 'username', title: __('管理员'), formatter: Table.api.formatter.search},
-
- {field: 'title', title: __('Title'), operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符', width: '280px'},
-
- {
- field: 'url',
- title: __('Url'),
- align: 'left',
- searchList: $.getJSON('example/bootstraptable/searchlist?search=a&field=row[user_id]'),
- formatter: Controller.api.formatter.url,
- addClass: "selectpicker"
- },
-
- {
- field: 'ip',
- title: __('IP'),
- events: Controller.api.events.ip,
- formatter: Controller.api.formatter.ip
- },
-
- {field: 'custom', title: __('切换'), operate: false, formatter: Controller.api.formatter.custom},
-
-
- {
- field: 'browser',
- title: __('Browser'),
- operate: false,
- events: Controller.api.events.browser,
- formatter: Controller.api.formatter.browser
- },
- {
- field: 'admin_id', title: __('联动搜索'), searchList: function (column) {
- return Template('categorytpl', {});
- }, formatter: function (value, row, index) {
- return '无';
- }, visible: false
- },
-
- {
- field: 'createtime',
- title: __('Update time'),
- sortable: true,
- formatter: Table.api.formatter.datetime,
- operate: 'RANGE',
- addclass: 'datetimerange'
- },
-
- {
- field: 'operate',
- width: "150px",
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- buttons: [
- {
- name: 'click',
- title: __('点击执行事件'),
- classname: 'btn btn-xs btn-info btn-click',
- icon: 'fa fa-leaf',
-
- click: function (data) {
- Layer.alert("点击按钮执行的事件");
- }
- },
- {
- name: 'detail',
- title: __('弹出窗口打开'),
- classname: 'btn btn-xs btn-primary btn-dialog',
- icon: 'fa fa-list',
- url: 'example/bootstraptable/detail',
- callback: function (data) {
- Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
- }
- },
- {
- name: 'ajax',
- title: __('发送Ajax'),
- classname: 'btn btn-xs btn-success btn-magic btn-ajax',
- icon: 'fa fa-magic',
- confirm: '确认发送Ajax请求?',
- url: 'example/bootstraptable/detail',
- success: function (data, ret) {
- Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
-
-
- },
- error: function (data, ret) {
- console.log(data, ret);
- Layer.alert(ret.msg);
- return false;
- }
- },
- {
- name: 'addtabs',
- title: __('新选项卡中打开'),
- classname: 'btn btn-xs btn-warning btn-addtabs',
- icon: 'fa fa-folder-o',
- url: 'example/bootstraptable/detail'
- }
- ],
- formatter: Table.api.formatter.operate
- },
- ],
- ],
-
-
-
- search: true,
-
- commonSearch: true,
-
- showExport: true,
-
- maintainSelected: true,
-
- fixedColumns: true,
-
- fixedRightNumber: 1,
-
- exportDataType: "all",
-
- exportTypes: ['json', 'xml', 'csv', 'txt', 'doc', 'excel'],
-
- searchFormVisible: true,
- queryParams: function (params) {
-
- var filter = JSON.parse(params.filter);
- var op = JSON.parse(params.op);
-
- filter.admin_id = 1;
- op.admin_id = "=";
- params.filter = JSON.stringify(filter);
- params.op = JSON.stringify(op);
- return params;
- },
- });
-
- Table.api.bindevent(table);
-
- $(document).on('change', 'select[name=admin]', function () {
- $("input[name='admin_id']").val($(this).val());
- });
-
- $(document).on("click", ".btn-singlesearch", function () {
- var options = table.bootstrapTable('getOptions');
- var queryParams = options.queryParams;
- options.pageNumber = 1;
- options.queryParams = function (params) {
-
- params = queryParams(params);
-
- var filter = params.filter ? JSON.parse(params.filter) : {};
- var op = params.op ? JSON.parse(params.op) : {};
- filter.url = 'login';
- op.url = 'like';
- params.filter = JSON.stringify(filter);
- params.op = JSON.stringify(op);
-
-
-
- return params;
- };
- table.bootstrapTable('refresh', {});
- Toastr.info("当前执行的是自定义搜索,搜索URL中包含login的数据");
- return false;
- });
-
- $(document).on("click", ".btn-selected", function () {
- Layer.alert(JSON.stringify(Table.api.selecteddata(table)));
- });
-
- $(document).on("click", ".btn-start,.btn-pause", function () {
-
-
-
- var ids = Table.api.selectedids(table);
- Table.api.multi("changestatus", ids.join(","), table, this);
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- detail: function () {
- $(document).on('click', '.btn-callback', function () {
- Fast.api.close($("input[name=callback]").val());
- });
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- formatter: {
- url: function (value, row, index) {
- return '<div class="input-group input-group-sm" style="width:250px;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
- },
- ip: function (value, row, index) {
- return '<a class="btn btn-xs btn-ip bg-success"><i class="fa fa-map-marker"></i> ' + value + '</a>';
- },
- browser: function (value, row, index) {
-
- return '<a class="btn btn-xs btn-browser">' + row.useragent.split(" ")[0] + '</a>';
- },
- custom: function (value, row, index) {
-
- return '<a class="btn-change text-success" data-url="example/bootstraptable/change" data-confirm="确认切换状态?" data-id="' + row.id + '"><i class="fa ' + (row.title == '' ? 'fa-toggle-on fa-flip-horizontal text-gray' : 'fa-toggle-on') + ' fa-2x"></i></a>';
- },
- },
- events: {
- ip: {
-
- 'click .btn-ip': function (e, value, row, index) {
- e.stopPropagation();
- var container = $("#table").data("bootstrap.table").$container;
- var options = $("#table").bootstrapTable('getOptions');
-
- $("form.form-commonsearch [name='ip']", container).val(value);
- $("form.form-commonsearch", container).trigger('submit');
- Toastr.info("执行了自定义搜索操作");
- }
- },
- browser: {
- 'click .btn-browser': function (e, value, row, index) {
- e.stopPropagation();
- Layer.alert("该行数据为: <code>" + JSON.stringify(row) + "</code>");
- }
- },
- }
- }
- };
- return Controller;
- });
|