hsy 2 hete
szülő
commit
83c3bd5668

BIN
src/assets/icon-link-error.png


+ 0 - 4
src/router/modules/login.ts

@@ -13,8 +13,4 @@ export default [
       title: "",
     },
   },
-  {
-    path: "/:pathMatch(.*)",
-    component: () => import("@/views/entry.vue"),
-  },
 ] as RouteConfigsTable[];

+ 10 - 0
src/router/modules/open.ts

@@ -0,0 +1,10 @@
+export default [
+  {
+    path: "/error",
+    name: "error",
+    component: () => import("@/views/open/error.vue"),
+    meta: {
+      title: '会员权益'
+    },
+  }
+] as RouteConfigsTable[];

+ 10 - 2
src/router/modules/promotion.ts

@@ -4,7 +4,15 @@ export default [
     name: "promotionGoods",
     component: () => import("@/views/promotion/goods.vue"),
     meta: {
-      title: '会员权益'
+      title: "会员权益",
     },
-  }
+  },
+  {
+    path: "/promotion/payResult",
+    name: "promotionPayResult",
+    component: () => import("@/views/promotion/payResult.vue"),
+    meta: {
+      title: "支付完成",
+    },
+  },
 ] as RouteConfigsTable[];

+ 24 - 0
src/views/open/error.vue

@@ -0,0 +1,24 @@
+<template>
+  <div class="h-screen flex items-center justify-center flex-col">
+    <img src="@/assets/icon-link-error.png" alt="" class="w-40">
+    <div class="text-xl mt-4 text-gray-600">{{ msg}}</div>
+  </div>
+</template>
+
+<script setup>
+import { ref, reactive, onMounted, computed, watch } from 'vue';
+
+import { useRoute, useRouter } from 'vue-router';
+
+import { request } from '@/utils';
+
+const [route, router] = [useRoute(), useRouter()];
+const msg = ref(route.query.msg || '未知错误');
+document.title = msg.value;
+
+</script>
+
+<style lang='scss' scoped>
+
+</style>
+

+ 75 - 40
src/views/promotion/goods.vue

@@ -43,7 +43,7 @@
     </div>
     <div class="relative -top-6 rounded rounded-t-2xl bg-white z-10">
       <div class="p-4 pb-20">
-        <div class="" v-html="goodsDetail.memberCard?.content"></div>
+        <div class="" v-html="goodsDetail.saleSlogan"></div>
       </div>
     </div>
 
