fix: 005 复制异常修复
This commit is contained in:
23
hx-op/src/util/copyText.ts
Normal file
23
hx-op/src/util/copyText.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { NsMessage } from '/nerv-lib/component';
|
||||||
|
const flag = navigator.clipboard && window.isSecureContext;
|
||||||
|
|
||||||
|
export const copyText = (text: any) => {
|
||||||
|
if (flag) {
|
||||||
|
// navigator clipboard 向剪贴板写文本
|
||||||
|
navigator.clipboard.writeText(text).then(() => {
|
||||||
|
NsMessage.success('复制成功');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 创建text area
|
||||||
|
const textArea = document.createElement('textarea');
|
||||||
|
textArea.value = text;
|
||||||
|
// 使text area不在viewport,同时设置不可见
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.focus();
|
||||||
|
textArea.select();
|
||||||
|
NsMessage.success('复制成功');
|
||||||
|
// 执行复制命令并移除文本框
|
||||||
|
document.execCommand('copy');
|
||||||
|
textArea.remove();
|
||||||
|
}
|
||||||
|
};
|
@@ -7,6 +7,7 @@ import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
|||||||
import { enterPrise } from '/@/api/origanizemanage';
|
import { enterPrise } from '/@/api/origanizemanage';
|
||||||
import { http } from '/nerv-lib/util/http';
|
import { http } from '/nerv-lib/util/http';
|
||||||
import { generateRandomString } from '/@/util/generateRandomString';
|
import { generateRandomString } from '/@/util/generateRandomString';
|
||||||
|
import { copyText } from '/@/util/copyText';
|
||||||
|
|
||||||
type status = 'NORMAL' | 'FREEZE';
|
type status = 'NORMAL' | 'FREEZE';
|
||||||
export const formConfig = [
|
export const formConfig = [
|
||||||
@@ -144,14 +145,7 @@ const handle = async (record: any) => {
|
|||||||
createVNode('p', {}, '重置成功'),
|
createVNode('p', {}, '重置成功'),
|
||||||
createVNode('p', {}, '点击【确认】后自动复制密码并离开'),
|
createVNode('p', {}, '点击【确认】后自动复制密码并离开'),
|
||||||
]),
|
]),
|
||||||
onOk: () => {
|
onOk: () => copyText(password),
|
||||||
try {
|
|
||||||
navigator.clipboard.writeText(password);
|
|
||||||
NsMessage.success('复制成功');
|
|
||||||
} catch (err) {
|
|
||||||
console.error('复制失败', err);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user