123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'clipboard'], function ($, undefined, Backend, Table, Form, Clipboard) {
- var clipboard = new Clipboard('.btn-operate-copy', {
- target: function (trigger) {
- var stxt = $(trigger).parent().parent().find('.url_text i').data('clipboard-text');
- trigger = document.querySelector('#many_copy_dom');
- $('#many_copy_dom').html(stxt);
- return trigger;
- }
- });
- clipboard.on('success',function (data) {
- Toastr.success('复制成功');
- }).on('error',function (data) {
- Toastr.error('复制失败');
- });
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'special/page/index',
- add_url: 'special/page/add',
- edit_url: 'special/page/edit',
- del_url: 'special/page/del',
- multi_url: 'special/page/multi',
- table: 'special_page',
- }
- });
- var table = $("#table");
- if (Config.group == 3 || Config.group == 4) {
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'url', title: __('Url'), formatter: Controller.api.source_url, operate: false},
- {field: 'title', title: __('Title'), operate:'LIKE %...%'},
- {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'status_text', title: __('Status'), operate:false},
- {
- field: 'copy',
- title: __('Operate'),
- operate: false,
- formatter: function (value, row) {
- if (row['status'] == 'normal') {
- return '<a href="javascript:;" class="btn btn-click btn-operate-copy" title="复制" data-table-id="table" data-field-index="8" data-row-index="0" data-button-index="0">复制 <i class="fa fa-copy copy"></i></a>';
- } else {
- return '-';
- }
- }
- }
- ]
- ]
- });
- } else {
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'title', title: __('Title'), operate:'LIKE %...%'},
- {field: 'preview', title: __('预览'), operate:false, formatter: function(value){
- if (value.indexOf('http') != '-1') {
- return '<a href="'+value+'" target="_blank">'+value+'</a>'
- }
- return value;
- }},
- {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate:false, visible:false},
- {field: 'type', title: __('Type'), visible:false, searchList: {"type 1":__('Type 1'),"type 2":__('Type 2'),"type 3":__('Type 3'),"type 4":__('Type 4')}, operate:false},
- {field: 'type_text', title: __('Type'), operate:false, visible:false},
- {field: 'book_id', title: __('Book_id'), visible:false, operate:false},
- {field: 'color', title: __('Color'), operate:false, visible:false},
- {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, visible:false},
- {field: 'resourcelist', title: __('专题资源配置'),formatter: Controller.api.formatter.resourcelist, operate:false},
- {field: 'changestatus', title: __('显示状态'),addClass:'btn-start',formatter: Controller.api.formatter.changestatus, operate:false},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:Controller.api.formatter.showBtn()}
- ]
- ],
- 'onPostBody': function () {
- $(".btn-delone").hide();
- }
- });
- }
- // 为表格绑定事件
- Table.api.bindevent(table);
- //启动和暂停按钮
- $(document).on("click", ".btn-start", function () {
- //在table外不可以使用添加.btn-change的方法
- //只能自己调用Table.api.multi实现
- var id = $(this).data('id');
- var thisvalue = $(this).val();
- var status = "normal";
- if(thisvalue=='点击打开'){
- status = "normal";
- }else{
- status = "hidden";
- }
- var textval = thisvalue.substring(2,4);
- var reloadfrom = $(this).data('reload');
- layer.confirm('确定要'+textval+'吗?', {
- btn: ['确定','取消'] //按钮
- }, function(){
- $.post('/admin/special/page/multi',{ids:id,params:"status="+status},function(data){
- if(data.code == 1){
- layer.msg('操作成功');
- if (reloadfrom == 1) {
- window.location.reload();
- } else {
- table.bootstrapTable('refresh');
- }
- }else{
- layer.msg('操作失败');
- }
- });
- }, function(){
- layer.close();
- });
- });
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- $(function () {
- if ($('#c-type').val() != 3) {
- $(".bg-color").removeClass("hide");
- }
- });
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- $(document).on('click', "#select-resources", function () {
- var block_id = Config.block_id;
- parent.Backend.api.open($(this).attr("href") + "?action=blockresoure&block_id=" + block_id, __('Select'), {callback: refreshkey});
- return false;
- });
- var refreshkey = function (data) {
- Layer.closeAll();
- $('#c-book_id_text').val(data[0].id);
- $('#c-book_id').val(data[0].id);
- };
- $(document).on("change", "#c-type", function () {
- if ($("#c-type").val() == 3) {
- $(".bg-color").addClass("hide");
- //清空数据
- $("#c-color").val("");
- } else {
- $(".bg-color").removeClass("hide");
- }
- });
- },
- source_url: function (value, row, index) {
- var html = [];
- value = row.url;
- if (row.status == "normal") {
- html.push('<div class="link_txt"></div><div class="url_text">' + value + ' <i class="fa fa-copy copy" data-clipboard-text="' + value + '"></i>');
- } else {
- html.push('<div class="link_txt">该专题页已关闭不可使用</div>');
- }
- return html.join('<br>');
- },
- formatter: {
- showBtn: function(){
- return [
- {name: 'clear_cache', text: '清除缓存', title: '清除缓存', classname: 'btn btn-xs btn-danger btn-ajax', url: '/admin/special/page/rmcache', callback:function(data){}}
- ];
- },
- changestatus:function(value,row,index){
- var showName = '';
- if (row.status == 'hidden'){
- return '<b>隐藏</b> <input type="button" class="btn-start btn btn-success" data-id="'+row.id+'" value="点击打开" />';
- }else{
- return '<b>正常</b> <input type="button" class="btn-start btn btn-warning" data-id="'+row.id+'" value="点击隐藏" />';
- }
- },
- resourcelist: function (value, row, index) {
- //这里手动构造URL
- url = "special/block/index?page_id="+row.id;
- return '<a href="' + url + '" class="label label-success addtabsit" title="资源列表">资源列表</a>';
- }
- },
- }
- };
- return Controller;
- });
|