| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <template>
- <div>
- <div class="mb-2">
- <span>{{$t('k8s.text_28')}}</span>
- <cluster-select
- :value="cluster"
- @input="setCluster"
- style="width: 140px;" />
- </div>
- <page-card-list
- v-if="responseData.length"
- :list="list"
- :showPageer="false"
- :isRefreshed="false"
- :card-fields="cardFields"
- :group-actions="groupActions"
- :single-actions="singleActions" />
- <a-alert v-else :message="$t('k8s.text_265')" banner />
- </div>
- </template>
- <script>
- import ClusterSelect from '@K8S/sections/ClusterSelect'
- import k8sCreateMixin from '@K8S/mixins/create'
- import WindowsMixin from '@/mixins/windows'
- export default {
- name: 'KubeComponentList',
- components: {
- ClusterSelect,
- },
- mixins: [WindowsMixin, k8sCreateMixin],
- props: {
- id: {
- type: String,
- },
- },
- data () {
- return {
- list: this.$list.createList(this, {
- id: this.id,
- idKey: 'name',
- }),
- cardFields: {
- url: {
- formatter: (data) => {
- return require(`../assets/images/${data.name.toLowerCase()}${data.name.toLowerCase() === 'cephcsi' ? '.svg' : '.png'}`)
- },
- },
- title: 'name',
- content: [{
- title: this.$t('k8s.text_266'),
- field: 'enabled',
- slots: (data) => {
- return (<div class='status'>
- <status status={ data.enabled } statusModule='enabled' />
- </div>)
- },
- },
- {
- title: this.$t('k8s.text_35'),
- field: 'status',
- slots: (data) => {
- if (!data.status) {
- return (<span>-</span>)
- }
- return (<div class='status'>
- <status status={ data.status } statusModule='kubecomponent' />
- </div>)
- },
- }],
- },
- groupActions: [],
- singleActions: [
- {
- label: this.$t('k8s.create'),
- action: obj => {
- this.$router.push({
- path: '/k8s-kubecomponent/create',
- query: {
- kubeComponent: obj.name,
- cluster: this.cluster,
- },
- })
- },
- meta: (obj) => ({
- buttonType: 'primary',
- validate: !obj.created,
- }),
- },
- {
- label: this.$t('k8s.text_95'),
- action: obj => {
- this.$router.push({
- path: '/k8s-kubecomponent/update',
- query: {
- kubeComponent: obj.name,
- cluster: this.cluster,
- },
- })
- },
- meta: (obj) => ({
- validate: obj.created,
- }),
- },
- {
- label: this.$t('k8s.text_267'),
- action: obj => {
- return new this.$Manager('kubeclusters', 'v1').performAction({
- id: this.cluster,
- action: 'disable-component',
- data: {
- type: obj.name,
- },
- }).then(() => {
- this.fetchData()
- }).catch(error => {
- throw error
- })
- },
- meta: (obj) => ({
- validate: obj.enabled && obj.created,
- }),
- },
- {
- label: this.$t('k8s.text_268'),
- action: obj => {
- return new this.$Manager('kubeclusters', 'v1').performAction({
- id: this.cluster,
- action: 'enable-component',
- data: {
- type: obj.name,
- },
- }).then(() => {
- this.fetchData()
- }).catch(error => {
- throw error
- })
- },
- meta: (obj) => ({
- validate: !obj.enabled && obj.created,
- }),
- },
- {
- label: this.$t('k8s.text_201'),
- action: obj => {
- this.createDialog('DeleteResDialog', {
- vm: this,
- data: [obj],
- title: this.$t('k8s.text_201'),
- name: obj.name,
- ok: (ids, data) => {
- return new this.$Manager('kubeclusters', 'v1').performAction({
- id: this.cluster,
- action: 'delete-component',
- data: {
- type: obj.name,
- },
- }).then(() => {
- this.fetchData()
- return true
- }).catch(error => {
- throw error
- })
- },
- })
- },
- meta: obj => ({
- validate: obj.created,
- }),
- },
- ],
- responseData: [],
- timer: null,
- }
- },
- watch: {
- cluster () {
- this.fetchData()
- },
- },
- created () {
- this.manager = new this.$Manager('kubeclusters', 'v1')
- this.fetchData()
- },
- methods: {
- async fetchData () {
- if (this.cluster) {
- const { data } = await this.manager.getSpecific({
- id: this.cluster,
- spec: 'components-status',
- })
- this.list.responseData = {
- data: [],
- }
- for (const key in data) {
- data[key].name = key
- // if (key === 'cephCSI') this.list.responseData.data.push(data[key])
- this.list.responseData.data.push(data[key])
- this.responseData = this.list.responseData.data
- }
- this.list.fetchData()
- this.getStableStatus(data)
- }
- },
- getStableStatus (data) {
- const kubeComponentStatus = ['deployed', 'deploy_fail', 'update_fail', 'delete_fail', 'init']
- const statusArr = Object.values(data).map(val => val.status).filter(v => v)
- const flatStableStatus = Object.values(kubeComponentStatus)
- const notStable = statusArr.some(val => !flatStableStatus.includes(val))
- if (notStable) {
- this.timer = setTimeout(() => {
- this.fetchData()
- }, 5000)
- } else {
- this.timer = null
- }
- },
- },
- }
- </script>
- <style lang="less" scoped>
- .status {
- display: inline-block;
- vertical-align: bottom;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- </style>
|