|
|
@@ -1,105 +0,0 @@
|
|
|
-import router from "@/router/index";
|
|
|
-import type { LocationQuery } from "vue-router";
|
|
|
-import type { Sort } from "./search-component.type";
|
|
|
-
|
|
|
-export type SearchType = 'simple' | 'advanced';
|
|
|
-
|
|
|
-export interface SearchRouteParam {
|
|
|
- type: SearchType;
|
|
|
- query?: string;
|
|
|
- field?: string;
|
|
|
- kw?: string;
|
|
|
- yearSelected?: string[];
|
|
|
- authorSelected?: string[];
|
|
|
- sort?: Sort;
|
|
|
- page?: number;
|
|
|
- size?: number;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 路由到搜索结果页面,把查询表达式传入到搜索结果页面
|
|
|
- * @param param queryString参数
|
|
|
- */
|
|
|
-export function routeToSearch(param: SearchRouteParam, extras: {[index: string]: any} = {}) {
|
|
|
- const queryStrParam: {[index: string]: any} = { ...param, ...extras };
|
|
|
-
|
|
|
- router.push({ name: 'SearchResult', query: queryStrParam });
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 解析url query string为SearchRouteParam对象
|
|
|
- * @param queryParam parsed url query string
|
|
|
- * @returns SearchRouteParam
|
|
|
- */
|
|
|
-export function parseUrlQuery(queryParam: LocationQuery): SearchRouteParam {
|
|
|
- let type: SearchType;
|
|
|
- let query: string = '';
|
|
|
- let field: string = '';
|
|
|
- let kw: string = '';
|
|
|
- if (queryParam.type == 'advanced') {
|
|
|
- type = 'advanced';
|
|
|
- query = queryParam.query as string;
|
|
|
- } else {
|
|
|
- type = 'simple';
|
|
|
- // 初始化关键词
|
|
|
- if (queryParam.kw) {
|
|
|
- kw = (queryParam.kw as string).trim();
|
|
|
- }
|
|
|
- if (queryParam.field) {
|
|
|
- field = (queryParam.field as string).trim();
|
|
|
- }
|
|
|
- query = `${field}=(${kw})`
|
|
|
- }
|
|
|
-
|
|
|
- let yearSelected: string[] = [];
|
|
|
- if (queryParam.yearSelected) {
|
|
|
- if (Array.isArray(queryParam.yearSelected)) {
|
|
|
- yearSelected = queryParam.yearSelected as string[];
|
|
|
- } else {
|
|
|
- yearSelected = [queryParam.yearSelected];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let authorSelected: string[] = [];
|
|
|
- if (queryParam.authorSelected) {
|
|
|
- if (Array.isArray(queryParam.authorSelected)) {
|
|
|
- authorSelected = queryParam.authorSelected as string[];
|
|
|
- } else {
|
|
|
- authorSelected = [queryParam.authorSelected];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let sort: Sort = 'Relevance';
|
|
|
- if (queryParam.sort) {
|
|
|
- sort = queryParam.sort as Sort;
|
|
|
- }
|
|
|
-
|
|
|
- let page: number | null = null;
|
|
|
- if (queryParam.page) {
|
|
|
- page = parseInt(queryParam.page as string);
|
|
|
- }
|
|
|
-
|
|
|
- let size: number | null = null;
|
|
|
- if (queryParam.size) {
|
|
|
- size = parseInt(queryParam.size as string);
|
|
|
- }
|
|
|
-
|
|
|
- const result: SearchRouteParam = {
|
|
|
- type,
|
|
|
- query,
|
|
|
- field,
|
|
|
- kw,
|
|
|
- yearSelected,
|
|
|
- authorSelected,
|
|
|
- sort,
|
|
|
- };
|
|
|
-
|
|
|
- if (page) {
|
|
|
- result['page'] = page;
|
|
|
- }
|
|
|
- if (size) {
|
|
|
- result['size'] = size;
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
-}
|