Parcourir la source

lcb-cd

master
fzzj il y a 9 mois
Parent
révision
dc8ddb6737

BIN
RuoYi-App/App.vue Voir le fichier


+ 10
- 0
RuoYi-App/api/novel.js Voir le fichier

@@ -0,0 +1,10 @@
1
+// src/api/novel.js
2
+import request from '@/utils/request'
3
+
4
+export function searchNovels(keyword) {
5
+  return request({
6
+    url: '/api/novel/list',
7
+    method: 'get',
8
+    params: { keyword }
9
+  })
10
+}

+ 60
- 0
RuoYi-App/pages/search/index.vue Voir le fichier

@@ -0,0 +1,60 @@
1
+<!-- src/views/search/index.vue -->
2
+<template>
3
+  <div class="app-container">
4
+    <el-input
5
+      v-model="keyword"
6
+      placeholder="请输入搜索内容"
7
+      clearable
8
+      @keyup.enter.native="handleSearch"
9
+    >
10
+      <el-button
11
+        slot="append"
12
+        icon="el-icon-search"
13
+        @click="handleSearch"
14
+      />
15
+    </el-input>
16
+    
17
+    <!-- 搜索结果展示 -->
18
+    <div v-if="results.length > 0" class="search-results">
19
+      <el-card v-for="item in results" :key="item.id">
20
+        <h3>{{ item.title }}</h3>
21
+        <p>{{ item.description }}</p>
22
+      </el-card>
23
+    </div>
24
+  </div>
25
+</template>
26
+
27
+<script>
28
+import { searchNovels } from '@/api/novel'
29
+
30
+export default {
31
+  name: 'Search',
32
+  data() {
33
+    return {
34
+      keyword: '',
35
+      results: []
36
+    }
37
+  },
38
+  methods: {
39
+    handleSearch() {
40
+      if (!this.keyword.trim()) {
41
+        this.$message.warning('请输入搜索关键词')
42
+        return
43
+      }
44
+      
45
+      searchNovels(this.keyword).then(response => {
46
+        this.results = response.data
47
+      })
48
+    }
49
+  }
50
+}
51
+</script>
52
+
53
+<style scoped>
54
+.app-container {
55
+  padding: 20px;
56
+}
57
+.search-results {
58
+  margin-top: 20px;
59
+}
60
+</style>

+ 52
- 0
RuoYi-App/router/index.js Voir le fichier

@@ -0,0 +1,52 @@
1
+// src/router/index.js
2
+import Vue from 'vue'
3
+import Router from 'vue-router'
4
+import Layout from '@/layout'
5
+
6
+Vue.use(Router)
7
+
8
+export default new Router({
9
+  mode: 'history',
10
+  base: process.env.BASE_URL,
11
+  routes: [
12
+    {
13
+      path: '/',
14
+      component: Layout,
15
+      redirect: '/dashboard',
16
+      children: [
17
+        {
18
+          path: 'dashboard',
19
+          component: () => import('@/views/dashboard/index'),
20
+          name: 'Dashboard',
21
+          meta: { title: '首页', icon: 'dashboard' }
22
+        }
23
+      ]
24
+    },
25
+    // 添加搜索路由
26
+    {
27
+      path: '/search',
28
+      component: Layout,
29
+      hidden: true,
30
+      children: [
31
+        {
32
+          path: 'index',
33
+          component: () => import('@/views/search/index'),
34
+          name: 'Search',
35
+          meta: { title: '搜索' }
36
+        }
37
+      ]
38
+    },
39
+    // 确保所有页面都有正确的路由配置
40
+    {
41
+      path: '/login',
42
+      component: () => import('@/views/login/index'),
43
+      hidden: true
44
+    }
45
+  ]
46
+})
47
+
48
+// 在路由配置中添加懒加载
49
+{
50
+  path: '/novel/list',
51
+  component: () => import(/* webpackChunkName: "novel-list" */ '@/views/novel/list.vue')
52
+}

+ 5
- 0
RuoYi-App/store/modules/user.js Voir le fichier

@@ -55,6 +55,11 @@ const user = {
55 55
         login(username, password, code, uuid).then(res => {
56 56
           setToken(res.token)
57 57
           commit('SET_TOKEN', res.token)
58
+        commit('SET_ROLES', data.roles)
59
+        commit('SET_PERMISSIONS', data.permissions)
60
+        commit('SET_NAME', data.userName)
61
+        commit('SET_AVATAR', data.avatar)
62
+        commit('SET_MENUS', data.menus) // 确保菜单数据设置
58 63
           resolve()
59 64
         }).catch(error => {
60 65
           reject(error)

+ 46
- 2
RuoYi-App/utils/permission.js Voir le fichier

@@ -1,10 +1,25 @@
1 1
 import store from '@/store'
2
-
2
+import router from '@/router'
3 3
 /**
4 4
  * 字符权限校验
5 5
  * @param {Array} value 校验值
6 6
  * @returns {Boolean}
7 7
  */
8
+export function checkPermission(path) {
9
+  // 确保路径以斜杠开头
10
+  if (!path.startsWith('/')) path = '/' + path
11
+  
12
+  // 检查路由是否存在
13
+  const route = router.resolve(path)
14
+  if (!route || !route.route) {
15
+    console.error(`路由不存在: ${path}`)
16
+    return false
17
+  }
18
+  
19
+  // 添加权限验证逻辑
20
+  // ...
21
+  return true
22
+}
8 23
 export function checkPermi(value) {
9 24
   if (value && value instanceof Array && value.length > 0) {
10 25
     const permissions = store.getters && store.getters.permissions
@@ -48,4 +63,33 @@ export function checkRole(value) {
48 63
     console.error(`need roles! Like checkRole="['admin','editor']"`)
49 64
     return false
50 65
   }
51
-}
66
+}
67
+
68
+// src/permission.js
69
+router.beforeEach(async(to, from, next) => {
70
+  // 确保登录页面可访问
71
+  if (to.path === '/login') {
72
+    next()
73
+    return
74
+  }
75
+  
76
+  // 检查 token
77
+  const token = store.getters.token
78
+  if (!token) {
79
+    next(`/login?redirect=${to.path}`)
80
+    return
81
+  }
82
+  
83
+  // 获取用户信息
84
+  if (!store.getters.name) {
85
+    try {
86
+      await store.dispatch('user/getInfo')
87
+      next()
88
+    } catch (error) {
89
+      await store.dispatch('user/resetToken')
90
+      next(`/login?redirect=${to.path}`)
91
+    }
92
+  } else {
93
+    next()
94
+  }
95
+})

Chargement…
Annuler
Enregistrer