dynamic.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'dynamic/dynamic/index' + location.search,
  8. // add_url: 'dynamic/dynamic/add',
  9. edit_url: 'dynamic/dynamic/edit',
  10. del_url: 'dynamic/dynamic/del',
  11. multi_url: 'dynamic/dynamic/multi',
  12. // import_url: 'dynamic/dynamic/import',
  13. table: 'dynamic',
  14. }
  15. });
  16. var table = $("#table");
  17. //修改 data-value="0" 和 name="status"
  18. table.on('post-common-search.bs.table', function (event, table) {
  19. $('ul.nav-tabs li a[data-value="0"]').trigger('click');
  20. $('select[name="status"]').val('0');
  21. $(".btn-success").trigger('click');
  22. });
  23. // 初始化表格
  24. table.bootstrapTable({
  25. url: $.fn.bootstrapTable.defaults.extend.index_url,
  26. pk: 'id',
  27. sortName: 'id',
  28. columns: [
  29. [
  30. {checkbox: true},
  31. {field: 'id', title: __('Id')},
  32. {field: 'user.u_id', title: __('User.u_id')},
  33. {field: 'user.nickname', title: __('User.nickname')},
  34. {
  35. field: 'content', title: __('Content'), operate: 'LIKE',
  36. formatter: function (value, row, index, field) {
  37. return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.content + "'>" + value + "</span>";
  38. },
  39. cellStyle: function (value, row, index, field) {
  40. return {
  41. css: {
  42. "white-space": "nowrap",
  43. "text-overflow": "ellipsis",
  44. "overflow": "hidden",
  45. "max-width": "250px"
  46. }
  47. };
  48. }
  49. },
  50. {field: 'res_type', title: __('Res_type'), searchList: {"1":__('Res_type 1'),"2":__('Res_type 2'),"3":__('Res_type 3')}, formatter: Table.api.formatter.normal},
  51. {
  52. field: 'image', title: __('Image'), operate: false, events: Table.api.events.image,
  53. formatter: function (value, row, index) {
  54. if (row.res_type == 1) {
  55. value = value === null ? '' : value.toString();
  56. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  57. var arr = value.split(',');
  58. var html = [];
  59. $.each(arr, function (i, value) {
  60. value = value ? value : '/assets/img/blank.gif';
  61. html.push('<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>');
  62. });
  63. return html.join(' ');
  64. } else if (row.res_type == 2) {
  65. 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>";
  66. } else if (row.res_type == 3) {
  67. return "<audio src='" + value + "' style='width:250px;height:30px;' controls='controls'>Your browser does not support the audio element.</audio>";
  68. }
  69. }
  70. },
  71. // {field: 'image_thumb', title: __('Image_thumb'), operate: 'LIKE'},
  72. {
  73. field: 'commit',
  74. title: __('Commit'),
  75. operate: false,
  76. formatter: Controller.api.formatter.commitsearch
  77. },
  78. {field: 'likes', title: __('Likes'), operate: false},
  79. {field: 'is_online', title: __('Is_online'), searchList: {"-1":__('Is_online -1'),"1":__('Is_online 1')}, formatter: Table.api.formatter.normal},
  80. {field: 'is_recommend', title: __('Is_recommend'), searchList: {"0":__('Is_recommend 0'),"1":__('Is_recommend 1')}, formatter: Table.api.formatter.normal},
  81. {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
  82. // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  83. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  84. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  85. ]
  86. ]
  87. });
  88. // 为表格绑定事件
  89. Table.api.bindevent(table);
  90. // 更多操作
  91. $(document).on("click", ".nav-tabs li", function () {
  92. datavalue = $(this).find('a').data('value');
  93. if(datavalue === 0){
  94. $(".dropdown").show();
  95. }else{
  96. $(".dropdown").hide();
  97. }
  98. });
  99. },
  100. add: function () {
  101. Controller.api.bindevent();
  102. },
  103. edit: function () {
  104. Controller.api.bindevent();
  105. },
  106. api: {
  107. bindevent: function () {
  108. Form.api.bindevent($("form[role=form]"));
  109. },
  110. formatter: {
  111. commitsearch: function (value, row, index) {
  112. //这里手动构造URL
  113. url = "dynamic/commit?dynamic_id=" + row.id;
  114. //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容
  115. //return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">' + __('Search %s', value) + '</a>';
  116. //方式二,直接调用Table.api.formatter.addtabs
  117. this.url = url;
  118. this.atitle = '动态评论列表';
  119. return Table.api.formatter.dialog.call(this, value, row, index);
  120. }
  121. }
  122. }
  123. };
  124. return Controller;
  125. });