v1.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'sqlbuilderpicker' . DS . 'v1.php';
  4. require_once dirname(__DIR__) . DS . 'sqlbuilderinput' . DS . 'v1.php';
  5. require_once dirname(__DIR__) . DS . 'formrow' . DS . 'v1.php';
  6. require_once dirname(__DIR__) . DS . 'formgroup' . DS . 'v1.php';
  7. class sqlBuilderFuncRow extends wg
  8. {
  9. /**
  10. * @var mixed[]
  11. */
  12. protected static $defineProps = array(
  13. 'index?: int', // 索引。
  14. 'tables?: array', // 表名下拉数据。
  15. 'fields?: array', // 字段名下拉数据。
  16. 'value?: array', // 值。
  17. 'onChange?: function',
  18. 'onAdd?: function',
  19. 'onRemove?: function',
  20. 'tableError?:bool=false', // 表名选择是否存在错误。
  21. 'fieldError?:bool=false', // 字段名选择是否存在错误。
  22. 'functionError?:bool=false', // 函数名选择是否存在错误。
  23. 'aliasError?:bool=false', // 别名是否存在错误。
  24. 'duplicateError?:bool=false' // 别名是否存在重复。
  25. );
  26. protected function buildTable()
  27. {
  28. global $lang;
  29. list($index, $items, $value, $onChange, $error) = $this->prop(array('index', 'tables', 'value', 'onChange', 'tableError'));
  30. $value = $value['table'];
  31. return sqlBuilderPicker
  32. (
  33. set::name("table_$index"),
  34. set::label($lang->bi->do),
  35. set::items($items),
  36. set::value($value),
  37. set::placeholder($lang->bi->selectTableTip),
  38. set::width('48'),
  39. set::labelWidth('30px'),
  40. set::onChange($onChange),
  41. set::error($error)
  42. );
  43. }
  44. protected function buildField()
  45. {
  46. global $lang;
  47. list($index, $items, $value, $onChange, $error) = $this->prop(array('index', 'fields', 'value', 'onChange', 'fieldError'));
  48. $value = $value['field'];
  49. return sqlBuilderPicker
  50. (
  51. set::name("field_$index"),
  52. set::items($items),
  53. set::value($value),
  54. set::placeholder($lang->bi->selectFieldTip),
  55. set::width('40'),
  56. set::onChange($onChange),
  57. set::error($error)
  58. );
  59. }
  60. protected function buildFunction()
  61. {
  62. global $lang;
  63. list($index, $value, $onChange, $error) = $this->prop(array('index', 'value', 'onChange', 'functionError'));
  64. $value = $value['function'];
  65. return sqlBuilderPicker
  66. (
  67. set::name("function_$index"),
  68. set::label($lang->bi->set),
  69. set::items($lang->bi->funcList),
  70. set::value($value),
  71. set::placeholder($lang->bi->selectFuncTip),
  72. set::onChange($onChange),
  73. set::error($error)
  74. );
  75. }
  76. protected function buildAlias()
  77. {
  78. global $lang;
  79. list($index, $value, $onChange, $emptyError, $duplicateError) = $this->prop(array('index', 'value', 'onChange', 'aliasError', 'duplicateError'));
  80. $value = $value['alias'];
  81. $errorText = $duplicateError ? $lang->bi->duplicateError : null;
  82. return sqlBuilderInput
  83. (
  84. set::name("alias_$index"),
  85. set::label($lang->bi->funcAs),
  86. set::value($value),
  87. set::placeholder($lang->bi->selectInputTip),
  88. set::width('80'),
  89. set::labelWidth('160px'),
  90. set::onChange($onChange),
  91. set::error($emptyError || $duplicateError),
  92. set::errorText($errorText)
  93. );
  94. }
  95. protected function build()
  96. {
  97. list($index, $onAdd, $onRemove) = $this->prop(array('index', 'onAdd', 'onRemove'));
  98. return formRow
  99. (
  100. setClass('mb-4'),
  101. $this->buildTable(),
  102. $this->buildField(),
  103. $this->buildFunction(),
  104. $this->buildAlias(),
  105. formGroup
  106. (
  107. btn
  108. (
  109. setClass('add-function'),
  110. set('data-index', $index),
  111. set::type('ghost'),
  112. set::icon('plus'),
  113. on::click()->do($onAdd)
  114. ),
  115. btn
  116. (
  117. setClass('remove-function'),
  118. set('data-index', $index),
  119. set::type('ghost'),
  120. set::icon('minus'),
  121. on::click()->do($onRemove)
  122. )
  123. )
  124. );
  125. }
  126. }