|
@@ -0,0 +1,109 @@
|
|
|
+<template>
|
|
|
+ <div class="main animate__animated animate__backInRight">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" style="text-align: right; padding: 10px">
|
|
|
+ <el-button type="primary" size="small" @click="toAdd()">{{ $t('common.create') }}</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24">
|
|
|
+ <menu-table></menu-table>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-dialog v-model="dialog" :title="$t('pages.menus.dialogTitle')" :destroy-on-close="false" @close="toClose">
|
|
|
+ <menu-info></menu-info>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import menuTable from './parts/menu-table.vue'
|
|
|
+import menuInfo from './parts/menu-info.vue'
|
|
|
+import { cloneDeep, get, omit } from 'lodash-es'
|
|
|
+import { UserMenusStore } from '@/store/api/system/userMenus'
|
|
|
+import { DictDataStore } from '@/store/api/system/dictData'
|
|
|
+import { useI18n } from 'vue-i18n'
|
|
|
+const { t } = useI18n()
|
|
|
+const store = UserMenusStore()
|
|
|
+const dictDataStore = DictDataStore()
|
|
|
+const $checkRes = inject('$checkRes')
|
|
|
+const dialog = ref(false)
|
|
|
+const list = ref([])
|
|
|
+const form = ref({})
|
|
|
+const typeList = [
|
|
|
+ // { label: '目录', value: '0' },
|
|
|
+ { label: '页面', value: '1' },
|
|
|
+ { label: '子页面', value: '2' }
|
|
|
+]
|
|
|
+const iconList = ref([])
|
|
|
+onMounted(async () => {
|
|
|
+ await searchOther()
|
|
|
+ await search()
|
|
|
+})
|
|
|
+const searchOther = async () => {
|
|
|
+ const result = await dictDataStore.query({ code: 'icon', is_use: '0' })
|
|
|
+ if ($checkRes(result)) iconList.value = result.data
|
|
|
+}
|
|
|
+// #region 接口函数
|
|
|
+const search = async () => {
|
|
|
+ const res = await store.query()
|
|
|
+ if ($checkRes(res)) {
|
|
|
+ list.value = res.data
|
|
|
+ }
|
|
|
+}
|
|
|
+const toSave = async () => {
|
|
|
+ const data = cloneDeep(omit(form.value, ['children', 'parent_name']))
|
|
|
+ let res
|
|
|
+ if (get(data, 'id')) {
|
|
|
+ res = await store.update(data)
|
|
|
+ } else res = await store.create(data)
|
|
|
+ if ($checkRes(res, true)) {
|
|
|
+ search()
|
|
|
+ toClose()
|
|
|
+ }
|
|
|
+}
|
|
|
+const toDelete = async (row) => {
|
|
|
+ ElMessageBox.confirm(t('common.delete_confirm'), t('common.warning'), {
|
|
|
+ confirmButtonText: t('common.confirm'),
|
|
|
+ cancelButtonText: t('common.cancel'),
|
|
|
+ type: 'warning'
|
|
|
+ }).then(async () => {
|
|
|
+ const res = await store.del(row.id)
|
|
|
+ if ($checkRes(res, true)) {
|
|
|
+ search()
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+// #endregion
|
|
|
+
|
|
|
+// #region 工具函数
|
|
|
+const toAddNext = (row) => {
|
|
|
+ const obj = { parent_id: row.id, is_use: '0' }
|
|
|
+ form.value = obj
|
|
|
+ dialog.value = true
|
|
|
+}
|
|
|
+const toUpdate = (row) => {
|
|
|
+ form.value = cloneDeep(row)
|
|
|
+ dialog.value = true
|
|
|
+}
|
|
|
+
|
|
|
+const toAdd = () => {
|
|
|
+ dialog.value = true
|
|
|
+ form.value = { is_use: '0' }
|
|
|
+}
|
|
|
+const toClose = () => {
|
|
|
+ form.value = {}
|
|
|
+ dialog.value = false
|
|
|
+}
|
|
|
+// #endregion
|
|
|
+
|
|
|
+// provide
|
|
|
+provide('menuTree', list)
|
|
|
+provide('form', form)
|
|
|
+provide('typeList', typeList)
|
|
|
+provide('toUpdate', toUpdate)
|
|
|
+provide('toAddNext', toAddNext)
|
|
|
+provide('toDelete', toDelete)
|
|
|
+provide('toSave', toSave)
|
|
|
+provide('iconList', iconList)
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|