@@ -98,18 +98,30 @@ const handleClose = () => {
   showDialog.value = false;
 };
 function onBridgeReady(paySign) {
+  if (!WeixinJSBridge) {
+    return showToast("请在微信浏览器中打开");
+  }
   WeixinJSBridge.invoke(
     "getBrandWCPayRequest",
     {
       appId: appId.value, //公众号ID,由商户传入
-      ...paySign
+      ...paySign,
     },
     function (res) {
-      console.log(res)
+      console.log(res);
       if (res.err_msg == "get_brand_wcpay_request:ok") {
         // 使用以上方式判断前端返回,微信团队郑重提示:
         //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠,商户需进一步调用后端查单确认支付结果。
         console.log("支付成功");
+        router.push({
+          name: 'promotionPayResult',
+          query: {
+            promotionGoodsId: route.query.promotionGoodsId,
+            promotionSiteId: route.query.promotionSiteId,
+          }
+        })
+      } else {
+        showToast("支付失败" + res.err_msg);
       }
     }
   );
@@ -117,15 +129,18 @@ function onBridgeReady(paySign) {
 const handleConfirm = async (mobile, captcha) => {
   console.log("Payment confirmed");
   showDialog.value = false;
-  const { data } = await request.post(`/archivesService/member/promotionGoods/paymentParams`, {
-    promotionGoodsId: route.query.promotionGoodsId,
-    promotionSiteId: route.query.promotionSiteId,
-    mobile,
-    captcha,
-    openId: openId.value,
-  });
+  const { data } = await request.post(
+    `/archivesService/member/promotionGoods/paymentParams`,
+    {
+      promotionGoodsId: route.query.promotionGoodsId,
+      promotionSiteId: route.query.promotionSiteId,
+      mobile,
+      captcha,
+      openId: openId.value,
+    }
+  );
   console.log(data.paymentParams);
-  data.paymentParams?.paySign && onBridgeReady(data.paymentParams.paySign)
+  data.paymentParams?.paySign && onBridgeReady(data.paymentParams.paySign);
 };
 const buy = () => {
   showDialog.value = true;
@@ -142,44 +157,52 @@ const preCheck = async () => {
   );
   return data;
 };
-const jsSdkConfig = async () => {
-  const { data } = await request.post(
-    "archivesService/member/promotionGoods/getJssdk",
-    {
-      url: location.href,
-      promotionGoodsId: route.query.promotionGoodsId,
-    }
-  );
-  return data;
-};
-const wxConfig = async () => {
-  const { data } = await jsSdkConfig();
-  window["wx"]?.config?.(data.config);
-  window["wx"]?.error((res) => {
-    console.log(res);
-  });
-};
-const appId = ref(localStorage.getItem("appId"));
-const openId = ref("");
+// const jsSdkConfig = async () => {
+//   const { data } = await request.post(
+//     "archivesService/member/promotionGoods/getJssdk",
+//     {
+//       url: location.href,
+//       promotionGoodsId: route.query.promotionGoodsId,
+//     }
+//   );
+//   return data;
+// };
+// const wxConfig = async () => {
+//   const { data } = await jsSdkConfig();
+//   window["wx"]?.config?.(data.config);
+//   window["wx"]?.error((res) => {
+//     console.log(res);
+//   });
+// };
+const appId = ref(sessionStorage.getItem("appId"));
+const openId = ref("ozZpI7OTqj9cNlHfzAxcJ9MH41V8");
 const getWeChatAuth = async () => {
   const { appId, errMsg, paymentSettingId } = await preCheck();
   if (errMsg) {
-    return showToast(errMsg);
+    // return showToast(errMsg);
+    route.push({
+      name: "error",
+      query: {
+        msg: errMsg,
+      },
+    });
+    return;
   }
   if (appId) {
     //缓存信息
-    localStorage.setItem("appId", appId);
-    localStorage.setItem("paymentSettingId", paymentSettingId);
+    sessionStorage.setItem("appId", appId);
+    sessionStorage.setItem("paymentSettingId", paymentSettingId);
     //跳转微信授权
 
     const redirectUri = encodeURIComponent(location.href);
     location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`;
     return;
   }
+  showToast("微信配置不存在");
 };
 const getOpenId = async () => {
   const { code } = route.query;
-  const paymentSettingId = localStorage.getItem("paymentSettingId");
+  const paymentSettingId = sessionStorage.getItem("paymentSettingId");
   if (!code) {
     return;
   }
@@ -192,16 +215,28 @@ const getOpenId = async () => {
       },
     }
   );
-  openId.value = data.openId;
+  if (data.openId) {
+    openId.value = data.openId;
+  } else {
+    showToast("获取openId失败");
+  }
 };
 const init = async () => {
-  const { code } = route.query;
-  const paymentSettingId = localStorage.getItem("paymentSettingId");
+  const { code, promotionGoodsId, promotionSiteId } = route.query;
+  if (!promotionSiteId || !promotionGoodsId) {
+    return router.push({
+      name: "error",
+      query: {
+        msg: "参数异常",
+      },
+    });
+  }
+  const paymentSettingId = sessionStorage.getItem("paymentSettingId");
   if (!code || !paymentSettingId) {
-    return getWeChatAuth();
+    // return getWeChatAuth();
   }
-  getOpenId()
-  wxConfig();
+  // getOpenId()
+  // wxConfig();
 };
 onMounted(() => init());
 </script>

+ 39 - 0
src/views/promotion/payResult.vue

@@ -0,0 +1,39 @@
+<template>
+  <div>
+
+    <div class="flex items-center justify-center py-16">
+      <van-icon name="checked" class="text-[64px] text-green-500 mr-2" />
+      <span class="text-2xl font-bold text-green-600">购买成功!</span>
+    </div>
+    <div class="p-2">
+      <div v-html="goodsDetail.paidSlogan"></div>
+    </div>
+  </div>
+</template>
+
+<script setup>
+import { ref, reactive, onMounted, computed, watch } from 'vue';
+
+import { useRoute, useRouter } from 'vue-router';
+
+import { request } from '@/utils';
+
+const [route, router] = [useRoute(), useRouter()];
+const goodsDetail = ref({});
+const getGoodsDetail = async () => {
+  const { data } = await request.get(
+    `archivesService/member/promotionGoods/detail`,
+    {
+      params: {
+        promotionGoodsId: route.query.promotionGoodsId,
+      },
+    }
+  );
+  goodsDetail.value = data.detail;
+};
+getGoodsDetail();
+</script>
+
+<style lang='scss' scoped>
+
+</style>