Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/views/imgMgt/homeBanner/index.vue
#	src/views/imgMgt/researchHonor/index.vue
This commit is contained in:
qingyu 2025-07-01 14:10:06 +08:00
commit 60d8c1c923
10 changed files with 517 additions and 639 deletions

View File

@ -0,0 +1,14 @@
/**
* 海邻动态接口
*/
import request from '@/utils/request'
// 获取公司动态列表
export const getDataList = (params) => request.basic.get('/api/v1/products/categorys', params)
// 获取单条数据
export const getItem = (id) => request.basic.get(`/api/v1/products/categorys/${id}`)
// 添加动态
export const createProductsItem = (params) => request.basic.post('/api/v1/products/categorys', params)
// 更新动态
export const updateItem = (id, params) => request.basic.put(`/api/v1/products/categorys/${id}`, params)
// 删除动态
export const delProductsItem = (id) => request.basic.delete(`/api/v1/products/categorys/${id}`)

View File

@ -51,4 +51,5 @@ export default {
friendlyLinks:'友情链接', friendlyLinks:'友情链接',
websiteStatement:'网站声明', websiteStatement:'网站声明',
contactUs:'联系我们', contactUs:'联系我们',
productType:'产品分类'
} }

View File

@ -13,4 +13,16 @@ export default [
permission: '*', permission: '*',
}, },
}, },
{
path: 'productType',
name: 'productType',
component: 'productType/index.vue',
meta: {
icon: ShoppingOutlined,
title: '产品分类',
isMenu: true,
keepAlive: true,
permission: '*',
},
},
] ]

View File

@ -1,169 +0,0 @@
<template>
<a-card
:body-style="{ height: 'calc(100% - 56px - 47px)', padding: 0 }"
:style="{
position: 'sticky',
top: appStore.mainOffsetTop,
height: appStore.mainHeight,
}">
<template #title>
<a-input-search placeholder="搜索部门"></a-input-search>
</template>
<x-scrollbar class="pa-8-2">
<a-spin :spinning="loading">
<a-tree
block-node
:selected-keys="selectedKeys"
:tree-data="listData"
:field-names="{ key: 'id', children: 'children' }"
@select="onSelect">
<template #title="{ title }">
<span class="ant-tree-title__name">{{ title }}</span>
<span class="ant-tree-title__actions">
<a-dropdown
:trigger="['click']"
@click.stop>
<x-action-button>
<more-outlined></more-outlined>
</x-action-button>
<template #overlay>
<a-menu>
<a-menu-item @click="$refs.editDepartmentDialogRef.handleEdit()">
添加子部门
</a-menu-item>
<a-menu-item @click="$refs.editDepartmentDialogRef.handleEdit()">
编辑
</a-menu-item>
<a-menu-item @click="handleDelete">删除</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</span>
</template>
</a-tree>
<empty
v-if="!listData.length"
:image="Empty.PRESENTED_IMAGE_SIMPLE"></empty>
</a-spin>
</x-scrollbar>
<template #actions>
<span @click="$refs.editDepartmentDialogRef.handleCreate()">
<plus-outlined></plus-outlined>
新建部门
</span>
</template>
</a-card>
<edit-department-dialog
ref="editDepartmentDialogRef"
@ok="onOk"></edit-department-dialog>
</template>
<script setup>
import { useAppStore } from '@/store'
import { ref, watch } from 'vue'
import { usePagination } from '@/hooks'
import apis from '@/apis'
import { Empty, Modal, message } from 'ant-design-vue'
import { config } from '@/config'
import { head, get, find } from 'lodash-es'
import { MoreOutlined, PlusOutlined } from '@ant-design/icons-vue'
import EditDepartmentDialog from './EditDepartmentDialog.vue'
const props = defineProps({
value: {
type: String,
default: '',
},
})
const emit = defineEmits(['change', 'update:value'])
const appStore = useAppStore()
const { listData, loading, showLoading, hideLoading } = usePagination()
const editDepartmentDialogRef = ref()
const selectedKeys = ref([props.value])
watch(
() => props.value,
(val) => {
if (val === selectedKeys.value?.[0]) return
selectedKeys.value = [val]
}
)
getList()
/**
* 获取列表
* @returns {Promise<void>}
*/
async function getList() {
try {
showLoading()
const { code, data } = await apis.common.getPageList().catch(() => {
throw new Error()
})
hideLoading()
if (config('http.code.success') === code) {
const { records } = data
listData.value = records
if (listData.value.length) {
selectedKeys.value = [get(head(listData.value), 'id')]
trigger()
}
}
} catch (error) {
hideLoading()
}
}
/**
* 删除
*/
function handleDelete({ id }) {
Modal.confirm({
title: '删除提示',
content: '确认删除?',
okText: '确认',
onOk: () => {
return new Promise((resolve, reject) => {
;(async () => {
try {
const { code } = await apis.common.del(id).catch(() => {
throw new Error()
})
if (config('http.code.success') === code) {
resolve()
message.success('删除成功')
await getList()
}
} catch (error) {
reject()
}
})()
})
},
})
}
function onSelect(keys) {
if (!keys.length) return
selectedKeys.value = keys
trigger()
}
async function onOk() {
await getList()
}
function trigger() {
const value = head(selectedKeys.value)
const record = find(listData.value, { id: value })
emit('update:value', value)
emit('change', record)
}
</script>
<style lang="less" scoped></style>

