新增分享页,以及BUG修复

This commit is contained in:
kron
2025-11-05 09:36:37 +08:00
parent 802d21a896
commit ecdf4a76f4
6 changed files with 509 additions and 55 deletions

View File

@@ -1,5 +1,5 @@
<script setup>
import { ref, watch, onMounted } from "vue";
import { ref, watch, onMounted, computed } from "vue";
import { getPointBookConfigAPI } from "@/apis";
const props = defineProps({
itemIndex: {
@@ -34,6 +34,11 @@ const groupArrows = [3, 6, 12, 18];
const data = ref([]);
const selectedIndex = ref(-1);
const secondSelectIndex = ref(-1);
const meter = ref("");
const sets = ref("");
const arrowAmount = ref("");
const onSelectItem = (index) => {
selectedIndex.value = index;
if (props.itemIndex === 0) {
@@ -42,11 +47,13 @@ const onSelectItem = (index) => {
props.onSelect(props.itemIndex, distances[index]);
} else if (props.itemIndex === 2) {
props.onSelect(props.itemIndex, data.value[index]);
} else if (props.itemIndex === 3 && secondSelectIndex.value !== -1) {
props.onSelect(
props.itemIndex,
`${selectedIndex.value}/${groupArrows[secondSelectIndex.value]}`
);
} else if (props.itemIndex === 3) {
if (secondSelectIndex.value !== -1) {
props.onSelect(
props.itemIndex,
`${selectedIndex.value}/${groupArrows[secondSelectIndex.value]}`
);
}
}
};
const onSelectSecondItem = (index) => {
@@ -54,36 +61,39 @@ const onSelectSecondItem = (index) => {
if (selectedIndex.value !== -1) {
props.onSelect(
props.itemIndex,
`${selectedIndex.value}/${groupArrows[secondSelectIndex.value]}`
);
}
};
const meter = ref("");
const onMeterChange = (e) => {
meter.value = e.detail.value;
props.onSelect(props.itemIndex, e.detail.value);
};
const sets = ref(null);
const onSetsChange = (e) => {
sets.value = e.detail.value;
if (!sets.value) return;
if (arrowAmount.value || groupArrows[secondSelectIndex.value]) {
props.onSelect(
props.itemIndex,
`${e.detail.value}/${
arrowAmount.value || groupArrows[secondSelectIndex.value]
`${selectedIndex.value < 5 ? selectedIndex.value : sets.value}/${
groupArrows[secondSelectIndex.value]
}`
);
}
};
const onMeterChange = (e) => {
meter.value = e.detail.value;
props.onSelect(props.itemIndex, e.detail.value);
};
const onSetsChange = (e) => {
sets.value = e.detail.value;
if (!sets.value) return;
if (secondSelectIndex.value !== -1) {
props.onSelect(
props.itemIndex,
`${sets.value}/${
secondSelectIndex === 99
? arrowAmount.value
: groupArrows[secondSelectIndex.value]
}`
);
}
};
const arrowAmount = ref("");
const onArrowAmountChange = (e) => {
arrowAmount.value = e.detail.value;
if (!arrowAmount.value) return;
if (sets.value || selectedIndex.value !== -1) {
if (selectedIndex.value !== -1) {
props.onSelect(
props.itemIndex,
`${sets.value || selectedIndex.value}/${e.detail.value}`
`${selectedIndex.value === 99 ? sets.value : selectedIndex.value}/${
arrowAmount.value
}`
);
}
};
@@ -138,6 +148,15 @@ const loadConfig = () => {
}
}
};
const formatSetAndAmount = computed(() => {
if (selectedIndex.value === -1 || secondSelectIndex.value === -1)
return itemTexts[props.itemIndex];
return `${selectedIndex.value === 99 ? sets.value : selectedIndex.value}组/${
secondSelectIndex.value === 99
? arrowAmount.value
: groupArrows[secondSelectIndex.value]
}`;
});
onMounted(async () => {
const config = uni.getStorageSync("point-book-config");
if (config) {
@@ -173,9 +192,7 @@ onMounted(async () => {
value || itemTexts[itemIndex]
}}</text>
<text :style="{ opacity: expand ? 0 : 1 }" v-if="itemIndex === 3">{{
selectedIndex !== -1 && secondSelectIndex !== -1
? `${selectedIndex}/${groupArrows[secondSelectIndex]}`
: itemTexts[itemIndex]
formatSetAndAmount
}}</text>
</block>
<button hover-class="none">
@@ -218,7 +235,6 @@ onMounted(async () => {
}"
>
<input
v-model="meter"
placeholder="自定义"
placeholder-style="color: #DDDDDD"
@focus="() => (selectedIndex = 9)"
@@ -255,15 +271,14 @@ onMounted(async () => {
</view>
<view
:style="{
borderColor: selectedIndex === 5 ? '#fed847' : '#eeeeee',
borderColor: selectedIndex === 99 ? '#fed847' : '#eeeeee',
}"
>
<input
v-model="sets"
placeholder="自定义"
type="number"
placeholder-style="color: #DDDDDD"
@focus="() => (selectedIndex = 5)"
@focus="() => (selectedIndex = 99)"
@change="onSetsChange"
/>
<text></text>
@@ -287,15 +302,14 @@ onMounted(async () => {
</view>
<view
:style="{
borderColor: secondSelectIndex === 4 ? '#fed847' : '#eeeeee',
borderColor: secondSelectIndex === 99 ? '#fed847' : '#eeeeee',
}"
>
<input
v-model="arrowAmount"
placeholder="自定义"
type="number"
placeholder-style="color: #DDDDDD"
@focus="() => (secondSelectIndex = 4)"
@focus="() => (secondSelectIndex = 99)"
@change="onArrowAmountChange"
/>
<text></text>

View File

@@ -1,5 +1,5 @@
<script setup>
import { ref, onMounted } from "vue";
import { ref, onMounted, computed } from "vue";
const props = defineProps({
data: {
@@ -8,13 +8,16 @@ const props = defineProps({
},
onRemove: {
type: Function,
default: () => {},
default: null,
},
});
const bowOptions = ref({});
const targetOptions = ref({});
// 使用插槽自定义右侧按钮为图标,若需要文字按钮可恢复 rightOptions
// 根据是否传入 onRemove 来决定是否允许左滑
const canSwipe = computed(() => typeof props.onRemove === "function");
const toDetailPage = () => {
uni.navigateTo({
url: `/pages/point-book-detail?id=${props.data.id}`,
@@ -38,12 +41,14 @@ const onSwipeActionClick = () => {
<template>
<uni-swipe-action>
<uni-swipe-action-item
@change="() => {}"
>
<template v-slot:right>
<uni-swipe-action-item :disabled="!canSwipe" @change="() => {}">
<template v-slot:right v-if="canSwipe">
<view class="swipe-right" @click="onSwipeActionClick">
<image class="swipe-icon" src="../static/delete-white.png" mode="widthFix" />
<image
class="swipe-icon"
src="../static/delete-white.png"
mode="widthFix"
/>
</view>
</template>
<view class="container" @click="toDetailPage">