123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'dynamic/dynamic/index' + location.search,
- // add_url: 'dynamic/dynamic/add',
- edit_url: 'dynamic/dynamic/edit',
- del_url: 'dynamic/dynamic/del',
- multi_url: 'dynamic/dynamic/multi',
- // import_url: 'dynamic/dynamic/import',
- table: 'dynamic',
- }
- });
- var table = $("#table");
- //修改 data-value="0" 和 name="status"
- table.on('post-common-search.bs.table', function (event, table) {
- $('ul.nav-tabs li a[data-value="0"]').trigger('click');
- $('select[name="status"]').val('0');
- $(".btn-success").trigger('click');
- });
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'user.u_id', title: __('User.u_id')},
- {field: 'user.nickname', title: __('User.nickname')},
- {
- field: 'content', title: __('Content'), operate: 'LIKE',
- formatter: function (value, row, index, field) {
- return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.content + "'>" + value + "</span>";
- },
- cellStyle: function (value, row, index, field) {
- return {
- css: {
- "white-space": "nowrap",
- "text-overflow": "ellipsis",
- "overflow": "hidden",
- "max-width": "250px"
- }
- };
- }
- },
- {field: 'res_type', title: __('Res_type'), searchList: {"1":__('Res_type 1'),"2":__('Res_type 2'),"3":__('Res_type 3')}, formatter: Table.api.formatter.normal},
- {
- field: 'image', title: __('Image'), operate: false, events: Table.api.events.image,
- formatter: function (value, row, index) {
- if (row.res_type == 1) {
- value = value === null ? '' : value.toString();
- var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
- var arr = value.split(',');
- var html = [];
- $.each(arr, function (i, value) {
- value = value ? value : '/assets/img/blank.gif';
- html.push('<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>');
- });
- return html.join(' ');
- } else if (row.res_type == 2) {
- return "<a href='" + value + "' data-url='" + value + "' target=\"_blank\" class=\"thumbnail\"><img src=\"/lcFzdPIjLH.php/ajax/icon?suffix=mp4\" onerror=\"this.src='/lcFzdPIjLH.php/ajax/icon?suffix=mp4';this.onerror=null;\" class=\"img-responsive\" style=\"width: 30px;height: 30px;\"></a>";
- } else if (row.res_type == 3) {
- return "<audio src='" + value + "' style='width:250px;height:30px;' controls='controls'>Your browser does not support the audio element.</audio>";
- }
- }
- },
- // {field: 'image_thumb', title: __('Image_thumb'), operate: 'LIKE'},
- {
- field: 'commit',
- title: __('Commit'),
- operate: false,
- formatter: Controller.api.formatter.commitsearch
- },
- {field: 'likes', title: __('Likes'), operate: false},
- {field: 'is_online', title: __('Is_online'), searchList: {"-1":__('Is_online -1'),"1":__('Is_online 1')}, formatter: Table.api.formatter.normal},
- {field: 'is_recommend', title: __('Is_recommend'), searchList: {"0":__('Is_recommend 0'),"1":__('Is_recommend 1')}, formatter: Table.api.formatter.normal},
- {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
- // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // 更多操作
- $(document).on("click", ".nav-tabs li", function () {
- datavalue = $(this).find('a').data('value');
- if(datavalue === 0){
- $(".dropdown").show();
- }else{
- $(".dropdown").hide();
- }
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- formatter: {
- commitsearch: function (value, row, index) {
- //这里手动构造URL
- url = "dynamic/commit?dynamic_id=" + row.id;
- //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
- //return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">' + __('Search %s', value) + '</a>';
- //方式二,直接调用Table.api.formatter.addtabs
- this.url = url;
- this.atitle = '动态评论列表';
- return Table.api.formatter.dialog.call(this, value, row, index);
- }
- }
- }
- };
- return Controller;
- });
|