123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'vbot/template/index' + location.search,
- add_url: 'vbot/template/add',
- edit_url: 'vbot/template/edit',
- del_url: 'vbot/template/del',
- multi_url: 'vbot/template/multi',
- table: 'vbot_template',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name'), operate: 'LIKE'},
- {field: 'code', title: __('Code')},
- {
- field: 'robot_names',
- title: __('Robot_ids'),
- formatter: Controller.api.formatter.robot_names,
- operate: false
- },
- {
- field: 'typelist',
- title: __('Typelist'),
- searchList: {
- "text": __('Typelist text'),
- "markdown": __('Typelist markdown'),
- "image": __('Typelist image'),
- "news": __('Typelist news')
- },
- formatter: Table.api.formatter.normal
- },
- {
- field: 'content',
- title: __('Content'),
- placeholder: '模糊查找',
- operate: 'LIKE',
- formatter: Controller.api.formatter.content_names
- },
- {field: 'title', title: __('Title'), placeholder: '模糊查找', operate: 'LIKE'},
- {field: 'at_mobiles', title: __('At_mobiles'), operate: 'LIKE', placeholder: '模糊查找'},
- {
- field: 'is_atall',
- title: __('Is_atall'),
- searchList: {"0": __('Is_atall 0'), "1": __('Is_atall 1')},
- formatter: Table.api.formatter.normal
- },
- {
- field: 'openswitch',
- title: __('Openswitch'),
- searchList: {"0": __('Openswitch 0'), "1": __('Openswitch 1')},
- formatter: Table.api.formatter.toggle
- },
- {
- field: 'updatetime',
- title: __('Updatetime'),
- operate: 'RANGE',
- addclass: 'datetimerange',
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'createtime',
- title: __('Createtime'),
- operate: 'RANGE',
- addclass: 'datetimerange',
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
- buttons: [
- {
- name: 'test_msg',
- title: __('发送通知消息'),
- classname: 'btn btn-xs btn-success btn-magic btn-ajax',
- icon: 'fa fa-send-o',
- url: 'vbot/template/msg_test',
- confirm: '确认发送?',
- success: function (data, ret) {
- Fast.api.msg(ret.msg);
- },
- error: function (data, ret) {
- Fast.api.msg(ret.msg);
- return false;
- }
- }
- ],
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- recyclebin: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- 'dragsort_url': ''
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: 'vbot/template/recyclebin' + location.search,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {
- field: 'content',
- title: __('Content'),
- placeholder: '模糊查找',
- formatter: Controller.api.formatter.content_names
- },
- {
- field: 'deletetime',
- title: __('Deletetime'),
- operate: 'RANGE',
- addclass: 'datetimerange',
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'operate',
- width: '130px',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- buttons: [
- {
- name: 'Restore',
- text: __('Restore'),
- classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
- icon: 'fa fa-rotate-left',
- url: 'vbot/template/restore',
- refresh: true
- },
- {
- name: 'Destroy',
- text: __('Destroy'),
- classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
- icon: 'fa fa-times',
- url: 'vbot/template/destroy',
- refresh: true
- }
- ],
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function (e) {
- Form.api.bindevent($("form[role=form]"));
- function need_show(value) {
- $('.msg_group').hide();
- if (value == 'text') {
- $('.msg_content,.msg_at').show(200);
- } else if (value == 'markdown') {
- $('.msg_title,.msg_content,.markdown_help').show(200);
- } else if (value == 'image') {
- $('.msg_picurl_image').show(200);
- } else if (value == 'news') {
- $('.msg_content,.msg_news').show(200);
- }
- }
- need_show($('#c-typelist')[0].value);
- // 切换消息类型时,显示不同的输入框
- $('#c-typelist').on('change', function () {
- need_show(this.value);
- })
- $('#show_grammar').on('click', function () {
- $('.markdown_grammar').show(200);
- $('.markdown_help').hide();
- })
- },
- formatter: {
- robot_names: function (value, row) {
- var value = value.split(',');
- var btn_html = '';
- for (let i in value) {
- btn_html += ' <a href="javascript:;" title="' + value[i] + '" class="btn btn-xs btn-info robot_names">' + value[i] + '</a> ';
- }
- return btn_html;
- },
- content_names: function (value, row) {
- if (value.length > 30) {
- return value.substring(0, 30) + '...';
- }
- return value;
- }
- }
- }
- };
- return Controller;
- });
|