Commit 14b17e16 by renyizhao

apiKey添加复制按钮

parent a63dfbb0
...@@ -12,6 +12,14 @@ ...@@ -12,6 +12,14 @@
<el-tooltip effect="dark" :content="apiKey" placement="top"> <el-tooltip effect="dark" :content="apiKey" placement="top">
<span class="secret-text">{{ maskedKey }}</span> <span class="secret-text">{{ maskedKey }}</span>
</el-tooltip> </el-tooltip>
<el-button
type="primary"
link
class="ml10"
@click="copyApiKey"
>
<el-icon><DocumentCopy /></el-icon>
</el-button>
</el-form-item> </el-form-item>
<el-form-item label="服务地址:"> <el-form-item label="服务地址:">
<el-tooltip effect="dark" content="http://phslgld.hnluchuan.com:3000/" placement="top"> <el-tooltip effect="dark" content="http://phslgld.hnluchuan.com:3000/" placement="top">
...@@ -186,6 +194,7 @@ ...@@ -186,6 +194,7 @@
<script setup> <script setup>
import { getTokenInfo, getToken, createRecharge, getRecharge } from "@/api/console"; import { getTokenInfo, getToken, createRecharge, getRecharge } from "@/api/console";
import { ElMessage, ElMessageBox } from "element-plus"; import { ElMessage, ElMessageBox } from "element-plus";
import { DocumentCopy } from "@element-plus/icons-vue";
import QRCode from "qrcode"; import QRCode from "qrcode";
import useUserStore from "@/store/modules/user"; import useUserStore from "@/store/modules/user";
...@@ -247,6 +256,44 @@ function maskKey(key) { ...@@ -247,6 +256,44 @@ function maskKey(key) {
return key.substring(0, 6) + "****" + key.substring(key.length - 6); return key.substring(0, 6) + "****" + key.substring(key.length - 6);
} }
function copyApiKey() {
if (!apiKey.value) {
proxy.$modal.msgError("暂无可复制的 API Key");
return;
}
const text = apiKey.value;
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(() => {
proxy.$modal.msgSuccess("已复制 API Key");
}).catch(() => {
fallbackCopy(text);
});
} else {
fallbackCopy(text);
}
}
function fallbackCopy(text) {
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
const successful = document.execCommand("copy");
if (successful) {
proxy.$modal.msgSuccess("已复制 API Key");
} else {
proxy.$modal.msgError("复制失败,请手动复制");
}
} catch (e) {
proxy.$modal.msgError("复制失败,请手动复制");
}
document.body.removeChild(textarea);
}
function loadTokenInfo() { function loadTokenInfo() {
getTokenInfo().then(response => { getTokenInfo().then(response => {
if (response && response.apiKey && response.hasToken) { if (response && response.apiKey && response.hasToken) {
......
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