refactor: mp模块统一accountId未初始化值为-1,删除QueryParams定义

(cherry picked from commit 198752868c)
This commit is contained in:
dhb52 2023-04-22 23:43:35 +08:00 committed by shizhong
parent 64d4583805
commit a737b267a8
11 changed files with 42 additions and 83 deletions

View File

@ -1,7 +1,7 @@
import request from '@/config/axios'
export interface AccountVO {
id?: number
id: number
name: string
}

View File

@ -103,6 +103,7 @@ import ReplyTable from './components/ReplyTable.vue'
import { MsgType } from './components/types'
const message = useMessage() //
const accountId = ref(-1) // ID
const msgType = ref<MsgType>(MsgType.Keyword) //
const RequestMessageTypes = ['text', 'image', 'voice', 'video', 'shortvideo', 'location', 'link'] //
const loading = ref(true) //
@ -110,15 +111,10 @@ const total = ref(0) // 总条数
const list = ref<any[]>([]) //
const formRef = ref<FormInstance | null>(null) // ref
//
interface QueryParams {
pageNo: number
pageSize: number
accountId: number
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: 0
accountId: accountId
})
const dialogTitle = ref('') //
@ -127,7 +123,7 @@ const replyForm = ref<any>({}) // 表单参数
//
const reply = ref<Reply>({
type: ReplyType.Text,
accountId: 0
accountId: -1
})
//
const rules = {
@ -137,8 +133,9 @@ const rules = {
/** 侦听账号变化 */
const onAccountChanged = (id: number) => {
queryParams.accountId = id
accountId.value = id
reply.value.accountId = id
queryParams.pageNo = 1
getList()
}

View File

@ -8,13 +8,14 @@
import * as MpAccountApi from '@/api/mp/account'
const account: MpAccountApi.AccountVO = reactive({
id: undefined,
id: -1,
name: ''
})
const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
const accountList = ref<MpAccountApi.AccountVO[]>([])
const emit = defineEmits<{
(e: 'change', id: number, name: string): void
(e: 'change', id: number, name: string)
}>()
const handleQuery = async () => {

View File

@ -76,18 +76,14 @@ import {
const message = useMessage() //
const accountId = ref<number>(-1)
const accountId = ref(-1)
provide('accountId', accountId)
const loading = ref(true) //
const list = ref<any[]>([]) //
const total = ref(0) //
interface QueryParams {
pageNo: number
pageSize: number
accountId: number
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: accountId
@ -102,7 +98,8 @@ const isSubmitting = ref(false)
/** 侦听公众号变化 **/
const onAccountChanged = (id: number) => {
setAccountId(id)
accountId.value = id
queryParams.pageNo = 1
getList()
}
@ -115,12 +112,6 @@ const onBeforeDialogClose = async (onDone: () => {}) => {
}
// ======================== ========================
/** 设置账号编号 */
const setAccountId = (id: number) => {
accountId.value = id
// queryParams.accountId = id
}
/** 查询列表 */
const getList = async () => {
loading.value = true
@ -161,10 +152,10 @@ const onSubmitNewsItem = async () => {
isSubmitting.value = true
try {
if (isCreating.value) {
await MpDraftApi.createDraft(queryParams.accountId, newsList.value)
await MpDraftApi.createDraft(accountId.value, newsList.value)
message.notifySuccess('新增成功')
} else {
await MpDraftApi.updateDraft(queryParams.accountId, mediaId.value, newsList.value)
await MpDraftApi.updateDraft(accountId.value, mediaId.value, newsList.value)
message.notifySuccess('更新成功')
}
} finally {
@ -176,7 +167,6 @@ const onSubmitNewsItem = async () => {
// ======================== 稿 ========================
const onPublish = async (item: Article) => {
const accountId = queryParams.accountId
const mediaId = item.mediaId
const content =
'你正在通过发布的方式发表内容。 发布不占用群发次数,一天可多次发布。' +
@ -184,7 +174,7 @@ const onPublish = async (item: Article) => {
'发布后,你可以前往发表记录获取链接,也可以将发布内容添加到自定义菜单、自动回复、话题和页面模板中。'
try {
await message.confirm(content)
await MpFreePublishApi.submitFreePublish(accountId, mediaId)
await MpFreePublishApi.submitFreePublish(accountId.value, mediaId)
message.notifySuccess('发布成功')
await getList()
} catch {}
@ -192,11 +182,10 @@ const onPublish = async (item: Article) => {
/** 删除按钮操作 */
const onDelete = async (item: Article) => {
const accountId = queryParams.accountId
const mediaId = item.mediaId
try {
await message.confirm('此操作将永久删除该草稿, 是否继续?')
await MpDraftApi.deleteDraft(accountId, mediaId)
await MpDraftApi.deleteDraft(accountId.value, mediaId)
message.notifySuccess('删除成功')
await getList()
} catch {}

View File

@ -59,20 +59,16 @@ const loading = ref(true) // 列表的加载中
const total = ref(0) //
const list = ref<any[]>([]) //
interface QueryParams {
pageNo: number
pageSize: number
accountId: number
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: 0
accountId: -1
})
/** 侦听公众号变化 **/
const onAccountChanged = (id: number) => {
queryParams.accountId = id
queryParams.pageNo = 1
getList()
}

View File

@ -99,16 +99,10 @@ const loading = ref(false) // 遮罩层
const list = ref<any[]>([]) //
const total = ref(0) //
//
interface QueryParams {
pageNo: number
pageSize: number
accountId: number
permanent: boolean
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: 0,
accountId: -1,
permanent: true
})
const showCreateVideo = ref(false) //
@ -116,6 +110,7 @@ const showCreateVideo = ref(false) // 是否新建视频的弹窗
/** 侦听公众号变化 **/
const onAccountChanged = (id: number) => {
queryParams.accountId = id
queryParams.pageNo = 1
getList()
}

View File

@ -65,7 +65,7 @@ const MENU_NOT_SELECTED = '__MENU_NOT_SELECTED__'
// ======================== ========================
const loading = ref(false) //
const accountId = ref<number>(0)
const accountId = ref(-1)
const accountName = ref<string>('')
const menuList = ref<Menu[]>([])

View File

@ -93,20 +93,12 @@ const total = ref(0) // 数据的总页数
const list = ref<any[]>([]) //
//
interface QueryParams {
pageNo: number
pageSize: number
openid: string | undefined
accountId: number
type: MsgType | undefined
createTime: string[] | []
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
openid: undefined,
accountId: 0,
type: undefined,
openid: '',
accountId: -1,
type: MsgType.Text,
createTime: []
})
const queryFormRef = ref<FormInstance | null>(null) //
@ -120,6 +112,7 @@ const messageBox = reactive({
/** 侦听accountId */
const onAccountChanged = (id: number) => {
queryParams.accountId = id
queryParams.pageNo = 1
handleQuery()
}

View File

@ -84,7 +84,7 @@ const dateRange = ref([
beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7)),
endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24))
])
const accountId = ref() //
const accountId = ref(-1) //
const accountList = ref<MpAccountApi.AccountVO[]>([]) //
const xAxisDate = ref([] as any[]) // X
@ -232,7 +232,7 @@ const getAccountList = async () => {
accountList.value = await MpAccountApi.getSimpleAccountList()
//
if (accountList.value.length > 0) {
accountId.value = accountList.value[0].id
accountId.value = accountList.value[0].id!
}
}

View File

@ -95,23 +95,18 @@ const loading = ref(true) // 列表的加载中
const total = ref(0) //
const list = ref<any[]>([]) //
interface QueryParams {
pageNo: number
pageSize: number
accountId: number
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: 0
accountId: -1
})
const formRef = ref<InstanceType<typeof TagForm> | null>(null)
/** 侦听公众号变化 **/
const onAccountChanged = (id: number) => {
queryParams.pageNo = 1
queryParams.accountId = id
queryParams.pageNo = 1
getList()
}

View File

@ -113,27 +113,20 @@ const loading = ref(true) // 列表的加载中
const total = ref(0) //
const list = ref<any[]>([]) //
interface QueryParams {
pageNo: number
pageSize: number
accountId: number
openid: string | null
nickname: string | null
}
const queryParams: QueryParams = reactive({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
accountId: 0,
openid: null,
nickname: null
accountId: -1,
openid: '',
nickname: ''
})
const queryFormRef = ref<FormInstance | null>(null) //
const tagList = ref<any[]>([]) //
/** 侦听公众号变化 **/
const onAccountChanged = (id: number) => {
queryParams.pageNo = 1
queryParams.accountId = id
queryParams.pageNo = 1
getList()
}