吴雨瞳添加了注释

master
wyt 4 months ago
parent 889e6456e6
commit fd01452699

@ -1,69 +1,97 @@
<template>
<!-- 主卡片容器用于包裹整个资源管理页面内容 -->
<el-card class="main-card">
<!-- 页面标题使用当前路由名称作为标题 -->
<div class="title">{{ this.$route.name }}</div>
<!-- 操作按钮和搜索区域容器 -->
<div class="operation-container">
<!-- 新增模块按钮 -->
<el-button type="primary" size="small" icon="el-icon-plus" @click="openModel(null)"> </el-button>
<!-- 搜索区域居右显示 -->
<div style="margin-left: auto">
<!-- 搜索输入框支持回车搜索 -->
<el-input
v-model="keywords"
prefix-icon="el-icon-search"
size="small"
placeholder="请输入资源名"
style="width: 200px"
@keyup.enter.native="listResources" />
v-model="keywords"
prefix-icon="el-icon-search"
size="small"
placeholder="请输入资源名"
style="width: 200px"
@keyup.enter.native="listResources" />
<!-- 搜索按钮 -->
<el-button type="primary" size="small" icon="el-icon-search" style="margin-left: 1rem" @click="listResources">
搜索
</el-button>
</div>
</div>
<!-- 资源列表表格支持树形结构展示 -->
<el-table
v-loading="loading"
:data="resources"
row-key="id"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
<el-table-column prop="resourceName" label="资源名" width="220" />
<el-table-column prop="url" label="资源路径" width="300" />
<el-table-column prop="requetMethod" label="请求方式">
<template slot-scope="scope" v-if="scope.row.requestMethod">
<el-tag :type="tagType(scope.row.requestMethod)">
{{ scope.row.requestMethod }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="isAnonymous" label="匿名访问" align="center">
<template slot-scope="scope">
<el-switch
v-if="scope.row.url"
v-model="scope.row.isAnonymous"
active-color="#13ce66"
inactive-color="#F4F4F5"
:active-value="1"
:inactive-value="0"
@change="changeResource(scope.row)" />
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" align="center">
<template slot-scope="scope">
<i class="el-icon-time" style="margin-right: 5px" />
{{ scope.row.createTime | date }}
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="200">
<template slot-scope="scope">
<el-button type="text" size="mini" @click="openAddResourceModel(scope.row)" v-if="scope.row.children">
<i class="el-icon-plus" /> 新增
</el-button>
<el-button type="text" size="mini" @click="openEditResourceModel(scope.row)">
<i class="el-icon-edit" /> 修改
</el-button>
<el-popconfirm title="确定删除吗?" style="margin-left: 10px" @confirm="deleteResource(scope.row.id)">
<el-button size="mini" type="text" slot="reference"> <i class="el-icon-delete" /> 删除 </el-button>
</el-popconfirm>
</template>
</el-table-column>
v-loading="loading" <!-- 加载状态 -->
:data="resources" <!-- 表格数据 -->
row-key="id" <!-- 每行的唯一标识字段 -->
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"> <!-- 树形结构配置 -->
<!-- 资源名列 -->
<el-table-column prop="resourceName" label="资源名" width="220" />
<!-- 资源路径列 -->
<el-table-column prop="url" label="资源路径" width="300" />
<!-- 请求方式列使用标签展示不同请求类型 -->
<el-table-column prop="requetMethod" label="请求方式">
<template slot-scope="scope" v-if="scope.row.requestMethod">
<el-tag :type="tagType(scope.row.requestMethod)">
{{ scope.row.requestMethod }}
</el-tag>
</template>
</el-table-column>
<!-- 匿名访问列使用开关控制 -->
<el-table-column prop="isAnonymous" label="匿名访问" align="center">
<template slot-scope="scope">
<el-switch
v-if="scope.row.url" <!-- 只有存在资源路径的行才显示开关 -->
v-model="scope.row.isAnonymous"
active-color="#13ce66"
inactive-color="#F4F4F5"
:active-value="1" <!-- 1表示允许匿名访问 -->
:inactive-value="0" <!-- 0表示不允许匿名访问 -->
@change="changeResource(scope.row)" /> <!-- 开关变化时触发的事件 -->
</template>
</el-table-column>
<!-- 创建时间列格式化显示 -->
<el-table-column prop="createTime" label="创建时间" align="center">
<template slot-scope="scope">
<i class="el-icon-time" style="margin-right: 5px" />
{{ scope.row.createTime | date }} <!-- 使用date过滤器格式化时间 -->
</template>
</el-table-column>
<!-- 操作列包含新增子资源修改删除功能 -->
<el-table-column label="操作" align="center" width="200">
<template slot-scope="scope">
<!-- 新增子资源按钮只有存在子资源的行才显示 -->
<el-button type="text" size="mini" @click="openAddResourceModel(scope.row)" v-if="scope.row.children">
<i class="el-icon-plus" /> 新增
</el-button>
<!-- 修改按钮 -->
<el-button type="text" size="mini" @click="openEditResourceModel(scope.row)">
<i class="el-icon-edit" /> 修改
</el-button>
<!-- 删除确认弹窗 -->
<el-popconfirm title="确定删除吗?" style="margin-left: 10px" @confirm="deleteResource(scope.row.id)">
<el-button size="mini" type="text" slot="reference"> <i class="el-icon-delete" /> 删除 </el-button>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<!-- 新增/修改模块弹窗 -->
<el-dialog :visible.sync="addModule" width="30%">
<div class="dialog-title-container" slot="title" ref="moduleTitle" />
<div class="dialog-title-container" slot="title" ref="moduleTitle" /> <!-- 弹窗标题动态设置 -->
<el-form label-width="80px" size="medium" :model="resourceForm">
<el-form-item label="模块名">
<el-input v-model="resourceForm.resourceName" style="width: 220px" />
@ -74,8 +102,10 @@
<el-button type="primary" @click="addOrEditResource"> </el-button>
</span>
</el-dialog>
<!-- 新增/修改资源弹窗 -->
<el-dialog :visible.sync="addResource" width="30%">
<div class="dialog-title-container" slot="title" ref="resourceTitle" />
<div class="dialog-title-container" slot="title" ref="resourceTitle" /> <!-- 弹窗标题动态设置 -->
<el-form label-width="80px" size="medium" :model="resourceForm">
<el-form-item label="资源名">
<el-input v-model="resourceForm.resourceName" style="width: 220px" />
@ -102,41 +132,44 @@
<script>
export default {
//
created() {
this.listResources()
},
data() {
return {
loading: true,
keywords: '',
resources: [],
addModule: false,
addResource: false,
resourceForm: {}
loading: true, //
keywords: '', //
resources: [], //
addModule: false, // /
addResource: false, // /
resourceForm: {} //
}
},
methods: {
//
listResources() {
this.axios
.get('/api/admin/resources', {
params: {
keywords: this.keywords
}
})
.then(({ data }) => {
this.resources = data.data
this.loading = false
})
.get('/api/admin/resources', {
params: {
keywords: this.keywords //
}
})
.then(({ data }) => {
this.resources = data.data //
this.loading = false //
})
},
// 访
changeResource(resource) {
this.axios.post('/api/admin/resources', resource).then(({ data }) => {
if (data.flag) {
if (data.flag) { //
this.$notify.success({
title: '成功',
message: data.message
})
this.listResources()
} else {
this.listResources() //
} else { //
this.$notify.error({
title: '失败',
message: data.message
@ -144,41 +177,46 @@ export default {
}
})
},
// /
openModel(resource) {
if (resource != null) {
if (resource != null) { //
this.resourceForm = JSON.parse(JSON.stringify(resource))
this.$refs.moduleTitle.innerHTML = '修改模块'
} else {
this.$refs.moduleTitle.innerHTML = '修改模块' //
} else { //
this.resourceForm = {}
this.$refs.moduleTitle.innerHTML = '添加模块'
this.$refs.moduleTitle.innerHTML = '添加模块' //
}
this.addModule = true
this.addModule = true //
},
//
openEditResourceModel(resource) {
if (resource.url == null) {
if (resource.url == null) { //
this.openModel(resource)
return false
}
//
this.resourceForm = JSON.parse(JSON.stringify(resource))
this.$refs.resourceTitle.innerHTML = '修改资源'
this.addResource = true
this.$refs.resourceTitle.innerHTML = '修改资源' //
this.addResource = true //
},
//
openAddResourceModel(resource) {
console.log(resource)
this.resourceForm = {}
this.resourceForm.parentId = resource.id
this.$refs.resourceTitle.innerHTML = '添加资源'
this.addResource = true
this.resourceForm = {} //
this.resourceForm.parentId = resource.id // ID
this.$refs.resourceTitle.innerHTML = '添加资源' //
this.addResource = true //
},
//
deleteResource(id) {
this.axios.delete('/api/admin/resources/' + id).then(({ data }) => {
if (data.flag) {
if (data.flag) { //
this.$notify.success({
title: '成功',
message: data.message
})
this.listResources()
} else {
this.listResources() //
} else { //
this.$notify.error({
title: '失败',
message: data.message
@ -186,44 +224,49 @@ export default {
}
})
},
// /
addOrEditResource() {
//
if (this.resourceForm.resourceName.trim() == '') {
this.$message.error('资源名不能为空')
return false
}
//
this.axios.post('/api/admin/resources', this.resourceForm).then(({ data }) => {
if (data.flag) {
if (data.flag) { //
this.$notify.success({
title: '成功',
message: data.message
})
this.listResources()
} else {
this.listResources() //
} else { //
this.$notify.error({
title: '失败',
message: data.message
})
}
//
this.addModule = false
this.addResource = false
})
}
},
computed: {
//
tagType() {
return function (type) {
switch (type) {
case 'GET':
return ''
return '' //
case 'POST':
return 'success'
return 'success' // 绿
case 'PUT':
return 'warning'
return 'warning' //
case 'DELETE':
return 'danger'
return 'danger' //
}
}
}
}
}
</script>
</script>
Loading…
Cancel
Save