ServiceDetail.vue 7.4 KB
Newer Older
M
min 已提交
1 2 3 4 5 6
<!--
  - Licensed to the Apache Software Foundation (ASF) under one or more
  - contributor license agreements.  See the NOTICE file distributed with
  - this work for additional information regarding copyright ownership.
  - The ASF licenses this file to You under the Apache License, Version 2.0
  - (the "License"); you may not use this file except in compliance with
N
nzomkxia 已提交
7
  - the License.  You may obtain a copy of the License at
M
min 已提交
8
  -
N
nzomkxia 已提交
9
  -     http://www.apache.org/licenses/LICENSE-2.0
M
min 已提交
10
  -
N
nzomkxia 已提交
11 12 13 14 15
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
M
min 已提交
16 17 18 19 20 21
  -->

<template>
  <v-container grid-list-xl fluid >
    <v-layout row wrap >
      <v-flex sm12>
X
Xin Wang 已提交
22
        <h3>{{$t('basicInfo')}}</h3>
M
min 已提交
23 24 25 26 27 28 29 30
      </v-flex>
      <v-flex lg12>
        <v-data-table
          :items="basic"
          class="elevation-1"
          hide-actions
          hide-headers >
          <template slot="items" slot-scope="props">
N
nzomkxia 已提交
31
            <td>{{props.item.name}} </td>
M
min 已提交
32 33 34 35 36
            <td>{{props.item.value}}</td>
          </template>
        </v-data-table>
      </v-flex>
      <v-flex sm12>
N
nzomkxia 已提交
37
        <h3>{{$t('serviceInfo')}}</h3>
M
min 已提交
38 39 40 41 42
      </v-flex>
      <v-flex lg12 >
        <v-tabs
          class="elevation-1">
          <v-tab>
N
nzomkxia 已提交
43
            {{$t('providers')}}
M
min 已提交
44 45
          </v-tab>
          <v-tab>
N
nzomkxia 已提交
46
            {{$t('consumers')}}
M
min 已提交
47 48 49 50 51 52 53 54
          </v-tab>
          <v-tab-item>
            <v-data-table
              class="elevation-1"
              :headers="detailHeaders.providers"
              :items="providerDetails"
            >
              <template slot="items" slot-scope="props">
55 56 57 58 59 60 61 62 63
                <td>{{getIp(props.item.address)}}</td>
                <td>{{getPort(props.item.address)}}</td>
                <td></td>
                <td></td>
                <td><v-tooltip top>
                  <v-btn
                          small
                          slot="activator"
                          color="primary"
64
                          @click="toCopyText(props.item.url)"
65
                  >
66
                    {{$t('copyUrl')}}
67 68 69
                  </v-btn>
                  <span>{{props.item.url}}</span>
                </v-tooltip></td>
M
min 已提交
70 71 72 73 74 75 76 77 78 79
              </template>
            </v-data-table>
          </v-tab-item>
          <v-tab-item >
            <v-data-table
              class="elevation-1"
              :headers="detailHeaders.consumers"
              :items="consumerDetails"
            >
              <template slot="items" slot-scope="props">
80 81 82
                <td>{{getIp(props.item.address)}}</td>
                <td>{{getPort(props.item.address)}}</td>
                <td>{{props.item.application}}</td>
M
min 已提交
83 84 85 86 87 88
              </template>
            </v-data-table>
          </v-tab-item>
        </v-tabs>
      </v-flex>
      <v-flex sm12>
X
Xin Wang 已提交
89
        <h3>{{$t('metaData')}}</h3>
M
min 已提交
90 91 92 93 94
      </v-flex>
      <v-flex lg12>
        <v-data-table
          class="elevation-1"
          :headers="metaHeaders"
N
nzomkxia 已提交
95
          :items="methodMetaData">
M
min 已提交
96
          <template slot="items" slot-scope="props">
N
nzomkxia 已提交
97
            <td>{{props.item.name}}</td>
N
nzomkxia 已提交
98 99 100
            <td>
              <v-chip v-for="(type, index) in props.item.parameterTypes" :key="type.id" label>{{type}}</v-chip>
            </td>
N
nzomkxia 已提交
101 102 103
            <td>
              <v-chip label>{{props.item.returnType}}</v-chip>
            </td>
M
min 已提交
104
          </template>
N
nzomkxia 已提交
105 106 107 108 109 110
          <template slot="no-data">
            <v-alert :value="true" color="warning" icon="warning">
              {{$t('noMetadataHint')}}
              <a :href="$t('configAddress')" target="_blank">{{$t('here')}}</a>
            </v-alert>
          </template>
