6 changed files with 274 additions and 165 deletions
@ -1,119 +1,134 @@ |
|||||||
import {BasicColumn} from '/@/components/Table'; |
/** |
||||||
import {FormSchema} from '/@/components/Table'; |
* @program: kicc-ui |
||||||
import {h} from "vue"; |
* @description: 字典模块动态渲染配置 |
||||||
import {Tag} from "ant-design-vue"; |
* @author: entfrm开发团队-王翔 |
||||||
|
* @create: 2022/5/8 |
||||||
|
*/ |
||||||
|
|
||||||
|
import { BasicColumn } from '/@/components/Table'; |
||||||
|
import { FormSchema } from '/@/components/Table'; |
||||||
|
import { h } from 'vue'; |
||||||
|
import { Tag } from 'ant-design-vue'; |
||||||
|
|
||||||
|
/** 表格列配置 */ |
||||||
export const columns: BasicColumn[] = [ |
export const columns: BasicColumn[] = [ |
||||||
{ |
{ |
||||||
title: '字典ID', |
title: '字典名称', |
||||||
dataIndex: 'id', |
dataIndex: 'name' |
||||||
width: 100, |
}, |
||||||
}, |
{ |
||||||
{ |
title: '字典类型', |
||||||
title: '字典名称', |
dataIndex: 'type' |
||||||
dataIndex: 'name', |
}, |
||||||
width: 100, |
{ |
||||||
}, |
title: '系统内置', |
||||||
{ |
dataIndex: 'isSys', |
||||||
title: '字典类型', |
width: 90, |
||||||
dataIndex: 'type', |
customRender: ({ record }) => { |
||||||
width: 130, |
const status = record.status; |
||||||
}, |
const enable = ~~status === 0; |
||||||
{ |
const color = enable ? 'green' : 'red'; |
||||||
title: '系统内置', |
const text = enable ? '是' : '否'; |
||||||
dataIndex: 'isSys', |
return h(Tag, { color: color }, () => text); |
||||||
width: 90, |
|
||||||
customRender: ({ record }) => { |
|
||||||
const status = record.status; |
|
||||||
const enable = status === '0'; |
|
||||||
const color = 'gray'; |
|
||||||
const text = enable ? '是' : '否'; |
|
||||||
return h(Tag, { color: color }, () => text); |
|
||||||
} |
|
||||||
}, |
|
||||||
{ |
|
||||||
title: '状态', |
|
||||||
dataIndex: 'status', |
|
||||||
width: 90, |
|
||||||
customRender: ({ record }) => { |
|
||||||
const status = record.status; |
|
||||||
const enable = status === '0'; |
|
||||||
const color = enable ? 'green' : 'red'; |
|
||||||
const text = enable ? '启用' : '禁用'; |
|
||||||
return h(Tag, { color: color }, () => text); |
|
||||||
} |
|
||||||
} |
} |
||||||
]; |
}, |
||||||
|
{ |
||||||
export const searchFormSchema: FormSchema[] = [ |
title: '状态', |
||||||
{ |
dataIndex: 'status', |
||||||
field: 'type', |
width: 130, |
||||||
label: '字典类型', |
customRender: ({ record }) => { |
||||||
component: 'Input', |
const status = record.status; |
||||||
componentProps: { |
const enable = ~~status === 0; |
||||||
placeholder: '请输入字典类型', |
const color = enable ? 'green' : 'red'; |
||||||
}, |
const text = enable ? '启用' : '禁用'; |
||||||
colProps: {span: 16}, |
return h(Tag, { color: color }, () => text); |
||||||
} |
} |
||||||
|
} |
||||||
]; |
]; |
||||||
|
|
||||||
export const formSchema: FormSchema[] = [ |
/** 搜索表单配置 */ |
||||||
{ |
export const searchFormSchema: FormSchema[] = [ |
||||||
field: 'id', |
{ |
||||||
label: 'ID', |
field: 'name', |
||||||
component: 'Input', |
label: '字典名称', |
||||||
show: false, |
component: 'Input', |
||||||
}, |
componentProps: { |
||||||
{ |
placeholder: '请输入字典名称', |
||||||
field: 'name', |
|
||||||
label: '字典名称', |
|
||||||
component: 'Input', |
|
||||||
colProps:{ |
|
||||||
span: 12 |
|
||||||
} |
|
||||||
|
|
||||||
}, |
}, |
||||||
{ |
colProps: { span: 8 } |
||||||
field: 'type', |
}, |
||||||
label: '字典类型', |
{ |
||||||
component: 'Input', |
field: 'type', |
||||||
colProps:{ |
label: '字典类型', |
||||||
span: 12 |
component: 'Input', |
||||||
} |
componentProps: { |
||||||
|
placeholder: '请输入字典类型', |
||||||
}, |
}, |
||||||
{ |
colProps: { span: 8 } |
||||||
field: 'isSys', |
}, |
||||||
label: '系统内置', |
{ |
||||||
component: 'Select', |
field: 'status', |
||||||
defaultValue: '0', |
label: '状态', |
||||||
componentProps: { |
component: 'Select', |
||||||
options: [ |
componentProps: { |
||||||
{ label: '是', value: '0' }, |
options: [ |
||||||
{ label: '否', value: '1' } |
{ label: '正常', value: '0' }, |
||||||
] |
{ label: '停用', value: '1' } |
||||||
}, |
] |
||||||
colProps:{ |
|
||||||
span: 12 |
|
||||||
} |
|
||||||
}, |
}, |
||||||
{ |
colProps: { span: 8 } |
||||||
field: 'status', |
} |
||||||
label: '状态', |
]; |
||||||
component: 'Select', |
|
||||||
defaultValue: '0', |
/** 表单配置 */ |
||||||
componentProps: { |
export const formSchema: FormSchema[] = [ |
||||||
options: [ |
{ |
||||||
{ label: '启用', value: '0' }, |
field: 'id', |
||||||
{ label: '禁用', value: '1' } |
label: 'ID', |
||||||
] |
component: 'Input', |
||||||
}, |
show: false |
||||||
colProps:{ |
}, |
||||||
span: 12 |
{ |
||||||
} |
field: 'name', |
||||||
|
label: '字典名称', |
||||||
|
component: 'Input', |
||||||
|
colProps:{ span: 12 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'type', |
||||||
|
label: '字典类型', |
||||||
|
component: 'Input', |
||||||
|
colProps:{ span: 12 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'isSys', |
||||||
|
label: '系统内置', |
||||||
|
component: 'Select', |
||||||
|
defaultValue: '0', |
||||||
|
componentProps: { |
||||||
|
options: [ |
||||||
|
{ label: '是', value: '0' }, |
||||||
|
{ label: '否', value: '1' } |
||||||
|
] |
||||||
}, |
}, |
||||||
{ |
colProps:{ span: 12 } |
||||||
field: 'remarks', |
}, |
||||||
label: '备注', |
{ |
||||||
component: 'InputTextArea', |
field: 'status', |
||||||
|
label: '状态', |
||||||
|
component: 'Select', |
||||||
|
defaultValue: '0', |
||||||
|
componentProps: { |
||||||
|
options: [ |
||||||
|
{ label: '启用', value: '0' }, |
||||||
|
{ label: '禁用', value: '1' } |
||||||
|
] |
||||||
}, |
}, |
||||||
|
colProps:{ span: 12 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'remarks', |
||||||
|
label: '备注', |
||||||
|
component: 'InputTextArea', |
||||||
|
}, |
||||||
]; |
]; |
||||||
|
@ -1,109 +1,177 @@ |
|||||||
<template> |
<template> |
||||||
<PageWrapper dense contentFullHeight fixedHeight contentClass="flex"> |
<PageWrapper dense |
||||||
<BasicTable @register="registerTable" @row-click="clickSubTable" class="w-2/4 xl:w-2/4"> |
fixedHeight |
||||||
|
contentFullHeight |
||||||
|
contentClass="flex" |
||||||
|
> |
||||||
|
<BasicTable class="w-2/4 xl:w-2/4" |
||||||
|
@register="registerTable" |
||||||
|
@selection-change="handleSelectionChange" |
||||||
|
@row-click="handleClickSubTable" |
||||||
|
> |
||||||
<template #toolbar> |
<template #toolbar> |
||||||
<a-button type="primary" @click="handleCreate">新增字典</a-button> |
<a-button v-auth="['dict_add']" |
||||||
|
type="primary" |
||||||
|
@click="handleAdd()" |
||||||
|
>新增字典</a-button> |
||||||
|
<a-button v-auth="['dict_edit']" |
||||||
|
type="primary" |
||||||
|
:disabled="state.single" |
||||||
|
@click="handleEdit()" |
||||||
|
>修改字典</a-button> |
||||||
|
<a-button v-auth="['dict_del']" |
||||||
|
type="primary" |
||||||
|
:disabled="state.multiple" |
||||||
|
@click="handleDel()" |
||||||
|
>删除字典</a-button> |
||||||
</template> |
</template> |
||||||
<template #action="{ record }"> |
<template #action="{ record }"> |
||||||
<TableAction |
<TableAction :actions="[ |
||||||
:actions="[ |
{ |
||||||
{ |
label: '编辑', |
||||||
icon: 'clarity:note-edit-line', |
icon: 'fa6-regular:pen-to-square', |
||||||
onClick: handleEdit.bind(null, record), |
auth: ['dict_edit'], |
||||||
}, |
onClick: handleEdit.bind(null, record) |
||||||
{ |
}, |
||||||
icon: 'ant-design:delete-outlined', |
{ |
||||||
color: 'error', |
label: '删除', |
||||||
popConfirm: { |
icon: 'ant-design:delete-outlined', |
||||||
title: '是否确认删除', |
auth: ['dict_del'], |
||||||
confirm: handleDelete.bind(null, record), |
color: 'error', |
||||||
}, |
onClick: handleDel.bind(null, record) |
||||||
}, |
}]" |
||||||
]" |
|
||||||
/> |
/> |
||||||
</template> |
</template> |
||||||
</BasicTable> |
</BasicTable> |
||||||
<DictDataTable ref="dictSubRef" class="w-2/4 xl:w-2/4" /> |
<DictDataTable ref="dictSubRef" class="w-2/4 xl:w-2/4"/> |
||||||
<DictModal @register="registerModal" @success="handleSuccess" /> |
<!--弹出窗体区域--> |
||||||
|
<DictModal @register="registerModal" @success="handleRefreshTable"/> |
||||||
</PageWrapper> |
</PageWrapper> |
||||||
</template> |
</template> |
||||||
<script lang="ts"> |
<script lang="ts"> |
||||||
import { defineComponent, ref } from 'vue'; |
/** |
||||||
// 引入基础组件 |
* 提供模板规范代码参考,请尽量保证编写代码风格跟模板规范代码一致 |
||||||
|
* 采用vben-动态表格表单封装组件编写,不采用 setup 写法 |
||||||
|
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved. |
||||||
|
* author entfrm开发团队-王翔 |
||||||
|
*/ |
||||||
|
import { defineComponent, reactive, ref, toRaw } from 'vue'; |
||||||
import { PageWrapper } from '/@/components/Page'; |
import { PageWrapper } from '/@/components/Page'; |
||||||
import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
||||||
// 插入数据内容 |
|
||||||
import { columns, searchFormSchema} from './dict.data'; |
import { columns, searchFormSchema} from './dict.data'; |
||||||
// 通过API接口获取日志 |
import { listDict, delDict } from '/@/api/platform/system/controller/dict'; |
||||||
//import { list, remove } from '/@/api/platform/system/controller/dict'; |
|
||||||
import { useModal } from '/@/components/Modal'; |
import { useModal } from '/@/components/Modal'; |
||||||
|
import { useMessage } from '/@/hooks/web/useMessage'; |
||||||
import DictModal from './DictModal.vue'; |
import DictModal from './DictModal.vue'; |
||||||
import DictDataTable from './DictDataTable.vue'; |
import DictDataTable from './DictDataTable.vue'; |
||||||
import { useMessage } from '/@/hooks/web/useMessage'; |
import {delRole} from "/@/api/platform/system/controller/role"; |
||||||
|
|
||||||
|
/** 类型规范统一声明定义区域 */ |
||||||
|
interface TableState { |
||||||
|
ids: string[]; |
||||||
|
single: boolean; |
||||||
|
multiple: boolean; |
||||||
|
} |
||||||
|
|
||||||
export default defineComponent({ |
export default defineComponent({ |
||||||
|
name: 'DictManagement', |
||||||
components: { BasicTable, PageWrapper, DictModal, DictDataTable, TableAction }, |
components: { BasicTable, PageWrapper, DictModal, DictDataTable, TableAction }, |
||||||
setup() { |
setup() { |
||||||
const { createMessage } = useMessage(); |
|
||||||
|
/** 通用变量统一声明区域 */ |
||||||
const dictSubRef = ref(); |
const dictSubRef = ref(); |
||||||
|
const state = reactive<TableState>({ |
||||||
|
// 选中数组 |
||||||
|
ids: [], |
||||||
|
// 非单个禁用 |
||||||
|
single: true, |
||||||
|
// 非多个禁用 |
||||||
|
multiple: true |
||||||
|
}); |
||||||
|
const { createConfirm, createMessage } = useMessage(); |
||||||
const [registerModal, { openModal }] = useModal(); |
const [registerModal, { openModal }] = useModal(); |
||||||
const [registerTable, { reload }] = useTable({ |
const [registerTable, { reload, clearSelectedRowKeys }] = useTable({ |
||||||
title: '字典列表', |
title: '字典列表', |
||||||
//api: list, |
api: listDict, |
||||||
|
rowKey: 'id', |
||||||
columns, |
columns, |
||||||
formConfig: { |
formConfig: { |
||||||
labelWidth: 100, |
labelWidth: 80, |
||||||
schemas: searchFormSchema, |
schemas: searchFormSchema, |
||||||
|
autoSubmitOnEnter: true |
||||||
}, |
}, |
||||||
|
rowSelection: { type: 'checkbox' }, |
||||||
useSearchForm: true, |
useSearchForm: true, |
||||||
showTableSetting: true, |
showTableSetting: true, |
||||||
bordered: true, |
bordered: true, |
||||||
showIndexColumn: false, |
showIndexColumn: false, |
||||||
actionColumn: { |
actionColumn: { |
||||||
width: 80, |
width: 220, |
||||||
title: '操作', |
title: '操作', |
||||||
dataIndex: 'action', |
dataIndex: 'action', |
||||||
slots: { customRender: 'action' }, |
slots: { customRender: 'action' }, |
||||||
fixed: undefined, |
fixed: false |
||||||
}, |
}, |
||||||
|
handleSearchInfoFn: () => clearSelectedRowKeys() |
||||||
}); |
}); |
||||||
|
|
||||||
function handleCreate() { |
/** 处理多选框选中数据 */ |
||||||
openModal(true, { |
function handleSelectionChange(selection?: Recordable) { |
||||||
isUpdate: false, |
const rowSelection = toRaw(selection?.keys) || []; |
||||||
}); |
state.ids = rowSelection; |
||||||
|
state.single = rowSelection.length != 1; |
||||||
|
state.multiple = !rowSelection.length; |
||||||
} |
} |
||||||
function handleEdit(record: Recordable) { |
|
||||||
openModal(true, { |
/** 新增按钮操作,行内新增与工具栏局域新增通用 */ |
||||||
record, |
function handleAdd() { |
||||||
isUpdate: true, |
openModal(true,{ _tag: 'add' }); |
||||||
}); |
} |
||||||
|
|
||||||
|
/** 编辑按钮操作,行内编辑 */ |
||||||
|
function handleEdit(record?: Recordable) { |
||||||
|
record = record || { id: toRaw(state.ids) }; |
||||||
|
openModal(true, { _tag: 'edit', record }); |
||||||
} |
} |
||||||
|
|
||||||
async function handleDelete(record: Recordable) { |
/** 删除按钮操作,行内删除 */ |
||||||
await remove({ id: record.id }); |
async function handleDel(record?: Recordable) { |
||||||
createMessage.success('删除成功!'); |
const ids = record?.id || toRaw(state.ids); |
||||||
handleSuccess(); |
createConfirm({ |
||||||
|
iconType: 'warning', |
||||||
|
title: '警告', |
||||||
|
content: `是否确认删除角色编号为${ids}角色吗?`, |
||||||
|
onOk: async () => { |
||||||
|
await delRole(ids); |
||||||
|
createMessage.success('删除成功!'); |
||||||
|
handleRefreshTable(); |
||||||
|
} |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
function clickSubTable(record: Recordable) { |
/** 处理点击字典子表 */ |
||||||
|
function handleClickSubTable(record: Recordable) { |
||||||
dictSubRef.value.filterByDictType(record); |
dictSubRef.value.filterByDictType(record); |
||||||
} |
} |
||||||
|
|
||||||
function handleSuccess() { |
/** 处理表格刷新 */ |
||||||
|
function handleRefreshTable() { |
||||||
|
clearSelectedRowKeys(); |
||||||
reload(); |
reload(); |
||||||
} |
} |
||||||
|
|
||||||
return { |
return { |
||||||
|
state, |
||||||
registerTable, |
registerTable, |
||||||
registerModal, |
registerModal, |
||||||
clickSubTable, |
|
||||||
handleCreate, |
|
||||||
handleEdit, |
|
||||||
handleDelete, |
|
||||||
handleSuccess, |
|
||||||
dictSubRef, |
dictSubRef, |
||||||
|
handleClickSubTable, |
||||||
|
handleAdd, |
||||||
|
handleEdit, |
||||||
|
handleDel, |
||||||
|
handleRefreshTable, |
||||||
|
handleSelectionChange |
||||||
}; |
}; |
||||||
}, |
} |
||||||
}); |
}); |
||||||
</script> |
</script> |
||||||
|
Loading…
Reference in new issue