From b0e6e72e2157cae119c29c6864e2bdaacbeb6718 Mon Sep 17 00:00:00 2001 From: gxwebsoft Date: Wed, 13 Mar 2024 11:59:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=8B=E6=83=85=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E7=9A=84=E6=8E=92=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/api/cms/website/model/index.ts | 11 ++---- src/api/link/model/index.ts | 2 + src/store/modules/tenant.ts | 4 -- src/utils/domain.ts | 39 ++++++++++++------- src/utils/request.ts | 17 ++++---- src/views/about/components/detail.vue | 2 +- src/views/article/components/news-list.vue | 2 +- .../article/detail/components/news-detail.vue | 2 +- src/views/index/index.vue | 34 ++++++++++++++-- 10 files changed, 73 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 178135c..3d2bc62 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /dist/ +/node_modules/ diff --git a/src/api/cms/website/model/index.ts b/src/api/cms/website/model/index.ts index 6116e28..b48526f 100644 --- a/src/api/cms/website/model/index.ts +++ b/src/api/cms/website/model/index.ts @@ -1,6 +1,7 @@ import {WebsiteField} from "@/api/cms/website/field/model"; import {Navigation} from "@/api/cms/navigation/model"; import {ArrangeCategory} from "@/api/cms/category/model"; +import {Link} from "@/api/link/model"; // import {MenuMeta} from "ele-admin-pro/es/ele-pro-layout/types"; // import {MenuItem} from "ele-admin-pro"; @@ -13,6 +14,7 @@ export interface Website { websiteCode?: string; websiteIcon?: string; websiteLogo?: string; + websiteDarkLogo?: string; keywords?: string; address?: string; phone?: string; @@ -41,16 +43,9 @@ export interface Website { tenantName?: string; navigations?: Navigation[]; categoryList?: ArrangeCategory[]; + links?: Link[]; // 配置信息 config?: any; - - // path?: string; - // name?: string; - // meta: MenuMeta; - // component?: string; - // redirect?: string; - // children?: Array; - // tempChildren?: Array; } /** diff --git a/src/api/link/model/index.ts b/src/api/link/model/index.ts index 24ea715..16a3a11 100644 --- a/src/api/link/model/index.ts +++ b/src/api/link/model/index.ts @@ -38,6 +38,8 @@ export interface Link { // 打开方式 openType?: number; hide?: number; + url?: string; + icon?: string; } /** diff --git a/src/store/modules/tenant.ts b/src/store/modules/tenant.ts index eea6dad..f104ca5 100644 --- a/src/store/modules/tenant.ts +++ b/src/store/modules/tenant.ts @@ -57,10 +57,6 @@ export const useTenantStore = defineStore({ if(d.type == 0){ d.path = `/article/${d.categoryId}` } - // 链接 - if(d.type == 2){ - d.path = `${d.path}` - } return { ...d, name: d.title, diff --git a/src/utils/domain.ts b/src/utils/domain.ts index 889ea22..25547c9 100644 --- a/src/utils/domain.ts +++ b/src/utils/domain.ts @@ -1,5 +1,7 @@ // 解析域名结构 -export function getHost():any { +import { isNumber } from 'ele-admin-pro'; + +export function getHost(): any { const host = window.location.host; return host.split('.'); } @@ -8,7 +10,7 @@ export function getHost():any { * 获取原始域名 * @return http://www.domain.com */ -export function getOriginDomain():string { +export function getOriginDomain(): string { return window.origin; } @@ -20,7 +22,7 @@ export function getProtocol(): string { * 获取域名 * @return https://www.domain.com */ -export function getDomain():string { +export function getDomain(): string { return window.location.protocol + '//www.' + getRootDomain(); } @@ -28,42 +30,51 @@ export function getDomain():string { * 获取根域名 * abc.com */ -export function getRootDomain():string { +export function getRootDomain(): string { const split = getHost(); - return split[split.length-2] + '.' + split[split.length-1]; + return split[split.length - 2] + '.' + split[split.length - 1]; } /** * 获取二级域名 * @return abc.com */ -export function getSubDomainPath():string { +export function getSubDomainPath(): string { const split = getHost(); - if(split.length == 2) { + if (split.length == 2) { return ''; } - return split[split.length-3]; + return split[split.length - 3]; +} + +// 域名的第一部分 +export function getDomainPart1(): any { + const split = getHost(); + if (isNumber(split[0])) { + return split[0]; + } + return undefined; } /** * 获取租户ID * @return 10048 */ -export function getTenantId():string|null { +export function getTenantId(): string | null { const subDomain = getSubDomainPath(); - if(subDomain == undefined){ + if (subDomain == undefined) { return null; } - return subDomain.replace(/[^\d]/g,''); + return subDomain.replace(/[^\d]/g, ''); } /** * 获取产品标识 * @return 10048 */ -export function getProductCode():string|null { +export function getProductCode(): string | null { const subDomain = getSubDomainPath(); - if(subDomain == undefined){ + if (subDomain == undefined) { return null; } const split = subDomain.split('-'); @@ -73,6 +84,6 @@ export function getProductCode():string|null { /** * 控制台域名 */ -export function navSubDomain(path):string { +export function navSubDomain(path): string { return `${window.location.protocol}//${path}.${getRootDomain()}`; } diff --git a/src/utils/request.ts b/src/utils/request.ts index d68c274..1520fd2 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -15,6 +15,7 @@ import { import { getToken, setToken } from './token-util'; import { logout } from './page-tab-util'; import type { ApiResult } from '@/api'; +import {getDomainPart1} from "@/utils/domain"; // import {getTenantId} from "@/utils/domain"; const service = axios.create({ @@ -31,14 +32,14 @@ service.interceptors.request.use( if (token && config.headers) { config.headers.common[TOKEN_HEADER_NAME] = token; } - // 从配置文件获取租户ID - if(config.headers){ - config.headers.common['TenantId'] = TENANT_ID; - // 解析二级域名获取租户ID - // if(getTenantId() != null && getTenantId() != '0'){ - // config.headers.common['TenantId'] = getTenantId(); - // } - } + // 从配置文件获取租户ID + if (config.headers) { + config.headers.common['TenantId'] = TENANT_ID; + // 解析二级域名获取租户ID + if (getDomainPart1()) { + config.headers.common['TenantId'] = getDomainPart1(); + } + } return config; }, (error) => { diff --git a/src/views/about/components/detail.vue b/src/views/about/components/detail.vue index 146f9e1..bbba91a 100644 --- a/src/views/about/components/detail.vue +++ b/src/views/about/components/detail.vue @@ -4,7 +4,7 @@ @@ -175,6 +196,11 @@