mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
office: update loader
This commit is contained in:
1 parent
a38efa9b11
commit
7342bbd0c3
2 files changed
+38
-64
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/onlyoffice",
|
"name": "@hydrooj/onlyoffice",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
|
|||||||
@@ -1,31 +1,27 @@
|
|||||||
(() => {
|
(() => {
|
||||||
const { AutoloadPage } = window.Hydro;
|
const { AutoloadPage } = window.Hydro;
|
||||||
const { $ } = window.node_modules;
|
const { $ } = window.node_modules;
|
||||||
const { request } = window.Hydro.utils;
|
|
||||||
|
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
async function load() {
|
async function load() {
|
||||||
if (loaded) return Promise.resolve();
|
if (loaded) return Promise.resolve();
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
const scriptElement = document.createElement('script');
|
const scriptElement = document.createElement('script');
|
||||||
scriptElement.src = UiContext.onlyofficeApi;
|
scriptElement.src = UiContext.onlyofficeApi;
|
||||||
scriptElement.async = true;
|
scriptElement.async = true;
|
||||||
document.head.appendChild(scriptElement);
|
document.head.appendChild(scriptElement);
|
||||||
scriptElement.onload = resolve;
|
scriptElement.onload = resolve;
|
||||||
|
scriptElement.onerror = reject;
|
||||||
loaded = true;
|
loaded = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = new AutoloadPage('onlyoffice', async () => {
|
const loader = mode => async (element) => {
|
||||||
let res = $('div[data-doc]');
|
const id = `${mode}-${Math.random().toString()}`;
|
||||||
if (res.length) await load();
|
|
||||||
res.get().forEach(async (element) => {
|
|
||||||
const id = `doc-${Math.random().toString()}`;
|
|
||||||
$(element).attr('id', id);
|
$(element).attr('id', id);
|
||||||
const url = $(element).text();
|
const url = $(element).text();
|
||||||
const t = new URL(url, window.location.href).pathname.split('.');
|
const t = new URL(url, window.location.href).pathname.split('.');
|
||||||
const n = new URL(url, window.location.href).pathname.split('/');
|
const n = new URL(url, window.location.href).pathname.split('/');
|
||||||
const res = await request.get(url);
|
|
||||||
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
window.editor = new DocsAPI.DocEditor(id, {
|
window.editor = new DocsAPI.DocEditor(id, {
|
||||||
@@ -33,68 +29,46 @@
|
|||||||
fileType: t[t.length - 1],
|
fileType: t[t.length - 1],
|
||||||
key: Math.random().toString(16),
|
key: Math.random().toString(16),
|
||||||
title: n[n.length - 1],
|
title: n[n.length - 1],
|
||||||
url: new URL(res.url, window.location.href),
|
url: new URL(url, window.location.href),
|
||||||
|
permissions: {
|
||||||
|
comment: false,
|
||||||
|
copy: true,
|
||||||
|
download: true,
|
||||||
|
edit: false,
|
||||||
|
fillForms: false,
|
||||||
|
modifyContentControl: false,
|
||||||
|
modifyFilter: false,
|
||||||
|
print: true,
|
||||||
|
protect: false,
|
||||||
|
review: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
editorConfig: {
|
editorConfig: {
|
||||||
lang,
|
lang,
|
||||||
mode: 'view',
|
mode: 'view',
|
||||||
|
user: {
|
||||||
|
group: "Hydro",
|
||||||
|
id: UserContext._id.toString(),
|
||||||
|
name: UserContext.uname,
|
||||||
},
|
},
|
||||||
documentType: 'word',
|
|
||||||
height: '980px',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
res = $('div[data-cell]');
|
|
||||||
if (res.length) await load();
|
|
||||||
res.get().forEach(async (element) => {
|
|
||||||
const id = `cell-${Math.random().toString()}`;
|
|
||||||
$(element).attr('id', id);
|
|
||||||
const url = $(element).text();
|
|
||||||
const t = new URL(url, window.location.href).pathname.split('.');
|
|
||||||
const n = new URL(url, window.location.href).pathname.split('/');
|
|
||||||
const res = await request.get(url);
|
|
||||||
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
window.editor = new DocsAPI.DocEditor(id, {
|
|
||||||
document: {
|
|
||||||
fileType: t[t.length - 1],
|
|
||||||
key: Math.random().toString(16),
|
|
||||||
title: n[n.length - 1],
|
|
||||||
url: new URL(res.url, window.location.href),
|
|
||||||
},
|
},
|
||||||
editorConfig: {
|
documentType: mode,
|
||||||
lang,
|
height: mode === 'slide' ? '560px' : '900px',
|
||||||
mode: 'cell',
|
|
||||||
},
|
|
||||||
documentType: 'word',
|
|
||||||
height: '980px',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
res = $('div[data-slide]');
|
|
||||||
if (res.length) await load();
|
|
||||||
res.get().forEach(async (element) => {
|
|
||||||
const id = `slide-${Math.random().toString()}`;
|
|
||||||
$(element).attr('id', id);
|
|
||||||
const url = $(element).text();
|
|
||||||
const t = new URL(url, window.location.href).pathname.split('.');
|
|
||||||
const n = new URL(url, window.location.href).pathname.split('/');
|
|
||||||
const res = await request.get(url);
|
|
||||||
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
window.editor = new DocsAPI.DocEditor(id, {
|
|
||||||
document: {
|
|
||||||
fileType: t[t.length - 1],
|
|
||||||
key: Math.random().toString(16),
|
|
||||||
title: n[n.length - 1],
|
|
||||||
url: new URL(res.url, window.location.href),
|
|
||||||
},
|
|
||||||
editorConfig: {
|
|
||||||
lang,
|
|
||||||
mode: 'slide',
|
|
||||||
},
|
|
||||||
documentType: 'word',
|
|
||||||
height: '980px',
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const getEles = types => {
|
||||||
|
const eles = [];
|
||||||
|
for (const type of types) eles.push(...$('div[data-' + type + ']').get());
|
||||||
|
return eles;
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = new AutoloadPage('onlyoffice', async () => {
|
||||||
|
let all = getEles(['doc', 'docx', 'cell', 'xls', 'xlsx', 'slide', 'ppt', 'pptx']);
|
||||||
|
if (all.length) await load();
|
||||||
|
getEles(['doc', 'docx']).forEach(loader('word'));
|
||||||
|
getEles(['cell', 'xls', 'xlsx']).forEach(loader('cell'))
|
||||||
|
getEles(['slide', 'ppt', 'pptx']).forEach(loader('slide'));
|
||||||
});
|
});
|
||||||
|
|
||||||
window.Hydro.extraPages.push(page);
|
window.Hydro.extraPages.push(page);
|
||||||
|
|||||||
Reference in new issue
Block a user