update:对接会员限制次数
This commit is contained in:
@@ -8,14 +8,16 @@ import SModal from "@/components/SModal.vue";
|
||||
import Signin from "@/components/Signin.vue";
|
||||
import CreateRoom from "@/components/CreateRoom.vue";
|
||||
import Avatar from "@/components/Avatar.vue";
|
||||
import ModalDialog from "@/components/ModalDialog.vue";
|
||||
|
||||
import { getRoomAPI, joinRoomAPI, getBattleDataAPI } from "@/apis";
|
||||
import { debounce, canEenter } from "@/util";
|
||||
import { getRoomAPI, joinRoomAPI, getBattleDataAPI, getDailyCountAPI } from "@/apis";
|
||||
import { debounce, canEenter, getLimitCountText, isLimitReached } from "@/util";
|
||||
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const store = useStore();
|
||||
const { user, device, online, game } = storeToRefs(store);
|
||||
const { user, device, online, game, dailyCount } = storeToRefs(store);
|
||||
const { updateDailyCount } = store;
|
||||
|
||||
const showModal = ref(false);
|
||||
const showSignin = ref(false);
|
||||
@@ -24,8 +26,12 @@ const roomNumber = ref("");
|
||||
const data = ref({});
|
||||
const roomID = ref("");
|
||||
const loading = ref(false);
|
||||
const showLimitModal = ref(false);
|
||||
const isSVip = computed(() => user.value.sVip === true);
|
||||
const isVip = computed(() => user.value.vip === true && !isSVip.value);
|
||||
const challengeLimitText = computed(() =>
|
||||
getLimitCountText("约战", dailyCount.value.challenge)
|
||||
);
|
||||
|
||||
const enterRoom = debounce(async (number) => {
|
||||
if (loading.value) return;
|
||||
@@ -67,9 +73,37 @@ const enterRoom = debounce(async (number) => {
|
||||
});
|
||||
const onCreateRoom = async () => {
|
||||
if (!canEenter(user.value, device.value, online.value)) return;
|
||||
const countData = await loadDailyCount();
|
||||
if (isLimitReached(countData.challenge)) {
|
||||
showLimitModal.value = true;
|
||||
return;
|
||||
}
|
||||
warnning.value = "";
|
||||
showModal.value = true;
|
||||
};
|
||||
|
||||
const closeLimitModal = () => {
|
||||
showLimitModal.value = false;
|
||||
};
|
||||
|
||||
const goVipPage = () => {
|
||||
showLimitModal.value = false;
|
||||
uni.navigateTo({
|
||||
url: "/pages/member/be-vip",
|
||||
});
|
||||
};
|
||||
|
||||
const loadDailyCount = async () => {
|
||||
if (!user.value.id) return dailyCount.value;
|
||||
try {
|
||||
const result = await getDailyCountAPI();
|
||||
updateDailyCount(result);
|
||||
return result || dailyCount.value;
|
||||
} catch (error) {
|
||||
console.log("load daily count error", error);
|
||||
return dailyCount.value;
|
||||
}
|
||||
};
|
||||
const onSignin = () => {
|
||||
if (roomID.value && user.value.id) enterRoom(roomID.value);
|
||||
showSignin.value = false;
|
||||
@@ -83,7 +117,10 @@ const goMyRecord = () => {
|
||||
};
|
||||
onShow(async () => {
|
||||
if (user.value.id) {
|
||||
const result = await getBattleDataAPI();
|
||||
const [result] = await Promise.all([
|
||||
getBattleDataAPI(),
|
||||
loadDailyCount(),
|
||||
]);
|
||||
data.value = result;
|
||||
}
|
||||
});
|
||||
@@ -168,8 +205,8 @@ onLoad(async (options) => {
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<view class="pp-text">
|
||||
<!-- 今日约战次数:2/2 -->
|
||||
<view v-if="challengeLimitText" class="pp-text">
|
||||
{{ challengeLimitText }}
|
||||
</view>
|
||||
<SButton width="80%" :rounded="30" :onClick="() => $clickSound(onCreateRoom)">
|
||||
创建约战房
|
||||
@@ -186,6 +223,14 @@ onLoad(async (options) => {
|
||||
<Signin :show="showSignin" :onClose="onSignin" />
|
||||
</view>
|
||||
</Container>
|
||||
<ModalDialog
|
||||
:show="showLimitModal"
|
||||
:content="'今日约战次数已经用完\n开通会员可增加次数'"
|
||||
cancelText="知道了"
|
||||
confirmText="去开通"
|
||||
:onCancel="closeLimitModal"
|
||||
:onConfirm="goVipPage"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user