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
13977674
authored
Apr 11, 2023
by
dhb52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 【MP素材管理】使用【WxMpSelect】
parent
c7b296a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
56 deletions
+74
-56
src/views/mp/material/index.vue
+74
-56
No files found.
src/views/mp/material/index.vue
View file @
13977674
...
@@ -2,7 +2,14 @@
...
@@ -2,7 +2,14 @@
<doc-alert
title=
"公众号素材"
url=
"https://doc.iocoder.cn/mp/material/"
/>
<doc-alert
title=
"公众号素材"
url=
"https://doc.iocoder.cn/mp/material/"
/>
<!-- 搜索工作栏 -->
<!-- 搜索工作栏 -->
<ContentWrap>
<ContentWrap>
<WxAccountSelect
@
change=
"(accountId) => accountChange(accountId)"
/>
<el-form
class=
"-mb-15px"
:inline=
"true"
label-width=
"68px"
>
<el-form-item
label=
"公众号"
prop=
"accountId"
>
<WxMpSelect
@
change=
"(accountId) => accountChange(accountId)"
/>
</el-form-item>
<el-form-item>
<slot
name=
"actions"
></slot>
</el-form-item>
</el-form>
</ContentWrap>
</ContentWrap>
<ContentWrap>
<ContentWrap>
...
@@ -14,7 +21,7 @@
...
@@ -14,7 +21,7 @@
</
template
>
</
template
>
<div
class=
"add_but"
v-hasPermi=
"['mp:material:upload-permanent']"
>
<div
class=
"add_but"
v-hasPermi=
"['mp:material:upload-permanent']"
>
<el-upload
<el-upload
:action=
"
action
Url"
:action=
"
upload
Url"
:headers=
"headers"
:headers=
"headers"
multiple
multiple
:limit=
"1"
:limit=
"1"
...
@@ -37,7 +44,7 @@
...
@@ -37,7 +44,7 @@
<img
class=
"material-img"
:src=
"item.url"
/>
<img
class=
"material-img"
:src=
"item.url"
/>
<div
class=
"item-name"
>
{{ item.name }}
</div>
<div
class=
"item-name"
>
{{ item.name }}
</div>
</a>
</a>
<el-row
class=
"ope-row"
justify=
"center"
>
<el-row
justify=
"center"
>
<el-button
<el-button
type=
"danger"
type=
"danger"
circle
circle
...
@@ -65,7 +72,7 @@
...
@@ -65,7 +72,7 @@
</
template
>
</
template
>
<div
class=
"add_but"
v-hasPermi=
"['mp:material:upload-permanent']"
>
<div
class=
"add_but"
v-hasPermi=
"['mp:material:upload-permanent']"
>
<el-upload
<el-upload
:action=
"
action
Url"
:action=
"
upload
Url"
:headers=
"headers"
:headers=
"headers"
multiple
multiple
:limit=
"1"
:limit=
"1"
...
@@ -82,6 +89,8 @@
...
@@ -82,6 +89,8 @@
</
template
>
</
template
>
</el-upload>
</el-upload>
</div>
</div>
<!-- 列表 -->
<el-table
:data=
"list"
stripe
border
v-loading=
"loading"
style=
"margin-top: 10px"
>
<el-table
:data=
"list"
stripe
border
v-loading=
"loading"
style=
"margin-top: 10px"
>
<el-table-column
label=
"编号"
align=
"center"
prop=
"mediaId"
/>
<el-table-column
label=
"编号"
align=
"center"
prop=
"mediaId"
/>
<el-table-column
label=
"文件名"
align=
"center"
prop=
"name"
/>
<el-table-column
label=
"文件名"
align=
"center"
prop=
"name"
/>
...
@@ -143,7 +152,7 @@
...
@@ -143,7 +152,7 @@
v-loading=
"addMaterialLoading"
v-loading=
"addMaterialLoading"
>
>
<el-upload
<el-upload
:action=
"
action
Url"
:action=
"
upload
Url"
:headers=
"headers"
:headers=
"headers"
multiple
multiple
:limit=
"1"
:limit=
"1"
...
@@ -182,11 +191,14 @@
...
@@ -182,11 +191,14 @@
</el-row>
</el-row>
</el-form>
</el-form>
<
template
#
footer
>
<
template
#
footer
>
<!--
<span
class=
"dialog-footer"
>
-->
<el-button
@
click=
"cancelVideo"
>
取 消
</el-button>
<el-button
@
click=
"cancelVideo"
>
取 消
</el-button>
<el-button
type=
"primary"
@
click=
"submitVideo"
>
提 交
</el-button>
<el-button
type=
"primary"
@
click=
"submitVideo"
>
提 交
</el-button>
<!--
</span>
-->
</
template
>
</
template
>
</el-dialog>
</el-dialog>
<!-- 列表 -->
<el-table
:data=
"list"
stripe
border
v-loading=
"loading"
style=
"margin-top: 10px"
>
<el-table
:data=
"list"
stripe
border
v-loading=
"loading"
style=
"margin-top: 10px"
>
<el-table-column
label=
"编号"
align=
"center"
prop=
"mediaId"
/>
<el-table-column
label=
"编号"
align=
"center"
prop=
"mediaId"
/>
<el-table-column
label=
"文件名"
align=
"center"
prop=
"name"
/>
<el-table-column
label=
"文件名"
align=
"center"
prop=
"name"
/>
...
@@ -237,24 +249,41 @@
...
@@ -237,24 +249,41 @@
</el-tabs>
</el-tabs>
</ContentWrap>
</ContentWrap>
</template>
</template>
<
script
setup
name=
"MpMaterial"
>
<
script
lang=
"ts"
setup
name=
"MpMaterial"
>
import
WxVoicePlayer
from
'@/views/mp/components/wx-voice-play/main.vue'
import
WxVoicePlayer
from
'@/views/mp/components/wx-voice-play/main.vue'
import
WxVideoPlayer
from
'@/views/mp/components/wx-video-play/main.vue'
import
WxVideoPlayer
from
'@/views/mp/components/wx-video-play/main.vue'
import
Wx
AccountSelect
from
'@/views/mp/components/wx-account-select/main
.vue'
import
Wx
MpSelect
from
'@/views/mp/components/WxMpSelect
.vue'
import
*
as
MpMaterialApi
from
'@/api/mp/material'
import
*
as
MpMaterialApi
from
'@/api/mp/material'
import
*
as
authUtil
from
'@/utils/auth'
import
*
as
authUtil
from
'@/utils/auth'
import
{
dateFormatter
}
from
'@/utils/formatTime'
import
{
dateFormatter
}
from
'@/utils/formatTime'
import
type
{
const
message
=
useMessage
()
FormInstance
,
FormRules
,
TabPaneName
,
UploadInstance
,
UploadProps
,
UploadRawFile
,
UploadUserFile
}
from
'element-plus'
const
BASE_URL
=
import
.
meta
.
env
.
VITE_BASE_URL
const
BASE_URL
=
import
.
meta
.
env
.
VITE_BASE_URL
const
action
Url
=
BASE_URL
+
'/admin-api/mp/material/upload-permanent'
const
upload
Url
=
BASE_URL
+
'/admin-api/mp/material/upload-permanent'
const
headers
=
{
Authorization
:
'Bearer '
+
authUtil
.
getAccessToken
()
}
const
headers
=
{
Authorization
:
'Bearer '
+
authUtil
.
getAccessToken
()
}
const
uploadFormRef
=
ref
()
const
message
=
useMessage
()
const
uploadVideoRef
=
ref
()
const
uploadFormRef
=
ref
<
FormInstance
>
()
const
uploadVideoRef
=
ref
<
UploadInstance
>
()
const
type
=
ref
(
'image'
)
const
uploadRules
:
FormRules
=
{
title
:
[{
required
:
true
,
message
:
'请输入标题'
,
trigger
:
'blur'
}],
introduction
:
[{
required
:
true
,
message
:
'请输入描述'
,
trigger
:
'blur'
}]
}
// 素材类型
type
MatertialType
=
'image'
|
'voice'
|
'video'
const
type
=
ref
<
MatertialType
>
(
'image'
)
// 遮罩层
// 遮罩层
const
loading
=
ref
(
false
)
const
loading
=
ref
(
false
)
// 总条数
// 总条数
...
@@ -262,15 +291,27 @@ const total = ref(0)
...
@@ -262,15 +291,27 @@ const total = ref(0)
// 数据列表
// 数据列表
const
list
=
ref
([])
const
list
=
ref
([])
// 查询参数
// 查询参数
const
queryParams
=
reactive
({
interface
QueryParams
{
pageNo
:
number
pageSize
:
number
accountId
?:
number
permanent
:
boolean
}
const
queryParams
:
QueryParams
=
reactive
({
pageNo
:
1
,
pageNo
:
1
,
pageSize
:
10
,
pageSize
:
10
,
accountId
:
undefined
,
accountId
:
undefined
,
permanent
:
true
permanent
:
true
})
})
const
fileList
=
ref
([])
const
fileList
=
ref
<
UploadUserFile
[]
>
([])
const
uploadData
=
reactive
({
interface
UploadData
{
type
:
MatertialType
title
:
string
introduction
:
string
}
const
uploadData
:
UploadData
=
reactive
({
type
:
'image'
,
type
:
'image'
,
title
:
''
,
title
:
''
,
introduction
:
''
introduction
:
''
...
@@ -279,33 +320,16 @@ const uploadData = reactive({
...
@@ -279,33 +320,16 @@ const uploadData = reactive({
// === 视频上传,独有变量 ===
// === 视频上传,独有变量 ===
const
dialogVideoVisible
=
ref
(
false
)
const
dialogVideoVisible
=
ref
(
false
)
const
addMaterialLoading
=
ref
(
false
)
const
addMaterialLoading
=
ref
(
false
)
const
uploadRules
=
reactive
({
// 视频上传的校验规则
title
:
[{
required
:
true
,
message
:
'请输入标题'
,
trigger
:
'blur'
}],
introduction
:
[{
required
:
true
,
message
:
'请输入描述'
,
trigger
:
'blur'
}]
})
/** 侦听公众号变化 **/
/** 侦听公众号变化 **/
const
accountChange
=
(
accountId
)
=>
{
const
accountChange
=
(
accountId
:
number
|
undefined
)
=>
{
setAccountId
(
accountId
)
queryParams
.
accountId
=
accountId
getList
()
getList
()
}
}
// ======================== 列表查询 ========================
// ======================== 列表查询 ========================
/** 设置账号编号 */
const
setAccountId
=
(
accountId
)
=>
{
queryParams
.
accountId
=
accountId
uploadData
.
accountId
=
accountId
}
/** 查询列表 */
/** 查询列表 */
const
getList
=
async
()
=>
{
const
getList
=
async
()
=>
{
// 如果没有选中公众号账号,则进行提示。
if
(
!
queryParams
.
accountId
)
{
message
.
error
(
'未选中公众号,无法查询草稿箱'
)
return
false
}
loading
.
value
=
true
loading
.
value
=
true
try
{
try
{
const
data
=
await
MpMaterialApi
.
getMaterialPage
({
const
data
=
await
MpMaterialApi
.
getMaterialPage
({
...
@@ -322,16 +346,12 @@ const getList = async () => {
...
@@ -322,16 +346,12 @@ const getList = async () => {
/** 搜索按钮操作 */
/** 搜索按钮操作 */
const
handleQuery
=
()
=>
{
const
handleQuery
=
()
=>
{
queryParams
.
pageNo
=
1
queryParams
.
pageNo
=
1
// 默认选中第一个
if
(
queryParams
.
accountId
)
{
setAccountId
(
queryParams
.
accountId
)
}
getList
()
getList
()
}
}
const
handleTabChange
=
(
tabName
)
=>
{
const
handleTabChange
=
(
tabName
:
TabPaneName
)
=>
{
// 设置 type
// 设置 type
uploadData
.
type
=
tabName
uploadData
.
type
=
tabName
as
MatertialType
// 提前情况数据,避免tab切换后显示垃圾数据
// 提前情况数据,避免tab切换后显示垃圾数据
list
.
value
=
[]
list
.
value
=
[]
...
@@ -342,15 +362,15 @@ const handleTabChange = (tabName) => {
...
@@ -342,15 +362,15 @@ const handleTabChange = (tabName) => {
}
}
// ======================== 文件上传 ========================
// ======================== 文件上传 ========================
const
beforeImageUpload
=
(
f
ile
)
=>
{
const
beforeImageUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawF
ile
)
=>
{
const
isType
=
[
'image/jpeg'
,
'image/png'
,
'image/gif'
,
'image/bmp'
,
'image/jpg'
].
includes
(
const
isType
=
[
'image/jpeg'
,
'image/png'
,
'image/gif'
,
'image/bmp'
,
'image/jpg'
].
includes
(
f
ile
.
type
rawF
ile
.
type
)
)
if
(
!
isType
)
{
if
(
!
isType
)
{
message
.
error
(
'上传图片格式不对!'
)
message
.
error
(
'上传图片格式不对!'
)
return
false
return
false
}
}
const
isLt
=
f
ile
.
size
/
1024
/
1024
<
2
const
isLt
=
rawF
ile
.
size
/
1024
/
1024
<
2
if
(
!
isLt
)
{
if
(
!
isLt
)
{
message
.
error
(
'上传图片大小不能超过 2M!'
)
message
.
error
(
'上传图片大小不能超过 2M!'
)
return
false
return
false
...
@@ -359,9 +379,9 @@ const beforeImageUpload = (file) => {
...
@@ -359,9 +379,9 @@ const beforeImageUpload = (file) => {
return
true
return
true
}
}
const
beforeVoiceUpload
=
(
f
ile
)
=>
{
const
beforeVoiceUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawF
ile
)
=>
{
const
isType
=
[
'audio/mp3'
,
'audio/wma'
,
'audio/wav'
,
'audio/amr'
].
includes
(
file
.
type
)
const
isType
=
[
'audio/mp3'
,
'audio/wma'
,
'audio/wav'
,
'audio/amr'
].
includes
(
file
.
type
)
const
isLt
=
f
ile
.
size
/
1024
/
1024
<
2
const
isLt
=
rawF
ile
.
size
/
1024
/
1024
<
2
if
(
!
isType
)
{
if
(
!
isType
)
{
message
.
error
(
'上传语音格式不对!'
)
message
.
error
(
'上传语音格式不对!'
)
return
false
return
false
...
@@ -374,14 +394,14 @@ const beforeVoiceUpload = (file) => {
...
@@ -374,14 +394,14 @@ const beforeVoiceUpload = (file) => {
return
true
return
true
}
}
const
beforeVideoUpload
=
(
f
ile
)
=>
{
const
beforeVideoUpload
:
UploadProps
[
'beforeUpload'
]
=
(
rawFile
:
UploadRawF
ile
)
=>
{
const
isType
=
f
ile
.
type
===
'video/mp4'
const
isType
=
rawF
ile
.
type
===
'video/mp4'
if
(
!
isType
)
{
if
(
!
isType
)
{
message
.
error
(
'上传视频格式不对!'
)
message
.
error
(
'上传视频格式不对!'
)
return
false
return
false
}
}
const
isLt
=
f
ile
.
size
/
1024
/
1024
<
10
const
isLt
=
rawF
ile
.
size
/
1024
/
1024
<
10
if
(
!
isLt
)
{
if
(
!
isLt
)
{
message
.
error
(
'上传视频大小不能超过 10M!'
)
message
.
error
(
'上传视频大小不能超过 10M!'
)
return
false
return
false
...
@@ -391,7 +411,7 @@ const beforeVideoUpload = (file) => {
...
@@ -391,7 +411,7 @@ const beforeVideoUpload = (file) => {
return
true
return
true
}
}
const
handleUploadSuccess
=
(
response
,
file
,
fileList
)
=>
{
const
handleUploadSuccess
:
UploadProps
[
'onSuccess'
]
=
(
response
:
any
)
=>
{
loading
.
value
=
false
loading
.
value
=
false
addMaterialLoading
.
value
=
false
addMaterialLoading
.
value
=
false
if
(
response
.
code
!==
0
)
{
if
(
response
.
code
!==
0
)
{
...
@@ -410,17 +430,17 @@ const handleUploadSuccess = (response, file, fileList) => {
...
@@ -410,17 +430,17 @@ const handleUploadSuccess = (response, file, fileList) => {
}
}
// 下载文件
// 下载文件
const
handleDownload
=
(
row
)
=>
{
const
handleDownload
=
(
row
:
any
)
=>
{
window
.
open
(
row
.
url
,
'_blank'
)
window
.
open
(
row
.
url
,
'_blank'
)
}
}
// 提交 video 新建的表单
// 提交 video 新建的表单
const
submitVideo
=
()
=>
{
const
submitVideo
=
()
=>
{
uploadFormRef
.
value
.
validate
((
valid
)
=>
{
uploadFormRef
.
value
?
.
validate
((
valid
)
=>
{
if
(
!
valid
)
{
if
(
!
valid
)
{
return
false
return
false
}
}
uploadVideoRef
.
value
.
submit
()
uploadVideoRef
.
value
?
.
submit
()
})
})
}
}
...
@@ -444,7 +464,7 @@ const resetVideo = () => {
...
@@ -444,7 +464,7 @@ const resetVideo = () => {
}
}
// ======================== 其它操作 ========================
// ======================== 其它操作 ========================
const
handleDelete
=
async
(
item
)
=>
{
const
handleDelete
=
async
(
item
:
any
)
=>
{
await
message
.
confirm
(
'此操作将永久删除该文件, 是否继续?'
)
await
message
.
confirm
(
'此操作将永久删除该文件, 是否继续?'
)
await
MpMaterialApi
.
deletePermanentMaterial
(
item
.
id
)
await
MpMaterialApi
.
deletePermanentMaterial
(
item
.
id
)
message
.
alertSuccess
(
'删除成功'
)
message
.
alertSuccess
(
'删除成功'
)
...
@@ -501,6 +521,4 @@ p {
...
@@ -501,6 +521,4 @@ p {
column-count
:
1
;
column-count
:
1
;
}
}
}
}
/*瀑布流样式*/
</
style
>
</
style
>
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