View File

@ -1,131 +0,0 @@
<template>
<a-modal
:open="modal.open"
:title="modal.title"
:width="480"
:confirm-loading="modal.confirmLoading"
:after-close="onAfterClose"
:cancel-text="cancelText"
@ok="handleOk"
@cancel="handleCancel">
<a-form
ref="formRef"
:model="formData"
:rules="formRules"
:label-col="{ style: { width: '90px' } }">
<a-form-item
label="部门名称"
name="name">
<a-input v-model:value="formData.name"></a-input>
</a-form-item>
<a-form-item
label="上级部门"
name="parent_id">
<a-tree-select v-model:value="formData.parent_id"></a-tree-select>
</a-form-item>
<a-form-item
label="部门负责人"
name="name">
<a-input v-model:value="formData.name"></a-input>
</a-form-item>
</a-form>
</a-modal>
</template>
<script setup>
import { cloneDeep } from 'lodash-es'
import { ref } from 'vue'
import { config } from '@/config'
import apis from '@/apis'
import { useForm, useModal } from '@/hooks'
const emit = defineEmits(['ok'])
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
const cancelText = ref('取消')
/**
* 新建
*/
function handleCreate() {
showModal({
type: 'create',
title: '新建部门',
})
}
/**
* 编辑
*/
function handleEdit(record = {}) {
showModal({
type: 'edit',
title: '编辑部门',
})
formRecord.value = record
formData.value = cloneDeep(record)
}
/**
* 确定
*/
function handleOk() {
formRef.value
.validateFields()
.then(async (values) => {
try {
showLoading()
const params = {
...values,
}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.common.create(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.common.update(params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (config('http.code.success') === result?.code) {
hideModal()
emit('ok')
}
} catch (error) {
hideLoading()
}
})
.catch(() => {
hideLoading()
})
}
/**
* 取消
*/
function handleCancel() {
hideModal()
}
/**
* 关闭后
*/
function onAfterClose() {
resetForm()
cancelText.value = '取消'
hideLoading()
}
defineExpose({
handleCreate,
handleEdit,
})
</script>
<style lang="less" scoped></style>

View File

@ -4,6 +4,8 @@
<a-spin :spinning="spining"> <a-spin :spinning="spining">
<a-form ref="formRef" :model="formData" :rules="formRules"> <a-form ref="formRef" :model="formData" :rules="formRules">
<a-card class="mb-8-2"> <a-card class="mb-8-2">
<a-tabs v-model:activeKey="activeKey">
<a-tab-pane key="1" tab="基本信息">
<a-row :gutter="12"> <a-row :gutter="12">
<a-col :span="24"> <a-col :span="24">
<a-form-item :label="'产品名称'" name="code"> <a-form-item :label="'产品名称'" name="code">
@ -11,68 +13,52 @@
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="24"> <a-col :span="24">
<a-form-item :label="'产品类别名称'" name="categoryID"> <a-form-item :label="'产品类别'" name="categoryIDs">
<!-- <a-input :placeholder="'请输入产品类别名称'" v-model:value="formData.categoryID"></a-input>--> <a-tree-select v-model:value="formData.categoryIDs" :tree-data="categoryList"
<div style="display: flex;justify-content: space-between;"> @change="handleTreeSelectChange" placeholder="请选择(只能选最后一级)"
<a-select v-model:value="formData.categoryID" allowClear> style="width: 100%" tree-default-expand-all/>
<a-select-option v-for="item in categoryList" :value="item.value">{{ item.categoryIDName }}</a-select-option> </a-form-item>
</a-select> </a-col>
<a-button type="primary" @click="childOpen = true">新增产品类别</a-button> <a-col :span="24">
</div> <a-form-item :label="'原料组成'" name="compose">
<a-textarea :placeholder="'请输入原料组成'"
v-model:value="formData.compose"></a-textarea>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="24"> <a-col :span="24">
<a-form-item :label="'适用对象'" name="target"> <a-form-item :label="'适用对象'" name="target">
<a-input :placeholder="'请输入适用对象'" v-model:value="formData.target"></a-input> <a-input :placeholder="'请输入适用对象'" v-model:value="formData.target"></a-input>
<!-- <div style="display: flex;justify-content: space-between;">-->
<!-- <a-select v-model:value="formData.target" allowClear>-->
<!-- <a-select-option v-for="item in areaList" :value="item.code">{{ item.targetName }}</a-select-option>-->
<!-- </a-select>-->
<!--&lt;!&ndash; <a-button type="primary" @click="childOpen = true">新增适用对象</a-button>&ndash;&gt;-->
<!-- </div>-->
</a-form-item> </a-form-item>
<!-- <a-form-item :label="'适用对象'" name="target">-->
<!-- <a-textarea :placeholder="'请输入岗位职责'" v-model:value="formData.target"></a-textarea>-->
<!-- </a-form-item>-->
</a-col> </a-col>
<a-col :span="24">
<a-form-item :label="'产品适用对象类别'" name="CategoryRootID"> <a-col :span="12">
<!-- <a-input :placeholder="'请输入产品类别名称'" v-model:value="formData.categoryID"></a-input>--> <a-form-item :label="'产品排序'" name="sequence">
<div style="display: flex;justify-content: space-between;" > <a-input-number v-model:value="formData.sequence" :placeholder="'请输入排序'"
<a-select v-model:value="formData.CategoryRootID" allowClear> style="width: 100%;" />
<a-select-option v-for="item in targetList" :value="item.value">{{ item.targetName }}</a-select-option>
</a-select>
<a-button type="primary" @click="childOpen = true">新增产品适用对象类别</a-button>
</div>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="24"> <a-col :span="12">
<a-form-item :label="'原料组成'" name="compose"> <a-form-item :label="'状态'" name="status">
<a-textarea :placeholder="'请输入原料组成'" v-model:value="formData.compose"></a-textarea> <a-radio-group v-model:value="formData.status" :options="[
{ label: '启用', value: 'enabled' },
{ label: '停用', value: 'disabled' },]"></a-radio-group>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-form-item :label="'产品图片'">
<gx-upload v-model="formData.mainImage" :fileNumber="2" />
</a-form-item>
</a-row>
</a-tab-pane>
<a-tab-pane key="2" tab="产品功能">
<a-col :span="24"> <a-col :span="24">
<a-form-item <a-form-item v-for="(item, index) in formData.feature" :key="index"
v-for="(item, index) in formData.feature"
:key="index"
:label="`产品功能特点 ${index + 1}`"> :label="`产品功能特点 ${index + 1}`">
<a-input <a-input v-model:value="item.label" placeholder="请输入功能特点标题" class="inputPhone" />
v-model:value="item.label" <a-select v-model:value="item.data" mode="tags" :placeholder="'请输入功能特点,按回车区分不同特点'"
placeholder="请输入功能特点标题" :token-separators="[',']" style="width: 100%;" />
class="inputPhone" <a-button danger @click="removeFeature(index)" size="small" style="margin-top: 8px">
/>
<a-select
v-model:value="item.data"
mode="tags"
:placeholder="'请输入功能特点,按回车分隔'"
:token-separators="[',']"
style="width: 100%;"
/>
<a-button
danger
@click="removeFeature(index)"
size="small"
style="margin-top: 8px">
删除 删除
</a-button> </a-button>
</a-form-item> </a-form-item>
@ -82,39 +68,21 @@
新增产品功能特点 新增产品功能特点
</a-button> </a-button>
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-tab-pane>
<a-tab-pane key="3" tab="产品标准">
<a-col :span="24"> <a-col :span="24">
<a-form-item <a-form-item v-for="(item, index) in formData.standard" :key="index"
v-for="(item, index) in formData.standard"
:key="index"
:label="`产品标准 ${index + 1}`"> :label="`产品标准 ${index + 1}`">
<a-input <a-input v-model:value="item.label" placeholder="请输入标准名称" class="inputPhone" />
v-model:value="item.label" <a-input v-model:value="item.fu_hoao" placeholder="请输入符号" class="inputPhone"
placeholder="请输入标准名称" style="margin-top: 8px" />
class="inputPhone" <a-input v-model:value="item.val" placeholder="请输入标准值" class="inputPhone"
/> style="margin-top: 8px" />
<a-input <a-input v-model:value="item.prx" placeholder="请输入标准值单位" class="inputPhone"
v-model:value="item.fu_hoao" style="margin-top: 8px" />
placeholder="请输入符号" <a-button danger @click="removeStandard(index)" size="small"
class="inputPhone"
style="margin-top: 8px"
/>
<a-input
v-model:value="item.val"
placeholder="请输入标准值"
class="inputPhone"
style="margin-top: 8px"
/>
<a-input
v-model:value="item.prx"
placeholder="请输入标准值单位"
class="inputPhone"
style="margin-top: 8px"
/>
<a-button
danger
@click="removeStandard(index)"
size="small"
style="margin-top: 8px"> style="margin-top: 8px">
删除 删除
</a-button> </a-button>
@ -127,99 +95,14 @@
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-tab-pane>
</a-tabs>
<!-- <a-col :span="24">-->
<!-- <a-form-item :label="'产品图片'" name="images">-->
<!-- <gx-upload v-model="formData.images" accept-types=".jpg,.png,.webp" :fileNumber="2" />-->
<!-- </a-form-item>-->
<!-- </a-col>-->
<a-form-item :label="'产品主图'" >
<gx-upload v-model="formData.mainImage" :fileNumber="1" />
</a-form-item>
<a-form-item :label="'内容物图'" >
<gx-upload v-model="formData.contentImage" :fileNumber="1" />
</a-form-item>
<!-- <a-col :span="24">-->
<!-- <a-form-item :label="'产品图片'" name="images">-->
<!-- <gx-upload v-model="formData.images[0]" accept-types=".jpg,.png,.webp" :fileNumber="1" />-->
<!-- </a-form-item>-->
<!-- </a-col>-->
<!-- <a-col :span="24">-->
<!-- <a-form-item :label="'产品内容物图片'" name="images">-->
<!-- <gx-upload v-model="formData.images[1]" accept-types=".jpg,.png,.webp" :fileNumber="1" />-->
<!-- </a-form-item>-->
<!-- </a-col>-->
<a-col :span="24">
<a-form-item :label="'产品排序'" name="sequence">
<a-input-number v-model:value="formData.sequence" :placeholder="'请输入排序'" style="width: 100%;" />
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="'状态'" name="status">
<a-radio-group v-model:value="formData.status" :options="[
{ label: '启用', value: 'enabled' },
{ label: '停用', value: 'disabled' },]"></a-radio-group>
</a-form-item>
</a-col>
</a-row>
</a-card> </a-card>
</a-form> </a-form>
</a-spin> </a-spin>
<a-modal ref="modalRef" v-model:open="childOpen" :wrap-style="{ overflow: 'hidden' }" @ok="handleCombinedOk">
<a-card class="mb-8-2">
<a-form ref="areaFormRef" :model="categoryForm" :rules="areaFormRules">
<a-row :gutter="12">
<a-col :span="24">
<a-form-item :label="'产品类别名称'" name="name">
<a-input v-model:value="categoryForm.name" :placeholder="'请输入产品类别名称'" />
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="'状态'" name="status" style="width: 100%;">
<a-radio-group v-model:value="categoryForm.status" :options="[
{ label: '启用', value: 'enabled' },
{ label: '停用', value: 'disabled' },
]"></a-radio-group>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<template #title>
<div ref="modalTitleRef" style="width: 100%; cursor: move">新增产品类别</div>
</template>
</a-modal> </a-modal>
<a-modal ref="modalRef" v-model:open="childOpen" :wrap-style="{ overflow: 'hidden' }" @ok="handleCombinedOk">
<a-card class="mb-8-2">
<a-form ref="areaFormRef" :model="targetForm" :rules="areaFormRules">
<a-row :gutter="12">
<a-col :span="24">
<a-form-item :label="'产品适用对象类别'" name="name">
<a-input v-model:value="targetForm.name" :placeholder="'请输入产品类别名称'" />
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="'状态'" name="status" style="width: 100%;">
<a-radio-group v-model:value="targetForm.status" :options="[
{ label: '启用', value: 'enabled' },
{ label: '停用', value: 'disabled' },
]"></a-radio-group>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-card>
<template #title>
<div ref="modalTitleRef" style="width: 100%; cursor: move">新增产品类别</div>
</template>
</a-modal>
</a-modal>
</template> </template>
<script setup> <script setup>
@ -227,7 +110,7 @@ import { cloneDeep } from 'lodash-es'
import { ref, onBeforeMount } from 'vue' import { ref, onBeforeMount } from 'vue'
import { config } from '@/config' import { config } from '@/config'
import apis from '@/apis' import apis from '@/apis'
import { useForm, useModal,useSpining } from '@/hooks' import { useForm, useModal, useSpining } from '@/hooks'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
@ -245,7 +128,7 @@ const emit = defineEmits(['ok'])
const { t } = useI18n() // t const { t } = useI18n() // t
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal() const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRecord, formData, formRef, formRules, resetForm } = useForm() const { formRecord, formData, formRef, formRules, resetForm } = useForm()
const { spining,showSpining,hideSpining} = useSpining() const { spining, showSpining, hideSpining } = useSpining()
const cancelText = ref(t('button.cancel')) const cancelText = ref(t('button.cancel'))
const okText = ref(t('button.confirm')) const okText = ref(t('button.confirm'))
const rolesValue = ref([]) const rolesValue = ref([])
@ -254,16 +137,14 @@ const imgUrl = ref('')
const categoryList = ref([]) const categoryList = ref([])
const targetList = ref([]) const targetList = ref([])
const images = ref([]) const images = ref([])
const mainImage = ref([])
const contentImage = ref([]) const contentImage = ref([])
const childOpen = ref(false) const childOpen = ref(false)
const formArea = ref({ name: '', status: 'enabled' })
const categoryForm = ref({ name: '', status: 'enabled' }) const activeKey = ref('1')
const targetForm = ref({ name: '', status: 'enabled' })
formRules.value = { formRules.value = {
title: { required: true, message: '请输入产品类别名称' }, title: { required: true, message: '请输入产品类别名称' },
code: { required: true, message: '请输入产品名称' }, code: { required: true, message: '请输入产品名称' },
categoryID: { required: true, message: '请选择产品类别', trigger: 'change' }, categoryIDs: { required: true, message: '请选择产品类别', trigger: 'change' },
compose: { required: true, message: '请选择产品适用对象', trigger: 'change' }, compose: { required: true, message: '请选择产品适用对象', trigger: 'change' },
feature: [{ required: true, message: '请输入产品功能特点', trigger: 'change' }], feature: [{ required: true, message: '请输入产品功能特点', trigger: 'change' }],
// feature: [{ required: true, message: '' }], // feature: [{ required: true, message: '' }],
@ -273,28 +154,15 @@ formRules.value = {
contentImage: { required: false, message: '请上传产品内容图片' }, contentImage: { required: false, message: '请上传产品内容图片' },
sequence: [{ required: true, message: '请输入产品排序' }], sequence: [{ required: true, message: '请输入产品排序' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }], status: [{ required: true, message: '请选择状态', trigger: 'change' }],
} }
const areaFormRules = {
categoryIDName: [{ required: true, message: '请输入产品类别' }],
targetName: [{ required: true, message: '请输入产品适用对象' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
}
const initData = async () => { const initData = async () => {
try { try {
showSpining(); showSpining();
const { success: prodSuccess, data: prodData } = await apis.categorys.getDataList({ pageSize: 999, page: 1 });
const { success: catSuccess, data: catData } = await apis.products.getProductCategory({ pageSize: 999, page: 1 });
if (config('http.code.success') === catSuccess) {
categoryList.value = catData
.filter(item => item.status === 'enabled')
.map(item => ({ code: item.id, name: item.name }));
}
const { success: prodSuccess, data: prodData } = await apis.products.getProductObj({ pageSize: 999, page: 1 });
if (config('http.code.success') === prodSuccess) { if (config('http.code.success') === prodSuccess) {
targetList.value = prodData categoryList.value = prodData
.filter(item => item.status === 'enabled')
.map(item => ({ code: item.id, name: item.name }));
} }
} catch (error) { } catch (error) {
@ -303,6 +171,7 @@ const initData = async () => {
hideSpining(); hideSpining();
} }
} }
/** /**
* 新建 * 新建
*/ */
@ -314,54 +183,26 @@ function handleCreate() {
// //
formData.value = { formData.value = {
title: '', title: '',
categoryID: '', categoryIDs:'',
compose: '', compose: '',
target: '', target: '',
feature: [{ feature: [{
label:'功能特点', label: '功能特点',
data:[ data: []
// { msg:[''], }
]
}], }],
standard: [{ standard: [{
label: '', label: '',
val: '' , val: '',
fu_hoao: '' , fu_hoao: '',
prx: '' , prx: '',
}], }],
images: [ images: [''],
...(Array.isArray(formData.value.mainImage)
? formData.value.mainImage
: [formData.value.mainImage]
).filter(Boolean).map(item => String(item)),
...(Array.isArray(formData.value.contentImage)
? formData.value.contentImage
: [formData.value.contentImage]
).filter(Boolean).map(item => String(item))
],
sequence: null, sequence: null,
status: 'enabled', status: 'enabled',
} }
initData() initData()
} }
//
const childHandleOk = async () => {
areaFormRef.value.validateFields().then(async (values) => {
try {
const params = { ...categoryForm.value }
const { success } = await apis.products.createProductCategory(params)
if (success) message.success('新增成功')
childOpen.value = false
categoryForm.value = { categoryIDName: '', status: 'enabled' }
initData()
} catch (error) {
message.error(error.message)
}
})
}
// //
const childHandleObjOk = async () => { const childHandleObjOk = async () => {
areaFormRef.value.validateFields().then(async (values) => { areaFormRef.value.validateFields().then(async (values) => {
@ -385,6 +226,7 @@ const handleCombinedOk = () => {
* 编辑 * 编辑
*/ */
async function handleEdit(record = {}) { async function handleEdit(record = {}) {
initData()
showModal({ showModal({
type: 'edit', type: 'edit',
title: t('pages.system.user.edit'), title: t('pages.system.user.edit'),
@ -396,26 +238,20 @@ async function handleEdit(record = {}) {
} }
formData.value = { formData.value = {
...data, ...data,
standard:data.standard|| [{ categoryIDs:data.categoryID,
standard: data.standard || [{
label: '', label: '',
val: '' , val: '',
fu_hoao: '' , fu_hoao: '',
prx: '' , prx: '',
}], }],
feature:data.feature|| [{ feature: data.feature || [{
label:'功能特点', label: '功能特点',
data:[ data: []
// {msg:[''],}
]
}], }],
// images:data.images || [''], // images:data.images || [''],
mainImage: data.images?[config('http.apiBasic')+data.images[0]]:[''], mainImage: data.images ? data.images.map(item=>config('http.apiBasic')+item):[''],
contentImage:data.images?[config('http.apiBasic')+data.images[1]]:[''],
} }
// imgUrl.value = config('http.apiBasic') + data.img
mainImage.value = config('http.apiBasic') + data.images?.[0] ,
contentImage.value = config('http.apiBasic') + data.images?.[1] ,
console.log('编辑产品数据:',formData.value);
} }
/** /**
@ -428,30 +264,17 @@ function handleOk() {
showLoading() showLoading()
const params = { const params = {
...values, ...values,
standard:formData.value.standard || categoryID:formData.value.categoryID,
categoryRootID:formData.value.categoryRootID,
standard: formData.value.standard ||
[{ [{
label: '', label: '',
val: '' , val: '',
fu_hoao: '' , fu_hoao: '',
prx: '' , prx: '',
}], }],
feature:formData.value.feature|| [{ feature: formData.value.feature,
label:'功能特点', images: formData.value.mainImage?formData.value.mainImage.map(item=>spliceUrl(item)):[''],
data:[
// { msg:[''], }
]
}],
images: [
...(Array.isArray(formData.value.mainImage)
? formData.value.mainImage
: [formData.value.mainImage]
).filter(Boolean).map(item => spliceUrl(item)),
...(Array.isArray(formData.value.contentImage)
? formData.value.contentImage
: [formData.value.contentImage]
).filter(Boolean).map(item => spliceUrl(item))
],
} }
let result = null let result = null
switch (modal.value.type) { switch (modal.value.type) {
@ -526,8 +349,52 @@ function removeFeature(index) {
formData.value.feature.splice(index, 1) formData.value.feature.splice(index, 1)
} }
} }
//
const findNodePath = (tree, value, path = []) => {
for (const node of tree) {
const currentPath = [...path, node.value];
if (node.value === value) return currentPath;
if (node.children) {
const found = findNodePath(node.children, value, currentPath);
if (found) return found;
}
}
return null;
};
//
const isLeafNode = (id) => {
const node = findNodeById(categoryList.value, id);
if(node.children.length>0) return false;
else return true
};
// ID
const findNodeById = (tree, value) => {
for (const node of tree) {
if (node.value === value) return node;
if(node.children){
const found=findNodeById(node.children,value)
if(found) return found;
}
}
return null;
};
//
const handleTreeSelectChange = (value) => {
//
if (!isLeafNode(value)) {
message.warning('只能选择最后一级节点');
formData.value.categoryID = null; //
return;
}
if (!value) return;
const pathIds = findNodePath(categoryList.value, value);
if (pathIds) {
console.log('选中的路径ID数组:', pathIds);
// 使 pathIds
formData.value.categoryID=pathIds[1]
formData.value.categoryRootID=pathIds[0]
}
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped></style>
</style>

View File

@ -49,7 +49,6 @@
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading" <a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange"> :pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'title'"> <template v-if="column.dataIndex === 'title'">
<a-tooltip :title="record.title"> <a-tooltip :title="record.title">
<div class="text-ellipsis">{{ record.title }}</div> <div class="text-ellipsis">{{ record.title }}</div>
@ -123,40 +122,31 @@ defineOptions({
}) })
const { t } = useI18n() // t const { t } = useI18n() // t
const columns = [ const columns = [
{ title: '产品名称', dataIndex: 'code', width: 120 }, { title: '产品名称', dataIndex: 'code', width: 120, ellipsis:true},
{ title: '产品类别名称', dataIndex: 'title', width: 120 }, { title: '产品类别', dataIndex: 'categoryID', key: 'categoryID', width: 120 },
{ title: '产品类别ID', dataIndex: 'categoryID', key: 'categoryID', 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: '原料组成', dataIndex: 'compose', key: 'compose', width: 120 },
{ // {
title: '功能特点', // title: '',
dataIndex: 'feature', // dataIndex: 'standard',
width: 120, // width: 120,
align: 'center', // align: 'center',
customRender: ({ text }) => Array.isArray(text) ? text.join(', ') : '' // customRender: ({ text }) => Array.isArray(text)
}, // ? text.map(item => `${item.label}: ${item.fu_hoao}${item.val}${item.prx}`).join(', ')
{ // : ''
title: '产品标准', // },
dataIndex: 'standard', // {
width: 120, // title: '',
align: 'center', // dataIndex: 'mainImage',
customRender: ({ text }) => Array.isArray(text) // width: 120,
? text.map(item => `${item.label}: ${item.fu_hoao}${item.val}${item.prx}`).join(', ') // align: 'center',
: '' // },
}, // {
{ // title: '',
title: '产品图片', // dataIndex: 'contentImage',
dataIndex: 'mainImage', // width: 120,
width: 120, // align: 'center',
align: 'center', // },
},
{
title: '产品内容图片',
dataIndex: 'contentImage',
width: 120,
align: 'center',
},
{ title: '产品排序', dataIndex: 'sequence', width: 120, align: 'center' }, { title: '产品排序', dataIndex: 'sequence', width: 120, align: 'center' },
{ title: '产品状态', dataIndex: 'status', width: 120, align: 'center' }, { title: '产品状态', dataIndex: 'status', width: 120, align: 'center' },
@ -188,12 +178,7 @@ async function getPageList() {
if (config('http.code.success') === success) { if (config('http.code.success') === success) {
listData.value = data.map(item => ({ listData.value = data.map(item => ({
...item, ...item,
mainImage: item.images?.[0] || '',
contentImage: item.images?.[1] || '',
})) }))
console.log('接口数据', data)
console.log('接口过滤数据', listData.value)
paginationState.total = total paginationState.total = total
} }
} catch (error) { } catch (error) {
@ -258,7 +243,6 @@ function handleResetSearch() {
* 编辑完成 * 编辑完成
*/ */
async function onOk() { async function onOk() {
message.success(t('component.message.success.delete'))
await getPageList() await getPageList()
} }
</script> </script>

View File

@ -0,0 +1,146 @@
<template>
<a-modal :open="modal.open" :title="modal.title" :width="640" :confirm-loading="modal.confirmLoading"
:after-close="onAfterClose" :cancel-text="cancelText" :ok-text="okText" @ok="handleOk" @cancel="handleCancel">
<a-spin :spinning="spining">
<a-form ref="formRef" :model="formData" :rules="formRules">
<a-card class="mb-8-2">
<a-row :gutter="12">
<a-col :span="24">
<a-form-item :label="'父级分类'" name="parentID">
<a-tree-select v-model:value="formData.parentID" show-search style="width: 100%"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" placeholder="请选择"
allow-clear tree-default-expand-all :tree-data="treeData"
tree-node-filter-prop="label">
</a-tree-select>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item :label="'产品分类'" name="label">
<a-input :placeholder="'请输入产品分类名称'" v-model:value="formData.label"></a-input>
</a-form-item>
</a-col>
</a-row>
</a-card>
</a-form>
</a-spin>
</a-modal>
</template>
<script setup>
import { cloneDeep } from 'lodash-es'
import { ref, onBeforeMount } from 'vue'
import { config } from '@/config'
import apis from '@/apis'
import { useForm, useModal, useSpining } from '@/hooks'
import { message } from 'ant-design-vue'
import { useI18n } from 'vue-i18n'
import { spliceUrl } from '@/utils/util'
const areaFormRef = ref()
const emit = defineEmits(['ok'])
const { t } = useI18n() // t
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
const { spining, showSpining, hideSpining } = useSpining()
const cancelText = ref(t('button.cancel'))
const okText = ref(t('button.confirm'))
const treeData=ref([])
formRules.value = {
label: { required: true, message: '请输入产品类别名称' },
}
const initData = async () => {
const { success, data, total } = await apis.categorys
.getDataList({
pageSize:99,
page: 1,
})
.catch(() => {
throw new Error()
})
if (config('http.code.success') === success) {
treeData.value = data.map(item => ({
...item
}))
}
}
/**
* 新建
*/
function handleCreate() {
showModal({
type: 'create',
title: '产品分类',
})
//
initData()
}
/**
* 确定
*/
function handleOk() {
formRef.value.validateFields().then(async (values) => {
try {
showLoading()
const params = {
...values,
parentID:formData.value.parentID?formData.value.parentID:0
}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.categorys.createProductsItem(params).catch((error) => {
throw new Error(error)
})
break
case 'edit':
result = await apis.products.updateProductsItem(formData.value.id, params).catch(() => {
throw new Error(error)
})
break
}
hideLoading()
if (config('http.code.success') === result?.success) {
hideModal()
emit('ok')
}
} catch (error) {
message.error({ content: error.message })
hideLoading()
}
})
.catch((e) => {
console.log(e)
hideLoading()
})
}
/**
* 取消
*/
function handleCancel() {
hideModal()
}
/**
* 关闭后
*/
function onAfterClose() {
resetForm()
hideLoading()
}
defineExpose({
handleCreate,
})
</script>
<style lang="less" scoped></style>

View File

@ -0,0 +1,154 @@
<template>
<a-row :gutter="8" :wrap="false">
<a-col flex="auto">
<a-card type="flex">
<x-action-bar class="mb-8-2">
<a-button type="primary" @click="$refs.editDialogRef.handleCreate()">
<template #icon>
<plus-outlined></plus-outlined>
</template>
新增分类
</a-button>
</x-action-bar>
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
:pagination="paginationState" @change="onTableChange">
<template #bodyCell="{ column, record }">
<template v-if="'status' === column.dataIndex">
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
</template>
<template v-if="'action' === column.key">
<x-action-button @click="handleDelete(record.value)">
<a-tooltip>
<template #title>{{ $t('pages.system.delete') }}</template>
<delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
</template>
</template>
</a-table>
</a-card>
</a-col>
</a-row>
<edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
</template>
<script setup>
import { message, Modal } from 'ant-design-vue'
import { ref } from 'vue'
import apis from '@/apis'
import { formatUtcDateTime } from '@/utils/util'
import { config } from '@/config'
import { statusUserTypeEnum } from '@/enums/system'
import { usePagination } from '@/hooks'
import EditDialog from './components/EditDialog.vue'
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import { useI18n } from 'vue-i18n'
import { delProductsItem, getProductsList } from '@/apis/modules/products'
defineOptions({
name: 'productType',
})
const { t } = useI18n() // t
const columns = [
{ title: '分类名称', dataIndex: 'label' },
// { title: '', dataIndex: 'status', width: 120, align: 'center' },
{ title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' },
]
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
usePagination()
const editDialogRef = ref()
getPageList()
/**
* 获取用户列表
* @returns {Promise<void>}
*/
async function getPageList() {
try {
showLoading()
const { pageSize, current } = paginationState
const { success, data, total } = await apis.categorys
.getDataList({
pageSize,
page: current,
})
.catch(() => {
throw new Error()
})
hideLoading()
if (config('http.code.success') === success) {
listData.value = data.map(item => ({
...item,
key:item.value
}))
paginationState.total = total
}
} catch (error) {
hideLoading()
}
}
/**
* 删除
*/
function handleDelete(value) {
Modal.confirm({
title: '确定删除该分类吗',
content: t('button.confirm'),
okText: t('button.confirm'),
onOk: () => {
return new Promise((resolve, reject) => {
; (async () => {
try {
const { success } = await apis.categorys.delProductsItem(value).catch(() => {
throw new Error()
})
if (config('http.code.success') === success) {
resolve()
message.success(t('component.message.success.delete'))
await getPageList()
}
} catch (error) {
reject()
}
})()
})
},
})
}
/**
* 分页
*/
function onTableChange({ current, pageSize }) {
paginationState.current = current
paginationState.pageSize = pageSize
getPageList()
}
/**
* 搜索
*/
function handleSearch() {
resetPagination()
getPageList()
}
/**
* 重置
*/
function handleResetSearch() {
searchFormData.value = {}
resetPagination()
getPageList()
}
/**
* 编辑完成
*/
async function onOk() {
await getPageList()
}
</script>
<style lang="less" scoped></style>

View File

@ -67,7 +67,7 @@ import { useForm, useModal } from '@/hooks'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { createMenu, getMenu, updateMenu } from '@/apis/modules/webSite'
const emit = defineEmits(['ok']) const emit = defineEmits(['ok'])
const { t } = useI18n() // t const { t } = useI18n() // t
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal() const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()