Skip to content

Commit

Permalink
refactor(webview): get target url from encoded url query (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
j10ccc authored Nov 4, 2024
1 parent 17c625a commit 40e2e0a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
14 changes: 14 additions & 0 deletions src/hooks/useWebview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Taro from "@tarojs/taro";

export default function useWebview() {
function open(url: string) {
const encoded = encodeURIComponent(url);
Taro.navigateTo({
url: `/pages/webview/index?target=${encoded}`
});
}

return {
open
};
}
8 changes: 3 additions & 5 deletions src/pages/announcement/InformationCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import Taro from "@tarojs/taro";
import { Information } from "@/types/Information";
import styles from "./index.module.scss";
import { Card } from "@/components";
import store from "@/store";
import dayjs from "dayjs";
import useWebview from "@/hooks/useWebview";
const { open } = useWebview();
const props = defineProps<{
source: Information;
}>();
const handleClickLink = () => {
store.commit("setTempUrl", { url: props.source.link });
Taro.navigateTo({
url: "/pages/webview/index"
});
open(props.source.link);
};
const handleClick = () => {
Expand Down
11 changes: 4 additions & 7 deletions src/pages/bind/YXY/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { useRequestNext } from "@/hooks";
import { RequestError } from "@/utils";
import useUserStore from "@/store/service/user";
import useHomeCardStore from "@/store/service/homecard";
import useWebview from "@/hooks/useWebview";
const { updateBindState } = useUserStore();
const homeCardStore = useHomeCardStore();
const { open } = useWebview();
const phoneNumber = ref("");
const graphCode = ref("");
Expand Down Expand Up @@ -83,13 +85,8 @@ const handleBind = async () => {
};
const handleClickTutorial = () => {
// TODO: encode url
// store.commit("setTempUrl", {
// url: "https://mp.weixin.qq.com/s/uFdF37XSznzPMOe_IfjrEQ"
// });
Taro.navigateTo({
url: "/pages/webview/index"
});
// TODO: 链接放到配置平台
open("https://mp.weixin.qq.com/s/uFdF37XSznzPMOe_IfjrEQ");
};
onMounted(() => {
Expand Down
19 changes: 10 additions & 9 deletions src/pages/information/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{ information.content.replace(/\\n/g, '\n') }}
</view>
<view v-if="information.img1" class="img_container">
<image
<taro-image
:src="information.img1"
alt="Card Image"
class="image"
Expand All @@ -22,7 +22,7 @@
/>
</view>
<view v-if="information.img2" class="img_container">
<image
<taro-image
:src="information.img2"
alt="Card Image"
class="image"
Expand All @@ -32,7 +32,7 @@
/>
</view>
<view v-if="information.img3" class="img_container">
<image
<taro-image
:src="information.img3"
alt="Card Image"
class="image"
Expand All @@ -46,7 +46,7 @@
</view>
<template #footer>
<view class="logo_container">
<image
<taro-image
src="https://api.cnpatrickstar.com/img/92a63e97-cd3e-411b-b4aa-8e6fad5fbd00.jpg"
alt="logo_fy"
class="logo_fy"
Expand All @@ -55,7 +55,7 @@
<view class="x">
X
</view>
<image
<taro-image
src="https://api.cnpatrickstar.com/img/15c05a4c-7c2d-4561-9536-80614b7b65b8.jpg"
alt="logo_jh"
class="logo_jh"
Expand All @@ -76,20 +76,21 @@

<script setup lang="ts">
import { Card, ThemeConfig, TitleBar } from "@/components";
import { serviceStore } from "@/store";
import { computed, ref } from "vue";
import Taro from "@tarojs/taro";
import dayjs from "dayjs";
import { Image as TaroImage } from "@tarojs/components";
import "./index.scss";
import useNotificationStore from "@/store/service/notification";
const notificationStore = useNotificationStore();
const instance = Taro.getCurrentInstance();
const needFixWidth = ref(false);
const { informationId } = instance.router?.params as { informationId?: number };
const id = instance.router?.params.informationId;
const information = computed(() => {
return serviceStore.information.informationList.find((information) => information.id == informationId)!;
return notificationStore.information.find((item) => String(item.id) === id)!;
});
const imageList = computed(() => [
Expand Down
7 changes: 4 additions & 3 deletions src/pages/schoolbus/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<web-view :src="schoolBusUrl" />
<web-view :src="generalInfo.schoolBusUrl" />
</template>

<script setup lang="ts">
import { systemStore } from "@/store";
import "./index.scss";
import useGeneralInfoStore from "@/store/system/generalInfo";
import { storeToRefs } from "pinia";
const schoolBusUrl = systemStore.generalInfo.schoolBusUrl;
const { info: generalInfo } = storeToRefs(useGeneralInfoStore());
</script>
14 changes: 5 additions & 9 deletions src/pages/webview/index.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<template>
<web-view :src="url" />
<web-view :src="target" />
</template>

<script setup lang="ts">
import store, { serviceStore } from "@/store";
import Taro from "@tarojs/taro";
const url = serviceStore.webview.tempUrl;
store.commit("clearTemp");
const router = Taro.getCurrentInstance().router;
const target = decodeURIComponent(router?.params["target"] ?? "");
if (!url) {
Taro.showModal({
title: "未找到页面"
});
throw new Error("invalid access");
if (!target) {
Taro.showModal({ title: "未找到页面" });
}
</script>

0 comments on commit 40e2e0a

Please sign in to comment.