代码合并

This commit is contained in:
ym1026
2025-09-09 10:01:45 +08:00
22 changed files with 2150 additions and 523 deletions

View File

@@ -152,7 +152,7 @@ const data = reactive({
newPageOption: {},
newTableOpt: {},
pageSizeOptions: ['15', '20', '30', '40', '50', '100'],
pageSizeOptions: ['10', '20', '30', '40', '50', '100'],
mountedScroll
})
const loading = ref(false)

View File

@@ -1,13 +1,10 @@
<!-- item.type:xxxx-unshow:表示不显示 items.displayFlag为false表示不展示卡片 -->
<template>
<div class="card-content">
<a-card
style="margin: 0 0 15px 0; text-align: left"
>
<a-card style="margin: 0 0 15px 0; text-align: left">
<div :class="['info-title', items.title ? '' : 'title-none']">
<div class="box">
<div >
<div>
{{ items.title ? items.title : '基础信息' }}
</div>
@@ -39,7 +36,7 @@
layout="horizontal"
:wrap="true"
ref="formRef"
:rules="props.formRules"
:rules="props.formRules"
name="info-form"
class="info-form"
label-align="left"
@@ -72,7 +69,7 @@
:placeholder="'请输入' + item.label"
:disabled="!props.disabled && type ? !!item.disabled : props.disabled"
/>
<a-input-number
v-if="item.type == 'input-number'"
id="inputNumber"
@@ -138,13 +135,24 @@
:disabled="!props.disabled && type ? !!item.disabled : props.disabled"
allow-clear
>
<a-select-option
:value="selectItem.value"
v-for="selectItem in item.list"
:key="selectItem.value"
>
{{ selectItem.label }}
</a-select-option>
<template v-if="item.options">
<a-select-option
:value="selectItem[item.options.value]"
v-for="selectItem in item.list"
:key="selectItem[item.options.value]"
>
{{ selectItem[item.options.label] }}
</a-select-option>
</template>
<template v-else>
<a-select-option
:value="selectItem.value"
v-for="selectItem in item.list"
:key="selectItem.value"
>
{{ selectItem.label }}
</a-select-option>
</template>
</a-select>
<!-- 下拉多选 -->
<a-select
@@ -548,11 +556,8 @@ defineExpose({
}
.card-content {
margin-top: 15px;
}
:deep(.ant-timeline) {
color: var(--theme-text-default) !important;
@@ -572,14 +577,13 @@ defineExpose({
margin-bottom: 20px;
.box {
color:#fff;
width:230px;
color: #fff;
width: 230px;
display: flex;
align-items: center;
margin-bottom: 10px;
border-bottom: 5px solid transparent;
border-image: url('../assets/boxBottom.png') 0 0 100% 0 stretch;
border-bottom: 5px solid transparent;
border-image: url('../assets/boxBottom.png') 0 0 100% 0 stretch;
div:last-child {
height: 25px;
@@ -603,9 +607,8 @@ border-image: url('../assets/boxBottom.png') 0 0 100% 0 stretch;
.title-none {
display: none;
}
:deep(.ant-card){
:deep(.ant-card) {
background-color: transparent;
}
:deep(.ant-card-body) {
padding: 15px;
@@ -629,25 +632,24 @@ border-image: url('../assets/boxBottom.png') 0 0 100% 0 stretch;
height: calc(100% - 30px);
.info-form {
.item-div {
width:45%;
width: 45%;
display: inline-block;
}
.item-l{
width:100%;
.item-l {
width: 100%;
}
.form-item {
width:320px!important;
width: 320px !important;
}
}
}
:deep(.ant-form-item-label) {
color:#fff;
color: #fff;
font-size: 16px !important;
width:100px;
width: 100px;
}
:deep(.ant-form-item-control-wrapper) {
@@ -678,14 +680,15 @@ border-image: url('../assets/boxBottom.png') 0 0 100% 0 stretch;
}
}
:deep(.ant-calendar-picker) {
width: 100% !important;
}
:deep(.ant-picker) {
width: 100% !important;
}
:deep(.ant-input-number) {
width: 100% !important;
}
:deep(.ant-form-item.form-item) {
padding: 0px !important;
@@ -702,19 +705,7 @@ border-image: url('../assets/boxBottom.png') 0 0 100% 0 stretch;
color: var(--theme-text-default) !important;
}
:deep(.ant-checkbox-wrapper) {
color: var(--theme-text-default);
}
</style>

View File

@@ -70,6 +70,9 @@ import {
roleFormRules,
stationOptions,
stationFormRules,
deviceOptions,
deviceFormRules,
alarmlogOptions,
serviceApiOptions,
serviceApiFormRules
} from '../../public/config/columnList'
@@ -115,6 +118,7 @@ export default {
// menu: 'menuConfirm',
user: 'userConfirm',
role: 'roleConfirm',
device: 'deviceConfirm',
station: 'stationConfirm',
serviceApi: 'serviceApiConfirm',
// permission: 'permissionConfirm',
@@ -163,6 +167,13 @@ export default {
this.formRules = stationFormRules
break
case 'device':
this.detailInfos = deviceOptions
this.formRules = deviceFormRules
break
case 'alarmLog':
this.detailInfos = alarmlogOptions
this.formRules = {}
case 'serviceApi':
this.detailInfos = serviceApiOptions
this.formRules = serviceApiFormRules
@@ -342,6 +353,37 @@ export default {
console.log(error, 'stationConfirm')
}
},
async deviceConfirm() {
try {
const menuApi = {
add: '/insertDevice',
edit: '/updateDevice'
}
const { is_open, rated_capacity, rated_current, rated_voltage, reted_power } = this.form
const paramsDate = {
...this.form,
is_open: Number(is_open),
attrs: JSON.stringify({rated_capacity, rated_current, rated_voltage, reted_power})
}
if (this.action == 'edit') {
paramsDate.device_id = this.record.device_id
}
const res = await postReq(menuApi[this.action], paramsDate)
if (res.errcode === 0) {
this.$message.success('添加成功')
setTimeout(() => {
this.handleback()
}, 1000)
} else {
throw res
}
} catch (error) {
this.$message.error('添加失败')
}
},
async serviceApiConfirm() {
try {
const menuApi = {

View File

@@ -1,58 +1,89 @@
<template>
<div class="device">
<div class="device" ref="device">
<div class="device-item" v-for="item in deviceList" :key="item">
<div class="item-header">
<div style="display: flex; width: 50%">
<div class="icon-bg"></div>
<div class="icon-bg">
<span class="iconfont" :class="getIcongont(item)"></span>
</div>
<div class="title">
<span class="number">521245786665412</span>
<span class="name">逆变器1</span>
<span class="number type">逆变器</span>
<span class="number">{{ item.device_id }}</span>
<span class="name">{{ item.name }}</span>
<span class="number type">{{ item.typename }}</span>
</div>
</div>
<div class="status">
<div class="status-item">
<span>在线</span>
<span>{{ ['离线', '在线'][item.is_online] }}</span>
<span class="text">在线状态</span>
</div>
<div class="status-item">
<span>在线</span>
<span>{{ ['正常', '错误'][item.is_error] }}</span>
<span class="text">故障状态</span>
</div>
<div class="status-item">
<span>在线</span>
<span>{{ ['空闲', '工作'][item.is_running] }}</span>
<span class="text">工作状态</span>
</div>
</div>
</div>
<div class="item-content">
<div v-for="info in chunengInfo" :key="info.key">
<span class="text">{{ info.label }}</span>
<a-button
v-if="info.key === 'realTimeData'"
type="primary"
size="small"
@click="openModal"
>查看</a-button
>
<span v-else class="value">{{ info.value }}</span>
<div v-for="info in item.params" :key="info.k" class="item-info">
<span class="text">{{ info.k }}</span>
<span class="value">{{ info.v }}</span>
</div>
</div>
<div v-if="item.view == 1" class="item-button">
<span class="text">实时数据</span>
<a-button type="primary" size="small" @click="openModal(item)">查看</a-button>
</div>
</div>
<a-modal v-model:open="modalOpen" @ok="handleOk" width="800px">
<!-- <p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p> -->
<a-modal
v-model:open="modalOpen"
@ok="handleOk"
width="90%"
class="modal-device"
:get-container="() => $refs.device"
>
<div>
<div class="title">
<div>电流电压</div>
<img src="@/assets/images/titleLine.png" alt="" />
</div>
<div class="echarts">
<predictEcharts
:chart-options="chartOptions[0]"
:chart-data="chartData"
ref="chartRef1"
/>
</div>
</div>
<div>
<div class="title">
<div>功率</div>
<img src="@/assets/images/titleLine.png" alt="" />
</div>
<div class="echarts">
<predictEcharts
:chart-options="chartOptions[1]"
:chart-data="chartData"
ref="chartRef2"
/>
</div>
</div>
</a-modal>
</div>
</template>
<script>
import predictEcharts from '@/components/predict/predictEcharts.vue'
import { postReq, getReq } from '@/request/api'
import { deviceTypeList } from '@/utils/config'
export default {
name: '',
components: {},
components: { predictEcharts },
props: {
stationId: {
type: String,
@@ -79,7 +110,70 @@ export default {
{ label: '实时数据', key: 'realTimeData', value: '0.01kWh' },
{ label: '额定功率', key: 'ratedPower', value: '0.01kW' },
{ label: '冷却方式', key: 'coolingMethod', value: '风冷' }
]
],
chartOptions: [
{
type: 'line',
smooth: true,
dataKey: 'chargeDischarge',
infoKeys: [
{
key: 'V',
label: '电压',
seriesOptions: {
symbol: 'circle',
symbolSize: 8,
itemStyle: {
color: '#00FDF9' // 充电电量线条颜色
},
lineStyle: {
color: '#00FDF9' // 充电电量线条颜色
}
}
},
{
key: 'I',
label: '电流',
seriesOptions: {
symbol: 'circle',
symbolSize: 8,
itemStyle: {
color: '#3E7EEF' // 充电电量线条颜色
},
lineStyle: {
color: '#3E7EEF' // 充电电量线条颜色
}
}
}
]
},
{
type: 'line',
smooth: true,
dataKey: 'chargeDischarge',
infoKeys: [
{
key: 'P',
label: '功率',
seriesOptions: {
symbol: 'circle',
symbolSize: 8,
itemStyle: {
color: '#00FDF9' // 充电电量线条颜色
},
lineStyle: {
color: '#00FDF9' // 充电电量线条颜色
}
}
}
]
}
],
chartData: {
xdata: [],
ydata: {}
}
}
},
watch: {
@@ -99,24 +193,65 @@ export default {
this.getDeviceList()
},
methods: {
async getDeviceList() {
const data = {
category: this.systemType,
'station_id': this.stationId,
page: 0,
'page_size': 1000
}
try {
const res = await getReq('/queryDeviceList', data)
getIcongont(ele) {
return deviceTypeList.find((item) => item.value == ele.type).iconfont || ''
},
generateTimePoints() {
const timePoints = []
for (let hour = 0; hour <= 24; hour++) {
for (let minute = 0; minute < 60; minute += 10) {
// 处理24:00的特殊情况
if (hour === 24 && minute === 0) {
timePoints.push('24:00')
break
}
// 格式化小时和分钟,确保两位数
const formattedHour = hour.toString().padStart(2, '0')
const formattedMinute = minute.toString().padStart(2, '0')
timePoints.push(`${formattedHour}:${formattedMinute}`)
}
}
return timePoints
},
//查看实时数据
async getDevicCharts(item) {
try {
const res = await getReq('/queryDevicCharts', {
station_id: this.stationId,
device_id: item.device_id
})
this.chartData.ydata = res.data
this.chartData.xdata = this.generateTimePoints()
this.$refs.chartRef1.initCharts()
this.$refs.chartRef2.initCharts()
console.log(res)
this.deviceList = res.data
// this.selectStation=this.stations[0]['station_id']
} catch (error) {
console.log(error)
}
},
openModal() {
//请求运行监控系统设备信息
async getDeviceList() {
try {
const res = await getReq('/queryDevicByCategory', {
station_id: this.stationId,
category: this.systemType
})
this.deviceList = res.data
} catch (error) {
this.deviceList = []
console.log(error)
}
},
async openModal(item) {
await this.getDevicCharts(item)
this.modalOpen = true
},
handleOk() {
@@ -136,8 +271,6 @@ export default {
grid-template-columns: 1fr 1fr 1fr;
overflow-y: auto;
.device-item {
// width: 410px;
// height: 340px;
border-radius: 15px;
background: $bg2-color;
@@ -149,11 +282,16 @@ export default {
color: #fff;
justify-content: space-between;
.icon-bg {
width: 76px;
height: 72px;
width: 66px;
height: 66px;
text-align: center;
line-height: 66px;
border-radius: 6px;
background: linear-gradient(90deg, #3dfefa 0%, #2a82e4 2.96%, #27a188 100%),
linear-gradient(90deg, #3dfefa 0%, #01dfef 2.96%, #08a5ff 100%);
.iconfont {
font-size: 50px;
}
}
.title {
display: flex;
@@ -194,12 +332,20 @@ export default {
grid-template-columns: 1fr 1fr;
color: #fff;
display: grid;
line-height: 45px;
// line-height: 45px;
margin-top: 15px;
padding: 0 10px;
height: 120px;
overflow-y: auto;
.value {
font-weight: 700;
}
.item-info {
height: 30px;
}
}
.item-button {
padding-left: 10px;
}
.text {
color: $text-color;
@@ -212,4 +358,22 @@ export default {
.environment {
width: 200px;
}
:deep(.modal-device) {
color: #fff;
.title {
display: flex;
font-weight: 700;
flex-direction: column;
img {
width: 232px;
height: 6px;
margin-top: 10px;
}
}
.echarts {
width: 100%;
height: 280px;
}
}
</style>

View File

@@ -32,13 +32,12 @@
</div>
<div class="table-content">
<ComTable
:columns="columns"
:table-data="tableData"
:columns="columns[activeTab]"
:table-data="tableDatas[activeTab]"
@handlePagesizeChange="handlePagesizeChange"
ref="comTable"
:table-option="tableOption"
:page-option="pageOption"
:table-h="tableH"
>
</ComTable>
</div>
@@ -46,65 +45,143 @@
</template>
<script>
import { postReq, getReq } from '@/request/api'
export default {
name: '',
components: {},
props: {},
props: {
stationId: {
type: String,
default: ''
},
systemType: {
type: Number,
default: 1
}
},
data() {
return {
activeTab: '0',
activeTab: 'temp_hum',
columns: {
airc: [
{
title: '名称',
dataIndex: 'pos',
key: 'pos',
ellipsis: true,
align: 'center'
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
ellipsis: true,
align: 'center'
}
],
cooling: [
{
title: '名称',
dataIndex: 'pos',
key: 'pos',
ellipsis: true,
align: 'center'
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
ellipsis: true,
align: 'center'
}
],
fire40: [
{
title: '点位',
dataIndex: 'pos',
key: 'pos',
ellipsis: true,
align: 'center'
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
ellipsis: true,
align: 'center'
}
],
'temp_hum': [
{
title: '点位',
dataIndex: 'pos',
key: 'pos',
ellipsis: true,
align: 'center'
},
{
title: '温度',
dataIndex: 'temp',
key: 'temp',
ellipsis: true,
align: 'center'
},
{
title: '湿度',
dataIndex: 'hum',
key: 'hum',
ellipsis: true,
align: 'center'
}
]
},
tabList: [
{
key: '0',
key: 'temp_hum',
name: '环境温湿度信息'
},
{
key: '1',
key: 'fire40',
name: '安防信息'
},
{
key: '2',
key: 'airc',
name: '空调信息'
},
{
key: '3',
key: 'cooling',
name: '冷机信息'
}
],
columns: [
{
title: '点位',
dataIndex: 'policyId',
key: 'policyId',
ellipsis: true
},
{
title: '温度',
dataIndex: 'name',
key: 'name',
ellipsis: true
},
{
title: '湿度',
dataIndex: 'type',
key: 'type',
ellipsis: true
}
],
tableDatas: {},
tableOption: {
select: false,
page: false
}
}
},
mounted() {},
methods: {}
mounted() {
this.getEnvironment()
},
methods: {
async getEnvironment() {
try {
const res = await getReq('/queryEnvironment', { station_id: this.stationId })
console.log(res, '==============')
this.tableDatas = res.data
// this.deviceList=res.data
} catch (error) {
console.log(error)
}
}
}
}
</script>
<style lang="scss" scoped>
.videos {
width: 60%;
width: calc(100% - 470px);
margin-left: 20px;
display: grid;
grid-gap: 20px;
@@ -130,7 +207,7 @@ export default {
}
}
.environment {
width: calc(40% - 20px);
width: 430px;
margin-left: 20px;
color: #fff;
@@ -187,6 +264,7 @@ export default {
}
.table-content {
margin-top: 20px;
height: calc(100% - 60px);
:deep(.ant-table) {
border-radius: 10px 10px 0 0 !important;
overflow: hidden; /* 确保圆角生效 */

View File

@@ -1,16 +1,17 @@
<template>
<div class="echarts">
<div class="chart-container">
<div class="content-header">
<div class="chart-container" >
<div class="content-header" v-if="chartOptions.title">
<div class="verline"></div>
<span>{{ chartOptions.title }}</span>
</div>
<!-- {{ chartData.ydata }} -->
<div ref="chartContainer" class="echarts-content"></div>
</div>
</div>
</template>
<script>
import { postReq } from '@/request/api'
export default {
name: 'PredictEcharts',
props: {
@@ -20,8 +21,8 @@ export default {
required: false // 非必须
},
chartData: {
type: Array,
default: () => ([]), // 默认空对象
type: Object,
default: () => ({}), // 默认空对象
required: false // 非必须
}
},
@@ -32,12 +33,11 @@ export default {
},
mounted() {
this.$nextTick(() => {
// 确保 DOM 完全渲染
this.initCharts()
window.addEventListener('resize', this.handleResize)
})
// this.$nextTick(() => {
// // 确保 DOM 完全渲染
// this.initCharts()
// window.addEventListener('resize', this.handleResize)
// })
},
beforeUnmount() {
window.removeEventListener('resize', this.handleResize)
@@ -45,8 +45,7 @@ export default {
},
methods: {
initCharts() {
// this.chartOptions.forEach((option, index) => {
const {title,infoKeys,dataKey,type,smooth}=this.chartOptions
const {infoKeys,dataKey,type,smooth}=this.chartOptions
const dom = this.$refs.chartContainer
if (!dom) return
@@ -73,12 +72,29 @@ export default {
grid: {
left: '3%',
right: '3%',
bottom: '1%',
bottom: '15%',
containLabel: true
},
dataZoom: [
{
type: 'slider', // 滑动条型
show: true,
xAxisIndex: 0, // 控制第一个X轴
start: 0, // 初始显示范围起点(百分比)
end: 20, // 初始显示范围终点(百分比)
height: 20, // 滑动条高度
bottom: 10 // 距离底部距离
},
{
type: 'inside', // 内置型(鼠标滚轮/拖拽交互)
xAxisIndex: 0,
start: 0,
end: 20
}
],
xAxis: {
type: 'category',
data: this.chartData.map((item) => item.date),
data: this.chartData.xdata,
axisLine: {
show: true,
lineStyle: {
@@ -122,7 +138,7 @@ export default {
name: info.label,
smooth: smooth || false,
type: type,
data: this.chartData.map((item) => item[info.key]),
data: this.chartData.ydata[info.key],
...info.seriesOptions,
}
})

View File

@@ -6,7 +6,7 @@
<img src="@/assets/images/titleLine.png" alt="" />
</div>
<a-form
:model="formState"
:model="formData"
layout="inline"
label-align="left"
:label-col="{ style: { width: '85px' } }"
@@ -22,7 +22,7 @@
v-model:value="formData.type"
placeholder=""
:disabled="formStatus == 'read'"
@change="changePolicy"
>
<a-select-option v-for="item in policyTypes" :value="item.value">{{
item.label
@@ -69,39 +69,44 @@
<a-form-item label="时段表" class="col1" v-if="formData.type == '1'">
<a-table
:columns="columns"
:data-source="formData.period"
:data-source="formData.period1"
size="small"
:scroll="{ y: 500 }"
:pagination="false"
row-class-name="no-hover-row"
row-key="month"
>
<template #headerCell="{ column }">
<template v-if="column.key === 'action'">
<span>
<!-- <a-button type="primary" @click="handleAdd" :disabled="formStatus == 'read'">Add</a-button> -->
<i
class="iconfont icon-add"
@click="handleAdd"
:disabled="formStatus == 'read'"
style="cursor: pointer"
:style="{ cursor: formStatus == 'read' ? 'not-allowed' : 'pointer' }"
></i>
</span>
</template>
</template>
<template #bodyCell="{ column, record }">
<template #bodyCell="{ column, index }">
<template v-if="column.dataIndex === 'action'">
<span>
<a @click="edit(record.key)">操作</a>
<a
@click="delPeriod(index)"
:style="{ cursor: formStatus == 'read' ? 'not-allowed' : 'pointer' }"
>删除</a
>
</span>
</template>
</template>
</a-table>
</a-form-item>
<div v-if="formData.type == 5">
<a-form-item label="充放策略" class="col1">
<a-form-item label="充放策略" class="col1" name="chargePolicy">
<a-radio-group
v-model:value="formData.chargePolicy"
:disabled="formStatus == 'read'"
name="chargePolicy"
@change="changePolicy"
>
<a-radio :value="1">一充一放</a-radio>
<a-radio :value="2">两充两放</a-radio>
@@ -109,58 +114,62 @@
</a-form-item>
<a-form-item label="" class="col1">
<div class="charge">
<div class="box" v-for="(item, index) in formData.chargePolicy" :key="index">
<div class="box" v-for="(item, index) in formData.period5" :key="index">
<span>{{ index == 0 ? '一' : '二' }}次充放过程</span>
<a-form
:ref="'period' + index"
:model="formData.period"
:ref="
(el) => {
periodFormRefs[index] = el
}
"
:model="item"
layout="inline"
label-align="left"
:label-col="{ style: { width: '85px' } }"
:rules="periodRules"
>
<a-form-item label="充电时间" class="col2" required>
<a-form-item label="充电时间" class="col2" name="charge_time">
<a-time-range-picker
v-model:value="formData.period[index]['charge_time']"
format="HH:mm"
value-format="HH:mm"
:disabled="formStatus == 'read'"
v-model:value="formData.period5[index]['charge_time']"
/>
</a-form-item>
<a-form-item label="放电时间" class="col2" name="discharge_time">
<a-time-range-picker
v-model:value="formData.period5[index]['discharge_time']"
format="HH:mm"
value-format="HH:mm"
:disabled="formStatus == 'read'"
/>
</a-form-item>
<a-form-item label="放电时间" class="col2" required>
<a-time-range-picker
v-model:value="formData.period[index]['discharge_time']"
format="HH:mm"
value-format="HH:mm"
:disabled="formStatus == 'read'"
/>
</a-form-item>
<a-form-item label="充电功率" class="col2" required>
<a-form-item label="充电功率" class="col2" name="chargeType">
<a-radio-group
v-model:value="formData.period[index].chargeType"
:disabled="formStatus == 'read'"
v-model:value="formData.period5[index].chargeType"
>
<a-radio :value="0">自动</a-radio>
<a-radio :value="1">自定义</a-radio>
<a-input
style="width: 60px"
v-model:value="formData.period[index]['charge_power']"
v-model:value="formData.period5[index]['charge_power']"
></a-input>
</a-radio-group>
</a-form-item>
<a-form-item label="放电功率" class="col2" required>
<a-form-item label="放电功率" class="col2" name="dischargeType">
<a-radio-group
v-model:value="formData.period[index].dischargeType"
:disabled="formStatus == 'read'"
v-model:value="formData.period5[index].dischargeType"
>
<a-radio :value="0">自动</a-radio>
<a-radio :value="1">自定义</a-radio>
<a-input
style="width: 60px"
v-model:value="formData.period[index]['discharge_power']"
v-model:value="formData.period5[index]['discharge_power']"
></a-input>
</a-radio-group>
</a-form-item>
@@ -179,20 +188,25 @@
<a-form-item class="col1">
<div style="display: flex; justify-content: center; gap: 20px">
<a-button @click="handleCancel">取消</a-button>
<a-button @click="handleOk" type="primary">确认</a-button>
<a-button @click="handleOk" type="primary" :disabled="formStatus == 'read'">确认</a-button>
</div>
</a-form-item>
</a-form>
</div>
<a-modal v-model:open="periodModal" @ok="handlePeriodModalOk">
<a-form ref="formRef" :model="periodForm" :label-col="{ style: { width: '85px' } }">
<a-form-item ref="name" label="月份" name="month">
<a-form
ref="periodRef"
:model="periodForm"
:label-col="{ style: { width: '85px' } }"
:rules="rules"
>
<a-form-item ref="name" label="月份" name="month" required>
<a-input v-model:value="periodForm.month" />
</a-form-item>
<a-form-item label="开始时间" name="time">
<a-form-item label="开始时间" name="time" required>
<a-time-picker v-model:value="periodForm.time" value-format="HH:mm" format="HH:mm" />
</a-form-item>
<a-form-item label="时段类型" name="type">
<a-form-item label="时段类型" name="type" required>
<a-select ref="select" v-model:value="periodForm.type">
<a-select-option value="尖"></a-select-option>
<a-select-option value="峰"></a-select-option>
@@ -230,7 +244,10 @@ export default {
return {
data: [],
policyTypes,
formData: {},
formData: {
period1: [],
period5: []
},
columns: [
{
title: '月份',
@@ -273,14 +290,17 @@ export default {
message: '请选择时段',
trigger: 'change'
}
]
],
month: [{ required: true, message: '请输入名称', trigger: 'change' }],
time: [{ required: true, message: '请输入名称', trigger: 'change' }]
},
periodRules: {
chargeTime: [{ required: true, trigger: 'change' }],
dischargeTime: [{ required: true, trigger: 'change' }],
charge_time: [{ required: true, trigger: 'change' }],
discharge_time: [{ required: true, trigger: 'change' }],
chargeType: [{ required: true, trigger: 'change' }],
dischargeType: [{ required: true, trigger: 'change' }]
}
},
periodFormRefs: []
}
},
watch: {
@@ -288,38 +308,32 @@ export default {
handler(newVal) {
if (this.formStatus == 'add') {
this.formData = {
type: '1',
type: '5',
name: '测试',
price: [0, 0, 0, 0],
period: [],
period1: [],
period5: [
{
charge_time: [],
discharge_time: [],
charge_power: '',
discharge_power: '',
chargeType: null,
dischargeType: null
}
// {
// charge_time: [],
// discharge_time: [],
// charge_power: '',
// discharge_power: '',
// chargeType: 1,
// dischargeType:1
// }
],
is_open: false,
chargePolicy: 1
}
// this.formData = {
// type: '5',
// name: '测试',
// price: [0, 0, 0, 0],
// chargePolicy:1,//1从
// period: [{
// charge_time: [],
// discharge_time: [],
// charge_power: '',
// discharge_power: '',
// chargeType: 1,
// dischargeType:1
// },
// {
// charge_time: [],
// discharge_time: [],
// charge_power: '',
// discharge_power: '',
// chargeType: 1,
// dischargeType:1
// }
// ],
// is_open: false,
// chargePolicy:1
// }
} else {
this.getFormData(newVal)
}
@@ -330,46 +344,85 @@ export default {
},
mounted() {},
methods: {
changePolicy(val) {
console.log(val)
changePolicy(e) {
const val = e.target.value
if (val == 1) {
this.formData.period = []
// const {length} = this.formData.period5
// this.formData.period5.splice(1,1)
this.formData.period1=[]
} else {
this.formData.period = [
this.formData.period5[1] =
{
charge_time: [],
discharge_time: [],
charge_power: '',
discharge_power: '',
powerType: 1
},
{
charge_time: [''],
discharge_time: [''],
charge_power: '',
discharge_power: '',
powerType: 1
chargeType: null,
dischargeType:null
}
]
}
},
//提交表单
handleOk() {
const { name, type, price, is_open, period, chargePolicy } = this.formData
const newForm = { name, type, is_open }
async handleOk() {
const { type, price, is_open, chargePolicy } = this.formData
const periodKey = `period${type}`
const period = this.formData[periodKey] // 正确使用 period
const newForm = { ...this.formData, is_open: Number(is_open) }
if (type == 1) {
newForm.value = JSON.stringify({
const data = {
period: this.getPeriodJson(type, period),
price: price.map((item) => Number(item))
})
price: price.map((item) => Number(item).toFixed(2))
}
newForm.value = JSON.stringify(data)
delete newForm.period1
} else {
newForm.value = JSON.stringify({
const data = {
period: this.getPeriodJson(type, period.slice(0, chargePolicy)),
price: price.map((item) => Number(item))
})
price: price.map((item) => Number(item).toFixed(2))
}
newForm.value = JSON.stringify(data)
delete newForm.period5
}
console.log(newForm, 'this.formData')
this.addPolicy(newForm)
delete newForm.price
// console.log(this.$refs.formRef,'=================');
//校验表单
// const formRefres = await this.validateform('formRef',newForm)
// const formRefres = this.validateform(periodKey,newForm)
// console.log(formRefres);
this.validateform(newForm)
},
async validateform(newForm) {
try {
await this.$refs.formRef.validateFields()
if(newForm.type==5){
const validFormRefs = this.periodFormRefs.filter((item) =>
item && typeof item.validateFields === 'function'
)
await Promise.all(
validFormRefs.map((item) => item.validateFields())
)
}
if (this.formStatus == 'add') {
this.addPolicy(newForm)
} else if (this.formStatus == 'edit') {
this.updatePolicy(newForm)
}
} catch (error) {
console.log(error)
}
},
handleCancel() {
this.$emit('closeModal')
@@ -377,54 +430,96 @@ export default {
async addPolicy(newForm) {
try {
const res = await postReq('/insertPolicy', newForm)
if (res.errcode == 0) {
this.$message.success('添加成功')
this.$emit('closeModal', true)
}
console.log(res)
} catch (error) {
console.log(error)
}
},
async updatePolicy(newForm) {
try {
const res = await postReq('/updatePolicy', newForm)
if (res.errcode == 0) {
this.$message.success('更新成功')
this.$emit('closeModal', true)
}
console.log(res)
} catch (error) {
console.log(error)
}
},
//时段表删除
delPeriod(index) {
// console.log(record);
this.formData.period1.splice(index, 1)
},
//获取编辑的表单
getFormData(newVal) {
const { value, type } = newVal
const { price, period } = JSON.parse(value)
const jsonValue = JSON.parse(value)
const { price, period } = jsonValue
this.formData = {
...newVal,
is_open: Boolean(newVal['is_open']),
price,
period: this.getPeriod(type, period)
price
}
// const periodKey=period[type]
this.formData[`period${type}`] = this.getPeriod(type, period)
console.log(this.formData)
},
handleAdd() {
this.periodModal = true
this.periodForm = {}
},
handlePeriodModalOk() {
this.formData.period.push(this.periodForm)
this.periodModal = false
this.$refs.periodRef
.validateFields()
.then((res) => {
console.log(this.formData.period1,'=============')
const target = this.formData.period1.find((item) => item.month == this.periodForm.month)
if (target) {
target.children.push(this.periodForm) // 如果找到,放入 children
}else{
this.formData.period1.push(this.periodForm)
}
// this.formData.period1.push(this.periodForm)
this.periodModal = false
})
.catch((err) => {
console.log(err)
})
},
getPeriod(type, list=[]) {
getPeriod(type, list = []) {
let newValue = []
debugger
if (type == 1) {
list.forEach((arr, index) => {
const item = arr[0]
if (arr.length == 0) return
const item = arr[0] || []
newValue.push({
month: index + 1,
time: item[0]||'',
type: item[1]||'',
time: item[0] || '',
type: item[1] || '',
children: []
})
for (let i = 1; i < arr.length; i++) {
const element = arr[i]
newValue[index].children.push({
time: element[0]||'',
type: element[1]||''
time: element[0] || '',
type: element[1] || ''
})
}
})
} else {
this.formData.chargePolicy = list.length
list.forEach((item, index) => {
const ele = {
...item,
@@ -434,6 +529,8 @@ export default {
newValue.push(ele)
})
}
console.log(newValue, '==========')
return newValue
},
getPeriodJson(type, period) {
@@ -444,6 +541,11 @@ export default {
period.forEach((item, index) => {
const { month, time, type } = item
newPeriod[month - 1].push([time, type])
if (item.children.length > 0) {
item.children.forEach((ele) => {
newPeriod[month - 1].push([ele.time, ele.type])
})
}
})
} else {
period.forEach((item, index) => {
@@ -455,7 +557,7 @@ export default {
newPeriod.push(ele)
})
}
return JSON.stringify(newPeriod)
return newPeriod
}
}
}
@@ -533,7 +635,42 @@ export default {
}
}
}
:deep(.ant-form-item-row) {
// border: 1px solid red;
:deep(.ant-table-wrapper .ant-table-row-expand-icon) {
color: $green !important;
}
//表格行悬浮样式
:deep(.no-hover-row:hover > td) {
background-color: transparent !important;
}
:deep(.ant-table-wrapper .ant-table-cell){
background:none!important;
}
// /* 禁用行的 hover 过渡动画 */
// .ant-table-tbody > tr.ant-table-row {
// transition: none !important;
// }
// /* 确保 hover 背景色完全透明 */
// .ant-table-tbody > tr.ant-table-row:hover > td {
// background-color: transparent !important;
// }
// .ant-table-wrapper .ant-table-tbody > tr.ant-table-row:hover > td {
// background-color: transparent !important;
// }
// :deep(.ant-table-tbody > tr.ant-table-row:hover > td) {
// background-color: transparent !important;
// }
// :deep(.ant-table-tbody) {
// color: var(--theme-text-default) !important;
// > tr {
// &:hover {
// > .ant-table-cell {
// background: none !important;
// }
// }
// }
// }
</style>