api.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div>
  3. <div class="button-box clearflex">
  4. <el-button @click="openDialog('addApi')" type="primary">新增api</el-button>
  5. </div>
  6. <el-table :data="tableData" border stripe>
  7. <el-table-column label="id" min-width="60" prop="ID"></el-table-column>
  8. <el-table-column label="api路径" min-width="150" prop="path"></el-table-column>
  9. <el-table-column label="api分组" min-width="150" prop="group"></el-table-column>
  10. <el-table-column label="api简介" min-width="150" prop="description"></el-table-column>
  11. <el-table-column fixed="right" label="操作" width="200">
  12. <template slot-scope="scope">
  13. <el-button @click="editApi(scope.row)" size="small" type="text">编辑</el-button>
  14. <el-button @click="deleteApi(scope.row)" size="small" type="text">删除</el-button>
  15. </template>
  16. </el-table-column>
  17. </el-table>
  18. <el-pagination
  19. :current-page="page"
  20. :page-size="pageSize"
  21. :page-sizes="[10, 30, 50, 100]"
  22. :style="{float:'right',padding:'20px'}"
  23. :total="total"
  24. @current-change="handleCurrentChange"
  25. @size-change="handleSizeChange"
  26. hide-on-single-page
  27. layout="total, sizes, prev, pager, next, jumper"
  28. ></el-pagination>
  29. <el-dialog :visible.sync="dialogFormVisible" title="新增Api">
  30. <el-form :inline="true" :model="form" label-width="80px">
  31. <el-form-item label="路径">
  32. <el-input autocomplete="off" @blur="autoGroup" v-model="form.path"></el-input>
  33. </el-form-item>
  34. <el-form-item label="api分组">
  35. <el-input autocomplete="off" v-model="form.group"></el-input>
  36. </el-form-item>
  37. <el-form-item label="api简介">
  38. <el-input autocomplete="off" v-model="form.description"></el-input>
  39. </el-form-item>
  40. </el-form>
  41. <div class="dialog-footer" slot="footer">
  42. <el-button @click="closeDialog">取 消</el-button>
  43. <el-button @click="enterDialog" type="primary">确 定</el-button>
  44. </div>
  45. </el-dialog>
  46. </div>
  47. </template>
  48. <script>
  49. // 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成
  50. import { getApiById, getApiList, createApi, updataApi } from '@/api/api'
  51. import infoList from '@/view/superAdmin/mixins/infoList'
  52. export default {
  53. name: 'Api',
  54. mixins: [infoList],
  55. data() {
  56. return {
  57. listApi: getApiList,
  58. listKey: 'list',
  59. dialogFormVisible: false,
  60. form: {
  61. path: '',
  62. group: '',
  63. description: ''
  64. },
  65. type: ''
  66. }
  67. },
  68. methods: {
  69. // 自动设置api分组
  70. autoGroup(){
  71. this.form.group = this.form.path.split('/')[1]
  72. },
  73. initForm() {
  74. this.form = {
  75. path: '',
  76. group: '',
  77. description: ''
  78. }
  79. },
  80. closeDialog() {
  81. this.initForm()
  82. this.dialogFormVisible = false
  83. },
  84. openDialog(type) {
  85. this.type = type
  86. this.dialogFormVisible = true
  87. },
  88. addApi() {
  89. createApi()
  90. },
  91. async editApi(row) {
  92. const res = await getApiById({ id: row.ID })
  93. this.form = res.data.api
  94. this.openDialog('edit')
  95. },
  96. deleteApi() {},
  97. async enterDialog() {
  98. switch (this.type) {
  99. case 'addApi':
  100. {
  101. const res = await createApi(this.form)
  102. if (res.success) {
  103. this.$message({
  104. type: 'success',
  105. message: '添加成功',
  106. showClose: true
  107. })
  108. }
  109. this.getTableData()
  110. this.closeDialog()
  111. }
  112. break
  113. case 'edit':
  114. {
  115. const res = await updataApi(this.form)
  116. if (res.success) {
  117. this.$message({
  118. type: 'success',
  119. message: '添加成功',
  120. showClose: true
  121. })
  122. }
  123. this.getTableData()
  124. this.closeDialog()
  125. }
  126. break
  127. default:
  128. {
  129. this.$message({
  130. type: 'error',
  131. message: '未知操作',
  132. showClose: true
  133. })
  134. }
  135. break
  136. }
  137. }
  138. },
  139. created() {
  140. this.getTableData()
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .button-box {
  146. padding: 10px 20px;
  147. .el-button {
  148. float: right;
  149. }
  150. }
  151. </style>