Browse Source

新增字典前台页面

temp
fks-yangshouda 4 months ago
parent
commit
0fba8917f2
  1. 6
      hx-ai-intelligent/src/api/dict.ts
  2. 1
      hx-ai-intelligent/src/icon/zidian.svg
  3. 15
      hx-ai-intelligent/src/router/dict.ts
  4. 51
      hx-ai-intelligent/src/view/dict/config.ts
  5. 302
      hx-ai-intelligent/src/view/dict/index.vue

6
hx-ai-intelligent/src/api/dict.ts

@ -0,0 +1,6 @@
export enum dict {
dictionaryUnitManagement = '/carbon-smart/client/dict/dictionaryUnitManagement',
updateDictionary = '/carbon-smart/client/dict/updateDictionary',
createDictionary = '/carbon-smart/client/dict/createDictionary',
delDictionary = '/carbon-smart/client/dict/delDictionary',
}

1
hx-ai-intelligent/src/icon/zidian.svg

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1721271548889" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4319" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16"><path d="M966.632727 253.602909c-18.850909 0-34.117818 15.266909-34.117818 34.094546v537.94909H602.926545A123.136 123.136 0 0 0 512 866.048a123.182545 123.182545 0 0 0-90.926545-40.401455H91.485091V287.697455a34.117818 34.117818 0 0 0-68.189091 0v549.632c0 32.209455 25.460364 58.414545 56.785455 58.414545h340.992c24.273455 0 45.009455 15.709091 53.154909 37.748364 4.677818 12.660364 17.175273 20.689455 30.673454 20.689454h14.196364c13.498182 0 25.995636-8.029091 30.673454-20.689454 8.145455-22.039273 28.881455-37.748364 53.154909-37.748364h340.968728c31.348364 0 56.832-26.205091 56.832-58.414545V287.697455c0-18.827636-15.266909-34.094545-34.094546-34.094546zM221.230545 139.938909h199.84291c31.325091 0 56.832 21.573818 56.832 48.104727v493.614546a130.443636 130.443636 0 0 0-56.832-12.8H221.230545V139.938909zM475.694545 775.168l2.21091 24.413091h68.18909l2.187637-24.413091c6.609455-21.317818 29.090909-36.212364 54.644363-36.212364h268.055273v-216.133818a34.117818 34.117818 0 0 0-68.189091 0v146.036364h-199.866182c-20.386909 0-39.726545 4.538182-56.832 12.8V188.043636c0-26.530909 25.483636-48.104727 56.832-48.104727h199.84291v244.875636a34.094545 34.094545 0 0 0 68.212363 0V116.363636a46.545455 46.545455 0 0 0-46.545454-46.545454h-221.509819c-35.84 0-68.119273 14.405818-90.926545 37.329454A128 128 0 0 0 421.073455 69.818182H199.563636a46.545455 46.545455 0 0 0-46.545454 46.545454v622.592h268.055273c25.553455 0 48.034909 14.894545 54.62109 36.212364z" p-id="4320"></path></svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

15
hx-ai-intelligent/src/router/dict.ts

@ -0,0 +1,15 @@
const dict = {
path: '/dict',
name: 'dict',
meta: { title: '字典', icon: 'zidian', index: 7, hideChildren: true },
redirect: { name: 'dictIndex' },
children: [
{
path: 'index',
name: 'dictIndex',
meta: { title: '字典', hideChildren: true, icon: 'zidian' },
component: () => import('/@/view/dict/index.vue'),
},
],
};
export default dict;

51
hx-ai-intelligent/src/view/dict/config.ts

@ -0,0 +1,51 @@
export const tableColumns = [
// {
// title: '序号',
// customRender: (text: any) => {
// return text.index + 1;
// },
// },
{
title: 'id',
dataIndex: 'id',
},
{
title: '字典组名',
dataIndex: 'grp',
},
{
title: '字典组名描述',
dataIndex: 'grpDesc',
},
{
title: '字典Key',
dataIndex: 'dicKey',
},
{
title: '字典中文Value',
dataIndex: 'cnValue',
},
{
title: '字典英文Value',
dataIndex: 'enValue',
},
{
title: '字典描述',
dataIndex: 'description',
},
{
title: '父级ID',
dataIndex: 'parentId',
},
{
title: '排序数字',
dataIndex: 'seq',
},
{
title: '是否展示',
dataIndex: 'showed',
},
{
title: '操作',
},
];

302
hx-ai-intelligent/src/view/dict/index.vue

