Browse Source

update: template dict model,api,page

dev
powersir 1 year ago
parent
commit
c04f570b63
4 changed files with 86 additions and 37 deletions
  1. +0
    -1
      src/models/index.ts
  2. +8
    -0
      src/models/template.data.ts
  3. +61
    -34
      src/pages/custom/template/dict/index.tsx
  4. +17
    -2
      src/request/service/template-dict.ts

+ 0
- 1
src/models/index.ts View File

@@ -16,7 +16,6 @@ export * from './category.data.ts'
export * from './material-classify.data.ts' export * from './material-classify.data.ts'
export * from './goods-classify.data.ts' export * from './goods-classify.data.ts'
export * from './goods-attr.data.ts' export * from './goods-attr.data.ts'
export * from './platform-template.data.ts'


export interface ResponseDTO<T>{ export interface ResponseDTO<T>{
code: number; code: number;


+ 8
- 0
src/models/template.data.ts View File

@@ -3,6 +3,7 @@ export interface DataDictVO{
description: string; description: string;
id: number; id: number;
name: string; name: string;
createTime?: number;
} }


//数据字典详情 //数据字典详情
@@ -14,6 +15,13 @@ export interface DataDictDetailVO {
value: string; value: string;
} }


export interface DataDictPageReqVO extends PageParam {
createTime?: string[];
description?: string;
name?: string;
}




