Ajax.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use think\Lang;
  5. use think\Response;
  6. /**
  7. * Ajax异步请求接口
  8. * @internal
  9. */
  10. class Ajax extends Frontend
  11. {
  12. protected $noNeedLogin = ['lang', 'upload'];
  13. protected $noNeedRight = ['*'];
  14. protected $layout = '';
  15. /**
  16. * 加载语言包
  17. */
  18. public function lang()
  19. {
  20. $header = ['Content-Type' => 'application/javascript'];
  21. if (!config('app_debug')) {
  22. $offset = 30 * 60 * 60 * 24; // 缓存一个月
  23. $header['Cache-Control'] = 'public';
  24. $header['Pragma'] = 'cache';
  25. $header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
  26. }
  27. $controllername = input("controllername");
  28. $this->loadlang($controllername);
  29. //强制输出JSON Object
  30. return jsonp(Lang::get(), 200, $header, ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
  31. }
  32. /**
  33. * 生成后缀图标
  34. */
  35. public function icon()
  36. {
  37. $suffix = $this->request->request("suffix");
  38. $suffix = $suffix ? $suffix : "FILE";
  39. $data = build_suffix_image($suffix);
  40. $header = ['Content-Type' => 'image/svg+xml'];
  41. $offset = 30 * 60 * 60 * 24; // 缓存一个月
  42. $header['Cache-Control'] = 'public';
  43. $header['Pragma'] = 'cache';
  44. $header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
  45. $response = Response::create($data, '', 200, $header);
  46. return $response;
  47. }
  48. /**
  49. * 上传文件
  50. */
  51. public function upload()
  52. {
  53. return action('api/common/upload');
  54. }
  55. }