Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
813e7d27
authored
Apr 14, 2023
by
dhb52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 使用Editor组件替换WxEditor
parent
f25a4d73
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
150 deletions
+74
-150
src/components/Editor/src/Editor.vue
+2
-1
src/views/mp/components/wx-editor/WxEditor.vue
+0
-104
src/views/mp/components/wx-editor/quill-options.js
+0
-45
src/views/mp/draft/editor-config.ts
+72
-0
src/views/mp/draft/index.vue
+0
-0
No files found.
src/components/Editor/src/Editor.vue
View file @
813e7d27
...
@@ -20,7 +20,7 @@ const props = defineProps({
...
@@ -20,7 +20,7 @@ const props = defineProps({
editorId
:
propTypes
.
string
.
def
(
'wangeEditor-1'
),
editorId
:
propTypes
.
string
.
def
(
'wangeEditor-1'
),
height
:
propTypes
.
oneOfType
([
Number
,
String
]).
def
(
'500px'
),
height
:
propTypes
.
oneOfType
([
Number
,
String
]).
def
(
'500px'
),
editorConfig
:
{
editorConfig
:
{
type
:
Object
as
PropType
<
IEditorConfig
>
,
type
:
Object
as
PropType
<
Partial
<
IEditorConfig
>
>
,
default
:
()
=>
undefined
default
:
()
=>
undefined
},
},
readonly
:
propTypes
.
bool
.
def
(
false
),
readonly
:
propTypes
.
bool
.
def
(
false
),
...
@@ -147,6 +147,7 @@ const editorConfig = computed((): IEditorConfig => {
...
@@ -147,6 +147,7 @@ const editorConfig = computed((): IEditorConfig => {
props
.
editorConfig
||
{}
props
.
editorConfig
||
{}
)
)
})
})
const
editorStyle
=
computed
(()
=>
{
const
editorStyle
=
computed
(()
=>
{
return
{
return
{
height
:
isNumber
(
props
.
height
)
?
`
${
props
.
height
}
px`
:
props
.
height
height
:
isNumber
(
props
.
height
)
?
`
${
props
.
height
}
px`
:
props
.
height
...
...
src/views/mp/components/wx-editor/WxEditor.vue
deleted
100644 → 0
View file @
f25a4d73
<
script
setup
>
import
{
ref
,
reactive
}
from
'vue'
import
{
getAccessToken
}
from
'@/utils/auth'
import
{
Editor
}
from
'@/components/Editor'
const
BASE_URL
=
import
.
meta
.
env
.
VITE_BASE_URL
const
actionUrl
=
BASE_URL
+
'/admin-api/mp/material/upload-news-image'
// 这里写你要上传的图片服务器地址
const
headers
=
{
Authorization
:
'Bearer '
+
getAccessToken
()
}
// 设置上传的请求头部
const
message
=
useMessage
()
const
props
=
defineProps
({
/* 公众号账号编号 */
accountId
:
{
type
:
Number
,
required
:
true
},
/* 编辑器的内容 */
value
:
{
type
:
String
,
default
:
''
},
/* 图片大小 */
maxSize
:
{
type
:
Number
,
default
:
4000
// kb
}
})
const
emit
=
defineEmits
([
'input'
])
const
myQuillEditorRef
=
ref
()
const
content
=
ref
(
props
.
value
.
replace
(
/data-src/g
,
'src'
))
const
loading
=
ref
(
false
)
// 根据图片上传状态来确定是否显示loading动画,刚开始是false,不显示
const
uploadData
=
reactive
({
type
:
'image'
,
// TODO 芋艿:试试要不要换成 thumb
accountId
:
props
.
accountId
})
const
onEditorChange
=
(
text
)
=>
{
//内容改变事件
emit
(
'input'
,
text
)
}
// 富文本图片上传前
const
beforeUpload
=
()
=>
{
// 显示 loading 动画
loading
.
value
=
true
}
// 图片上传成功
// 注意!由于微信公众号的图片有访问限制,所以会显示“此图片来自微信公众号,未经允许不可引用”
const
uploadSuccess
=
(
res
)
=>
{
// res为图片服务器返回的数据
// 获取富文本组件实例
const
quill
=
myQuillEditorRef
.
value
.
quill
// 如果上传成功
const
link
=
res
.
data
if
(
link
)
{
// 获取光标所在位置
let
length
=
quill
.
getSelection
().
index
// 插入图片 res.info为服务器返回的图片地址
quill
.
insertEmbed
(
length
,
'image'
,
link
)
// 调整光标到最后
quill
.
setSelection
(
length
+
1
)
}
else
{
message
.
error
(
'图片插入失败'
)
}
// loading 动画消失
loading
.
value
=
false
}
// 富文本图片上传失败
const
uploadError
=
()
=>
{
// loading 动画消失
loading
.
value
=
false
message
.
error
(
'图片插入失败'
)
}
</
script
>
<
template
>
<div
id=
"wxEditor"
>
<div
v-loading=
"loading"
element-loading-text=
"请稍等,图片上传中"
>
<!-- 图片上传组件辅助-->
<el-upload
class=
"avatar-uploader"
name=
"file"
:action=
"actionUrl"
:headers=
"headers"
:show-file-list=
"false"
:data=
"uploadData"
:on-success=
"uploadSuccess"
:on-error=
"uploadError"
:before-upload=
"beforeUpload"
/>
<Editor
editor-id=
"wxEditor"
ref=
"quillEditorRef"
:modelValue=
"content"
@
change=
"(editor) => onEditorChange(editor.getText())"
/>
</div>
</div>
</
template
>
src/views/mp/components/wx-editor/quill-options.js
deleted
100644 → 0
View file @
f25a4d73
const
toolbarOptions
=
[
[
'bold'
,
'italic'
,
'underline'
,
'strike'
],
// 加粗 斜体 下划线 删除线
[
'blockquote'
,
'code-block'
],
// 引用 代码块
[{
header
:
1
},
{
header
:
2
}],
// 1、2 级标题
[{
list
:
'ordered'
},
{
list
:
'bullet'
}],
// 有序、无序列表
[{
script
:
'sub'
},
{
script
:
'super'
}],
// 上标/下标
[{
indent
:
'-1'
},
{
indent
:
'+1'
}],
// 缩进
// [{'direction': 'rtl'}], // 文本方向
[{
size
:
[
'small'
,
false
,
'large'
,
'huge'
]
}],
// 字体大小
[{
header
:
[
1
,
2
,
3
,
4
,
5
,
6
,
false
]
}],
// 标题
[{
color
:
[]
},
{
background
:
[]
}],
// 字体颜色、字体背景颜色
[{
font
:
[]
}],
// 字体种类
[{
align
:
[]
}],
// 对齐方式
[
'clean'
],
// 清除文本格式
[
'link'
,
'image'
,
'video'
]
// 链接、图片、视频
]
export
default
{
theme
:
'snow'
,
placeholder
:
'请输入文章内容'
,
modules
:
{
toolbar
:
{
container
:
toolbarOptions
,
// container: "#toolbar",
handlers
:
{
image
:
function
(
value
)
{
if
(
value
)
{
// 触发input框选择图片文件
document
.
querySelector
(
'.avatar-uploader input'
).
click
()
}
else
{
this
.
quill
.
format
(
'image'
,
false
)
}
},
link
:
function
(
value
)
{
if
(
value
)
{
const
href
=
prompt
(
'注意!只支持公众号图文链接'
)
this
.
quill
.
format
(
'link'
,
href
)
}
else
{
this
.
quill
.
format
(
'link'
,
false
)
}
}
}
}
}
}
src/views/mp/draft/editor-config.ts
0 → 100644
View file @
813e7d27
import
{
IEditorConfig
}
from
'@wangeditor/editor'
import
{
getAccessToken
,
getTenantId
}
from
'@/utils/auth'
const
message
=
useMessage
()
type
InsertFnType
=
(
url
:
string
,
alt
:
string
,
href
:
string
)
=>
void
export
const
createEditorConfig
=
(
server
:
string
,
accountId
:
number
|
undefined
):
Partial
<
IEditorConfig
>
=>
{
return
{
MENU_CONF
:
{
[
'uploadImage'
]:
{
server
,
// 单个文件的最大体积限制,默认为 2M
maxFileSize
:
5
*
1024
*
1024
,
// 最多可上传几个文件,默认为 100
maxNumberOfFiles
:
10
,
// 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 []
allowedFileTypes
:
[
'image/*'
],
// 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。
meta
:
{
accountId
:
accountId
},
// 将 meta 拼接到 url 参数中,默认 false
metaWithUrl
:
true
,
// 自定义增加 http header
headers
:
{
Accept
:
'*'
,
Authorization
:
'Bearer '
+
getAccessToken
(),
'tenant-id'
:
getTenantId
()
},
// 跨域是否传递 cookie ,默认为 false
withCredentials
:
true
,
// 超时时间,默认为 10 秒
timeout
:
5
*
1000
,
// 5 秒
// form-data fieldName,后端接口参数名称,默认值wangeditor-uploaded-image
fieldName
:
'file'
,
// 上传之前触发
onBeforeUpload
(
file
:
File
)
{
console
.
log
(
file
)
return
file
},
// 上传进度的回调函数
onProgress
(
progress
:
number
)
{
// progress 是 0-100 的数字
console
.
log
(
'progress'
,
progress
)
},
onSuccess
(
file
:
File
,
res
:
any
)
{
console
.
log
(
'onSuccess'
,
file
,
res
)
},
onFailed
(
file
:
File
,
res
:
any
)
{
message
.
alertError
(
res
.
message
)
console
.
log
(
'onFailed'
,
file
,
res
)
},
onError
(
file
:
File
,
err
:
any
,
res
:
any
)
{
message
.
alertError
(
err
.
message
)
console
.
error
(
'onError'
,
file
,
err
,
res
)
},
// 自定义插入图片
customInsert
(
res
:
any
,
insertFn
:
InsertFnType
)
{
insertFn
(
res
.
data
,
'image'
,
res
.
data
)
}
}
}
}
}
src/views/mp/draft/index.vue
View file @
813e7d27
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment