驾驶舱功能开发

This commit is contained in:
GGJ
2025-05-28 08:41:29 +08:00
parent 2a6b9a37d2
commit 06d4f0ec91
21 changed files with 1866 additions and 170 deletions

View File

@@ -0,0 +1,242 @@
<template>
<GridLayout
v-model:layout="layout"
:row-height="rowHeight"
:is-resizable="false"
:is-draggable="false"
:responsive="false"
:vertical-compact="false"
prevent-collision
:col-num="12"
>
<template #item="{ item }">
<div class="box">
<div class="title">
<div style="display: flex; align-items: center">
<HelpFilled class="HelpFilled" />
{{ item.name }}
</div>
<!-- <FullScreen class="HelpFilled" style="cursor: pointer" @click="zoom(item)" /> -->
<img :src="flag ? img : img1" style="cursor: pointer; height: 16px" @click="zoom(item)" />
</div>
<div>
<component
:is="item.component"
v-if="item.component"
class="pd10"
:key="key"
:height="rowHeight * item.h - (item.h == 6 ? -20 : item.h == 2 ? 20 : 5) + 'px'"
:width="rowWidth * item.w - 5 + 'px'"
/>
<div v-else class="pd10">组件加载失败...</div>
</div>
</div>
</template>
</GridLayout>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, markRaw, onUnmounted, defineAsyncComponent, type Component } from 'vue'
import { GridLayout } from 'grid-layout-plus'
import { useDebounceFn } from '@vueuse/core'
import { queryActivatePage } from '@/api/system-boot/csstatisticalset'
import { HelpFilled, FullScreen } from '@element-plus/icons-vue'
// defineOptions({
// name: 'cockpit/homePage'
// })
// 定义类型
interface LayoutItem {
x: number
y: number
w: number
h: number
i: string | number
name: string
path: string
component?: Component | string
loading?: boolean
error?: any
}
const key = ref(0)
const img = new URL(`@/assets/imgs/amplify.png`, import.meta.url)
const img1 = new URL(`@/assets/imgs/reduce.png`, import.meta.url)
// 响应式数据
const rowHeight = ref(0)
const rowWidth = ref(0)
const layout = ref<LayoutItem[]>([
// {
// x: 4,
// y: 0,
// w: 4,
// h: 2,
// i: '1',
// name: '',
// path: '/src/views/pqs/runManage/assessment/components/uese/index.vue'
// },
])
const layoutCopy = ref<LayoutItem[]>([])
const flag = ref(true)
// 组件映射
const componentMap = reactive(new Map<string, Component | string>())
// 获取主内容区域高度
const getMainHeight = () => {
const elMain = document.querySelector('.el-main')
return (elMain?.offsetHeight || 0) - 70
}
// 获取主内容区域高度
const getMainWidth = () => {
const elMain = document.querySelector('.el-main')
return (elMain?.offsetWidth || 0) - 20
}
// 初始化行高
const initRowHeight = () => {
rowHeight.value = Math.max(0, getMainHeight() / 6)
rowWidth.value = Math.max(0, getMainWidth() / 12)
}
// 动态注册组件
const registerComponent = (path: string): Component | string | null => {
if (!path) return null
const cacheKey = path
// 使用缓存的组件
if (componentMap.has(cacheKey)) {
return componentMap.get(cacheKey)!
}
try {
// 动态导入组件
const modules = import.meta.glob('@/views/**/*.vue')
if (!modules[path]) {
console.error(`组件加载失败: ${path}`)
return null
}
const AsyncComponent = defineAsyncComponent({
loader: modules[path],
loadingComponent: () => h('div', '加载中...'),
errorComponent: ({ error }) => h('div', `加载错误: ${error.message}`),
delay: 200,
timeout: 10000
})
// 保存到映射中
componentMap.set(cacheKey, markRaw(AsyncComponent))
return AsyncComponent
} catch (error) {
console.error('注册组件失败:', error)
return null
}
}
// 缩放
const zoom = (value: any) => {
if (flag.value) {
layout.value = [{ ...value, x: 0, y: 0, w: 12, h: 6 }]
} else {
layout.value = layoutCopy.value.map((item, index) => ({
...item,
i: item.i || index, // 确保有唯一标识
component: registerComponent(item.path)
}))
}
flag.value = !flag.value
key.value += 1
}
// 获取布局数据
const fetchLayoutData = async () => {
try {
const { data } = await queryActivatePage()
const parsedLayout = JSON.parse(data.containerConfig || '[]') as LayoutItem[]
// 处理布局数据
layout.value = parsedLayout.map((item, index) => ({
...item,
i: item.i || index, // 确保有唯一标识
component: registerComponent(item.path)
}))
layoutCopy.value = JSON.parse(JSON.stringify(layout.value))
} catch (error) {
console.error('获取布局数据失败:', error)
// 可以添加错误提示逻辑
}
}
// 窗口大小变化处理 - 使用防抖
const handleResize = useDebounceFn(() => {
initRowHeight()
key.value += 1
}, 200)
// 生命周期钩子
onMounted(() => {
initRowHeight()
fetchLayoutData()
// 添加窗口大小变化监听器
window.addEventListener('resize', handleResize)
})
onUnmounted(() => {
// 移除监听器防止内存泄漏
window.removeEventListener('resize', handleResize)
})
</script>
<style lang="scss" scoped>
.vgl-layout {
background-color: #f8f9fa;
border-radius: 4px;
overflow: hidden;
}
:deep(.vgl-item:not(.vgl-item--placeholder)) {
background-color: #ffffff;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
transition: all 0.3s ease;
}
:deep(.vgl-item:hover:not(.vgl-item--placeholder)) {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.12);
}
:deep(.vgl-item--static) {
background-color: #f0f2f5;
}
.text {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
color: #606266;
}
:deep(.vgl-item) {
overflow: hidden;
}
.box {
overflow: hidden;
.title {
border-bottom: 1px solid #000;
font-size: 14px;
height: 30px;
font-weight: 600;
padding: 0px 10px;
color: #fff;
background-color: var(--el-color-primary);
display: flex;
align-items: center;
justify-content: space-between;
}
.HelpFilled {
height: 16px;
width: 16px;
margin-right: 5px;
}
}
</style>

