字典、配置

This commit is contained in:
陈红丽 2024-12-18 11:14:32 +08:00
parent 37be5e9b01
commit 5b6f32b732
6 changed files with 225 additions and 391 deletions

View File

@ -5,12 +5,6 @@ export const columns = [
{
type: 'selection',
},
{
label: 'ID',
prop: 'id',
fixed: 'left',
width: 50,
},
{
label: '配置名称',
prop: 'name',

View File

@ -88,7 +88,7 @@
*/
const actionColumn = reactive({
width: 200,
lable: '操作',
label: '操作',
prop: 'action',
fixed: 'right',
render(record) {

View File

@ -1,7 +1,7 @@
<template>
<PageWrapper>
<el-row :gutter="10" class="mt-3">
<el-col :xs="24" :sm="24" :md="7" :lg="7" :xl="7">
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8" class="mb-4">
<el-card shadow="hover" class="border-0">
<template #header>
<el-space>
@ -12,156 +12,124 @@
</el-icon>
</template>
</el-input>
<el-button
type="primary"
icon="Search"
@click="
pager.page = 1;
loadDataTable();
"
>
查询
</el-button>
<el-button type="primary" @click="reloadTable" icon="Search"> 查询 </el-button>
</el-space>
<div style="margin-top: 15px">
<el-button type="primary" icon="Plus" @click="handleAdd" v-perm="['sys:config:add']"
>新建</el-button
>
<el-button type="warning" icon="Edit" @click="handleEdit" v-perm="['sys:config:edit']"
>编辑</el-button
>
<el-button
type="danger"
icon="Delete"
@click="handleDelete()"
v-perm="['sys:config:delete']"
>删除</el-button
>
<div style="margin-top:15px;">
<el-button type="primary" @click="addConfig" icon="Plus">新建</el-button>
<el-button type="danger" :disabled="!selectionData.length" @click="handleDelete()" icon="Delete">删除</el-button>
</div>
</template>
<div :style="{ height: fwbHeight + 'px' }" class="dict-list-box">
<div
v-for="(item, index) in configDataList"
:key="index"
@click="onCheckedRow(item)"
class="dict-item"
:class="item.id == configId ? 'active' : ''"
>
<span class="t1"
>{{ item.name }}<span class="t2">({{ item.code }})</span></span
>
</div>
</div>
<pagination
style="justify-content: flex-end"
class="mt-10 flex"
@change="loadDataTable"
v-model="pager"
layout="total, prev, pager, next"
/>
<BasicTable :columns="columns" :showTableSetting="false" :request="loadDataTable" :row-key="(row) => row.id"
ref="tableRef" :actionColumn="actionColumn" @selection-change="onSelectionChange" highlight-current-row
@row-click="onCheckedRow" :pagination="{ small: true, layout: 'total,prev, pager, next,jumper' }"/>
</el-card>
</el-col>
<el-col :xs="24" :sm="24" :md="17" :lg="17" :xl="17">
<el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="16" class="mb-4">
<el-card shadow="hover" class="mb-4 border-0 proCard">
<configItem :configId="configId" v-if="configItemShow" />
<configItem :configId="configId" v-if="configItemShow"></configItem>
</el-card>
</el-col>
</el-row>
<editDialog
v-if="editVisible"
:configId="configId"
v-model:visible="editVisible"
@success="loadDataTable()"
/>
<editDialog v-if="editVisible" :configId="configId" v-model:visible="editVisible" @success="reloadTable">
</editDialog>
</PageWrapper>
</template>
<script lang="ts" setup>
import { ref, nextTick, defineAsyncComponent, onMounted } from 'vue';
import { ref, reactive, h, nextTick, defineAsyncComponent } from 'vue';
import { SearchOutlined } from '@vicons/antd';
import { getConfigList, configDelete } from '@/api/data/config';
import { TableAction } from '@/components/Table';
import { getConfigList, configDelete, configBatchDelete } from '@/api/data/config';
import { columns } from './columns';
import configItem from './configItem.vue';
import { message, confirm } from '@/utils/auth';
const editDialog = defineAsyncComponent(() => import('./edit.vue'));
const configId = ref(0);
const configItemShow = ref(false);
import { message, confirm } from "@/utils/auth";
const editDialog = defineAsyncComponent(() =>
import('./edit.vue')
)
const configId = ref(0)
const configItemShow = ref(false)
const tableRef = ref();
const editVisible = ref(false);
/**
* 定义查询参数
*/
const editVisible = ref(false)
const selectionData = ref([])
const params = ref({
name: '',
});
const configDataList = ref([]);
/**
* 定义分页参数
*/
const pager = ref({
page: 1,
size: 10,
count: configDataList.value.length,
const actionColumn = reactive({
width: 200,
label: '操作',
prop: 'action',
fixed: 'right',
render(record) {
return h(TableAction as any, {
style: 'text',
actions: [
{
label: '编辑',
icon:'Edit',
type: 'warning',
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
icon:'Delete',
type: 'danger',
onClick: handleDelete.bind(null, record),
}
],
});
},
});
const fwbHeight = document.body.clientHeight - 360;
/**
* 执行添加
*/
const handleAdd = async () => {
configId.value = 0;
//
const addConfig = async () => {
configId.value=0
await nextTick();
editVisible.value = true;
editVisible.value=true
};
/**
* 执行编辑
*/
const handleEdit = () => {
editVisible.value = true;
//
const handleEdit = async (record: Recordable) => {
configId.value=record.row.id
await nextTick();
editVisible.value=true
};
/**
* 选中行事件
* @param row 参数
*/
//
function onCheckedRow(row) {
configId.value = row.id;
configId.value = row.id
}
/**
* 加载数据列表
*/
const loadDataTable = async () => {
const result = await getConfigList({
...params.value,
pageNo: pager.value.page,
pageSize: pager.value.size,
});
configId.value = result?.records[0]?.id;
configItemShow.value = true;
configDataList.value = result.records;
pager.value.count = result.total;
//
function reloadTable() {
tableRef.value.reload({ pageNo: 1 });
}
//;
const loadDataTable = async (res) => {
const result = await getConfigList({ ...params.value, ...res });
configId.value = result?.records[0]?.id
configItemShow.value = true
nextTick(() => {
const tables = tableRef.value.getTableRef();
tables.setCurrentRow(result?.records[0])
})
return result;
};
/**
* 执行删除
*/
async function handleDelete() {
await confirm('确定要删除?');
await configDelete(configId.value);
message('删除成功');
pager.value.page = 1;
loadDataTable();
//
async function handleDelete(record: Recordable) {
let ids = []
if (!record) {
ids = selectionData.value.map(({ id }) => id);
}
await confirm('确定要删除?');
record ? await configDelete(record.row.id) : await configBatchDelete(ids);
message("删除成功");
reloadTable()
}
function onSelectionChange(value) {
selectionData.value = value
}
/**
* 钩子函数
*/
onMounted(() => {
loadDataTable();
});
</script>
<style lang="scss" scoped>
.card-header {
@ -169,43 +137,4 @@
justify-content: space-between;
align-items: center;
}
.dict-list-box {
overflow: auto;
.dict-item {
height: 40px;
line-height: 40px;
padding: 0 6px;
cursor: pointer;
display: flex;
justify-content: space-between;
.t1 {
font-size: 14px;
display: block;
font-weight: 700;
.t2 {
font-size: 12px;
font-weight: normal;
}
}
&.active {
background-color: #e8f1ff;
border-radius: 3px;
.t1 {
color: #1677ff;
}
.t2 {
color: rgb(22, 119, 255, 0.8);
}
}
.el-badge__content.is-fixed {
top: 20px;
right: calc(-10px + var(--el-badge-size) / 2);
}
}
}
</style>

View File

@ -2,12 +2,6 @@ export const columns = [
{
type: 'selection',
},
{
label: 'ID',
prop: 'id',
fixed: 'left',
width: 50,
},
{
label: '字典名称',
prop: 'name',

View File

@ -88,7 +88,7 @@
*/
const actionColumn = reactive({
width: 200,
lable: '操作',
label: '操作',
prop: 'action',
fixed: 'right',
render(record) {

View File

@ -1,7 +1,7 @@
<template>
<PageWrapper>
<el-row :gutter="10" class="mt-3">
<el-col :xs="24" :sm="24" :md="7" :lg="7" :xl="7">
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8" class="mb-4">
<el-card shadow="hover" class="border-0">
<template #header>
<el-space>
@ -12,177 +12,133 @@
</el-icon>
</template>
</el-input>
<el-button
type="primary"
icon="Search"
@click="
pager.page = 1;
loadDataTable();
"
>查询</el-button
>
<el-button
type="primary"
icon="RefreshRight"
@click="dictRefresh"
v-perm="['sys:dict:cache']"
>刷新缓存</el-button
>
<el-button type="primary" icon="Search" @click="reloadTable"> 查询 </el-button>
</el-space>
<div style="margin-top: 15px">
<el-button type="primary" icon="Plus" @click="handleAdd" v-perm="['sys:dict:add']"
>新建</el-button
>
<el-button type="warning" icon="Edit" @click="handleEdit" v-perm="['sys:dict:edit']"
>编辑</el-button
>
<el-button
type="danger"
icon="Delete"
v-perm="['sys:dict:delete']"
@click="handleDelete()"
>删除</el-button
>
<div style="margin-top:15px;">
<el-button type="primary" @click="dictRefresh" icon="RefreshRight" v-perm="['sys:dict:cache']">刷新缓存</el-button>
<el-button type="primary" @click="addDict" icon="Plus" v-perm="['sys:dict:add']">新建</el-button>
<el-button type="danger" v-perm="['sys:dict:delete']" icon="Delete" :disabled="!selectionData.length" @click="handleDelete()">删除</el-button>
</div>
</template>
<div :style="{ height: fwbHeight + 'px' }" class="dict-list-box">
<div
v-for="(item, index) in dictDataList"
:key="index"
@click="onCheckedRow(item)"
class="dict-item"
:class="item.id == dictId ? 'active' : ''"
>
<span class="t1"
>{{ item.name }}<span class="t2">({{ item.code }})</span></span
>
</div>
</div>
<pagination
style="justify-content: flex-end"
class="mt-10 flex"
@change="loadDataTable"
v-model="pager"
layout="total, prev, pager, next"
/>
<BasicTable :columns="columns" :showTableSetting="false" :request="loadDataTable" :row-key="(row) => row.id"
ref="tableRef" :actionColumn="actionColumn" @selection-change="onSelectionChange" highlight-current-row
@row-click="onCheckedRow" :pagination="{ small: true, layout: 'total,prev, pager, next,jumper' }" />
</el-card>
</el-col>
<el-col :xs="24" :sm="24" :md="17" :lg="17" :xl="17">
<el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="16" class="mb-4">
<el-card shadow="hover" class="mb-4 border-0 proCard">
<dictItem :dictId="dictId" v-if="dictItemShow" />
<dictItem :dictId="dictId" v-if="dictItemShow"></dictItem>
</el-card>
</el-col>
</el-row>
<editDialog
v-if="editVisible"
:dictId="dictId"
v-model:visible="editVisible"
@success="loadDataTable()"
/>
<editDialog v-if="editVisible" :dictId="dictId" v-model:visible="editVisible" @success="reloadTable">
</editDialog>
</PageWrapper>
</template>
<script lang="ts" setup>
import { onMounted, ref, nextTick, defineAsyncComponent } from 'vue';
import { ref, reactive, h, nextTick, defineAsyncComponent } from 'vue';
import { SearchOutlined } from '@vicons/antd';
import { getDictList, refreshCache, dictDelete } from '@/api/data/dictionary';
import { TableAction } from '@/components/Table';
import { getDictList, refreshCache, dictDelete, dictBatchDelete } from '@/api/data/dictionary';
import { columns } from './columns';
import dictItem from './dictItem.vue';
import { message, confirm } from '@/utils/auth';
/**
* 导入组件
*/
const editDialog = defineAsyncComponent(() => import('./edit.vue'));
/**
* 定义参数变量
*/
const dictId = ref(0);
const dictItemShow = ref(false);
const dictDataList = ref([]);
const editVisible = ref(false);
/**
* 定义查询参数
*/
import { message, confirm } from "@/utils/auth";
const editDialog = defineAsyncComponent(() =>
import('./edit.vue')
)
const dictId = ref(0)
const dictItemShow = ref(false)
const tableRef = ref();
const selectedKey = ref('');
const rowKeysName = ref('');
const currentRow = ref();
const editVisible = ref(false)
const selectionData = ref([])
const params = ref({
name: '',
});
/**
*定义分页参数
*/
const pager = ref({
page: 1,
size: 20,
count: dictDataList.value.length,
const actionColumn = reactive({
width: 200,
label: '操作',
prop: 'action',
fixed: 'right',
render(record) {
return h(TableAction as any, {
style: 'text',
actions: [
{
label: '编辑',
icon:'Edit',
type: 'warning',
onClick: handleEdit.bind(null, record),
},
{
label: '删除',
icon:'Delete',
type: 'danger',
onClick: handleDelete.bind(null, record),
}
],
});
},
});
const fwbHeight = document.body.clientHeight - 360;
/**
* 执行添加
*/
const handleAdd = async () => {
dictId.value = 0;
//
const addDict = async () => {
dictId.value=0
await nextTick();
editVisible.value = true;
editVisible.value=true
};
/**
* 执行编辑
*/
const handleEdit = () => {
editVisible.value = true;
//
const handleEdit = async (record: Recordable) => {
dictId.value=record.row.id
await nextTick();
editVisible.value=true
};
/**
* 字典数据选中事件
* @param row 参数
*/
//
function onCheckedRow(row) {
dictId.value = row.id;
dictId.value = row.id
}
/**
* 加载字典项值列表
*/
const loadDataTable = async () => {
const result = await getDictList({
...params.value,
pageNo: pager.value.page,
pageSize: pager.value.size,
});
dictId.value = result?.records[0]?.id;
dictItemShow.value = true;
dictDataList.value = result.records;
pager.value.count = result.total;
//
function reloadTable() {
tableRef.value.reload({ pageNo: 1 });
}
//;
const loadDataTable = async (res) => {
const result = await getDictList({ ...params.value, ...res });
dictId.value = result?.records[0]?.id
dictItemShow.value = true
nextTick(() => {
const tables = tableRef.value.getTableRef();
tables.setCurrentRow(result?.records[0])
})
return result;
};
/**
* 刷新缓存
*/
//
async function dictRefresh() {
await refreshCache();
message('刷新成功');
message("刷新成功");
}
//
async function handleDelete(record: Recordable) {
let ids = []
if (!record) {
ids = selectionData.value.map(({ id }) => id);
}
/**
* 删除字典项
*/
async function handleDelete() {
await confirm('确定要删除?');
await dictDelete(dictId.value);
message('删除成功');
pager.value.page = 1;
loadDataTable();
record ? await dictDelete(record.row.id) : await dictBatchDelete(ids);
message("删除成功");
reloadTable()
}
function onSelectionChange(value) {
selectionData.value = value
}
/**
* 钩子函数
*/
onMounted(() => {
loadDataTable();
});
</script>
<style lang="scss" scoped>
.card-header {
@ -190,43 +146,4 @@
justify-content: space-between;
align-items: center;
}
.dict-list-box {
overflow: auto;
.dict-item {
height: 40px;
line-height: 40px;
padding: 0 6px;
cursor: pointer;
display: flex;
justify-content: space-between;
.t1 {
font-size: 14px;
display: block;
font-weight: 700;
.t2 {
font-size: 12px;
font-weight: normal;
}
}
&.active {
background-color: #e8f1ff;
border-radius: 3px;
.t1 {
color: #1677ff;
}
.t2 {
color: rgb(22, 119, 255, 0.8);
}
}
.el-badge__content.is-fixed {
top: 20px;
right: calc(-10px + var(--el-badge-size) / 2);
}
}
}
</style>