diff --git a/.env.test b/.env.test index 6bbe541..0110621 100644 --- a/.env.test +++ b/.env.test @@ -2,5 +2,5 @@ VITE_BASE_URL=/ # backend service base url, test environment # VITE_SERVICE_BASE_URL=http://localhost:8080/snail-job -# VITE_SERVICE_BASE_URL=http://10.18.190.195:8080/snail-job -VITE_SERVICE_BASE_URL=http://10.21.21.29:8080/snail-job +VITE_SERVICE_BASE_URL=http://10.18.190.195:8080/snail-job +# VITE_SERVICE_BASE_URL=http://10.21.21.29:8080/snail-job diff --git a/src/locales/langs/en-us.ts b/src/locales/langs/en-us.ts index d3675d7..b9c6f27 100644 --- a/src/locales/langs/en-us.ts +++ b/src/locales/langs/en-us.ts @@ -488,7 +488,7 @@ const local: App.I18n.Schema = { name: 'Please enter category name', categoryName: 'Category Name', categoryStatus: 'Please select category status', - categoryParentName: 'Category ID', + categoryParentName: 'Category Name', categoryType: 'Category Type', createTime: 'Create Time' }, diff --git a/src/locales/langs/zh-cn.ts b/src/locales/langs/zh-cn.ts index 8af3914..bb55b9a 100644 --- a/src/locales/langs/zh-cn.ts +++ b/src/locales/langs/zh-cn.ts @@ -498,7 +498,7 @@ const local: App.I18n.Schema = { name: '请输入分类名称', categoryName: '分类名称', categoryStatus: '分类状态', - categoryParentName: '父级ID', + categoryParentName: '父级名称', categoryType: '分类类型', createTime: '创建时间' }, diff --git a/src/service/api/category.ts b/src/service/api/category.ts index b139492..c8d7405 100644 --- a/src/service/api/category.ts +++ b/src/service/api/category.ts @@ -25,7 +25,7 @@ export function fetchAddCategory(data: Api.Category.Model) { url: '/category', method: 'post', data:{ - parentId: data.parent, + parentId: data.id, categoryName: data.name, categoryType: parseInt(data.type) } @@ -39,7 +39,7 @@ export function fetchEditCategory(data: Api.Category.Model) { method: 'put', data:{ id: data.id, - parentId: data.parent, + parentId: data.parentId, categoryName: data.name, categoryType: parseInt(data.type) } diff --git a/src/service/api/group.ts b/src/service/api/group.ts index c78940f..77a394b 100644 --- a/src/service/api/group.ts +++ b/src/service/api/group.ts @@ -18,18 +18,18 @@ export function fetchGetAllGroupNameList(params?: Api.GroupConfig.GroupConfigSea } /** add groupConfig */ -export function fetchAddGroupConfig(data: Api.GroupConfig.GroupConfigRequestVO) { +export function fetchAddGroupConfig(data: Api.GroupConfig.GroupConfigRequestVO, type: string) { return request({ - url: '/group', + url: `/group?categoryId=${type}`, method: 'post', data }); } /** edit groupConfig */ -export function fetchEditGroupConfig(data: Api.GroupConfig.GroupConfigRequestVO) { +export function fetchEditGroupConfig(data: Api.GroupConfig.GroupConfigRequestVO, type: string) { return request({ - url: '/group', + url: `/group?categoryId=${type}`, method: 'put', data }); diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index 207e85b..bc3d36a 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -1366,7 +1366,7 @@ declare namespace Api { * backend api module: "Category" */ namespace Category { - type CategoryType = '1' | '2'; + // type CategoryType = '1' | '2'; type CategorySearchParams = { categoryName?: string | null, @@ -1379,19 +1379,21 @@ declare namespace Api { categoryName: string; level: string; createTime: string; - categoryType: CategoryType; + // categoryType: CategoryType; + categoryType: string; + } + + type Model = { + id: number; + parentId: number; + name: string; + type: string; + parentName: string; } type RowData = Category & { children?: RowData[]; }; - - interface Model { - id: number; - name: string; - type: string; - parent: string; - } } namespace Common { type DateRangeParams = { diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 08ad8c1..fd5afcc 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -34,6 +34,21 @@ async function init() { }; return dict; } -const dict = await init(); -export default dict; +function getDictLabel(dictData: indexAbleDictData[], dictValue: string) { + let label = ''; + if (dictData && dictData.length > 0) { + dictData.forEach(item => { + if (item.value == dictValue) { + label = item.label; + } + }); + } + return label; +} + + + +const dict:indexAbleDict = await init(); + +export { dict, getDictLabel }; diff --git a/src/views/category/index.vue b/src/views/category/index.vue index ed364e7..77abcd9 100644 --- a/src/views/category/index.vue +++ b/src/views/category/index.vue @@ -79,11 +79,19 @@ const { // 表头添加操作 const headAdd = () => { - handleAdd(0); + let item: Api.Category.RowData = { + id: 0, + parentId: 0, + categoryName: "暂无父类", + level: "", + createTime: "", + categoryType: "1" + }; + handleAdd(item); } // 行添加操作 const Add = (item: Api.Category.RowData) => { - handleAdd(item.id); + handleAdd(item); } // 行编辑操作 const Edit = (item: Api.Category.RowData) => { diff --git a/src/views/category/modules/category-operate-drawer.vue b/src/views/category/modules/category-operate-drawer.vue index 2203a9d..364fc6d 100644 --- a/src/views/category/modules/category-operate-drawer.vue +++ b/src/views/category/modules/category-operate-drawer.vue @@ -7,7 +7,7 @@ import { $t } from '@/locales'; import { useAuthStore } from '@/store/modules/auth'; import { fetchAddCategory, fetchEditCategory } from '@/service/api' // import { categoryTypeOptions } from '@/constants/business'; -import dict from '@/utils/dict'; +import { dict } from '@/utils/dict'; // 定义组件选项 defineOptions({ @@ -27,7 +27,7 @@ interface Emits { (e: 'submitted'): void; } -let key = "字典类型"; +let key = "web_category"; const categoryTypeOptions = ref([ { value: '1', label: '网站' }, @@ -56,42 +56,40 @@ const title = computed(() => { return titles[props.operateType]; }); -const model: Api.Category.Model = reactive(createDefaultModel()); -function updateModel(id: number, categoryName: string, categoryType: string, parentId: number) { - model.id = id; - model.name = categoryName; - model.type = categoryType; - model.parent = parentId.toString(); // 确保类型匹配 -} -function createDefaultModel(): Api.Category.Model { - return { - id: 0, - name: '', - type: '', - parent: '' - }; -} +const model: Api.Category.Model = reactive({ + id: 0, + parentId: 0, + name: '', + type: '1', + parentName: '' +}); // 定义表单验证规则 type RuleKey = Extract; const rules: Record = { + id: defaultRequiredRule, + parentId: defaultRequiredRule, name: defaultRequiredRule, type: defaultRequiredRule, - parent: defaultRequiredRule + parentName: defaultRequiredRule }; // 监听抽屉的可见性,当抽屉打开时,更新表单模型 function handleUpdateModelWhenEdit() { - if (props.operateType === 'add') { - const { id, parentId } = props.rowData!; - updateModel(id, '', '1', parentId); + if (props.operateType === 'add' && props.rowData) { + model.parentId = props.rowData.id; + model.name = ''; + model.type = '1'; + + model.parentName = props.rowData.categoryName; console.log(model); return; } if (props.operateType === 'edit' && props.rowData) { - const { id, categoryName, categoryType, parentId } = props.rowData; - updateModel(id, categoryName, categoryType.toString(), parentId); + model.id = props.rowData.id; + model.name = props.rowData.categoryName; + model.type = props.rowData.categoryType; console.log(model); } } @@ -185,8 +183,8 @@ async function handleCopy(source: string) { :options="translateOptions(categoryTypeOptions)" clearable /> --> - - + + diff --git a/src/views/category/modules/category.vue b/src/views/category/modules/category.vue index 8c15d3b..e2c107a 100644 --- a/src/views/category/modules/category.vue +++ b/src/views/category/modules/category.vue @@ -1,8 +1,9 @@