/** /**
* TemplateInfoVO,模板数据 * TemplateInfoVO,模板数据


+ 61
- 34
src/pages/custom/template/dict/index.tsx View File

@@ -1,4 +1,4 @@
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useEffect } from 'react';
import { Space, Table, Button, Image, Divider, Card, Input } from 'antd'; import { Space, Table, Button, Image, Divider, Card, Input } from 'antd';
import type { InputRef } from 'antd'; import type { InputRef } from 'antd';
import type { ColumnType, ColumnsType } from 'antd/es/table'; import type { ColumnType, ColumnsType } from 'antd/es/table';
@@ -6,27 +6,29 @@ import type { FilterConfirmProps, TableRowSelection } from 'antd/es/table/interf
import { t } from '@/utils/i18n'; import { t } from '@/utils/i18n';
import { PlusOutlined, ExclamationCircleFilled, DeleteOutlined, SearchOutlined } from '@ant-design/icons'; import { PlusOutlined, ExclamationCircleFilled, DeleteOutlined, SearchOutlined } from '@ant-design/icons';
import { antdUtils } from '@/utils/antd'; import { antdUtils } from '@/utils/antd';
import { useRequest } from '@/hooks/use-request';
import { DataDictVO, DataDictDetailVO } from '@/models'; import { DataDictVO, DataDictDetailVO } from '@/models';
import DictEditor from './dict-editor'; import DictEditor from './dict-editor';
import DictDetailEditor from './dict-detail-editor'; import DictDetailEditor from './dict-detail-editor';
import templateDictService from '@/request/service/template-dict';


const dataDicts: DataDictVO[] = [
{
"id": 43,
"name": "爆款词",
"description": "爆款词"
},
{
"id": 42,
"name": "T-T",
"description": "t-shirt"
},
{
"id": 41,
"name": "T-shirt Background",
"description": "T桖背景"
}
]
// const dataDicts: DataDictVO[] = [
// {
// "id": 43,
// "name": "爆款词",
// "description": "爆款词"
// },
// {
// "id": 42,
// "name": "T-T",
// "description": "t-shirt"
// },
// {
// "id": 41,
// "name": "T-shirt Background",
// "description": "T桖背景"
// }
// ]


const dictDetailsA: DataDictDetailVO[] = [ const dictDetailsA: DataDictDetailVO[] = [
{ {
@@ -117,7 +119,9 @@ const dictDetailsC: DataDictDetailVO[] = [


export default () => { export default () => {


const [dataDicts, setDataDicts] = useState<DataDictVO[]>();
const [dictDetail, setDictDetail] = useState<DataDictDetailVO[]>(); const [dictDetail, setDictDetail] = useState<DataDictDetailVO[]>();
const [total, setTotal] = useState(0);


const [editorVisable, seEditorVisable] = useState<boolean>(false); const [editorVisable, seEditorVisable] = useState<boolean>(false);
const [editData, seEditData] = useState<DataDictVO>(); const [editData, seEditData] = useState<DataDictVO>();
@@ -125,6 +129,23 @@ export default () => {
const [detailEditorVisable, seEdtailEditorVisable] = useState<boolean>(false); const [detailEditorVisable, seEdtailEditorVisable] = useState<boolean>(false);
const [editDetailData, seEditDetailData] = useState<DataDictDetailVO>(); const [editDetailData, seEditDetailData] = useState<DataDictDetailVO>();


//获取字典分页数据
const { runAsync: getDictPageApi } = useRequest(templateDictService.getDictPageApi, { manual: true });
//删除字典数据
const { runAsync: deleteDictApi } = useRequest(templateDictService.deleteDictApi, { manual: true });

const load = async () => {
const [error, { data }] = await getDictPageApi();
if (!error) {
setDataDicts(data.list);
setTotal(data.total);
}
}

useEffect(() => {
load();
}, []);

const showDeleteConfirm = (item: DataDictVO) => { const showDeleteConfirm = (item: DataDictVO) => {
antdUtils.modal?.confirm({ antdUtils.modal?.confirm({
title: `确认删除名称为: ${item.name} 的字典吗?`, title: `确认删除名称为: ${item.name} 的字典吗?`,
@@ -133,20 +154,14 @@ export default () => {
okText: '删除', okText: '删除',
okType: 'danger', okType: 'danger',
cancelText: '取消', cancelText: '取消',
onOk() {
return new Promise((resolve, reject) => {
setTimeout(() => {
antdUtils.message?.open({
type: 'success',
content: '删除成功',
});
resolve(null)
}, 1000);

}).catch(() => antdUtils.message?.open({
type: 'error',
content: '操作失败',
}));
onOk: async () => {
const [error, { code, msg }] = await deleteDictApi(item.id);
if (error || code !== 0) {
antdUtils.message?.open({ type: 'error', content: msg ?? '操作失败' })
} else {
antdUtils.message?.open({ type: 'success', content: '删除成功' })
}
await load();
}, },
onCancel() { onCancel() {
}, },
@@ -186,7 +201,7 @@ export default () => {
onClick={() => { onClick={() => {
seEditDetailData(record) seEditDetailData(record)
seEdtailEditorVisable(true); seEdtailEditorVisable(true);
}}>
}}>
编辑 编辑
</a> </a>
<a <a
@@ -256,7 +271,17 @@ export default () => {
return ( return (
<> <>
<div className='flex flex-row'> <div className='flex flex-row'>
<Card className='basis-2/5 w-[100px] mb-[10px] dark:bg-[rgb(33,41,70)] bg-white roundle-lg px[12px]'>
<Card className='basis-2/5 w-[100px] mb-[10px] dark:bg-[rgb(33,41,70)] bg-white roundle-lg px[12px]' bodyStyle={{
paddingTop: 0,
paddingBottom: 0
}}>
<div className="py-[8px] flex flex-row-reverse">
<Button className="ml-5" type='primary' size='middle' icon={<PlusOutlined />}
onClick={() => {
seEditData(undefined);
seEditorVisable(true);
}}> 新增 </Button>
</div>
<Table rowKey="id" scroll={{ x: true }} columns={dictColumns} dataSource={dataDicts} className='bg-transparent' <Table rowKey="id" scroll={{ x: true }} columns={dictColumns} dataSource={dataDicts} className='bg-transparent'
onRow={(record) => { onRow={(record) => {
return { return {
@@ -282,6 +307,8 @@ export default () => {
</div> </div>
<DictEditor <DictEditor
onSave={() => { onSave={() => {
load();
seEditorVisable(false);
}} }}
onCancel={() => { seEditorVisable(false) }} onCancel={() => { seEditorVisable(false) }}
visible={editorVisable} visible={editorVisable}


+ 17
- 2
src/request/service/template-dict.ts View File

@@ -1,10 +1,25 @@
import request from '@/request'; import request from '@/request';
import { DataDictVO, DataDictDetailVO } from '@/models';
import { DataDictVO, DataDictDetailVO, DataDictPageReqVO, PageData } from '@/models';


const BASE_URL = '/admin-api/system/dict';
const BASE_URL = '/admin-api/template/dict';


export default { export default {


//获取字典分页
getDictPageApi: (params: DataDictPageReqVO) => {
return request.get<PageData<DataDictVO>>(`${BASE_URL}/page`, { params });
},

//获取字典详情
getDictDetailApi: (id: number) => {
return request.get(`${BASE_URL}/get?id=${id}`);
},

//获取字典列表
getDictListApi: (ids: string[]) => {
return request.get(`${BASE_URL}/list?ids=${ids.join(",")}`);
},

createDictApi: (data: DataDictVO) => { createDictApi: (data: DataDictVO) => {
return request.post(`${BASE_URL}/create`, data); return request.post(`${BASE_URL}/create`, data);
}, },


Loading…
Cancel
Save