M
min 已提交
111 112 113 114 115 116 117 118
        </v-data-table>
      </v-flex>
    </v-layout>
  </v-container>
</template>
<script>
  export default {
    data: () => ({
X
Xin Wang 已提交
119 120 121 122 123 124 125 126 127 128
      metaHeaders: [],
      detailHeaders: {},
      providerDetails: [],
      consumerDetails: [],
      methodMetaData: [],
      basic: []
    }),
    methods: {
      setmetaHeaders: function () {
        this.metaHeaders = [
M
min 已提交
129
          {
X
Xin Wang 已提交
130 131 132
            text: this.$t('methodName'),
            value: 'method',
            sortable: false
M
min 已提交
133 134
          },
          {
X
Xin Wang 已提交
135 136 137
            text: this.$t('parameterList'),
            value: 'parameter',
            sortable: false
M
min 已提交
138 139
          },
          {
X
Xin Wang 已提交
140 141 142
            text: this.$t('returnType'),
            value: 'returnType',
            sortable: false
M
min 已提交
143 144
          }
        ]
145
      },
X
Xin Wang 已提交
146 147 148 149 150 151 152 153 154 155 156 157
      setdetailHeaders: function () {
        this.detailHeaders = {
          providers: [
            {
              text: this.$t('ip'),
              value: 'ip'
            },
            {
              text: this.$t('port'),
              value: 'port'
            },
            {
N
nzomkxia 已提交
158
              text: this.$t('timeout'),
X
Xin Wang 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
              value: 'timeout'
            },
            {
              text: this.$t('serialization'),
              value: 'serial'
            },
            {
              text: this.$t('operation'),
              value: 'operate'
            }

          ],
          consumers: [
            {
              text: this.$t('ip'),
              value: 'ip'
            },
            {
              text: this.$t('port'),
              value: 'port'
            },
            {
              text: this.$t('appName'),
              value: 'appName'
            }
          ]
        }
      },
187
      detail: function (service) {
马金凯 已提交
188
        this.$axios.get('/service/' + service)
189 190 191
            .then(response => {
              this.providerDetails = response.data.providers
              this.consumerDetails = response.data.consumers
N
nzomkxia 已提交
192 193 194
              if (response.data.metadata !== null) {
                this.methodMetaData = response.data.metadata.methods
              }
195 196 197 198 199 200 201
            })
      },
      getIp: function (address) {
        return address.split(':')[0]
      },
      getPort: function (address) {
        return address.split(':')[1]
N
nzomkxia 已提交
202 203 204 205 206 207 208
      },
      getParameters: function (parameterTypes) {
        let result = ''
        for (let i = 0; i < parameterTypes.length; i++) {
          result = result + parameterTypes[i] + ' '
        }
        return result.trim()
209 210 211 212 213
      },
      toCopyText (text) {
        this.$copyText(text).then(() => {
          this.$notify.success(this.$t('copySuccessfully'))
        }, () => {})
214 215
      }
    },
I
IORI 已提交
216 217 218 219 220 221 222 223 224 225 226
    computed: {
      area () {
        return this.$i18n.locale
      }
    },
    watch: {
      area () {
        this.setdetailHeaders()
        this.setmetaHeaders()
      }
    },
227
    mounted: function () {
X
Xin Wang 已提交
228 229
      this.setmetaHeaders()
      this.setdetailHeaders()
230
      let query = this.$route.query
N
nzomkxia 已提交
231 232 233 234 235 236 237
      let meta = {
        'service': '',
        'app': '',
        'group': '',
        'version': ''
      }
      var vm = this
238
      Object.keys(query).forEach(function (key) {
N
nzomkxia 已提交
239 240
        if (key in meta) {
          meta[key] = query[key]
241 242
        }
      })
N
nzomkxia 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255
      let dataId = meta['service']
      if (meta['group'] !== '') {
        dataId = meta['group'] + '*' + dataId
      }
      if (meta['version'] !== '') {
        dataId = dataId + ':' + meta['version']
      }

      if (dataId !== '') {
        this.detail(dataId)
        Object.keys(meta).forEach(function (key) {
          let item = {}
          item.value = meta[key]
J
Jinkai Ma 已提交
256
          item.name = vm.$t(key)
N
nzomkxia 已提交
257 258
          vm.basic.push(item)
        })
M
min 已提交
259
      }
260
    }
M
min 已提交
261 262 263
  }
</script>