feat:字典相关
This commit is contained in:
parent
5a8aba0d65
commit
a6c2b1261c
@ -3,7 +3,7 @@
|
||||
* @Author: zenghua.wang
|
||||
* @Date: 2023-06-20 11:48:41
|
||||
* @LastEditors: zenghua.wang
|
||||
* @LastEditTime: 2025-03-20 14:40:44
|
||||
* @LastEditTime: 2025-03-26 16:14:45
|
||||
*/
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import Layout from '@/layouts/index.vue';
|
||||
@ -13,6 +13,7 @@ import traceRouter from './modules/trace';
|
||||
import productOperateMainRoutes from './modules/productOperateMain';
|
||||
import inputSuppliesRoutes from './modules/inputSupplies';
|
||||
import plantingAndBreedingRouter from './modules/plantingAndBreeding';
|
||||
import systemRouter from './modules/system';
|
||||
|
||||
export const constantRoutes = [
|
||||
{
|
||||
@ -47,6 +48,7 @@ export const constantRoutes = [
|
||||
...inputSuppliesRoutes,
|
||||
...plantingAndBreedingRouter,
|
||||
...traceRouter,
|
||||
...systemRouter,
|
||||
];
|
||||
|
||||
/**
|
||||
|
25
sub-government-affairs-service/src/router/modules/system.js
Normal file
25
sub-government-affairs-service/src/router/modules/system.js
Normal file
@ -0,0 +1,25 @@
|
||||
import Layout from '@/layouts/index.vue';
|
||||
|
||||
export default [
|
||||
{
|
||||
path: '/sub-government-affairs-service/system',
|
||||
name: 'system',
|
||||
component: Layout,
|
||||
redirect: '/sub-government-affairs-service/system-dict',
|
||||
meta: { title: '系统管理', icon: 'Document' },
|
||||
children: [
|
||||
{
|
||||
path: '/sub-government-affairs-service/system-dict-type',
|
||||
component: () => import('@/views/system/dict/type.vue'),
|
||||
name: 'system-dict-type',
|
||||
meta: { title: '字典类型', icon: 'Document' },
|
||||
},
|
||||
{
|
||||
path: '/sub-government-affairs-service/system-dict',
|
||||
component: () => import('@/views/system/dict/index.vue'),
|
||||
name: 'system-dict',
|
||||
meta: { title: '字典管理', icon: 'Document' },
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
@ -3,7 +3,7 @@
|
||||
* @Author: zenghua.wang
|
||||
* @Date: 2022-02-23 21:12:37
|
||||
* @LastEditors: zenghua.wang
|
||||
* @LastEditTime: 2025-03-24 10:05:36
|
||||
* @LastEditTime: 2025-03-27 15:43:36
|
||||
*/
|
||||
import lodash from 'lodash';
|
||||
import dayjs from 'dayjs';
|
||||
@ -259,25 +259,30 @@ export const blobToJSON = (blob) => {
|
||||
* @param tree
|
||||
* @returns
|
||||
*/
|
||||
export const getTree = (tree = []) => {
|
||||
tree.forEach((item) => {
|
||||
delete item.children;
|
||||
export const getTree = (data, id = 'id', parentId = 'parentId', children = 'children') => {
|
||||
data.forEach((item) => {
|
||||
delete item[children];
|
||||
});
|
||||
|
||||
const map = {};
|
||||
tree.forEach((item) => {
|
||||
map[item.id] = item;
|
||||
data.forEach((item) => {
|
||||
map[item[id]] = item;
|
||||
});
|
||||
const arr = [];
|
||||
tree.forEach((item) => {
|
||||
const parent = map[item.parentId];
|
||||
|
||||
const tree = [];
|
||||
data.forEach((item) => {
|
||||
const parent = map[item[parentId]];
|
||||
if (parent) {
|
||||
(parent.children || (parent.children = [])).push(item);
|
||||
parent[children] = parent[children] || [];
|
||||
parent[children].push(item);
|
||||
} else {
|
||||
arr.push(item);
|
||||
tree.push(item);
|
||||
}
|
||||
});
|
||||
return arr;
|
||||
|
||||
return tree;
|
||||
};
|
||||
|
||||
/**
|
||||
* @Title 获取路由中的参数
|
||||
* @param name
|
||||
|
239
sub-government-affairs-service/src/views/system/dept/index.vue
Normal file
239
sub-government-affairs-service/src/views/system/dept/index.vue
Normal file
@ -0,0 +1,239 @@
|
||||
<template>
|
||||
<div class="custom-page">
|
||||
<avue-crud
|
||||
ref="crudRef"
|
||||
v-model="state.form"
|
||||
v-model:search="state.query"
|
||||
:table-loading="state.loading"
|
||||
:data="state.data"
|
||||
:option="state.options"
|
||||
@refresh-change="refreshChange"
|
||||
@search-reset="searchChange"
|
||||
@search-change="searchChange"
|
||||
@selection-change="selectionChange"
|
||||
@row-save="rowSave"
|
||||
@row-update="rowUpdate"
|
||||
@row-del="rowDel"
|
||||
>
|
||||
<template #menu="scope">
|
||||
<custom-table-operate :actions="state.options.actions" :data="scope" />
|
||||
</template>
|
||||
</avue-crud>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { useApp } from '@/hooks';
|
||||
import { CRUD_OPTIONS } from '@/config';
|
||||
import { isEmpty, getTree } from '@/utils';
|
||||
import { GetEntityList, AddEntity, UpdateEntity, DeleteEntity } from '@/apis/system/dept';
|
||||
|
||||
const app = useApp();
|
||||
const crudRef = ref(null);
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
query: {},
|
||||
form: {},
|
||||
selection: [],
|
||||
options: {
|
||||
...CRUD_OPTIONS,
|
||||
rowKey: 'deptId',
|
||||
index: false,
|
||||
selection: false,
|
||||
expand: true,
|
||||
column: [
|
||||
{
|
||||
label: '部门名称',
|
||||
prop: 'deptName',
|
||||
search: true,
|
||||
rules: {
|
||||
required: true,
|
||||
message: '请输入',
|
||||
trigger: 'blur',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
prop: 'status',
|
||||
type: 'select',
|
||||
search: true,
|
||||
dicData: [
|
||||
{
|
||||
label: '启用',
|
||||
value: '0',
|
||||
},
|
||||
{
|
||||
label: '禁用',
|
||||
value: '1',
|
||||
},
|
||||
],
|
||||
value: '0',
|
||||
rules: {
|
||||
required: true,
|
||||
message: '请输入',
|
||||
trigger: 'blur',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '排序',
|
||||
prop: 'orderNum',
|
||||
type: 'number',
|
||||
rules: {
|
||||
required: true,
|
||||
message: '请输入',
|
||||
trigger: 'blur',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '负责人',
|
||||
prop: 'leader',
|
||||
hide: true,
|
||||
},
|
||||
{
|
||||
label: '联系电话',
|
||||
prop: 'phone',
|
||||
hide: true,
|
||||
},
|
||||
{
|
||||
label: '邮箱',
|
||||
prop: 'email',
|
||||
hide: true,
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
name: '查看',
|
||||
icon: 'view',
|
||||
event: ({ row }) => rowView(row),
|
||||
},
|
||||
{
|
||||
name: '编辑',
|
||||
icon: 'edit',
|
||||
event: ({ row }) => rowEdit(row),
|
||||
},
|
||||
{
|
||||
type: 'danger',
|
||||
name: '删除',
|
||||
icon: 'delete',
|
||||
event: ({ row }) => rowDel(row),
|
||||
},
|
||||
],
|
||||
},
|
||||
pageData: {
|
||||
total: 0,
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
},
|
||||
data: [],
|
||||
minWeek: null,
|
||||
maxWeek: null,
|
||||
currentRow: {},
|
||||
});
|
||||
|
||||
// 加载
|
||||
const loadData = () => {
|
||||
state.loading = true;
|
||||
GetEntityList(state.query)
|
||||
.then((res) => {
|
||||
if (res.code === 200) {
|
||||
state.data = getTree(res.data, 'deptId');
|
||||
console.log(139, state.data);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
app.$message.error(err.msg);
|
||||
state.data = [];
|
||||
})
|
||||
.finally(() => {
|
||||
state.loading = false;
|
||||
});
|
||||
};
|
||||
|
||||
loadData();
|
||||
|
||||
// 搜索
|
||||
const searchChange = (params, done) => {
|
||||
if (done) done();
|
||||
state.query = params;
|
||||
loadData();
|
||||
};
|
||||
|
||||
// 刷新
|
||||
const refreshChange = () => {
|
||||
loadData();
|
||||
app.$message.success('刷新成功');
|
||||
};
|
||||
|
||||
// 选择
|
||||
const selectionChange = (rows) => {
|
||||
state.selection = rows;
|
||||
};
|
||||
|
||||
// 查看
|
||||
const rowView = (row) => {
|
||||
crudRef.value.rowView(row);
|
||||
};
|
||||
|
||||
// 新增
|
||||
const rowSave = (row, done, loading) => {
|
||||
AddEntity(row)
|
||||
.then((res) => {
|
||||
if (res.code === 200) {
|
||||
app.$message.success('添加成功!');
|
||||
done();
|
||||
loadData();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
app.$message.error(err.msg);
|
||||
})
|
||||
.finally(() => {
|
||||
loading();
|
||||
});
|
||||
};
|
||||
|
||||
// 编辑
|
||||
const rowEdit = (row) => {
|
||||
crudRef.value.rowEdit(row);
|
||||
};
|
||||
const rowUpdate = (row, index, done, loading) => {
|
||||
UpdateEntity(row)
|
||||
.then((res) => {
|
||||
if (res.code === 200) {
|
||||
app.$message.success('更新成功!');
|
||||
done();
|
||||
loadData();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
app.$message.error(err.msg);
|
||||
})
|
||||
.finally(() => {
|
||||
loading();
|
||||
});
|
||||
};
|
||||
|
||||
// 删除
|
||||
const rowDel = (row, index, done) => {
|
||||
if (isEmpty(row)) return;
|
||||
app
|
||||
.$confirm(`删除后信息将不可查看,确认要删除吗?`, '确定删除', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
DeleteEntity({ id: row.id })
|
||||
.then((res) => {
|
||||
if (res.code === 200) {
|
||||
app.$message.success('删除成功!');
|
||||
loadData();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
app.$message.error(err.msg);
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user