refactor(h5/i18n): 提取 auth 公共文案到 auth.common 命名空间

将 10 个 locale 下 auth.json 中三组完全镜像的 wechat/alipay/douyin 文案提取到
auth.common 公共组(loading/successTitle/failTitle/copy/close/copySuccess/copyFail/
codeMissing/authFail), 三组仅保留 secureTip + identifierLabel 两个差异 key
(原 wechat.openId / alipay.userId / douyin.openId 统一重命名为 identifierLabel)。

mobile AuthCallback 与 PC wechat 落地页同步切到公共 key, 消除同义文案在三组
channel 中重复维护的负担。
This commit is contained in:
bootx
2026-07-20 20:20:18 +08:00
parent 305f114178
commit caa4d5b0ed
12 changed files with 90 additions and 255 deletions

View File

@@ -29,21 +29,16 @@ interface ChannelConfig {
codeField: 'code' | 'auth_code'
/** 品牌色(loading 圈色 + 调试卡片 value 色) */
brandColor: string
/** i18n 命名空间(对应 auth.json 中的 wechat/alipay/douyin 组) */
/** i18n 命名空间(对应 auth.json 中的 wechat/alipay/douyin 组, 仅取差异 key) */
i18nNs: string
/**
* 标识字段名(用于调试卡片 label i18n key 拼接)
* wechat/douyin 用 openId, alipay 用 userId(C 方案 i18n 重组后统一为 identifierLabel)
*/
identifierKey: 'openId' | 'userId'
}
const props = defineProps<{ channel: AuthChannel }>()
const CHANNEL_CONFIG: Record<AuthChannel, ChannelConfig> = {
wechat: { codeField: 'code', brandColor: '#07c160', i18nNs: 'wechat', identifierKey: 'openId' },
alipay: { codeField: 'auth_code', brandColor: '#1677ff', i18nNs: 'alipay', identifierKey: 'userId' },
douyin: { codeField: 'code', brandColor: '#161823', i18nNs: 'douyin', identifierKey: 'openId' },
wechat: { codeField: 'code', brandColor: '#07c160', i18nNs: 'wechat' },
alipay: { codeField: 'auth_code', brandColor: '#1677ff', i18nNs: 'alipay' },
douyin: { codeField: 'code', brandColor: '#161823', i18nNs: 'douyin' },
}
const cfg = computed(() => CHANNEL_CONFIG[props.channel])
@@ -90,7 +85,7 @@ function markFailed(msg: string) {
*/
function init() {
if (!authToken || !code) {
markFailed(t(`auth.${cfg.value.i18nNs}.codeMissing`))
markFailed(t('auth.common.codeMissing'))
return
}
authAndGet({
@@ -110,10 +105,10 @@ function init() {
return
}
// 真正失败: 既无 returnPath 也无标识
markFailed(t(`auth.${cfg.value.i18nNs}.authFail`))
markFailed(t('auth.common.authFail'))
})
.catch((err: Error) => {
markFailed(err?.message || t(`auth.${cfg.value.i18nNs}.authFail`))
markFailed(err?.message || t('auth.common.authFail'))
})
}
@@ -142,10 +137,10 @@ async function copyIdentifier() {
document.execCommand('copy')
document.body.removeChild(textarea)
}
showSuccessToast(t(`auth.${cfg.value.i18nNs}.copySuccess`))
showSuccessToast(t('auth.common.copySuccess'))
}
catch {
showFailToast(t(`auth.${cfg.value.i18nNs}.copyFail`))
showFailToast(t('auth.common.copyFail'))
}
}
</script>
@@ -168,18 +163,18 @@ async function copyIdentifier() {
</svg>
</div>
<h3 class="result-title">
{{ t(`auth.${cfg.i18nNs}.successTitle`) }}
{{ t('auth.common.successTitle') }}
</h3>
<div class="identifier-card" @click="copyIdentifier">
<span class="card-label">{{ t(`auth.${cfg.i18nNs}.${cfg.identifierKey}`) }}</span>
<span class="card-label">{{ t(`auth.${cfg.i18nNs}.identifierLabel`) }}</span>
<div class="card-value" :style="{ color: cfg.brandColor }">
{{ identifierValue }}
</div>
<span class="copy-hint">{{ t(`auth.${cfg.i18nNs}.copy`) }}</span>
<span class="copy-hint">{{ t('auth.common.copy') }}</span>
</div>
<div class="action-buttons">
<van-button plain round block class="close-btn" @click="closeWebview">
{{ t(`auth.${cfg.i18nNs}.close`) }}
{{ t('auth.common.close') }}
</van-button>
</div>
</div>
@@ -193,14 +188,14 @@ async function copyIdentifier() {
</svg>
</div>
<h3 class="result-title">
{{ t(`auth.${cfg.i18nNs}.failTitle`) }}
{{ t('auth.common.failTitle') }}
</h3>
<p class="fail-msg">
{{ failMsg }}
</p>
<div class="action-buttons">
<van-button plain round block class="close-btn" @click="closeWebview">
{{ t(`auth.${cfg.i18nNs}.close`) }}
{{ t('auth.common.close') }}
</van-button>
</div>
</div>

View File

@@ -44,7 +44,7 @@ function markFailed(msg: string) {
*/
function init() {
if (!authToken || !code) {
markFailed(t('auth.wechat.codeMissing'))
markFailed(t('auth.common.codeMissing'))
return
}
authAndGet({
@@ -57,10 +57,10 @@ function init() {
if (finishGatewayAuthAndRedirect(data ?? {})) {
return
}
markFailed(t('auth.wechat.authFail'))
markFailed(t('auth.common.authFail'))
})
.catch((err: Error) => {
markFailed(err?.message || t('auth.wechat.authFail'))
markFailed(err?.message || t('auth.common.authFail'))
})
}
@@ -96,13 +96,13 @@ function handleBack() {
<path fill="#fff" d="M705.5 625.7l-41.8 41.8L512 515.8 360.3 667.5l-41.8-41.8L470.2 474 318.5 322.3l41.8-41.8L512 432.2l151.7-151.7 41.8 41.8L553.8 474l151.7 151.7z" />
</svg>
<h3 class="pc-wechat-auth__result-title">
{{ t('auth.wechat.failTitle') }}
{{ t('auth.common.failTitle') }}
</h3>
<p class="pc-wechat-auth__fail-msg">
{{ failMsg }}
</p>
<button class="pc-wechat-auth__btn pc-wechat-auth__btn--ghost" type="button" @click="handleBack">
{{ t('auth.wechat.close') }}
{{ t('auth.common.close') }}
</button>
</div>
</div>

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "Fetching authorization...",
"secureTip": "Alipay secure auth",
"successTitle": "Success",
"failTitle": "Failed",
"userId": "Alipay User ID",
"copy": "Copy",
"close": "Close",
"copySuccess": "Copied",
@@ -13,29 +11,15 @@
"authFail": "Failed to get user id"
},
"wechat": {
"loading": "Fetching authorization...",
"secureTip": "WeChat secure auth",
"successTitle": "Success",
"failTitle": "Failed",
"openId": "WeChat OpenId",
"copy": "Copy",
"close": "Close",
"copySuccess": "Copied",
"copyFail": "Copy failed",
"codeMissing": "No auth code received, please retry",
"authFail": "Failed to get user id"
"identifierLabel": "WeChat OpenId"
},
"alipay": {
"secureTip": "Alipay secure auth",
"identifierLabel": "Alipay User ID"
},
"douyin": {
"loading": "Fetching authorization...",
"secureTip": "Douyin secure auth",
"successTitle": "Success",
"failTitle": "Failed",
"openId": "Douyin OpenId",
"copy": "Copy",
"close": "Close",
"copySuccess": "Copied",
"copyFail": "Copy failed",
"codeMissing": "No auth code received, please retry",
"authFail": "Failed to get user id"
"identifierLabel": "Douyin OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "Mengambil otorisasi...",
"secureTip": "Alipay mengamankan autentikasi",
"successTitle": "Kesuksesan",
"failTitle": "Gagal",
"userId": "ID Pengguna Alipay",
"copy": "Menyalin",
"close": "Menutup",
"copySuccess": "Disalin",
@@ -13,29 +11,15 @@
"authFail": "Gagal mendapatkan id pengguna"
},
"wechat": {
"loading": "Mengambil otorisasi...",
"secureTip": "Otentikasi aman WeChat",
"successTitle": "Kesuksesan",
"failTitle": "Gagal",
"openId": "WeChat OpenId",
"copy": "Menyalin",
"close": "Menutup",
"copySuccess": "Disalin",
"copyFail": "Penyalinan gagal",
"codeMissing": "Tidak ada kode autentikasi yang diterima, silakan coba lagi",
"authFail": "Gagal mendapatkan id pengguna"
"identifierLabel": "WeChat OpenId"
},
"alipay": {
"secureTip": "Alipay mengamankan autentikasi",
"identifierLabel": "ID Pengguna Alipay"
},
"douyin": {
"loading": "Mengambil otorisasi...",
"secureTip": "Douyin mengamankan autentikasi",
"successTitle": "Kesuksesan",
"failTitle": "Gagal",
"openId": "Douyin OpenId",
"copy": "Menyalin",
"close": "Menutup",
"copySuccess": "Disalin",
"copyFail": "Penyalinan gagal",
"codeMissing": "Tidak ada kode autentikasi yang diterima, silakan coba lagi",
"authFail": "Gagal mendapatkan id pengguna"
"identifierLabel": "Douyin OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "認証を取得中...",
"secureTip": "Alipayの安全な認証",
"successTitle": "成功",
"failTitle": "失敗した",
"userId": "Alipay ユーザー ID",
"copy": "コピー",
"close": "近い",
"copySuccess": "コピーされました",
@@ -13,29 +11,15 @@
"authFail": "ユーザーIDの取得に失敗しました"
},
"wechat": {
"loading": "認証を取得中...",
"secureTip": "WeChat の安全な認証",
"successTitle": "成功",
"failTitle": "失敗した",
"openId": "WeChat オープン ID",
"copy": "コピー",
"close": "近い",
"copySuccess": "コピーされました",
"copyFail": "コピーに失敗しました",
"codeMissing": "認証コードを受信しませんでした。再試行してください",
"authFail": "ユーザーIDの取得に失敗しました"
"identifierLabel": "WeChat オープン ID"
},
"alipay": {
"secureTip": "Alipayの安全な認証",
"identifierLabel": "Alipay ユーザー ID"
},
"douyin": {
"loading": "認証を取得中...",
"secureTip": "Douyin の安全な認証",
"successTitle": "成功",
"failTitle": "失敗した",
"openId": "Douyin OpenId",
"copy": "コピー",
"close": "近い",
"copySuccess": "コピーされました",
"copyFail": "コピーに失敗しました",
"codeMissing": "認証コードを受信しませんでした。再試行してください",
"authFail": "ユーザーIDの取得に失敗しました"
"identifierLabel": "Douyin OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "승인을 가져오는 중...",
"secureTip": "Alipay 보안 인증",
"successTitle": "성공",
"failTitle": "실패한",
"userId": "알리페이 사용자 ID",
"copy": "복사",
"close": "닫다",
"copySuccess": "복사됨",
@@ -13,29 +11,15 @@
"authFail": "사용자 ID를 가져오지 못했습니다."
},
"wechat": {
"loading": "승인을 가져오는 중...",
"secureTip": "WeChat 보안 인증",
"successTitle": "성공",
"failTitle": "실패한",
"openId": "위챗 오픈아이디",
"copy": "복사",
"close": "닫다",
"copySuccess": "복사됨",
"copyFail": "복사 실패",
"codeMissing": "인증 코드가 수신되지 않았습니다. 다시 시도해 주세요.",
"authFail": "사용자 ID를 가져오지 못했습니다."
"identifierLabel": "위챗 오픈아이디"
},
"alipay": {
"secureTip": "Alipay 보안 인증",
"identifierLabel": "알리페이 사용자 ID"
},
"douyin": {
"loading": "승인을 가져오는 중...",
"secureTip": "Douyin 보안 인증",
"successTitle": "성공",
"failTitle": "실패한",
"openId": "Douyin OpenId",
"copy": "복사",
"close": "닫다",
"copySuccess": "복사됨",
"copyFail": "복사 실패",
"codeMissing": "인증 코드가 수신되지 않았습니다. 다시 시도해 주세요.",
"authFail": "사용자 ID를 가져오지 못했습니다."
"identifierLabel": "Douyin OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "Mengambil kebenaran...",
"secureTip": "Pengesahan selamat Alipay",
"successTitle": "Kejayaan",
"failTitle": "gagal",
"userId": "ID Pengguna Alipay",
"copy": "salin",
"close": "tutup",
"copySuccess": "disalin",
@@ -13,29 +11,15 @@
"authFail": "Gagal mendapatkan id pengguna"
},
"wechat": {
"loading": "Mengambil kebenaran...",
"secureTip": "Pengesahan selamat WeChat",
"successTitle": "Kejayaan",
"failTitle": "gagal",
"openId": "WeChat OpenId",
"copy": "salin",
"close": "tutup",
"copySuccess": "disalin",
"copyFail": "Salinan gagal",
"codeMissing": "Tiada kod pengesahan diterima, sila cuba semula",
"authFail": "Gagal mendapatkan id pengguna"
"identifierLabel": "WeChat OpenId"
},
"alipay": {
"secureTip": "Pengesahan selamat Alipay",
"identifierLabel": "ID Pengguna Alipay"
},
"douyin": {
"loading": "Mengambil kebenaran...",
"secureTip": "Pengesahan selamat Douyin",
"successTitle": "Kejayaan",
"failTitle": "gagal",
"openId": "Douyin OpenId",
"copy": "salin",
"close": "tutup",
"copySuccess": "disalin",
"copyFail": "Salinan gagal",
"codeMissing": "Tiada kod pengesahan diterima, sila cuba semula",
"authFail": "Gagal mendapatkan id pengguna"
"identifierLabel": "Douyin OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "กำลังดึงข้อมูลการอนุญาต...",
"secureTip": "Alipay รับรองความถูกต้องอย่างปลอดภัย",
"successTitle": "ความสำเร็จ",
"failTitle": "ล้มเหลว",
"userId": "รหัสผู้ใช้อาลีเพย์",
"copy": "สำเนา",
"close": "ปิด",
"copySuccess": "คัดลอกแล้ว",
@@ -13,29 +11,15 @@
"authFail": "ไม่สามารถรับ ID ผู้ใช้"
},
"wechat": {
"loading": "กำลังดึงข้อมูลการอนุญาต...",
"secureTip": "การตรวจสอบสิทธิ์ที่ปลอดภัยของ WeChat",
"successTitle": "ความสำเร็จ",
"failTitle": "ล้มเหลว",
"openId": "วีแชต โอเพ่นไอดี",
"copy": "สำเนา",
"close": "ปิด",
"copySuccess": "คัดลอกแล้ว",
"copyFail": "การคัดลอกล้มเหลว",
"codeMissing": "ไม่ได้รับรหัสรับรองความถูกต้อง โปรดลองอีกครั้ง",
"authFail": "ไม่สามารถรับ ID ผู้ใช้"
"identifierLabel": "วีแชต โอเพ่นไอดี"
},
"alipay": {
"secureTip": "Alipay รับรองความถูกต้องอย่างปลอดภัย",
"identifierLabel": "รหัสผู้ใช้อาลีเพย์"
},
"douyin": {
"loading": "กำลังดึงข้อมูลการอนุญาต...",
"secureTip": "Douyin รับรองความถูกต้องที่ปลอดภัย",
"successTitle": "ความสำเร็จ",
"failTitle": "ล้มเหลว",
"openId": "Douyin OpenId",
"copy": "สำเนา",
"close": "ปิด",
"copySuccess": "คัดลอกแล้ว",
"copyFail": "การคัดลอกล้มเหลว",
"codeMissing": "ไม่ได้รับรหัสรับรองความถูกต้อง โปรดลองอีกครั้ง",
"authFail": "ไม่สามารถรับ ID ผู้ใช้"
"identifierLabel": "Douyin OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "Đang tìm nạp ủy quyền...",
"secureTip": "Xác thực an toàn của Alipay",
"successTitle": "Thành công",
"failTitle": "Thất bại",
"userId": "ID người dùng Alipay",
"copy": "Sao chép",
"close": "Đóng",
"copySuccess": "Đã sao chép",
@@ -13,29 +11,15 @@
"authFail": "Không lấy được id người dùng"
},
"wechat": {
"loading": "Đang tìm nạp ủy quyền...",
"secureTip": "Xác thực bảo mật WeChat",
"successTitle": "Thành công",
"failTitle": "Thất bại",
"openId": "ID mở WeChat",
"copy": "Sao chép",
"close": "Đóng",
"copySuccess": "Đã sao chép",
"copyFail": "Sao chép không thành công",
"codeMissing": "Không nhận được mã xác thực, vui lòng thử lại",
"authFail": "Không lấy được id người dùng"
"identifierLabel": "ID mở WeChat"
},
"alipay": {
"secureTip": "Xác thực an toàn của Alipay",
"identifierLabel": "ID người dùng Alipay"
},
"douyin": {
"loading": "Đang tìm nạp ủy quyền...",
"secureTip": "Xác thực an toàn Douyin",
"successTitle": "Thành công",
"failTitle": "Thất bại",
"openId": "Id mở Douyin",
"copy": "Sao chép",
"close": "Đóng",
"copySuccess": "Đã sao chép",
"copyFail": "Sao chép không thành công",
"codeMissing": "Không nhận được mã xác thực, vui lòng thử lại",
"authFail": "Không lấy được id người dùng"
"identifierLabel": "Id mở Douyin"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "正在获取授权信息...",
"secureTip": "支付宝安全认证",
"successTitle": "获取成功",
"failTitle": "获取失败",
"userId": "支付宝用户ID",
"copy": "复制信息",
"close": "关闭页面",
"copySuccess": "复制成功",
@@ -13,29 +11,15 @@
"authFail": "获取用户标识失败"
},
"wechat": {
"loading": "正在获取授权信息...",
"secureTip": "微信安全认证",
"successTitle": "获取成功",
"failTitle": "获取失败",
"openId": "微信OpenId",
"copy": "复制信息",
"close": "关闭页面",
"copySuccess": "复制成功",
"copyFail": "复制失败",
"codeMissing": "未获取到授权码,请重新发起认证",
"authFail": "获取用户标识失败"
"identifierLabel": "微信OpenId"
},
"alipay": {
"secureTip": "支付宝安全认证",
"identifierLabel": "支付宝用户ID"
},
"douyin": {
"loading": "正在获取授权信息...",
"secureTip": "抖音安全认证",
"successTitle": "获取成功",
"failTitle": "获取失败",
"openId": "抖音OpenId",
"copy": "复制信息",
"close": "关闭页面",
"copySuccess": "复制成功",
"copyFail": "复制失败",
"codeMissing": "未获取到授权码,请重新发起认证",
"authFail": "获取用户标识失败"
"identifierLabel": "抖音OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "正在獲取授權信息...",
"secureTip": "支付寶安全認證",
"successTitle": "獲取成功",
"failTitle": "獲取失敗",
"userId": "支付寶用户ID",
"copy": "複製信息",
"close": "關閉頁面",
"copySuccess": "複製成功",
@@ -13,29 +11,15 @@
"authFail": "獲取用户標識失敗"
},
"wechat": {
"loading": "正在獲取授權信息...",
"secureTip": "微信安全認證",
"successTitle": "獲取成功",
"failTitle": "獲取失敗",
"openId": "微信OpenId",
"copy": "複製信息",
"close": "關閉頁面",
"copySuccess": "複製成功",
"copyFail": "複製失敗",
"codeMissing": "未獲取到授權碼,請重新發起認證",
"authFail": "獲取用户標識失敗"
"identifierLabel": "微信OpenId"
},
"alipay": {
"secureTip": "支付寶安全認證",
"identifierLabel": "支付寶用户ID"
},
"douyin": {
"loading": "正在獲取授權信息...",
"secureTip": "抖音安全認證",
"successTitle": "獲取成功",
"failTitle": "獲取失敗",
"openId": "抖音OpenId",
"copy": "複製信息",
"close": "關閉頁面",
"copySuccess": "複製成功",
"copyFail": "複製失敗",
"codeMissing": "未獲取到授權碼,請重新發起認證",
"authFail": "獲取用户標識失敗"
"identifierLabel": "抖音OpenId"
}
}

View File

@@ -1,10 +1,8 @@
{
"alipay": {
"common": {
"loading": "正在獲取授權資訊...",
"secureTip": "支付寶安全認證",
"successTitle": "獲取成功",
"failTitle": "獲取失敗",
"userId": "支付寶使用者ID",
"copy": "複製資訊",
"close": "關閉頁面",
"copySuccess": "複製成功",
@@ -13,29 +11,15 @@
"authFail": "獲取使用者標識失敗"
},
"wechat": {
"loading": "正在獲取授權資訊...",
"secureTip": "微信安全認證",
"successTitle": "獲取成功",
"failTitle": "獲取失敗",
"openId": "微信OpenId",
"copy": "複製資訊",
"close": "關閉頁面",
"copySuccess": "複製成功",
"copyFail": "複製失敗",
"codeMissing": "未獲取到授權碼,請重新發起認證",
"authFail": "獲取使用者標識失敗"
"identifierLabel": "微信OpenId"
},
"alipay": {
"secureTip": "支付寶安全認證",
"identifierLabel": "支付寶使用者ID"
},
"douyin": {
"loading": "正在獲取授權資訊...",
"secureTip": "抖音安全認證",
"successTitle": "獲取成功",
"failTitle": "獲取失敗",
"openId": "抖音OpenId",
"copy": "複製資訊",
"close": "關閉頁面",
"copySuccess": "複製成功",
"copyFail": "複製失敗",
"codeMissing": "未獲取到授權碼,請重新發起認證",
"authFail": "獲取使用者標識失敗"
"identifierLabel": "抖音OpenId"
}
}