Index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\SettingModel;
  5. use think\facade\View;
  6. use think\Request;
  7. class Index extends BaseController
  8. {
  9. function index(Request $request, $s = ''): string
  10. {
  11. $title = SettingModel::Config('title', 'Mtab书签');
  12. View::assign("title", $title);
  13. View::assign("keywords", SettingModel::Config('keywords', 'Mtab书签'));
  14. View::assign("description", SettingModel::Config('description', 'Mtab书签'));
  15. View::assign("version", app_version);
  16. $customHead = SettingModel::Config('customHead', '');
  17. if (SettingModel::Config('pwa', 0) == '1') {
  18. $customHead .= '<link rel="manifest" href="/manifest.json">';
  19. }
  20. View::assign("customHead", $customHead);
  21. View::assign("favicon", SettingModel::Config('logo', '/favicon.ico'));
  22. return View::fetch("dist/index.html");
  23. }
  24. function all()
  25. {
  26. $app = app();
  27. $ids = $this->request->post("ids", []);
  28. $dt = [];
  29. if (!in_array("link", $ids)) {
  30. $dt['link'] = (new Link($app))->get()->getData()['data'];
  31. }
  32. if (!in_array("tabbar", $ids)) {
  33. $dt['tabbar'] = (new Tabbar($app))->get()->getData()['data'];
  34. }
  35. if (!in_array("config", $ids)) {
  36. $dt['config'] = (new Config($app))->get()->getData()['data'];
  37. }
  38. $dt['site'] = (new Api($app))->site()->getData()['data'];
  39. return $this->success("ok", $dt);
  40. }
  41. function favicon()
  42. {
  43. //从配置中获取logo
  44. $favicon = $this->Setting('logo');
  45. $file = public_path() . $favicon;
  46. if (file_exists($file) && is_file($file)) {
  47. return download($file)->mimeType(\PluginStaticSystem::mimeType($file))->force(false)->expire(60 * 60 * 24);
  48. }
  49. return redirect("/static/mtab.png");
  50. }
  51. function manifest(): \think\response\Json
  52. {
  53. $manifest = [
  54. 'name' => SettingModel::Config('title', 'Mtab书签'),
  55. 'short_name' => SettingModel::Config('title', 'Mtab书签'),
  56. 'description' => SettingModel::Config('description', 'Mtab书签'),
  57. 'manifest_version' => 2,
  58. 'version' => app_version,
  59. 'theme_color' => SettingModel::Config('theme_color', '#141414'),
  60. 'icons' => [
  61. [
  62. 'src' => SettingModel::Config('logo', '/favicon.ico'),
  63. 'sizes' => '144x144'
  64. ]
  65. ],
  66. 'display' => 'standalone',
  67. 'orientation' => 'portrait',
  68. 'start_url' => '/',
  69. 'scope' => '/',
  70. 'permissions' => [
  71. 'geolocation',
  72. 'notifications'
  73. ]
  74. ];
  75. return json($manifest);
  76. }
  77. }