@ -0,0 +1,302 @@
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<div>
<a-table
:columns="tableColumns"
:data-source="data"
bordered
:pagination="false"
:scroll="{ y: 530 }">
<template #bodyCell="{ text, column, record }">
<template v-if="column.dataIndex === 'showed'">
<a-switch
:checked="text"
:checked-value="0"
:unCheckedValue="1"
@change="(checked) => updateShowed(record, true)" />
</template>
<template v-if="column.title === '操作'">
<a-button type="link" @click="updateDict(record)">编辑</a-button>
<a-button type="link" @click="deleteDict(record)">删除</a-button>
</template>
</template>
<template #title>
<div
style="display: flex; align-items: center; justify-content: space-between; width: 100%">
<div style="display: flex; align-items: center; width: 85%">
<div style="width: 10%">数据报表</div>
<a-input
v-model:value="queryParams.grp"
placeholder="请输入字典组名"
style="width: 15%" />
<a-input
v-model:value="queryParams.grpDesc"
placeholder="请输入字典组名描述"
style="width: 15%; margin-left: 10px" />
<a-input
v-model:value="queryParams.dicKey"
placeholder="请输入字典Key"
style="width: 15%; margin-left: 10px" />
<a-input
v-model:value="queryParams.cnValue"
placeholder="请输入字典中文Value"
style="width: 15%; margin-left: 10px" />
<a-button type="primary" style="margin-left: 10px" @click="getTableList">
查询
</a-button>
</div>
<a-button type="primary" style="margin-left: 10px" @click="addDict"> 新增 </a-button>
</div>
</template>
</a-table>
<a-drawer
:width="600"
:visible="visible"
:title="updateInfo.id ? '编辑' : '新增'"
:body-style="{ paddingBottom: '80px' }"
:footer-style="{ textAlign: 'right' }"
destroyOnClose
@close="onClose">
<a-form
ref="formRef"
:model="updateInfo"
:rules="rules"
:label-col="labelCol"
:wrapper-col="wrapperCol">
<a-form-item ref="grp" label="字典组名" name="grp">
<a-input v-model:value="updateInfo.grp" placeholder="请输入字典组名" />
</a-form-item>
<a-form-item ref="grpDesc" label="字典组名描述" name="grpDesc">
<a-input v-model:value="updateInfo.grpDesc" placeholder="请输入字典组名描述" />
</a-form-item>
<a-form-item ref="dicKey" label="字典Key" name="dicKey">
<a-input v-model:value="updateInfo.dicKey" placeholder="请输入字典Key" />
</a-form-item>
<a-form-item ref="cnValue" label="字典中文Value" name="cnValue">
<a-input v-model:value="updateInfo.cnValue" placeholder="请输入字典中文Value" />
</a-form-item>
<a-form-item ref="enValue" label="字典英文Value" name="enValue">
<a-input v-model:value="updateInfo.enValue" placeholder="请输入字典英文Value" />
</a-form-item>
<a-form-item ref="description" label="字典描述" name="description">
<a-input v-model:value="updateInfo.description" placeholder="请输入字典描述" />
</a-form-item>
<a-form-item ref="parentId" label="父级ID" name="parentId">
<a-input v-model:value="updateInfo.parentId" placeholder="请输入父级ID" />
</a-form-item>
<a-form-item ref="seq" label="排序数字" name="seq">
<a-input v-model:value="updateInfo.seq" placeholder="请输入排序数字" />
</a-form-item>
<a-form-item ref="showed" label="是否展示" name="showed">
<!-- <a-input v-model:value="updateInfo.showed" placeholder="请输入是否展示" /> -->
<a-switch
:checked="updateInfo.showed"
:checked-value="0"
:unCheckedValue="1"
@change="updateShowed(updateInfo, false)" />
</a-form-item>
<!-- <a-form-item label="计量单位" name="unit">
<a-cascader v-model:value="formState.unit" :options="measurementUnit" />
</a-form-item>
<a-form-item label="自动采集节点" name="collectionNode">
<a-tree-select
v-model:value="formState.collectionNode"
:tree-line="true"
:tree-data="treeData" />
</a-form-item>
<a-form-item label="计算碳排" name="isComputeCarbon">
<a-radio-group v-model:value="formState.isComputeCarbon" @change="changeRadio">
<a-radio :value="0"></a-radio>
<a-radio :value="1"></a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="排放类型" name="emissionType" :required="isRequired">
<a-select v-model:value="formState.emissionType" placeholder="请选择排放类型">
<a-select-option v-for="(item, index) in emissionTypeDic" :key="index" :value="item.id">
{{ item.cnValue }}
</a-select-option>
</a-select>
</a-form-item> -->
</a-form>
<template #footer>
<a-button style="margin-right: 8px" @click="onClose">取消</a-button>
<a-button type="primary" @click="onSubmit">确定</a-button>
</template>
</a-drawer>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted, defineOptions } from 'vue';
import { http } from '/nerv-lib/util/http';
import type { Rule } from 'ant-design-vue/es/form';
import { tableColumns } from './config';
import { dict } from '/@/api/dict';
import { NsMessage } from '/nerv-lib/component';
import { Modal } from 'ant-design-vue';
defineOptions({
energyType: 'dictIndex', // name
});
const data = ref([]);
const updateInfo = ref({});
const queryParams = ref({
grp: '',
grpDesc: '',
dicKey: '',
cnValue: '',
});
const orgId = ref('');
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
const fetch = (api, params = { orgId }) => {
return http.post(api, params);
};
//
const getTableList = () => {
fetch(dict.dictionaryUnitManagement, queryParams.value).then((res) => {
data.value = res.data;
});
};
//
const updateShowed = (record: any, falg: Boolean) => {
if (record.showed == 0) {
record.showed = 1;
} else {
record.showed = 0;
}
if (falg) {
fetch(dict.updateDictionary, record).then((res) => {
getTableList();
});
} else {
}
};
const visible = ref(false);
const formState = ref({
orgId: orgId.value,
});
const labelCol = { span: 5 };
const wrapperCol = { span: 19 };
// form
const rules: Record<string, Rule[]> = {
grp: [{ required: true, message: '请输入字典组名', trigger: 'change' }],
grpDesc: [{ required: true, message: '请输入字典组名描述', trigger: 'change' }],
dicKey: [{ required: true, message: '请输入字典Key', trigger: 'change' }],
cnValue: [{ required: true, message: '请输入字典中文Value', trigger: 'change' }],
seq: [{ required: true, message: '请输入排序数字', trigger: 'change' }],
showed: [{ required: true, message: '请输入是否展示', trigger: 'change' }],
};
interface FormState {
energyType: string;
unit: string;
collectionNode: string;
emissionType: string | undefined;
isComputeCarbon: string;
janFlag: string;
febFlag: string;
marFlag: string;
aprFlag: string;
mayFlag: string;
junFlag: string;
julFlag: string;
augFlag: string;
sepFlag: string;
octFlag: string;
novFlag: string;
decFlag: string;
}
//
const onClose = () => {
visible.value = false;
// formState.value = {
// orgId: orgId.value,
// };
// formRef.value.resetFields();
};
//
const updateDict = (record: any) => {
updateInfo.value = record;
visible.value = true;
// todo
};
//
const addDict = () => {
updateInfo.value = {};
visible.value = true;
// todo
};
//
const onSubmit = () => {
if (updateInfo.value.id) {
fetch(dict.updateDictionary, updateInfo.value).then((res) => {
if (res.retcode == 0) {
visible.value = false;
NsMessage.success('保存成功');
getTableList();
}
});
} else {
fetch(dict.createDictionary, updateInfo.value).then((res) => {
if (res.retcode == 0) {
visible.value = false;
NsMessage.success('保存成功');
getTableList();
}
});
}
};
//
const deleteDict = (record: any) => {
Modal.confirm({
title: '警告',
// icon: createVNode(ExclamationCircleOutlined),
content: '确定要删除么?',
okText: '确认',
okType: 'primary',
cancelText: '取消',
onOk() {
// let params = ;
// // http.post(dict.delDictionary, params).then((res) => {
// // if (res.retcode == 0) {
// // visible.value = false;
// // NsMessage.success('');
// // getTableList();
// // }
// // });
fetch(dict.delDictionary, { id: record.id }).then((res) => {
if (res.retcode == 0) {
visible.value = false;
NsMessage.success('删除成功');
getTableList();
}
});
},
onCancel() {
console.log('Cancel');
},
});
};
onMounted(() => {
getTableList();
});
</script>
<style scoped lang="less">
::v-deep .ant-table-title {
display: flex;
}
::v-deep .ant-table-container {
padding: 0px 16px;
}
</style>
<style scoped>
th.column-money,
td.column-money {
text-align: right !important;
}
</style>
Loading…
Cancel
Save