1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 12:01:57 +08:00

fixing dashboard errors (#985)

Co-authored-by: elsiosanchez <elsiossanches@gmail.com>
This commit is contained in:
Elsio Sanchez 2021-07-13 16:23:34 -04:00 committed by GitHub
parent f6a874784d
commit cba978916b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 27 deletions

View File

@ -22,12 +22,12 @@
> >
<div class="clearfix"> <div class="clearfix">
<el-row :gutter="2"> <el-row :gutter="2">
<el-col :span="isEmptyValue(title) ? 22 : 23"> <el-col :span="main ? 22 : 23">
<el-button type="text" class="label-dashboard" @click="metadata.isCollapsible = !metadata.isCollapsible"> <el-button type="text" class="label-dashboard" @click="metadata.isCollapsible = !metadata.isCollapsible">
{{ labelDashboard }} {{ labelDashboard }}
</el-button> </el-button>
</el-col> </el-col>
<el-col v-if="isEmptyValue(title)" :span="1"> <el-col v-if="main" :span="1">
<el-button type="text" icon="el-icon-files" @click="sendMain(metadata)" /> <el-button type="text" icon="el-icon-files" @click="sendMain(metadata)" />
</el-col> </el-col>
<el-col :span="1"> <el-col :span="1">
@ -59,6 +59,10 @@ export default {
title: { title: {
type: String, type: String,
default: '' default: ''
},
main: {
type: Boolean,
default: false
} }
}, },
data() { data() {

View File

@ -28,7 +28,7 @@ const dashboard = {
}, },
mutations: { mutations: {
addDashboard(state, payload) { addDashboard(state, payload) {
state.dashboard.push(payload) state.dashboard = payload
}, },
notifyDashboardRefresh: (state, payload) => { notifyDashboardRefresh: (state, payload) => {
@ -44,7 +44,7 @@ const dashboard = {
refreshDashboard({ commit }, parameters) { refreshDashboard({ commit }, parameters) {
commit('notifyDashboardRefresh', parameters) commit('notifyDashboardRefresh', parameters)
}, },
listDashboard({ commit, rootGetters }, { listDashboard({ commit, state, rootGetters }, {
roleId, roleId,
roleUuid roleUuid
}) { }) {
@ -66,7 +66,7 @@ const dashboard = {
roleUuid: roleUuid, roleUuid: roleUuid,
...dashboardResponse ...dashboardResponse
} }
commit('addDashboard', roleDashboards) commit('addDashboard', dashboardResponse.dashboardsList)
resolve(roleDashboards) resolve(roleDashboards)
}) })
.catch(error => { .catch(error => {
@ -79,15 +79,8 @@ const dashboard = {
} }
}, },
getters: { getters: {
getDashboard: (state) => (dashboardUuid) => { getDashboard: (state) => {
return state.dashboard.find( return state.dashboard
item => item.uuid === dashboardUuid
)
},
getDashboardByRole: (state) => (roleUuid) => {
return state.dashboard.find(
item => item.roleUuid === roleUuid
)
}, },
getMainDashboard: (state) => { getMainDashboard: (state) => {
return state.mainashboard return state.mainashboard

View File

@ -1,15 +1,19 @@
<template> <template>
<div class="dashboard-editor-container"> <div class="dashboard-editor-container">
<el-row :gutter="8"> <el-row v-if="!isEmptyValue(listDashboard)" :gutter="8">
<el-col v-if="!isEmptyValue(mainashboard)" :span="24" style="padding-right:8px;margin-bottom:2px;"> <el-col v-if="!isEmptyValue(maindashboard)" :span="24" style="padding-right:8px;margin-bottom:2px;">
<dashboard <dashboard
:metadata="mainashboard" :metadata="maindashboard"
:title="mainashboard.name" :title="maindashboard.name"
/> />
</el-col> </el-col>
<template v-for="(dashboardAttributes, index) in dashboardList"> <template v-for="(dashboardAttributes, index) in listDashboard">
<el-col v-if="index > 0" :key="index" :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 12 }" style="padding-right:8px;margin-bottom:2px;"> <el-col :key="index" :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 12 }" style="padding-right:8px;margin-bottom:2px;">
<dashboard :metadata="dashboardAttributes" /> <dashboard
:metadata="dashboardAttributes"
:title="dashboardAttributes.name"
:main="true"
/>
</el-col> </el-col>
</template> </template>
</el-row> </el-row>
@ -31,8 +35,9 @@ export default {
} }
}, },
computed: { computed: {
getterDashboard() { listDashboard() {
return this.$store.getters.getDashboardByRole(this.roleUuid) const list = this.$store.getters.getDashboard
return list.filter(dashboard => this.maindashboard.id !== dashboard.id)
}, },
currentRole() { currentRole() {
return this.$store.getters['user/getRole'] return this.$store.getters['user/getRole']
@ -40,7 +45,7 @@ export default {
getterRol() { getterRol() {
return this.$store.getters.getRoleUuid return this.$store.getters.getRoleUuid
}, },
mainashboard() { maindashboard() {
return this.$store.getters.getMainDashboard return this.$store.getters.getMainDashboard
} }
}, },
@ -48,7 +53,7 @@ export default {
getterRol(value) { getterRol(value) {
this.getDashboardListFromServer() this.getDashboardListFromServer()
}, },
mainashboard(value) { maindashboard(value) {
this.getDashboardListFromServer() this.getDashboardListFromServer()
} }
}, },
@ -62,8 +67,8 @@ export default {
roleUuid: this.currentRole.uuid roleUuid: this.currentRole.uuid
}) })
.then(response => { .then(response => {
if (this.isEmptyValue(this.mainashboard)) { if (this.isEmptyValue(this.maindashboard)) {
this.$store.dispatch('mainDashboard', response.dashboardsList[1]) this.$store.dispatch('mainDashboard', response.dashboardsList[0])
} }
this.dashboardList = response.dashboardsList this.dashboardList = response.dashboardsList
this.$forceUpdate() this.$forceUpdate()