Icon.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 海豚PHP框架 [ DolphinPHP ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://dolphinphp.com
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\model;
  10. use think\Model;
  11. /**
  12. * 图标模型
  13. * @package app\admin\model
  14. */
  15. class Icon extends Model
  16. {
  17. // 设置当前模型对应的完整数据表名称
  18. protected $name = 'admin_icon';
  19. // 自动写入时间戳
  20. protected $autoWriteTimestamp = true;
  21. /**
  22. * 图标列表
  23. * @author 蔡伟明 <314013107@qq.com>
  24. * @return \think\model\relation\HasMany
  25. */
  26. public function icons()
  27. {
  28. return $this->hasMany('IconList', 'icon_id')->field('title,class,code');
  29. }
  30. /**
  31. * 获取图标css链接
  32. * @author 蔡伟明 <314013107@qq.com>
  33. * @return array|string|\think\Collection
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @throws \think\exception\DbException
  37. */
  38. public static function getUrls()
  39. {
  40. $list = self::where('status', 1)->select();
  41. if ($list) {
  42. foreach ($list as $key => $item) {
  43. if ($item['icons']) {
  44. $html = '<ul class="js-icon-list items-push-2x text-center">';
  45. foreach ($item['icons'] as $icon) {
  46. $html .= '<li title="'.$icon['title'].'"><i class="'.$icon['class'].'"></i> <code>'.$icon['code'].'</code></li>';
  47. }
  48. $html .= '</ul>';
  49. } else {
  50. $html = '<p class="text-center text-muted">暂无图标</p>';
  51. }
  52. $list[$key]['html'] = $html;
  53. }
  54. }
  55. return $list;
  56. }
  57. }