Переглянути джерело

1、课程大纲分类
2、取课程数据接口
3、整理全局变量

liyanbo 9 місяців тому
батько
коміт
56138b1468

+ 11 - 0
.env

@@ -0,0 +1,11 @@
+# 标题
+VITE_APP_TITLE=AI课程网
+
+# 请求路径
+VITE_BASE_URL='http://59.110.91.129/admin-api'
+#VITE_BASE_URL='http://192.168.110.8:8080/admin-api'
+
+# 默认账户密码
+VITE_APP_DEFAULT_LOGIN_TENANT = 博雅智算
+VITE_APP_DEFAULT_LOGIN_USERNAME = admin
+VITE_APP_DEFAULT_LOGIN_PASSWORD = admin123

+ 1 - 1
src/api/questions.js

@@ -23,7 +23,7 @@ export async function sendChatMessageStream (
     onError,
     onClose
 ) {
-  return fetchEventSource(`http://59.110.91.129:8080/admin-api/bjdxWeb/ai/dialogue-send-stream`, {
+  return fetchEventSource(import.meta.env.VITE_BASE_URL + `/bjdxWeb/ai/dialogue-send-stream`, {
     method: 'post',
     headers: {
       'Content-Type': 'application/json',

+ 0 - 1
src/components/HomePage.vue

@@ -127,7 +127,6 @@ const fetchCtTypes = async () => {
 
 // 添加 watch 监听 selectedGrade 的变化
 watch(selectedGrade, (newValue) => {
-  console.log('当前选中的年级是:', newValue);
   // 根据 id 切换高年级或低年级
   const selectedItem = classData.value.find(item => item.ctType === newValue);
   if (selectedItem) {

+ 1 - 0
src/router/index.js

@@ -4,6 +4,7 @@ import App from '../App.vue'
 
 const routes = [
 
+  { path: '/', component: () => import('../views/Login.vue') },
   { path: '/login', component: () => import('../views/Login.vue') },
   // 首页
   {

+ 4 - 9
src/utils/request.js

@@ -9,17 +9,15 @@ import router from '@/router/index.js'
 // process.env.NODE_ENV 用来获取我们当前的环境
 const isDev = process.env.NODE_ENV == 'development'
 
-// const BASE_URL = 'http://192.168.110.8:8080/admin-api'
+// 修正赋值逻辑,使用逻辑或运算符
+const BASE_URL = import.meta.env.VITE_BASE_URL || 'http://192.168.110.8:8080/admin-api'
 
 // 创建一个请求对象
 const request = axios.create({
   // `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
   // 它可以通过设置一个 `baseURL` 便于为 axios 实例的方法传递相对 URL
   // baseURL: isDev ? 'http://121.89.205.189:3000/admin' : 'http://121.89.205.189:3000/admin',
-  //  baseURL: 'http://59.110.91.129:3000',
-  // baseURL: 'http://192.168.110.8:8080/admin-api',
-  baseURL: 'http://59.110.91.129/admin-api',
-  // baseURL: 'http://127.0.0.1:8080/admin-api',/
+  baseURL: BASE_URL,
 
   // baseURL: '/api',
   // `timeout` 指定请求超时的毫秒数。
@@ -86,11 +84,8 @@ export default function ajax (config) {
         }
         return request.post(url, obj, { headers })
       }
-      const obj = new FormData()
-      obj.append('Tenant-Id', headers['Tenant-Id'])
-      return request.post(url, obj, { headers })
       // 3. json 数据
-      // return request.post(url, data)
+      return request.post(url, data, {headers})
     case 'PUT':
       // 通常用来修改数据用的 --- 数据更新
       return request.put(url, data)

+ 15 - 3
src/views/AIDevelop.vue

@@ -256,6 +256,7 @@ import video12 from '@/assets/02video/12video.mp4'
 import video13 from '@/assets/02video/13video.mp4'
 import video14 from '@/assets/02video/14video.mp4'
 import video15 from '@/assets/02video/15video.mp4'
+import {ClassType} from "@/api/class.js";
 
 const router = useRouter() // 获取当前路由对象
 // 搜索框
@@ -290,6 +291,8 @@ const videoMap = {
 // 定义视频源
 const videoSrc = ref(video1)
 
+const courseList = ref([])
+
 
 // // 获取课程列表
 // ClassType().then(res=>{
@@ -302,8 +305,18 @@ const goBack = () => {
 }
 // 渲染页面标题
 const boxIconTitle = ref('')
-onMounted(() => {
-  const title = router.currentRoute.value.query.title
+onMounted(async () => {
+  const typeId = router.currentRoute.value.query.typeId
+  console.log(typeId,"----")
+  if (typeId) {
+    //取课程数据
+    // await ClassType(typeId).then(res => {
+    //   courseList.value = res.data
+    //   console.log("课程数据:",courseList.value)
+    // })
+
+  }
+  const title = router.currentRoute.value.query.typeName
   if (title) {
     boxIconTitle.value = String(title)
   }
@@ -608,7 +621,6 @@ const handleCloseQuestionDialog = () => {
 // 提交答案
 const handleSubmitAnswer = () => {
   // 这里可以添加答案验证逻辑
-  console.log('用户选择的答案是:', selectedOption.value)
   questionDialogVisible.value = false
   // 继续播放视频
   videoRef.value.play()

+ 33 - 27
src/views/AIGeneralCourse.vue

@@ -87,19 +87,20 @@
       <div class="box-2">
         <div
           class="small-box"
-          v-for="(image, index) in courseImages"
+          v-for="(outlineData, index) in classOutlineData"
           :key="index"
-          @click="goToAIExperience(index + 1)"
+          @click="goToAIExperience(outlineData)"
         >
           <div
             class="nested-box"
             :style="{
-              backgroundImage: `url(${image})`,
+              backgroundImage: `url(${outlineData.ctTypeImage})`,
               backgroundSize: 'cover'
             }"
           ></div>
           <div class="additional-text">
-            0{{ index + 1 }} {{ getCourseTitle(index + 1) }}
+<!--            0{{ index + 1 }} {{ getCourseTitle(index + 1) }}-->
+            ({{outlineData.ctTypeSort}}) {{outlineData.ctType}}
           </div>
         </div>
       </div>
@@ -143,7 +144,6 @@ const fetchCtTypes = async () => {
         selectedGrade.value = classData.value[0].ctType
       }
     }
-    console.log(classData.value, selectedGrade.value)
   } catch (error) {
     console.error('获取 ctType 数据失败:', error)
   }
@@ -168,7 +168,6 @@ watch(selectedGrade, newValue => {
        if (res.code === 0) {
         classOutlineData.value = res.data
       }
-      console.log(classOutlineData.value)
     })
   }
 })
@@ -215,34 +214,41 @@ const goBack = () => {
   router.go(-1) // 返回上一页
 }
 // 添加跳转课程页面的函数
-const goToAIExperience = index => {
-  const routes = [
-    '/ai-initial-experience', // 跳转AI初体验
-    '/ai-develop' // 跳转AI发展历程
-    // '/ai-development-history',
-  ]
-  // 跳转页面渲染title
-  const title = `0${index} ${getCourseTitle(index)}` // 定义 title 变量
-  if (index >= 1 && index <= routes.length) {
+const goToAIExperience = outlineData => {
+  // const routes = [
+  //   '/ai-initial-experience', // 跳转AI初体验
+  //   '/ai-develop' // 跳转AI发展历程
+  //   // '/ai-development-history',
+  // ]
+  // // 跳转页面渲染title
+  // const title = `0${index} ${getCourseTitle(index)}` // 定义 title 变量
+  // if (index >= 1 && index <= routes.length) {
+  //   router.push({
+  //     path: routes[index - 1],
+  //     query: { typeId: title, title: title }
+  //   })
+  // }
+
+  if (outlineData.ctTypeSort === 2) {
     router.push({
-      path: routes[index - 1],
-      query: { title: title }
+      path: '/ai-develop', // 跳转AI初体验
+      query: { typeId: outlineData.id, typeName: outlineData.ctType }
     })
   }
 }
 
 
 // 添加图片路径数组
-const courseImages = ref([
-  './src/assets/images/one.png',
-  './src/assets/images/two.png',
-  './src/assets/images/three.png',
-  './src/assets/images/four.png',
-  './src/assets/images/five.png',
-  './src/assets/images/six.png',
-  './src/assets/images/seven.png',
-  './src/assets/images/eight.png'
-])
+// const courseImages = ref([
+//   './src/assets/images/one.png',
+//   './src/assets/images/two.png',
+//   './src/assets/images/three.png',
+//   './src/assets/images/four.png',
+//   './src/assets/images/five.png',
+//   './src/assets/images/six.png',
+//   './src/assets/images/seven.png',
+//   './src/assets/images/eight.png'
+// ])
 // 首页点击渲染后的页面title
 const pageTitle = ref('')
 onMounted(() => {

+ 0 - 1
src/views/AIInitialExperience.vue

@@ -557,7 +557,6 @@ const handleCloseQuestionDialog = () => {
 // 提交答案
 const handleSubmitAnswer = () => {
   // 这里可以添加答案验证逻辑
-  console.log('用户选择的答案是:', selectedOption.value)
   questionDialogVisible.value = false
   // 继续播放视频
   videoRef.value.play()

+ 0 - 2
src/views/AIPainting.vue

@@ -307,9 +307,7 @@ const refreshWatchImages = async () => {
   if (imageIds.length === 0) {
     return
   }
-  console.log("轮询生成中的 image 列表",imageIds,imageIds.join(','))
   const list = await PaintingGetMys(imageIds)
-  console.log("轮询生成中的 image 列表",list)
   const newWatchImages = {}
   list.data.forEach((image) => {
     if (image.status === AiImageStatusEnum.IN_PROGRESS) {

+ 15 - 21
src/views/Login.vue

@@ -63,12 +63,10 @@ const router = useRouter()
 const loginFormRef = ref(null)
 
 const loginData = ref({
-  tenantEnable: true,
   loginForm: {
-    tenantName: '博雅智算',
-    username: 'admin',
-    password: 'admin123',
-    captchaVerification: '',
+    tenantName: import.meta.env.VITE_APP_DEFAULT_LOGIN_TENANT || '',
+    username: import.meta.env.VITE_APP_DEFAULT_LOGIN_USERNAME || '',
+    password: import.meta.env.VITE_APP_DEFAULT_LOGIN_PASSWORD || '',
     rememberMe: true // 默认记录我。如果不需要,可手动修改
   }
 })
@@ -88,22 +86,19 @@ const rules = {
 
 // 获取租户 ID
 const getTenantId = async () => {
-  if (loginData.value.tenantEnable === true) {
-    try {
-      const res = await getTenantIdByName(loginData.value.loginForm.tenantName)
-      console.log(res);
-      if (res && res.data) {
-        //记录租户id
-        tenantId.value = res.data
-      } else {
-        ElMessage.error('获取租户 ID 失败,请检查租户名称')
-        return
-      }
-    } catch (error) {
-      ElMessage.error('获取租户 ID 出错,请重试')
-      console.error('获取租户 ID 错误:', error)
+  try {
+    const res = await getTenantIdByName(loginData.value.loginForm.tenantName)
+    if (res && res.data) {
+      //记录租户id
+      tenantId.value = res.data
+    } else {
+      ElMessage.error('获取租户 ID 失败,请检查租户名称')
       return
     }
+  } catch (error) {
+    ElMessage.error('获取租户 ID 出错,请重试')
+    console.error('获取租户 ID 错误:', error)
+    return
   }
 }
 // 登录
@@ -115,7 +110,6 @@ const handleLogin = async params => {
       try {
         await getTenantId()
         const loginDataLoginForm = { ...loginData.value.loginForm }
-        loginDataLoginForm.captchaVerification = params?.captchaVerification
         // 构建包含 headers 的请求参数
         const res = await login(
           {
@@ -130,7 +124,7 @@ const handleLogin = async params => {
         //【补充】校验登录状态
         //成功-失败-提示文字
         // 校验登录状态,返回数据中 code 为 200 表示成功
-        if (res.code === 200) {
+        if (res.code === 0) {
           ElMessage.success('登录成功')
           isLoggedIn.value = true
           // 存储登录状态

+ 27 - 21
vite.config.js

@@ -1,4 +1,4 @@
-import { defineConfig } from 'vite'
+import { defineConfig, loadEnv } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import path from 'path'
 
@@ -6,26 +6,32 @@ import path from 'path'
 import legacy from '@vitejs/plugin-legacy'
 
 // https://vite.dev/config/
-export default defineConfig({
-  plugins: [
-    legacy({
-      targets: ['defaults', 'not IE 11']
-    }),
-    vue(),
-  ],
-  resolve: {
-    // 路径别名配置
-    alias: {
-      '@': path.resolve(__dirname, './src')
-    }
-  },
-  base: './',
-  server: {
-    host: '0.0.0.0',
-    proxy: {
-      '/admin-api': {
-        target: 'http://59.110.91.129',
-        changeOrigin: true
+export default defineConfig(({ mode }) => {
+  // 加载对应模式的环境变量
+  const env = loadEnv(mode, process.cwd())
+
+  return {
+    plugins: [
+      legacy({
+        targets: ['defaults', 'not IE 11']
+      }),
+      vue(),
+    ],
+    resolve: {
+      // 路径别名配置
+      alias: {
+        '@': path.resolve(__dirname, './src')
+      }
+    },
+    base: './',
+    server: {
+      host: '0.0.0.0',
+      proxy: {
+        '/admin-api': {
+          // 使用加载的环境变量
+          target: env.VITE_BASE_URL,
+          changeOrigin: true
+        }
       }
     }
   }