@7365admin1/layer-common 3.0.24 → 3.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ interface NFCPatrolLogQuery {
2
+ page?: number;
3
+ limit?: number;
4
+ site: string;
5
+ date: string;
6
+ routeId: string;
7
+ routeStartTime: string;
8
+ }
9
+
10
+ export default function useNFCPatrolLog() {
11
+ function getAll<T = Record<string, any>>({
12
+ page = 1,
13
+ limit = 10,
14
+ site,
15
+ date,
16
+ routeId,
17
+ routeStartTime,
18
+ }: NFCPatrolLogQuery) {
19
+ return useNuxtApp().$api<T>("/api/nfc-patrol-log", {
20
+ method: "GET",
21
+ query: {
22
+ page,
23
+ limit,
24
+ site,
25
+ date,
26
+ "route._id": routeId,
27
+ "route.startTime": routeStartTime,
28
+ },
29
+ });
30
+ }
31
+
32
+ return {
33
+ getAll,
34
+ };
35
+ }
@@ -3,25 +3,58 @@ import type {
3
3
  NFCPatrolReport,
4
4
  NFCPatrolReportFilters,
5
5
  } from "../types/nfc-patrol-report";
6
- import { useNFCPatrolReportService } from "../services/nfcPatrolReport";
7
6
 
8
- export function useNFCPatrolReport(filters: NFCPatrolReportFilters) {
9
- const reportService = useNFCPatrolReportService();
7
+ interface NFCPatrolLogResponse {
8
+ data?: NFCPatrolLogResponse | NFCPatrolReport;
9
+ item?: NFCPatrolReport;
10
+ items?: NFCPatrolReport[];
11
+ nfcPatrolLog?: NFCPatrolReport;
12
+ }
13
+
14
+ export function useNFCPatrolReport(
15
+ filters: NFCPatrolReportFilters,
16
+ site: string,
17
+ ) {
18
+ const { getAll: getPatrolLogs } = useNFCPatrolLog();
10
19
  const report = ref<NFCPatrolReport | null>(null);
11
20
  const loading = ref(false);
12
21
  const selectedActivityRemarks = ref("");
13
22
  const dialogRemarks = ref(false);
14
23
 
15
24
  async function fetchReport() {
25
+ if (!site || !filters.date || !filters.route || !filters.timeRange) {
26
+ report.value = null;
27
+ return;
28
+ }
29
+
16
30
  loading.value = true;
17
31
 
18
32
  try {
19
- report.value = await reportService.getPatrolReport(filters);
33
+ const response = await getPatrolLogs<NFCPatrolLogResponse>({
34
+ page: 1,
35
+ limit: 10,
36
+ site,
37
+ date: filters.date,
38
+ routeId: filters.route,
39
+ routeStartTime: filters.timeRange.split(" - ")[0],
40
+ });
41
+
42
+ report.value = extractReport(response);
20
43
  } finally {
21
44
  loading.value = false;
22
45
  }
23
46
  }
24
47
 
48
+ function extractReport(response: NFCPatrolLogResponse): NFCPatrolReport | null {
49
+ const payload = response.data ?? response;
50
+
51
+ if ("location" in payload && "activities" in payload) {
52
+ return payload;
53
+ }
54
+
55
+ return payload.nfcPatrolLog ?? payload.item ?? payload.items?.[0] ?? null;
56
+ }
57
+
25
58
  function openRemarksDialog(activity: NFCPatrolActivity) {
26
59
  selectedActivityRemarks.value = activity.remarks || "No remarks provided";
27
60
  dialogRemarks.value = true;
@@ -2,14 +2,13 @@ import type {
2
2
  NFCPatrolReportFilterOptions,
3
3
  NFCPatrolReportFilters,
4
4
  } from "../types/nfc-patrol-report";
5
- import { useNFCPatrolReportService } from "../services/nfcPatrolReport";
6
5
 
7
6
  export function useNFCPatrolReportFilters(site: string) {
8
- const reportService = useNFCPatrolReportService();
7
+ const { getAll: getPatrolRoutes } = useNFCPatrolRoute();
9
8
 
10
9
  const filters = reactive<NFCPatrolReportFilters>({
11
- route: "WH01 Patrol Route",
12
- timeRange: "15:00 - 17:00",
10
+ route: "",
11
+ timeRange: "",
13
12
  date: "2025-11-27",
14
13
  });
15
14
 
@@ -24,12 +23,36 @@ export function useNFCPatrolReportFilters(site: string) {
24
23
  loading.value = true;
25
24
 
26
25
  try {
27
- options.value = await reportService.getFilterOptions(site);
26
+ const response = await getPatrolRoutes({ site, page: 1, limit: 100 });
27
+ const routes = (response.items ?? []).map((route: Record<string, any>) => ({
28
+ title: route.name,
29
+ value: route._id,
30
+ startTimes: route.startTimes ?? [],
31
+ }));
32
+
33
+ options.value.routes = routes;
34
+
35
+ if (!routes.some((route) => route.value === filters.route)) {
36
+ filters.route = routes[0]?.value ?? "";
37
+ }
38
+
39
+ updateStartTimes();
28
40
  } finally {
29
41
  loading.value = false;
30
42
  }
31
43
  }
32
44
 
45
+ function updateStartTimes() {
46
+ const route = options.value.routes.find(({ value }) => value === filters.route);
47
+ options.value.timeRanges = route?.startTimes ?? [];
48
+
49
+ if (!options.value.timeRanges.includes(filters.timeRange)) {
50
+ filters.timeRange = options.value.timeRanges[0] ?? "";
51
+ }
52
+ }
53
+
54
+ watch(() => filters.route, updateStartTimes);
55
+
33
56
  return {
34
57
  filters,
35
58
  options,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "3.0.24",
5
+ "version": "3.0.25",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {
@@ -7,7 +7,11 @@ import type {
7
7
  } from "../types/nfc-patrol-report";
8
8
 
9
9
  const filterOptions: NFCPatrolReportFilterOptions = {
10
- routes: ["WH01 Patrol Route", "WH02 Patrol Route", "WH03 Patrol Route"],
10
+ routes: [
11
+ { title: "WH01 Patrol Route", value: "WH01 Patrol Route", startTimes: [] },
12
+ { title: "WH02 Patrol Route", value: "WH02 Patrol Route", startTimes: [] },
13
+ { title: "WH03 Patrol Route", value: "WH03 Patrol Route", startTimes: [] },
14
+ ],
11
15
  timeRanges: ["15:00 - 17:00", "08:00 - 10:00", "13:00 - 15:00", "18:00 - 20:00"],
12
16
  };
13
17
 
@@ -13,8 +13,14 @@ export interface NFCPatrolReportExportRequest {
13
13
  filters: NFCPatrolReportFilters;
14
14
  }
15
15
 
16
+ export interface NFCPatrolReportRouteOption {
17
+ title: string;
18
+ value: string;
19
+ startTimes: string[];
20
+ }
21
+
16
22
  export interface NFCPatrolReportFilterOptions {
17
- routes: string[];
23
+ routes: NFCPatrolReportRouteOption[];
18
24
  timeRanges: string[];
19
25
  }
20
26
 
@@ -71,6 +71,7 @@ declare type TVisitorPayload = Pick<
71
71
  | "createdBy"
72
72
  > & {
73
73
  members?: TMemberInfo[];
74
+ updatedBy?: string;
74
75
  };
75
76
 
76
77
  declare type TDefaultOptionObj = {