Emoji.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace common\widgets\emoji;
  3. use Yii;
  4. use yii\base\Widget;
  5. use common\widgets\emoji\assets\AppAsset;
  6. /**
  7. * 表情选择器
  8. *
  9. * Class Emoji
  10. * @package common\widgets\emoji
  11. * @author jianyan74 <751393839@qq.com>
  12. */
  13. class Emoji extends Widget
  14. {
  15. /**
  16. * 主题
  17. *
  18. * default 和 wechat 二种类型
  19. *
  20. * @var string
  21. */
  22. public $theme = 'default';
  23. /**
  24. * @var string
  25. */
  26. public $name = 'emoji';
  27. /**
  28. * @var array
  29. */
  30. public $options = [];
  31. /**
  32. * 绑定文本域
  33. *
  34. * @var string
  35. */
  36. public $bind_id = '';
  37. /**
  38. * @return string
  39. */
  40. public function run()
  41. {
  42. $baseUrl = $this->registerClientScript();
  43. return $this->render('emoji', [
  44. 'name' => $this->name,
  45. 'theme' => $this->theme,
  46. 'options' => $this->options,
  47. 'baseUrl' => $baseUrl,
  48. 'bind_id' => $this->bind_id,
  49. ]);
  50. }
  51. /**
  52. * 注册资源
  53. */
  54. protected function registerClientScript()
  55. {
  56. $view = $this->getView();
  57. AppAsset::register($view);
  58. return Yii::$app->view->assetBundles[AppAsset::class]->baseUrl . '/';
  59. }
  60. }
粤ICP备19079148号