This commit is contained in:
南思 2023-07-12 10:36:35 +08:00
parent f60690c4c9
commit f137561d6e
2 changed files with 478 additions and 0 deletions

View File

@ -81,6 +81,12 @@ const routes = [
component: () => import("../views/addprovide/index.vue"),
name: "addprovide",
meta: { title: "新增服务接口" },
},
{
path: "/dc/field",
component: () => import("../views/field/index.vue"),
name: "field",
meta: { title: "字段管理" },
},
],
},

472
src/views/field/index.vue Normal file
View File

@ -0,0 +1,472 @@
<template>
<div class="example">
<TableBody v-bind="data" @handleTableHeader="handleTableHeader" @handleTablePagination="handleTablePagination"
ref="TableBodyRef">
<!-- 右侧顶部插槽 -->
<template #TableHeaderRight="{ selectData }">
<el-select v-model="reqParams.deptId" placeholder="请选择部门" @change="init" clearable class="status-select">
<el-option v-for="item in bmOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-select v-model="reqParams.projectId" placeholder="请选择项目" @change="init" clearable class="status-select">
<el-option v-for="item in bmOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</template>
<!-- 表格插槽使用 -->
<template #state="{ currentCol, currentData }">
<span>{{ currentData == '0' ? "未配置" : "已配置" }}</span>
</template>
</TableBody>
<FormDialog v-model="formDialog" v-bind="FormDialogData" @handleSubmit="handleSubmit">
</FormDialog>
</div>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import TableBody from "@/components/TableBody/TableBody.vue";
import FormDialog from "@/components/FormDialog/FormDialog.vue";
import http from "@/utils/request.js";
import { ElMessage } from "element-plus";
const bmOptions = ref([])
const TableBodyRef = ref();
const data = reactive({
/**
* @type {Object}
* @description 表格头部
*/
tableHeader: [
{
buttons: [
"create",
"edit",
"delete",
"detail",
],
},
{
buttons: [
{
type: "custom", // custom popconfirm ,
name: "ruleButton", // handleTableHeader
title: "配置规则", //
icon: "Switch", // element icon
// 1. 'single'2. 'Arbitrary '
// 3. 'custom '4.
isOpen: "custom",
// isOpen custom Boolean | | function
disabled: false,
// permission: false, //
}, {
type: "custom", // custom popconfirm ,
name: "dataButton", // handleTableHeader
title: "数据", //
icon: "Switch", // element icon
// 1. 'single'2. 'Arbitrary '
// 3. 'custom '4.
isOpen: "custom",
// isOpen custom Boolean | | function
disabled: false,
// permission: false, //
}, {
type: "custom", // custom popconfirm ,
name: "Button", // handleTableHeader
title: "字段管理", //
icon: "Switch", // element icon
// 1. 'single'2. 'Arbitrary '
// 3. 'custom '4.
isOpen: "custom",
// isOpen custom Boolean | | function
disabled: false,
// permission: false, //
},
{
name: "mixInput", //
options: [
{ label: '表中文名', value: 'name' },
{ label: '表英文名', value: 'ename' },
],
// permission: false, //
},
],
},
// permission
// undefinedfalse
{
create: undefined,
edit: false,
delete: false,
search: false,
advanced: false,
refresh: false,
bulkDelete: false,
filter: false,
},
],
/**
* @type {Array}
* @description 表格参数
*/
tableType: {
selection: true, // Boolean
tableLoading: false, // Boolean loading
tableIndex: true, // Boolean
tableTree: false, // Boolean id
tableTreeName: "children", // String 'children'
isExpand: true, // Boolean false
isHiddenPagination: false, // Boolean false
changeHeight: false, // String / Number false
},
/**
* @type {Array}
* @description 表格配置
*/
tableList: [
// {
// type: "slot", // slot 使
// name: "slotName", // name
// label: "",
// show: true, //
// sortable: true, // Boolean | 'custom' ( 'custom' handleTableSort )
// width: 100,
// },
{
name: "deptId",
label: "所属部门",
show: true,
},
{
name: "projectId",
label: "所属项目",
show: true,
},
{
name: "name",
label: "中文表名",
show: true,
},
{
name: "ename",
label: "英文表名",
show: true,
},
{
name: "intro",
label: "简介",
show: true,
},
{
type: "slot", // slot 使
name: "state", // name
label: "配置状态",
show: true, //
// sortable: true, // Boolean | 'custom' ( 'custom' handleTableSort )
// width: 100,
},
{
name: "dataNum",
label: "数据量(只读)",
show: true,
},
],
/**
* @type {Array}
* @description 表格数据(模拟数据)
*/
tableData: [],
/**
* @type {Object}
* @description 分页数据
*/
pagination: {
pageSize: 15,
current: 1,
total: 0,
},
});
//
const handleTableHeader = ({ type, data }) => {
console.log(type, '111111111111', data);
switch (type) {
case "create":
handleCreate();
break;
case "edit":
handleEdit(data);
break;
case "search":
handleSearch(data);
break;
case "delete":
handleDelete(data)
break;
case "detail":
handleDetail(data);
break;
case "mixInput":
handleMixInput(data);
break;
}
};
//
const handleTablePagination = (current) => {
console.log(current);
};
//
const handleSearch = (val) => {
reqParams.name = val.value;
init();
};
//
const handleCreate = () => {
formDialogStatus.value = 'create'
FormDialogData.title = '新增'
FormDialogData.formJsonData = {}
formDialog.value = true
};
const fromId = ref('')
//
const handleEdit = (val) => {
console.log('val', val);
formDialogStatus.value = 'edit'
const id = val[0].id
FormDialogData.title = '编辑'
http.get(`/api/system/metadata/${id}`).then(response => {
FormDialogData.formJsonData = response.data
formDialog.value = true
})
};
//
const handleDelete = (data) => {
const ids = data.map(item => {
return item.id
})
// http.post(`/api/config/removeBatch`, { ids }).then(res => {
// if (res.code == 200) {
// ElMessage({
// message: '',
// type: 'success',
// })
// init()
// }
// })
}
//
const handleDetail = (val) => {
console.log('val', val);
formDialogStatus.value = 'detail'
const id = val[0].id
FormDialogData.title = '详情'
http.get(`/api/system/metadata/${id}`).then(response => {
console.log('response', response);
FormDialogData.formJsonData = response.data
formDialog.value = true
FormDialogData.formJosnDisabled = true
})
}
//
// TableBodyRef.value.clearMixInput()
//
// TableBodyRef.value.clearSearch()
/* 表单弹框 */
const formDialog = ref(false)
const formDialogStatus = ref('')
const FormDialogData = reactive({
title: '新增', // String | |
width: '50%', // String | 30% |
formType: 'json', // 'slot' slot | 'json' json
// json
formJosnRules: {
deptId: [
{ required: true, message: '请选择所属部门', trigger: 'blur' },
],
projectId: [
{ required: true, message: '请填写所属项目', trigger: 'blur' },
],
name: [
{ required: true, message: '请填写中文表名', trigger: 'blur' },
],
ename: [
{ required: true, message: '请填写英文表名', trigger: 'blur' },
],
intro: [
{ required: true, message: '请填写简介', trigger: 'blur' },
],
state: [
{ required: true, message: '请选择配置状态', trigger: 'blur' },
],
dataNum: [
{ required: true, message: '请填写数据量', trigger: 'blur' },
],
}, // {}
formJosnLabelWidth: 'auto', // 120px label
// form
formJosnElement: [
{
type: 'tree-select', //
cloSpan: 12, // 24
disabled: false, // false
label: '所属部门', // label
placeholder: '请选择所属部门', // placeholder
model: 'deptId', // form key
options: bmOptions // type select []
},
{
type: 'input', //
cloSpan: 12, // 24
disabled: false, // false
label: '所属项目', // label
placeholder: '请填写所属项目', // placeholder
model: 'projectId', // form key
},
{
type: 'input', //
cloSpan: 12, // 24
disabled: false, // false
label: '中文表名', // label
placeholder: '请填写中文表名', // placeholder
model: 'name', // form key
},
{
type: 'input', //
cloSpan: 12, // 24
disabled: false, // false
label: '英文表名', // label
placeholder: '请填写英文表名', // placeholder
model: 'ename', // form key
},
{
type: 'input', //
cloSpan: 12, // 24
disabled: false, // false
label: '简介', // label
placeholder: '请填写简介', // placeholder
model: 'intro', // form key
},
{
type: 'select', //
cloSpan: 12, // 24
disabled: false, // false
label: '配置状态', // label
placeholder: '请选择配置状态', // placeholder
model: 'state', // form key
options: [
{
label: '启用',
value: "1",
},
{
label: '未启用',
value: "0",
},
] // type select []
},
{
type: 'number', //
cloSpan: 12, // 24
disabled: false, // false
label: '数据量', // label
placeholder: '请填写数据量', // placeholder
model: 'dataNum', // form key
},
],
formJosnDisabled: false, //
formJsonData: {}, //
})
const handleSubmit = (formJsonValue) => {
console.log(formJsonValue)
switch (formDialogStatus.value) {
case 'create':
http.post(`/api/system/metadata`, formJsonValue).then(response => {
if (response.code == 200) {
ElMessage({
message: '新增成功',
type: 'success',
})
init()
formDialog.value = false
}
})
break;
case 'edit':
formJsonValue.id = formJsonValue.id
http.post(`/api/system/metadata`, formJsonValue).then(response => {
if (response.code == 200) {
ElMessage({
message: '编辑成功',
type: 'success',
})
fromId.value = ''
init()
formDialog.value = false
}
})
break;
default:
break;
}
}
/* 请求参数 */
const reqParams = reactive({
page: data.pagination.current,
size: data.pagination.pageSize,
deptId: undefined,
projectId: undefined,// id
name: undefined,//
ename: undefined, //
})
const handleMixInput = (val) => {
reqParams.name = undefined
reqParams.ename = undefined
if (val.seachMixSelect.value === '' || val.seachMixInput.value === '') {
init()
return
}
reqParams[val.seachMixSelect.value] = val.seachMixInput.value
init()
}
//
const init = () => {
data.tableType.tableLoading = true
http.get(`/api/system/metadata`, reqParams).then(res => {
if (res.code == 200) {
console.log(res.data)
data.tableData = res.data.rows
data.tableType.tableLoading = false
data.pagination.total = res.data.count
}
}).catch(() => {
data.tableType.tableLoading = false
})
}
onMounted(() => {
init()
})
</script>
<style lang="scss" scoped>
.status-select {
width: 200px;
}
</style>