config.js 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: 'wechat/config/index',
  8. add_url: 'wechat/config/add',
  9. edit_url: 'wechat/config/edit',
  10. del_url: 'wechat/config/del',
  11. multi_url: 'wechat/config/multi',
  12. table: 'wechat_config',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {field: 'state', checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'name', title: __('Name')},
  26. {field: 'title', title: __('Title')},
  27. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  28. {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime},
  29. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  30. ]
  31. ]
  32. });
  33. // 为表格绑定事件
  34. Table.api.bindevent(table);
  35. },
  36. add: function () {
  37. Controller.api.bindevent();
  38. },
  39. edit: function () {
  40. Controller.api.bindevent();
  41. },
  42. api: {
  43. bindevent: function () {
  44. Form.api.bindevent($("form[role=form]"));
  45. $(document).on('click', ".btn-jsoneditor", function () {
  46. $("#c-value").toggle();
  47. $(".fieldlist").toggleClass("hide");
  48. $(".btn-insertlink").toggle();
  49. $("input[name='row[mode]']").val($("#c-value").is(":visible") ? "textarea" : "json");
  50. });
  51. $(document).on('click', ".btn-insertlink", function () {
  52. var textarea = $("textarea[name='row[value]']");
  53. var cursorPos = textarea.prop('selectionStart');
  54. var v = textarea.val();
  55. var textBefore = v.substring(0, cursorPos);
  56. var textAfter = v.substring(cursorPos, v.length);
  57. Layer.prompt({title: '请输入显示的文字', formType: 3}, function (text, index) {
  58. Layer.close(index);
  59. Layer.prompt({title: '请输入跳转的链接URL(包含http)', formType: 3}, function (link, index) {
  60. text = text == '' ? link : text;
  61. textarea.val(textBefore + '<a href="' + link + '">' + text + '</a>' + textAfter);
  62. Layer.close(index);
  63. });
  64. });
  65. });
  66. $("input[name='row[type]']:checked").trigger("click");
  67. $(document).on("click", ".fieldlist .append", function () {
  68. var rel = parseInt($(this).closest("dl").attr("rel")) + 1;
  69. $(this).closest("dl").attr("rel", rel);
  70. $('<dd><input type="text" name="field[' + rel + ']" class="form-control" id="field-' + rel + '" value="" size="10" /> <input type="text" name="value[' + rel + ']" class="form-control" id="value-' + rel + '" value="" size="40" /> <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span> <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span></dd>').insertBefore($(this).parent());
  71. });
  72. $(document).on("click", ".fieldlist dd .btn-remove", function () {
  73. $(this).parent().remove();
  74. });
  75. //拖拽排序
  76. require(['dragsort'], function () {
  77. //绑定拖动排序
  78. $("dl.fieldlist").dragsort({
  79. itemSelector: 'dd',
  80. dragSelector: ".btn-dragsort",
  81. dragEnd: function () {
  82. },
  83. placeHolderTemplate: "<dd></dd>"
  84. });
  85. });
  86. }
  87. }
  88. };
  89. return Controller;
  90. });