feat(admin): merge stash changes into comclib-analytics (order/finance/product + rpc sql)

This commit is contained in:
comlibmb
2026-02-10 18:49:21 +08:00
parent bf394eb65d
commit 80e5a1ddeb
23 changed files with 1599 additions and 143 deletions

View File

@@ -149,59 +149,99 @@
</template>
<script setup lang="uts">
import { ref, reactive } from 'vue'
import { ref, reactive, onMounted } from 'vue'
import {
fetchAdminCategoryList,
createAdminCategory,
updateAdminCategory,
deleteAdminCategory,
type AdminCategory
} from '@/services/admin/productCategoryService.uts'
interface CateItem {
id: number;
id: string;
name: string;
icon: string;
sort: number;
status: boolean;
expanded?: boolean;
children?: CateItem[];
parentId?: number;
parentId?: string | null;
}
const list = reactive<CateItem[]>([
{
id: 100, name: '家用电器', icon: '/static/logo.png', sort: 1, status: true, expanded: true,
children: [
{ id: 101, name: '电视机', icon: '/static/logo.png', sort: 1, status: true, parentId: 100 },
{ id: 102, name: '电冰箱', icon: '/static/logo.png', sort: 2, status: true, parentId: 100 }
]
},
{
id: 200, name: '手机数码', icon: '/static/logo.png', sort: 2, status: true, expanded: false,
children: [
{ id: 201, name: '手机', icon: '/static/logo.png', sort: 1, status: true, parentId: 200 },
{ id: 202, name: '耳机', icon: '/static/logo.png', sort: 2, status: true, parentId: 200 }
]
}
])
const list = ref<Array<CateItem>>([])
const showDrawerMask = ref(false)
const showDrawer = ref(false)
const isEdit = ref(false)
const editingId = ref<string | null>(null)
const form = reactive({
name: '',
parentId: null as string | null,
parentName: '',
sort: 0,
status: true
})
onMounted(() => {
loadList()
})
function buildTree(items: Array<AdminCategory>): Array<CateItem> {
const map: Record<string, CateItem> = {}
const roots: Array<CateItem> = []
for (let i = 0; i < items.length; i++) {
const c = items[i]
map[c.id] = {
id: c.id,
name: c.name,
icon: c.icon ?? '',
sort: c.sort ?? 0,
status: c.is_active === true,
expanded: false,
children: [],
parentId: c.parent_id ?? null
}
}
const ids = Object.keys(map)
for (let i = 0; i < ids.length; i++) {
const id = ids[i]
const node = map[id]
if (node.parentId != null && map[node.parentId] != null) {
map[node.parentId].children = map[node.parentId].children ?? []
map[node.parentId].children!.push(node)
} else {
roots.push(node)
}
}
return roots
}
async function loadList() {
const items = await fetchAdminCategoryList({})
list.value = buildTree(items)
}
function openDrawer(item: CateItem | null = null) {
if (item != null) {
isEdit.value = true
editingId.value = item.id
form.name = item.name
form.sort = item.sort
form.status = item.status
form.parentId = item.parentId ?? null
form.parentName = item.parentId != null ? '子分类' : '顶级分类'
} else {
isEdit.value = false
editingId.value = null
form.name = ''
form.sort = 0
form.status = true
form.parentId = null
form.parentName = '顶级分类'
}
showDrawerMask.value = true
@@ -217,22 +257,49 @@ showDrawerMask.value = false
}, 300)
}
function saveCate() {
async function saveCate() {
if (isEdit.value && editingId.value != null) {
await updateAdminCategory({
id: editingId.value,
parentId: form.parentId,
name: form.name,
sortOrder: form.sort,
isActive: form.status
})
} else {
await createAdminCategory({
parentId: form.parentId,
name: form.name,
sortOrder: form.sort,
isActive: form.status
})
}
uni.showToast({ title: '保存成功', icon: 'success' })
closeDrawer()
loadList()
}
function toggleStatus(item: CateItem) {
async function toggleStatus(item: CateItem) {
await updateAdminCategory({
id: item.id,
parentId: item.parentId,
name: item.name,
sortOrder: item.sort,
isActive: !item.status
})
item.status = !item.status
}
function deleteItem(item: CateItem) {
async function deleteItem(item: CateItem) {
uni.showModal({
title: '提示',
content: '确定删除该分类吗?',
success: (res) => {
success: async (res) => {
if (res.confirm) {
uni.showToast({ title: '已模拟删除', icon: 'none' })
await deleteAdminCategory(item.id)
uni.showToast({ title: '删除成功', icon: 'success' })
loadList()
}
}
})