Skip to content

Commit 0be7360

Browse files
authored
feat: Implement Punycode utility functions and integrate into domain dispay (#11433)
* feat: Implement Punycode utility functions and integrate into domain display * chore: Add punycode package and update import path in utility functions
1 parent c9cc064 commit 0be7360

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"nprogress": "^0.2.0",
4848
"pinia": "^2.1.7",
4949
"pinia-plugin-persistedstate": "^1.6.1",
50+
"punycode": "^2.3.1",
5051
"qs": "^6.12.1",
5152
"screenfull": "^6.0.2",
5253
"uuid": "^10.0.0",

frontend/src/utils/util.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { v4 as uuidv4 } from 'uuid';
77
import JSEncrypt from 'jsencrypt';
88
import CryptoJS from 'crypto-js';
99
import { routerToPathWithQuery } from './router';
10+
import { toUnicode } from 'punycode';
1011

1112
export function deepCopy<T>(obj: any): T {
1213
let newObj: any;
@@ -919,3 +920,30 @@ export function sortMenu(arr) {
919920

920921
arr.sort(compareById);
921922
}
923+
924+
export function isPunycoded(domain: string): boolean {
925+
return domain.includes('xn--');
926+
}
927+
928+
export function GetPunyCodeDomain(domain: string): string {
929+
if (!domain || typeof domain !== 'string') {
930+
return '';
931+
}
932+
933+
const lowerDomain = domain.toLowerCase();
934+
if (!lowerDomain.includes('xn--')) {
935+
return '';
936+
}
937+
938+
try {
939+
const decoded = toUnicode(domain);
940+
941+
if (decoded === domain) {
942+
return '';
943+
}
944+
945+
return decoded;
946+
} catch (error) {
947+
return '';
948+
}
949+
}

frontend/src/views/website/website/config/basic/domain/index.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
<el-button link :icon="Promotion" @click="openUrl(row)"></el-button>
99
</template>
1010
</el-table-column>
11-
<el-table-column :label="$t('website.domain')" prop="domain"></el-table-column>
11+
<el-table-column :label="$t('website.domain')" prop="domain">
12+
<template #default="{ row }">
13+
{{ row.domain }}
14+
<span class="text-gray-400" v-if="isPunycoded(row.domain)">({{ GetPunyCodeDomain(row.domain) }})</span>
15+
</template>
16+
</el-table-column>
1217
<el-table-column :label="$t('commons.table.port')" prop="port"></el-table-column>
1318
<el-table-column :label="'SSL'" prop="ssl">
1419
<template #default="{ row }">
@@ -37,6 +42,7 @@ import { Promotion } from '@element-plus/icons-vue';
3742
import { GlobalStore } from '@/store';
3843
import { checkAppInstalled } from '@/api/modules/app';
3944
import { MsgSuccess } from '@/utils/message';
45+
import { GetPunyCodeDomain, isPunycoded } from '@/utils/util';
4046
const globalStore = GlobalStore();
4147
4248
const props = defineProps({

frontend/src/views/website/website/domain/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
</el-form>
1616
<el-text v-else type="primary" class="cursor-pointer" @click="openConfig(row.id)">
1717
{{ row.primaryDomain }}
18+
<span class="text-gray-400" v-if="isPunycoded(row.primaryDomain)">
19+
({{ GetPunyCodeDomain(row.primaryDomain) }})
20+
</span>
1821
</el-text>
1922
<el-popover
2023
placement="right"
@@ -61,11 +64,12 @@
6164
</template>
6265

6366
<script lang="ts" setup>
64-
import { ref } from 'vue';
67+
import { ref, nextTick } from 'vue';
6568
import { listDomains } from '@/api/modules/website';
6669
import { Website } from '@/api/interface/website';
6770
import { routerToNameWithParams } from '@/utils/router';
6871
import { Rules } from '@/global/form-rules';
72+
import { GetPunyCodeDomain, isPunycoded } from '@/utils/util';
6973
7074
interface Props {
7175
row: Website.Website;

0 commit comments

Comments
 (0)