mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-13 02:57:13 +08:00
feat: 新增系统管理/字典管理(列表、新增、修改、删除、导出、查询字典项列表、新增字典项、修改字典项、删除字典项)
This commit is contained in:
57
continew-admin-ui/src/api/system/dict-item.ts
Normal file
57
continew-admin-ui/src/api/system/dict-item.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import axios from 'axios';
|
||||
import qs from 'query-string';
|
||||
|
||||
const BASE_URL = '/system/dict/item';
|
||||
|
||||
export interface DataRecord {
|
||||
id?: number;
|
||||
label: string;
|
||||
value: string;
|
||||
color?: string;
|
||||
sort?: number;
|
||||
description: string;
|
||||
dictId?: number;
|
||||
createUser?: string;
|
||||
createTime?: string;
|
||||
updateUser?: string;
|
||||
updateTime?: string;
|
||||
createUserString?: string;
|
||||
updateUserString?: string;
|
||||
}
|
||||
|
||||
export interface ListParam {
|
||||
dictId?: number;
|
||||
page?: number;
|
||||
size?: number;
|
||||
sort?: Array<string>;
|
||||
}
|
||||
|
||||
export interface ListRes {
|
||||
list: DataRecord[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export function list(params: ListParam) {
|
||||
return axios.get<ListRes>(`${BASE_URL}`, {
|
||||
params,
|
||||
paramsSerializer: (obj) => {
|
||||
return qs.stringify(obj);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function get(id: number) {
|
||||
return axios.get<DataRecord>(`${BASE_URL}/${id}`);
|
||||
}
|
||||
|
||||
export function add(req: DataRecord) {
|
||||
return axios.post(BASE_URL, req);
|
||||
}
|
||||
|
||||
export function update(req: DataRecord, id: number) {
|
||||
return axios.put(`${BASE_URL}/${id}`, req);
|
||||
}
|
||||
|
||||
export function del(ids: number | Array<number>) {
|
||||
return axios.delete(`${BASE_URL}/${ids}`);
|
||||
}
|
54
continew-admin-ui/src/api/system/dict.ts
Normal file
54
continew-admin-ui/src/api/system/dict.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import axios from 'axios';
|
||||
import qs from 'query-string';
|
||||
|
||||
const BASE_URL = '/system/dict';
|
||||
|
||||
export interface DataRecord {
|
||||
id?: number;
|
||||
name: string;
|
||||
code: string;
|
||||
description?: string;
|
||||
createUser?: string;
|
||||
createTime?: string;
|
||||
updateUser?: string;
|
||||
updateTime?: string;
|
||||
createUserString?: string;
|
||||
updateUserString?: string;
|
||||
}
|
||||
|
||||
export interface ListParam {
|
||||
name?: string;
|
||||
page?: number;
|
||||
size?: number;
|
||||
sort?: Array<string>;
|
||||
}
|
||||
|
||||
export interface ListRes {
|
||||
list: DataRecord[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
export function list(params: ListParam) {
|
||||
return axios.get<ListRes>(`${BASE_URL}`, {
|
||||
params,
|
||||
paramsSerializer: (obj) => {
|
||||
return qs.stringify(obj);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function get(id: number) {
|
||||
return axios.get<DataRecord>(`${BASE_URL}/${id}`);
|
||||
}
|
||||
|
||||
export function add(req: DataRecord) {
|
||||
return axios.post(BASE_URL, req);
|
||||
}
|
||||
|
||||
export function update(req: DataRecord, id: number) {
|
||||
return axios.put(`${BASE_URL}/${id}`, req);
|
||||
}
|
||||
|
||||
export function del(ids: number | Array<number>) {
|
||||
return axios.delete(`${BASE_URL}/${ids}`);
|
||||
}
|
@@ -5,6 +5,7 @@ import localeRole from '@/views/system/role/locale/en-US';
|
||||
import localeMenu from '@/views/system/menu/locale/en-US';
|
||||
import localeDept from '@/views/system/dept/locale/en-US';
|
||||
import localeAnnouncement from '@/views/system/announcement/locale/en-US';
|
||||
import localeDict from '@/views/system/dict/locale/en-US';
|
||||
|
||||
import localeGenerator from '@/views/tool/generator/locale/en-US';
|
||||
|
||||
@@ -60,6 +61,7 @@ export default {
|
||||
...localeMenu,
|
||||
...localeDept,
|
||||
...localeAnnouncement,
|
||||
...localeDict,
|
||||
|
||||
...localeGenerator,
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import localeRole from '@/views/system/role/locale/zh-CN';
|
||||
import localeMenu from '@/views/system/menu/locale/zh-CN';
|
||||
import localeDept from '@/views/system/dept/locale/zh-CN';
|
||||
import localeAnnouncement from '@/views/system/announcement/locale/zh-CN';
|
||||
import localeDict from '@/views/system/dict/locale/zh-CN';
|
||||
|
||||
import localeGenerator from '@/views/tool/generator/locale/zh-CN';
|
||||
|
||||
@@ -60,6 +61,7 @@ export default {
|
||||
...localeMenu,
|
||||
...localeDept,
|
||||
...localeAnnouncement,
|
||||
...localeDict,
|
||||
|
||||
...localeGenerator,
|
||||
|
||||
|
@@ -7,7 +7,7 @@ const FORM: AppRouteRecordRaw = {
|
||||
component: DEFAULT_LAYOUT,
|
||||
meta: {
|
||||
locale: 'menu.form',
|
||||
icon: 'bookmark',
|
||||
icon: 'select-all',
|
||||
requiresAuth: true,
|
||||
order: 901,
|
||||
},
|
||||
|
@@ -21,6 +21,15 @@ const System: AppRouteRecordRaw = {
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Dept',
|
||||
path: '/system/dept',
|
||||
component: () => import('@/views/system/dept/index.vue'),
|
||||
meta: {
|
||||
locale: 'menu.system.dept.list',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Role',
|
||||
path: '/system/role',
|
||||
@@ -30,6 +39,15 @@ const System: AppRouteRecordRaw = {
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Announcement',
|
||||
path: '/system/announcement',
|
||||
component: () => import('@/views/system/announcement/index.vue'),
|
||||
meta: {
|
||||
locale: 'menu.system.announcement.list',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Menu',
|
||||
path: '/system/menu',
|
||||
@@ -40,20 +58,11 @@ const System: AppRouteRecordRaw = {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Dept',
|
||||
path: '/system/dept',
|
||||
component: () => import('@/views/system/dept/index.vue'),
|
||||
name: 'Dict',
|
||||
path: '/system/dict',
|
||||
component: () => import('@/views/system/dict/index.vue'),
|
||||
meta: {
|
||||
locale: 'menu.system.dept.list',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Announcement',
|
||||
path: '/system/announcement',
|
||||
component: () => import('@/views/system/announcement/index.vue'),
|
||||
meta: {
|
||||
locale: 'menu.system.announcement.list',
|
||||
locale: 'menu.system.dict.list',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
|
453
continew-admin-ui/src/views/system/dict/index.vue
Normal file
453
continew-admin-ui/src/views/system/dict/index.vue
Normal file
@@ -0,0 +1,453 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<Breadcrumb :items="['menu.system', 'menu.system.dict.list']" />
|
||||
<a-card class="general-card" :title="$t('menu.system.dict.list')">
|
||||
<a-row>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
|
||||
<!-- 头部区域 -->
|
||||
<div class="header">
|
||||
<!-- 搜索栏 -->
|
||||
<div v-if="showQuery" class="header-query">
|
||||
<a-form ref="queryRef" :model="queryParams" layout="inline">
|
||||
<a-form-item field="name" hide-label>
|
||||
<a-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="输入字典名称搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@press-enter="handleQuery"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item hide-label>
|
||||
<a-space>
|
||||
<a-button type="primary" @click="handleQuery">
|
||||
<template #icon><icon-search /></template>查询
|
||||
</a-button>
|
||||
<a-button @click="resetQuery">
|
||||
<template #icon><icon-refresh /></template>重置
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
<!-- 操作栏 -->
|
||||
<div class="header-operation">
|
||||
<a-row>
|
||||
<a-col :span="12">
|
||||
<a-space>
|
||||
<a-button
|
||||
v-permission="['system:dict:add']"
|
||||
type="primary"
|
||||
@click="toAdd"
|
||||
>
|
||||
<template #icon><icon-plus /></template>新增
|
||||
</a-button>
|
||||
<a-button
|
||||
v-permission="['system:dict:update']"
|
||||
type="primary"
|
||||
status="success"
|
||||
:disabled="single"
|
||||
:title="single ? '请选择一条要修改的数据' : ''"
|
||||
@click="toUpdate(ids[0])"
|
||||
>
|
||||
<template #icon><icon-edit /></template>修改
|
||||
</a-button>
|
||||
<a-button
|
||||
v-permission="['system:dict:delete']"
|
||||
type="primary"
|
||||
status="danger"
|
||||
:disabled="multiple"
|
||||
:title="multiple ? '请选择要删除的数据' : ''"
|
||||
@click="handleBatchDelete"
|
||||
>
|
||||
<template #icon><icon-delete /></template>删除
|
||||
</a-button>
|
||||
<a-button
|
||||
v-permission="['system:dict:export']"
|
||||
:loading="exportLoading"
|
||||
type="primary"
|
||||
status="warning"
|
||||
@click="handleExport"
|
||||
>
|
||||
<template #icon><icon-download /></template>导出
|
||||
</a-button>
|
||||
</a-space>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<right-toolbar
|
||||
v-model:show-query="showQuery"
|
||||
@refresh="handleQuery"
|
||||
/>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 列表区域 -->
|
||||
<a-table
|
||||
ref="tableRef"
|
||||
row-key="id"
|
||||
:data="dataList"
|
||||
:loading="loading"
|
||||
:row-selection="{
|
||||
type: 'checkbox',
|
||||
showCheckedAll: true,
|
||||
onlyCurrent: false,
|
||||
}"
|
||||
:pagination="{
|
||||
showTotal: true,
|
||||
showPageSize: true,
|
||||
total: total,
|
||||
current: queryParams.page,
|
||||
}"
|
||||
:bordered="false"
|
||||
column-resizable
|
||||
size="large"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
@row-click="handleSelect"
|
||||
>
|
||||
<template #columns>
|
||||
<a-table-column title="序号" :width="60">
|
||||
<template #cell="{ rowIndex }">
|
||||
{{ rowIndex + 1 + (queryParams.page - 1) * queryParams.size }}
|
||||
</template>
|
||||
</a-table-column>
|
||||
<a-table-column title="字典名称" data-index="name" :width="100" />
|
||||
<a-table-column
|
||||
title="字典编码"
|
||||
data-index="code"
|
||||
ellipsis
|
||||
tooltip
|
||||
/>
|
||||
<a-table-column title="描述" data-index="description" />
|
||||
<a-table-column
|
||||
v-if="
|
||||
checkPermission(['system:dict:update', 'system:dict:delete'])
|
||||
"
|
||||
title="操作"
|
||||
align="center"
|
||||
:width="191"
|
||||
>
|
||||
<template #cell="{ record }">
|
||||
<a-button
|
||||
v-permission="['system:dict:update']"
|
||||
type="text"
|
||||
size="small"
|
||||
title="修改"
|
||||
@click="toUpdate(record.id)"
|
||||
>
|
||||
<template #icon><icon-edit /></template>修改
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
content="确定要删除当前选中的数据吗?"
|
||||
type="warning"
|
||||
@ok="handleDelete([record.id])"
|
||||
>
|
||||
<a-button
|
||||
v-permission="['system:dict:delete']"
|
||||
type="text"
|
||||
size="small"
|
||||
title="删除"
|
||||
:disabled="record.disabled"
|
||||
>
|
||||
<template #icon><icon-delete /></template>删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</a-table-column>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-col>
|
||||
<a-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
|
||||
<dictItem ref="dictItemRef" :dict-id="dictId" />
|
||||
</a-col>
|
||||
</a-row>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<a-modal
|
||||
:title="title"
|
||||
:visible="visible"
|
||||
:mask-closable="false"
|
||||
:esc-to-close="false"
|
||||
unmount-on-close
|
||||
render-to-body
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<a-form ref="formRef" :model="form" :rules="rules" size="large">
|
||||
<a-form-item label="字典名称" field="name">
|
||||
<a-input v-model="form.name" placeholder="请输入字典名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="字典编码" field="code">
|
||||
<a-input v-model="form.code" placeholder="请输入字典编码" />
|
||||
</a-form-item>
|
||||
<a-form-item label="描述" field="description">
|
||||
<a-textarea
|
||||
v-model="form.description"
|
||||
:max-length="200"
|
||||
placeholder="请输入描述"
|
||||
:auto-size="{
|
||||
minRows: 3,
|
||||
}"
|
||||
show-word-limit
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import { TableData } from '@arco-design/web-vue';
|
||||
import {
|
||||
DataRecord,
|
||||
ListParam,
|
||||
list,
|
||||
get,
|
||||
add,
|
||||
update,
|
||||
del,
|
||||
} from '@/api/system/dict';
|
||||
import checkPermission from '@/utils/permission';
|
||||
import dictItem from './item.vue';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
|
||||
const dataList = ref<DataRecord[]>([]);
|
||||
const total = ref(0);
|
||||
const ids = ref<Array<number>>([]);
|
||||
const title = ref('');
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const showQuery = ref(true);
|
||||
const loading = ref(false);
|
||||
const exportLoading = ref(false);
|
||||
const visible = ref(false);
|
||||
const dictId = ref();
|
||||
|
||||
const data = reactive({
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
name: undefined,
|
||||
page: 1,
|
||||
size: 10,
|
||||
sort: ['createTime,desc'],
|
||||
},
|
||||
// 表单数据
|
||||
form: {} as DataRecord,
|
||||
// 表单验证规则
|
||||
rules: {
|
||||
name: [{ required: true, message: '字典名称不能为空' }],
|
||||
code: [{ required: true, message: '字典编码不能为空' }],
|
||||
},
|
||||
});
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/**
|
||||
* 选中行
|
||||
*
|
||||
* @param record 所选行记录
|
||||
*/
|
||||
const handleSelect = (record: TableData) => {
|
||||
proxy.$refs.tableRef.selectAll(false);
|
||||
proxy.$refs.tableRef.select(record.id);
|
||||
dictId.value = record.id;
|
||||
proxy.$refs.dictItemRef.getList(record.id);
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*
|
||||
* @param params 查询参数
|
||||
*/
|
||||
const getList = (params: ListParam = { ...queryParams.value }) => {
|
||||
dictId.value = null;
|
||||
loading.value = true;
|
||||
list(params)
|
||||
.then((res) => {
|
||||
dataList.value = res.data.list;
|
||||
total.value = res.data.total;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
getList();
|
||||
|
||||
/**
|
||||
* 打开新增对话框
|
||||
*/
|
||||
const toAdd = () => {
|
||||
reset();
|
||||
title.value = '新增字典';
|
||||
visible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开修改对话框
|
||||
*
|
||||
* @param id ID
|
||||
*/
|
||||
const toUpdate = (id: number) => {
|
||||
reset();
|
||||
get(id).then((res) => {
|
||||
form.value = res.data;
|
||||
title.value = '修改字典';
|
||||
visible.value = true;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单
|
||||
*/
|
||||
const reset = () => {
|
||||
form.value = {
|
||||
id: undefined,
|
||||
name: '',
|
||||
code: '',
|
||||
description: '',
|
||||
};
|
||||
proxy.$refs.formRef?.resetFields();
|
||||
};
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
const handleCancel = () => {
|
||||
visible.value = false;
|
||||
proxy.$refs.formRef.resetFields();
|
||||
};
|
||||
|
||||
/**
|
||||
* 确定
|
||||
*/
|
||||
const handleOk = () => {
|
||||
proxy.$refs.formRef.validate((valid: any) => {
|
||||
if (!valid) {
|
||||
if (form.value.id !== undefined) {
|
||||
update(form.value, form.value.id).then((res) => {
|
||||
handleCancel();
|
||||
getList();
|
||||
proxy.$message.success(res.msg);
|
||||
});
|
||||
} else {
|
||||
add(form.value).then((res) => {
|
||||
handleCancel();
|
||||
getList();
|
||||
proxy.$message.success(res.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
const handleBatchDelete = () => {
|
||||
if (ids.value.length === 0) {
|
||||
proxy.$message.info('请选择要删除的数据');
|
||||
} else {
|
||||
proxy.$modal.warning({
|
||||
title: '警告',
|
||||
titleAlign: 'start',
|
||||
content: '确定要删除当前选中的数据吗?',
|
||||
hideCancel: false,
|
||||
onOk: () => {
|
||||
handleDelete(ids.value);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids ID 列表
|
||||
*/
|
||||
const handleDelete = (ids: Array<number>) => {
|
||||
del(ids).then((res) => {
|
||||
proxy.$message.success(res.msg);
|
||||
getList();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 已选择的数据行发生改变时触发
|
||||
*
|
||||
* @param rowKeys ID 列表
|
||||
*/
|
||||
const handleSelectionChange = (rowKeys: Array<any>) => {
|
||||
ids.value = rowKeys;
|
||||
single.value = rowKeys.length !== 1;
|
||||
multiple.value = !rowKeys.length;
|
||||
if (!rowKeys.length) {
|
||||
dictId.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
const handleExport = () => {
|
||||
if (exportLoading.value) return;
|
||||
exportLoading.value = true;
|
||||
proxy
|
||||
.download('/system/dict/export', { ...queryParams.value }, '字典数据')
|
||||
.finally(() => {
|
||||
exportLoading.value = false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
const handleQuery = () => {
|
||||
proxy.$refs.tableRef.selectAll(false);
|
||||
getList();
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置
|
||||
*/
|
||||
const resetQuery = () => {
|
||||
proxy.$refs.queryRef.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换页码
|
||||
*
|
||||
* @param current 页码
|
||||
*/
|
||||
const handlePageChange = (current: number) => {
|
||||
queryParams.value.page = current;
|
||||
getList();
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换每页条数
|
||||
*
|
||||
* @param pageSize 每页条数
|
||||
*/
|
||||
const handlePageSizeChange = (pageSize: number) => {
|
||||
queryParams.value.size = pageSize;
|
||||
getList();
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'Dict',
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
:deep(.arco-table-td) {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
363
continew-admin-ui/src/views/system/dict/item.vue
Normal file
363
continew-admin-ui/src/views/system/dict/item.vue
Normal file
@@ -0,0 +1,363 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<!-- 头部区域 -->
|
||||
<div style="margin-bottom: 18px">
|
||||
<a-row>
|
||||
<a-col :span="18" />
|
||||
<a-col :span="6" style="display: flex; justify-content: end">
|
||||
<a-button
|
||||
v-permission="['system:dictItem:add']"
|
||||
type="primary"
|
||||
:disabled="!dictId"
|
||||
:title="!dictId ? '请先点击左侧字典' : ''"
|
||||
@click="toAdd"
|
||||
>
|
||||
<template #icon><icon-plus /></template>新增
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
|
||||
<!-- 列表区域 -->
|
||||
<a-table
|
||||
ref="tableRef"
|
||||
row-key="id"
|
||||
:data="dictId ? dataList : []"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
showTotal: true,
|
||||
showPageSize: true,
|
||||
total: total,
|
||||
current: queryParams.page,
|
||||
}"
|
||||
:bordered="false"
|
||||
column-resizable
|
||||
stripe
|
||||
size="large"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
>
|
||||
<template #columns>
|
||||
<a-table-column title="字典标签" align="center">
|
||||
<template #cell="{ record }">
|
||||
<a-tag v-if="record.color === 'primary'" color="arcoblue">{{
|
||||
record.label
|
||||
}}</a-tag>
|
||||
<a-tag v-else-if="record.color === 'success'" color="green">{{
|
||||
record.label
|
||||
}}</a-tag>
|
||||
<a-tag
|
||||
v-else-if="record.color === 'warning'"
|
||||
color="orangered"
|
||||
>{{ record.label }}</a-tag
|
||||
>
|
||||
<a-tag v-else-if="record.color === 'error'" color="red">{{
|
||||
record.label
|
||||
}}</a-tag>
|
||||
<a-tag v-else-if="record.color === 'default'" color="gray">{{
|
||||
record.label
|
||||
}}</a-tag>
|
||||
<span v-else-if="!record.color">{{ record.label }}</span>
|
||||
<a-tag v-else :color="record.color">{{ record.label }}</a-tag>
|
||||
</template>
|
||||
</a-table-column>
|
||||
<a-table-column title="字典值" align="center" data-index="value" />
|
||||
<a-table-column title="排序" align="center" data-index="sort" />
|
||||
<a-table-column title="描述" data-index="description" />
|
||||
<a-table-column
|
||||
v-if="
|
||||
checkPermission([
|
||||
'system:dictItem:update',
|
||||
'system:dictItem:delete',
|
||||
])
|
||||
"
|
||||
title="操作"
|
||||
align="center"
|
||||
>
|
||||
<template #cell="{ record }">
|
||||
<a-button
|
||||
v-permission="['system:dictItem:update']"
|
||||
type="text"
|
||||
size="small"
|
||||
title="修改"
|
||||
@click="toUpdate(record.id)"
|
||||
>
|
||||
<template #icon><icon-edit /></template>修改
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
content="确定要删除当前选中的数据吗?"
|
||||
type="warning"
|
||||
@ok="handleDelete([record.id])"
|
||||
>
|
||||
<a-button
|
||||
v-permission="['system:dictItem:delete']"
|
||||
type="text"
|
||||
size="small"
|
||||
title="删除"
|
||||
:disabled="record.disabled"
|
||||
>
|
||||
<template #icon><icon-delete /></template>删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</template>
|
||||
</a-table-column>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<a-modal
|
||||
:title="title"
|
||||
:visible="visible"
|
||||
:mask-closable="false"
|
||||
:esc-to-close="false"
|
||||
unmount-on-close
|
||||
render-to-body
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<a-form ref="formRef" :model="form" :rules="rules" size="large">
|
||||
<a-form-item label="字典标签" field="label">
|
||||
<a-input v-model="form.label" placeholder="请输入字典标签" />
|
||||
</a-form-item>
|
||||
<a-form-item label="字典值" field="value">
|
||||
<a-input v-model="form.value" placeholder="请输入字典值" />
|
||||
</a-form-item>
|
||||
<a-form-item label="背景颜色" field="color">
|
||||
<a-auto-complete
|
||||
v-model="form.color"
|
||||
:data="colors"
|
||||
placeholder="请选择或输入背景颜色"
|
||||
allow-clear
|
||||
>
|
||||
<template #option="{ data }">
|
||||
<a-tag v-if="data.value === 'primary'" color="arcoblue">{{
|
||||
data.value
|
||||
}}</a-tag>
|
||||
<a-tag v-else-if="data.value === 'success'" color="green">{{
|
||||
data.value
|
||||
}}</a-tag>
|
||||
<a-tag v-else-if="data.value === 'warning'" color="orangered">{{
|
||||
data.value
|
||||
}}</a-tag>
|
||||
<a-tag v-else-if="data.value === 'error'" color="red">{{
|
||||
data.value
|
||||
}}</a-tag>
|
||||
<a-tag v-else color="gray">{{ data.value }}</a-tag>
|
||||
</template>
|
||||
</a-auto-complete>
|
||||
</a-form-item>
|
||||
<a-form-item label="排序" field="sort">
|
||||
<a-input-number
|
||||
v-model="form.sort"
|
||||
placeholder="请输入排序"
|
||||
:min="1"
|
||||
mode="button"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="描述" field="description">
|
||||
<a-textarea
|
||||
v-model="form.description"
|
||||
:max-length="200"
|
||||
placeholder="请输入描述"
|
||||
:auto-size="{
|
||||
minRows: 3,
|
||||
}"
|
||||
show-word-limit
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue';
|
||||
import {
|
||||
DataRecord,
|
||||
ListParam,
|
||||
list,
|
||||
get,
|
||||
add,
|
||||
update,
|
||||
del,
|
||||
} from '@/api/system/dict-item';
|
||||
import checkPermission from '@/utils/permission';
|
||||
|
||||
const props = defineProps({
|
||||
dictId: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const dataList = ref<DataRecord[]>([]);
|
||||
const colors = ref(['primary', 'success', 'warning', 'error', 'default']);
|
||||
const total = ref(0);
|
||||
const title = ref('');
|
||||
const loading = ref(false);
|
||||
const visible = ref(false);
|
||||
const dictId = computed(() => props.dictId);
|
||||
|
||||
const data = reactive({
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
page: 1,
|
||||
size: 10,
|
||||
sort: ['createTime,desc'],
|
||||
} as ListParam,
|
||||
// 表单数据
|
||||
form: {} as DataRecord,
|
||||
// 表单验证规则
|
||||
rules: {
|
||||
label: [{ required: true, message: '字典标签不能为空' }],
|
||||
value: [{ required: true, message: '字典值不能为空' }],
|
||||
},
|
||||
});
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*
|
||||
* @param dictId 字典 ID
|
||||
*/
|
||||
const getList = (dictId: number) => {
|
||||
queryParams.value.dictId = dictId;
|
||||
loading.value = true;
|
||||
list(queryParams.value)
|
||||
.then((res) => {
|
||||
dataList.value = res.data.list;
|
||||
total.value = res.data.total;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
};
|
||||
defineExpose({
|
||||
getList,
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开新增对话框
|
||||
*/
|
||||
const toAdd = () => {
|
||||
reset();
|
||||
title.value = '新增字典项';
|
||||
visible.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开修改对话框
|
||||
*
|
||||
* @param id ID
|
||||
*/
|
||||
const toUpdate = (id: number) => {
|
||||
reset();
|
||||
get(id).then((res) => {
|
||||
form.value = res.data;
|
||||
title.value = '修改字典项';
|
||||
visible.value = true;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置表单
|
||||
*/
|
||||
const reset = () => {
|
||||
form.value = {
|
||||
id: undefined,
|
||||
label: '',
|
||||
value: '',
|
||||
color: '',
|
||||
sort: 999,
|
||||
description: '',
|
||||
dictId: dictId.value,
|
||||
};
|
||||
proxy.$refs.formRef?.resetFields();
|
||||
};
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
const handleCancel = () => {
|
||||
visible.value = false;
|
||||
proxy.$refs.formRef.resetFields();
|
||||
};
|
||||
|
||||
/**
|
||||
* 确定
|
||||
*/
|
||||
const handleOk = () => {
|
||||
proxy.$refs.formRef.validate((valid: any) => {
|
||||
if (!valid) {
|
||||
if (form.value.id !== undefined) {
|
||||
update(form.value, form.value.id).then((res) => {
|
||||
handleCancel();
|
||||
getList(dictId.value);
|
||||
proxy.$message.success(res.msg);
|
||||
});
|
||||
} else {
|
||||
add(form.value).then((res) => {
|
||||
handleCancel();
|
||||
getList(dictId.value);
|
||||
proxy.$message.success(res.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param ids ID 列表
|
||||
*/
|
||||
const handleDelete = (ids: Array<number>) => {
|
||||
del(ids).then((res) => {
|
||||
proxy.$message.success(res.msg);
|
||||
getList(dictId.value);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
const handleQuery = () => {
|
||||
getList(dictId.value);
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置
|
||||
*/
|
||||
const resetQuery = () => {
|
||||
proxy.$refs.queryRef.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换页码
|
||||
*
|
||||
* @param current 页码
|
||||
*/
|
||||
const handlePageChange = (current: number) => {
|
||||
queryParams.value.page = current;
|
||||
getList(dictId.value);
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换每页条数
|
||||
*
|
||||
* @param pageSize 每页条数
|
||||
*/
|
||||
const handlePageSizeChange = (pageSize: number) => {
|
||||
queryParams.value.size = pageSize;
|
||||
getList(dictId.value);
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'DictItem',
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="less"></style>
|
3
continew-admin-ui/src/views/system/dict/locale/en-US.ts
Normal file
3
continew-admin-ui/src/views/system/dict/locale/en-US.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
'menu.system.dict.list': 'Dictionary management',
|
||||
};
|
3
continew-admin-ui/src/views/system/dict/locale/zh-CN.ts
Normal file
3
continew-admin-ui/src/views/system/dict/locale/zh-CN.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
'menu.system.dict.list': '字典管理',
|
||||
};
|
Reference in New Issue
Block a user