feat: 新增工作台分类编辑、删除接口调试

This commit is contained in:
wanglihui 2024-01-13 18:58:40 +08:00
parent c36831a211
commit d354ce6b73
4 changed files with 150 additions and 25 deletions

View File

@ -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({ return request({
url: '/manager/workplace/category/reorder', url: '/manager/workplace/category/reorder',
method: 'put', method: 'put',

View File

@ -26,12 +26,20 @@
import { ref } from 'vue'; import { ref } from 'vue';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
// API // API
import { categoryPost } from '@/api/workplace/category'; import { categoryPost, categoryPut } from '@/api/workplace/category';
interface IProps { interface IProps {
value: boolean; value: boolean;
type: 'add' | 'edit';
data: {
category_no?: string;
name?: string;
sort_num?: number;
};
} }
const props = withDefaults(defineProps<IProps>(), { const props = withDefaults(defineProps<IProps>(), {
value: false value: false,
title: '新增分类',
type: 'add'
}); });
const content = ref(''); const content = ref('');
@ -47,17 +55,21 @@ watch(
(n, _o) => { (n, _o) => {
console.log(props.value); console.log(props.value);
props.value = n; props.value = n;
if (n && props.type == 'edit') {
content.value = props.data?.name || '';
}
if (!n) {
content.value = '';
}
} }
); );
// //
const onClose = () => { const onClose = () => {
emits('update:value', false); emits('update:value', false);
}; };
//
const onSend = () => { //
if (!content.value) { const addCategor = () => {
return ElMessage.info('请输入分类!');
}
const fromData = { const fromData = {
name: content.value name: content.value
}; };
@ -66,7 +78,7 @@ const onSend = () => {
.then((res: any) => { .then((res: any) => {
loaging.value = false; loaging.value = false;
if (res.status == 200) { if (res.status == 200) {
ElMessage.success('新增分类成功!'); ElMessage.success('编辑分类成功!');
content.value = ''; content.value = '';
onClose(); onClose();
emits('ok', true); 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();
}
};
</script> </script>

View File

@ -5,7 +5,7 @@
<div class="h-50px pl-12px pr-12px box-border flex items-center justify-between bd-title"> <div class="h-50px pl-12px pr-12px box-border flex items-center justify-between bd-title">
<div class="bd-title-left font-500 text-14px">分组</div> <div class="bd-title-left font-500 text-14px">分组</div>
<div class="flex items-center h-50px"> <div class="flex items-center h-50px">
<i-bd-add :size="22" class="cursor-pointer" @click="categoryDialogValue = true" /> <i-bd-add :size="22" class="cursor-pointer" @click="onCategoryAdd" />
</div> </div>
</div> </div>
<div class="m-12px"> <div class="m-12px">
@ -26,8 +26,8 @@
</div> </div>
<div class="flex-1 text">{{ item.name }}</div> <div class="flex-1 text">{{ item.name }}</div>
<div class="bd-opt"> <div class="bd-opt">
<i-bd-editor :size="16" class="cursor-pointer pr-4px" /> <i-bd-editor :size="16" class="cursor-pointer pr-4px" @click.stop="onCategoryEdit(item)" />
<i-bd-delete :size="16" class="cursor-pointer" /> <i-bd-delete :size="16" class="cursor-pointer" @click.stop="onCategoryDelete(item)" />
</div> </div>
</div> </div>
</div> </div>
@ -78,7 +78,13 @@
<!-- E 右侧 表格 --> <!-- E 右侧 表格 -->
<!-- 新增分类 --> <!-- 新增分类 -->
<CategoryDialog v-model:value="categoryDialogValue" @ok="onCategoryOk" /> <CategoryDialog
v-model:value="categoryValue"
:type="categoryType"
:title="categoryTitle"
:data="categoryData"
@ok="onCategoryOk"
/>
<!-- 添加应用 --> <!-- 添加应用 -->
<AppDialog v-model:value="appDialogValue" :data="appDialogData" @ok="onAppDialogOk" /> <AppDialog v-model:value="appDialogValue" :data="appDialogData" @ok="onAppDialogOk" />
@ -93,7 +99,14 @@ import AppDialog from './AppDialog.vue';
import { BU_DOU_CONFIG } from '@/config'; import { BU_DOU_CONFIG } from '@/config';
// API // API
import { categoryGet, categoryPut, categoryAppGet, categoryAppDelete, categorysAppsReorderPut } from '@/api/workplace/category'; import {
categoryGet,
categoryDelete,
categoryReorderPut,
categoryAppGet,
categoryAppDelete,
categorysAppsReorderPut
} from '@/api/workplace/category';
interface Tree { interface Tree {
category_no: string; category_no: string;
@ -103,7 +116,6 @@ interface Tree {
/** /**
* 左侧分类 * 左侧分类
*/ */
const categoryDialogValue = ref<boolean>(false);
const dataTree = ref<Tree[]>([]); const dataTree = ref<Tree[]>([]);
const optTree = ref(''); const optTree = ref('');
const keyword = ref(''); const keyword = ref('');
@ -128,12 +140,12 @@ const onOptTreeClick = (no: string) => {
const onCategoryOk = () => { const onCategoryOk = () => {
getCategoryData(); getCategoryData();
}; };
//
const categoryReorder = (newIndex: string, oldIndex: string) => { const categoryReorder = (newIndex: string, oldIndex: string) => {
const fromData = { const fromData = {
category_nos: [newIndex, oldIndex] category_nos: [newIndex, oldIndex]
}; };
categoryPut(fromData).then(res => { categoryReorderPut(fromData).then(res => {
if (res.status == 200) { if (res.status == 200) {
getCategoryData(); getCategoryData();
ElMessage({ 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: '取消成功!'
});
});
};
/** /**
* 添加应用 * 添加应用
*/ */

View File

@ -18,7 +18,6 @@ meta:
<script lang="tsx" setup> <script lang="tsx" setup>
import Banner from './components/Banner.vue'; import Banner from './components/Banner.vue';
import Recommend from './components/Recommend.vue';
import CustomGroup from './components/CustomGroup.vue'; import CustomGroup from './components/CustomGroup.vue';
const activeName = ref('banner'); const activeName = ref('banner');
@ -31,13 +30,6 @@ const tabsData = reactive([
return <Banner />; return <Banner />;
} }
}, },
{
name: 'recommend',
label: '管理员推荐',
render: () => {
return <Recommend />;
}
},
{ {
name: 'custom-group', name: 'custom-group',
label: '自定义分组', label: '自定义分组',