api.vue 3.9 KB
Newer Older
1
<template>
2 3
  <div>
    <div class="button-box clearflex">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
4
      <el-button @click="openDialog('addApi')" type="primary">新增api</el-button>
5
    </div>
6
    <el-table :data="tableData" border stripe>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
7 8 9
      <el-table-column label="id" min-width="60" prop="ID"></el-table-column>
      <el-table-column label="api路径" min-width="150" prop="path"></el-table-column>
      <el-table-column label="api简介" min-width="150" prop="description"></el-table-column>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
      <el-table-column fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button @click="editApi(scope.row)" size="small" type="text">编辑</el-button>
          <el-button @click="deleteApi(scope.row)" size="small" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page"
      :page-size="pageSize"
      :page-sizes="[10, 30, 50, 100]"
      :style="{float:'right',padding:'20px'}"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      hide-on-single-page
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

    <el-dialog :visible.sync="dialogFormVisible" title="新增Api">
      <el-form :inline="true" :model="form" label-width="80px">
        <el-form-item label="路径">
          <el-input autocomplete="off" v-model="form.path"></el-input>
        </el-form-item>
        <el-form-item label="说明">
          <el-input autocomplete="off" v-model="form.description"></el-input>
        </el-form-item>
      </el-form>
      <div class="dialog-footer" slot="footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button @click="enterDialog" type="primary">确 定</el-button>
      </div>
    </el-dialog>
43
  </div>
44 45
</template>

Mr.奇淼('s avatar
注释  
Mr.奇淼( 已提交
46

47
<script>
Mr.奇淼('s avatar
注释  
Mr.奇淼( 已提交
48 49
// 获取列表内容封装在mixins内部  getTableData方法 初始化已封装完成

Mr.奇淼('s avatar
Mr.奇淼( 已提交
50
import { getApiById, getApiList, createApi, updataApi } from '@/api/api'
51 52
import infoList from '@/view/superAdmin/mixins/infoList'

53
export default {
54
  name: 'Api',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
55
  mixins: [infoList],
56 57 58
  data() {
    return {
      listApi: getApiList,
Mr.奇淼('s avatar
Mr.奇淼( 已提交
59 60 61 62 63 64 65
      listKey: 'list',
      dialogFormVisible: false,
      form: {
        path: '',
        description: ''
      },
      type: ''
66 67 68
    }
  },
  methods: {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    initForm() {
      this.form = {
        path: '',
        description: ''
      }
    },
    closeDialog() {
      this.initForm()
      this.dialogFormVisible = false
    },
    openDialog(type) {
      this.type = type
      this.dialogFormVisible = true
    },
    addApi() {
      createApi()
    },
    async editApi(row) {
      const res = await getApiById({ id: row.ID })
      this.form = res.data.api
      this.openDialog('edit')
    },
    deleteApi() {},
    async enterDialog() {
      switch (this.type) {
        case 'addApi':
          {
            const res = await createApi(this.form)
            if (res.success) {
              this.$message({
                type: 'success',
                message: '添加成功',
                showClose: true
              })
            }
            this.getTableData()
            this.closeDialog()
          }
107

Mr.奇淼('s avatar
Mr.奇淼( 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
          break
        case 'edit':
          {
            const res = await updataApi(this.form)
            if (res.success) {
              this.$message({
                type: 'success',
                message: '添加成功',
                showClose: true
              })
            }
            this.getTableData()
            this.closeDialog()
          }
          break
        default:
          {
            this.$message({
              type: 'error',
              message: '未知操作',
              showClose: true
            })
          }
          break
      }
    }
134 135 136 137
  },
  created() {
    this.getTableData()
  }
138 139
}
</script>
140 141 142 143 144 145 146
<style scoped lang="scss">
.button-box {
  padding: 10px 20px;
  .el-button {
    float: right;
  }
}
147
</style>