Ver código fonte

代码格式化

Kevin Jiang 2 anos atrás
pai
commit
c970058bac

+ 28 - 28
src/services/httpClient.ts

@@ -1,49 +1,49 @@
-import {message} from "ant-design-vue";
-import axios, {AxiosError, type AxiosRequestConfig} from "axios";
-import {routeToLogin} from "@/router";
-import type {MessageType} from "ant-design-vue/lib/message";
+import { message } from "ant-design-vue";
+import axios, { AxiosError, type AxiosRequestConfig } from "axios";
+import { routeToLogin } from "@/router";
+import type { MessageType } from "ant-design-vue/lib/message";
 
-const urlPrefix = "http://127.0.0.1:8088";
+const urlPrefix = "/";
 
 const httpClient = axios.create({
-    baseURL: urlPrefix,
-    timeout: 60000,
+  baseURL: urlPrefix,
+  timeout: 60000,
 });
 
 
 // 添加请求拦截器
 httpClient.interceptors.request.use(function (config: AxiosRequestConfig) {
-    // 在发送请求之前做些什么
-    const token = localStorage.getItem('token');
-    if (token && config.headers) {
-        config.headers.Authorization = token;
-    }
-    return config;
+  // 在发送请求之前做些什么
+  const token = localStorage.getItem('token');
+  if (token && config.headers) {
+    config.headers.Authorization = token;
+  }
+  return config;
 }, function (error) {
-    // 对请求错误做些什么
-    return Promise.reject(error);
+  // 对请求错误做些什么
+  return Promise.reject(error);
 });
 
 let errorMsgHandler: MessageType | null = null;
 
 // 添加响应拦截器
 httpClient.interceptors.response.use(function (response) {
-    // 对响应数据做点什么
-    return response;
+  // 对响应数据做点什么
+  return response;
 }, function (error: AxiosError) {
-    if (error.response?.status == 404) {
-        message.error("请求参数错误!");
-    } else if (error.response?.status == 401) {
-        routeToLogin();
-    } else if (error) {
-        if (errorMsgHandler != null) {
-            errorMsgHandler()
-        }
-        errorMsgHandler = message.error(error.message);
-        // routeToLogin();
+  if (error.response?.status == 404) {
+    message.error("请求参数错误!");
+  } else if (error.response?.status == 401) {
+    routeToLogin();
+  } else if (error) {
+    if (errorMsgHandler != null) {
+      errorMsgHandler()
     }
+    errorMsgHandler = message.error(error.message);
+    // routeToLogin();
+  }
 
-    return Promise.reject(error);
+  return Promise.reject(error);
 });
 
 export default httpClient;

+ 39 - 39
src/services/user.service.ts

@@ -1,25 +1,25 @@
-import type {SearchHistoryRecord, UserLoginRequest, CurrentUser} from "@/types/user.types";
-import type {Page} from "@/types/pagination.types"
-import type {Response} from "@/types/response.types";
-import type {AxiosResponse} from "axios";
+import type { SearchHistoryRecord, UserLoginRequest, CurrentUser } from "@/types/user.types";
+import type { Page } from "@/types/pagination.types"
+import type { Response } from "@/types/response.types";
+import type { AxiosResponse } from "axios";
 import httpClient from "./httpClient";
 
 const urlPrefix = "/gw/user";
 
 function _url(path: string): string {
-    return `${urlPrefix}${path}`;
+  return `${urlPrefix}${path}`;
 }
 
 function login(param: UserLoginRequest): Promise<AxiosResponse<Response<CurrentUser>>> {
-    return httpClient.post<Response<CurrentUser>>(_url("/login"), param);
+  return httpClient.post<Response<CurrentUser>>(_url("/login"), param);
 }
 
 async function checkLogin(): Promise<boolean> {
-    const resp = await httpClient.get("/gw/user/user/checkLogin");
-    if (resp) {
-        return true;
-    }
-    return false;
+  const resp = await httpClient.get("/gw/user/user/checkLogin");
+  if (resp) {
+    return true;
+  }
+  return false;
 }
 
 /**
@@ -30,51 +30,51 @@ async function checkLogin(): Promise<boolean> {
  * @returns Promise
  */
 export function fetchHistory(currentUser: string, page: number, size: number, dateNum: number) {
-    const url = _url("/searchHistory/getMySearchHistory");
-    const headers = {currentUser};
-    const params = {page, size, dateNum};
-    return httpClient.get<Response<Page<SearchHistoryRecord>>>(url, {params, headers});
+  const url = _url("/searchHistory/getMySearchHistory");
+  const headers = { currentUser };
+  const params = { page, size, dateNum };
+  return httpClient.get<Response<Page<SearchHistoryRecord>>>(url, { params, headers });
 }
 
 export function delHistory(currentUser: string, id: number) {
-    const url = _url("/searchHistory/delById/" + id);
-    const headers = {currentUser};
-    return httpClient.delete<Response<Object>>(url, {headers});
+  const url = _url("/searchHistory/delById/" + id);
+  const headers = { currentUser };
+  return httpClient.delete<Response<Object>>(url, { headers });
 }
 
 export function delAllHistory(currentUser: string) {
-    const url = _url("/searchHistory/delAllByUserId");
-    const headers = {currentUser};
-    return httpClient.delete<Response<Object>>(url, {headers});
+  const url = _url("/searchHistory/delAllByUserId");
+  const headers = { currentUser };
+  return httpClient.delete<Response<Object>>(url, { headers });
 }
 
 export function fetchBrowsing(currentUser: string, page: number, size: number, dateNum: number) {
-    const url = _url("/browsing/getPage");
-    const headers = {currentUser};
-    const params = {page, size, dateNum};
-    return httpClient.get<Response<Page<SearchHistoryRecord>>>(url, {params, headers});
+  const url = _url("/browsing/getPage");
+  const headers = { currentUser };
+  const params = { page, size, dateNum };
+  return httpClient.get<Response<Page<SearchHistoryRecord>>>(url, { params, headers });
 }
 
 export function delBrowsingById(currentUser: string, id: number) {
-    const url = _url("/browsing/delById/" + id);
-    const headers = {currentUser};
-    return httpClient.delete<Response<Object>>(url, {headers});
+  const url = _url("/browsing/delById/" + id);
+  const headers = { currentUser };
+  return httpClient.delete<Response<Object>>(url, { headers });
 }
 
 export function delAllBrowsing(currentUser: string) {
-    const url = _url("/browsing/delByUserId");
-    const headers = {currentUser};
-    return httpClient.delete<Response<Object>>(url, {headers});
+  const url = _url("/browsing/delByUserId");
+  const headers = { currentUser };
+  return httpClient.delete<Response<Object>>(url, { headers });
 }
 
 export default {
-    login,
-    checkLogin,
-    fetchHistory,
-    delHistory,
-    delAllHistory,
+  login,
+  checkLogin,
+  fetchHistory,
+  delHistory,
+  delAllHistory,
 
-    fetchBrowsing,
-    delBrowsingById,
-    delAllBrowsing
+  fetchBrowsing,
+  delBrowsingById,
+  delAllBrowsing
 }

+ 83 - 85
src/views/history/DocumentHistoryView.vue

@@ -1,93 +1,91 @@
 <script setup lang="ts">
-    import {onMounted, Ref, ref} from "vue";
-    import HistoryList from "./components/HistoryList.vue";
-    import HistoryToolbar from "./components/HistoryToolbar.vue";
-    import {SearchHistoryRecord} from "@/types/user.types";
-    import * as userService from "@/services/user.service";
-    import {delAllBrowsing, delAllHistory, delBrowsingById, fetchBrowsing} from "@/services/user.service";
-    import {useAuthStore} from "@/stores/auth.store";
-
-    const authStore = useAuthStore();
-
-    const records: Ref<SearchHistoryRecord[]> = ref([]);
-
-    const currentPage = ref(1);
-
-    const page = ref(1);
-
-    const total = ref(0);
-
-    const filterValue = ref("3");
-
-    function handleDelete(id: number) {
-        const currentUser = JSON.stringify(authStore.currentUser)
-        userService.delBrowsingById(currentUser, id).then((res) => {
-            fetchBrowsing()
-        })
-    }
-
-    function onfilterChange(value) {
-        filterValue.value = value
-        fetchBrowsing()
-    }
-
-    function ondeleteAll() {
-        delAllHistory
-        const currentUser = JSON.stringify(authStore.currentUser)
-        userService.delAllBrowsing(currentUser).then((res) => {
-            fetchBrowsing()
-        })
-    }
-
-    function fetchBrowsing() {
-        const currentUser = JSON.stringify(authStore.currentUser)
-        userService.fetchBrowsing(currentUser, page.value, 10, Number(filterValue.value)).then((resp) => {
-            const respData = resp.data.data;
-            records.value = respData.records;
-            total.value = respData.total;
-        })
-    }
-
-    function onNext() {
-        page.value = currentPage.value + 1;
-        fetchBrowsing();
-    }
-
-    function onPrev() {
-        page.value = currentPage.value - 1;
-        fetchBrowsing();
-    }
-
-    onMounted(() => {
-        fetchBrowsing();
-    });
+import { onMounted, type Ref, ref } from "vue";
+import HistoryList from "./components/HistoryList.vue";
+import HistoryToolbar from "./components/HistoryToolbar.vue";
+import type { SearchHistoryRecord } from "@/types/user.types";
+import * as userService from "@/services/user.service";
+import { useAuthStore } from "@/stores/auth.store";
+
+const authStore = useAuthStore();
+
+const records: Ref<SearchHistoryRecord[]> = ref([]);
+
+const currentPage = ref(1);
+
+const page = ref(1);
+
+const total = ref(0);
+
+const filterValue = ref("3");
+
+function fetchBrowsing() {
+  const currentUser = JSON.stringify(authStore.currentUser)
+  userService.fetchBrowsing(currentUser, page.value, 10, Number(filterValue.value)).then((resp) => {
+    const respData = resp.data.data;
+    records.value = respData.records;
+    total.value = respData.total;
+  })
+}
+
+function handleDelete(id: number) {
+  const currentUser = JSON.stringify(authStore.currentUser)
+  userService.delBrowsingById(currentUser, id).then(() => {
+    fetchBrowsing()
+  })
+}
+
+function onfilterChange(value: string) {
+  filterValue.value = value
+  fetchBrowsing()
+}
+
+function ondeleteAll() {
+  const currentUser = JSON.stringify(authStore.currentUser)
+  userService.delAllBrowsing(currentUser).then(() => {
+    fetchBrowsing()
+  })
+}
+
+function onNext() {
+  page.value = currentPage.value + 1;
+  fetchBrowsing();
+}
+
+function onPrev() {
+  page.value = currentPage.value - 1;
+  fetchBrowsing();
+}
+
+onMounted(() => {
+  fetchBrowsing();
+});
 </script>
 
 <template>
-    <HistoryToolbar @filterChange="onfilterChange" @deleteAll="ondeleteAll"/>
-    <HistoryList :data="records" @delete="handleDelete" class="history-list-wrap"/>
-    <div class="pagination">
-        <a-pagination v-model:current="currentPage" simple :total="total">
-            <template #itemRender="{ type, originalElement }">
-                <a-button v-if="type === 'prev'" size="small" @click="onPrev()"> 上一页</a-button>
-                <a-button v-else-if="type === 'next'" size="small" @click="onNext()">下一页</a-button>
-                <component :is="originalElement" v-else></component>
-            </template>
-        </a-pagination>
-    </div>
+  <HistoryToolbar @filterChange="onfilterChange" @deleteAll="ondeleteAll" />
+  <HistoryList :data="records" @delete="handleDelete" class="history-list-wrap" />
+  <div class="pagination">
+    <a-pagination v-model:current="currentPage" simple :total="total">
+      <template #itemRender="{ type, originalElement }">
+        <a-button v-if="type === 'prev'" size="small" @click="onPrev()"> 上一页</a-button>
+        <a-button v-else-if="type === 'next'" size="small" @click="onNext()">下一页</a-button>
+        <component :is="originalElement" v-else></component>
+      </template>
+    </a-pagination>
+  </div>
 </template>
 
 <style scoped lang="scss">
-    .history-list-wrap {
-        margin-top: 16px;
-    }
-
-    .pagination {
-        margin-top: 16px;
-        text-align: right;
-
-        .ant-pagination {
-            height: 28px;
-        }
-    }
+.history-list-wrap {
+  margin-top: 16px;
+}
+
+.pagination {
+  margin-top: 16px;
+  text-align: right;
+
+  .ant-pagination {
+    height: 28px;
+  }
+}
 </style>

+ 83 - 85
src/views/history/SearchHistoryView.vue

@@ -1,93 +1,91 @@
 <script setup lang="ts">
-    import {useAuthStore} from "@/stores/auth.store";
-    import {ref, onMounted, type Ref} from "vue";
-    import HistoryList from "./components/HistoryList.vue";
-    import HistoryToolbar from "./components/HistoryToolbar.vue";
-    import * as userService from "@/services/user.service"
-    import type {SearchHistoryRecord} from "@/types/user.types"
-    import {delAllHistory} from "@/services/user.service";
-
-    const authStore = useAuthStore();
-
-    const records: Ref<SearchHistoryRecord[]> = ref([]);
-
-    const currentPage = ref(1);
-
-    const page = ref(1);
-
-    const total = ref(0);
-
-    const filterValue = ref("3");
-
-    function handleDelete(id: number) {
-        const currentUser = JSON.stringify(authStore.currentUser)
-        userService.delHistory(currentUser, id).then((res) => {
-            fetchHistory()
-        })
-    }
-
-    function onfilterChange(value) {
-        filterValue.value = value
-        fetchHistory()
-    }
-
-    function ondeleteAll() {
-        delAllHistory
-        const currentUser = JSON.stringify(authStore.currentUser)
-        userService.delAllHistory(currentUser).then((res) => {
-            fetchHistory()
-        })
-    }
-
-    function fetchHistory() {
-        const currentUser = JSON.stringify(authStore.currentUser)
-        userService.fetchHistory(currentUser, currentPage.value, 10, Number(filterValue.value)).then((resp) => {
-            const respData = resp.data.data;
-            records.value = respData.records;
-            total.value = respData.total;
-        })
-    }
-
-    function onNext() {
-        page.value = currentPage.value + 1;
-        fetchHistory();
-    }
-
-    function onPrev() {
-        page.value = currentPage.value - 1;
-        fetchHistory();
-    }
-
-    onMounted(() => {
-        fetchHistory();
-    });
+import { useAuthStore } from "@/stores/auth.store";
+import { ref, onMounted, type Ref } from "vue";
+import HistoryList from "./components/HistoryList.vue";
+import HistoryToolbar from "./components/HistoryToolbar.vue";
+import * as userService from "@/services/user.service"
+import type { SearchHistoryRecord } from "@/types/user.types"
+
+const authStore = useAuthStore();
+
+const records: Ref<SearchHistoryRecord[]> = ref([]);
+
+const currentPage = ref(1);
+
+const page = ref(1);
+
+const total = ref(0);
+
+const filterValue = ref("3");
+
+function fetchHistory() {
+  const currentUser = JSON.stringify(authStore.currentUser)
+  userService.fetchHistory(currentUser, currentPage.value, 10, Number(filterValue.value)).then((resp) => {
+    const respData = resp.data.data;
+    records.value = respData.records;
+    total.value = respData.total;
+  })
+}
+
+function handleDelete(id: number) {
+  const currentUser = JSON.stringify(authStore.currentUser)
+  userService.delHistory(currentUser, id).then(() => {
+    fetchHistory()
+  })
+}
+
+function onfilterChange(value: string) {
+  filterValue.value = value
+  fetchHistory()
+}
+
+function ondeleteAll() {
+  const currentUser = JSON.stringify(authStore.currentUser)
+  userService.delAllHistory(currentUser).then(() => {
+    fetchHistory()
+  })
+}
+
+function onNext() {
+  page.value = currentPage.value + 1;
+  fetchHistory();
+}
+
+function onPrev() {
+  page.value = currentPage.value - 1;
+  fetchHistory();
+}
+
+onMounted(() => {
+  fetchHistory();
+});
 </script>
 
 <template>
-    <HistoryToolbar @filterChange="onfilterChange" @deleteAll="ondeleteAll"/>
-    <HistoryList :data="records" @delete="handleDelete" class="history-list-wrap"/>
-    <div class="pagination">
-        <a-pagination v-model:current="currentPage" simple :total="total">
-            <template #itemRender="{ type, originalElement }">
-                <a-button v-if="type === 'prev'" size="small" @click="onPrev()"> 上一页</a-button>
-                <a-button v-else-if="type === 'next'" size="small" @click="onNext()">下一页</a-button>
-                <component :is="originalElement" v-else></component>
-            </template>
-        </a-pagination>
-    </div>
+  <HistoryToolbar @filterChange="onfilterChange" @deleteAll="ondeleteAll" />
+  <HistoryList :data="records" @delete="handleDelete" class="history-list-wrap" />
+  <div class="pagination">
+    <a-pagination v-model:current="currentPage" simple :total="total">
+      <template #itemRender="{ type, originalElement }">
+        <a-button v-if="type === 'prev'" size="small" @click="onPrev()"> 上一页</a-button>
+        <a-button v-else-if="type === 'next'" size="small" @click="onNext()">下一页</a-button>
+        <component :is="originalElement" v-else></component>
+      </template>
+    </a-pagination>
+  </div>
 </template>
 
 <style scoped lang="scss">
-    .history-list-wrap {
-        margin-top: 16px;
-    }
-
-    .pagination {
-        margin-top: 16px;
-        text-align: right;
-
-        .ant-pagination {
-            height: 28px;
-        }
-    }
+.history-list-wrap {
+  margin-top: 16px;
+}
+
+.pagination {
+  margin-top: 16px;
+  text-align: right;
+
+  .ant-pagination {
+    height: 28px;
+  }
+}
 </style>

+ 0 - 11
src/views/history/components/HistoryItem.vue

@@ -40,17 +40,6 @@ function handleDelete() {
             {{ data.expression }}
           </a>
         </span>
-
-        <span class="item-expression" v-if="data.title">
-          <span>标题:</span>
-           <RouterLink :to="'/detail/' + data.docId" target="_blank">
-            {{ data.title }}
-          </RouterLink>
-
-<!--          <a href="javascript:void(0)" @click="routeToSearchResult(data.id)" type="link">-->
-<!--            {{ data.title }}-->
-<!--          </a>-->
-        </span>
       </a-col>
       <a-col>
         <a-button type="text" @click="handleDelete">