|
@@ -103,7 +103,7 @@
|
|
|
<div class="redeem_code_title">兑换码</div>
|
|
|
<div class="redeem_code_num">
|
|
|
<span class="code_num">{{prizeCode}}</span>
|
|
|
- <span @click="handleCopy">复制</span>
|
|
|
+ <span @click="handleCopy(prizeCode)">复制</span>
|
|
|
</div>
|
|
|
<image class="redeem_erCode" :src="urlQrCode"></image>
|
|
|
</div>
|
|
@@ -130,12 +130,41 @@
|
|
|
this.urlQrCode = this.getQueryParam('urlQrCode')
|
|
|
},
|
|
|
methods: {
|
|
|
- handleCopy () {
|
|
|
- navigator.clipboard.writeText(this.prizeCode)
|
|
|
- this.$message({
|
|
|
- message: "复制成功",
|
|
|
- type: 'success'
|
|
|
- })
|
|
|
+ // 检测是否iOS端
|
|
|
+ iosAgent() {
|
|
|
+ return navigator.userAgent.match(/(iPhone|iPod|iPad);?/i);
|
|
|
+ },
|
|
|
+ // 复制文本函数,微信端,需要在用户触发 Click 事件里面才能执行成功
|
|
|
+ handleCopy(message) {
|
|
|
+ if (this.iosAgent()) {
|
|
|
+ let inputObj = document.createElement("input");
|
|
|
+ inputObj.value = message;
|
|
|
+ document.body.appendChild(inputObj);
|
|
|
+ inputObj.select();
|
|
|
+ inputObj.setSelectionRange(0, inputObj.value.length);
|
|
|
+ this.execCommand('Copy');
|
|
|
+ document.body.removeChild(inputObj);
|
|
|
+ } else {
|
|
|
+ let domObj = document.createElement("span");
|
|
|
+ domObj.innerHTML = message;
|
|
|
+ document.body.appendChild(domObj);
|
|
|
+ let selection = window.getSelection();
|
|
|
+ let range = document.createRange();
|
|
|
+ range.selectNodeContents(domObj);
|
|
|
+ selection.removeAllRanges();
|
|
|
+ selection.addRange(range);
|
|
|
+ this.execCommand('Copy');
|
|
|
+ document.body.removeChild(domObj);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 执行浏览器命令 Copy 顺便输出一下日志,如果在移动端推荐写个方法展示日志或者用alert(msg)也行。
|
|
|
+ execCommand(action) {
|
|
|
+ let is = document.execCommand(action);
|
|
|
+ if (is) {
|
|
|
+ console.log("复制成功");
|
|
|
+ } else {
|
|
|
+ console.log("复制失败");
|
|
|
+ }
|
|
|
},
|
|
|
// 截取url中的数据
|
|
|
getQueryParam (paramName) {
|