mirror of https://github.com/halo-dev/halo
fix: error occurs when opening attachment library in the uc (#5590)
#### What type of PR is this? /kind bug /area ui #### What this PR does / why we need it: 在个人中心,使用默认富文本编辑器上传附件库时,由于在 UC 中不存在附件库列表,因此会出现错误。 本 PR 通过对默认富文本编辑器上传组件进行调整,调整如下: 1. 当不具有 uc 和 system 的附件权限时,用户仅能通过链接插入图片、音频等,且不允许拖拽和粘贴上传。 2. 当用户具有 uc 但没有 system 的附件权限时,用户可以通过拖拽和粘贴的方式上传,但不允许通过附件库上传。 3. 当用户具有 system 附件权限时,允许通过所有方式(上传、附件库、链接、拖拽和粘贴)进行上传。 #### How to test it? 测试默认富文本编辑器中,用户在不同附件库权限下上传图片是否能够按照逻辑正常处理。 #### Which issue(s) this PR fixes: Fixes #5581 #### Does this PR introduce a user-facing change? ```release-note 修复在个人中心中使用默认富文本编辑器的附件库而导致的报错问题 ```pull/5601/head
parent
78b60a0a29
commit
b8293faafd
|
@ -17,7 +17,6 @@ import {
|
||||||
ExtensionOrderedList,
|
ExtensionOrderedList,
|
||||||
ExtensionStrike,
|
ExtensionStrike,
|
||||||
ExtensionText,
|
ExtensionText,
|
||||||
ExtensionImage,
|
|
||||||
ExtensionTaskList,
|
ExtensionTaskList,
|
||||||
ExtensionLink,
|
ExtensionLink,
|
||||||
ExtensionTextAlign,
|
ExtensionTextAlign,
|
||||||
|
@ -29,8 +28,6 @@ import {
|
||||||
ExtensionHighlight,
|
ExtensionHighlight,
|
||||||
ExtensionCommands,
|
ExtensionCommands,
|
||||||
ExtensionIframe,
|
ExtensionIframe,
|
||||||
ExtensionVideo,
|
|
||||||
ExtensionAudio,
|
|
||||||
ExtensionCodeBlock,
|
ExtensionCodeBlock,
|
||||||
ExtensionFontSize,
|
ExtensionFontSize,
|
||||||
ExtensionColor,
|
ExtensionColor,
|
||||||
|
@ -213,10 +210,6 @@ onMounted(() => {
|
||||||
emit("update", html);
|
emit("update", html);
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
const image = currentUserHasPermission(["uc:attachments:manage"])
|
|
||||||
? UiExtensionImage
|
|
||||||
: ExtensionImage;
|
|
||||||
|
|
||||||
editor.value = new Editor({
|
editor.value = new Editor({
|
||||||
content: props.raw,
|
content: props.raw,
|
||||||
extensions: [
|
extensions: [
|
||||||
|
@ -239,7 +232,7 @@ onMounted(() => {
|
||||||
ExtensionOrderedList,
|
ExtensionOrderedList,
|
||||||
ExtensionStrike,
|
ExtensionStrike,
|
||||||
ExtensionText,
|
ExtensionText,
|
||||||
image.configure({
|
UiExtensionImage.configure({
|
||||||
inline: true,
|
inline: true,
|
||||||
allowBase64: false,
|
allowBase64: false,
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
|
@ -272,16 +265,12 @@ onMounted(() => {
|
||||||
lowlight,
|
lowlight,
|
||||||
}),
|
}),
|
||||||
ExtensionIframe,
|
ExtensionIframe,
|
||||||
currentUserHasPermission(["uc:attachments:manage"])
|
UiExtensionVideo.configure({
|
||||||
? UiExtensionVideo.configure({
|
uploadVideo: props.uploadImage,
|
||||||
uploadVideo: props.uploadImage,
|
}),
|
||||||
})
|
UiExtensionAudio.configure({
|
||||||
: ExtensionVideo,
|
uploadAudio: props.uploadImage,
|
||||||
currentUserHasPermission(["uc:attachments:manage"])
|
}),
|
||||||
? UiExtensionAudio.configure({
|
|
||||||
uploadAudio: props.uploadImage,
|
|
||||||
})
|
|
||||||
: ExtensionAudio,
|
|
||||||
ExtensionCharacterCount,
|
ExtensionCharacterCount,
|
||||||
ExtensionFontSize,
|
ExtensionFontSize,
|
||||||
ExtensionColor,
|
ExtensionColor,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { watch } from "vue";
|
||||||
import { uploadFile } from "../utils/upload";
|
import { uploadFile } from "../utils/upload";
|
||||||
import type { Attachment } from "@halo-dev/api-client";
|
import type { Attachment } from "@halo-dev/api-client";
|
||||||
import type { AxiosRequestConfig } from "axios";
|
import type { AxiosRequestConfig } from "axios";
|
||||||
|
import HasPermission from "@/components/permission/HasPermission.vue";
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -188,22 +189,30 @@ defineExpose({
|
||||||
>
|
>
|
||||||
<slot v-if="$slots.icon" name="icon"></slot>
|
<slot v-if="$slots.icon" name="icon"></slot>
|
||||||
<VSpace>
|
<VSpace>
|
||||||
<VButton @click="open()">
|
<HasPermission :permissions="['uc:attachments:manage']">
|
||||||
{{ $t("core.common.buttons.upload") }}
|
<VButton @click="open()">
|
||||||
</VButton>
|
{{ $t("core.common.buttons.upload") }}
|
||||||
<VButton @click="openAttachmentSelector">
|
</VButton>
|
||||||
{{
|
</HasPermission>
|
||||||
$t(
|
|
||||||
"core.components.default_editor.extensions.upload.attachment.title"
|
<HasPermission :permissions="['system:attachments:manage']">
|
||||||
)
|
<VButton @click="openAttachmentSelector">
|
||||||
}}</VButton
|
{{
|
||||||
>
|
$t(
|
||||||
|
"core.components.default_editor.extensions.upload.attachment.title"
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</VButton>
|
||||||
|
</HasPermission>
|
||||||
|
|
||||||
<VDropdown>
|
<VDropdown>
|
||||||
<VButton>{{
|
<VButton>
|
||||||
$t(
|
{{
|
||||||
"core.components.default_editor.extensions.upload.permalink.title"
|
$t(
|
||||||
)
|
"core.components.default_editor.extensions.upload.permalink.title"
|
||||||
}}</VButton>
|
)
|
||||||
|
}}
|
||||||
|
</VButton>
|
||||||
<template #popper>
|
<template #popper>
|
||||||
<input
|
<input
|
||||||
v-model="externalLink"
|
v-model="externalLink"
|
||||||
|
|
|
@ -3,14 +3,20 @@ import ImageView from "./ImageView.vue";
|
||||||
import type { AxiosRequestConfig } from "axios";
|
import type { AxiosRequestConfig } from "axios";
|
||||||
import type { Attachment } from "@halo-dev/api-client";
|
import type { Attachment } from "@halo-dev/api-client";
|
||||||
|
|
||||||
interface UiImageOptions {
|
export interface ImageOptions {
|
||||||
|
inline: boolean;
|
||||||
|
allowBase64: boolean;
|
||||||
|
HTMLAttributes: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UiImageOptions {
|
||||||
uploadImage?: (
|
uploadImage?: (
|
||||||
file: File,
|
file: File,
|
||||||
options?: AxiosRequestConfig
|
options?: AxiosRequestConfig
|
||||||
) => Promise<Attachment>;
|
) => Promise<Attachment>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Image = ExtensionImage.extend<UiImageOptions>({
|
const Image = ExtensionImage.extend<ImageOptions & UiImageOptions>({
|
||||||
addOptions() {
|
addOptions() {
|
||||||
const { parent } = this;
|
const { parent } = this;
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -5,12 +5,15 @@ import Image from "../extensions/image";
|
||||||
import ExtensionVideo from "../extensions/video";
|
import ExtensionVideo from "../extensions/video";
|
||||||
import ExtensionAudio from "../extensions/audio";
|
import ExtensionAudio from "../extensions/audio";
|
||||||
import type { AxiosRequestConfig } from "axios";
|
import type { AxiosRequestConfig } from "axios";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
export interface FileProps {
|
export interface FileProps {
|
||||||
file: File;
|
file: File;
|
||||||
editor: CoreEditor;
|
editor: CoreEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles file events, determining if the file is an image and triggering the appropriate upload process.
|
* Handles file events, determining if the file is an image and triggering the appropriate upload process.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +25,10 @@ export const handleFileEvent = ({ file, editor }: FileProps) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!currentUserHasPermission(["uc:attachments:manage"])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (file.type.startsWith("image/")) {
|
if (file.type.startsWith("image/")) {
|
||||||
uploadImage({ file, editor });
|
uploadImage({ file, editor });
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue