feat: implement desktop app structure with API base URL handling and bindings for Wails integration
This commit is contained in:
@@ -1955,6 +1955,10 @@ export default {
|
||||
description: 'View and manage your API key',
|
||||
keyLabel: 'API Key',
|
||||
keyDescription: 'Secret used for API requests. Keep it safe.',
|
||||
urlLabel: 'API URL',
|
||||
urlDescription: 'Base path for REST API requests; append the specific endpoint when calling.',
|
||||
copyUrlTitle: 'Copy API URL',
|
||||
urlCopySuccess: 'API URL copied to clipboard',
|
||||
copyTitle: 'Copy API Key',
|
||||
docLabel: 'API Documentation',
|
||||
docDescription: 'View complete API documentation and examples,',
|
||||
|
||||
@@ -1403,6 +1403,10 @@ export default {
|
||||
description: "API 키 보기 및 관리",
|
||||
keyLabel: "API 키",
|
||||
keyDescription: "API 호출에 사용되는 키, 안전하게 보관하세요",
|
||||
urlLabel: "API URL",
|
||||
urlDescription: "REST API 기본 경로입니다. 호출 시 구체적인 엔드포인트 경로를 이어서 사용하세요.",
|
||||
copyUrlTitle: "API URL 복사",
|
||||
urlCopySuccess: "API URL이 클립보드에 복사되었습니다",
|
||||
copyTitle: "API 키 복사",
|
||||
docLabel: "API 문서",
|
||||
docDescription: "전체 API 호출 문서 및 예시 보기, ",
|
||||
|
||||
@@ -1250,6 +1250,10 @@ export default {
|
||||
description: 'Просматривайте и управляйте своим API-ключом',
|
||||
keyLabel: 'API Key',
|
||||
keyDescription: 'Ключ для API-запросов. Храните его в безопасности.',
|
||||
urlLabel: 'URL API',
|
||||
urlDescription: 'Базовый путь REST API; при вызове добавляйте конкретный путь эндпоинта.',
|
||||
copyUrlTitle: 'Скопировать URL API',
|
||||
urlCopySuccess: 'URL API скопирован в буфер обмена',
|
||||
copyTitle: 'Скопировать API Key',
|
||||
docLabel: 'Документация API',
|
||||
docDescription: 'Ознакомьтесь с полной документацией и примерами API,',
|
||||
|
||||
@@ -1397,6 +1397,10 @@ export default {
|
||||
description: "查看和管理您的 API 密钥",
|
||||
keyLabel: "API Key",
|
||||
keyDescription: "用于 API 调用的密钥,请妥善保管",
|
||||
urlLabel: "API 地址",
|
||||
urlDescription: "REST API 的基础路径,请求时在末尾拼接具体接口路径",
|
||||
copyUrlTitle: "复制 API 地址",
|
||||
urlCopySuccess: "API 地址已复制到剪贴板",
|
||||
copyTitle: "复制 API Key",
|
||||
docLabel: "API 文档",
|
||||
docDescription: "查看完整的 API 调用文档和示例,",
|
||||
|
||||
@@ -55,6 +55,32 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API base URL -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.urlLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.urlDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<t-input
|
||||
:model-value="apiBaseUrlDisplay"
|
||||
readonly
|
||||
type="text"
|
||||
style="width: 100%; font-family: monospace; font-size: 12px;"
|
||||
/>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="copyApiUrl"
|
||||
:title="$t('tenant.api.copyUrlTitle')"
|
||||
>
|
||||
<t-icon name="file-copy" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API docs -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
@@ -123,6 +149,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { getCurrentUser, type TenantInfo, type UserInfo } from '@/api/auth'
|
||||
import { getApiBaseUrl } from '@/utils/api-base'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -134,6 +161,8 @@ const userInfo = ref<UserInfo | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const showApiKey = ref(false)
|
||||
/** WeKnora Lite (Wails): real API origin is loopback + dynamic port, not window.location.origin */
|
||||
const wailsApiBaseURL = ref<string | null>(null)
|
||||
|
||||
// Computed
|
||||
const displayApiKey = computed(() => {
|
||||
@@ -148,6 +177,54 @@ const displayApiKey = computed(() => {
|
||||
return masked
|
||||
})
|
||||
|
||||
const apiBaseUrlDisplay = computed(() => {
|
||||
if (wailsApiBaseURL.value) {
|
||||
return wailsApiBaseURL.value
|
||||
}
|
||||
const configured = getApiBaseUrl().trim().replace(/\/$/, '')
|
||||
let origin = typeof window !== 'undefined' ? window.location.origin : ''
|
||||
if (!origin || origin === 'null') {
|
||||
origin = ''
|
||||
}
|
||||
const base = configured || origin
|
||||
return `${base}/api/v1`
|
||||
})
|
||||
|
||||
type WeKnoraDesktopWindow = Window & {
|
||||
__WEKNORA_API_BASE__?: string
|
||||
go?: {
|
||||
main?: {
|
||||
App?: {
|
||||
GetAPIBaseURL?: () => Promise<string> | string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function tryLoadWailsApiBaseURL() {
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const injected = win.__WEKNORA_API_BASE__
|
||||
if (typeof injected === 'string' && injected.trim()) {
|
||||
wailsApiBaseURL.value = injected.trim().replace(/\/$/, '')
|
||||
return
|
||||
}
|
||||
const fn = win.go?.main?.App?.GetAPIBaseURL
|
||||
if (typeof fn === 'function') {
|
||||
try {
|
||||
const raw = await Promise.resolve(fn())
|
||||
if (typeof raw === 'string' && raw.trim()) {
|
||||
wailsApiBaseURL.value = raw.trim().replace(/\/$/, '')
|
||||
}
|
||||
} catch {
|
||||
/* binding error */
|
||||
}
|
||||
return
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 50))
|
||||
}
|
||||
}
|
||||
|
||||
// Methods
|
||||
const loadInfo = async () => {
|
||||
try {
|
||||
@@ -203,6 +280,21 @@ const copyApiKey = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const copyApiUrl = async () => {
|
||||
const text = apiBaseUrlDisplay.value
|
||||
try {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
} else {
|
||||
fallbackCopyText(text)
|
||||
}
|
||||
MessagePlugin.success(t('tenant.api.urlCopySuccess'))
|
||||
} catch {
|
||||
fallbackCopyText(text)
|
||||
MessagePlugin.success(t('tenant.api.urlCopySuccess'))
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (dateStr: string | undefined) => {
|
||||
if (!dateStr) return t('tenant.unknown')
|
||||
|
||||
@@ -223,6 +315,7 @@ const formatDate = (dateStr: string | undefined) => {
|
||||
|
||||
// Lifecycle
|
||||
onMounted(() => {
|
||||
void tryLoadWailsApiBaseURL()
|
||||
loadInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function GetAPIBaseURL():Promise<string>;
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function GetAPIBaseURL() {
|
||||
return window['go']['main']['App']['GetAPIBaseURL']();
|
||||
}
|
||||
Reference in New Issue
Block a user