From 56152eb63279eb9ed08aede23d98d6fb26b0a0c2 Mon Sep 17 00:00:00 2001 From: qingyu <14049064+qingyuya123@user.noreply.gitee.com> Date: Tue, 24 Jun 2025 11:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=B3=E5=B0=86=E4=BA=A7=E5=93=81-=E6=B7=B7?= =?UTF-8?q?=E4=B9=B1=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.dev | 5 +- .env.test | 3 +- src/apis/modules/products.js | 9 +- src/views/product/components/EditDialog.vue | 98 ++++++++++++++++----- src/views/product/index.vue | 22 ----- 5 files changed, 85 insertions(+), 52 deletions(-) diff --git a/.env.dev b/.env.dev index 7f1c9e6..bcb46e7 100644 --- a/.env.dev +++ b/.env.dev @@ -12,7 +12,8 @@ VITE_ROUTER_BASE=/ VITE_ROUTER_HISTORY=hash # api -VITE_API_BASIC=https://api.hailin-keji.com +#VITE_API_BASIC=https://api.hailin-keji.com +VITE_API_BASIC=http://10.10.1.6:8060 VITE_API_HTTP=/api/v1/ # storage -VITE_STORAGE_NAMESPACE = gin-admin_local_ \ No newline at end of file +VITE_STORAGE_NAMESPACE = gin-admin_local_ diff --git a/.env.test b/.env.test index 5f684f9..5a0cefd 100644 --- a/.env.test +++ b/.env.test @@ -11,7 +11,8 @@ VITE_PERMISSION=false VITE_ROUTER_HISTORY=hash # api -VITE_API_BASIC=https://mock.apifox.cn/m1/3156808-0-default +#VITE_API_BASIC=https://mock.apifox.cn/m1/3156808-0-default +VITE_API_BASIC=http://10.10.1.6:8060 # storage VITE_STORAGE_NAMESPACE=admin_test_ diff --git a/src/apis/modules/products.js b/src/apis/modules/products.js index 15df115..c7122cd 100644 --- a/src/apis/modules/products.js +++ b/src/apis/modules/products.js @@ -4,7 +4,6 @@ import request from '@/utils/request' // 获取产品列表 export const getProductsList = (params) => request.basic.get('/api/v1/products', params) - // 获取产品单条数据 export const getProductsItem = (id) => request.basic.get(`/api/v1/products/${id}`) // 添加产品 @@ -14,10 +13,10 @@ export const updateProductsItem = (id, params) => request.basic.put(`/api/v1/pro // 删除产品 export const delProductsItem = (id) => request.basic.delete(`/api/v1/products/${id}`) // 获取产品类别列表 -export const getProduct = (params) => request.basic.get('/api/v1/products/job_areas', params) +export const getProductCategory = (params) => request.basic.get('/api/v1/products/categorys', params) // 获取产品适用对象 -export const getProductObj = (params) => request.basic.get('/api/v1/products/job_areas', params) +export const getProductObj = (params) => request.basic.get('/api/v1/products/target', params) // 添加产品类别 -export const createProduct = (params) => request.basic.post('/api/v1/products/job_areas', params) +export const createProductCategory = (params) => request.basic.post('/api/v1/products/categorys', params) // 添加适用对象产品 -export const createProductObj = (params) => request.basic.post('/api/v1/products/job_areas', params) +export const createProductObj = (params) => request.basic.post('/api/v1/products/target', params) diff --git a/src/views/product/components/EditDialog.vue b/src/views/product/components/EditDialog.vue index a49f3a0..0cef726 100644 --- a/src/views/product/components/EditDialog.vue +++ b/src/views/product/components/EditDialog.vue @@ -27,8 +27,16 @@ - +
+ + {{ item.name }} + + 新增适用对象 +
+ + +
@@ -104,7 +112,7 @@ - + @@ -141,6 +149,13 @@ import { useForm, useModal,useSpining } from '@/hooks' import { message } from 'ant-design-vue' import { useI18n } from 'vue-i18n' import dayjs from 'dayjs' +import { + createProductCategory, + createProductObj, createProductsItem, + getProductCategory, + getProductObj, + getProductsItem, updateProductsItem, +} from '@/apis/modules/products' const areaFormRef = ref() const emit = defineEmits(['ok']) const { t } = useI18n() // 解构出t方法 @@ -167,26 +182,48 @@ formRules.value = { } const areaFormRules = { categoryIDName: [{ required: true, message: '请输入产品类别' }], - composeName: [{ required: true, message: '请输入产品适用对象' }], + targetName: [{ required: true, message: '请输入产品适用对象' }], status: [{ required: true, message: '请选择状态', trigger: 'change' }], } -const initData = async () => { +const initDataBatch = async (configs) => { try { showSpining() - const { success, data, total } = await apis.products.getAreasList({ pageSize: 999, page: 1, }) - if (config('http.code.success') === success) { - hideSpining() - areaList.value = data.map(item => { - if (item.status === 'enabled') { - return { code: item.id, name: item.name } - } - }) - } + 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) { + areaList.value = [ + ...areaList.value, + ...data + .filter(item => item.status === 'enabled') + .map(item => ({ + code: item.id, + [resultKey]: item[nameKey], + })) + ] + } + }) } catch (error) { message.error({ content: error.message }) + } finally { hideSpining() } } +initDataBatch([ + { + apiFunc: apis.products.getProductCategory, + nameKey: 'name', + resultKey: 'categoryIDName' + }, + { + apiFunc: apis.products.getProductObj, + nameKey: 'name', + resultKey: 'targetName' + } +]) /** * 新建 @@ -194,29 +231,46 @@ const initData = async () => { function handleCreate() { showModal({ type: 'create', - title: '薪资招聘岗位', + title: '产品中心', }) initData() formData.value.status = 'enabled' } -//新建基地 - +//新建产品类别 const childHandleOk = async () => { areaFormRef.value.validateFields().then(async (values) => { try { const params = { ...formArea.value } - const { success } = await apis.recruitment.createAreaItem(params) + const { success } = await apis.products.createProductCategory(params) if (success) message.success('新增成功') childOpen.value = false - formArea.value = { name: '', status: 'enabled' } + formArea.value = { categoryIDName: '', status: 'enabled' } initData() } catch (error) { message.error(error.message) } }) - } +//新建产品适用对象 +const childHandleObjOk = async () => { + areaFormRef.value.validateFields().then(async (values) => { + try { + const params = { ...formArea.value } + const { success } = await apis.products.createProductObj(params) + if (success) message.success('新增成功') + childOpen.value = false + formArea.value = { targetName: '', status: 'enabled' } + initData() + } catch (error) { + message.error(error.message) + } + }) +} +const handleCombinedOk = () => { + childHandleOk(); + childHandleObjOk(); +}; /** * 编辑 */ @@ -225,7 +279,7 @@ async function handleEdit(record = {}) { type: 'edit', title: t('pages.system.user.edit'), }) - const { data, success } = await apis.recruitment.getItem(record.id).catch() + const { data, success } = await apis.products.getProductsItem(record.id).catch() if (!success) { hideModal() return @@ -250,12 +304,12 @@ function handleOk() { let result = null switch (modal.value.type) { case 'create': - result = await apis.recruitment.createItem(params).catch((error) => { + result = await apis.products.createProductsItem(params).catch((error) => { throw new Error(error) }) break case 'edit': - result = await apis.recruitment.updateItem(formData.value.id, params).catch(() => { + result = await apis.products.updateProductsItem(formData.value.id, params).catch(() => { throw new Error(error) }) break diff --git a/src/views/product/index.vue b/src/views/product/index.vue index c11a23f..4ecf29c 100644 --- a/src/views/product/index.vue +++ b/src/views/product/index.vue @@ -107,18 +107,6 @@ defineOptions({ name: 'components', }) const { t } = useI18n() // 解构出t方法 -// const columns = [ -// { title: '产品名称', dataIndex: 'title', width: 120, }, -// { title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 }, -// { title: '原料组成', dataIndex: 'compose', key: 'compose',width: 120}, -// { title: '适用对象', dataIndex: 'target',width: 120}, -// { title: '功能特点', dataIndex: 'feature', width: 120, align: 'center'}, -// { title: '产品标准', dataIndex: 'standard', width: 120, align: 'center'}, -// { title: '产品图片', dataIndex: 'images', width: 120, align: 'center'}, -// { title: '产品排序', dataIndex: 'sequence', width: 120, align: 'center'}, -// { title: '产品状态', dataIndex: 'status',width:120 , align: 'center'}, -// { title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' }, -// ] const columns = [ { title: '产品名称', dataIndex: 'title', width: 120 }, { title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 }, @@ -254,16 +242,6 @@ async function onOk() { message.success(t('component.message.success.delete')) await getPageList() } - -function addImage() { - images.value.push('') -} - -function removeImage(index) { - if (images.value.length > 1) { - images.value.splice(index, 1) - } -}