🎉 是否显示默认显示

This commit is contained in:
dh186609 2023-02-24 10:02:07 +08:00
parent e3fceb4375
commit bf77dacdb2

View File

@ -1,218 +1,219 @@
<template>
<el-dialog :title="state.ruleForm.menuId ? $t('common.editBtn') : $t('common.addBtn')" v-model="visible"
:close-on-click-modal="false" draggable>
<el-form ref="menuDialogFormRef" :model="state.ruleForm" :rules="dataRules" label-width="90px" v-loading="loading">
<el-row :gutter="20">
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.menuType')" prop="menType">
<el-radio-group v-model="state.ruleForm.menuType">
<el-radio-button label="0">左菜单</el-radio-button>
<el-radio-button label="1">按钮</el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.parentId')" prop="parentId">
<el-tree-select v-model="state.ruleForm.parentId" :data="state.parentData" default-expand-all
:props="{ value: 'id', label: 'name', children: 'children' }" class="w100" clearable check-strictly
:placeholder="$t('sysmenu.inputParentIdTip')">
</el-tree-select>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.name')" prop="name">
<el-input v-model="state.ruleForm.name" clearable placeholder="格式router.xxx"></el-input>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0'">
<el-form-item :label="$t('sysmenu.path')" prop="path">
<el-input v-model="state.ruleForm.path" :placeholder="$t('sysmenu.inputPathTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '1'">
<el-form-item :label="$t('sysmenu.permission')" prop="permission">
<el-input v-model="state.ruleForm.permission" maxlength="50"
:placeholder="$t('sysmenu.inputPermissionTip')" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.sortOrder')" prop="sortOrder">
<el-input-number v-model="state.ruleForm.sortOrder" :min="0" controls-position="right" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.icon')" prop="icon">
<IconSelector :placeholder="$t('sysmenu.inputIconTip')" v-model="state.ruleForm.icon" />
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0' && showembedded">
<el-form-item :label="$t('sysmenu.embedded')" prop="embedded">
<el-radio-group v-model="state.ruleForm.embedded">
<el-radio-button label="0"></el-radio-button>
<el-radio-button label="1"></el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0'">
<el-form-item :label="$t('sysmenu.keepAlive')" prop="keepAlive">
<el-radio-group v-model="state.ruleForm.keepAlive">
<el-radio-button label="0"></el-radio-button>
<el-radio-button label="1"></el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0'">
<el-form-item :label="$t('sysmenu.visible')" prop="visible">
<el-radio-group v-model="state.ruleForm.visible">
<el-radio-button label="0"></el-radio-button>
<el-radio-button label="1"></el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-dialog :close-on-click-modal="false" :title="state.ruleForm.menuId ? $t('common.editBtn') : $t('common.addBtn')"
draggable v-model="visible">
<el-form :model="state.ruleForm" :rules="dataRules" label-width="90px" ref="menuDialogFormRef"
v-loading="loading">
<el-row :gutter="20">
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.menuType')" prop="menType">
<el-radio-group v-model="state.ruleForm.menuType">
<el-radio-button label="0">左菜单</el-radio-button>
<el-radio-button label="1">按钮</el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.parentId')" prop="parentId">
<el-tree-select :data="state.parentData" :placeholder="$t('sysmenu.inputParentIdTip')" :props="{ value: 'id', label: 'name', children: 'children' }"
check-strictly class="w100"
clearable default-expand-all
v-model="state.ruleForm.parentId">
</el-tree-select>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.name')" prop="name">
<el-input clearable placeholder="格式router.xxx" v-model="state.ruleForm.name"></el-input>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0'">
<el-form-item :label="$t('sysmenu.path')" prop="path">
<el-input :placeholder="$t('sysmenu.inputPathTip')" v-model="state.ruleForm.path"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '1'">
<el-form-item :label="$t('sysmenu.permission')" prop="permission">
<el-input :placeholder="$t('sysmenu.inputPermissionTip')" maxlength="50"
v-model="state.ruleForm.permission"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.sortOrder')" prop="sortOrder">
<el-input-number :min="0" controls-position="right" v-model="state.ruleForm.sortOrder"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item :label="$t('sysmenu.icon')" prop="icon">
<IconSelector :placeholder="$t('sysmenu.inputIconTip')" v-model="state.ruleForm.icon"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0' && showembedded">
<el-form-item :label="$t('sysmenu.embedded')" prop="embedded">
<el-radio-group v-model="state.ruleForm.embedded">
<el-radio-button label="0"></el-radio-button>
<el-radio-button label="1"></el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0'">
<el-form-item :label="$t('sysmenu.keepAlive')" prop="keepAlive">
<el-radio-group v-model="state.ruleForm.keepAlive">
<el-radio-button label="0"></el-radio-button>
<el-radio-button label="1"></el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0'">
<el-form-item :label="$t('sysmenu.visible')" prop="visible">
<el-radio-group v-model="state.ruleForm.visible">
<el-radio-button label="0"></el-radio-button>
<el-radio-button label="1"></el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
<el-button type="primary" @click="onSubmit">{{ $t('common.confirmButtonText') }}</el-button>
<el-button @click="onSubmit" type="primary">{{ $t('common.confirmButtonText') }}</el-button>
</span>
</template>
</el-dialog>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="systemMenuDialog">
import { info, pageList, update, addObj } from "/@/api/admin/menu";
import { useMessage } from "/@/hooks/message";
<script lang="ts" name="systemMenuDialog" setup>
import {addObj, info, pageList, update} from "/@/api/admin/menu";
import {useMessage} from "/@/hooks/message";
// /
const emit = defineEmits(['refresh']);
//
const IconSelector = defineAsyncComponent(() => import('/@/components/iconSelector/index.vue'));
// /
const emit = defineEmits(['refresh']);
//
const IconSelector = defineAsyncComponent(() => import('/@/components/iconSelector/index.vue'));
const visible = ref(false)
const loading = ref(false)
//
const menuDialogFormRef = ref();
//
const state = reactive({
ruleForm: {
id: '',
menuId: '',
name: '',
permission: '',
parentId: '',
icon: '',
path: '',
sortOrder: 0,
menuType: '0',
keepAlive: '0',
visible: '0',
embedded: '0',
},
parentData: [] as any[], //
});
//
const getMenuData = () => {
state.parentData = []
pageList().then(res => {
let menu = {
createBy: "",
createTime: "",
delFlag: "",
icon: "",
keepAlive: "",
menuId: "",
menuType: "",
parentId: "",
path: "",
embedded: '0',
sortOrder: 0,
updateBy: "",
updateTime: "",
visible: "",
id: '-1', name: '根菜单', children: []
};
menu.children = res.data;
state.parentData.push(menu)
})
};
const showembedded = ref(false)
watch(() => state.ruleForm.path, (val) => {
if (val.startsWith('http')) {
showembedded.value = true
} else {
showembedded.value = false
state.ruleForm.embedded = '0'
}
})
const dataRules = reactive({
menType: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
parentId: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
path: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
permission: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
sortOrder: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
keepAlive: [{ required: true, message: "姓名不能为空", trigger: "blur" }]
})
//
const openDialog = (type: string, row?: any) => {
if (row?.id && type === 'edit') {
state.ruleForm.id = row.id
//
loading.value = true
info(row.id).then(res => {
Object.assign(state.ruleForm, res.data)
}).finally(() => {
loading.value = false
})
} else {
// 使
nextTick(() => {
menuDialogFormRef?.value?.resetFields();
state.ruleForm.parentId = row?.id || '-1'
const visible = ref(false)
const loading = ref(false)
//
const menuDialogFormRef = ref();
//
const state = reactive({
ruleForm: {
id: '',
menuId: '',
name: '',
permission: '',
parentId: '',
icon: '',
path: '',
sortOrder: 0,
menuType: '0',
keepAlive: '0',
visible: '1',
embedded: '0',
},
parentData: [] as any[], //
});
}
visible.value = true;
getMenuData();
};
//
const getMenuData = () => {
state.parentData = []
pageList().then(res => {
let menu = {
createBy: "",
createTime: "",
delFlag: "",
icon: "",
keepAlive: "",
menuId: "",
menuType: "",
parentId: "",
path: "",
embedded: '0',
sortOrder: 0,
updateBy: "",
updateTime: "",
visible: "",
id: '-1', name: '根菜单', children: []
};
menu.children = res.data;
state.parentData.push(menu)
})
};
//
const onSubmit = () => {
//
if (state.ruleForm.id) {
loading.value = true
update(state.ruleForm).then(() => {
visible.value = false;
emit('refresh');
}).catch(err => {
useMessage().error(err.msg)
}).finally(() => {
loading.value = false
const showembedded = ref(false)
watch(() => state.ruleForm.path, (val) => {
if (val.startsWith('http')) {
showembedded.value = true
} else {
showembedded.value = false
state.ruleForm.embedded = '0'
}
})
} else {
loading.value = true
addObj(state.ruleForm).then(() => {
visible.value = false;
emit('refresh');
}).catch(err => {
useMessage().error(err.msg)
}).finally(() => {
loading.value = false
const dataRules = reactive({
menType: [{required: true, message: "姓名不能为空", trigger: "blur"}],
parentId: [{required: true, message: "姓名不能为空", trigger: "blur"}],
name: [{required: true, message: "姓名不能为空", trigger: "blur"}],
path: [{required: true, message: "姓名不能为空", trigger: "blur"}],
permission: [{required: true, message: "姓名不能为空", trigger: "blur"}],
sortOrder: [{required: true, message: "姓名不能为空", trigger: "blur"}],
keepAlive: [{required: true, message: "姓名不能为空", trigger: "blur"}]
})
}
//
const openDialog = (type: string, row?: any) => {
if (row?.id && type === 'edit') {
state.ruleForm.id = row.id
//
loading.value = true
info(row.id).then(res => {
Object.assign(state.ruleForm, res.data)
}).finally(() => {
loading.value = false
})
} else {
// 使
nextTick(() => {
menuDialogFormRef?.value?.resetFields();
state.ruleForm.parentId = row?.id || '-1'
});
};
}
visible.value = true;
getMenuData();
};
// 使
defineExpose({
openDialog,
});
//
const onSubmit = () => {
//
if (state.ruleForm.id) {
loading.value = true
update(state.ruleForm).then(() => {
visible.value = false;
emit('refresh');
}).catch(err => {
useMessage().error(err.msg)
}).finally(() => {
loading.value = false
})
} else {
loading.value = true
addObj(state.ruleForm).then(() => {
visible.value = false;
emit('refresh');
}).catch(err => {
useMessage().error(err.msg)
}).finally(() => {
loading.value = false
})
}
};
// 使
defineExpose({
openDialog,
});
</script>