View File

@@ -0,0 +1,374 @@
<template>
<el-dialog
draggable
:title="title"
v-model.trim="dialogVisible"
width="900px"
:before-close="handleClose"
:close-on-click-modal="false"
>
<div style="display: flex">
<el-form ref="formRef" style="flex: 1" :rules="rules" :model="form" label-width="auto" class="form mr10">
<el-form-item label="页面名称:" prop="pageName">
<el-input
maxlength="32"
show-word-limit
v-model.trim="form.pageName"
placeholder="请输入页面名称"
></el-input>
</el-form-item>
<el-form-item label="页面排序:" prop="sort">
<el-input
maxlength="32"
show-word-limit-number
v-model.trim.number="form.sort"
:min="0"
:step="1"
step-strictly
style="width: 100%"
/>
</el-form-item>
<el-form-item label="备注:" class="top">
<el-input
maxlength="300"
show-word-limit
type="textarea"
:rows="2"
placeholder="请输入内容"
v-model.trim="form.remark"
></el-input>
</el-form-item>
</el-form>
<!-- 拖拽组件 -->
<div>
<div class="image">
<img
v-for="(item, index) in imgList"
:key="index"
:src="item"
class="mr10"
@click="imgData(index)"
/>
<el-button type="primary" icon="el-icon-Plus" size="small" @click="addItem">添加容器</el-button>
</div>
<GridLayout
class="GridLayout"
v-model:layout="layout"
style="width: 511px; height: 310px"
:row-height="40"
:col-num="12"
>
<template #item="{ item }">
<span class="text">{{ `${item.name}` }}</span>
<!-- <span class="remove" @click="removeItem(item.i)">x</span> -->
<CloseBold class="remove" @click="removeItem(item.i)" />
<el-popover placement="top" :width="230" trigger="click">
<template #reference>
<!-- <span class="bind">绑定页面</span> -->
<Tools class="bind" />
</template>
<el-select
v-model="item.path"
filterable
placeholder="选择绑定页面"
class="mb10"
@change="change($event, item)"
>
<el-option
v-for="item in treeList"
:key="item.id"
:label="item.name"
:value="item.path"
/>
</el-select>
</el-popover>
</template>
</GridLayout>
</div>
</div>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose"> </el-button>
<el-button type="primary" @click="addFn">确定</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { componentTree } from '@/api/user-boot/user'
import { ref, reactive, onMounted, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { GridLayout, GridItem } from 'grid-layout-plus'
import { Tools, CloseBold } from '@element-plus/icons-vue'
import { addDashboard, updateDashboard } from '@/api/system-boot/csstatisticalset'
import html2canvas from 'html2canvas'
const title = ref('')
const formRef = ref()
const treeList: any = ref([])
const dialogVisible = ref(false)
let index = 9
const emit = defineEmits(['submit'])
const layout: any = ref([
{ x: 0, y: 0, w: 4, h: 2, i: '0', name: '', path: '' },
{ x: 4, y: 0, w: 4, h: 2, i: '1', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '2', name: '', path: '' },
{ x: 0, y: 0, w: 4, h: 2, i: '3', name: '', path: '' },
{ x: 4, y: 0, w: 4, h: 2, i: '4', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '5', name: '', path: '' },
{ x: 0, y: 0, w: 4, h: 2, i: '6', name: '', path: '' },
{ x: 4, y: 0, w: 4, h: 2, i: '7', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '8', name: '', path: '' }
])
const imgList = [
new URL(`@/assets/imgs/1x1.png`, import.meta.url),
new URL(`@/assets/imgs/2x2.png`, import.meta.url),
new URL(`@/assets/imgs/2x3.png`, import.meta.url),
new URL(`@/assets/imgs/3x3.png`, import.meta.url)
]
const form: any = reactive({
pageName: '',
thumbnail: '',
containerConfig: [],
sort: '100',
id: '',
remark: ''
})
const rules = {
pageName: [{ required: true, message: '请输入页面名称', trigger: 'blur' }],
projectIds: [{ required: true, message: '请选择工程页面', trigger: 'change' }],
sort: [{ required: true, message: '请输入排序', trigger: 'blur' }]
}
// 删除拖拽
const removeItem = (id: string) => {
const index = layout.value.findIndex(item => item.i === id)
if (index > -1) {
layout.value.splice(index, 1)
}
}
// 添加拖拽容器
function addItem() {
layout.value.push({
x: (layout.value.length * 2) % 6,
y: layout.value.length + 6, // puts it at the bottom
w: 4,
h: 2,
i: `${index++}`,
name: '',
path: ''
})
}
const addFn = () => {
if (layout.value.length == 0) {
return ElMessage.warning('页面设计不能为空!')
}
const maxValue = Math.max(...layout.value.map(item => item.y + item.h))
if (maxValue > 6) {
return ElMessage.warning('组件不能超出当前容器!')
}
formRef.value.validate(async (valid: boolean) => {
let url = ''
await html2canvas(document.querySelector('.GridLayout'), {
useCORS: true
}).then(canvas => {
url = canvas.toDataURL('image/png')
})
if (valid) {
if (title.value == '新增页面') {
addDashboard({ ...form, containerConfig: JSON.stringify(layout.value), thumbnail: url }).then(
(res: any) => {
ElMessage.success('新增页面成功!')
handleClose()
}
)
} else {
updateDashboard({ ...form, containerConfig: JSON.stringify(layout.value), thumbnail: url }).then(
(res: any) => {
ElMessage.success('修改页面成功!')
handleClose()
}
)
}
}
})
}
const change = (e: any, item: any) => {
item.name = treeList.value.filter((item: any) => item.path == e)[0].name
}
// 设置布局
const imgData = i => {
switch (i) {
case 0:
// 1x1
layout.value = [{ x: 0, y: 0, w: 12, h: 6, i: '0', name: '', path: '' }]
return
case 1:
// 2x2
layout.value = [
{ x: 0, y: 0, w: 6, h: 3, i: '0', name: '', path: '' },
{ x: 6, y: 0, w: 6, h: 3, i: '1', name: '', path: '' },
{ x: 0, y: 3, w: 6, h: 3, i: '3', name: '', path: '' },
{ x: 6, y: 3, w: 6, h: 3, i: '4', name: '', path: '' }
]
return
case 2:
// 2x3
layout.value = [
{ x: 0, y: 0, w: 8, h: 4, i: '0', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '2', name: '', path: '' },
{ x: 8, y: 2, w: 4, h: 2, i: '5', name: '', path: '' },
{ x: 0, y: 4, w: 4, h: 2, i: '6', name: '', path: '' },
{ x: 4, y: 4, w: 4, h: 2, i: '7', name: '', path: '' },
{ x: 8, y: 4, w: 4, h: 2, i: '8', name: '', path: '' }
]
return
case 3:
// 3x3
layout.value = [
{ x: 0, y: 0, w: 4, h: 2, i: '0', name: '', path: '' },
{ x: 4, y: 0, w: 4, h: 2, i: '1', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '2', name: '', path: '' },
{ x: 0, y: 0, w: 4, h: 2, i: '3', name: '', path: '' },
{ x: 4, y: 0, w: 4, h: 2, i: '4', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '5', name: '', path: '' },
{ x: 0, y: 0, w: 4, h: 2, i: '6', name: '', path: '' },
{ x: 4, y: 0, w: 4, h: 2, i: '7', name: '', path: '' },
{ x: 8, y: 0, w: 4, h: 2, i: '8', name: '', path: '' }
]
return
default:
}
}
const open = ref((row: any) => {
if (row.data) {
layout.value = JSON.parse(row.data.containerConfig)
form.pageName = row.data.pageName
form.sort = row.data.sort
form.remark = row.data.remark
form.id = row.data.id
}
title.value = row.title
dialogVisible.value = true
// if (row.title == '新增页面') {
// form.name = ''
// form.projectIds = []
// form.sort = '100'
// form.remark = ''
// } else {
// for (let key in form) {
// form[key] = row.row[key] || ''
// }
// form.id = row.row.id
// }
})
onMounted(() => {
componentTree().then((res: any) => {
const uniqueArray = tree2List(res.data, Math.random() * 1000).filter(
(item: any) => item.path != '' && item.path != null
)
treeList.value = Array.from(new Map(uniqueArray.map(item => [item.path, item])).values())
})
})
const tree2List = (list: any, id: any) => {
//存储结果的数组
let arr: any = []
// 遍历 tree 数组
list.forEach((item: any) => {
item.uPid = id
item.uId = Math.random() * 1000
// 判断item是否存在children
if (!item.children) return arr.push(item)
// 函数递归对children数组进行tree2List的转换
const children = tree2List(item.children, item.uId)
// 删除item的children属性
delete item.children
// 把item和children数组添加至结果数组
//..children: 意思是把children数组展开
arr.push(item, ...children)
})
// 返回结果数组
return arr
}
const handleClose = () => {
dialogVisible.value = false
emit('submit')
}
defineExpose({ open })
</script>
<style lang="scss" scoped>
.vgl-layout {
background-color: #eee;
}
:deep(.vgl-item:not(.vgl-item--placeholder)) {
background-color: #ccc;
border: 1px solid black;
}
:deep(.vgl-item--resizing) {
opacity: 90%;
}
:deep(.vgl-item--static) {
background-color: #cce;
}
.text {
position: absolute;
display: flex;
align-items: center;
inset: 0;
width: 80%;
height: 100%;
padding: 5px;
color: #000;
font-size: 14px;
}
.layout-json {
padding: 10px;
margin-top: 10px;
background-color: #ddd;
border: 1px solid black;
}
.columns {
columns: 120px;
}
.remove {
position: absolute;
top: 5px;
right: 2px;
width: 16px;
cursor: pointer;
}
.bind {
position: absolute;
top: 50%;
right: -5px;
transform: translate(-50%, -50%);
color: var(--el-color-primary);
cursor: pointer;
width: 16px;
}
.image {
display: flex;
align-items: center;
margin-bottom: 5px;
img {
height: 20px;
cursor: pointer;
}
.el-button {
margin-left: auto;
}
}
</style>

View File

@@ -0,0 +1,287 @@
<template>
<div class="default-main">
<TableHeader>
<template v-slot:select>
<el-form-item label="页面名称">
<el-input
maxlength="32"
show-word-limit
v-model.trim="tableStore.table.params.searchValue"
placeholder="请输入页面名称"
></el-input>
</el-form-item>
</template>
<template v-slot:operation>
<el-button type="primary" @click="onSubmitadd" icon="el-icon-Plus">新增</el-button>
</template>
</TableHeader>
<!-- <Table ref="tableRef" /> -->
<div
style="overflow-x: hidden; overflow-y: scroll; padding: 0 10px"
v-loading="tableStore.table.loading"
:style="{ height: tableStore.table.height }"
>
<el-row :gutter="12">
<el-col :span="6" v-for="item in tableStore.table.data" :key="item.id" class="mt10">
<el-card class="box-card" shadow="hover">
<div slot="header" class="clearfix">
<span
style="display: flex; align-items: center; font-weight: 550"
:style="{ color: item.state == 1 ? `var(--el-color-primary)` : '' }"
>
{{ item.pageName }}
</span>
<div style="display: flex; justify-content: end">
<el-button
class="color"
icon="el-icon-Position"
style="padding: 3px 0"
type="text"
v-if="item.state == 0"
@click="activation(item)"
>
激活
</el-button>
<el-button
class="color"
icon="el-icon-Edit"
style="padding: 3px 0"
type="text"
@click="editd(item)"
>
修改
</el-button>
<el-button
icon="el-icon-Delete"
style="padding: 3px 0; color: red"
type="text"
@click="deleted(item)"
>
删除
</el-button>
</div>
</div>
<img v-if="item.thumbnail" :src="item.thumbnail" class="image" />
<el-empty style="height: 220px" v-else description="暂无设计" />
</el-card>
</el-col>
</el-row>
</div>
<div class="table-pagination">
<el-pagination
:currentPage="tableStore.table.params!.pageNum"
:page-size="tableStore.table.params!.pageSize"
:page-sizes="[10, 20, 50, 100]"
background
:layout="'sizes,total, ->, prev, pager, next, jumper'"
:total="tableStore.table.total"
@size-change="onTableSizeChange"
@current-change="onTableCurrentChange"
></el-pagination>
</div>
<popup ref="popupRef" @submit="tableStore.index()" v-if="popupFlag" />
</div>
</template>
<script setup lang="ts">
import { Plus } from '@element-plus/icons-vue'
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import TableHeader from '@/components/table/header/index.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Edit } from '@element-plus/icons-vue'
import popup from './components/popup.vue'
import { deleteDashboard, activatePage } from '@/api/system-boot/csstatisticalset'
defineOptions({
name: 'cockpit/setUp'
})
const tableRef = ref()
const popupRef = ref()
const popupFlag = ref(false)
const tableStore = new TableStore({
showPage: false,
url: '/system-boot/dashboard/queryPage',
method: 'POST',
publicHeight: 60,
column: [],
loadCallback: () => {
popupFlag.value = false
}
})
provide('tableStore', tableStore)
tableStore.table.params.searchValue = ''
onMounted(() => {
tableStore.table.ref = tableRef.value
tableStore.index()
tableStore.table.loading = false
})
// 查询
const onSubmitadd = () => {
popupFlag.value = true
setTimeout(() => {
popupRef.value.open({
title: '新增页面'
})
}, 100)
}
// 修改
const editd = (e: any) => {
popupFlag.value = true
setTimeout(() => {
popupRef.value.open({
data: e,
title: '修改页面'
})
}, 100)
}
// 删除
const deleted = (e: any) => {
ElMessageBox.confirm('此操作将永久删除该页面, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
deleteDashboard({ id: e.id }).then((res: any) => {
if (res.code == 'A0000') {
ElMessage({
type: 'success',
message: '删除页面成功!'
})
}
tableStore.index()
})
})
.catch(() => {
ElMessage({
type: 'info',
message: '已取消删除'
})
})
}
// 激活
const activation = (e: any) => {
ElMessageBox.confirm('此操作将激活该页面, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
activatePage({ id: e.id }).then((res: any) => {
if (res.code == 'A0000') {
ElMessage({
type: 'success',
message: '激活成功!'
})
}
tableStore.index()
})
})
.catch(() => {
ElMessage({
type: 'info',
message: '已取消删除'
})
})
}
const onTableSizeChange = (val: number) => {
tableStore.onTableAction('page-size-change', { size: val })
}
const onTableCurrentChange = (val: number) => {
tableStore.onTableAction('current-page-change', { page: val })
}
</script>
<style lang="scss" scoped>
.text {
font-size: 14px;
}
span {
font-size: 16px;
}
.item {
margin-bottom: 18px;
}
.image {
display: block;
width: 100%;
height: 220px;
}
.clearfix::before,
.clearfix::after {
display: table;
content: '';
}
.clearfix::after {
clear: both;
}
.box-card {
width: 100%;
// border: 1px solid #000;
box-shadow: var(--el-box-shadow-light);
}
.setstyle {
min-height: 200px;
padding: 0 !important;
margin: 0;
overflow: auto;
cursor: default !important;
}
.color {
color: var(--el-color-primary);
}
:deep(.el-select-dropdown__wrap) {
max-height: 300px;
}
:deep(.el-tree) {
padding-top: 15px;
padding-left: 10px;
// 不可全选样式
.el-tree-node {
.is-leaf + .el-checkbox .el-checkbox__inner {
display: inline-block;
}
.el-checkbox .el-checkbox__inner {
display: none;
}
}
}
:deep(.el-card__header) {
padding: 13px 20px;
height: 44px;
}
.table-pagination {
height: 58px;
box-sizing: border-box;
width: 100%;
max-width: 100%;
background-color: var(--ba-bg-color-overlay);
padding: 13px 15px;
border-left: 1px solid #e4e7e9;
border-right: 1px solid #e4e7e9;
border-bottom: 1px solid #e4e7e9;
}
:deep(.el-pagination__sizes) {
.el-select {
min-width: 128px;
}
}
</style>