2121
This commit is contained in:
parent
2e470397e4
commit
736f11b356
|
|
@ -20,6 +20,7 @@ public class ConfigController : ControllerBase
|
|||
{
|
||||
private readonly IAdminConfigService _configService;
|
||||
private readonly ILogger<ConfigController> _logger;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// 配置键常量
|
||||
|
|
@ -32,10 +33,26 @@ public class ConfigController : ControllerBase
|
|||
public const string UserConfig = "user_config";
|
||||
}
|
||||
|
||||
public ConfigController(IAdminConfigService configService, ILogger<ConfigController> logger)
|
||||
public ConfigController(IAdminConfigService configService, ILogger<ConfigController> logger, IConfiguration configuration)
|
||||
{
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取站点公开配置(无需登录)
|
||||
/// </summary>
|
||||
/// <returns>站点配置</returns>
|
||||
[HttpGet("site/get")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetSiteConfig()
|
||||
{
|
||||
var apiBaseUrl = _configuration["SiteSettings:ApiBaseUrl"] ?? "";
|
||||
return Ok(ApiResponse<object>.Success(new
|
||||
{
|
||||
apiBaseUrl
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { initSiteConfig } from '@/utils/siteConfig'
|
||||
|
||||
// 全局初始化:加载站点配置
|
||||
onMounted(() => {
|
||||
initSiteConfig()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 站点全局配置
|
||||
* 页面加载时请求后端接口,缓存到内存中供全局使用
|
||||
*/
|
||||
import { request, type ApiResponse } from './request'
|
||||
|
||||
/** 站点配置数据 */
|
||||
interface SiteConfig {
|
||||
/** API服务地址(用于拼接报告等外部链接) */
|
||||
apiBaseUrl: string
|
||||
}
|
||||
|
||||
/** 缓存的配置数据 */
|
||||
let cachedConfig: SiteConfig | null = null
|
||||
|
||||
/** 加载中的 Promise,防止重复请求 */
|
||||
let loadingPromise: Promise<SiteConfig> | null = null
|
||||
|
||||
/**
|
||||
* 获取站点配置(从后端接口加载,带缓存)
|
||||
*/
|
||||
export async function getSiteConfig(): Promise<SiteConfig> {
|
||||
if (cachedConfig) {
|
||||
return cachedConfig
|
||||
}
|
||||
|
||||
// 防止并发重复请求
|
||||
if (loadingPromise) {
|
||||
return loadingPromise
|
||||
}
|
||||
|
||||
loadingPromise = request<SiteConfig>({
|
||||
url: '/admin/config/site/get',
|
||||
method: 'get'
|
||||
}).then((res: ApiResponse<SiteConfig>) => {
|
||||
cachedConfig = res.data ?? { apiBaseUrl: '' }
|
||||
return cachedConfig
|
||||
}).catch(() => {
|
||||
// 请求失败时返回默认值
|
||||
cachedConfig = { apiBaseUrl: '' }
|
||||
return cachedConfig
|
||||
}).finally(() => {
|
||||
loadingPromise = null
|
||||
})
|
||||
|
||||
return loadingPromise
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取API基础地址
|
||||
*/
|
||||
export function getApiBaseUrl(): string {
|
||||
return cachedConfig?.apiBaseUrl ?? ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化站点配置(在 App.vue 中调用)
|
||||
*/
|
||||
export async function initSiteConfig(): Promise<void> {
|
||||
await getSiteConfig()
|
||||
}
|
||||
|
|
@ -382,6 +382,7 @@ import {
|
|||
type AssessmentRecordQuery
|
||||
} from '@/api/business/assessmentRecord'
|
||||
import { getScoreOptionList, type ScoreOptionItem } from '@/api/business/assessment'
|
||||
import { getApiBaseUrl } from '@/utils/siteConfig'
|
||||
|
||||
// ============ Constants ============
|
||||
|
||||
|
|
@ -665,7 +666,12 @@ function handleViewReport(row: AssessmentRecordItem) {
|
|||
|
||||
/** 在新标签页打开网页版报告 */
|
||||
function handleViewWebReport(row: AssessmentRecordItem) {
|
||||
const url = `/report/full?recordId=${row.id}`
|
||||
const baseUrl = getApiBaseUrl()
|
||||
if (!baseUrl) {
|
||||
ElMessage.warning('API地址未配置,请在后台 appsettings.json 中配置 SiteSettings:ApiBaseUrl')
|
||||
return
|
||||
}
|
||||
const url = `${baseUrl.replace(/\/+$/, '')}/report/full?recordId=${row.id}`
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@
|
|||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"SiteSettings": {
|
||||
"ApiBaseUrl": ""
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user