@@ -0,0 +1,42 @@ | |||||
export default function uniCopy({content,success,error}) { | |||||
if(!content) return error('复制的内容不能为空 !') | |||||
content = typeof content === 'string' ? content : content.toString() // 复制内容,必须字符串,数字需要转换为字符串 | |||||
/** | |||||
* 小程序端 和 app端的复制逻辑 | |||||
*/ | |||||
//#ifndef H5 | |||||
uni.setClipboardData({ | |||||
data: content, | |||||
success: function() { | |||||
success("复制成功~") | |||||
console.log('success'); | |||||
}, | |||||
fail:function(){ | |||||
success("复制失败~") | |||||
} | |||||
}); | |||||
//#endif | |||||
/** | |||||
* H5端的复制逻辑 | |||||
*/ | |||||
// #ifdef H5 | |||||
if (!document.queryCommandSupported('copy')) { //为了兼容有些浏览器 queryCommandSupported 的判断 | |||||
// 不支持 | |||||
error('浏览器不支持') | |||||
} | |||||
let textarea = document.createElement("textarea") | |||||
textarea.value = content | |||||
textarea.readOnly = "readOnly" | |||||
document.body.appendChild(textarea) | |||||
textarea.select() // 选择对象 | |||||
textarea.setSelectionRange(0, content.length) //核心 | |||||
let result = document.execCommand("copy") // 执行浏览器复制命令 | |||||
if(result){ | |||||
success("复制成功~") | |||||
}else{ | |||||
error("复制失败,请检查h5中调用该方法的方式,是不是用户点击的方式调用的,如果不是请改为用户点击的方式触发该方法,因为h5中安全性,不能js直接调用!") | |||||
} | |||||
textarea.remove() | |||||
// #endif | |||||
} |
@@ -28,6 +28,8 @@ | |||||
<l-tag v-if="root.type !== 'user' || staffTag" :line="tagColor" size="sm" class="margin-left-sm"> | <l-tag v-if="root.type !== 'user' || staffTag" :line="tagColor" size="sm" class="margin-left-sm"> | ||||
{{ tagName }} | {{ tagName }} | ||||
</l-tag> | </l-tag> | ||||
<!-- <uni-view v-if="root.type === 'user' && mobile" class="margin-left-sm sm line-gray cu-tag" style="z-index: 1;" @tap="copy(mobile)">复制</uni-view> --> | |||||
<!-- 开启按钮显示且级别对应,则显示按钮 --> | <!-- 开启按钮显示且级别对应,则显示按钮 --> | ||||
<view v-if="button && root.type === level" class="tree-item-action"> | <view v-if="button && root.type === level" class="tree-item-action"> | ||||
@@ -57,6 +59,7 @@ | |||||
</template> | </template> | ||||
<script> | <script> | ||||
import uniCopy from "@/common/js/uni-copy.js" | |||||
export default { | export default { | ||||
name: 'l-organize-tree', | name: 'l-organize-tree', | ||||
@@ -160,7 +163,27 @@ export default { | |||||
this.isLoadOk = true | this.isLoadOk = true | ||||
this.isOpen = true | this.isOpen = true | ||||
this.isLoading = false | this.isLoading = false | ||||
} | |||||
}, | |||||
copy(mobile){ | |||||
uniCopy({ | |||||
content:mobile, | |||||
success:(res)=>{ | |||||
uni.showToast({ | |||||
title: "复制手机号成功~", | |||||
icon: 'none', | |||||
duration:3000, | |||||
}) | |||||
}, | |||||
error:(e)=>{ | |||||
uni.showToast({ | |||||
title: e, | |||||
icon: 'none', | |||||
duration:3000, | |||||
}) | |||||
} | |||||
}) | |||||
} | |||||
}, | }, | ||||
computed: { | computed: { | ||||