This commit is contained in:
Leo_Ding 2025-06-30 11:08:57 +08:00
commit f48342bba2
2 changed files with 30 additions and 50 deletions

View File

@ -137,7 +137,8 @@ const okText = ref(t('button.confirm'))
const rolesValue = ref([])
const roles = ref([])
const imgUrl = ref('')
const areaList = ref([])
const categoryList = ref([])
const targetList = ref([])
const images = ref([])
const mainImage = ref([])
const contentImage = ref([])
@ -161,51 +162,25 @@ formRules.value = {
}
const areaFormRules = {
categoryIDName: [{ required: true, message: '请输入产品类别' }],
// targetName: [{ required: true, message: '' }],
targetName: [{ required: true, message: '请输入产品适用对象' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
}
const initDataBatch = async (configs) => {
const initData = async () => {
try {
showSpining()
const responses = await Promise.all(
configs.map(({ apiFunc }) => apiFunc({ pageSize: 999, page: 1 }))
)
configs.forEach(({ nameKey, resultKey }, index) => {
const { success, data } = responses[index]
if (config('http.code.success') === success) {
const mapped = data.map(item => {
return {
value: item.value,
children: item.children,
[resultKey]: item.label,// e.g. item['label']
showSpining();
const { success: prodSuccess, data: prodData } = await apis.products.getProductObj({ pageSize: 999, page: 1 });
if (config('http.code.success') === prodSuccess) {
targetList.value = prodData
.filter(item => item.status === 'enabled')
.map(item => ({ code: item.id, name: item.name }));
}
})
areaList.value = [...areaList.value, ...mapped]
console.log(areaList.value)
console.log('after merge:', areaList.value)
}
})
} catch (error) {
message.error({ content: error.message })
message.error({ content: error.message });
} finally {
hideSpining()
hideSpining();
}
}
initDataBatch([
{
apiFunc: apis.products.getProductCategory,
nameKey: 'name',
resultKey: 'categoryIDName'
},
// {
// apiFunc: apis.products.getProductObj,
// nameKey: 'name',
// resultKey: 'targetName'
// }
])
/**
* 新建
@ -253,11 +228,11 @@ function handleCreate() {
const childHandleOk = async () => {
areaFormRef.value.validateFields().then(async (values) => {
try {
const params = { ...formArea.value }
const params = { ...categoryForm.value }
const { success } = await apis.products.createProductCategory(params)
if (success) message.success('新增成功')
childOpen.value = false
formArea.value = { categoryIDName: '', status: 'enabled' }
categoryForm.value = { categoryIDName: '', status: 'enabled' }
initData()
} catch (error) {
message.error(error.message)
@ -268,11 +243,11 @@ const childHandleOk = async () => {
const childHandleObjOk = async () => {
areaFormRef.value.validateFields().then(async (values) => {
try {
const params = { ...formArea.value }
const params = { ...targetForm.value }
const { success } = await apis.products.createProductObj(params)
if (success) message.success('新增成功')
childOpen.value = false
formArea.value = { targetName: '', status: 'enabled' }
targetForm.value = { targetName: '', status: 'enabled' }
initData()
} catch (error) {
message.error(error.message)

View File

@ -60,17 +60,21 @@
<div class="text-ellipsis">{{ record.categoryID }}</div>
</a-tooltip>
</template>
<template v-if="column.dataIndex === 'compose'">
<a-tooltip :title="record.compose">
<div class="text-ellipsis">{{ record.compose }}</div>
</a-tooltip>
</template>
<template v-if="column.dataIndex === 'target'">
<a-tooltip :title="record.target">
<div class="text-ellipsis">{{ record.target }}</div>
</a-tooltip>
</template>
<template v-if="column.dataIndex === 'CategoryRootID'">
<a-tooltip :title="record.CategoryRootID">
<div class="text-ellipsis">{{ record.CategoryRootID }}</div>
</a-tooltip>
</template>
<template v-if="column.dataIndex === 'compose'">
<a-tooltip :title="record.compose">
<div class="text-ellipsis">{{ record.compose }}</div>
</a-tooltip>
</template>
<template v-if="'mainImage' === column.dataIndex">
<a-image :width="60" :alt="column.title" :src="config('http.apiBasic') + record.mainImage || $imageErr.imgErr" />
</template>
@ -121,9 +125,10 @@ const { t } = useI18n() // 解构出t方法
const columns = [
{ title: '产品名称', dataIndex: 'code', width: 120 },
{ title: '产品类别名称', dataIndex: 'title', width: 120 },
{ title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 },
{ title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 },
{ title: '产品类别ID', dataIndex: 'categoryID', key: 'categoryID', width: 120 },
{ title: '适用对象', dataIndex: 'target', width: 120 },
{ title: '产品适用类别ID', dataIndex: 'CategoryRootID', key: 'CategoryRootID', width: 120 },
{ title: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 },
{
title: '功能特点',
dataIndex: 'feature',