公告管理权限设置
This commit is contained in:
parent
cc3f12a980
commit
70c350b866
|
|
@ -212,7 +212,9 @@
|
|||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { createNotice, getUserList } from '@/api';
|
||||
import { useUserStore } from '@/store/user';
|
||||
import AttachmentImageUploader from '@/components/task/AttachmentImageUploader.vue';
|
||||
import AttachmentFileUploader from '@/components/task/AttachmentFileUploader.vue';
|
||||
|
||||
|
|
@ -462,7 +464,26 @@ const handleSubmit = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
// 用户角色判断
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
const isAdmin = computed(() => {
|
||||
if (!userInfo.value || !Array.isArray(userInfo.value.roles)) return false;
|
||||
return userInfo.value.roles.some((role) => ['admin', 'sys_admin'].includes(role));
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
// 权限检查:只有 admin 和 sys_admin 可以创建公告
|
||||
if (!isAdmin.value) {
|
||||
uni.showToast({
|
||||
title: '无权限访问',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
loadUserOptions();
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -341,6 +341,15 @@ const previewAttachment = (attach) => {
|
|||
|
||||
// 编辑公告
|
||||
const handleEdit = () => {
|
||||
// 权限检查:只有 admin 和 sys_admin 可以编辑公告
|
||||
if (!isAdmin.value) {
|
||||
uni.showToast({
|
||||
title: '无权限操作',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!noticeId.value) {
|
||||
uni.showToast({
|
||||
title: '公告ID无效',
|
||||
|
|
@ -356,6 +365,15 @@ const handleEdit = () => {
|
|||
|
||||
// 删除公告
|
||||
const handleDelete = async () => {
|
||||
// 权限检查:只有 admin 和 sys_admin 可以删除公告
|
||||
if (!isAdmin.value) {
|
||||
uni.showToast({
|
||||
title: '无权限操作',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!noticeId.value) {
|
||||
uni.showToast({
|
||||
title: '公告ID无效',
|
||||
|
|
|
|||
|
|
@ -215,7 +215,9 @@
|
|||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { getUserList, getNoticeDetail, updateNotice } from '@/api';
|
||||
import { useUserStore } from '@/store/user';
|
||||
import AttachmentImageUploader from '@/components/task/AttachmentImageUploader.vue';
|
||||
import AttachmentFileUploader from '@/components/task/AttachmentFileUploader.vue';
|
||||
|
||||
|
|
@ -581,7 +583,27 @@ const handleSubmit = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
// 用户角色判断
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
const isAdmin = computed(() => {
|
||||
if (!userInfo.value || !Array.isArray(userInfo.value.roles)) return false;
|
||||
return userInfo.value.roles.some((role) => ['admin', 'sys_admin'].includes(role));
|
||||
});
|
||||
|
||||
onLoad(async (options) => {
|
||||
// 权限检查:只有 admin 和 sys_admin 可以编辑公告
|
||||
if (!isAdmin.value) {
|
||||
uni.showToast({
|
||||
title: '无权限访问',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!options || !options.id) {
|
||||
uni.showToast({
|
||||
title: '缺少公告ID',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user