component refactoring

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2019-09-20 12:57:22 +05:30
parent 2ed0b2dcae
commit 12c82f5be5
11 changed files with 201 additions and 186 deletions

View File

@ -1,26 +1,6 @@
<template> <template>
<div> <div>
<a-breadcrumb class="breadcrumb" v-if="device !== 'desktop'" style="margin-left: -16px; margin-right: -16px; margin-top: -16px"> <breadcrumb v-if="device !== 'desktop'" style="margin-left: -16px; margin-right: -16px; margin-top: -16px" />
<a-card :bordered="true">
<a-breadcrumb-item v-for="(item, index) in breadList" :key="index">
<router-link
v-if="item.name"
:to="{ path: item.path === '' ? '/' : item.path }"
>
<a-icon v-if="index == 0" :type="item.meta.icon" />
{{ $t(item.meta.title) }}
</router-link>
<span v-else-if="$route.params.id">
{{ $route.params.id }}
<a-button shape="circle" type="dashed" size="small" v-clipboard:copy="$route.params.id">
<a-icon type="copy" style="margin-left: 0px"/>
</a-button>
</span>
<span v-else>{{ $t(tem.meta.title) }}</span>
</a-breadcrumb-item>
</a-card>
</a-breadcrumb>
<a-row> <a-row>
<a-col :span="17"> <a-col :span="17">
<a-tooltip placement="bottom" v-for="(action, actionIndex) in actions" :key="actionIndex" v-if="(!dataView && (action.listView || action.groupAction && selectedRowKeys.length > 0)) || (dataView && action.dataView)"> <a-tooltip placement="bottom" v-for="(action, actionIndex) in actions" :key="actionIndex" v-if="(!dataView && (action.listView || action.groupAction && selectedRowKeys.length > 0)) || (dataView && action.dataView)">
@ -103,72 +83,88 @@
</a-col> </a-col>
</a-row> </a-row>
<a-modal <div v-show="showAction">
:title="currentAction.label" <keep-alive v-if="currentAction.component">
:visible="showAction" <a-modal
:closable="true" :title="currentAction.label"
style="top: 20px;" :visible="showAction"
@ok="handleSubmit" :closable="true"
@cancel="closeAction" style="top: 20px;"
:confirmLoading="currentAction.loading" @ok="handleSubmit"
centered @cancel="closeAction"
> :confirmLoading="currentAction.loading"
<a-spin :spinning="currentAction.loading"> centered
<a-form >
:form="form" <component :is="currentAction.component"/></component>
@submit="handleSubmit" </a-modal>
layout="vertical" > </keep-alive>
<a-form-item
v-for="(field, fieldIndex) in currentAction.params"
:key="fieldIndex"
:label="field.name"
:v-bind="field.name"
v-if="field.name !== 'id'"
>
<span v-if="field.type==='boolean'"> <a-modal
<a-switch :title="currentAction.label"
v-decorator="[field.name, { :visible="showAction"
rules: [{ required: field.required, message: 'Please provide input' }] :closable="true"
}]" style="top: 20px;"
:placeholder="field.description" @ok="handleSubmit"
/> @cancel="closeAction"
</span> :confirmLoading="currentAction.loading"
<span v-else-if="field.type==='uuid' || field.name==='account'"> centered
<a-select >
:loading="field.loading" <a-spin :spinning="currentAction.loading">
v-decorator="[field.name, { <a-form
rules: [{ required: field.required, message: 'Please select option' }] :form="form"
}]" @submit="handleSubmit"
:placeholder="field.description" layout="vertical" >
<a-form-item
v-for="(field, fieldIndex) in currentAction.params"
:key="fieldIndex"
:label="$t(field.name)"
:v-bind="field.name"
v-if="field.name !== 'id'"
>
> <span v-if="field.type==='boolean'">
<a-select-option v-for="(opt, optIndex) in field.opts" :key="optIndex"> <a-switch
{{ opt.name }} v-decorator="[field.name, {
</a-select-option> rules: [{ required: field.required, message: 'Please provide input' }]
</a-select> }]"
</span> :placeholder="field.description"
<span v-else-if="field.type==='long'"> />
<a-input-number </span>
v-decorator="[field.name, { <span v-else-if="field.type==='uuid' || field.name==='account'">
rules: [{ required: field.required, message: 'Please enter a number' }] <a-select
}]" :loading="field.loading"
:placeholder="field.description" v-decorator="[field.name, {
/> rules: [{ required: field.required, message: 'Please select option' }]
</span> }]"
<span v-else> :placeholder="field.description"
<a-input
v-decorator="[field.name, {
rules: [{ required: field.required, message: 'Please enter input' }]
}]"
:placeholder="field.description"
/>
</span>
</a-form-item>
</a-form> >
</a-spin> <a-select-option v-for="(opt, optIndex) in field.opts" :key="optIndex">
</a-modal> {{ opt.name }}
</a-select-option>
</a-select>
</span>
<span v-else-if="field.type==='long'">
<a-input-number
v-decorator="[field.name, {
rules: [{ required: field.required, message: 'Please enter a number' }]
}]"
:placeholder="field.description"
/>
</span>
<span v-else>
<a-input
v-decorator="[field.name, {
rules: [{ required: field.required, message: 'Please enter input' }]
}]"
:placeholder="field.description"
/>
</span>
</a-form-item>
</a-form>
</a-spin>
</a-modal>
</div>
<div v-if="dataView"> <div v-if="dataView">
<instance-view :vm="resource" v-if="routeName == 'vm'" /> <instance-view :vm="resource" v-if="routeName == 'vm'" />
@ -185,6 +181,7 @@
:loading="loading" :loading="loading"
v-show="!tableView" /> v-show="!tableView" />
</div> </div>
</div> </div>
</template> </template>
@ -192,10 +189,10 @@
import { api } from '@/api' import { api } from '@/api'
import { mixinDevice } from '@/utils/mixin.js' import { mixinDevice } from '@/utils/mixin.js'
import store from '@/store' import store from '@/store'
import Breadcrumb from '@/components/widgets/Breadcrumb'
import CardView from '@/components/widgets/CardView' import CardView from '@/components/widgets/CardView'
import ChartCard from '@/components/chart/ChartCard' import ChartCard from '@/components/chart/ChartCard'
import DataView from '@/components/widgets/DataView' import DataView from '@/components/widgets/DataView'
import FormView from '@/components/widgets/FormView'
import InstanceView from '@/components/widgets/InstanceView' import InstanceView from '@/components/widgets/InstanceView'
import ListView from '@/components/widgets/ListView' import ListView from '@/components/widgets/ListView'
import Status from '@/components/widgets/Status' import Status from '@/components/widgets/Status'
@ -203,10 +200,10 @@ import Status from '@/components/widgets/Status'
export default { export default {
name: 'Resource', name: 'Resource',
components: { components: {
Breadcrumb,
CardView, CardView,
ChartCard, ChartCard,
DataView, DataView,
FormView,
InstanceView, InstanceView,
ListView, ListView,
Status Status
@ -225,7 +222,6 @@ export default {
showAction: false, showAction: false,
dataView: false, dataView: false,
actions: [], actions: [],
breadList: [],
tableView: true tableView: true
} }
}, },
@ -253,15 +249,7 @@ export default {
this.form = this.$form.createForm(this) this.form = this.$form.createForm(this)
}, },
methods: { methods: {
getBreadcrumb () {
this.breadList = []
this.name = this.$route.name
this.$route.matched.forEach((item) => {
this.breadList.push(item)
})
},
fetchData (search = '') { fetchData (search = '') {
this.getBreadcrumb()
this.routeName = this.$route.name this.routeName = this.$route.name
if (!this.routeName) { if (!this.routeName) {
this.routeName = this.$route.matched[this.$route.matched.length - 1].parent.name this.routeName = this.$route.matched[this.$route.matched.length - 1].parent.name

View File

@ -73,7 +73,6 @@
import UserMenu from '../tools/UserMenu' import UserMenu from '../tools/UserMenu'
import SMenu from '../menu/' import SMenu from '../menu/'
import Logo from '../tools/Logo' import Logo from '../tools/Logo'
import Breadcrumb from '@/components/tools/Breadcrumb'
import { mixin } from '@/utils/mixin.js' import { mixin } from '@/utils/mixin.js'
@ -82,8 +81,7 @@ export default {
components: { components: {
SMenu, SMenu,
Logo, Logo,
UserMenu, UserMenu
Breadcrumb
}, },
mixins: [mixin], mixins: [mixin],
props: { props: {

View File

@ -34,7 +34,7 @@
</template> </template>
<script> <script>
import Breadcrumb from '@/components/tools/Breadcrumb' import Breadcrumb from '@/components/widgets/Breadcrumb'
export default { export default {
name: 'PageHeader', name: 'PageHeader',

View File

@ -1,51 +0,0 @@
<template>
<a-breadcrumb class="breadcrumb">
<a-breadcrumb-item v-for="(item, index) in breadList" :key="index">
<router-link v-if="item.name != name" :to="{ path: item.path }">
{{ this.$t(item.meta.title) }}
</router-link>
<span v-else>{{ this.$t(item.meta.title) }}</span>
</a-breadcrumb-item>
</a-breadcrumb>
</template>
<script>
export default {
data () {
return {
name: '',
breadList: []
}
},
created () {
this.getBreadcrumb()
},
methods: {
getBreadcrumb () {
console.log('this.$route.matched', this.$route.matched)
this.breadList = []
this.breadList.push({ name: 'index', path: '/dashboard/', meta: { title: '首页' } })
this.name = this.$route.name
this.$route.matched.forEach((item) => {
// item.meta.name === 'dashboard' ? item.path = '/dashboard' : this.$route.path === item.path
this.breadList.push(item)
})
}
},
watch: {
$route () {
this.getBreadcrumb()
}
}
}
</script>
<style lang="less" scoped>
.breadcrumb {
.mobile & {
display: none;
}
}
</style>

View File

@ -0,0 +1,65 @@
<template>
<a-breadcrumb class="breadcrumb">
<a-card :bordered="true">
<a-breadcrumb-item v-for="(item, index) in breadList" :key="index">
<router-link
v-if="item.name"
:to="{ path: item.path === '' ? '/' : item.path }"
>
<a-icon v-if="index == 0" :type="item.meta.icon" />
{{ $t(item.meta.title) }}
</router-link>
<span v-else-if="$route.params.id">
{{ $route.params.id }}
<a-button shape="circle" type="dashed" size="small" v-clipboard:copy="$route.params.id">
<a-icon type="copy" style="margin-left: 0px"/>
</a-button>
</span>
<span v-else>{{ $t(item.meta.title) }}</span>
</a-breadcrumb-item>
</a-card>
</a-breadcrumb>
</template>
<script>
export default {
name: 'Breadcrumb',
components: {
},
data () {
return {
name: '',
breadList: []
}
},
created () {
this.getBreadcrumb()
},
watch: {
$route () {
this.getBreadcrumb()
}
},
methods: {
getBreadcrumb () {
this.breadList = []
this.name = this.$route.name
this.$route.matched.forEach((item) => {
this.breadList.push(item)
})
}
}
}
</script>
<style>
.ant-breadcrumb {
vertical-align: text-bottom;
margin-bottom: 8px;
}
.ant-breadcrumb .anticon {
margin-left: 8px;
}
</style>

View File

@ -1,12 +1,12 @@
<template> <template>
<a-modal <a-modal
:title="currentAction.label" :title="currentAction.label"
:visible="showForm"
:closable="true" :closable="true"
:visible="showAction" :confirmLoading="currentAction.loading"
style="top: 20px;" style="top: 20px;"
@ok="handleSubmit" @ok="handleSubmit"
@cancel="close" @cancel="close"
:confirmLoading="currentAction.loading"
centered centered
> >
<a-spin :spinning="currentAction.loading"> <a-spin :spinning="currentAction.loading">
@ -17,11 +17,10 @@
<a-form-item <a-form-item
v-for="(field, fieldIndex) in currentAction.params" v-for="(field, fieldIndex) in currentAction.params"
:key="fieldIndex" :key="fieldIndex"
:label="field.name" :label="$t(field.name)"
:v-bind="field.name" :v-bind="field.name"
v-if="field.name !== 'id'" v-if="field.name !== 'id'"
> >
<span v-if="field.type==='boolean'"> <span v-if="field.type==='boolean'">
<a-switch <a-switch
v-decorator="[field.name, { v-decorator="[field.name, {
@ -80,21 +79,23 @@ export default {
type: Object, type: Object,
required: true required: true
}, },
showAction: { showForm: {
type: Boolean, type: Boolean,
default: false default: false
}, },
handleSubmit: { handleSubmit: {
type: Function, type: Function,
default: () => {} default: () => {}
},
close: {
type: Function,
default: () => {}
} }
}, },
beforeCreate () { beforeCreate () {
this.form = this.$form.createForm(this) this.form = this.$form.createForm(this)
},
methods: {
close () {
this.currentAction.loading = false
this.showForm = false
}
} }
} }
</script> </script>

View File

@ -1,6 +1,6 @@
<template> <template>
<a-table <a-table
:size="columns.length > 12 ? 'small' : 'medium'" size="small"
:loading="loading" :loading="loading"
:columns="columns" :columns="columns"
:dataSource="items" :dataSource="items"

View File

@ -26,7 +26,7 @@ export function generateRouterMap (section) {
map.meta.permission = section.children[0].permission map.meta.permission = section.children[0].permission
map.children = [] map.children = []
for (const child of section.children) { for (const child of section.children) {
map.children.push({ var route = {
name: child.name, name: child.name,
path: '/' + child.name, path: '/' + child.name,
meta: { meta: {
@ -54,7 +54,8 @@ export function generateRouterMap (section) {
component: child.viewComponent ? child.viewComponent : child.component component: child.viewComponent ? child.viewComponent : child.component
} }
] ]
}) }
map.children.push(route)
} }
} else { } else {
map.hideChildrenInMenu = true map.hideChildrenInMenu = true

View File

@ -10,7 +10,16 @@ export default {
icon: 'global', icon: 'global',
permission: [ 'listZones', 'listZonesMetrics' ], permission: [ 'listZones', 'listZonesMetrics' ],
component: () => import('@/components/CloudMonkey/Resource.vue'), component: () => import('@/components/CloudMonkey/Resource.vue'),
columns: [ 'name', 'allocationstate', 'networktype', 'guestcidraddress' ] columns: [ 'name', 'allocationstate', 'networktype', 'guestcidraddress' ],
actions: [
{
api: 'createZone',
icon: 'plus',
label: 'Add Zone',
listView: true,
component: () => import('@/views/infra/ZoneWizard.vue')
}
]
}, },
{ {
name: 'pod', name: 'pod',

View File

@ -1,23 +0,0 @@
<template>
<div>
</div>
</template>
<script>
export default {
name: '',
components: {
},
data () {
return {
}
},
methods: {
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,27 @@
<template>
<div>
<a-steps direction="vertical" :current="1">
<a-step title="Finished" description="This is a description." />
<a-step title="In Progress" description="This is a description." />
<a-step title="Waiting" description="This is a description." />
</a-steps>
</div>
</template>
<script>
export default {
name: 'ZoneWizard',
components: {
},
data () {
return {
}
},
methods: {
}
}
</script>
<style scoped>
</style>