mirror of
https://github.com/OpenListTeam/OpenList-Frontend.git
synced 2026-03-13 11:20:24 +00:00
feat: add aliyun office previewer
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<meta name="referrer" content="same-origin" />
|
||||
<meta name="generator" content="AList V3" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<script src="https://g.alicdn.com/IMM/office-js/1.1.5/aliyun-web-office-sdk.min.js" async></script>
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/ico"
|
||||
|
||||
6
src/index.d.ts
vendored
6
src/index.d.ts
vendored
@@ -1 +1,7 @@
|
||||
declare module "aplayer";
|
||||
declare namespace aliyun {
|
||||
class Config {
|
||||
setToken(token: { token: string }): any;
|
||||
}
|
||||
function config(options: { mount: Element; url: string }): Config;
|
||||
}
|
||||
36
src/pages/home/previews/aliyun_office.tsx
Normal file
36
src/pages/home/previews/aliyun_office.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Box } from "@hope-ui/solid";
|
||||
import { MaybeLoading } from "~/components";
|
||||
import { useFetch, useRouter } from "~/hooks";
|
||||
import { password } from "~/store";
|
||||
import { Resp } from "~/types";
|
||||
import { handleRresp, r } from "~/utils";
|
||||
|
||||
const AliDocPreview = () => {
|
||||
const { pathname } = useRouter();
|
||||
const [loading, post] = useFetch(
|
||||
(): Promise<Resp<{ access_token: string; preview_url: string }>> =>
|
||||
r.post("/fs/other", {
|
||||
path: pathname(),
|
||||
password: password(),
|
||||
method: "doc_preview"
|
||||
})
|
||||
);
|
||||
const init = async () => {
|
||||
const resp = await post();
|
||||
handleRresp(resp, (data) => {
|
||||
const docOptions = aliyun.config({
|
||||
mount: document.querySelector("#office-preview")!,
|
||||
url: data.preview_url,
|
||||
});
|
||||
docOptions.setToken({ token: data.access_token });
|
||||
});
|
||||
};
|
||||
init();
|
||||
return (
|
||||
<MaybeLoading loading={loading()}>
|
||||
<Box w="$full" h="70vh" id="office-preview"></Box>
|
||||
</MaybeLoading>
|
||||
);
|
||||
};
|
||||
|
||||
export default AliDocPreview;
|
||||
@@ -55,6 +55,12 @@ const previews: Preview[] = [
|
||||
exts: ["plist"],
|
||||
component: lazy(() => import("./plist")),
|
||||
},
|
||||
{
|
||||
name: "Aliyun Office Previewer",
|
||||
exts: ["doc", "docx", "ppt", "pptx", "xls", "xlsx", "pdf"],
|
||||
provider: /Aliyundrive/,
|
||||
component: lazy(() => import("./aliyun_office")),
|
||||
},
|
||||
];
|
||||
|
||||
export const getPreviews = (
|
||||
|
||||
Reference in New Issue
Block a user