修复分类问题

This commit is contained in:
2026-08-27 23:02:17 +08:00
parent d6bba226d0
commit ae6b060c25
5 changed files with 54 additions and 25 deletions
@@ -47,14 +47,19 @@
<div class="category-actions">
<el-button-group size="small">
<el-button type="text" title="编辑" @click.stop="$emit('edit', item)">
<el-button
v-if="!isGlobal"
type="text"
title="编辑"
@click.stop="$emit('edit', item)"
>
<el-icon><Edit /></el-icon>
</el-button>
<el-button type="text" title="添加子分类" @click.stop="$emit('add-child', item)">
<el-icon><Plus /></el-icon>
</el-button>
<el-button
v-if="item.tid !== 0"
v-if="!isGlobal"
type="text"
class="danger"
title="删除"
@@ -62,7 +67,7 @@
>
<el-icon><Delete /></el-icon>
</el-button>
<el-tag v-else type="info" size="small" title="全局分类不可删除">
<el-tag v-if="isGlobal" type="info" size="small" title="全局分类不可修改或删除">
全局
</el-tag>
</el-button-group>
@@ -88,6 +93,7 @@
</template>
<script setup>
import { computed } from "vue";
import { ArrowDown, ArrowRight, Edit, Plus, Delete, Document } from "@element-plus/icons-vue";
const props = defineProps({
@@ -97,6 +103,11 @@ const props = defineProps({
const emit = defineEmits(['edit', 'add-child', 'delete']);
// 全局分类(tid = 0)由平台维护,租户端不能编辑或删除
const isGlobal = computed(
() => props.item.is_global === true || Number(props.item.tid) === 0
);
const toggleExpand = () => {
props.item.expanded = !props.item.expanded;
};
@@ -245,9 +245,8 @@ async function handleSubmit() {
if (fileList.value.length > 0 && fileList.value[0].raw) {
const uploadFormData = new FormData()
uploadFormData.append('file', fileList.value[0].raw)
uploadFormData.append('cate', 'category')
const uploadRes = await uploadFile(uploadFormData)
const uploadRes: any = await uploadFile(uploadFormData)
if (uploadRes?.data?.url) {
imageUrl = uploadRes.data.url
}
@@ -262,17 +261,20 @@ async function handleSubmit() {
cid: formData.parentId,
}
if (isEdit.value) {
await editCategory(formData.id, payload)
const res: any = await editCategory(formData.id, payload)
if (res?.code && res.code !== 200) throw res
ElMessage.success('更新成功')
} else {
await createCategory(payload)
const res: any = await createCategory(payload)
if (res?.code && res.code !== 200) throw res
ElMessage.success('创建成功')
}
emit('saved')
closeDialog()
} catch (err) {
} catch (err: any) {
console.error(err)
ElMessage.error(isEdit.value ? '更新失败' : '创建失败')
const msg = err?.response?.data?.msg || err?.msg
ElMessage.error(msg || (isEdit.value ? '更新失败' : '创建失败'))
} finally {
submitLoading.value = false
}
@@ -70,9 +70,8 @@ const searchText = ref("");
const categories = ref([]);
// 新增分类
const addCategory = ref(null);
const handleAdd = () => {
addCategory.value = { parentId: 0 };
currentEdit.value = { parentId: 0 };
dialogVisible.value = true;
}
@@ -128,6 +127,10 @@ function handleCreate() {
}
function handleEdit(category) {
if (Number(category.tid) === 0 || category.is_global === true) {
ElMessage.warning("全局分类不可修改");
return;
}
currentEdit.value = category;
dialogVisible.value = true;
}