唐钦 3 years ago
parent
commit
c2697b52e2

+ 25 - 18
src/services/httpClient.ts

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

+ 1 - 1
src/services/search.service.ts

@@ -5,7 +5,7 @@ import httpClient from "./httpClient";
 
 function search(query: Object): Promise<AxiosResponse<Response<SearchResult>>> {
   // const params = { query };
-  return httpClient.post("/search", query);
+  return httpClient.post("/gw/search/search", query);
 }
 
 export default {

+ 13 - 0
src/services/user.service.ts

@@ -0,0 +1,13 @@
+import type { SearchResult } from "@/types/search.types";
+import type { Response } from "@/types/response.types";
+import type { AxiosResponse } from "axios";
+import httpClient from "./httpClient";
+
+function login(param: Object): Promise<AxiosResponse<Response<Object>>> {
+  // const params = { query };
+  return httpClient.post("/gw/user/login", param);
+}
+
+export default {
+  login
+}

+ 119 - 101
src/views/LoginView.vue

@@ -1,124 +1,142 @@
-<script setup lang="ts">import { reactive } from 'vue';
+<script setup lang="ts">import {reactive} from 'vue';
+import {useRoute, useRouter} from "vue-router";
+import user from "@/services/user.service";
 
 interface FormState {
-  username: string;
-  password: string;
-  remember: boolean;
+    username: string;
+    password: string;
+    remember: boolean;
 }
 
+// 路由管理器
+const router = useRouter();
+// 当前路由对象
+const route = useRoute();
+
 const formState = reactive<FormState>({
-  username: '',
-  password: '',
-  remember: true,
+    username: '',
+    password: '',
+    remember: true,
 });
 const onFinish = (values: any) => {
-  console.log('Success:', values);
+    console.log(values);
+    let param = {
+        mobilePhone: values.username,
+        password: values.password,
+        type: 1
+    }
+    user.login(param).then((resp) => {
+        localStorage.setItem('token', resp.data.data.token);
+        router.push({name: "SearchIndex"});
+    }).catch((err) => {
+        console.log(err);
+    })
 };
 
 const onFinishFailed = (errorInfo: any) => {
-  console.log('Failed:', errorInfo);
+    console.log('Failed:', errorInfo);
 };
 
 </script>
 
 <template>
-  <div class="login-main">
-    <a-row type="flex">
-      <a-col class="left" :flex="1">
-        <h1 class="login-title">技淘平台智慧产权大脑</h1>
-        <p class="login-banner">
-          <img src="@/assets/imgs/login-banner@2x.png" />
-        </p>
-      </a-col>
-      <a-col class="right" :flex="1">
-        <h1>用户登录</h1>
-        <a-divider></a-divider>
-        <div class="login-form-wrapper">
-          <a-form
-            :model="formState"
-            name="basic"
-            :label-col="{ span: 4 }"
-            :wrapper-col="{ span: 20 }"
-            autocomplete="off"
-            @finish="onFinish"
-            @finishFailed="onFinishFailed"
-          >
-            <a-form-item
-              label="用户名"
-              name="username"
-              :rules="[{ required: true, message: '请输入用户名' }]"
-            >
-              <a-input v-model:value="formState.username" />
-            </a-form-item>
-
-            <a-form-item
-              label="密码"
-              name="password"
-              :rules="[{ required: true, message: '请输入密码' }]"
-            >
-              <a-input-password v-model:value="formState.password" />
-            </a-form-item>
-
-            <a-form-item :wrapper-col="{sm: {span: 20, offset: 4}, xs: {span: 24, offset: 0}}">
-              <a-button type="primary" html-type="submit" block>登&nbsp;&nbsp;&nbsp;&nbsp;录</a-button>
-            </a-form-item>
-          </a-form>
-          <p class="forgot-password-wrap">
-            <a href="#">忘记密码?</a>
-          </p>
-        </div>
-      </a-col>
-    </a-row>
-  </div>
+    <div class="login-main">
+        <a-row type="flex">
+            <a-col class="left" :flex="1">
+                <h1 class="login-title">技淘平台智慧产权大脑</h1>
+                <p class="login-banner">
+                    <img src="@/assets/imgs/login-banner@2x.png"/>
+                </p>
+            </a-col>
+            <a-col class="right" :flex="1">
+                <h1>用户登录</h1>
+                <a-divider></a-divider>
+                <div class="login-form-wrapper">
+                    <a-form
+                            :model="formState"
+                            name="basic"
+                            :label-col="{ span: 4 }"
+                            :wrapper-col="{ span: 20 }"
+                            autocomplete="off"
+                            @finish="onFinish"
+                            @finishFailed="onFinishFailed"
+                    >
+                        <a-form-item
+                                label="用户名"
+                                name="username"
+                                :rules="[{ required: true, message: '请输入用户名' }]"
+                        >
+                            <a-input v-model:value="formState.username"/>
+                        </a-form-item>
+
+                        <a-form-item
+                                label="密码"
+                                name="password"
+                                :rules="[{ required: true, message: '请输入密码' }]"
+                        >
+                            <a-input-password v-model:value="formState.password"/>
+                        </a-form-item>
+
+                        <a-form-item :wrapper-col="{sm: {span: 20, offset: 4}, xs: {span: 24, offset: 0}}">
+                            <a-button type="primary" html-type="submit" block>登&nbsp;&nbsp;&nbsp;&nbsp;录</a-button>
+                        </a-form-item>
+                    </a-form>
+                    <p class="forgot-password-wrap">
+                        <a href="#">忘记密码?</a>
+                    </p>
+                </div>
+            </a-col>
+        </a-row>
+    </div>
 </template>
 
 <style scoped lang="scss">
-.login-main {
-  height: 100vh;
-  background-color: #00A09A;
-
-  .left {
-    text-align: center;
-    padding-top: 100px;
-
-    .login-title {
-      color: #ffffff;
+    .login-main {
+        height: 100vh;
+        background-color: #00A09A;
+
+        .left {
+            text-align: center;
+            padding-top: 100px;
+
+            .login-title {
+                color: #ffffff;
+            }
+
+            .login-banner {
+                margin: 0 auto;
+                width: 300px;
+
+                img {
+                    margin-top: 50px;
+                    width: 100%;
+                }
+            }
+        }
+
+        .right {
+            height: 100vh;
+            padding-top: 100px;
+            padding-left: 60px;
+            border-top-left-radius: 1em;
+            border-bottom-left-radius: 1em;
+            background-color: #ffffff;
+
+            .login-form-wrapper {
+                width: 400px;
+            }
+        }
     }
 
-    .login-banner {
-      margin: 0 auto;
-      width: 300px;
+    .forgot-password-wrap {
+        text-align: right;
 
-      img {
-        margin-top: 50px;
-        width: 100%;
-      }
-    }
-  }
-
-  .right {
-    height: 100vh;
-    padding-top: 100px;
-    padding-left: 60px;
-    border-top-left-radius: 1em;
-    border-bottom-left-radius: 1em;
-    background-color: #ffffff;
-
-    .login-form-wrapper {
-      width: 400px;
-    }
-  }
-}
-
-.forgot-password-wrap {
-  text-align: right;
-
-  // a {
-  //   color: #ffffff;
+        // a {
+        //   color: #ffffff;
 
-  //   &:hover {
-  //     text-decoration: underline;
-  //   }
-  // }
-}
+        //   &:hover {
+        //     text-decoration: underline;
+        //   }
+        // }
+    }
 </style>

+ 38 - 41
src/views/search/SearchResultView.vue

@@ -25,11 +25,11 @@
 
     const size = ref(10);
 
-    const authorChecked = ref(false);
-    const yearChecked = ref(false);
+    let authorChecked = ref(false);
+    let yearChecked = ref(false);
 
     let yearValueArr: string[] = []
-    const authorValueArr: string[] = []
+    let authorValueArr: string[] = []
 
     // 搜索结果
     const searchResult: Ref<SearchResult | null> = ref(null);
@@ -39,12 +39,8 @@
     // 搜索结果
     const aggAuthorResult = ref(null);
 
-    function aggsYearSearch(field: string, keyword: string) {
-        if (keyword && keyword.length == 0) {
-            router.push({name: "SearchIndex"});
-            return;
-        }
-        const query = `${field}=(${keyword})`;
+    // 根据年份聚合
+    function aggsYearSearch(query: string) {
         const aggYear = {
             name: 'year',
             field: 'year'
@@ -62,12 +58,9 @@
         })
     }
 
-    function aggsAuthorsSearch(field: string, keyword: string) {
-        if (keyword && keyword.length == 0) {
-            router.push({name: "SearchIndex"});
-            return;
-        }
-        const query = `${field}=(${keyword})`;
+    // 根据作者聚合
+    function aggsAuthorsSearch(query: string) {
+
         const aggAuthors = {
             name: 'authors',
             field: 'authors.keyword'
@@ -103,7 +96,6 @@
             sortParam = {"cited": "ASC"}
         }
 
-
         const param: { [key: string]: any } = {
             query: query,
             from: page.value,
@@ -129,32 +121,30 @@
             param.query += ' AND ' + yearQuery + pyKw
         }
 
-        if (!authorValueArr || authorValueArr.length <= 0) {
-
-        } else {
-            // var yearQuery: string = "PY=";
-            // console.log(yearValueArr);
-            // var pyKw = '('
-            // for (let i = 0; i < yearValueArr.length; i++) {
-            //     if (i == 0) {
-            //         pyKw += yearValueArr[i]
-            //     } else {
-            //         pyKw += " " + yearValueArr[i]
-            //     }
-            //
-            //     console.log(pyKw);
-            //     if (i == yearValueArr.length - 1) {
-            //         pyKw += ')'
-            //     }
-            // }
-            // param.query += ' AND ' + yearQuery + pyKw
+        if (authorValueArr && authorValueArr.length > 0) {
+            var auQuery: string = "AU=";
+            var pyKw = '('
+            for (let i = 0; i < authorValueArr.length; i++) {
+                if (i == 0) {
+                    pyKw += authorValueArr[i]
+                } else {
+                    pyKw += " " + authorValueArr[i]
+                }
+
+                console.log(pyKw);
+                if (i == authorValueArr.length - 1) {
+                    pyKw += ')'
+                }
+            }
+            param.query += ' AND ' + auQuery + pyKw
         }
         searchResult.value = null
         searchService.search(param).then((resp) => {
             searchResult.value = resp.data.data;
-            if (!yearValueArr || yearValueArr.length <= 0) {
-
-
+            if (yearValueArr && yearValueArr.length > 0) {
+                aggsAuthorsSearch(param.query)
+            }else {
+                aggsYearSearch(param.query)
             }
         }).catch((err) => {
             console.log(err);
@@ -174,8 +164,9 @@
         }
         // 搜索
         doSearch(field.value, keyword.value);
-        aggsYearSearch(field.value, keyword.value);
-        aggsAuthorsSearch(field.value, keyword.value);
+        const query = `${field.value}=(${keyword.value})`
+        aggsYearSearch(query);
+        aggsAuthorsSearch(query);
     });
 
     function changeFile(val) {
@@ -202,6 +193,7 @@
 
     function changeYearChecked() {
         yearValueArr = []
+        authorValueArr = []
         for (let valueKey in yearChecked.value) {
             yearValueArr.push(yearChecked.value[valueKey])
         }
@@ -209,7 +201,12 @@
     }
 
     function changeAuthorChecked() {
-        console.log(authorChecked.value);
+        authorValueArr = []
+        yearValueArr = []
+        for (let valueKey in authorChecked.value) {
+            authorValueArr.push(authorChecked.value[valueKey])
+        }
+        doSearch(field.value, keyword.value);
     }
 
     onUnmounted(() => {