jasan/models.php
2026-02-08 17:12:56 +09:00

157 lines
No EOL
7.8 KiB
PHP

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DB 관리 - 노트북 모델 | FKI ASSET</title>
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Pretendard:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/style.css">
<style>
body {
font-family: 'Pretendard', sans-serif;
}
[x-cloak] {
display: none !important;
}
.modal-bg {
background-color: rgba(15, 23, 42, 0.7);
backdrop-filter: blur(4px);
}
</style>
</head>
<body class="bg-[#f8fafc] text-slate-800" x-data="modelManagement()">
<?php include 'nav.php'; ?>
<main class="max-w-[1600px] mx-auto p-8 pt-10">
<header class="mb-10 flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<h2 class="text-3xl font-extrabold text-slate-900 tracking-tight">DB 관리: 노트북 모델</h2>
<p class="text-slate-500 mt-1">자산 등록 시 사용될 하드웨어 모델 정보 및 상세 사양 관리</p>
</div>
<button @click="openAddModal()"
class="bg-blue-600 text-white px-5 py-2.5 rounded-xl font-bold shadow-lg shadow-blue-200 hover:bg-blue-700 transition-all">신규
모델 등록</button>
</header>
<!-- Model List Table -->
<div class="bg-white rounded-3xl shadow-sm border border-slate-200 overflow-hidden">
<table class="min-w-full divide-y divide-slate-100">
<thead class="bg-slate-50/50">
<tr>
<th class="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">제조사
</th>
<th class="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">모델명
</th>
<th class="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">상세 사양
</th>
<th class="px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider">관리
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-50">
<template x-for="model in models" :key="model.id">
<tr class="hover:bg-slate-50/80 transition-colors group">
<td class="px-6 py-4 whitespace-nowrap">
<span
class="px-2.5 py-1 bg-slate-100 text-slate-600 rounded-lg text-xs font-black uppercase tracking-widest"
x-text="model.manufacturer"></span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="text-sm font-bold text-slate-900" x-text="model.model_name"></span>
</td>
<td class="px-6 py-4">
<span class="text-xs text-slate-500 line-clamp-1" x-text="model.specs || '-'"></span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right">
<button @click="editModel(model)"
class="text-xs font-bold text-blue-600 hover:underline px-3 py-1 rounded-lg hover:bg-blue-50 transition-all">수정</button>
</td>
</tr>
</template>
</tbody>
</table>
</div>
</main>
<!-- Model Modal -->
<div x-show="showModal" x-cloak class="fixed inset-0 z-[110] flex items-center justify-center p-4">
<div class="fixed inset-0 modal-bg" @click="showModal = false"></div>
<div class="bg-white rounded-3xl p-8 max-w-md w-full relative z-[111] shadow-2xl">
<h3 class="text-2xl font-black mb-6" x-text="isEdit ? '모델 정보 수정' : '신규 모델 등록'"></h3>
<form @submit.prevent="submitModel" class="space-y-4">
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">제조사</label>
<input type="text" x-model="formData.manufacturer" required placeholder="예: Samsung, Apple"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">모델명</label>
<input type="text" x-model="formData.model_name" required placeholder="예: Galaxy Book 4 Pro"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">상세 사양 (CPU, RAM, SSD 등)</label>
<textarea x-model="formData.specs" rows="3" placeholder="예: Core Ultra 7 / 32GB / 1TB"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none resize-none"></textarea>
</div>
<div class="pt-4 flex gap-3">
<button type="button" @click="showModal = false"
class="flex-1 py-3 bg-slate-100 rounded-xl font-bold">취소</button>
<button type="submit" class="flex-1 py-3 bg-blue-600 text-white rounded-xl font-bold"
x-text="isEdit ? '수정 완료' : '모델 등록'"></button>
</div>
</form>
</div>
</div>
<script>
function modelManagement() {
return {
models: [],
showModal: false,
isEdit: false,
formData: { id: '', manufacturer: '', model_name: '', specs: '' },
init() { this.fetchModels(); },
fetchModels() {
const scrollPos = window.scrollY;
fetch('api.php?action=get_models').then(res => res.json()).then(data => {
this.models = data;
this.$nextTick(() => window.scrollTo(0, scrollPos));
});
},
openAddModal() {
this.isEdit = false;
this.formData = { id: '', manufacturer: '', model_name: '', specs: '' };
this.showModal = true;
},
editModel(model) {
this.isEdit = true;
this.formData = { ...model };
this.showModal = true;
},
submitModel() {
const action = this.isEdit ? 'update_model' : 'add_model';
fetch(`api.php?action=${action}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(this.formData)
}).then(res => res.json()).then(data => {
if (data.success) {
this.showModal = false;
this.fetchModels();
}
});
}
}
}
</script>
</body>
</html>