index.ts 888 B

123456789101112131415161718192021222324252627282930313233
  1. import { UploadController } from "@/controllers/UploadController";
  2. import { createRequest } from "@/utils/request";
  3. const token = localStorage.getItem("token");
  4. export const request = createRequest({
  5. baseURL: "https://www.infish.cn/adhuaxi/v1",
  6. interceptors: {
  7. request(req: any) {
  8. if (!req.headers) req.headers = {};
  9. req.headers["authorization"] = `Bearer ${token}`;
  10. return req;
  11. },
  12. // response: (res: any) => {},
  13. },
  14. });
  15. export const uploader = new UploadController(request);
  16. export const renderTitle = (title?: string) => {
  17. if (title) {
  18. if (title.length > 30) {
  19. return title.substring(0, 30) + "...";
  20. }
  21. return title;
  22. }
  23. return "";
  24. };
  25. export const renderSummary = (summary?: string) => {
  26. if (summary) {
  27. if (summary.length >= 60) {
  28. return summary.substring(0, 60) + "...";
  29. }
  30. return summary;
  31. }
  32. return "";
  33. };