Skip to content

Commit c1a8f93

Browse files
authored
Merge pull request #65 from LabSyncro/feat/add-device
fix: handle IO device
2 parents b74d7ef + 1c07741 commit c1a8f93

11 files changed

Lines changed: 27 additions & 24 deletions

File tree

components/app/DeviceNew/InventoryTable/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const emits = defineEmits<{
1515
const showAddModal = ref(false);
1616
1717
async function fetchData (offset: number, length: number, options: { desc?: boolean, sortField?: string, searchText?: string, searchFields?: string[] }): Promise<{ data: unknown[], totalPages: number }> {
18-
const res = await deviceService.getByKind(props.kindId, offset, length, { searchText: options.searchText, searchFields: ['device_id'], sortField: options.sortField as any, desc: options.desc });
18+
const res = await deviceService.getByKind(props.kindId.toLowerCase(), offset, length, { searchText: options.searchText, searchFields: ['device_id'], sortField: options.sortField as any, desc: options.desc });
1919
return {
2020
data: res.devices,
2121
totalPages: res.totalPages,

components/app/DeviceNew/PrintQRCode.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
22
import { deviceService } from '@/services';
33
4+
const router = useRouter();
5+
46
interface DeviceData {
57
quantity: string
68
location: string
@@ -26,18 +28,18 @@ const generateDevices = async (): Promise<{ id: string; url: string; name: strin
2628
return props.listDeviceIds.map(deviceId => {
2729
return {
2830
id: `${deviceKindId.toLowerCase()}/${deviceId}`,
29-
url: `http://localhost:3000/devices/${deviceKindId.toLowerCase()}?id=${deviceId}`,
31+
url: `https://labsyncro.tickflow.net/devices/${deviceKindId.toLowerCase()}?id=${deviceId}`,
3032
name: deviceKindName,
3133
};
3234
});
3335
};
3436
const handlePrint = async () => {
3537
const devices = await generateDevices();
36-
console.log(devices);
3738
await deviceService.printQRCode({ devices });
3839
await deviceService.updatePrintedAt(props.listDeviceIds.map(id => ({ id, printedAt: new Date() })));
3940
emit('print');
4041
emit('update:isOpen', false);
42+
router.push(`/devices/${props.deviceData.deviceKindId.toLowerCase()}`);
4143
};
4244
4345
const handleSkip = () => {

composables/states.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const useLab = () => {
22
const lab = useState<{ id: string }>('lab', () => ({
3-
id: '16824ad6-5ffd-4c90-80d2-a1d70f068cf1',
3+
id: 'c44dbb4c-9a28-4dc7-bb5e-79f112ad8412',
44
}));
55

66
return {

composables/useVirtualKeyboardDetection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function useVirtualKeyboardDetection (
1616
let timeoutId: NodeJS.Timeout | null = null;
1717
let isProcessing = false;
1818
const defaultDeviceRegex =
19-
/^https?:\/\/[^/]+\/devices\/\d{8}\?id=[a-fA-F0-9]+$/;
19+
/^https?:\/\/[^/]+\/devices\/[a-fA-F0-9]{8}\?id=[a-fA-F0-9]+$/;
2020

2121
const defaultOptions = {
2222
userId: {
@@ -53,6 +53,7 @@ export function useVirtualKeyboardDetection (
5353
};
5454

5555
const handleKeyDown = (e: KeyboardEvent): void => {
56+
5657
if (isProcessing) return;
5758

5859
if (currentInput.length === 0) {
@@ -74,7 +75,6 @@ export function useVirtualKeyboardDetection (
7475
resetDetection();
7576
return;
7677
}
77-
7878
if (mergedOptions.device.pattern.test(currentInput)) {
7979
handleDetection(currentInput, 'device');
8080
resetDetection();

pages/admin/borrows/form.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ async function addDevice({ kind, id }: { kind: string; id: string }) {
9191
try {
9292
const deviceKind = devicesInCart.value.find(item => item.id === kind);
9393
if (deviceKind) {
94-
if (!deviceKind.deviceIds.includes(id)) {
95-
deviceKind.deviceIds.push(id);
96-
}
94+
deviceKind.deviceIds.push(id);
95+
console.log(selectedDevices.value);
9796
return;
9897
}
9998
@@ -107,6 +106,7 @@ async function addDevice({ kind, id }: { kind: string; id: string }) {
107106
} catch (error) {
108107
toast.error('Không thể thêm thiết bị');
109108
}
109+
console.log(selectedDevices.value);
110110
}
111111
112112
function deleteDevice({ kind, id }: { kind: string; id: string }) {
@@ -155,7 +155,6 @@ async function handleUserCodeChange(userId: string) {
155155
userInfo.role = userRole;
156156
userInfo.translatedRole = translateRole(userRole as ValidRole);
157157
} else {
158-
console.log(userMeta.roles);
159158
userInfo.role = '';
160159
userInfo.translatedRole = 'Vai trò không hợp lệ';
161160
}
@@ -166,7 +165,6 @@ async function handleUserCodeChange(userId: string) {
166165
167166
// Form submission
168167
async function submitBorrowForm() {
169-
console.log(formState);
170168
if (!isValidForm.value) {
171169
toast.error('Vui lòng điền đầy đủ thông tin');
172170
return;
@@ -239,7 +237,7 @@ watch(() => formState.userId, handleUserCodeChange);
239237
240238
useVirtualKeyboardDetection(handleVirtualKeyboardDetection, {
241239
userId: { length: 7 },
242-
device: { pattern: /^https?:\/\/[^/]+\/devices\/\d{8}\?id=[a-fA-F0-9]+$/ },
240+
device: { pattern: /^https?:\/\/[^/]+\/devices\/[a-fA-F0-9]{8}\?id=[a-fA-F0-9]+$/ },
243241
scannerThresholdMs: 100,
244242
maxInputTimeMs: 1000
245243
});

pages/admin/returns/form.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ watch(() => formState.userId, handleUserCodeChange);
226226
227227
useVirtualKeyboardDetection(handleVirtualKeyboardDetection, {
228228
userId: { length: 7 },
229-
device: { pattern: /^https?:\/\/[^/]+\/devices\/\d{8}\?id=[a-fA-F0-9]+$/ },
229+
device: { pattern: /^https?:\/\/[^/]+\/devices\/[a-fA-F0-9]{8}\?id=[a-fA-F0-9]+$/ },
230230
scannerThresholdMs: 100,
231231
maxInputTimeMs: 1000,
232232
});

pages/devices/[id].vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,27 @@ watch(searchText, async () => {
7777
<div class="flex-1">
7878
<section class="bg-white p-10 flex flex-col md:flex-row gap-8 md:gap-16">
7979
<div class="w-[100%] md:max-w-[300px]">
80-
<NuxtImg :src="deviceKindMeta.mainImage" class="border-[1px] border-gray-200" />
80+
<NuxtImg :src="deviceKindMeta?.mainImage" class="border-[1px] border-gray-200" />
8181
<div class="grid grid-cols-4 gap-2 mt-5">
8282
<NuxtImg
83-
v-for="img in deviceKindMeta.subImages" :key="img" :src="img"
83+
v-for="img in deviceKindMeta?.subImages" :key="img" :src="img"
8484
class="border-[1px] border-gray-200" />
8585
</div>
8686
</div>
8787
<div class="flex-1 flex flex-col">
8888
<div class="text-normal md:text-sm">
89-
<h2 class="text-lg mb-3">{{ deviceKindMeta.name }}</h2>
89+
<h2 class="text-lg mb-3">{{ deviceKindMeta?.name }}</h2>
9090
<div class="grid grid-cols-2 mb-1">
9191
<p class="font-bold text-slate-dark">Phân loại</p>
92-
<p>{{ deviceKindMeta.categoryName }}</p>
92+
<p>{{ deviceKindMeta?.categoryName }}</p>
9393
</div>
9494
<div class="grid grid-cols-2 mb-1">
9595
<p class="font-bold text-slate-dark">Thương hiệu</p>
96-
<p>{{ deviceKindMeta.brand || 'Không rõ' }}</p>
96+
<p>{{ deviceKindMeta?.brand || 'Không rõ' }}</p>
9797
</div>
9898
<div class="mt-8 font-semibold">
9999
<span
100-
v-if="deviceKindMeta.borrowableQuantity > 0"
100+
v-if="deviceKindMeta?.borrowableQuantity > 0"
101101
class="border-[1px] border-safe-darker bg-green-50 text-green-500 p-1.5 rounded-sm">
102102
Sẵn có
103103
</span>
@@ -107,7 +107,7 @@ watch(searchText, async () => {
107107
</div>
108108
<div class="mt-10 mb-10">
109109
<h3 class="font-bold text-slate-dark">Mô tả thiết bị</h3>
110-
<p class="mt-2 overflow-auto">{{ deviceKindMeta.description }}</p>
110+
<p class="mt-2 overflow-auto">{{ deviceKindMeta?.description }}</p>
111111
</div>
112112
</div>
113113
<button

pages/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const handleVirtualKeyboardDetection = async (input: string, type?: 'userId' | '
2121
if (status === 'borrowing') {
2222
navigateTo({
2323
path: '/admin/returns/form',
24-
query: { deviceKindId, deviceId }
24+
query: { deviceKindId, deviceId, userId: '2114417' }
2525
});
2626
} else if (status === 'healthy') {
2727
navigateTo({
@@ -34,7 +34,7 @@ const handleVirtualKeyboardDetection = async (input: string, type?: 'userId' | '
3434
3535
useVirtualKeyboardDetection(handleVirtualKeyboardDetection, {
3636
userId: { length: 7 },
37-
device: { pattern: /^https?:\/\/[^/]+\/devices\/\d{8}\?id=[a-fA-F0-9]+$/ },
37+
device: { pattern: /^https?:\/\/[^/]+\/devices\/[a-fA-F0-9]{8}\?id=[a-fA-F0-9]+$/ },
3838
scannerThresholdMs: 100,
3939
maxInputTimeMs: 1000,
4040
});

pages/settings/permissions/group/[role].vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ onMounted(async () => {
4343
selectedPermissions.value = roleDetail.value.permissions
4444
.flatMap(p => p.actions.map(a => `${p.resource}-${a}`));
4545
}
46-
console.log(selectedPermissions.value);
4746
});
4847
4948
const togglePermission = (resource: string, action: string) => {

server/api/devices/[id]/checked.post.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export default defineEventHandler<Promise<DeviceCheckerResourceDto>>(
105105
});
106106
}
107107

108+
109+
108110
return {
109111
id: returnedDevice[0].id,
110112
status: returnedDevice[0].status,

0 commit comments

Comments
 (0)