Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-csf-front
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yuzhenWang
yd-csf-front
Commits
fd0e8cfe
Commit
fd0e8cfe
authored
May 08, 2026
by
Sweet Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决点击复制的工具类方法,新增出账时默认关联保单
parent
03497a45
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
29 deletions
+34
-29
src/utils/copyToClipboard.js
+29
-26
src/views/financialCenter/payables.vue
+5
-3
No files found.
src/utils/copyToClipboard.js
View file @
fd0e8cfe
import
{
ElMessage
}
from
'element-plus'
export
function
copyToClipboard
(
text
)
{
// 方案1:使用现代 Clipboard API
if
(
navigator
.
clipboard
&&
navigator
.
clipboard
.
writeText
)
{
return
navigator
.
clipboard
.
writeText
(
text
).
catch
((
err
)
=>
{
console
.
error
(
'Clipboard API 写入失败:'
,
err
);
ElMessage
.
error
(
'复制失败'
)
// 降级到传统方案
fallbackCopyText
(
text
);
});
}
// 方案2:降级使用传统方法
else
{
fallbackCopyText
(
text
);
}
}
// 传统复制方法
// 传统降级复制方法
function
fallbackCopyText
(
text
,
typeName
=
'内容'
)
{
const
textarea
=
document
.
createElement
(
'textarea'
);
textarea
.
value
=
text
;
// 防止页面滚动或闪烁
textarea
.
style
.
position
=
'fixed'
;
textarea
.
style
.
opacity
=
'0'
;
textarea
.
style
.
left
=
'-9999px'
;
document
.
body
.
appendChild
(
textarea
);
try
{
textarea
.
select
();
textarea
.
setSelectionRange
(
0
,
99999
);
// 对于移动设备
document
.
execCommand
(
'copy'
);
console
.
log
(
'传统方法复制成功'
);
ElMessage
.
success
(
`
${
typeName
}
已复制`
)
textarea
.
setSelectionRange
(
0
,
99999
);
// 兼容移动端
const
successful
=
document
.
execCommand
(
'copy'
);
if
(
successful
)
{
ElMessage
.
success
(
`
${
typeName
}
已复制`
);
}
else
{
throw
new
Error
(
'execCommand 返回失败'
);
}
}
catch
(
err
)
{
console
.
error
(
'传统方法复制失败:'
,
err
)
ElMessage
.
error
(
'复制失败
'
);
console
.
error
(
'传统方法复制失败:'
,
err
)
;
ElMessage
.
error
(
'复制失败,请手动复制
'
);
}
finally
{
document
.
body
.
removeChild
(
textarea
);
}
}
export
default
{
copyToClipboard
}
// 主导出函数,接收 text 和 typeName 两个参数
export
default
function
copyToClipboard
(
text
,
typeName
=
'内容'
)
{
// 1. 判断是否在安全上下文(HTTPS/localhost) 且 浏览器支持 Clipboard API
if
(
window
.
isSecureContext
&&
navigator
.
clipboard
&&
navigator
.
clipboard
.
writeText
)
{
navigator
.
clipboard
.
writeText
(
text
).
then
(()
=>
{
ElMessage
.
success
(
`
${
typeName
}
已复制`
);
}).
catch
((
err
)
=>
{
console
.
error
(
'Clipboard API 写入失败,降级处理:'
,
err
);
// API 调用失败(如权限被拒),自动降级到传统方案
fallbackCopyText
(
text
,
typeName
);
});
}
else
{
// 2. 非安全环境(如 HTTP)或不支持新 API,直接使用传统降级方案
fallbackCopyText
(
text
,
typeName
);
}
}
\ No newline at end of file
src/views/financialCenter/payables.vue
View file @
fd0e8cfe
...
...
@@ -316,7 +316,7 @@ const searchConfig = ref([
const
payRecordDialogTableVisible
=
ref
(
false
)
// 新增出账记录
const
addPayRecordFormModel
=
ref
({
fortuneBizType
:
'
U
'
,
fortuneBizType
:
'
R
'
,
})
const
addPayRecordDialogVisible
=
ref
(
false
)
const
addPayRecordFormRef
=
ref
()
...
...
@@ -375,7 +375,8 @@ const addPayRecordFormConfig = [
type
:
'select'
,
prop
:
'currency'
,
label
:
'出账币种'
,
dictType
:
'bx_currency_type'
dictType
:
'bx_currency_type'
,
defaultValue
:
'HKD'
},
{
type
:
'input'
,
prop
:
'defaultExchangeRate'
,
...
...
@@ -411,7 +412,8 @@ const addPayRecordFormConfig = [
type
:
'select'
,
prop
:
'status'
,
label
:
'出账状态'
,
dictType
:
'csf_expected_fortune_status'
dictType
:
'csf_expected_fortune_status'
,
defaultValue
:
0
}
]
const
handleConfirmAddPayRecord
=
async
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment