control.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Dict_Apis } from "@/dict/apis";
  2. import { reactive } from "vue";
  3. export class MapCountCtrl {
  4. _originData = { areas: [] as any[] };
  5. tabs = [
  6. {
  7. label: "浏览量(PV)",
  8. value: "pv" as const,
  9. },
  10. {
  11. label: "访客量(UV)",
  12. value: "uv" as const,
  13. },
  14. {
  15. label: "IP数",
  16. value: "ip" as const,
  17. },
  18. ];
  19. state = reactive({
  20. total: {
  21. uv: 0,
  22. pv: 0,
  23. ip: 0,
  24. } as Record<string, number>,
  25. currType: "pv",
  26. currMapData: [] as any[],
  27. });
  28. init(id: string) {
  29. fetch(`${Dict_Apis.promotion}/count/${id}`).then((res) => {
  30. res.json().then((ret) => {
  31. if (ret.errorNo === 200) {
  32. this._originData.areas = ret.result.areas || [];
  33. const total = { uv: 0, pv: 0, ip: 0 };
  34. this._originData.areas.forEach((item) => {
  35. total.pv += item.PV;
  36. total.uv += item.UV.length;
  37. total.ip += item.IP.length;
  38. });
  39. this.state.total = total;
  40. this.state.currMapData = this.createMapData();
  41. }
  42. });
  43. });
  44. }
  45. createMapData() {
  46. const data: any[] = [];
  47. this._originData.areas.forEach((item) => {
  48. const itemNum: any = {
  49. pv: item.PV,
  50. uv: item.UV.length,
  51. ip: item.IP.length,
  52. };
  53. data.push({
  54. name: item.Province,
  55. value: itemNum[this.state.currType] || 0,
  56. });
  57. });
  58. return data;
  59. }
  60. switchStatType(type: string) {
  61. this.state.currType = type;
  62. this.state.currMapData = this.createMapData();
  63. }
  64. }