瀏覽代碼

权限调整

CzRger 2 月之前
父節點
當前提交
33bfa168f8
共有 5 個文件被更改,包括 56 次插入45 次删除
  1. 1 0
      src/api/interceptors.ts
  2. 32 22
      src/router/index.ts
  3. 2 2
      src/stores/modules/app.ts
  4. 7 5
      src/views/global/login/index.vue
  5. 14 16
      src/views/manage/knowledge/index.vue

+ 1 - 0
src/api/interceptors.ts

@@ -71,6 +71,7 @@ export class Interceptors {
           title: res.data.message,
           message: res.data.data,
           type: 'error',
+          duration: 0,
         })
         break
       default:

+ 32 - 22
src/router/index.ts

@@ -41,31 +41,41 @@ const router = createRouter({
 })
 const initUser = (next, isLogin = false) => {
   const AppStore = useAppStore()
-  if (hasLogin) {
-    if (AppStore.userInfo) {
-      isLogin ? next({ name: 'root' }) : next()
-      AppStore.loadingEnd()
-    } else {
-      if (localStorage.getItem((import.meta as any).env.VITE_TOKEN)) {
-        AppStore.initUserInfo()
-          .then(() => {
-            isLogin ? next({ name: 'root' }) : next()
-          })
-          .catch((e) => {
-            localStorage.removeItem((import.meta as any).env.VITE_TOKEN)
-            next({ name: 'login' })
-          })
-          .finally(() => {
-            AppStore.loadingEnd()
-          })
-      } else {
-        next({ name: 'login' })
+  AppStore.loadingStart()
+  if (
+    isLogin &&
+    !AppStore.userInfo &&
+    !localStorage.getItem((import.meta as any).env.VITE_TOKEN)
+  ) {
+    next()
+    AppStore.loadingEnd()
+  } else {
+    if (hasLogin) {
+      if (AppStore.userInfo) {
+        isLogin ? next({ name: 'root' }) : next()
         AppStore.loadingEnd()
+      } else {
+        if (localStorage.getItem((import.meta as any).env.VITE_TOKEN)) {
+          AppStore.initUserInfo()
+            .then(() => {
+              isLogin ? next({ name: 'root' }) : next()
+            })
+            .catch((e) => {
+              localStorage.removeItem((import.meta as any).env.VITE_TOKEN)
+              next({ name: 'login' })
+            })
+            .finally(() => {
+              AppStore.loadingEnd()
+            })
+        } else {
+          next({ name: 'login' })
+          AppStore.loadingEnd()
+        }
       }
+    } else {
+      next()
+      AppStore.loadingEnd()
     }
-  } else {
-    next()
-    AppStore.loadingEnd()
   }
 }
 router.beforeEach((to, from, next) => {

+ 2 - 2
src/stores/modules/app.ts

@@ -10,8 +10,8 @@ export const useAppStore = defineStore('app', {
     initUserInfo() {
       return new Promise((resolve, reject) => {
         userInfo()
-          .then((res: any) => {
-            this.userInfo = res.data
+          .then(({ data }: any) => {
+            this.userInfo = data
             resolve(this.userInfo)
           })
           .catch((e) => {

+ 7 - 5
src/views/global/login/index.vue

@@ -73,7 +73,9 @@ import { User, Lock, Clock } from '@element-plus/icons-vue'
 import { ElMessage } from 'element-plus'
 import { loginCaptcha, loginSubmit } from '@/api/modules/global/login'
 import CzrForm from '@/components/czr-ui/CzrForm.vue'
+import { useRouter } from 'vue-router'
 
+const router = useRouter()
 const emit = defineEmits([])
 const props = defineProps({})
 const { proxy }: any = getCurrentInstance()
@@ -96,14 +98,14 @@ const onLogin = () => {
       .then(() => {
         state.loading = true
         loginSubmit(state.form)
-          .then((res: any) => {
+          .then(({ data }: any) => {
             ElMessage.success('登录成功!')
-            localStorage.setItem((import.meta as any).env.VITE_TOKEN, res.data)
-            window.location.replace(`/${(import.meta as any).env.VITE_BASE}/`)
+            localStorage.setItem((import.meta as any).env.VITE_TOKEN, data)
+            router.replace({ name: 'root' })
             state.loading = false
           })
-          .catch((e) => {
-            ElMessage.error(e.message)
+          .catch(({ message }: any) => {
+            ElMessage.error(message)
             state.loading = false
           })
       })

+ 14 - 16
src/views/manage/knowledge/index.vue

@@ -192,6 +192,7 @@ const { proxy }: any = getCurrentInstance()
 const state: any = reactive({
   text: '',
   query: {
+    init: false,
     loading: false,
     page: {
       pageNum: 1,
@@ -221,7 +222,11 @@ watch(
 watch(
   () => state.query.form,
   (n) => {
-    onSearch()
+    console.log(state.query.init)
+    console.log(3)
+    if (state.query.init) {
+      onSearch()
+    }
   },
   { deep: true },
 )
@@ -231,8 +236,9 @@ const onPage = (pageNum, pageSize) => {
     pageSize: pageSize,
   }
   const params = {
-    pageNum: state.query.page.pageNum,
-    pageSize: state.query.page.pageSize,
+    tenantId: 0,
+    page: state.query.page.pageNum,
+    size: state.query.page.pageSize,
   }
   //  添加表单参数
   for (const [k, v] of Object.entries(state.query.formReal)) {
@@ -260,18 +266,11 @@ const onPage = (pageNum, pageSize) => {
     state.query.result.data = arr
     state.query.loading = false
   }, 1000)
-  // state.query.loading = true
-  // listRuleLogisticsDataSubscribeInfo(params).then(res => {
-  //   if (res.code == 200) {
-  //     state.query.result.total = res.total
-  //     state.query.result.data = res.rows
-  //     state.query.loading = false
-  //   } else {
-  //     ElMessage.error(res.msg)
-  //   }
-  // }).catch(() => {
-  //   state.query.loading = false
-  // })
+  datasetsGetAllByPage(params).then(({ data }) => {})
+
+  setTimeout(() => {
+    state.query.loading = true
+  }, 100)
 }
 const onSearch = () => {
   state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
@@ -316,7 +315,6 @@ const initDictionary = () => {
   DictionaryStore.initKnowledgeGroups()
 }
 onMounted(() => {
-  datasetsGetAllByPage()
   initDictionary()
   onReset()
 })