Procházet zdrojové kódy

更新课程权限逻辑:课程和blockly课程数据权限在后台查询给状态

liyanbo před 4 měsíci
rodič
revize
6497fd58a6

+ 0 - 4
src/components/HomePage.vue

@@ -141,8 +141,6 @@ const LogoutClick = async () => {
     localStorage.removeItem('token')
     localStorage.removeItem('isLoggedIn')
     localStorage.removeItem('maxCourseSections')
-    localStorage.removeItem('courseDataScope')
-    localStorage.removeItem('blocklyDataScope')
 
     // 跳转到登录页面
     router.push({ path: '/login' })
@@ -152,8 +150,6 @@ const LogoutClick = async () => {
     localStorage.removeItem('token')
     localStorage.removeItem('isLoggedIn')
     localStorage.removeItem('maxCourseSections')
-    localStorage.removeItem('courseDataScope')
-    localStorage.removeItem('blocklyDataScope')
     Message().notifyError('退出登录失败,请重试', true)
     router.push({ path: '/login' })
   }

+ 5 - 17
src/views/AIPage/AIDevelop.vue

@@ -243,8 +243,6 @@ const courseId = ref('')
 // 课程排序
 const typeSort = ref('')
 
-// 课程权限
-const courseDataScope = ref([])
 // 测试账号禁用视频
 const isDisabled = ref(false)
 
@@ -295,7 +293,6 @@ const handleSelect = index => {
   if (videoPathMap.value[index]) {
     course.value = videoPathMap.value[index]
     courseId.value = course.value.id
-    console.log("课程id:",courseId.value)
     // 切换标题后,关闭抽屉
     drawerVisible.value = false
   } else {
@@ -304,7 +301,7 @@ const handleSelect = index => {
   }
 
   //测试账号禁用视频
-  if (disableVideo(index)) return
+  if (disableMsg(index)) return
 }
 
 // 展平所有菜单项索引
@@ -370,16 +367,11 @@ const handleVideoEnded = () => {
   }
 }
 
-// 禁用视频
-const disableVideo = (index = course.value.key) => {
-
-  // 未配置课程权限,不禁用视频
-  if (!courseDataScope.value || courseDataScope.value.length === 0) {
-    return false
-  }
+// 禁用视频(提示语)
+const disableMsg = (index = course.value.key) => {
 
   //配置了课程权限,且视频id不在权限列表中
-  isDisabled.value = !courseDataScope.value.some(item => Number(item) === videoPathMap.value[index].id)
+  isDisabled.value = videoPathMap.value[index].dataReadonly
   if (isDisabled.value) {
     Message().notifyWarning('您的账号并未开放此课程!', true)
     return isDisabled.value;
@@ -481,10 +473,6 @@ const getAllCourseSections = () => {
 // 渲染 课程数据结构 以及 视频
 onMounted(async () => {
 
-  if (localStorage.getItem("courseDataScope")) {
-    courseDataScope.value = localStorage.getItem("courseDataScope").split(",");
-  }
-
    const typeIdParam = router.currentRoute.value.query.typeId
   if (typeIdParam) {
     typeId.value = typeIdParam
@@ -558,7 +546,7 @@ onMounted(async () => {
         //确定默认课程
         if (index === 0) {
           courseId.value = courseTemp.id
-          if(!disableVideo(menuIndex)){
+          if(!disableMsg(menuIndex)){
             course.value = courseTemp
           }else{
             course.value.key = courseTemp.key

+ 0 - 3
src/views/Login.vue

@@ -277,9 +277,6 @@ const handleLogin = async params => {
           // 存储登录状态
           localStorage.setItem('isLoggedIn', 'true')
           localStorage.setItem('token', res.data.accessToken)
-          //课程权限
-          localStorage.setItem('courseDataScope', res.data.courseDataScope)
-          localStorage.setItem('blocklyDataScope', res.data.blocklyDataScope)
 
           if (loginData.value.loginForm.rememberMe) {
             localStorage.setItem('userName', loginData.value.loginForm.username)

+ 0 - 3
src/views/QuickLogin.vue

@@ -73,9 +73,6 @@ const autoLogin = async () => {
       localStorage.setItem('tenantName', testAccount.tenantName)
       localStorage.setItem('password', testAccount.password)
       localStorage.setItem('rememberMe', 'true')
-      //课程权限
-      localStorage.setItem('courseDataScope', res.data.courseDataScope)
-      localStorage.setItem('blocklyDataScope', res.data.blocklyDataScope)
 
       ElMessage.success('信息校验成功')
       // 跳转到课程界面

+ 5 - 42
src/views/programming/Interface.vue

@@ -17,7 +17,7 @@
           <span>{{ course.courseName }}</span>
         </div>
 
-        <el-empty v-if="isDisabled"
+        <el-empty v-if="course.isDisabled"
                   image-size="500"
           description="您无权查看该课程!"
           :image="isDisabledImage"
@@ -167,8 +167,6 @@ const courseList = ref([])
 const course = ref({})
 // 菜单数据
 const menuItems = ref([])
-// 课程集合数据
-const videoPathMap = ref({})
 // 已观看课程ID列表
 const watchedCourseIds = ref([])
 // 试题弹框显示状态
@@ -183,10 +181,6 @@ const typeId = ref('')
 const courseId = ref('')
 // 课程排序
 const typeSort = ref('')
-// 课程权限
-const blocklyDataScope = ref([])
-// 测试账号禁用视频
-const isDisabled = ref(false)
 
 // 展平所有菜单项索引
 const flattenMenuItems = () => {
@@ -215,8 +209,6 @@ const playPreviousVideo = () => {
       courseId.value = course.value.id;
       // 更新标题
       boxIconTitle.value = course.value.courseName;
-      // 禁用视频检查
-      disableVideo(course.value.key);
     }
   }
 }
@@ -233,8 +225,6 @@ const playNextVideo = () => {
       courseId.value = course.value.id;
       // 更新标题
       boxIconTitle.value = course.value.courseName;
-      // 禁用视频检查
-      disableVideo(course.value.key);
     }
   }
 }
@@ -259,24 +249,6 @@ const handleVideoEnded = () => {
   // playNextVideo();
 }
 
-// 禁用视频
-const disableVideo = (index = course.value.key) => {
-
-  // 未配置课程权限,不禁用视频
-  if (!blocklyDataScope.value || blocklyDataScope.value.length === 0) {
-    return false
-  }
-
-  //配置了课程权限,且视频id不在权限列表中
-  isDisabled.value = !blocklyDataScope.value.some(item => Number(item) === videoPathMap.value[index].id)
-  if (isDisabled.value) {
-    Message().notifyWarning('您的账号并未开放此课程!', true)
-    return isDisabled.value;
-  }
-
-  return isDisabled.value;
-}
-
 // 处理视频时间更新事件
 const handleVideoTimeUpdate = ({ currentTime, progressPercentage, courseConfig: config }) => {
   if (config) {
@@ -324,20 +296,13 @@ const handleSubmitAnswer = ({ selectedOption }) => {
   questionDialogVisible.value = false
 }
 
-// 初始化课程数据范围
-const initCourseDataScope = () => {
-  const scope = localStorage.getItem("blocklyDataScope");
-  if (scope) {
-    blocklyDataScope.value = scope.split(",");
-  }
-};
-
 // 处理父组件传递的课程数据
 const handleParentCourseData = (courseData = props.courseData) => {
   if (!courseData) return false;
   // 设置返回按钮标题
   boxIconTitle.value = courseData.bcName;
   // 重新定义course接收传递过来的数据
+  console.log(courseData.isDisabled);
   course.value = {
     id: courseData.id,
     courseName: courseData.bcName,
@@ -356,11 +321,12 @@ const handleParentCourseData = (courseData = props.courseData) => {
     blocklyUserImage: courseData.blocklyUserImage,
     blocklyInfo: courseData.blocklyInfo,
     blocklySpecialBlocks: courseData.blocklySpecialBlocks ? courseData.blocklySpecialBlocks.split(',') : [],
+    isDisabled: courseData.isDisabled,
   };
   courseId.value = course.value.id;
   // 如果有配置,禁用视频检查
-  if (!disableVideo(course.value.key)) {
-    console.log('课程已加载:', course.value);
+  if (courseData.isDisabled) {
+    Message().notifyWarning('您的账号并未开放此课程!', true)
   }
   return true;
 };
@@ -399,9 +365,6 @@ const initWatchedCourseIds = () => {
 
 // 渲染 课程数据结构 以及 视频
 onMounted(async () => {
-  // 初始化课程数据范围
-  initCourseDataScope();
-
   // 初始化已观看课程ID
   initWatchedCourseIds();
 

+ 18 - 3
src/views/programming/ProgrammingCourset.vue

@@ -97,6 +97,7 @@ import Interface from './Interface.vue'
 // 星星图片
 import star02Image from '@/assets/programming/star02.png'
 import star01Image from '@/assets/programming/star01.png'
+import {Message} from "@/utils/message/Message.js";
 
 
 // 获取路由实例
@@ -107,6 +108,7 @@ const pageTitle = ref('')
 // 保存原始的课程ID和标题
 const originalCourseId = ref('')
 const originalCourseTitle = ref('')
+const isDisabled = ref(false) // 课程是否只读
 // 类型ID(从ProgrammingList页面传递过来)
 const typeId = ref('')
 // 控制视频界面显示
@@ -243,10 +245,12 @@ const fetchCourseData = () => {
   if (typeId.value) {
     getBlocklyByTypeId(typeId.value).then(res => {
       if (res && res.data && Array.isArray(res.data)) {
-        console.log(res);
-        
+
         // 保存原始API返回的数据
         resData.value = res.data;
+        resData.value.forEach(item => {
+          item.isDisabled = isDisabled.value
+        })
         // 创建图片映射,根据bcLabel显示对应图片
         const imageMap = {
           '1': explanation,
@@ -265,7 +269,8 @@ const fetchCourseData = () => {
             title: item.bcName,
             image: image,
             contentType: item.bcContentType,
-            progress: item.progress 
+            progress: item.progress, // 进度
+            isDisabled: isDisabled.value // 保存bcLabel用于图片映射
           })
         })
       }
@@ -286,6 +291,8 @@ onMounted(() => {
   // 保存原始的课程ID和标题,返回时使用
   originalCourseId.value = route.query.originalCourseId
   originalCourseTitle.value = route.query.originalCourseTitle
+  isDisabled.value = Boolean(isDisabled.value)
+
   // 获取到topicId后,调用函数获取课程列表
   fetchCourseData();
 })
@@ -294,6 +301,13 @@ onMounted(() => {
 const handleCourseItemClick = (item) => {
   // 如果在拖动过程中,则不触发点击事件
   if (hasMoved.value) return
+
+  // 如果是只读模式,不允许点击
+  if (isDisabled.value) {
+    Message().notifyWarning('您的账号并未开放此课程!', true)
+    return;
+  }
+
   if (item.contentType === 'video' || item.contentType === 'blockly') {
     showVideo.value = true
     // 查找并保存完整的课程数据
@@ -301,6 +315,7 @@ const handleCourseItemClick = (item) => {
     if (fullCourseData) {
       selectedCourseData.value = fullCourseData
       selectedCourseData.value.ztId = originalCourseId.value
+      selectedCourseData.value.isDisabled = isDisabled.value
     }
   }
 }

+ 8 - 44
src/views/programming/ProgrammingList.vue

@@ -42,11 +42,11 @@
                 v-for="(courseType, index) in specificCourses"
                 :key="index"
                 class="middle-inner-box"
-                @click="handleItemClick(courseType, index)"
+                @click="goToProgrammingList(courseType, index)"
               >
                 <div class="new-white-box"
                      :class="{ 'active': activeButton === index, 'disabled': courseType.isDisabled }"
-                     @click.stop="handleItemClick(courseType, index)"
+                     @click.stop="goToProgrammingList(courseType, index)"
                      :style="{ '--lock-image': `url(${lockImage})` }"
                      >
                     <!-- 列表封面图 -->
@@ -126,11 +126,6 @@ const pageTitle = ref('')
 // 课程类别ID
 const categoryId = ref('')
 
-// 课程权限
-const blocklyDataScope = ref([])
-// 测试账号禁用视频
-const isDisabled = ref(false)
-
 // 返回上一页
 const goBackIndex = () => {
   router.push('/programming')
@@ -148,9 +143,10 @@ const currentIndex = ref(0)
 const fetchTopicList = () => {
   if (categoryId.value) {
     getTypeByThemeId(categoryId.value).then(res => {
-      console.log(categoryId.value, res);
+
       // 更新课程数据,使用接口返回的数据
       if (res && res.data && Array.isArray(res.data)) {
+
         // 清空原有数据
         specificCourses.splice(0, specificCourses.length);
         res.data.forEach(item => {
@@ -160,7 +156,7 @@ const fetchTopicList = () => {
             title: item.ctType,
             bgImage: item.ctTypeImage,
             progress: item.progress,
-            isDisabled: disableBlockly(item.id)
+            isDisabled: item.dataReadonly
           });
         });
         // 更新圆形按钮数据
@@ -175,7 +171,6 @@ const fetchTopicList = () => {
   }
 }
 
-
 // 定义圆形按钮数据(根据课程数量动态生成)
 const circleButtons = reactive(specificCourses.map((_, index) => ({ text: String(index + 1) })))
 
@@ -260,14 +255,6 @@ const handleScroll = () => {
   }
 }
 
-
-
-// 处理项目点击事件
-const handleItemClick = (courseType, index) => {
-  // 调用原始的goToProgrammingList函数
-  goToProgrammingList(courseType, index)
-}
-
 // 上一页
 const prevSlide = () => {
   if (currentIndex.value > 0) {
@@ -304,10 +291,6 @@ const middleBox = ref(null)
 // 组件挂载时获取路由参数设置标题和课程ID
 onMounted(() => {
 
-  if (localStorage.getItem("blocklyDataScope")) {
-    blocklyDataScope.value = localStorage.getItem("blocklyDataScope").split(",");
-  }
-
   const title = route.query.courseTitle
   if (title) {
     pageTitle.value = title
@@ -321,8 +304,7 @@ onMounted(() => {
   }
 })
 
-
-// 跳转到课程详情页面
+// 处理项目点击事件-跳转到课程详情页面
 const goToProgrammingList = (courseType, index) => {
   // 检查是否禁用
   if (courseType.isDisabled) {
@@ -340,29 +322,11 @@ const goToProgrammingList = (courseType, index) => {
       courseIndex: index,
       typeId: courseType.id, // 当前类型的id,避免与课程ID混淆
       originalCourseId: categoryId.value, // 原始的课程ID
-      originalCourseTitle: pageTitle.value // 原始的课程标题
+      originalCourseTitle: pageTitle.value, // 原始的课程标题
+      isDisabled: courseType.isDisabled // 课程是否只读
     }
   })
 }
-
-// 禁用视频
-const disableBlockly = (blocklyId = categoryId.value) => {
-
-  // 未配置课程权限,不禁用视频
-  if (!blocklyDataScope.value || blocklyDataScope.value.length === 0) {
-    return false
-  }
-
-  //配置了课程权限,且视频id不在权限列表中
-  isDisabled.value = !blocklyDataScope.value.some(item => Number(item) === blocklyId)
-  // if (isDisabled.value) {
-  //   Message().notifyWarning('您的账号并未开放此课程!', true)
-  //   return isDisabled.value;
-  // }
-
-  return isDisabled.value;
-}
-
 </script>
 
 <style scoped lang="scss">