api.vue 5.3 KB
Newer Older
1
<template>
2 3
  <div>
    <div class="button-box clearflex">
4
    </div>
5 6 7 8 9 10 11 12
        <div class="search-term">
      <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  <el-form-item label="路径">
    <el-input v-model="searchInfo.path" placeholder="路径"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">查询</el-button>
  </el-form-item>
13 14 15
   <el-form-item >
      <el-button @click="openDialog('addApi')" type="primary">新增api</el-button>
  </el-form-item>
16 17
</el-form>
  </div>
18
    <el-table :data="tableData" border stripe>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
19 20
      <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>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
21
      <el-table-column label="api分组" min-width="150" prop="group"></el-table-column>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
      <el-table-column label="api简介" min-width="150" prop="description"></el-table-column>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
      <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"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
40 41 42 43

    <el-dialog :visible.sync="dialogFormVisible" title="新增Api">
      <el-form :inline="true" :model="form" label-width="80px">
        <el-form-item label="路径">
44
          <el-input autocomplete="off" v-model="form.path"></el-input>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
45
        </el-form-item>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
46 47 48 49
        <el-form-item label="api分组">
          <el-input autocomplete="off" v-model="form.group"></el-input>
        </el-form-item>
        <el-form-item label="api简介">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
50 51 52 53 54 55 56 57
          <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>
58
  </div>
59 60
</template>

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

62
<script>
63
// 获取列表内容封装在mixins内部  getTableData方法 初始化已封装完成 条件搜索时候 请把条件安好后台定制的结构体字段 放到 this.searchInfo 中即可实现条件搜索
Mr.奇淼('s avatar
注释  
Mr.奇淼( 已提交
64

65 66 67 68 69 70 71
import {
  getApiById,
  getApiList,
  createApi,
  updataApi,
  deleteApi
} from '@/api/api'
72
import infoList from '@/components/mixins/infoList'
73

74
export default {
75
  name: 'Api',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
76
  mixins: [infoList],
77 78 79
  data() {
    return {
      listApi: getApiList,
Mr.奇淼('s avatar
Mr.奇淼( 已提交
80 81 82 83
      listKey: 'list',
      dialogFormVisible: false,
      form: {
        path: '',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
84
        group: '',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
85 86 87
        description: ''
      },
      type: ''
88 89 90
    }
  },
  methods: {
91 92 93 94 95 96
    //条件搜索前端看此方法
    onSubmit(){
      this.page = 1 
      this.pageSize = 10
      this.getTableData()
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
97 98 99
    initForm() {
      this.form = {
        path: '',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
100
        group: '',
Mr.奇淼('s avatar
Mr.奇淼( 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        description: ''
      }
    },
    closeDialog() {
      this.initForm()
      this.dialogFormVisible = false
    },
    openDialog(type) {
      this.type = type
      this.dialogFormVisible = true
    },
    async editApi(row) {
      const res = await getApiById({ id: row.ID })
      this.form = res.data.api
      this.openDialog('edit')
    },
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    async deleteApi(row) {
      this.$confirm('此操作将永久删除所有角色下该菜单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await deleteApi(row)
          if (res.success) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getTableData()
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
Mr.奇淼('s avatar
Mr.奇淼( 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    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()
          }
155

Mr.奇淼('s avatar
Mr.奇淼( 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
          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
      }
    }
182
  }
183 184
}
</script>
185 186 187 188 189 190 191
<style scoped lang="scss">
.button-box {
  padding: 10px 20px;
  .el-button {
    float: right;
  }
}
192
</style>