gridComponent.vue
4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
<div>
<a-row :gutter="[12, 12]" v-if="!isConfig">
<!-- 第一排 -->
<a-col>
<a-row :gutter="12" style="height: 400px;">
<a-col :span="6">
<!-- 电站概览【电站】基础数据 -->
<CardOne/>
</a-col>
<a-col :span="12">
<GridLayout :style="{height: '100%'}" v-model:layout="layout.pageConfig"
:row-height="30"
is-draggable
is-resizable
is-bounded>
<template #item="{item}">
<component :is="EnumChartType[item.chartType]" :public="{
cardKey:item.cardKey,
dashboardConfigId: 7
}"></component>
<!-- 编辑or删除按钮 -->
<div class="handle-row" v-if="!item.static">
<a-button type="primary" size="mini" @click="handleEditItem(item)">编辑</a-button>
</div>
</template>
</GridLayout>
</a-col>
<a-col class="weather" :span="6">
<!-- 天气 -->
<CardFour/>
</a-col>
</a-row>
</a-col>
</a-row>
<!-- 编辑 -->
<edit-card v-else :cardEditParams="cardEditParams" :deviceSn="searchForm.deviceSn"
@handleEditCancel="handleEditCancel"/>
</div>
</template>
<script setup lang="ts">
import {GridLayout} from 'grid-layout-plus'
import {onMounted, ref} from 'vue';
import CardOne from './components/card-one.vue'
import CardFour from './components/card-four.vue'
import {EnumChartType, getPageKey, getPageName} from "@/views/dashboard/preview/index";
import {useRoute, useRouter} from "vue-router";
import {getCardConfig, updateDashboardConfig} from "@/api/dashboard/api";
import EditCard from "@/views/dashboard/preview/edit-card.vue";
import {isArray} from "lodash";
const props = defineProps({
// 1 用电,2 光伏
stationType: {
type: Number,
default: 1
},
// configType 1: 指定 2: 通用
configType: {
type: Number,
default: 1
}
})
// 是否开启 配置模式
const isConfig = ref(false);
//路由
const router = useRouter();
const route = useRoute();
// 页面key
const pageKey = getPageKey(router) + '-pv';
const pageName = getPageName(route);
const searchForm = ref({
})
// grid布局
const layout = ref<any>({
id: 0,
pageName: pageName,
pageKey: pageKey,
pageType: 2,
pageConfig: [
{x: 0, y: 0, w: 8, h: 7, i: 0, static: false, chartType: 8, cardKey: 1719195486780},
{x: 8, y: 3.5, w: 4, h: 3.5, i: 1, static: false, chartType: 14, cardKey: 1719384449255},
{x: 8, y: 0, w: 4, h: 3.5, i: 2, static: false, chartType: 14, cardKey: 1719384449255},
{x: 0, y: 5, w: 3, h: 3, i: 3, static: false, chartType: 14, cardKey: 1719384449255},
{x: 3, y: 5, w: 3, h: 3, i: 4, static: false, chartType: 14, cardKey: 1719384449255},
{x: 6, y: 5, w: 3, h: 3, i: 5, static: false, chartType: 14, cardKey: 1719384449255},
{x: 9, y: 5, w: 3, h: 3, i: 6, static: false, chartType: 14, cardKey: 1719384449255},
]
});
// 传给编辑组件的数据
const cardEditParams = ref<any>();
/**
* 获取布局
*/
const getLayout = async () => {
try {
const res = await getCardConfig(pageKey);
// if (res.code === 200 && res.data) {
// layout.value = {
// ...res.data,
// pageConfig: JSON.parse(res.data.pageConfig)
// }
// }
// 如果是第一次进入页面 调用一下保存接口(生成id)
if (!res.data) {
layout.value = {
pageName,
pageKey,
pageType: 2,
pageConfig: '[]'
}
await updateDashboardConfig(layout.value);
await getLayout();
}
} catch (e) {
console.log('err', e);
}
};
/**
* 编辑
*/
const handleEditItem = (item: any) => {
cardEditParams.value = {
configType: props.configType,
chartType: item.chartType,
cardKey: item.i,
headType: item.headType,
staticType: item.staticType,
public: item.public,
dashboardConfigId: layout.value.id,
};
isConfig.value = true;
};
/**
* 子组件 是否可编辑
* @param status
*/
const changeLayoutDisable = (status: boolean) => {
if (!isArray(layout.value.pageConfig) && !layout.value.pageConfig.length) return
layout.value.pageConfig.forEach((item: any) => {
item.static = status;
});
}
/**
* 关闭编辑页组件
*/``
const handleEditCancel = () => {
isConfig.value = false;
if (props.configType === 2) {
searchForm.value.deviceSn = null;
}
}
onMounted(async () => {
await getLayout();
// changeLayoutDisable(true);
});
</script>
<style lang="less" scoped>
.handle-row {
position: absolute;
bottom: 5px;
right: 10px;
.arco-btn-status-danger {
margin-left: 10px;
}
}
</style>