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

View File

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