chart.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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: 'customcharts/chart/index' + location.search,
  8. add_url: 'customcharts/chart/add',
  9. edit_url: 'customcharts/chart/edit',
  10. del_url: 'customcharts/chart/del',
  11. table: 'customcharts_chart',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. pk: 'id',
  19. sortName: 'weigh',
  20. columns: [
  21. [
  22. {checkbox: true},
  23. {field: 'id', title: __('Id')},
  24. {field: 'title', title: __('Title')},
  25. {field: 'subtext', title: __('Subtext')},
  26. {field: 'chart_type', title: __('Chart_type'), searchList: {"pie":__('Pie'),"graph":__('Graph'),"histogram":__('Histogram')}, formatter: Table.api.formatter.normal},
  27. {field: 'name', title: __('Name')},
  28. {field: 'field_total', title: __('Field_total')},
  29. {field: 'type_total', title: __('Type_total'), searchList: {"sum":__('Sum'),"count":__('Count')}, formatter: Table.api.formatter.normal},
  30. {field: 'group_field', title: __('Group_field')},
  31. {field: 'field_time', title: __('Field_time')},
  32. {field: 'weigh', title: __('Weigh')},
  33. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  34. ]
  35. ]
  36. });
  37. // 为表格绑定事件
  38. Table.api.bindevent(table);
  39. },
  40. add: function () {
  41. Controller.api.bindevent();
  42. },
  43. edit: function () {
  44. Controller.api.bindevent();
  45. },
  46. api: {
  47. bindevent: function () {
  48. Form.api.bindevent($("form[role=form]"));
  49. //选择表和渲染字段
  50. var typelist = {};
  51. $(document).on('change', "select[name='row[name]']", function () {
  52. var that = this;
  53. Fast.api.ajax({
  54. url: "customcharts/totalnumber/get_field_list",
  55. data: {table: $(that).val()},
  56. }, function (data, ret) {
  57. let mainfields = data.fieldlist;
  58. let commentlist = data.commentlist;
  59. typelist = data.typelist;//字段类型
  60. Controller.api.renderselect("#c-field_total", mainfields, commentlist, typelist);//渲染数据
  61. Controller.api.renderselect("#c-group_field", mainfields, commentlist, typelist);//渲染数据
  62. Controller.api.renderselect("#c-field_time" , mainfields, commentlist, typelist);//渲染数据
  63. Controller.api.renderselect("#c-foreign_key", mainfields, commentlist, typelist);//渲染数据
  64. return false;
  65. });
  66. return false;
  67. });
  68. $("select[name='row[name]']").change();
  69. //选择时间字段
  70. $(document).on('change', "select[name='row[field_time]']", function () {
  71. $('input[name="row[field_time_type]"]').val(typelist[$(this).val()]);
  72. });
  73. //选择关联表
  74. $(document).on('change', "select[name='row[join_table]']", function () {
  75. var that = this;
  76. if($(that).val() !== '') {
  77. Fast.api.ajax({
  78. url: "customcharts/totalnumber/get_field_list",
  79. data: {table: $(that).val()},
  80. }, function (data, ret) {
  81. let mainfields = data.fieldlist;
  82. let commentlist = data.commentlist;
  83. typelist = data.typelist;//字段类型
  84. Controller.api.renderselect("#c-local_key", mainfields, commentlist, typelist);//渲染数据
  85. Controller.api.renderselect("#c-field_show", mainfields, commentlist, typelist);//渲染数据
  86. $('.join_table').show();
  87. $('.dictionary').hide();
  88. return false;
  89. });
  90. } else {
  91. $('.join_table').hide();
  92. $('.dictionary').show();
  93. }
  94. return false;
  95. });
  96. $("select[name='row[join_table]']").change();
  97. },
  98. renderselect: function(select, data, commentlist, typelist) {
  99. var val = $(select).data('value');
  100. var html = [];
  101. for (var i = 0; i < data.length; i++) {
  102. if ('#c-field_time' == select && typelist[data[i]] != 'int' && typelist[data[i]] != 'datetime' && typelist[data[i]] != 'date' && typelist[data[i]] != 'bigint') {
  103. continue;
  104. }
  105. if (val == data[i]) {
  106. html.push("<option data-subtext='" + commentlist[i] + "' value='" + data[i] + "' selected>" + data[i] + "</option>");
  107. } else {
  108. html.push("<option data-subtext='" + commentlist[i] + "' value='" + data[i] + "'>" + data[i] + "</option>");
  109. }
  110. }
  111. $(select).html(html.join(""));
  112. $(select).selectpicker('refresh');
  113. }
  114. }
  115. };
  116. return Controller;
  117. });