v1.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace zin;
  3. requireWg('thinkModel');
  4. class think3c extends thinkModel
  5. {
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array
  10. (
  11. 'key?: string="view"',
  12. 'disabled?=false: bool',
  13. );
  14. public static function getPageCSS()
  15. {
  16. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  17. }
  18. public static function getPageJS()
  19. {
  20. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  21. }
  22. protected function buildAreaCard()
  23. {
  24. global $app;
  25. $blocks = $this->prop('blocks');
  26. $area = array();
  27. foreach($blocks as $block)
  28. {
  29. if(!empty($block->steps)) $area[] = $this->buildResultCard($block->steps, $block->id + 1, true);
  30. }
  31. return $area;
  32. }
  33. protected function buildBody()
  34. {
  35. global $lang, $app;
  36. $app->loadLang('thinkrun');
  37. list($blocks, $mode, $disabled, $key) = $this->prop(array('blocks', 'mode', 'disabled', 'key'));
  38. jsVar('blockName', $lang->thinkwizard->placeholder->blockName);
  39. jsVar('model3cKey', $key);
  40. jsVar('loadGraphTip', $lang->thinkrun->tips->loadGraph);
  41. return div
  42. (
  43. setData(array('clientLang' => $app->getClientLang(), 'model' => '3c', 'mode' => $mode, 'blocks' => $blocks, 'disabled' => $disabled)),
  44. setClass('model-canvas relative', "model-canvas-$key", $mode == 'view' ? '' : 'flex justify-center'),
  45. h::canvas(setID('canvas_' . $key)),
  46. on::blur('.model-canvas input')
  47. ->const('blockName', $lang->thinkwizard->block)
  48. ->const('blocksData', $blocks)
  49. ->const('repeatTips', $lang->thinkwizard->error->blockRepeat)
  50. ->do(
  51. 'const $tatget = $(this);',
  52. 'const index = $tatget.data("index");',
  53. 'const block = $tatget.data("block");',
  54. 'const value = $tatget.val() || block;',
  55. 'const $blockTitle = $(`.block-title-${index}`);',
  56. 'const currentValue = blocksData[index];',
  57. 'const values = [];',
  58. 'const inputs = $(`input[name="blocks[]"]`);',
  59. 'inputs.each((index, ele) => {values.push($(ele).val());});',
  60. 'if(value != currentValue && new Set(values).size != values.length)
  61. {
  62. return zui.Modal.alert({message: repeatTips, icon: "icon-exclamation-sign", iconClass: "warning-pale rounded-full icon-2x"}).then(() => {
  63. $tatget.val(currentValue);
  64. $tatget.attr("title", currentValue);
  65. if($blockTitle.length)
  66. {
  67. $blockTitle.text(currentValue);
  68. $blockTitle.closest(".block-title").attr("title", currentValue + blockName);
  69. }
  70. });
  71. }',
  72. '$tatget.attr("title", value);',
  73. '$tatget.val(value);',
  74. 'if($blockTitle.length) {$blockTitle.text(value); $blockTitle.closest(".block-title").attr("title", value + blockName);}'
  75. ),
  76. $mode == 'view' ? $this->buildAreaCard() : null
  77. );
  78. }
  79. protected function build()
  80. {
  81. $mode = $this->prop('mode');
  82. $style = $mode == 'preview' ? setStyle(array('min-height' => '254px')) : setStyle(array('min-height' => '254px', 'width' => '2400px'));
  83. return div
  84. (
  85. setClass('model-3c my-1 flex col flex-wrap justify-between'),
  86. $style,
  87. $this->buildBody(),
  88. on::init()->call('initThinkCanvas')
  89. );
  90. }
  91. }