ServiceDetail.vue 7.7 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">
31
            <td>{{$t(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
                <td>{{getIp(props.item.address)}}</td>
                <td>{{getPort(props.item.address)}}</td>
                <td></td>
                <td></td>
N
nzomkxia 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
                <td>
                  <v-tooltip top>
                    <v-btn
                      class="tiny"
                      slot="activator"
                      color="primary"
                      @mouseover="setHoverHint"
                      @mouseout="setoutHint"
                      @click="toCopyText(props.item.url)"
                    >
                        {{$t(hint)}}
                    </v-btn>
                    <span>{{props.item.url}}</span>
                  </v-tooltip>
                </td>
M
min 已提交
74 75 76 77 78 79 80 81 82 83
              </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">
84 85 86
                <td>{{getIp(props.item.address)}}</td>
                <td>{{getPort(props.item.address)}}</td>
                <td>{{props.item.application}}</td>
M
min 已提交
87 88 89 90 91 92
              </template>
            </v-data-table>
          </v-tab-item>
        </v-tabs>
      </v-flex>
      <v-flex sm12>
X
Xin Wang 已提交
93
        <h3>{{$t('metaData')}}</h3>
M
min 已提交
94 95 96 97 98
      </v-flex>
      <v-flex lg12>
        <v-data-table
          class="elevation-1"
          :headers="metaHeaders"
N
nzomkxia 已提交
99
          :items="methodMetaData">
M
min 已提交
100
          <template slot="items" slot-scope="props">
N
nzomkxia 已提交
101
            <td>{{props.item.name}}</td>
N
nzomkxia 已提交
102 103 104
            <td>
              <v-chip v-for="(type, index) in props.item.parameterTypes" :key="type.id" label>{{type}}</v-chip>
            </td>
N
nzomkxia 已提交
105 106 107
            <td>
              <v-chip label>{{props.item.returnType}}</v-chip>
            </td>
M
min 已提交
108
          </template>
N
nzomkxia 已提交
109 110 111 112 113 114
          <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 已提交
115 116 117 118 119 120 121 122
        </v-data-table>
      </v-flex>
    </v-layout>
  </v-container>
</template>
<script>
  export default {
    data: () => ({
X
Xin Wang 已提交
123 124 125 126 127
      metaHeaders: [],
      detailHeaders: {},
      providerDetails: [],
      consumerDetails: [],
      methodMetaData: [],
N
nzomkxia 已提交
128 129
      basic: [],
      hint: 'url'
X
Xin Wang 已提交
130 131 132 133
    }),
    methods: {
      setmetaHeaders: function () {
        this.metaHeaders = [
M
min 已提交
134
          {
X
Xin Wang 已提交
135 136 137
            text: this.$t('methodName'),
            value: 'method',
            sortable: false
M
min 已提交
138 139
          },
          {
X
Xin Wang 已提交
140 141 142
            text: this.$t('parameterList'),
            value: 'parameter',
            sortable: false
M
min 已提交
143 144
          },
          {
X
Xin Wang 已提交
145 146 147
            text: this.$t('returnType'),
            value: 'returnType',
            sortable: false
M
min 已提交
148 149
          }
        ]
150
      },
N
nzomkxia 已提交
151 152 153 154 155 156 157
      setHoverHint: function () {
        this.hint = 'copy'
      },

      setoutHint: function () {
        this.hint = 'url'
      },
X
Xin Wang 已提交
158 159 160 161 162 163 164 165 166 167 168 169
      setdetailHeaders: function () {
        this.detailHeaders = {
          providers: [
            {
              text: this.$t('ip'),
              value: 'ip'
            },
            {
              text: this.$t('port'),
              value: 'port'
            },
            {
N
nzomkxia 已提交
170
              text: this.$t('timeout'),
X
Xin Wang 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
              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'
            }
          ]
        }
      },
199
      detail: function (service) {
马金凯 已提交
200
        this.$axios.get('/service/' + service)
201 202 203
            .then(response => {
              this.providerDetails = response.data.providers
              this.consumerDetails = response.data.consumers
N
nzomkxia 已提交
204 205 206
              if (response.data.metadata !== null) {
                this.methodMetaData = response.data.metadata.methods
              }
207 208 209 210 211 212 213
            })
      },
      getIp: function (address) {
        return address.split(':')[0]
      },
      getPort: function (address) {
        return address.split(':')[1]
N
nzomkxia 已提交
214 215 216 217 218 219 220
      },
      getParameters: function (parameterTypes) {
        let result = ''
        for (let i = 0; i < parameterTypes.length; i++) {
          result = result + parameterTypes[i] + ' '
        }
        return result.trim()
221 222 223 224 225
      },
      toCopyText (text) {
        this.$copyText(text).then(() => {
          this.$notify.success(this.$t('copySuccessfully'))
        }, () => {})
226 227
      }
    },
I
IORI 已提交
228 229 230 231 232 233 234 235 236 237 238
    computed: {
      area () {
        return this.$i18n.locale
      }
    },
    watch: {
      area () {
        this.setdetailHeaders()
        this.setmetaHeaders()
      }
    },
239
    mounted: function () {
X
Xin Wang 已提交
240 241
      this.setmetaHeaders()
      this.setdetailHeaders()
242
      let query = this.$route.query
N
nzomkxia 已提交
243 244 245 246 247 248 249
      let meta = {
        'service': '',
        'app': '',
        'group': '',
        'version': ''
      }
      var vm = this
250
      Object.keys(query).forEach(function (key) {
N
nzomkxia 已提交
251 252
        if (key in meta) {
          meta[key] = query[key]
253 254
        }
      })
N
nzomkxia 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267
      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]
268
          item.name = key
N
nzomkxia 已提交
269 270
          vm.basic.push(item)
        })
M
min 已提交
271
      }
272
    }
M
min 已提交
273 274 275
  }
</script>

N
nzomkxia 已提交
276 277 278 279 280 281 282 283
<style scoped>
  .tiny {
    min-width: 30px;
    height: 20px;
    font-size: 8px;
  }
</style>