refactor: ♻️ 重构菜单管理前端
This commit is contained in:
@@ -1,17 +1,23 @@
|
|||||||
import { CrudOptions, AddReq, DelReq, EditReq, dict, CrudExpose } from '@fast-crud/fast-crud';
|
import {
|
||||||
|
CrudOptions,
|
||||||
|
AddReq,
|
||||||
|
DelReq,
|
||||||
|
EditReq,
|
||||||
|
dict,
|
||||||
|
CrudExpose,
|
||||||
|
CreateCrudOptionsRet,
|
||||||
|
CreateCrudOptionsProps,
|
||||||
|
UserPageQuery,
|
||||||
|
} from '@fast-crud/fast-crud';
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import * as api from './api';
|
import * as api from './api';
|
||||||
import { dictionary } from '/@/utils/dictionary';
|
|
||||||
|
|
||||||
interface CreateCrudOptionsTypes {
|
|
||||||
crudOptions: CrudOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
import { request } from '/@/utils/service';
|
import { request } from '/@/utils/service';
|
||||||
//此处为crudOptions配置
|
//此处为crudOptions配置
|
||||||
export const createCrudOptions = function ({ crudExpose, selectOptions }: { crudExpose: CrudExpose; selectOptions: any }): CreateCrudOptionsTypes {
|
export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||||
const pageRequest = async (query: any) => {
|
const pageRequest = async (query: UserPageQuery) => {
|
||||||
return await api.GetList({ menu: selectOptions.value.id } as any);
|
console.log(context!.selectOptions);
|
||||||
|
return await api.GetList({ menu: context!.selectOptions.value.id } as any);
|
||||||
};
|
};
|
||||||
const editRequest = async ({ form, row }: EditReq) => {
|
const editRequest = async ({ form, row }: EditReq) => {
|
||||||
form.id = row.id;
|
form.id = row.id;
|
||||||
@@ -1,83 +1,28 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-drawer size="70%" v-model="menuButtonDrawer" direction="rtl" destroy-on-close :before-close="handleClose">
|
<fs-page>
|
||||||
<template #header>
|
|
||||||
<div>
|
|
||||||
当前菜单:
|
|
||||||
<el-tag>{{ selectOptions.name }}</el-tag>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<div>
|
|
||||||
<fs-page style="margin-top: 60px">
|
|
||||||
<fs-crud ref="crudRef" v-bind="crudBinding"> </fs-crud>
|
<fs-crud ref="crudRef" v-bind="crudBinding"> </fs-crud>
|
||||||
</fs-page>
|
</fs-page>
|
||||||
</div>
|
|
||||||
</el-drawer>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, defineProps, defineEmits, watch, toRaw } from 'vue';
|
import { ref, defineProps, watch } from 'vue';
|
||||||
import { useExpose, useCrud } from '@fast-crud/fast-crud';
|
import { useFs } from '@fast-crud/fast-crud';
|
||||||
import { createCrudOptions } from './curd';
|
import { createCrudOptions } from './crud';
|
||||||
import { ElMessageBox } from 'element-plus';
|
|
||||||
// 弹窗是否显示
|
|
||||||
let menuButtonDrawer = ref(false);
|
|
||||||
// 当前选择的菜单信息
|
// 当前选择的菜单信息
|
||||||
let selectOptions: any = ref({ name: null });
|
let selectOptions: any = ref({ name: null });
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
drawerShow: {
|
|
||||||
type: boolean;
|
|
||||||
default: false;
|
|
||||||
};
|
|
||||||
selectMenu: object;
|
selectMenu: object;
|
||||||
}>();
|
}>();
|
||||||
const emit = defineEmits<{
|
|
||||||
(e: 'drawer-close', value: boolean): void;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
// 侦听弹窗变量
|
watch(props.selectMenu, (val: any) => {
|
||||||
watch(
|
if (!val.is_catalog) {
|
||||||
() => props.drawerShow,
|
|
||||||
(newVal) => {
|
|
||||||
menuButtonDrawer.value = newVal ? true : false;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(props.selectMenu, (val) => {
|
|
||||||
selectOptions.value = val;
|
selectOptions.value = val;
|
||||||
doRefresh();
|
doRefresh();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//抽屉关闭确认
|
const { crudRef, crudBinding, crudExpose, context } = useFs({ createCrudOptions, context: { selectOptions } });
|
||||||
const handleClose = (done: () => void) => {
|
|
||||||
ElMessageBox.confirm('您确定要关闭?', {
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning',
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
done();
|
|
||||||
// @ts-ignore
|
|
||||||
emit('drawer-close', menuButtonDrawer);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
// catch error
|
|
||||||
});
|
|
||||||
};
|
|
||||||
// crud组件的ref
|
|
||||||
const crudRef = ref();
|
|
||||||
// crud 配置的ref
|
|
||||||
const crudBinding = ref();
|
|
||||||
// 暴露的方法
|
|
||||||
const { crudExpose } = useExpose({ crudRef, crudBinding });
|
|
||||||
|
|
||||||
const { doRefresh } = crudExpose;
|
const { doRefresh } = crudExpose;
|
||||||
// 你的crud配置
|
|
||||||
const { crudOptions } = createCrudOptions({ crudExpose, selectOptions });
|
|
||||||
// 初始化crud配置
|
|
||||||
// @ts-ignore
|
|
||||||
const { resetCrudOptions } = useCrud({ crudExpose, crudOptions });
|
|
||||||
// 你可以调用此方法,重新初始化crud配置
|
|
||||||
// resetCrudOptions(options)
|
|
||||||
|
|
||||||
defineExpose({ menuButtonDrawer, selectOptions });
|
defineExpose({ selectOptions });
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -79,16 +79,7 @@
|
|||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="20">
|
|
||||||
<el-form-item label="权限" class="flex flex-wrap w-full">
|
|
||||||
<el-checkbox-group v-model="form.permission" :disabled="form.is_catalog" class="flex flex-wrap">
|
|
||||||
<el-checkbox v-model="form.permission">全选</el-checkbox>
|
|
||||||
<!-- TODO 选中没做 -->
|
|
||||||
<el-checkbox v-for="item in menuPermissonList" :checked="true" :label="`${item.name}(${item.value})`" />
|
|
||||||
</el-checkbox-group>
|
|
||||||
<el-button class="mx-2" @click="addPermission()">其他权限</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="20">
|
<el-col :span="20">
|
||||||
<el-form-item label="图标" prop="icon">
|
<el-form-item label="图标" prop="icon">
|
||||||
<IconSelector clearable v-model="form.icon" />
|
<IconSelector clearable v-model="form.icon" />
|
||||||
@@ -104,11 +95,15 @@
|
|||||||
</el-divider>
|
</el-divider>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
<el-row>
|
||||||
|
<el-col>
|
||||||
|
<menuButton :select-menu="form" class="h-screen/2" />
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<menuButton :drawer-show="permissionDrawerVisible" @drawer-close="drawerClose()" :select-menu="form"></menuButton>
|
|
||||||
</fs-page>
|
</fs-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
content: ['./index.html', './src/**/*.{vue,js}'],
|
content: ['./index.html', './src/**/*.{vue,js}'],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {
|
||||||
|
height: {
|
||||||
|
'screen/2': '50vh',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user