Browse Source

菜单管理setup改造完成

main
piexlmax 3 years ago
parent
commit
26066ce7bc
  1. 1
      web/src/view/superAdmin/authority/authority.vue
  2. 2
      web/src/view/superAdmin/authority/components/datas.vue
  3. 32
      web/src/view/superAdmin/menu/icon.vue
  4. 285
      web/src/view/superAdmin/menu/menu.vue

1
web/src/view/superAdmin/authority/authority.vue

@ -179,7 +179,6 @@ const datas = ref(null)
const autoEnter = (activeName, oldActiveName) => { const autoEnter = (activeName, oldActiveName) => {
const paneArr = [menus, apis, datas] const paneArr = [menus, apis, datas]
if (oldActiveName) { if (oldActiveName) {
console.log(paneArr[oldActiveName].value.needConfirm)
if (paneArr[oldActiveName].value.needConfirm) { if (paneArr[oldActiveName].value.needConfirm) {
paneArr[oldActiveName].value.enterAndNext() paneArr[oldActiveName].value.enterAndNext()
paneArr[oldActiveName].value.needConfirm = false paneArr[oldActiveName].value.needConfirm = false

2
web/src/view/superAdmin/authority/components/datas.vue

@ -67,7 +67,6 @@ init()
// 使 // 使
const enterAndNext = () => { const enterAndNext = () => {
console.log(123)
authDataEnter() authDataEnter()
} }
@ -97,7 +96,6 @@ const getChildrenId = (row, arrBox) => {
} }
// //
const authDataEnter = async() => { const authDataEnter = async() => {
console.log(123, props.row)
const res = await setDataAuthority(props.row) const res = await setDataAuthority(props.row)
if (res.code === 0) { if (res.code === 0) {
ElMessage({ type: 'success', message: '资源设置成功' }) ElMessage({ type: 'success', message: '资源设置成功' })

32
web/src/view/superAdmin/menu/icon.vue

@ -18,22 +18,18 @@
</div> </div>
</template> </template>
<script>
export default {
name: 'Icon',
props: {
<script setup>
import { defineProps, ref, reactive } from 'vue'
const props = defineProps({
meta: { meta: {
default: function() { default: function() {
return {} return {}
}, },
type: Object type: Object
} }
},
data() {
return {
input: '',
metaData: {},
options: [
})
const options = reactive([
{ {
'key': 'aim', 'key': 'aim',
'label': 'aim' 'label': 'aim'
@ -1154,14 +1150,14 @@ export default {
'key': 'wind-power', 'key': 'wind-power',
'label': 'wind-power' 'label': 'wind-power'
} }
],
value: ''
}
},
created() {
this.metaData = this.meta
},
methods: {}
])
const metaData = ref(props.meta)
</script>
<script>
export default {
name: 'Icon',
} }
</script> </script>

285
web/src/view/superAdmin/menu/menu.vue

@ -188,9 +188,7 @@
</div> </div>
</template> </template>
<script>
// mixins getTableData
<script setup>
import { import {
updateBaseMenu, updateBaseMenu,
getMenuList, getMenuList,
@ -198,45 +196,12 @@ import {
deleteBaseMenu, deleteBaseMenu,
getBaseMenuById getBaseMenuById
} from '@/api/menu' } from '@/api/menu'
import infoList from '@/mixins/infoList'
import icon from '@/view/superAdmin/menu/icon.vue' import icon from '@/view/superAdmin/menu/icon.vue'
import warningBar from '@/components/warningBar/warningBar.vue' import warningBar from '@/components/warningBar/warningBar.vue'
export default {
name: 'Menus',
components: {
icon,
warningBar
},
mixins: [infoList],
data() {
return {
checkFlag: false,
listApi: getMenuList,
dialogFormVisible: false,
dialogTitle: '新增菜单',
menuOption: [
{
ID: '0',
title: '根菜单'
}
],
form: {
ID: 0,
path: '',
name: '',
hidden: '',
parentId: '',
component: '',
meta: {
title: '',
icon: '',
defaultMenu: false,
closeTab: false,
keepAlive: false
},
parameters: []
},
rules: {
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const rules = reactive({
path: [{ required: true, message: '请输入菜单name', trigger: 'blur' }], path: [{ required: true, message: '请输入菜单name', trigger: 'blur' }],
component: [ component: [
{ required: true, message: '请输入文件路径', trigger: 'blur' } { required: true, message: '请输入文件路径', trigger: 'blur' }
@ -244,74 +209,69 @@ export default {
'meta.title': [ 'meta.title': [
{ required: true, message: '请输入菜单展示名称', trigger: 'blur' } { required: true, message: '请输入菜单展示名称', trigger: 'blur' }
] ]
},
isEdit: false,
test: ''
})
const page = ref(1)
const total = ref(0)
const pageSize = ref(999)
const tableData = ref([])
const searchInfo = ref({})
//
const getTableData = async() => {
const table = await getMenuList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
if (table.code === 0) {
tableData.value = table.data.list
total.value = table.data.total
page.value = table.data.page
pageSize.value = table.data.pageSize
} }
},
async created() {
this.pageSize = 999
await this.getTableData()
},
methods: {
addParameter(form) {
}
getTableData()
//
const addParameter = (form) => {
if (!form.parameters) { if (!form.parameters) {
this.form.parameters = []
form.value.parameters = []
} }
form.parameters.push({ form.parameters.push({
type: 'query', type: 'query',
key: '', key: '',
value: '' value: ''
}) })
},
deleteParameter(parameters, index) {
}
//
const deleteParameter = (parameters, index) => {
parameters.splice(index, 1) parameters.splice(index, 1)
},
changeName() {
this.form.path = this.form.name
},
setOptions() {
this.menuOption = [
{
ID: '0',
title: '根目录'
} }
]
this.setMenuOptions(this.tableData, this.menuOption, false)
const form = ref({
ID: 0,
path: '',
name: '',
hidden: '',
parentId: '',
component: '',
meta: {
title: '',
icon: '',
defaultMenu: false,
closeTab: false,
keepAlive: false
}, },
setMenuOptions(menuData, optionsData, disabled) {
menuData &&
menuData.forEach(item => {
if (item.children && item.children.length) {
const option = {
title: item.meta.title,
ID: String(item.ID),
disabled: disabled || item.ID === this.form.ID,
children: []
}
this.setMenuOptions(
item.children,
option.children,
disabled || item.ID === this.form.ID
)
optionsData.push(option)
} else {
const option = {
title: item.meta.title,
ID: String(item.ID),
disabled: disabled || item.ID === this.form.ID
}
optionsData.push(option)
}
parameters: []
}) })
},
handleClose(done) {
this.initForm()
const changeName = () => {
form.value.path = form.value.name
}
const handleClose = (done) => {
initForm()
done() done()
},
}
// //
deleteMenu(ID) {
this.$confirm('此操作将永久删除所有角色下该菜单, 是否继续?', '提示', {
const deleteMenu = (ID) => {
ElMessageBox.confirm('此操作将永久删除所有角色下该菜单, 是否继续?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
@ -319,28 +279,30 @@ export default {
.then(async() => { .then(async() => {
const res = await deleteBaseMenu({ ID }) const res = await deleteBaseMenu({ ID })
if (res.code === 0) { if (res.code === 0) {
this.$message({
ElMessage({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}) })
if (this.tableData.length === 1 && this.page > 1) {
this.page--
if (tableData.value.length === 1 && page.value > 1) {
page.value--
} }
this.getTableData()
getTableData()
} }
}) })
.catch(() => { .catch(() => {
this.$message({
ElMessage({
type: 'info', type: 'info',
message: '已取消删除' message: '已取消删除'
}) })
}) })
},
}
// //
initForm() {
this.checkFlag = false
this.$refs.menuForm.resetFields()
this.form = {
const menuForm = ref(null)
const checkFlag = ref(false)
const initForm = () => {
checkFlag.value = false
menuForm.value.resetFields()
form.value = {
ID: 0, ID: 0,
path: '', path: '',
name: '', name: '',
@ -354,51 +316,108 @@ export default {
keepAlive: '' keepAlive: ''
} }
} }
},
}
// //
closeDialog() {
this.initForm()
this.dialogFormVisible = false
},
const dialogFormVisible = ref(false)
const closeDialog = () => {
initForm()
dialogFormVisible.value = false
}
// menu // menu
async enterDialog() {
this.$refs.menuForm.validate(async valid => {
const enterDialog = async() => {
menuForm.value.validate(async valid => {
if (valid) { if (valid) {
let res let res
if (this.isEdit) {
res = await updateBaseMenu(this.form)
if (isEdit.value) {
res = await updateBaseMenu(form.value)
} else { } else {
res = await addBaseMenu(this.form)
res = await addBaseMenu(form.value)
} }
if (res.code === 0) { if (res.code === 0) {
this.$message({
ElMessage({
type: 'success', type: 'success',
message: this.isEdit ? '编辑成功' : '添加成功!'
message: isEdit.value ? '编辑成功' : '添加成功!'
}) })
this.getTableData()
getTableData()
} }
this.initForm()
this.dialogFormVisible = false
initForm()
dialogFormVisible.value = false
} }
}) })
},
}
const menuOption = ref([
{
ID: '0',
title: '根菜单'
}
])
const setOptions = () => {
menuOption.value = [
{
ID: '0',
title: '根目录'
}
]
setMenuOptions(tableData.value, menuOption.value, false)
}
const setMenuOptions = (menuData, optionsData, disabled) => {
menuData &&
menuData.forEach(item => {
if (item.children && item.children.length) {
const option = {
title: item.meta.title,
ID: String(item.ID),
disabled: disabled || item.ID === form.value.ID,
children: []
}
setMenuOptions(
item.children,
option.children,
disabled || item.ID === form.value.ID
)
optionsData.push(option)
} else {
const option = {
title: item.meta.title,
ID: String(item.ID),
disabled: disabled || item.ID === form.value.ID
}
optionsData.push(option)
}
})
}
// id 0 // id 0
addMenu(id) {
this.dialogTitle = '新增菜单'
this.form.parentId = String(id)
this.isEdit = false
this.setOptions()
this.dialogFormVisible = true
},
const isEdit = ref(false)
const dialogTitle = ref('新增菜单')
const addMenu = (id) => {
dialogTitle.value = '新增菜单'
form.value.parentId = String(id)
isEdit.value = false
setOptions()
dialogFormVisible.value = true
}
// //
async editMenu(id) {
this.dialogTitle = '编辑菜单'
const editMenu = async(id) => {
dialogTitle.value = '编辑菜单'
const res = await getBaseMenuById({ id }) const res = await getBaseMenuById({ id })
this.form = res.data.menu
this.isEdit = true
this.setOptions()
this.dialogFormVisible = true
form.value = res.data.menu
isEdit.value = true
setOptions()
dialogFormVisible.value = true
} }
</script>
<script>
// mixins getTableData
export default {
name: 'Menus',
methods: {
} }
} }
</script> </script>

Loading…
Cancel
Save