!113 refactor: 抽离组件【公众号下拉选择】并重构相关页面

Merge pull request !113 from dhb52/dev
This commit is contained in:
芋道源码 2023-04-11 15:13:15 +00:00 committed by Gitee
commit 129766fca4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 438 additions and 643 deletions

View File

@ -17,3 +17,18 @@ VITE_API_URL=/admin-api
# 打包路径 # 打包路径
VITE_BASE_PATH=/ VITE_BASE_PATH=/
# 项目本地运行端口号, 与.vscode/launch.json配合
VITE_PORT=5173
# 是否删除debugger
VITE_DROP_DEBUGGER=false
# 是否删除console.log
VITE_DROP_CONSOLE=false
# 是否sourcemap
VITE_SOURCEMAP=true
# 验证码的开关
VITE_APP_CAPTCHA_ENABLE=false

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "msedge",
"request": "launch",
"name": "Launch Edge against localhost",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}/src",
"sourceMaps": true
}
]
}

View File

@ -98,7 +98,8 @@ export function createVitePlugins() {
deleteOriginFile: false //压缩后是否删除源文件 deleteOriginFile: false //压缩后是否删除源文件
}), }),
ViteEjsPlugin(), ViteEjsPlugin(),
topLevelAwait({ // https://juejin.cn/post/7152191742513512485 topLevelAwait({
// https://juejin.cn/post/7152191742513512485
// The export name of top-level await promise for each chunk module // The export name of top-level await promise for each chunk module
promiseExportName: '__tla', promiseExportName: '__tla',
// The function to generate import names of top-level await promise in each chunk module // The function to generate import names of top-level await promise in each chunk module

View File

@ -127,7 +127,7 @@
"vite-plugin-purge-icons": "^0.9.2", "vite-plugin-purge-icons": "^0.9.2",
"vite-plugin-svg-icons": "^2.0.1", "vite-plugin-svg-icons": "^2.0.1",
"vite-plugin-top-level-await": "^1.3.0", "vite-plugin-top-level-await": "^1.3.0",
"vite-plugin-vue-setup-extend": "^0.4.0", "vite-plugin-vue-setup-extend-plus": "^0.1.0",
"vite-plugin-windicss": "^1.8.10", "vite-plugin-windicss": "^1.8.10",
"vue-tsc": "^1.2.0", "vue-tsc": "^1.2.0",
"windicss": "^3.5.6" "windicss": "^3.5.6"

View File

@ -3,28 +3,7 @@
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChanged(accountId)" />
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
</el-form-item>
</el-form>
</ContentWrap> </ContentWrap>
<!-- tab 切换 --> <!-- tab 切换 -->
@ -181,20 +160,13 @@
</ContentWrap> </ContentWrap>
</template> </template>
<script setup name="MpAutoReply"> <script setup name="MpAutoReply">
import { ref, reactive, onMounted, nextTick } from 'vue'
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue' import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue' import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
import WxMusic from '@/views/mp/components/wx-music/main.vue' import WxMusic from '@/views/mp/components/wx-music/main.vue'
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
import WxReplySelect from '@/views/mp/components/wx-reply/main.vue' import WxReplySelect from '@/views/mp/components/wx-reply/main.vue'
import { getSimpleAccountList } from '@/api/mp/account' import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import { import * as MpAutoReplyApi from '@/api/mp/autoReply'
createAutoReply,
deleteAutoReply,
getAutoReply,
getAutoReplyPage,
updateAutoReply
} from '@/api/mp/autoReply'
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
@ -202,7 +174,7 @@ import { ContentWrap } from '@/components/ContentWrap'
const message = useMessage() const message = useMessage()
const queryFormRef = ref() // const queryFormRef = ref()
const formRef = ref() const formRef = ref()
// tab 123 // tab 123
@ -240,43 +212,27 @@ const rules = {
requestMatch: [{ required: true, message: '请求的关键字的匹配不能为空', trigger: 'blur' }] requestMatch: [{ required: true, message: '请求的关键字的匹配不能为空', trigger: 'blur' }]
} }
const hackResetWxReplySelect = ref(false) // WxReplySelect // WxReplySelect
const hackResetWxReplySelect = ref(false)
// const accountChanged = (accountId) => {
const accountList = ref([]) queryParams.accountId = accountId
onMounted(() => {
getSimpleAccountList().then((data) => {
accountList.value = data
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
//
getList() getList()
}) }
})
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
//
if (!queryParams.accountId) {
message.error('未选中公众号,无法查询自动回复')
return false
}
loading.value = false loading.value = false
// try {
let params = { const data = await MpAutoReplyApi.getAutoReplyPage({
...queryParams, ...queryParams,
type: type.value type: type.value
} })
//
getAutoReplyPage(params).then((data) => {
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally {
loading.value = false loading.value = false
}) }
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
@ -285,16 +241,6 @@ const handleQuery = () => {
getList() getList()
} }
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
handleQuery()
}
const handleTabChange = (tabName) => { const handleTabChange = (tabName) => {
type.value = tabName type.value = tabName
handleQuery() handleQuery()
@ -319,7 +265,7 @@ const handleUpdate = (row) => {
resetEditor() resetEditor()
console.log(row) console.log(row)
getAutoReply(row.id).then((data) => { MpAutoReplyApi.getAutoReply(row.id).then((data) => {
// //
form.value = { ...data } form.value = { ...data }
delete form.value['responseMessageType'] delete form.value['responseMessageType']
@ -370,13 +316,13 @@ const handleSubmit = () => {
form.responseHqMusicUrl = objData.value.hqMusicUrl form.responseHqMusicUrl = objData.value.hqMusicUrl
if (form.value.id !== undefined) { if (form.value.id !== undefined) {
updateAutoReply(form).then(() => { MpAutoReplyApi.updateAutoReply(form).then(() => {
message.success('修改成功') message.success('修改成功')
open.value = false open.value = false
getList() getList()
}) })
} else { } else {
createAutoReply(form).then(() => { MpAutoReplyApi.createAutoReply(form).then(() => {
message.success('新增成功') message.success('新增成功')
open.value = false open.value = false
getList() getList()
@ -414,7 +360,7 @@ const resetEditor = () => {
const handleDelete = async (row) => { const handleDelete = async (row) => {
await message.confirm('是否确认删除此数据?') await message.confirm('是否确认删除此数据?')
await deleteAutoReply(row.id) await MpAutoReplyApi.deleteAutoReply(row.id)
await getList() await getList()
message.success('删除成功') message.success('删除成功')
} }

View File

@ -0,0 +1,39 @@
<template>
<el-select
v-model="accountId"
placeholder="请选择公众号"
class="!w-240px"
@change="accountChanged"
>
<el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</template>
<script lang="ts" setup name="WxMpSelect">
import * as MpAccountApi from '@/api/mp/account'
const accountId: Ref<number | undefined> = ref()
const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
const emit = defineEmits<{
(e: 'change', id: number | undefined): void
}>()
onMounted(async () => {
handleQuery()
})
const handleQuery = async () => {
const data = await MpAccountApi.getSimpleAccountList()
accountList.value = data
//
if (accountList.value.length > 0) {
accountId.value = accountList.value[0].id
emit('change', accountId.value)
}
}
const accountChanged = () => {
emit('change', accountId.value)
}
</script>

View File

@ -0,0 +1,44 @@
<template>
<el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
<el-form-item label="公众号" prop="accountId">
<el-select
v-model="accountId"
placeholder="请选择公众号"
class="!w-240px"
@change="accountChanged()"
>
<el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item>
<slot name="actions"></slot>
</el-form-item>
</el-form>
</template>
<script setup name="WxAccountSelect">
import * as MpAccountApi from '@/api/mp/account'
const accountId = ref()
const accountList = ref([])
const queryFormRef = ref()
const emit = defineEmits(['change'])
onMounted(async () => {
handleQuery()
})
const handleQuery = async () => {
const data = await MpAccountApi.getSimpleAccountList()
accountList.value = data
//
if (accountList.value.length > 0) {
accountId.value = accountList.value[0].id
emit('change', accountId.value)
}
}
const accountChanged = () => {
emit('change', accountId.value)
}
</script>

View File

@ -14,7 +14,8 @@
<p class="item-name">{{ item.name }}</p> <p class="item-name">{{ item.name }}</p>
<el-row class="ope-row"> <el-row class="ope-row">
<el-button type="success" @click="selectMaterialFun(item)"> <el-button type="success" @click="selectMaterialFun(item)">
选择 <Icon icon="ep:circle-check" /> 选择
<Icon icon="ep:circle-check" />
</el-button> </el-button>
</el-row> </el-row>
</div> </div>
@ -48,7 +49,8 @@
<el-table-column label="操作" align="center" fixed="right"> <el-table-column label="操作" align="center" fixed="right">
<template #default="scope"> <template #default="scope">
<el-button type="primary" link @click="selectMaterialFun(scope.row)" <el-button type="primary" link @click="selectMaterialFun(scope.row)"
>选择<Icon icon="ep:plus" /> >选择
<Icon icon="ep:plus" />
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
@ -89,7 +91,8 @@
> >
<template #default="scope"> <template #default="scope">
<el-button type="primary" link @click="selectMaterialFun(scope.row)" <el-button type="primary" link @click="selectMaterialFun(scope.row)"
>选择<Icon icon="akar-icons:circle-plus" /> >选择
<Icon icon="akar-icons:circle-plus" />
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
@ -110,7 +113,8 @@
<WxNews :articles="item.content.newsItem" /> <WxNews :articles="item.content.newsItem" />
<el-row class="ope-row"> <el-row class="ope-row">
<el-button type="success" @click="selectMaterialFun(item)"> <el-button type="success" @click="selectMaterialFun(item)">
选择<Icon icon="ep:circle-check" /> 选择
<Icon icon="ep:circle-check" />
</el-button> </el-button>
</el-row> </el-row>
</div> </div>
@ -127,23 +131,16 @@
</div> </div>
</template> </template>
<script lang="ts" name="WxMaterialSelect"> <script lang="ts" setup name="WxMaterialSelect">
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
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 { getMaterialPage } from '@/api/mp/material' import * as MpMaterialApi from '@/api/mp/material'
import { getFreePublishPage } from '@/api/mp/freePublish' import * as MpFreePublishApi from '@/api/mp/freePublish'
import { getDraftPage } from '@/api/mp/draft' import * as MpDraftApi from '@/api/mp/draft'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import { defineComponent, PropType } from 'vue'
export default defineComponent({ const props = defineProps({
components: {
WxNews,
WxVoicePlayer,
WxVideoPlayer
},
props: {
objData: { objData: {
type: Object, // type - accountId - type: Object, // type - accountId -
required: true required: true
@ -153,57 +150,58 @@ export default defineComponent({
type: String as PropType<string>, type: String as PropType<string>,
default: '1' default: '1'
} }
}, })
setup(props, ctx) {
// const emit = defineEmits(['select-material'])
const loading = ref(false)
// //
const total = ref(0) const loading = ref(false)
// //
const list = ref([]) const total = ref(0)
// //
const queryParams = reactive({ const list = ref([])
//
const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
accountId: props.objData.accountId accountId: props.objData.accountId
}) })
const objDataRef = reactive(props.objData) const objDataRef = reactive(props.objData)
const newsTypeRef = ref(props.newsType) const newsTypeRef = ref(props.newsType)
const selectMaterialFun = (item) => { const selectMaterialFun = (item) => {
ctx.emit('select-material', item) emit('select-material', item)
} }
/** 搜索按钮操作 */
const handleQuery = () => { const getPage = async () => {
queryParams.pageNo = 1
getPage()
}
const getPage = () => {
loading.value = true loading.value = true
try {
if (objDataRef.type === 'news' && newsTypeRef.value === '1') { if (objDataRef.type === 'news' && newsTypeRef.value === '1') {
// + // +
getFreePublishPageFun() await getFreePublishPageFun()
} else if (objDataRef.type === 'news' && newsTypeRef.value === '2') { } else if (objDataRef.type === 'news' && newsTypeRef.value === '2') {
// + 稿 // + 稿
getDraftPageFun() await getDraftPageFun()
} else { } else {
// //
getMaterialPageFun() await getMaterialPageFun()
} }
} finally {
loading.value = false
} }
}
const getMaterialPageFun = async () => { const getMaterialPageFun = async () => {
let data = await getMaterialPage({ const data = await MpMaterialApi.getMaterialPage({
...queryParams, ...queryParams,
type: objDataRef.type type: objDataRef.type
}) })
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
loading.value = false }
}
const getFreePublishPageFun = async () => { const getFreePublishPageFun = async () => {
let data = await getFreePublishPage(queryParams) const data = await MpFreePublishApi.getFreePublishPage(queryParams)
data.list.forEach((item) => { data.list.forEach((item) => {
const newsItem = item.content.newsItem const newsItem = item.content.newsItem
newsItem.forEach((article) => { newsItem.forEach((article) => {
@ -212,11 +210,10 @@ export default defineComponent({
}) })
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
loading.value = false }
}
const getDraftPageFun = async () => { const getDraftPageFun = async () => {
let data = await getDraftPage(queryParams) const data = await MpDraftApi.getDraftPage(queryParams)
data.list.forEach((item) => { data.list.forEach((item) => {
const newsItem = item.content.newsItem const newsItem = item.content.newsItem
newsItem.forEach((article) => { newsItem.forEach((article) => {
@ -225,27 +222,10 @@ export default defineComponent({
}) })
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
loading.value = false }
}
onMounted(async () => { onMounted(async () => {
getPage() getPage()
})
return {
handleQuery,
dateFormatter,
selectMaterialFun,
getMaterialPageFun,
getPage,
formatDate,
queryParams,
objDataRef,
list,
total,
loading
}
}
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -276,6 +256,7 @@ p {
.waterfall { .waterfall {
column-count: 3; column-count: 3;
} }
p { p {
color: red; color: red;
} }
@ -285,6 +266,7 @@ p {
.waterfall { .waterfall {
column-count: 2; column-count: 2;
} }
p { p {
color: orange; color: orange;
} }

View File

@ -3,31 +3,13 @@
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChanged(accountId)">
class="-mb-15px" <template #actions>
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
<el-button type="primary" plain @click="handleAdd" v-hasPermi="['mp:draft:create']"> <el-button type="primary" plain @click="handleAdd" v-hasPermi="['mp:draft:create']">
<Icon icon="ep:plus" />新增 <Icon icon="ep:plus" />新增
</el-button> </el-button>
</el-form-item> </template>
</el-form> </WxAccountSelect>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
@ -35,7 +17,7 @@
<div class="waterfall" v-loading="loading"> <div class="waterfall" v-loading="loading">
<template v-for="item in list" :key="item.articleId"> <template v-for="item in list" :key="item.articleId">
<div class="waterfall-item" v-if="item.content && item.content.newsItem"> <div class="waterfall-item" v-if="item.content && item.content.newsItem">
<wx-news :articles="item.content.newsItem" /> <WxNews :articles="item.content.newsItem" />
<!-- 操作按钮 --> <!-- 操作按钮 -->
<el-row class="ope-row"> <el-row class="ope-row">
<el-button <el-button
@ -239,7 +221,7 @@
</div> </div>
<!--富文本编辑器组件--> <!--富文本编辑器组件-->
<el-row> <el-row>
<wx-editor <WxEditor
v-model="articlesAdd[isActiveAddNews].content" v-model="articlesAdd[isActiveAddNews].content"
:account-id="uploadData.accountId" :account-id="uploadData.accountId"
v-if="hackResetEditor" v-if="hackResetEditor"
@ -258,14 +240,15 @@
import WxEditor from '@/views/mp/components/wx-editor/WxEditor.vue' import WxEditor from '@/views/mp/components/wx-editor/WxEditor.vue'
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue' import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue'
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import { getAccessToken } from '@/utils/auth' import { getAccessToken } from '@/utils/auth'
import * as MpAccountApi from '@/api/mp/account'
import * as MpDraftApi from '@/api/mp/draft' import * as MpDraftApi from '@/api/mp/draft'
import * as MpFreePublishApi from '@/api/mp/freePublish' import * as MpFreePublishApi from '@/api/mp/freePublish'
const message = useMessage() //
// API // API
// import drafts from './mock' // import drafts from './mock'
const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
const total = ref(0) // const total = ref(0) //
const list = ref([]) // const list = ref([]) //
@ -274,8 +257,6 @@ const queryParams = reactive({
pageSize: 10, pageSize: 10,
accountId: undefined accountId: undefined
}) })
const queryFormRef = ref() //
const accountList = ref([]) //
// ========== ========== // ========== ==========
const materialSelectRef = ref() const materialSelectRef = ref()
@ -298,16 +279,11 @@ const operateMaterial = ref('add')
const articlesMediaId = ref('') const articlesMediaId = ref('')
const hackResetEditor = ref(false) const hackResetEditor = ref(false)
/** 初始化 **/ /** 侦听公众号变化 **/
onMounted(async () => { const accountChanged = (accountId) => {
accountList.value = await MpAccountApi.getSimpleAccountList() setAccountId(accountId)
// getList()
if (accountList.value.length > 0) { }
// @ts-ignore
queryParams.accountId = accountList.value[0].id
}
await getList()
})
// ======================== ======================== // ======================== ========================
/** 设置账号编号 */ /** 设置账号编号 */
@ -341,26 +317,6 @@ const getList = async () => {
} }
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
//
if (queryParams.accountId) {
setAccountId(queryParams.accountId)
}
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
handleQuery()
}
// ======================== /稿 ======================== // ======================== /稿 ========================
/** 新增按钮操作 */ /** 新增按钮操作 */
const handleAdd = () => { const handleAdd = () => {

View File

@ -3,28 +3,7 @@
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChanged(accountId)" />
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
@ -59,10 +38,11 @@
</ContentWrap> </ContentWrap>
</template> </template>
<script setup lang="ts" name="MpFreePublish"> <script setup name="MpFreePublish">
import * as FreePublishApi from '@/api/mp/freePublish' import * as FreePublishApi from '@/api/mp/freePublish'
import * as MpAccountApi from '@/api/mp/account'
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -72,18 +52,17 @@ const list = ref([]) // 列表的数据
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
accountId: undefined // accountId: undefined
}) })
const queryFormRef = ref() //
const accountList = ref<MpAccountApi.AccountVO[]>([]) // /** 侦听公众号变化 **/
const accountChanged = (accountId) => {
queryParams.accountId = accountId
getList()
}
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
//
if (!queryParams.accountId) {
message.error('未选中公众号,无法查询已发表图文')
return false
}
try { try {
loading.value = true loading.value = true
const data = await FreePublishApi.getFreePublishPage(queryParams) const data = await FreePublishApi.getFreePublishPage(queryParams)
@ -94,22 +73,6 @@ const getList = async () => {
} }
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
handleQuery()
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (item) => { const handleDelete = async (item) => {
try { try {
@ -122,16 +85,8 @@ const handleDelete = async (item) => {
await getList() await getList()
} catch {} } catch {}
} }
onMounted(async () => {
accountList.value = await MpAccountApi.getSimpleAccountList()
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
await getList()
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.ope-row { .ope-row {
margin-top: 5px; margin-top: 5px;

View File

@ -2,26 +2,12 @@
<doc-alert title="公众号素材" url="https://doc.iocoder.cn/mp/material/" /> <doc-alert title="公众号素材" url="https://doc.iocoder.cn/mp/material/" />
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <el-form class="-mb-15px" :inline="true" label-width="68px">
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId"> <el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px"> <WxMpSelect @change="(accountId) => accountChange(accountId)" />
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button> <slot name="actions"></slot>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap> </ContentWrap>
@ -31,11 +17,11 @@
<!-- tab 1图片 --> <!-- tab 1图片 -->
<el-tab-pane name="image"> <el-tab-pane name="image">
<template #label> <template #label>
<span><Icon icon="ep:picture" />图片</span> <span> <Icon icon="ep:picture" />图片 </span>
</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="actionUrl" :action="uploadUrl"
:headers="headers" :headers="headers"
multiple multiple
:limit="1" :limit="1"
@ -58,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
@ -82,11 +68,11 @@
<!-- tab 2语音 --> <!-- tab 2语音 -->
<el-tab-pane name="voice"> <el-tab-pane name="voice">
<template #label> <template #label>
<span><Icon icon="ep:microphone" />语音</span> <span> <Icon icon="ep:microphone" />语音 </span>
</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="actionUrl" :action="uploadUrl"
:headers="headers" :headers="headers"
multiple multiple
:limit="1" :limit="1"
@ -103,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" />
@ -111,9 +99,15 @@
<WxVoicePlayer :url="scope.row.url" /> <WxVoicePlayer :url="scope.row.url" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="上传时间" align="center" prop="createTime" width="180"> <el-table-column
label="上传时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180"
>
<template #default="scope"> <template #default="scope">
<span>{{ formatDate(scope.row.createTime) }}</span> <span>{{ scope.row.createTime }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@ -145,7 +139,7 @@
<!-- tab 3视频 --> <!-- tab 3视频 -->
<el-tab-pane name="video"> <el-tab-pane name="video">
<template #label> <template #label>
<span><Icon icon="ep:video-play" /> 视频</span> <span> <Icon icon="ep:video-play" /> 视频 </span>
</template> </template>
<div class="add_but" v-hasPermi="['mp:material:upload-permanent']"> <div class="add_but" v-hasPermi="['mp:material:upload-permanent']">
<el-button type="primary" plain @click="handleAddVideo">新建视频</el-button> <el-button type="primary" plain @click="handleAddVideo">新建视频</el-button>
@ -158,7 +152,7 @@
v-loading="addMaterialLoading" v-loading="addMaterialLoading"
> >
<el-upload <el-upload
:action="actionUrl" :action="uploadUrl"
:headers="headers" :headers="headers"
multiple multiple
:limit="1" :limit="1"
@ -197,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" />
@ -212,16 +209,22 @@
<WxVideoPlayer :url="scope.row.url" /> <WxVideoPlayer :url="scope.row.url" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="上传时间" align="center" prop="createTime" width="180"> <el-table-column
label="上传时间"
align="center"
:formatter="dateFormatter"
prop="createTime"
width="180"
>
<template #default="scope"> <template #default="scope">
<span>{{ formatDate(scope.row.createTime) }}</span> <span>{{ scope.row.createTime }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" fixed="right"> <el-table-column label="操作" align="center" fixed="right">
<template #default="scope"> <template #default="scope">
<el-button type="primary" link plain @click="handleDownload(scope.row)" <el-button type="primary" link plain @click="handleDownload(scope.row)">
><Icon icon="ep:download" />下载</el-button <Icon icon="ep:download" />下载
> </el-button>
<el-button <el-button
type="primary" type="primary"
link link
@ -246,23 +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 { getSimpleAccountList } from '@/api/mp/account' import WxMpSelect from '@/views/mp/components/WxMpSelect.vue'
import { getMaterialPage, deletePermanentMaterial } from '@/api/mp/material' import * as MpMaterialApi from '@/api/mp/material'
import { getAccessToken } from '@/utils/auth' import * as authUtil from '@/utils/auth'
import { formatDate } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import type {
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 uploadUrl = BASE_URL + '/admin-api/mp/material/upload-permanent'
const headers = { Authorization: 'Bearer ' + authUtil.getAccessToken() }
const message = useMessage() const message = useMessage()
const queryFormRef = ref() const uploadFormRef = ref<FormInstance>()
const uploadFormRef = ref() const uploadVideoRef = ref<UploadInstance>()
const uploadVideoRef = ref()
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)
// //
@ -270,17 +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 actionUrl = BASE_URL + '/admin-api/mp/material/upload-permanent' const fileList = ref<UploadUserFile[]>([])
const headers = { Authorization: 'Bearer ' + getAccessToken() }
const fileList = ref([]) interface UploadData {
const uploadData = reactive({ type: MatertialType
title: string
introduction: string
}
const uploadData: UploadData = reactive({
type: 'image', type: 'image',
title: '', title: '',
introduction: '' introduction: ''
@ -289,96 +320,57 @@ 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 accountList = ref([]) const accountChange = (accountId: number | undefined) => {
onMounted(() => {
getSimpleAccountList().then((data) => {
accountList.value = data
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
//
getList()
})
})
// ======================== ========================
/** 设置账号编号 */
const setAccountId = (accountId) => {
queryParams.accountId = accountId queryParams.accountId = accountId
uploadData.accountId = accountId getList()
} }
// ======================== ========================
/** 查询列表 */ /** 查询列表 */
const getList = () => { const getList = async () => {
//
if (!queryParams.accountId) {
message.error('未选中公众号,无法查询草稿箱')
return false
}
loading.value = true loading.value = true
getMaterialPage({ try {
const data = await MpMaterialApi.getMaterialPage({
...queryParams, ...queryParams,
type: type.value type: type.value
}) })
.then((data) => {
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
}) } finally {
.finally(() => {
loading.value = false loading.value = false
}) }
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
const handleQuery = () => { const handleQuery = () => {
queryParams.pageNo = 1 queryParams.pageNo = 1
//
if (queryParams.accountId) {
setAccountId(queryParams.accountId)
}
getList() getList()
} }
/** 重置按钮操作 */ const handleTabChange = (tabName: TabPaneName) => {
const resetQuery = () => {
queryFormRef.value?.resetFields()
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
handleQuery()
}
const handleTabChange = (tabName) => {
// type // type
uploadData.type = tabName uploadData.type = tabName as MatertialType
// tab
list.value = []
total.value = 0
// //
handleQuery() handleQuery()
} }
// ======================== ======================== // ======================== ========================
const beforeImageUpload = (file) => { const beforeImageUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => {
const isType = const isType = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/jpg'].includes(
file.type === 'image/jpeg' || rawFile.type
file.type === 'image/png' || )
file.type === 'image/gif' ||
file.type === 'image/bmp' ||
file.type === 'image/jpg'
if (!isType) { if (!isType) {
message.error('上传图片格式不对!') message.error('上传图片格式不对!')
return false return false
} }
const isLt = file.size / 1024 / 1024 < 2 const isLt = rawFile.size / 1024 / 1024 < 2
if (!isLt) { if (!isLt) {
message.error('上传图片大小不能超过 2M!') message.error('上传图片大小不能超过 2M!')
return false return false
@ -387,13 +379,9 @@ const beforeImageUpload = (file) => {
return true return true
} }
const beforeVoiceUpload = (file) => { const beforeVoiceUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => {
const isType = const isType = ['audio/mp3', 'audio/wma', 'audio/wav', 'audio/amr'].includes(file.type)
file.type === 'audio/mp3' || const isLt = rawFile.size / 1024 / 1024 < 2
file.type === 'audio/wma' ||
file.type === 'audio/wav' ||
file.type === 'audio/amr'
const isLt = file.size / 1024 / 1024 < 2
if (!isType) { if (!isType) {
message.error('上传语音格式不对!') message.error('上传语音格式不对!')
return false return false
@ -406,22 +394,24 @@ const beforeVoiceUpload = (file) => {
return true return true
} }
const beforeVideoUpload = (file) => { const beforeVideoUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => {
const isType = file.type === 'video/mp4' const isType = rawFile.type === 'video/mp4'
if (!isType) { if (!isType) {
message.error('上传视频格式不对!') message.error('上传视频格式不对!')
return false return false
} }
const isLt = file.size / 1024 / 1024 < 10
const isLt = rawFile.size / 1024 / 1024 < 10
if (!isLt) { if (!isLt) {
message.error('上传视频大小不能超过 10M!') message.error('上传视频大小不能超过 10M!')
return false return false
} }
addMaterialLoading.value = true addMaterialLoading.value = true
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) {
@ -440,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()
}) })
} }
@ -474,9 +464,9 @@ const resetVideo = () => {
} }
// ======================== ======================== // ======================== ========================
const handleDelete = async (item) => { const handleDelete = async (item: any) => {
await message.confirm('此操作将永久删除该文件, 是否继续?') await message.confirm('此操作将永久删除该文件, 是否继续?')
await deletePermanentMaterial(item.id) await MpMaterialApi.deletePermanentMaterial(item.id)
message.alertSuccess('删除成功') message.alertSuccess('删除成功')
} }
</script> </script>
@ -487,40 +477,48 @@ const handleDelete = async (item) => {
width: 100%; width: 100%;
column-gap: 10px; column-gap: 10px;
column-count: 5; column-count: 5;
margin-top: 10px; /* 芋道源码:增加 10px避免顶着上面 */ margin-top: 10px;
/* 芋道源码:增加 10px避免顶着上面 */
} }
.waterfall-item { .waterfall-item {
padding: 10px; padding: 10px;
margin-bottom: 10px; margin-bottom: 10px;
break-inside: avoid; break-inside: avoid;
border: 1px solid #eaeaea; border: 1px solid #eaeaea;
} }
.material-img { .material-img {
width: 100%; width: 100%;
} }
p { p {
line-height: 30px; line-height: 30px;
} }
@media (min-width: 992px) and (max-width: 1300px) { @media (min-width: 992px) and (max-width: 1300px) {
.waterfall { .waterfall {
column-count: 3; column-count: 3;
} }
p { p {
color: red; color: red;
} }
} }
@media (min-width: 768px) and (max-width: 991px) { @media (min-width: 768px) and (max-width: 991px) {
.waterfall { .waterfall {
column-count: 2; column-count: 2;
} }
p { p {
color: orange; color: orange;
} }
} }
@media (max-width: 767px) { @media (max-width: 767px) {
.waterfall { .waterfall {
column-count: 1; column-count: 1;
} }
} }
/*瀑布流样式*/
</style> </style>

View File

@ -2,22 +2,7 @@
<doc-alert title="公众号菜单" url="https://doc.iocoder.cn/mp/menu/" /> <doc-alert title="公众号菜单" url="https://doc.iocoder.cn/mp/menu/" />
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px"> <WxAccountSelect @change="(accountId) => accountChanged(accountId)" />
<el-form-item label="公众号" prop="accountId">
<el-select v-model="accountId" placeholder="请选择公众号" class="!w-240px">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
</el-form-item>
</el-form>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
@ -204,17 +189,15 @@ import { handleTree } from '@/utils/tree'
import WxReplySelect from '@/views/mp/components/wx-reply/main.vue' import WxReplySelect from '@/views/mp/components/wx-reply/main.vue'
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue' import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue'
import { deleteMenu, getMenuList, saveMenu } from '@/api/mp/menu' import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import * as MpAccountApi from '@/api/mp/account' import * as MpMenuApi from '@/api/mp/menu'
import menuOptions from './menuOptions' import menuOptions from './menuOptions'
const message = useMessage() // const message = useMessage() //
// ======================== ======================== // ======================== ========================
const loading = ref(true) // const loading = ref(true) //
const accountId = ref(undefined) // Id const accountId = ref(undefined) // Id
const name = ref('') //
const menuList = ref({ children: [] }) const menuList = ref({ children: [] })
const accountList = ref([]) //
// ======================== ======================== // ======================== ========================
const isActive = ref(-1) // const isActive = ref(-1) //
@ -228,60 +211,34 @@ const showConfigureContent = ref(true) // 是否展示配置内容;如果有
const hackResetWxReplySelect = ref(false) // WxReplySelect const hackResetWxReplySelect = ref(false) // WxReplySelect
const tempObj = ref({}) // const tempObj = ref({}) //
const tempSelfObj = ref({ // tempObjmenu
// tempObjmenu const tempSelfObj = ref({})
})
const dialogNewsVisible = ref(false) // const dialogNewsVisible = ref(false) //
onMounted(async () => { /** 侦听公众号变化 **/
accountList.value = await MpAccountApi.getSimpleAccountList() const accountChanged = (id) => {
//
if (accountList.value.length > 0) {
// @ts-ignore
setAccountId(accountList.value[0].id)
}
await getList()
})
// ======================== ========================
/** 设置账号编号 */
const setAccountId = (id) => {
accountId.value = id accountId.value = id
name.value = accountList.value.find((item) => item.id === accountId.value)?.name getList()
} }
/** 查询并转换菜单 **/
const getList = async () => { const getList = async () => {
loading.value = false loading.value = false
getMenuList(accountId.value) try {
.then((response) => { const data = await MpMenuApi.getMenuList(accountId.value)
const menuData = convertMenuList(response) const menuData = convertMenuList(data)
menuList.value = handleTree(menuData, 'id') menuList.value = handleTree(menuData, 'id')
}) } finally {
.finally(() => {
loading.value = false loading.value = false
}) }
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
const handleQuery = () => { const handleQuery = () => {
resetForm() resetForm()
//
if (accountId.value) {
setAccountId(accountId.value)
}
getList() getList()
} }
/** 重置按钮操作 */
const resetQuery = () => {
resetForm()
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
handleQuery()
}
// menuList menuList // menuList menuList
const convertMenuList = (list) => { const convertMenuList = (list) => {
if (!list) return [] if (!list) return []
@ -443,7 +400,7 @@ const handleSave = async () => {
try { try {
await message.confirm('确定要删除吗?') await message.confirm('确定要删除吗?')
loading.value = true loading.value = true
await saveMenu(accountId.value, convertMenuFormList()) await MpMenuApi.saveMenu(accountId.value, convertMenuFormList())
getList() getList()
message.notifySuccess('发布成功') message.notifySuccess('发布成功')
} finally { } finally {
@ -464,7 +421,7 @@ const handleDelete = async () => {
try { try {
await message.confirm('确定要删除吗?') await message.confirm('确定要删除吗?')
loading.value = true loading.value = true
await deleteMenu(accountId.value) await MpMenuApi.deleteMenu(accountId.value)
handleQuery() handleQuery()
message.notifySuccess('清空成功') message.notifySuccess('清空成功')
} finally { } finally {
@ -546,6 +503,7 @@ const deleteMaterial = () => {
delete tempObj.value['replyArticles'] delete tempObj.value['replyArticles']
} }
</script> </script>
<!--本组件样式--> <!--本组件样式-->
<style lang="scss" scoped="scoped"> <style lang="scss" scoped="scoped">
/* 公共颜色变量 */ /* 公共颜色变量 */

View File

@ -3,45 +3,16 @@
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChanged(accountId)">
class="-mb-15px" <template #actions>
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="标签名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入标签名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
<el-button type="primary" plain @click="openForm('create')" v-hasPermi="['mp:tag:create']"> <el-button type="primary" plain @click="openForm('create')" v-hasPermi="['mp:tag:create']">
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
<el-button type="success" plain @click="handleSync" v-hasPermi="['mp:tag:sync']"> <el-button type="success" plain @click="handleSync" v-hasPermi="['mp:tag:sync']">
<Icon icon="ep:refresh" class="mr-5px" /> 同步 <Icon icon="ep:refresh" class="mr-5px" /> 同步
</el-button> </el-button>
</el-form-item> </template>
</el-form> </WxAccountSelect>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
@ -92,8 +63,8 @@
</template> </template>
<script setup lang="ts" name="MpTag"> <script setup lang="ts" name="MpTag">
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import * as MpTagApi from '@/api/mp/tag' import * as MpTagApi from '@/api/mp/tag'
import * as MpAccountApi from '@/api/mp/account'
import TagForm from './TagForm.vue' import TagForm from './TagForm.vue'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -104,19 +75,18 @@ const list = ref([]) // 列表的数据
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
accountId: undefined, accountId: undefined
name: null
}) })
const queryFormRef = ref() //
const accountList = ref<MpAccountApi.AccountVO[]>([]) // /** 侦听公众号变化 **/
const accountChanged = (accountId) => {
queryParams.pageNo = 1
queryParams.accountId = accountId
getList()
}
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
//
if (!queryParams.accountId) {
await message.error('未选中公众号,无法查询标签')
return
}
try { try {
loading.value = true loading.value = true
const data = await MpTagApi.getTagPage(queryParams) const data = await MpTagApi.getTagPage(queryParams)
@ -127,22 +97,6 @@ const getList = async () => {
} }
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
handleQuery()
}
/** 添加/修改操作 */ /** 添加/修改操作 */
const formRef = ref() const formRef = ref()
const openForm = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
@ -172,14 +126,4 @@ const handleSync = async () => {
await getList() await getList()
} catch {} } catch {}
} }
/** 初始化 **/
onMounted(async () => {
accountList.value = await MpAccountApi.getSimpleAccountList()
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
await getList()
})
</script> </script>

View File

@ -3,49 +3,13 @@
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChanged(accountId)">
class="-mb-15px" <template #actions>
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="用户标识" prop="openid">
<el-input
v-model="queryParams.openid"
placeholder="请输入用户标识"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="昵称" prop="nickname">
<el-input
v-model="queryParams.nickname"
placeholder="请输入昵称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
<el-button type="success" plain @click="handleSync" v-hasPermi="['mp:user:sync']"> <el-button type="success" plain @click="handleSync" v-hasPermi="['mp:user:sync']">
<Icon icon="ep:refresh" class="mr-5px" /> 同步 <Icon icon="ep:refresh" class="mr-5px" /> 同步
</el-button> </el-button>
</el-form-item> </template>
</el-form> </WxAccountSelect>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
@ -101,11 +65,12 @@
<UserForm ref="formRef" @success="getList" /> <UserForm ref="formRef" @success="getList" />
</template> </template>
<script lang="ts" setup name="MpUser"> <script lang="ts" setup name="MpUser">
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import * as MpAccountApi from '@/api/mp/account'
import * as MpUserApi from '@/api/mp/user' import * as MpUserApi from '@/api/mp/user'
import * as MpTagApi from '@/api/mp/tag' import * as MpTagApi from '@/api/mp/tag'
import UserForm from './UserForm.vue' import UserForm from './UserForm.vue'
const message = useMessage() // const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
@ -118,17 +83,22 @@ const queryParams = reactive({
openid: null, openid: null,
nickname: null nickname: null
}) })
const queryFormRef = ref() //
const accountList = ref([]) //
const tagList = ref([]) // const tagList = ref([]) //
/** 初始化 */
onMounted(async () => {
tagList.value = await MpTagApi.getSimpleTagList()
})
/** 侦听公众号变化 **/
const accountChanged = (accountId) => {
queryParams.pageNo = 1
queryParams.accountId = accountId
getList()
}
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
//
if (!queryParams.accountId) {
message.error('未选中公众号,无法查询用户')
return false
}
try { try {
loading.value = true loading.value = true
const data = await MpUserApi.getUserPage(queryParams) const data = await MpUserApi.getUserPage(queryParams)
@ -139,22 +109,6 @@ const getList = async () => {
} }
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
//
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
handleQuery()
}
/** 添加/修改操作 */ /** 添加/修改操作 */
const formRef = ref() const formRef = ref()
const openForm = (id: number) => { const openForm = (id: number) => {
@ -171,17 +125,4 @@ const handleSync = async () => {
await getList() await getList()
} catch {} } catch {}
} }
/** 初始化 */
onMounted(async () => {
//
tagList.value = await MpTagApi.getSimpleTagList()
//
accountList.value = await MpAccountApi.getSimpleAccountList()
if (accountList.value.length > 0) {
queryParams.accountId = accountList.value[0].id
}
await getList()
})
</script> </script>