API增删改查忘词嗯

This commit is contained in:
pixel
2019-09-28 16:34:43 +08:00
parent 324d45f1de
commit 3237b8402b
11 changed files with 267 additions and 40 deletions
+69
View File
@@ -17,4 +17,73 @@ export const getApiList = (data) => {
method: 'post',
data
})
}
// @Tags Api
// @Summary 创建基础api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateApiParams true "创建api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/createApi [post]
export const createApi = (data) => {
return service({
url: "/api/createApi",
method: 'post',
data
})
}
// @Tags menu
// @Summary 根据id获取菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.GetById true "根据id获取菜单"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getApiById [post]
export const getApiById = (data) => {
return service({
url: "/api/getApiById",
method: 'post',
data
})
}
// @Tags Api
// @Summary 更新api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateApiParams true "更新api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /api/updataApi [post]
export const updataApi = (data) => {
return service({
url: "/api/updataApi",
method: 'post',
data
})
}
// @Tags Api
// @Summary 更新api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateApiParams true "更新api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /api/setAuthApi [post]
export const setAuthApi = (data) => {
return service({
url: "/api/setAuthApi",
method: 'post',
data
})
}
+17
View File
@@ -97,4 +97,21 @@ export const updataBaseMenu = (data) => {
method: 'post',
data
})
}
// @Tags menu
// @Summary 根据id获取菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.GetById true "根据id获取菜单"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuById [post]
export const getBaseMenuById = (data) => {
return service({
url: "/menu/getBaseMenuById",
method: 'post',
data
})
}
+92 -10
View File
@@ -1,12 +1,12 @@
<template>
<div>
<div class="button-box clearflex">
<el-button @click="addApi" type="primary">新增api</el-button>
<el-button @click="openDialog('addApi')" type="primary">新增api</el-button>
</div>
<el-table :data="tableData" border stripe>
<el-table-column label="id" min-width="180" prop="ID"></el-table-column>
<el-table-column label="api路径" min-width="180" prop="path"></el-table-column>
<el-table-column label="api简介" min-width="180" prop="description"></el-table-column>
<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>
<el-table-column fixed="right" label="操作" width="200">
<template slot-scope="scope">
<el-button @click="editApi(scope.row)" size="small" type="text">编辑</el-button>
@@ -25,6 +25,21 @@
hide-on-single-page
layout="total, sizes, prev, pager, next, jumper"
></el-pagination>
<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>
</div>
</template>
@@ -32,23 +47,90 @@
<script>
// 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成
import { getApiList } from '@/api/api'
import { getApiById, getApiList, createApi, updataApi } from '@/api/api'
import infoList from '@/view/superAdmin/mixins/infoList'
export default {
name: 'Api',
mixins:[infoList],
mixins: [infoList],
data() {
return {
listApi: getApiList,
listKey:'list'
listKey: 'list',
dialogFormVisible: false,
form: {
path: '',
description: ''
},
type: ''
}
},
methods: {
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()
}
addApi() {},
editApi() {},
deleteApi() {}
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
}
}
},
created() {
this.getTableData()
@@ -4,11 +4,13 @@
<el-button @click="addAuthority" type="primary">新增角色</el-button>
</div>
<el-table :data="tableData" border stripe>
<el-table-column label="id" min-width="180" prop="ID"></el-table-column>
<el-table-column label="角色id" min-width="180" prop="authorityId"></el-table-column>
<el-table-column label="角色名称" min-width="180" prop="authorityName"></el-table-column>
<el-table-column fixed="right" label="操作" width="500">
<template slot-scope="scope">
<el-button @click="addAuthMenu(scope.row)" size="small" type="text">增加角色菜单</el-button>
<el-button @click="addAuthMenu(scope.row)" size="small" type="text">变更角色菜单</el-button>
<el-button @click="addAuthApi(scope.row)" size="small" type="text">变更角色Api</el-button>
<el-button @click="deleteAuth(scope.row)" size="small" type="text">删除角色</el-button>
</template>
</el-table-column>
+17 -10
View File
@@ -27,7 +27,7 @@
<el-table-column fixed="right" label="操作" width="300">
<template slot-scope="scope">
<el-button @click="deleteMenu(scope.row.ID)" size="small" type="text">删除菜单</el-button>
<el-button @click="editMenu(scope.row)" size="small" type="text">编辑菜单</el-button>
<el-button @click="editMenu(scope.row.ID)" size="small" type="text">编辑菜单</el-button>
<el-button @click="addMenu(scope.row.ID)" size="small" type="text">添加子菜单</el-button>
</template>
</el-table-column>
@@ -82,7 +82,7 @@
<script>
// 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成
import { updataBaseMenu ,getMenuList, addBaseMenu, deleteBaseMenu } from '@/api/menu'
import { updataBaseMenu ,getMenuList, addBaseMenu, deleteBaseMenu, getBaseMenuById } from '@/api/menu'
import infoList from '@/view/superAdmin/mixins/infoList'
export default {
name: 'Menus',
@@ -93,6 +93,7 @@ export default {
listKey:'list',
dialogFormVisible: false,
form: {
ID:0,
path: '',
name: '',
hidden: '',
@@ -102,7 +103,8 @@ export default {
title: '',
icon: ''
}
}
},
isEdit:false
}
},
methods: {
@@ -151,7 +153,12 @@ export default {
},
// 添加menu
async enterDialog() {
const res = await addBaseMenu(this.form)
let res
if(this.isEdit){
res = await updataBaseMenu(this.form)
}else{
res = await addBaseMenu(this.form)
}
if (res.success) {
this.$message({
type: 'success',
@@ -172,15 +179,15 @@ export default {
// 添加菜单方法,id为 0则为添加根菜单
addMenu(id) {
this.form.parentId = String(id)
this.isEdit = false
this.dialogFormVisible = true
},
// 修改菜单方法
async editMenu(row){
row.name = "修改测试"
row.meta.title="修改测试"
row.meta.icon = "share"
const res = await updataBaseMenu(row)
console.log(res)
async editMenu(id){
const res = await getBaseMenuById({id})
this.form = res.data.menu
this.dialogFormVisible = true
this.isEdit = true
}
}
}