公告管理权限设置

This commit is contained in:
WindowBird 2025-11-22 14:45:13 +08:00
parent cc3f12a980
commit 70c350b866
3 changed files with 61 additions and 0 deletions

View File

@ -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>

View File

@ -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无效',

View File

@ -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',