config.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. search: true,
  7. advancedSearch: false,
  8. pagination: false,
  9. extend: {
  10. "index_url": "wechat/config/index",
  11. "add_url": "wechat/config/add",
  12. "edit_url": "wechat/config/edit",
  13. "del_url": "wechat/config/del",
  14. "multi_url": "wechat/config/multi",
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {field: 'state', checkbox: true, },
  25. {field: 'id', title: 'ID'},
  26. {field: 'name', title: __('Name')},
  27. {field: 'value', title: __('Value')},
  28. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  29. ]
  30. ]
  31. });
  32. // 为表格绑定事件
  33. Table.api.bindevent(table);//当内容渲染完成后
  34. },
  35. add: function () {
  36. Controller.api.bindevent();
  37. },
  38. edit: function () {
  39. Controller.api.bindevent();
  40. },
  41. api: {
  42. bindevent: function () {
  43. Form.api.bindevent($("form[role=form]"));
  44. $(document).on('click', ".btn-insertlink", function () {
  45. var textarea = $("textarea[name='row[value]']");
  46. var cursorPos = textarea.prop('selectionStart');
  47. var v = textarea.val();
  48. var textBefore = v.substring(0, cursorPos);
  49. var textAfter = v.substring(cursorPos, v.length);
  50. Layer.prompt({title: '请输入显示的文字', formType: 3}, function (text, index) {
  51. Layer.close(index);
  52. Layer.prompt({title: '请输入跳转的链接URL(包含http)', formType: 3}, function (link, index) {
  53. text = text == '' ? link : text;
  54. textarea.val(textBefore + '<a href="' + link + '">' + text + '</a>' + textAfter);
  55. Layer.close(index);
  56. });
  57. });
  58. });
  59. $("input[name='row[type]']:checked").trigger("click");
  60. }
  61. }
  62. };
  63. return Controller;
  64. });