| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_auth = require("../../utils/auth.js");
- require("../../utils/api.js");
- const _sfc_main = {
- __name: "pool",
- setup(__props) {
- const isPurchased = common_vendor.ref(false);
- const showModal = common_vendor.ref(false);
- const showPhoneAuth = common_vendor.ref(false);
- const selectedPlan = common_vendor.ref("daily");
- const selectedDate = common_vendor.ref("2025年11月20日");
- const isLoggedIn = common_vendor.ref(false);
- const checkLogin = () => {
- isLoggedIn.value = utils_auth.isLoggedIn();
- console.log("[超短池] 登录状态:", isLoggedIn.value);
- return isLoggedIn.value;
- };
- const checkPurchaseStatus = () => {
- try {
- const purchaseInfo = common_vendor.index.getStorageSync("pool_purchase");
- if (purchaseInfo) {
- const now = Date.now();
- const expireTime = purchaseInfo.expireTime;
- if (now < expireTime) {
- isPurchased.value = true;
- } else {
- common_vendor.index.removeStorageSync("pool_purchase");
- isPurchased.value = false;
- }
- } else {
- isPurchased.value = false;
- }
- } catch (e) {
- console.error("检查购买状态失败:", e);
- isPurchased.value = false;
- }
- };
- const showPurchaseModal = () => {
- console.log("点击立即解锁");
- if (!checkLogin()) {
- console.log("未登录,显示手机号授权弹窗");
- showPhoneAuth.value = true;
- return;
- }
- console.log("已登录,显示购买弹窗");
- showModal.value = true;
- };
- const onGetPhoneNumber = async (e) => {
- console.log("[超短池] 获取手机号回调:", e.detail);
- if (e.detail.errMsg === "getPhoneNumber:ok") {
- const phoneCode = e.detail.code;
- console.log("[超短池] phoneCode:", phoneCode);
- common_vendor.index.showLoading({
- title: "登录中...",
- mask: true
- });
- try {
- const loginRes = await common_vendor.index.login();
- console.log("[超短池] uni.login完整响应:", loginRes);
- console.log("[超短池] 微信登录code:", loginRes.code);
- if (!loginRes.code) {
- throw new Error("获取微信登录code失败");
- }
- const result = await utils_auth.wxAuthLogin(loginRes.code, phoneCode);
- common_vendor.index.hideLoading();
- if (result) {
- showPhoneAuth.value = false;
- checkLogin();
- showModal.value = true;
- }
- } catch (error) {
- common_vendor.index.hideLoading();
- console.error("[超短池] 登录失败:", error);
- }
- } else {
- showPhoneAuth.value = false;
- common_vendor.index.showToast({
- title: "需要授权手机号才能完成登录",
- icon: "none",
- duration: 2e3
- });
- }
- };
- const closePhoneAuth = () => {
- showPhoneAuth.value = false;
- };
- const closePurchaseModal = () => {
- showModal.value = false;
- };
- const handlePurchase = () => {
- if (!selectedPlan.value) {
- common_vendor.index.showToast({
- title: "请选择订阅方案",
- icon: "none"
- });
- return;
- }
- const now = Date.now();
- let expireTime = now;
- if (selectedPlan.value === "daily") {
- const today = /* @__PURE__ */ new Date();
- today.setHours(23, 59, 59, 999);
- expireTime = today.getTime();
- } else if (selectedPlan.value === "weekly") {
- expireTime = now + 7 * 24 * 60 * 60 * 1e3;
- }
- const purchaseInfo = {
- plan: selectedPlan.value,
- purchaseTime: now,
- expireTime
- };
- common_vendor.index.setStorageSync("pool_purchase", purchaseInfo);
- isPurchased.value = true;
- closePurchaseModal();
- common_vendor.index.showToast({
- title: "解锁成功",
- icon: "success"
- });
- };
- const onHistorySearch = () => {
- common_vendor.index.showToast({
- title: "历史查询功能开发中",
- icon: "none"
- });
- };
- common_vendor.onLoad(() => {
- checkLogin();
- checkPurchaseStatus();
- });
- common_vendor.onShow(() => {
- checkLogin();
- checkPurchaseStatus();
- });
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: !isPurchased.value
- }, !isPurchased.value ? {
- b: common_vendor.o(showPurchaseModal)
- } : {}, {
- c: selectedDate.value,
- d: common_vendor.o(($event) => selectedDate.value = $event.detail.value),
- e: common_vendor.o(onHistorySearch),
- f: showPhoneAuth.value
- }, showPhoneAuth.value ? {
- g: common_vendor.o(onGetPhoneNumber),
- h: common_vendor.o(() => {
- }),
- i: common_vendor.o(closePhoneAuth)
- } : {}, {
- j: showModal.value
- }, showModal.value ? {
- k: common_vendor.o(closePurchaseModal),
- l: selectedPlan.value === "daily" ? 1 : "",
- m: common_vendor.o(($event) => selectedPlan.value = "daily"),
- n: selectedPlan.value === "weekly" ? 1 : "",
- o: common_vendor.o(($event) => selectedPlan.value = "weekly"),
- p: common_vendor.o(handlePurchase),
- q: common_vendor.o(() => {
- }),
- r: common_vendor.o(closePurchaseModal)
- } : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao-wx/src/pages/pool/pool.vue"]]);
- wx.createPage(MiniProgramPage);
|