fix: 分类管理图标可选项+编辑修复

- 图标默认改为空(可选,占位符标注)
- 编辑时正确解构各字段(避免多余字段干扰)
- 后端 icon 为空时自动回退🔗
- 后端 sort 为 null 时自动回退0
This commit is contained in:
Agent
2026-07-15 09:29:57 +08:00
parent 9590231e21
commit 0cdcb7cf5b
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ const router = (app) => {
app.put('/api/admin/categories/:id', authenticate, async (req, res) => {
try {
const { name, icon, sort } = req.body;
await pool.query('UPDATE categories SET name = ?, icon = ?, sort = ? WHERE id = ?', [name, icon, sort, Number(req.params.id)]);
await pool.query('UPDATE categories SET name = ?, icon = ?, sort = ? WHERE id = ?', [name, icon || '🔗', sort ?? 0, Number(req.params.id)]);
res.json({ status: 200, message: '更新成功' });
} catch {
res.json({ status: 500, message: '更新失败' });
+3 -3
View File
@@ -26,7 +26,7 @@
<el-dialog v-model="dialogVisible" :title="editId ? '编辑分类' : '新增分类'" :width="dialogWidth">
<el-form :model="form" label-width="60px">
<el-form-item label="图标">
<el-input v-model="form.icon" placeholder="如:🌟" />
<el-input v-model="form.icon" placeholder="可选,如:🌟" />
</el-form-item>
<el-form-item label="名称">
<el-input v-model="form.name" />
@@ -52,7 +52,7 @@ import { adminApi } from '@/api'
const categories = ref([])
const dialogVisible = ref(false)
const editId = ref(null)
const form = ref({ icon: '🔗', name: '', sort: 0 })
const form = ref({ icon: '', name: '', sort: 0 })
const dialogWidth = computed(() => window.innerWidth < 500 ? '92%' : '420px')
async function load() {
@@ -61,7 +61,7 @@ async function load() {
function openDialog(row?: any) {
editId.value = row?.id || null
form.value = row || { icon: '🔗', name: '', sort: 0 }
form.value = row ? { icon: row.icon || '', name: row.name || '', sort: row.sort ?? 0 } : { icon: '', name: '', sort: 0 }
dialogVisible.value = true
}