refactor: WxMaterialSelect组件setup

This commit is contained in:
dhb52 2023-04-10 00:26:43 +08:00
parent e035eb2618
commit a8b4c16a7e

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,26 +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,
queryParams,
objDataRef,
list,
total,
loading
}
}
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -275,6 +256,7 @@ p {
.waterfall { .waterfall {
column-count: 3; column-count: 3;
} }
p { p {
color: red; color: red;
} }
@ -284,6 +266,7 @@ p {
.waterfall { .waterfall {
column-count: 2; column-count: 2;
} }
p { p {
color: orange; color: orange;
} }