Files
frontend-app/uni_modules/uview-plus/components/u-copy/u-copy.vue
T

73 lines
1.7 KiB
Vue
Raw Normal View History

2025-08-05 15:25:23 +08:00
<template>
<view @click="handleClick">
2026-07-23 14:31:06 +08:00
<slot>{{ t("up.common.copy") }}</slot>
2025-08-05 15:25:23 +08:00
</view>
</template>
<script>
2026-07-23 14:31:06 +08:00
import { t } from '../../libs/i18n'
2025-08-05 15:25:23 +08:00
export default {
name: "up-copy",
props: {
content: {
type: String,
default: ''
},
alertStyle: {
type: String,
default: 'toast'
},
notice: {
type: String,
2026-07-23 14:31:06 +08:00
default: t("up.common.copy") + t("up.common.success")
2025-08-05 15:25:23 +08:00
}
},
emits: ['success'],
methods: {
2026-07-23 14:31:06 +08:00
t,
2025-08-05 15:25:23 +08:00
handleClick() {
let content = this.content;
if (!content) {
uni.showToast({
2026-07-23 14:31:06 +08:00
title: t("up.common.none"),
2025-08-05 15:25:23 +08:00
icon: 'none',
duration: 2000,
});
return false;
}
content = typeof content === 'string' ? content : content.toString() // 复制内容,必须字符串,数字需要转换为字符串
/**
2026-07-23 14:31:06 +08:00
* 复制逻辑
2025-08-05 15:25:23 +08:00
*/
let that = this;
uni.setClipboardData({
data: content,
success: function() {
if (that.alertStyle == 'modal') {
uni.showModal({
2026-07-23 14:31:06 +08:00
title: "up.common.tip",
2025-08-05 15:25:23 +08:00
content: that.notice
});
} else {
uni.showToast({
title: that.notice,
icon: 'none'
});
}
that.$emit('success');
},
fail:function(){
uni.showToast({
2026-07-23 14:31:06 +08:00
title: t("up.common.copy") + t("up.common.fail"),
2025-08-05 15:25:23 +08:00
icon: 'none',
duration:3000,
});
}
});
}
}
}
</script>
<style lang="scss" scoped>
</style>