v1.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * The thumbnail widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2024 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Gang Liu <liugang@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. class thumbnail extends wg
  13. {
  14. /**
  15. * @var mixed[]
  16. */
  17. protected static $defineProps = array(
  18. 'name?: string="thumbnail"',
  19. 'src?: string',
  20. 'tips?: string',
  21. 'errorTips?: string',
  22. 'accept?: array=["jpg", "jpeg", "png", "gif"]'
  23. );
  24. public static function getPageJS()
  25. {
  26. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  27. }
  28. protected function created()
  29. {
  30. if(!$this->prop('errorTips')) $this->setProp('errorTips', 'Upload failed, please upload images in ' . implode(', ', $this->prop('accept')) . ' format.');
  31. }
  32. protected function build()
  33. {
  34. $name = $this->prop('name');
  35. $src = $this->prop('src');
  36. $tips = $this->prop('tips');
  37. $accept = $this->prop('accept');
  38. jsVar('acceptExtensions', $accept);
  39. jsVar('errorTips', $this->prop('errorTips'));
  40. return array
  41. (
  42. div
  43. (
  44. setClass('flex items-center justify-center cursor-pointer bg-white w-full h-60 '),
  45. setData(array('on' => 'click', 'call' => 'uploadThumbnail')),
  46. img
  47. (
  48. setID('thumbnail-img'),
  49. setClass('h-full' . ($src ? '' : ' hidden')),
  50. set::src($src),
  51. set::title($tips)
  52. ),
  53. $src ? null : span(setID('thumbnail-tips'), setClass('text-primary font-bold'), $tips)
  54. ),
  55. input
  56. (
  57. set::type('hidden'),
  58. set::name($name),
  59. set::value($src)
  60. ),
  61. input
  62. (
  63. setID('thumbnail-file'),
  64. setClass('hidden'),
  65. set::type('file'),
  66. set::name('files[]'),
  67. set::accept('.' . implode(',.', $accept)),
  68. setData(array('on' => 'change', 'call' => 'changeThumbnail'))
  69. )
  70. );
  71. }
  72. }