电表页面优化
This commit is contained in:
parent
9829f24d0a
commit
4004700a70
|
|
@ -0,0 +1,87 @@
|
|||
<template>
|
||||
<a-drawer :title="title" :width="width" :visible="visible" :closable="true" :footer-style="{ textAlign: 'right' }"
|
||||
:bodyStyle="{ padding: '14px' }" @close="handleCancel">
|
||||
<template #footer>
|
||||
<a-button type="primary" style="margin-right: 8px" @click="handleCancel">关闭</a-button>
|
||||
<a-button type="primary" @click="handleOk" v-if="!disableSubmit">确认</a-button>
|
||||
</template>
|
||||
<ElectricityInfoDrawer v-if="visible" ref="registerForm" @ok="submitCallback" :formDisabled="disableSubmit"
|
||||
:formBpm="false">
|
||||
</ElectricityInfoDrawer>
|
||||
</a-drawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, nextTick, defineExpose } from 'vue';
|
||||
import ElectricityInfoDrawer from './ElectricityInfoDrawer.vue'
|
||||
import JModal from '/@/components/Modal/src/JModal/JModal.vue';
|
||||
|
||||
const title = ref<string>('');
|
||||
const width = ref<number>(800);
|
||||
const visible = ref<boolean>(false);
|
||||
const disableSubmit = ref<boolean>(false);
|
||||
const registerForm = ref();
|
||||
const configForm = ref();
|
||||
const configVisible = ref<boolean>(false);
|
||||
const emit = defineEmits(['register', 'success']);
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
function add() {
|
||||
title.value = '新增';
|
||||
visible.value = true;
|
||||
nextTick(() => {
|
||||
registerForm.value.add();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定按钮点击事件
|
||||
*/
|
||||
function handleOk() {
|
||||
registerForm.value.submitForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* form保存回调事件
|
||||
*/
|
||||
function submitCallback() {
|
||||
handleCancel();
|
||||
emit('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消按钮回调事件
|
||||
*/
|
||||
function handleCancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工信息变更-关闭
|
||||
*/
|
||||
function handleConfigCancel() {
|
||||
configVisible.value = false
|
||||
emit('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工信息变更确认
|
||||
*/
|
||||
function handleConfigOk() {
|
||||
configForm.value.submitForm();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
add,
|
||||
disableSubmit,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
/**隐藏样式-modal确定按钮 */
|
||||
.jee-hidden {
|
||||
display: none !important;
|
||||
}
|
||||
</style>
|
||||
<style lang="less" scoped></style>
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
<template>
|
||||
<a-spin :spinning="confirmLoading">
|
||||
<JFormContainer :disabled="disabled">
|
||||
<template #detail>
|
||||
<a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
||||
<a-row >
|
||||
<a-col :span="24">
|
||||
<a-form-item label="设备序号">
|
||||
<a-input v-model:value="formData.sn"></a-input>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</template>
|
||||
</JFormContainer>
|
||||
</a-spin>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted } from 'vue';
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { getValueType } from '/@/utils';
|
||||
import { save } from '../electricity.api';
|
||||
import { Form } from 'ant-design-vue';
|
||||
|
||||
const props = defineProps({
|
||||
formDisabled: { type: Boolean, default: false },
|
||||
formData: { type: Object, default: ()=>{} },
|
||||
formBpm: { type: Boolean, default: true }
|
||||
});
|
||||
const formRef = ref();
|
||||
const useForm = Form.useForm;
|
||||
const emit = defineEmits(['register', 'ok']);
|
||||
const formData = reactive<Record<string, any>>({
|
||||
id: '',
|
||||
sn: '',
|
||||
});
|
||||
const { createMessage } = useMessage();
|
||||
const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
|
||||
const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
|
||||
const confirmLoading = ref<boolean>(false);
|
||||
//表单验证
|
||||
const validatorRules = {
|
||||
// remarks: [{ required: true, message: '请输入备注!'},],
|
||||
};
|
||||
const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });
|
||||
|
||||
// 表单禁用
|
||||
const disabled = computed(()=>{
|
||||
if(props.formBpm === true){
|
||||
if(props.formData.disabled === false){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return props.formDisabled;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
function add() {
|
||||
let record = {};
|
||||
edit(record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
function edit(record) {
|
||||
nextTick(() => {
|
||||
resetFields();
|
||||
//赋值
|
||||
const tmpData = {};
|
||||
Object.keys(formData).forEach((key) => {
|
||||
if(record.hasOwnProperty(key)){
|
||||
tmpData[key] = record[key]
|
||||
}
|
||||
})
|
||||
//赋值
|
||||
Object.assign(formData, tmpData);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交数据
|
||||
*/
|
||||
async function submitForm() {
|
||||
try {
|
||||
// 触发表单验证
|
||||
await validate();
|
||||
} catch ({ errorFields }) {
|
||||
if (errorFields) {
|
||||
const firstField = errorFields[0];
|
||||
if (firstField) {
|
||||
formRef.value.scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
}
|
||||
return Promise.reject(errorFields);
|
||||
}
|
||||
confirmLoading.value = true;
|
||||
const isUpdate = ref<boolean>(false);
|
||||
//时间格式化
|
||||
let model = formData;
|
||||
if (model.id) {
|
||||
isUpdate.value = true;
|
||||
}
|
||||
//循环数据
|
||||
for (let data in model) {
|
||||
//如果该数据是数组并且是字符串类型
|
||||
if (model[data] instanceof Array) {
|
||||
let valueType = getValueType(formRef.value.getProps, data);
|
||||
//如果是字符串类型的需要变成以逗号分割的字符串
|
||||
if (valueType === 'string') {
|
||||
model[data] = model[data].join(',');
|
||||
}
|
||||
}
|
||||
}
|
||||
await save(model)
|
||||
.then((res) => {
|
||||
if (res.success) {
|
||||
createMessage.success(res.message);
|
||||
emit('ok');
|
||||
} else {
|
||||
createMessage.warning(res.message);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
confirmLoading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
add,
|
||||
edit,
|
||||
submitForm,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
</style>
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import { defHttp } from '/@/utils/http/axios';
|
||||
|
||||
enum Api {
|
||||
list = '/iot/hs/dsElectricityMeter/list',
|
||||
save = '/iot/hs/dsElectricityMeter/add',
|
||||
delete = '/iot/hs/dsElectricityMeter/delete',
|
||||
eleReset = '/iot/hs/dsElectricityMeter/eleReset',
|
||||
eleCutOff = '/iot/hs/dsElectricityMeter/eleControl',
|
||||
eleConnected = '/iot/hs/dsElectricityMeter/eleControl',
|
||||
eleRead = '/iot/hs/dsElectricityMeter/eleRead',
|
||||
}
|
||||
|
||||
/**
|
||||
* 电表列表接口
|
||||
* @param params
|
||||
*/
|
||||
export const list = (params) => defHttp.get({ url: Api.list, params });
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param params
|
||||
*/
|
||||
export const save = (params) => defHttp.post({ url: Api.save, params });
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
*/
|
||||
export const deleteMeter = (id) => defHttp.delete({ url: Api.delete, params:{ id } }, { joinParamsToUrl: true });
|
||||
|
||||
/**
|
||||
* 电表清零
|
||||
* @param params
|
||||
*/
|
||||
export const eleReset = (params?) => defHttp.get({ url: Api.eleReset, params });
|
||||
|
||||
/**
|
||||
* 拉闸
|
||||
* @param params
|
||||
*/
|
||||
export const eleCutOff = (params?) => defHttp.get({ url: Api.eleCutOff, params });
|
||||
|
||||
/**
|
||||
* 合闸
|
||||
* @param params
|
||||
*/
|
||||
export const eleConnected = (params?) => defHttp.get({ url: Api.eleConnected, params });
|
||||
|
||||
/**
|
||||
* 抄电表
|
||||
* @param params
|
||||
*/
|
||||
export const eleRead = (params?) => defHttp.get({ url: Api.eleRead, params });
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
import {BasicColumn} from '/@/components/Table';
|
||||
import {FormSchema} from '/@/components/Table';
|
||||
|
||||
//列表数据
|
||||
export const columns: BasicColumn[] = [
|
||||
// {
|
||||
// title: '单元编码',
|
||||
// align: "center",
|
||||
// dataIndex: 'nuId'
|
||||
// },
|
||||
// {
|
||||
// title: '单元名称',
|
||||
// align: "center",
|
||||
// dataIndex: 'nuName'
|
||||
// },
|
||||
{
|
||||
title: '序号',
|
||||
align: "center",
|
||||
dataIndex: 'id'
|
||||
},
|
||||
{
|
||||
title: '设备序号',
|
||||
align: "center",
|
||||
dataIndex: 'sn'
|
||||
},
|
||||
{
|
||||
title: '设备维度',
|
||||
align: "center",
|
||||
dataIndex: 'dimension'
|
||||
},
|
||||
{
|
||||
title: '设备状态',
|
||||
align: "center",
|
||||
dataIndex: 'relayState',
|
||||
customRender:({record})=>{
|
||||
return record.relayState?(record.relayState=='1'?'合闸':'拉闸'):'';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '分配状态',
|
||||
align: "center",
|
||||
dataIndex: 'izAllocate',
|
||||
customRender:({record})=>{
|
||||
if(record.izAllocate=='Y'){
|
||||
return "已分配";
|
||||
}else{
|
||||
return "未分配";
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '用电量KWH',
|
||||
align: "center",
|
||||
dataIndex: 'eleValue'
|
||||
},
|
||||
{
|
||||
title: '上次抄表时间',
|
||||
align: "center",
|
||||
dataIndex: 'readTime'
|
||||
},
|
||||
];
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{
|
||||
label: '设备状态',
|
||||
field: 'relayState',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: [
|
||||
{ label: '合闸', value: '1' },
|
||||
{ label: '拉闸', value: '0' },
|
||||
],
|
||||
},
|
||||
// colProps: { span: 6 },
|
||||
},
|
||||
{
|
||||
label: '分配状态',
|
||||
field: 'izAllocate',
|
||||
component: 'JDictSelectTag',
|
||||
componentProps: {
|
||||
placeholder: '请选择分配状态',
|
||||
options: [
|
||||
{label: '已分配', value: 'Y'},
|
||||
{label: '未分配', value: 'N'},
|
||||
],
|
||||
},
|
||||
// colProps: { span: 6 },
|
||||
}
|
||||
];
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
<template>
|
||||
<div>
|
||||
<!--引用表格-->
|
||||
<BasicTable @register="registerTable">
|
||||
<!--插槽:table标题-->
|
||||
<template #tableTitle>
|
||||
<a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd"> 添加设备</a-button>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record, index, text }">
|
||||
<template v-if="column.dataIndex === 'relayState'">
|
||||
<span v-if="record.relayState ==='1'" style="color:green">
|
||||
合闸
|
||||
</span>
|
||||
<span v-else style="color:red">
|
||||
拉闸
|
||||
</span>
|
||||
</template>
|
||||
</template>
|
||||
<!--操作栏-->
|
||||
<template #action="{ record }">
|
||||
<TableAction :actions="getTableAction(record)"/>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<ApiLogModal ref="apiLogModal"></ApiLogModal>
|
||||
<DrawerModal ref="registerDrawer" @success="handleSuccess" />
|
||||
<a-modal v-model:visible="tipVisible" width="300px">
|
||||
<template #title>
|
||||
<Icon icon="ant-design:info-circle-outlined" :size="20" style="margin-right:10px;color:white;background:#1ea0fa;border-radius:10px;"/>{{tipTitle}}
|
||||
</template>
|
||||
<div style="text-align: center;margin: 40px 0;">
|
||||
{{tipContent}}
|
||||
</div>
|
||||
<template #footer style="text-align: center;">
|
||||
<a-button type="primary" style="margin-right: 35%" @click="handleCancel">知道了</a-button>
|
||||
</template>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="iot-nuIotElectricitynInfo" setup>
|
||||
import {reactive, ref,h} from 'vue';
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table';
|
||||
import { useListPage } from '/@/hooks/system/useListPage';
|
||||
import { useUserStore } from '/@/store/modules/user';
|
||||
import {Modal} from "ant-design-vue";
|
||||
import {list, add, deleteMeter, eleReset, eleCutOff, eleConnected, eleRead} from './electricity.api';
|
||||
import { columns, searchFormSchema } from './electricity.data';
|
||||
import {useModal} from "@/components/Modal";
|
||||
import ApiLogModal from "./apilog/ApiLogModal.vue";
|
||||
import DrawerModal from "./components/DrawerModal.vue";
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
|
||||
const queryParam = reactive<any>({});
|
||||
const apiLogModal = ref();
|
||||
const registerDrawer = ref();
|
||||
const tipVisible = ref(false);
|
||||
const tipTitle = ref('提示');
|
||||
const tipContent = ref('');
|
||||
//注册model
|
||||
const [registerModal, {openModal}] = useModal();
|
||||
//注册table数据
|
||||
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
|
||||
tableProps:{
|
||||
title: '智能电表',
|
||||
api: list,
|
||||
columns,
|
||||
canResize:false,
|
||||
showIndexColumn: true,
|
||||
formConfig: {
|
||||
//labelWidth: 120,
|
||||
schemas: searchFormSchema,
|
||||
autoSubmitOnEnter:true,
|
||||
showAdvancedButton:false,
|
||||
fieldMapToNumber: [
|
||||
],
|
||||
fieldMapToTime: [
|
||||
],
|
||||
},
|
||||
actionColumn: {
|
||||
width: 290,
|
||||
fixed:'right'
|
||||
},
|
||||
beforeFetch: (params) => {
|
||||
return Object.assign(params, queryParam);
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
function handleAdd() {
|
||||
registerDrawer.value.disableSubmit = false;
|
||||
registerDrawer.value.add();
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
tipVisible.value = false;
|
||||
}
|
||||
/**
|
||||
* 成功回调
|
||||
*/
|
||||
function handleSuccess() {
|
||||
(selectedRowKeys.value = []) && reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作栏
|
||||
*/
|
||||
function getTableAction(record){
|
||||
return [
|
||||
{
|
||||
label: '删除',
|
||||
onClick: handleRead.bind(null, record),
|
||||
ifShow: record.izAllocate != 'Y',
|
||||
},
|
||||
{
|
||||
label: '抄表',
|
||||
onClick: handleRead.bind(null, record),
|
||||
},
|
||||
{
|
||||
label: '拉闸',
|
||||
popConfirm: {
|
||||
title: '是否确认拉闸',
|
||||
confirm: handleControlLz.bind(null, record),
|
||||
placement: 'topLeft',
|
||||
},
|
||||
ifShow: record.relayState == 1,
|
||||
},
|
||||
{
|
||||
label: '合闸',
|
||||
popConfirm: {
|
||||
title: '是否确认合闸',
|
||||
confirm: handleControlHz.bind(null, record),
|
||||
placement: 'topLeft',
|
||||
},
|
||||
ifShow: record.relayState == 0,
|
||||
},
|
||||
{
|
||||
label: '清零',
|
||||
popConfirm: {
|
||||
title: '是否确认清零',
|
||||
confirm: handleReset.bind(null, record),
|
||||
placement: 'topLeft',
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '日志',
|
||||
onClick: showApiLog.bind(null, record),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// 抄电表
|
||||
async function handleRead(record: Recordable) {
|
||||
const params = {
|
||||
'cid' : record.cid,
|
||||
'address' : record.address,
|
||||
};
|
||||
await eleRead(params);
|
||||
reload();
|
||||
}
|
||||
|
||||
// 电表拉闸
|
||||
async function handleControlLz(record: Recordable) {
|
||||
if(record.relayState == '0'){
|
||||
tipVisible.value=true;
|
||||
tipTitle.value = "拉闸";
|
||||
tipContent.value = "此电表已拉闸!";
|
||||
return;
|
||||
}
|
||||
const params = {
|
||||
'sn' : record.sn
|
||||
};
|
||||
await eleCutOff(params);
|
||||
reload();
|
||||
}
|
||||
|
||||
// 电表合闸
|
||||
async function handleControlHz(record: Recordable) {
|
||||
if(record.relayState == '1'){
|
||||
tipVisible.value=true;
|
||||
tipTitle.value = "合闸";
|
||||
tipContent.value = "此电表已合闸!";
|
||||
return;
|
||||
}
|
||||
const params = {
|
||||
'sn' : record.sn
|
||||
};
|
||||
await eleConnected(params);
|
||||
reload();
|
||||
}
|
||||
|
||||
// 电表清零
|
||||
async function handleReset(record: Recordable) {
|
||||
const params = {
|
||||
'sn' : record.sn
|
||||
};
|
||||
await eleReset(params);
|
||||
reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看api日志
|
||||
*/
|
||||
function showApiLog(record){
|
||||
console.log(record);
|
||||
apiLogModal.value.disableSubmit = true;
|
||||
apiLogModal.value.showApiLog(record);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -142,7 +142,7 @@ export const searchFormSchema: FormSchema[] = [
|
|||
// colProps: { span: 6 },
|
||||
// },
|
||||
// {
|
||||
// label: '设备号',
|
||||
// label: '设备序号',
|
||||
// field: 'address',
|
||||
// component: 'Input',
|
||||
// colProps: { span: 4 },
|
||||
|
|
@ -154,8 +154,8 @@ export const searchFormSchema: FormSchema[] = [
|
|||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: [
|
||||
{ label: '合闸', value: '1' },
|
||||
{ label: '拉闸', value: '0' },
|
||||
{ label: '开闸', value: '1' },
|
||||
{ label: '关闸', value: '0' },
|
||||
],
|
||||
},
|
||||
// colProps: { span: 4 },
|
||||
|
|
|
|||
|
|
@ -128,12 +128,12 @@ export const searchFormSchema: FormSchema[] = [
|
|||
// },
|
||||
// colProps: { span: 6 },
|
||||
// },
|
||||
{
|
||||
label: '设备号',
|
||||
field: 'sn',
|
||||
component: 'Input',
|
||||
// colProps: { span: 4 },
|
||||
},
|
||||
// {
|
||||
// label: '设备序号',
|
||||
// field: 'sn',
|
||||
// component: 'Input',
|
||||
// // colProps: { span: 4 },
|
||||
// },
|
||||
{
|
||||
label: '在线状态',
|
||||
field: 'status',
|
||||
|
|
@ -170,7 +170,7 @@ export const formSchema: FormSchema[] = [
|
|||
ifShow: false,
|
||||
},
|
||||
{
|
||||
label: '设备号',
|
||||
label: '设备序号',
|
||||
field: 'sn',
|
||||
component: 'Input',
|
||||
dynamicDisabled: ({ values }) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue