v1.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace zin;
  3. class searchToggle extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'target?: string',
  10. 'open?: bool',
  11. 'module?: string',
  12. 'url?: string',
  13. 'searchUrl?: string',
  14. 'text?: string',
  15. 'onSearch?: callback', // jsRaw("(result) => console.log('onSearchForm', result)")
  16. 'searchLoader?: string|array',
  17. 'simple?: boolean' // 是否为简单模式,不包含保存搜索条件和已保存的查询条件侧边栏。
  18. );
  19. public static function getPageCSS()
  20. {
  21. return <<<'CSS'
  22. .nav-item + li > .search-form-toggle {margin-left: 0.5rem}
  23. .search-form-toggle.active,
  24. .show-search-form #featureBar .search-form-toggle {--skin-text: var(--color-primary-500); --skin-ring: var(--color-primary-500)}
  25. CSS;
  26. }
  27. protected function checkErrors()
  28. {
  29. if($this->hasProp('formName')) trigger_error('[ZIN] The property "formName" is not supported in the "searchToggle()"', E_USER_WARNING);
  30. }
  31. protected function build()
  32. {
  33. if(!common::hasPriv('search', 'buildForm')) return;
  34. global $lang, $app, $config;
  35. list($target, $module, $open, $url, $searchUrl, $text, $simple, $onSearch, $searchLoader) = $this->prop(array('target', 'module', 'open', 'url', 'searchUrl', 'text', 'simple', 'onSearch', 'searchLoader'));
  36. if(is_null($open))
  37. {
  38. $browseType = !empty($_GET['browseType']) ? $_GET['browseType'] : data('browseType');
  39. $open = $browseType ? strtolower($browseType) == 'bysearch' : false;
  40. }
  41. if(is_null($module)) $module = $app->rawModule;
  42. if(empty($text)) $text = $lang->searchAB;
  43. if(isset($config->zin->mode) && $config->zin->mode == 'compatible')
  44. {
  45. if(is_null($url)) $url = createLink('search', 'buildZinForm', 'module=' . $module);
  46. if(is_null($searchUrl)) $searchUrl = createLink('search', 'buildZinQuery');
  47. }
  48. $searchFormOptions = array('module' => $module, 'target' => $target, 'url' => $url);
  49. if(!empty($searchUrl)) $searchFormOptions['searchUrl'] = $searchUrl;
  50. if(!empty($simple)) $searchFormOptions['simple'] = $simple;
  51. if(!empty($onSearch)) $searchFormOptions['onSearch'] = $onSearch;
  52. if(!empty($searchLoader)) $searchFormOptions['searchLoader'] = $searchLoader;
  53. return btn
  54. (
  55. set::className('search-form-toggle rounded-full gray-300-outline size-sm'),
  56. set::icon('search'),
  57. set::active($open),
  58. set::text($text),
  59. toggle::searchform($searchFormOptions),
  60. $open ? on::init()->call('zui.toggleSearchForm', array_merge(array('show' => $open), $searchFormOptions)) : on::init()->do('$element.closest(".show-search-form").removeClass("show-search-form").find(".search-form[data-module=' . $module . ']").remove()')
  61. );
  62. }
  63. }