table_layouts.blade.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. @extends('admin.layouts')
  2. @section('css')
  3. <link href="/assets/global/vendor/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
  4. <link href="/assets/global/vendor/bootstrap-select/bootstrap-select.min.css" rel="stylesheet">
  5. <style>
  6. #swal2-content {
  7. display: grid !important;
  8. }
  9. .table a {
  10. text-decoration: none;
  11. }
  12. .table .th-inner a {
  13. color: #76838f;
  14. }
  15. </style>
  16. @stack('css')
  17. @endsection
  18. @section('javascript')
  19. <script src="/assets/global/vendor/bootstrap-table/bootstrap-table.min.js"></script>
  20. <script src="/assets/global/vendor/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
  21. <script src="/assets/global/vendor/bootstrap-select/bootstrap-select.min.js"></script>
  22. <script src="/assets/global/js/Plugin/bootstrap-select.js"></script>
  23. <script>
  24. $(document).ready(function() {
  25. populateFormFromQueryParams();
  26. });
  27. $("form:not(.modal-body form)").on("submit", function() {
  28. $(this).find("input:not([type=\"submit\"]), select").filter(function() {
  29. return this.value === "";
  30. }).prop("disabled", true);
  31. setTimeout(function() {
  32. $(this).find(":disabled").prop("disabled", false);
  33. }, 0);
  34. });
  35. $("select").not(".modal-body select").on("change", function() {
  36. $(this).closest("form").trigger("submit");
  37. });
  38. // 使用事件委托处理所有删除按钮点击
  39. document.addEventListener('click', function(e) {
  40. // 检查被点击的元素是否是删除按钮或包含在删除按钮内
  41. const deleteButton = e.target.closest('[data-action="delete"]');
  42. if (deleteButton) {
  43. e.preventDefault();
  44. // 查找包含 data-delete-config 的最近父元素
  45. const container = deleteButton.closest('[data-delete-config]');
  46. if (!container) {
  47. console.error('Delete button must be inside an element with data-delete-config attribute');
  48. return;
  49. }
  50. try {
  51. // 解析配置(处理HTML转义字符)
  52. const configStr = container.getAttribute('data-delete-config');
  53. const config = JSON.parse(configStr);
  54. // 获取 ID 和名称(优先使用手动指定的值,否则从表格中自动获取)
  55. const id = deleteButton.getAttribute('data-id') || getCellValue(deleteButton, config.idColumn || 0);
  56. const name = deleteButton.getAttribute('data-name') || getCellValue(deleteButton, config.nameColumn || 1);
  57. const attribute = deleteButton.getAttribute('data-attribute') || config.attribute;
  58. // 验证必要参数
  59. if (!id || !name) {
  60. console.error('No ID/name found for delete action');
  61. return;
  62. }
  63. // 构建 URL 并执行删除
  64. const url = config.url.replace('PLACEHOLDER', id);
  65. confirmDelete(url, name, attribute, config.options || {});
  66. } catch (error) {
  67. console.error('Error processing delete action:', error);
  68. }
  69. }
  70. });
  71. // 获取表格单元格值的辅助函数
  72. function getCellValue(button, columnIndex) {
  73. const row = button.closest('tr');
  74. if (!row) return null;
  75. const cells = row.querySelectorAll('td');
  76. if (cells.length <= columnIndex) return null;
  77. const cell = cells[columnIndex];
  78. // 首先检查单元格内是否有输入元素
  79. const input = cell.querySelector('input, select, textarea');
  80. return input ? input.value.trim() : cell.textContent.trim();
  81. }
  82. </script>
  83. @stack('javascript')
  84. @endsection