Commit 61c9d5e8 by renyizhao

添加服务地址复制按钮

parent 14b17e16
...@@ -25,6 +25,14 @@ ...@@ -25,6 +25,14 @@
<el-tooltip effect="dark" content="http://phslgld.hnluchuan.com:3000/" placement="top"> <el-tooltip effect="dark" content="http://phslgld.hnluchuan.com:3000/" placement="top">
<span class="secret-text">http://phslgld.hnluchuan.com:3000/</span> <span class="secret-text">http://phslgld.hnluchuan.com:3000/</span>
</el-tooltip> </el-tooltip>
<el-button
type="primary"
link
class="ml10"
@click="copyBaseUrl"
>
<el-icon><DocumentCopy /></el-icon>
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-form :model="rechargeForm" label-width="100px" label-position="left"> <el-form :model="rechargeForm" label-width="100px" label-position="left">
...@@ -256,24 +264,33 @@ function maskKey(key) { ...@@ -256,24 +264,33 @@ function maskKey(key) {
return key.substring(0, 6) + "****" + key.substring(key.length - 6); return key.substring(0, 6) + "****" + key.substring(key.length - 6);
} }
const BASE_URL = "http://phslgld.hnluchuan.com:3000/";
function copyApiKey() { function copyApiKey() {
if (!apiKey.value) { if (!apiKey.value) {
proxy.$modal.msgError("暂无可复制的 API Key"); proxy.$modal.msgError("暂无可复制的 API Key");
return; return;
} }
const text = apiKey.value; copyText(apiKey.value, "API Key");
}
function copyBaseUrl() {
copyText(BASE_URL, "服务地址");
}
function copyText(text, label) {
if (navigator.clipboard && window.isSecureContext) { if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(() => { navigator.clipboard.writeText(text).then(() => {
proxy.$modal.msgSuccess("已复制 API Key"); proxy.$modal.msgSuccess(`已复制${label}`);
}).catch(() => { }).catch(() => {
fallbackCopy(text); fallbackCopy(text, label);
}); });
} else { } else {
fallbackCopy(text); fallbackCopy(text, label);
} }
} }
function fallbackCopy(text) { function fallbackCopy(text, label) {
const textarea = document.createElement("textarea"); const textarea = document.createElement("textarea");
textarea.value = text; textarea.value = text;
textarea.style.position = "fixed"; textarea.style.position = "fixed";
...@@ -284,7 +301,7 @@ function fallbackCopy(text) { ...@@ -284,7 +301,7 @@ function fallbackCopy(text) {
try { try {
const successful = document.execCommand("copy"); const successful = document.execCommand("copy");
if (successful) { if (successful) {
proxy.$modal.msgSuccess("已复制 API Key"); proxy.$modal.msgSuccess(`已复制${label}`);
} else { } else {
proxy.$modal.msgError("复制失败,请手动复制"); proxy.$modal.msgError("复制失败,请手动复制");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment