You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
6.4 KiB
208 lines
6.4 KiB
<template>
|
|
<div>
|
|
<CardContainer>
|
|
<vxe-toolbar>
|
|
<template #buttons>
|
|
<el-button icon="el-icon-plus" type="primary" size="small" @click="isShowAdd = true">新增</el-button>
|
|
<el-button icon="el-icon-search" type="primary" plain size="small" @click="getList">搜索</el-button>
|
|
</template>
|
|
</vxe-toolbar>
|
|
<vxe-table
|
|
ref="table"
|
|
style="margin-top: 10px;"
|
|
:loading="loading"
|
|
keep-source
|
|
:row-config="{ useKey: 'id', isHover: true }"
|
|
:column-config="{ resizable: true }"
|
|
:edit-rules="validRules"
|
|
:edit-config="{ trigger: 'manual', mode: 'row', showStatus: true, autoClear: false, expandALl: true }"
|
|
:tree-config="{ rowField: 'id', parentField: 'pid' }"
|
|
:data="tableData"
|
|
>
|
|
<vxe-column type="seq" width="58" align="center" />
|
|
<vxe-column field="name" tree-node width="160" title="菜单" :edit-render="{ name: 'input', attrs: { type: 'text'} }" />
|
|
<vxe-column field="path" title="路由地址" min-width="140" :edit-render="{ name: 'input', attrs: { type: 'text'} }">
|
|
<template #default="{ row }">
|
|
<template v-if="/#/g.test(row.path)">
|
|
<SvgIcon icon-class="folder" class-name="icon-folder" />
|
|
</template>
|
|
<template v-else>
|
|
<span>{{ row.path }}</span>
|
|
</template>
|
|
</template>
|
|
</vxe-column>
|
|
<vxe-column field="api_profix" min-width="140" title="api前缀" :edit-render="{ name: 'input', attrs: { type: 'text'} }">
|
|
<template #default="{ row }">
|
|
<template v-if="/#/g.test(row.api_profix)">
|
|
<SvgIcon icon-class="folder" class-name="icon-folder" />
|
|
</template>
|
|
<template v-else>
|
|
<span>{{ row.api_profix }}</span>
|
|
</template>
|
|
</template>
|
|
</vxe-column>
|
|
<vxe-column field="visible" width="100" align="center" title="是否显示" :edit-render="{ name: 'select', options: [{ value: 1, label: '显示' },{ value: 0, label: '隐藏' }] }" />
|
|
<vxe-column field="icon" width="160" align="center" title="图标" :edit-render="{ name: 'input', attrs: { type: 'text'} }">
|
|
<template #default="{ row }">
|
|
<Icon :icon="row.icon" />
|
|
</template>
|
|
</vxe-column>
|
|
<vxe-column field="sortnumber" width="80" title="排序" align="center" :edit-render="{ name: 'input', attrs: { type: 'number' } }" />
|
|
<vxe-column field="operate" title="操作" min-width="240">
|
|
<template #default="{ row }">
|
|
<template v-if="isActiveStatus(row)">
|
|
<el-button size="small" type="primary" @click="saveRowEvent(row)">保存</el-button>
|
|
<el-button size="small" type="primary" plain @click="cancelRowEvent(row)">取消</el-button>
|
|
</template>
|
|
<template v-else>
|
|
<el-button size="small" type="success" @click="$refs['AddMenu'].setPid(row.id),isShowAdd = true">子菜单</el-button>
|
|
<el-button size="small" type="warning" @click="editRowEvent(row)">编辑</el-button>
|
|
<el-button size="small" type="danger" @click="destroyRowEvent(row)">删除</el-button>
|
|
</template>
|
|
</template>
|
|
</vxe-column>
|
|
</vxe-table>
|
|
</CardContainer>
|
|
|
|
<add-menu ref="AddMenu" :is-show.sync="isShowAdd" :list="tableData" @refresh="getList" />
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import addMenu from './components/AddMenu.vue'
|
|
import Icon from '@/layout/components/Navbar/Icon.vue'
|
|
import SvgIcon from '@/components/SvgIcon'
|
|
import { index, save, destroy } from '@/api/menu'
|
|
import { deepCopy } from '@/utils'
|
|
export default {
|
|
components: {
|
|
SvgIcon,
|
|
Icon,
|
|
addMenu
|
|
},
|
|
data() {
|
|
return {
|
|
isShowAdd: false,
|
|
|
|
loading: false,
|
|
allAlign: null,
|
|
tableData: [],
|
|
validRules: {
|
|
name: [
|
|
{ required: true, message: '请输入名称' }
|
|
],
|
|
path: [
|
|
{ required: true, message: '请输入路由路径' }
|
|
],
|
|
api_profix: [
|
|
{ required: true, message: '请输入api前缀' }
|
|
]
|
|
},
|
|
form: {
|
|
id: '',
|
|
pid: '',
|
|
name: '',
|
|
url: '',
|
|
path: '',
|
|
api_profix: '',
|
|
icon: '',
|
|
visible: 1,
|
|
sortnumber: 0
|
|
}
|
|
}
|
|
},
|
|
computed: {
|
|
isActiveStatus() {
|
|
return function(row) {
|
|
if (this.$refs['table']) {
|
|
return this.$refs['table'].isEditByRow(row)
|
|
}
|
|
}
|
|
}
|
|
},
|
|
created() {
|
|
this.getList()
|
|
},
|
|
methods: {
|
|
editRowEvent(row) {
|
|
if (this.$refs['table']) {
|
|
this.$refs['table'].setEditRow(row)
|
|
}
|
|
},
|
|
cancelRowEvent(row) {
|
|
if (this.$refs['table']) {
|
|
this.$refs['table'].clearEdit().then(() => {
|
|
// 还原行数据
|
|
this.$refs['table'].revertData(row)
|
|
})
|
|
}
|
|
},
|
|
|
|
async getList() {
|
|
this.loading = true
|
|
try {
|
|
const res = await index()
|
|
this.tableData = res
|
|
console.log(this.tableData)
|
|
this.loading = false
|
|
} catch (err) {
|
|
console.error(err)
|
|
this.loading = false
|
|
}
|
|
},
|
|
|
|
async saveRowEvent(row) {
|
|
try {
|
|
const errMap = await this.$refs['table'].validate()
|
|
if (errMap) {
|
|
throw new Error(errMap)
|
|
}
|
|
await this.$confirm('确认保存?', '提示', {
|
|
confirmButtonText: '确认',
|
|
cancelButtonText: '取消'
|
|
})
|
|
await this.$refs['table'].clearEdit()
|
|
const form = deepCopy(this.form)
|
|
for (const key in form) {
|
|
form[key] = row[key]
|
|
}
|
|
console.log(form)
|
|
this.loading = true
|
|
await save(form)
|
|
await this.getList()
|
|
this.loading = false
|
|
} catch (err) {
|
|
this.loading = false
|
|
}
|
|
},
|
|
async destroyRowEvent(row) {
|
|
try {
|
|
await this.$confirm('确认删除?', '提示', {
|
|
confirmButtonText: '确认',
|
|
cancelButtonText: '取消'
|
|
})
|
|
this.loading = true
|
|
if (row.id) {
|
|
await destroy({
|
|
id: row.id
|
|
})
|
|
await this.getList()
|
|
} else {
|
|
this.tableData.splice(this.tableData.findIndex(i => i._X_ROW_KEY === row._X_ROW_KEY), 1)
|
|
}
|
|
this.loading = false
|
|
} catch (err) {
|
|
this.loading = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.icon-folder {
|
|
width: 2em;
|
|
height: 2em;
|
|
}
|
|
</style>
|