|
@@ -0,0 +1,63 @@
|
|
|
|
+import Taro, { FC, useDidHide, useDidShow, useRouter } from "@tarojs/taro";
|
|
|
|
+import { useEffect, useRef } from "react";
|
|
|
|
+
|
|
|
|
+const DocumentPage: FC = () => {
|
|
|
|
+ const route = useRouter();
|
|
|
|
+ const goBack = useRef(false);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (!route.params.url) {
|
|
|
|
+ Taro.showToast({
|
|
|
|
+ title: "请传入url",
|
|
|
|
+ icon: "error",
|
|
|
|
+ duration: 3000,
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Taro.showLoading({
|
|
|
|
+ title: "加载中",
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Taro.downloadFile({
|
|
|
|
+ url: decodeURIComponent(route.params.url),
|
|
|
|
+ success(res) {
|
|
|
|
+ Taro.openDocument({
|
|
|
|
+ filePath: res.tempFilePath,
|
|
|
|
+ // @ts-ignore
|
|
|
|
+ fileType: route.params.fileType || "pdf",
|
|
|
|
+ showMenu: true,
|
|
|
|
+ success() {
|
|
|
|
+ Taro.hideLoading();
|
|
|
|
+ },
|
|
|
|
+ fail(res) {
|
|
|
|
+ Taro.showToast({
|
|
|
|
+ title: res.errMsg,
|
|
|
|
+ icon: "none",
|
|
|
|
+ duration: 3000,
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ fail(res) {
|
|
|
|
+ Taro.showToast({
|
|
|
|
+ title: res.errMsg,
|
|
|
|
+ icon: "none",
|
|
|
|
+ duration: 3000,
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ useDidShow(() => {
|
|
|
|
+ goBack.current && Taro.navigateBack();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ useDidHide(() => {
|
|
|
|
+ goBack.current = true;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export default DocumentPage;
|