From 877b2a2021d749e5825e66fcc068d06e96597d4e Mon Sep 17 00:00:00 2001 From: veypi Date: Wed, 30 Oct 2024 17:06:41 +0800 Subject: [PATCH] feat: app index --- oaer/lib/fs.ts | 16 ++++++++++++ oaer/lib/main.ts | 4 +++ oaweb/components/editor/index.vue | 30 ++++++++++++++------- oaweb/components/editor/options.ts | 13 ++++++--- oaweb/composables/api/webapi.ts | 1 + oaweb/pages/app/[id]/index.vue | 42 +++++++++++++----------------- 6 files changed, 68 insertions(+), 38 deletions(-) diff --git a/oaer/lib/fs.ts b/oaer/lib/fs.ts index 756d033..cd80167 100644 --- a/oaer/lib/fs.ts +++ b/oaer/lib/fs.ts @@ -33,6 +33,9 @@ class davWraper { this.prefix = prefix this.token = token this.client = webdav.createClient(host + prefix) + if (this.prefix.endsWith('/')) { + this.prefix = this.prefix.slice(0, -1) + } } set(k: 'host' | 'token', value: string) { if (value !== this[k]) { @@ -58,6 +61,19 @@ class davWraper { stat(path: string, options?: webdav.StatOptions) { return this.retry(() => this.client.stat(path, options)) } + urlwrap(path: string) { + if (path.startsWith('/')) { + return this.prefix + path + } else { + return this.prefix + '/' + path + } + } + urlunwrap(url: string) { + if (url.startsWith(this.prefix)) { + return url.slice(this.prefix.length) + } + return url + } private retry(fn: () => Promise): Promise { let retries = 0; function attempt(): Promise { diff --git a/oaer/lib/main.ts b/oaer/lib/main.ts index ff99e38..e10a3ea 100644 --- a/oaer/lib/main.ts +++ b/oaer/lib/main.ts @@ -13,6 +13,10 @@ import api from './api' import fs from './fs' +export { + fs +} + export default new class { private ui?: ui constructor() { diff --git a/oaweb/components/editor/index.vue b/oaweb/components/editor/index.vue index 1e813f1..55bca9b 100644 --- a/oaweb/components/editor/index.vue +++ b/oaweb/components/editor/index.vue @@ -5,8 +5,10 @@ * Distributed under terms of the MIT license. --> @@ -36,20 +38,15 @@ let props = withDefaults(defineProps<{ ) watch(computed(() => props.modelValue), (e) => { - set_mode(e) + editor.switchModel(e ? 'previewOnly' : 'edit&preview') }) watch(computed(() => props.content), (e) => { if (e) { - console.log(e) editor.setValue(e) } }) -const set_mode = (preview: boolean) => { - editor.switchModel(preview ? 'previewOnly' : 'edit&preview') -} - const fileUpload = (f: File, cb: (url: string, params: any) => void) => { /** * @param params.name 回填的alt信息 @@ -86,7 +83,7 @@ const init = () => { let config = { value: props.content, id: props.eid, - // isPreviewOnly: true, + isPreviewOnly: props.modelValue, callback: { }, fileUpload: fileUpload, @@ -96,7 +93,6 @@ const init = () => { // @ts-ignore options.toolbars.customMenu.backMenu = backMenu editor = new Cherry(Object.assign({}, options, config)); - set_mode(props.modelValue) } @@ -106,6 +102,20 @@ onMounted(() => {