http.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. SY
  3. } from "./index.js"
  4. import {
  5. MY
  6. } from "./my.js"
  7. const HTTP = {
  8. SY: SY, //首页的接口
  9. MY: MY, //我的,接口
  10. jsonf: (json) => { //处理json字符串
  11. if (json) {
  12. return encodeURIComponent(JSON.stringify(json))
  13. } else {
  14. return json
  15. }
  16. },
  17. jsonp: (json) => { //恢复处理后的json字符串
  18. if (json) {
  19. return JSON.parse(decodeURIComponent(json))
  20. } else {
  21. return json
  22. }
  23. },
  24. name: (str) => { //处理姓名
  25. if (str.length <= 4) {
  26. // 根据长度不同进行不同的替换
  27. switch (str.length) {
  28. case 2:
  29. return str[0] + "*";
  30. case 3:
  31. return str[0] + "*" + str[2];
  32. case 4:
  33. return str.slice(0, 2) + "**";
  34. default:
  35. return str;
  36. }
  37. } else {
  38. // 长度超过4个,替换中间的字符
  39. return str[0] + "**" + str[str.length - 1];
  40. }
  41. },
  42. jfs: () => { //统一处理名称,方便后续改动
  43. return "积分"
  44. },
  45. uns: (e) => { //接口提示
  46. uni.showToast({
  47. duration: 2000,
  48. icon: "none",
  49. title: e
  50. })
  51. },
  52. tm1: (e) => { //时间戳转字符串时间
  53. // 创建一个 Date 对象
  54. const date = new Date(e);
  55. // 获取年份、月份和日期
  56. const year = date.getFullYear();
  57. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以要加1
  58. const day = String(date.getDate()).padStart(2, '0');
  59. // 返回格式化后的日期字符串
  60. return `${year}-${month}-${day}`;
  61. },
  62. tm2:e=>{//秒级时间搓
  63. // 将秒级时间戳转换成毫秒级时间戳
  64. const milliseconds = e * 1000;
  65. // 创建一个 Date 对象
  66. const date = new Date(milliseconds);
  67. // 获取年份、月份和日期
  68. const year = date.getFullYear();
  69. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以要加1
  70. const day = String(date.getDate()).padStart(2, '0');
  71. // 返回格式化后的日期字符串
  72. return `${year}-${month}-${day}`;
  73. }
  74. }
  75. export {
  76. HTTP
  77. }