apiList.vue 2.47 KB
<!-- api列表 -->
<template>
  <d2-container>
    <d2-table-header title="API列表"></d2-table-header>
    <d2-table
      ref="apiList"
      :hasNum="false"
      :searchForm="searchForm"
      :tableParams="tableParams"
      :getListApi="getListApi"
    >
      <auth-button
        slot="auth-button"
        slot-scope="scope"
        :data="scope.scope"
      ></auth-button>
    </d2-table>
  </d2-container>
</template>

<script>
import { apiList, apiStartandStartAndStop } from '@api/api'
export default {
  name: 'apiList',
  data() {
    return {
      searchForm: {},
      getListApi: apiList,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '序号',
          prop: 'id',
          width: '50px'
        }, {
          label: 'API分类',
          prop: 'apiClassification',
          formatter: (cellValue) => {
            return {
              1: '授权管理',
              2: '设备管理',
              3: '数据服务'
            }[cellValue.apiClassification]
          }
        }, {
          label: 'API名称',
          prop: 'apiName'
        }, {
          label: '请求方式',
          prop: 'requestMethod',
          formatter: (cellValue) => {
            return {
              1: 'GET',
              2: 'POST'
            }[cellValue.requestMethod]
          }
        }, {
          label: 'API接口',
          prop: 'apiInterface'
        }, {
          label: '说明',
          prop: 'description'
        }, {
          label: '状态',
          prop: 'status',
          width: '60px',
          formatter: (cellValue) => {
            return {
              0: '停用',
              1: '可用'
            }[cellValue.status]
          }
        }]
      }
    }
  },

  mounted() { },

  methods: {
    messageConfirm(txt, fn, title = '提示', type) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: type || 'warning'
      }).then(() => {
        fn()
      })
    },
    handleUpOrDown(row) {
      this.messageConfirm('是否' + (row.status ? '停用' : '启用') + '?', () => {
        apiStartandStartAndStop({
          id: row.id,
          status: row.status === 1 ? 0 : 1
        }).then(res => {
          this.notice.okTips()
          this.$refs.apiList.refreshTable()
        })
      })
    }
  }
}

</script>
<style scoped>
</style>