feat: complete

This commit is contained in:
Rogee
2024-12-13 21:28:43 +08:00
parent 13ebc91220
commit 7aebb161f6
13 changed files with 219 additions and 161 deletions

View File

@@ -3,7 +3,7 @@
<template #title>
<van-button block size="small" type="primary" plain @click="loadChargeCodes">刷新充值码</van-button>
</template>
<van-cell v-for="c in codes" size="large" :title="getCodeAmountTitle(c)" :value="c.code" @click="copyCode(c)" />
<van-cell v-for="c in codes" size="large" :title="getCodeAmountTitle(c)" :value="c.code" />
</van-cell-group>
</template>
@@ -32,14 +32,6 @@ export default defineComponent({
return code.amount / 100 + " 元/ " + code.amount + " 点";
};
const copyCode = (code) => {
navigator.clipboard.writeText(code.code).then(() => {
showSuccessToast('充值码已复制');
}).catch((err) => {
showFailToast('复制失败');
});
};
onMounted(() => {
loadChargeCodes();
});
@@ -47,7 +39,6 @@ export default defineComponent({
return {
codes,
getCodeAmountTitle,
copyCode,
loadChargeCodes,
}
}

View File

@@ -1,5 +1,5 @@
<template>
<van-notice-bar left-icon="volume-o" :text="'购买充值码请添加客服微信:' + contact + '(点击复制微信号)'" @click="copyCode(contact)" />
<van-notice-bar left-icon="volume-o" :text="'购买充值码请添加客服微信:' + contact" />
</template>
@@ -12,15 +12,6 @@ export default defineComponent({
contact: String,
},
setup(props) {
const copyCode = (code) => {
navigator.clipboard.writeText(code).then(() => {
showSuccessToast('客服微信已复制');
}).catch((err) => {
showFailToast('复制失败');
});
};
return {
copyCode,
}

View File

@@ -1,5 +1,8 @@
import NotFound from '@/views/NotFound.vue';
import PlayView from '@/views/PlayView.vue';
import BoughtView from '@/views/tabs/BoughtView.vue';
import HomeView from '@/views/tabs/HomeView.vue';
import UserView from '@/views/tabs/UserView.vue';
import TabView from '@/views/TabView.vue';
const routes = [
@@ -22,7 +25,7 @@ const routes = [
{
path: 'bought',
name: 'tab.bought',
component: () => import('@/views/tabs/BoughtView.vue'),
component: BoughtView,
meta: {
title: '已购买',
keepAlive: true,
@@ -35,7 +38,7 @@ const routes = [
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('@/views/tabs/UserView.vue'),
component: UserView,
meta: {
title: '个人中心',
keepAlive: false,
@@ -46,7 +49,7 @@ const routes = [
{
path: '/t/:tenant/play/:hash',
name: 'play',
component: () => import('@/views/PlayView.vue'),
component: PlayView,
meta: {
title: '播放',
keepAlive: false,

View File

@@ -0,0 +1,44 @@
const copy = (text) => {
// 数字没有 .length 不能执行selectText 需要转化成字符串
const textString = text.toString();
const input = document.createElement('input');
input.id = 'copy-input';
input.readOnly = true; // 防止ios聚焦触发键盘事件
input.style.position = 'absolute';
input.style.left = '-1000px';
input.style.zIndex = '-1000';
document.body.appendChild(input);
input.value = textString;
// ios必须先选中文字且不支持 input.select();
selectText(input, 0, textString.length);
input.blur();
document.body.removeChild(input); // 使用完成后,移除 input 元素,避免占用页面高度
// input自带的select()方法在苹果端无法进行选择,所以需要自己去写一个类似的方法
// 选择文本。createTextRange(setSelectionRange)是input方法
function selectText(textBox, startIndex, stopIndex) {
if (textBox.createTextRange) {
//ie
const range = textBox.createTextRange();
range.collapse(true);
range.moveStart('character', startIndex); //起始光标
range.moveEnd('character', stopIndex - startIndex); //结束光标
range.select(); //不兼容苹果
} else {
//firefox/chrome
textBox.setSelectionRange(startIndex, stopIndex);
textBox.focus();
}
}
console.log(document.execCommand('copy'), 'execCommand');
if (document.execCommand('copy')) {
document.execCommand('copy');
return true
}
return false
};
export default copy;