bootstrap.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. use App\Admin\Extensions\Form\WangEditor;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Grid;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid\Filter;
  7. use Dcat\Admin\Show;
  8. /**
  9. * Dcat-admin - admin builder based on Laravel.
  10. * @author jqh <https://github.com/jqhph>
  11. *
  12. * Bootstraper for Admin.
  13. *
  14. * Here you can remove builtin form field:
  15. *
  16. * extend custom field:
  17. * Dcat\Admin\Form::extend('php', PHPEditor::class);
  18. * Dcat\Admin\Grid\Column::extend('php', PHPEditor::class);
  19. * Dcat\Admin\Grid\Filter::extend('php', PHPEditor::class);
  20. *
  21. * Or require js and css assets:
  22. * Admin::css('/packages/prettydocs/css/styles.css');
  23. * Admin::js('/packages/prettydocs/js/main.js');
  24. *
  25. */
  26. // 注册前端组件别名
  27. // 注册前端组件别名
  28. //Admin::asset()->alias('@ckeditor', [
  29. // 'js' => [
  30. //// '/vendor/ckeditor_4.20.0/ckeditor.js',
  31. //// '/vendor/ckeditor_4.20.0/adapters/jquery.js',
  32. // '/vendor/ckeditor5/ckeditor.js',
  33. // '/vendor/ckeditor5/translations/zh-cn.js',
  34. // ],
  35. //]);
  36. //Form::extend('ckeditor', \App\Admin\Extensions\Form\CKEditor::class);
  37. Form\Field\Editor::resolving(function (Form\Field\Editor $editor) {
  38. $editor->options([
  39. 'file_picker_types' => 'media',
  40. 'file_picker_callback' => \Dcat\Admin\Support\JavaScript::make(<<<JS
  41. function file_picker_callback (callback, value, meta) {
  42. // 设置上传地址为原富文本框图片文件上传地址
  43. var upurl = opts.images_upload_url;
  44. var filetype = '';
  45. // 处理媒体类型文件能选择的文件类型
  46. if (meta.filetype == 'media') {
  47. filetype = '.mp4,.webm,.ogg'
  48. }
  49. //模拟出一个input用于添加本地文件
  50. var input = document.createElement('input');
  51. input.setAttribute('type', 'file');
  52. input.setAttribute('accept', filetype);
  53. // 模拟点击file input
  54. input.click();
  55. input.onchange = function() {
  56. // 文件选择后进行上传
  57. var file = this.files[0];
  58. var xhr, formData;
  59. console.log(file.name);
  60. Dcat.loading()
  61. xhr = new XMLHttpRequest();
  62. xhr.withCredentials = false;
  63. xhr.open('POST', upurl);
  64. xhr.onload = function() {
  65. var json;
  66. if (xhr.status != 200) {
  67. failure('HTTP Error: ' + xhr.status);
  68. return;
  69. }
  70. json = JSON.parse(xhr.responseText);
  71. if (!json || typeof json.location != 'string') {
  72. failure('Invalid JSON: ' + xhr.responseText);
  73. return;
  74. }
  75. json.location = json.location.replace('http://','https://')
  76. json.location = json.location.replace('-internal','')
  77. Dcat.loading(false)
  78. callback(json.location);
  79. };
  80. formData = new FormData();
  81. formData.append('file', file, file.name );
  82. xhr.send(formData);
  83. }
  84. }
  85. JS)
  86. ]);
  87. });