From d354ce6b73c5dd4fc825d7fb234ce8a2e335bade Mon Sep 17 00:00:00 2001 From: wanglihui <1769794040@qq.com> Date: Sat, 13 Jan 2024 18:58:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8F=B0=E5=88=86=E7=B1=BB=E7=BC=96=E8=BE=91=E3=80=81=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/workplace/category.ts | 19 ++++- .../components/CategoryDialog.vue | 67 +++++++++++++-- .../configuration/components/CustomGroup.vue | 81 +++++++++++++++++-- src/pages/workplace/configuration/index.vue | 8 -- 4 files changed, 150 insertions(+), 25 deletions(-) diff --git a/src/api/workplace/category.ts b/src/api/workplace/category.ts index af268f5..d1067fe 100644 --- a/src/api/workplace/category.ts +++ b/src/api/workplace/category.ts @@ -18,8 +18,25 @@ export function categoryPost(data: any) { }); } +// 分类编辑 +export function categoryPut(data: any, category_no: string) { + return request({ + url: `/manager/workplace/categorys/${category_no}`, + method: 'put', + data + }); +} + +// 删除分类 +export function categoryDelete(category_no: string) { + return request({ + url: `/manager/workplace/categorys/${category_no}`, + method: 'delete' + }); +} + // 分类排序 -export function categoryPut(data: any) { +export function categoryReorderPut(data: any) { return request({ url: '/manager/workplace/category/reorder', method: 'put', diff --git a/src/pages/workplace/configuration/components/CategoryDialog.vue b/src/pages/workplace/configuration/components/CategoryDialog.vue index a4c43fc..fa025d1 100644 --- a/src/pages/workplace/configuration/components/CategoryDialog.vue +++ b/src/pages/workplace/configuration/components/CategoryDialog.vue @@ -26,12 +26,20 @@ import { ref } from 'vue'; import { ElMessage } from 'element-plus'; // API 接口 -import { categoryPost } from '@/api/workplace/category'; +import { categoryPost, categoryPut } from '@/api/workplace/category'; interface IProps { value: boolean; + type: 'add' | 'edit'; + data: { + category_no?: string; + name?: string; + sort_num?: number; + }; } const props = withDefaults(defineProps(), { - value: false + value: false, + title: '新增分类', + type: 'add' }); const content = ref(''); @@ -47,17 +55,21 @@ watch( (n, _o) => { console.log(props.value); props.value = n; + if (n && props.type == 'edit') { + content.value = props.data?.name || ''; + } + if (!n) { + content.value = ''; + } } ); // 取消 const onClose = () => { emits('update:value', false); }; -// 发送 -const onSend = () => { - if (!content.value) { - return ElMessage.info('请输入分类!'); - } + +// 新增分类 +const addCategor = () => { const fromData = { name: content.value }; @@ -66,7 +78,7 @@ const onSend = () => { .then((res: any) => { loaging.value = false; if (res.status == 200) { - ElMessage.success('新增分类成功!'); + ElMessage.success('编辑分类成功!'); content.value = ''; onClose(); emits('ok', true); @@ -79,4 +91,43 @@ const onSend = () => { } }); }; +// 编辑分类 +const editCategor = () => { + const fromData = { + name: content.value + }; + loaging.value = true; + const category_no = (props.data as any).category_no; + categoryPut(fromData, category_no) + .then((res: any) => { + loaging.value = false; + if (res.status == 200) { + ElMessage.success('编辑分类成功!'); + content.value = ''; + onClose(); + emits('ok', true); + } + }) + .catch(err => { + loaging.value = false; + if (err.status == 400) { + ElMessage.error(err.msg); + } + }); +}; + +// 保存 +const onSend = () => { + if (!content.value) { + return ElMessage.info('请输入分类!'); + } + // 新增 + if (props.type === 'add') { + addCategor(); + } + // 编辑 + if (props.type === 'edit') { + editCategor(); + } +}; diff --git a/src/pages/workplace/configuration/components/CustomGroup.vue b/src/pages/workplace/configuration/components/CustomGroup.vue index ec56f17..e8ffb29 100644 --- a/src/pages/workplace/configuration/components/CustomGroup.vue +++ b/src/pages/workplace/configuration/components/CustomGroup.vue @@ -5,7 +5,7 @@
分组
- +
@@ -26,8 +26,8 @@
{{ item.name }}
- - + +
@@ -78,7 +78,13 @@ - + @@ -93,7 +99,14 @@ import AppDialog from './AppDialog.vue'; import { BU_DOU_CONFIG } from '@/config'; // API接口 -import { categoryGet, categoryPut, categoryAppGet, categoryAppDelete, categorysAppsReorderPut } from '@/api/workplace/category'; +import { + categoryGet, + categoryDelete, + categoryReorderPut, + categoryAppGet, + categoryAppDelete, + categorysAppsReorderPut +} from '@/api/workplace/category'; interface Tree { category_no: string; @@ -103,7 +116,6 @@ interface Tree { /** * 左侧分类 */ -const categoryDialogValue = ref(false); const dataTree = ref([]); const optTree = ref(''); const keyword = ref(''); @@ -128,12 +140,12 @@ const onOptTreeClick = (no: string) => { const onCategoryOk = () => { getCategoryData(); }; - +// 分类排序 const categoryReorder = (newIndex: string, oldIndex: string) => { const fromData = { category_nos: [newIndex, oldIndex] }; - categoryPut(fromData).then(res => { + categoryReorderPut(fromData).then(res => { if (res.status == 200) { getCategoryData(); ElMessage({ @@ -163,6 +175,59 @@ const treesDrop = () => { }); }; +const categoryValue = ref(false); +const categoryTitle = ref('新增分类'); +const categoryType = ref<'add' | 'edit'>('add'); +const categoryData = ref({}); + +// 分类新增 +const onCategoryAdd = () => { + categoryValue.value = true; + categoryTitle.value = '新增分类'; + categoryType.value = 'add'; + categoryData.value = {}; +}; + +// 分类编辑 +const onCategoryEdit = (item: any) => { + console.log(item); + categoryValue.value = true; + categoryTitle.value = '编辑分类'; + categoryType.value = 'edit'; + categoryData.value = { ...item }; +}; + +// 分类删除 +const onCategoryDelete = (item: any) => { + ElMessageBox.confirm(`确定要对该分类吗?`, `操作提示`, { + confirmButtonText: '确定', + cancelButtonText: '取消', + closeOnClickModal: false, + type: 'warning' + }) + .then(() => { + categoryDelete(item.category_no) + .then((_res: any) => { + getCategoryData(); + ElMessage({ + type: 'success', + message: `轮播删除成功!` + }); + }) + .catch(err => { + if (err.status == 400) { + ElMessage.error(err.msg); + } + }); + }) + .catch(() => { + ElMessage({ + type: 'info', + message: '取消成功!' + }); + }); +}; + /** * 添加应用 */ diff --git a/src/pages/workplace/configuration/index.vue b/src/pages/workplace/configuration/index.vue index 55890f0..8a6696e 100644 --- a/src/pages/workplace/configuration/index.vue +++ b/src/pages/workplace/configuration/index.vue @@ -18,7 +18,6 @@ meta: