feat:【antd/ele】【mp】优化 mp 账号的选择逻辑

This commit is contained in:
YunaiV
2025-11-19 21:58:25 +08:00
parent 25cd2b629c
commit d7b6c87e33
23 changed files with 127 additions and 171 deletions

View File

@@ -1,21 +1,15 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridPropTypes } from '#/adapter/vxe-table'; import type { VxeGridPropTypes } from '#/adapter/vxe-table';
import type { MpAccountApi } from '#/api/mp/account';
import { markRaw } from 'vue'; import { markRaw } from 'vue';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { getSimpleAccountList } from '#/api/mp/account';
import { WxReply } from '#/views/mp/components'; import { WxReply } from '#/views/mp/components';
import { MsgType } from './types'; import { MsgType } from './types';
/** 关联数据 */
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
// TODO @芋艿:要不要使用统一枚举? // TODO @芋艿:要不要使用统一枚举?
const RequestMessageTypes = new Set([ const RequestMessageTypes = new Set([
'image', 'image',
@@ -159,21 +153,12 @@ export function useFormSchema(msgType: MsgType): VbenFormSchema[] {
} }
/** 列表的搜索表单 */ /** 列表的搜索表单 */
// TODO @芋艿:貌似可能微信号拿不到。
export function useGridFormSchema(): VbenFormSchema[] { export function useGridFormSchema(): VbenFormSchema[] {
return [ return [
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'ApiSelect', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
]; ];
} }

View File

@@ -16,6 +16,7 @@ import {
getAutoReplyPage, getAutoReplyPage,
} from '#/api/mp/autoReply'; } from '#/api/mp/autoReply';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { WxAccountSelect } from '#/views/mp/components';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import ReplyContentCell from './modules/content.vue'; import ReplyContentCell from './modules/content.vue';
@@ -43,6 +44,12 @@ function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
gridApi.formApi.setValues({ accountId });
gridApi.formApi.submitForm();
}
/** 切换回复类型 */ /** 切换回复类型 */
async function onTabChange(tabName: any) { async function onTabChange(tabName: any) {
msgType.value = tabName; msgType.value = tabName;
@@ -106,7 +113,6 @@ const [FormModal, formModalApi] = useVbenModal({
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
submitOnChange: true, // 表单值变化时自动提交,这样 accountId 会被正确传递到查询函数
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(Number(msgType.value) as MsgType), columns: useGridColumns(Number(msgType.value) as MsgType),
@@ -123,6 +129,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
}, },
}, },
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
@@ -144,6 +151,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid> <Grid>
<template #form-accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
<template #toolbar-actions> <template #toolbar-actions>
<Tabs <Tabs
v-model:active-key="msgType" v-model:active-key="msgType"

View File

@@ -1,5 +1,6 @@
// 消息类型Follow: 关注时回复Message: 消息回复Keyword: 关键词回复) // 消息类型Follow: 关注时回复Message: 消息回复Keyword: 关键词回复)
// 作为 tab.nameenum 的数字不能随意修改,与 api 参数相关 // 作为 tab.nameenum 的数字不能随意修改,与 api 参数相关
// TODO @hw可以搞到 biz-mp-enum.ts 里。
export enum MsgType { export enum MsgType {
Follow = 1, Follow = 1,
Keyword = 3, Keyword = 3,

View File

@@ -59,7 +59,7 @@ onMounted(handleQuery);
<Select <Select
v-model:value="account.id" v-model:value="account.id"
placeholder="请选择公众号" placeholder="请选择公众号"
class="!w-[240px]" class="!w-full"
@change="onChanged" @change="onChanged"
> >
<Select.Option v-for="item in accountList" :key="item.id" :value="item.id"> <Select.Option v-for="item in accountList" :key="item.id" :value="item.id">

View File

@@ -1,12 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MpAccountApi } from '#/api/mp/account';
import { getSimpleAccountList } from '#/api/mp/account';
/** 关联数据 */
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 获取表格列配置 */ /** 获取表格列配置 */
export function useGridColumns(): VxeTableGridOptions['columns'] { export function useGridColumns(): VxeTableGridOptions['columns'] {
@@ -32,15 +25,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'ApiSelect', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
]; ];
} }

View File

@@ -11,6 +11,7 @@ import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteDraft, getDraftPage } from '#/api/mp/draft'; import { deleteDraft, getDraftPage } from '#/api/mp/draft';
import { submitFreePublish } from '#/api/mp/freePublish'; import { submitFreePublish } from '#/api/mp/freePublish';
import { WxAccountSelect } from '#/views/mp/components';
import { createEmptyNewsItem } from '#/views/mp/draft/modules/types'; import { createEmptyNewsItem } from '#/views/mp/draft/modules/types';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
@@ -24,6 +25,12 @@ function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
gridApi.formApi.setValues({ accountId });
gridApi.formApi.submitForm();
}
/** 新增草稿 */ /** 新增草稿 */
async function handleCreate() { async function handleCreate() {
const formValues = await gridApi.formApi.getValues(); const formValues = await gridApi.formApi.getValues();
@@ -115,7 +122,6 @@ const [FormModal, formModalApi] = useVbenModal({
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
submitOnChange: true,
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(), columns: useGridColumns(),
@@ -144,6 +150,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}; };
}, },
}, },
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'mediaId', keyField: 'mediaId',
@@ -167,6 +174,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="草稿列表"> <Grid table-title="草稿列表">
<template #form-accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[

View File

@@ -1,29 +1,14 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { MpAccountApi } from '#/api/mp/account';
import { beginOfDay, endOfDay, formatDateTime } from '@vben/utils'; import { beginOfDay, endOfDay, formatDateTime } from '@vben/utils';
import { getSimpleAccountList } from '#/api/mp/account';
/** 关联数据 */
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 列表的搜索表单 */ /** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] { export function useGridFormSchema(): VbenFormSchema[] {
return [ return [
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'ApiSelect', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
{ {
fieldName: 'dateRange', fieldName: 'dateRange',
@@ -36,7 +21,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
defaultValue: [ defaultValue: [
formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))), formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))),
formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))), formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))),
] as [Date, Date], ],
}, },
]; ];
} }

View File

@@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts'; import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue'; import { ref } from 'vue';
import { ContentWrap, Page } from '@vben/common-ui'; import { ContentWrap, Page } from '@vben/common-ui';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts'; import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
@@ -16,6 +16,7 @@ import {
getUserCumulate, getUserCumulate,
getUserSummary, getUserSummary,
} from '#/api/mp/statistics'; } from '#/api/mp/statistics';
import { WxAccountSelect } from '#/views/mp/components';
import { import {
interfaceSummaryOption, interfaceSummaryOption,
@@ -95,6 +96,12 @@ async function getSummary(values: Record<string, any>) {
); );
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
queryFormApi.setValues({ accountId });
queryFormApi.submitForm();
}
const [QueryForm, queryFormApi] = useVbenForm({ const [QueryForm, queryFormApi] = useVbenForm({
commonConfig: { commonConfig: {
componentProps: { componentProps: {
@@ -106,17 +113,16 @@ const [QueryForm, queryFormApi] = useVbenForm({
wrapperClass: 'grid-cols-1 md:grid-cols-2', wrapperClass: 'grid-cols-1 md:grid-cols-2',
handleSubmit: getSummary, handleSubmit: getSummary,
}); });
/** 初始化 */
onMounted(() => {
queryFormApi.submitForm();
});
</script> </script>
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<ContentWrap class="h-full w-full"> <ContentWrap class="h-full w-full">
<QueryForm /> <QueryForm>
<template #accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
</QueryForm>
<div class="flex h-1/3 w-full gap-4"> <div class="flex h-1/3 w-full gap-4">
<Card class="h-full w-1/2" title="用户增减数据"> <Card class="h-full w-1/2" title="用户增减数据">

View File

@@ -1,12 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridPropTypes } from '#/adapter/vxe-table'; import type { VxeGridPropTypes } from '#/adapter/vxe-table';
import type { MpAccountApi } from '#/api/mp/account';
import { getSimpleAccountList } from '#/api/mp/account';
/** 关联数据 */
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
@@ -41,21 +34,12 @@ export function useFormSchema(): VbenFormSchema[] {
} }
/** 列表的搜索表单 */ /** 列表的搜索表单 */
// TODO @YunaiV 这种方式获取刷新浏览器会导致空白
export function useGridFormSchema(): VbenFormSchema[] { export function useGridFormSchema(): VbenFormSchema[] {
return [ return [
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'ApiSelect', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
]; ];
} }

View File

@@ -9,6 +9,7 @@ import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag'; import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { WxAccountSelect } from '#/views/mp/components';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
@@ -23,6 +24,12 @@ function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
gridApi.formApi.setValues({ accountId });
gridApi.formApi.submitForm();
}
/** 创建标签 */ /** 创建标签 */
async function handleCreate() { async function handleCreate() {
const formValues = await gridApi.formApi.getValues(); const formValues = await gridApi.formApi.getValues();
@@ -101,6 +108,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
}, },
}, },
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
@@ -118,6 +126,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<Page auto-content-height> <Page auto-content-height>
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="公众号标签列表"> <Grid table-title="公众号标签列表">
<template #form-accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[

View File

@@ -1,11 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MpAccountApi } from '#/api/mp/account';
import { getSimpleAccountList } from '#/api/mp/account';
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 修改的表单 */ /** 修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
@@ -43,15 +37,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'Select', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
{ {
fieldName: 'openid', fieldName: 'openid',

View File

@@ -9,6 +9,7 @@ import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getUserPage, syncUser } from '#/api/mp/user'; import { getUserPage, syncUser } from '#/api/mp/user';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { WxAccountSelect } from '#/views/mp/components';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
@@ -25,6 +26,12 @@ function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
gridApi.formApi.setValues({ accountId });
gridApi.formApi.submitForm();
}
/** 编辑用户 */ /** 编辑用户 */
function handleEdit(row: MpUserApi.User) { function handleEdit(row: MpUserApi.User) {
formModalApi.setData({ id: row.id }).open(); formModalApi.setData({ id: row.id }).open();
@@ -73,6 +80,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
}, },
}, },
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
@@ -95,6 +103,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="粉丝列表"> <Grid table-title="粉丝列表">
<template #form-accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[

View File

@@ -2,13 +2,13 @@ import { requestClient } from '#/api/request';
export namespace MpStatisticsApi { export namespace MpStatisticsApi {
/** 统计查询参数 */ /** 统计查询参数 */
export interface StatisticsQuery { export interface StatisticsGetReqVO {
accountId: number; accountId: number;
date: Date[]; date: Date[];
} }
/** 消息发送概况数据 */ /** 消息发送概况数据 */
export interface UpstreamMessage { export interface StatisticsUpstreamMessageRespVO {
refDate: string; refDate: string;
msgType: string; msgType: string;
msgUser: number; msgUser: number;
@@ -16,7 +16,7 @@ export namespace MpStatisticsApi {
} }
/** 用户增减数据 */ /** 用户增减数据 */
export interface UserSummary { export interface StatisticsUserSummaryRespVO {
refDate: string; refDate: string;
userSource: number; userSource: number;
newUser: number; newUser: number;
@@ -25,13 +25,13 @@ export namespace MpStatisticsApi {
} }
/** 用户累计数据 */ /** 用户累计数据 */
export interface UserCumulate { export interface StatisticsUserCumulateRespVO {
refDate: string; refDate: string;
cumulateUser: number; cumulateUser: number;
} }
/** 接口分析数据 */ /** 接口分析数据 */
export interface InterfaceSummary { export interface StatisticsInterfaceSummaryRespVO {
refDate: string; refDate: string;
callbackCount: number; callbackCount: number;
failCount: number; failCount: number;
@@ -41,8 +41,8 @@ export namespace MpStatisticsApi {
} }
/** 获取消息发送概况数据 */ /** 获取消息发送概况数据 */
export function getUpstreamMessage(params: MpStatisticsApi.StatisticsQuery) { export function getUpstreamMessage(params: MpStatisticsApi.StatisticsGetReqVO) {
return requestClient.get<MpStatisticsApi.UpstreamMessage[]>( return requestClient.get<MpStatisticsApi.StatisticsUpstreamMessageRespVO[]>(
'/mp/statistics/upstream-message', '/mp/statistics/upstream-message',
{ {
params, params,
@@ -51,8 +51,8 @@ export function getUpstreamMessage(params: MpStatisticsApi.StatisticsQuery) {
} }
/** 获取用户增减数据 */ /** 获取用户增减数据 */
export function getUserSummary(params: MpStatisticsApi.StatisticsQuery) { export function getUserSummary(params: MpStatisticsApi.StatisticsGetReqVO) {
return requestClient.get<MpStatisticsApi.UserSummary[]>( return requestClient.get<MpStatisticsApi.StatisticsUserSummaryRespVO[]>(
'/mp/statistics/user-summary', '/mp/statistics/user-summary',
{ {
params, params,
@@ -61,8 +61,8 @@ export function getUserSummary(params: MpStatisticsApi.StatisticsQuery) {
} }
/** 获取用户累计数据 */ /** 获取用户累计数据 */
export function getUserCumulate(params: MpStatisticsApi.StatisticsQuery) { export function getUserCumulate(params: MpStatisticsApi.StatisticsGetReqVO) {
return requestClient.get<MpStatisticsApi.UserCumulate[]>( return requestClient.get<MpStatisticsApi.StatisticsUserCumulateRespVO[]>(
'/mp/statistics/user-cumulate', '/mp/statistics/user-cumulate',
{ {
params, params,
@@ -71,8 +71,10 @@ export function getUserCumulate(params: MpStatisticsApi.StatisticsQuery) {
} }
/** 获取接口分析数据 */ /** 获取接口分析数据 */
export function getInterfaceSummary(params: MpStatisticsApi.StatisticsQuery) { export function getInterfaceSummary(
return requestClient.get<MpStatisticsApi.InterfaceSummary[]>( params: MpStatisticsApi.StatisticsGetReqVO,
) {
return requestClient.get<MpStatisticsApi.StatisticsInterfaceSummaryRespVO[]>(
'/mp/statistics/interface-summary', '/mp/statistics/interface-summary',
{ {
params, params,

View File

@@ -11,12 +11,6 @@ export namespace MpTagApi {
count?: number; count?: number;
createTime?: Date; createTime?: Date;
} }
/** 标签分页查询参数 */
export interface TagPageQuery extends PageParam {
accountId?: number;
name?: string;
}
} }
/** 创建公众号标签 */ /** 创建公众号标签 */
@@ -44,7 +38,7 @@ export function getTag(id: number) {
} }
/** 获取公众号标签分页 */ /** 获取公众号标签分页 */
export function getTagPage(params: MpTagApi.TagPageQuery) { export function getTagPage(params: PageParam) {
return requestClient.get<PageResult<MpTagApi.Tag>>('/mp/tag/page', { return requestClient.get<PageResult<MpTagApi.Tag>>('/mp/tag/page', {
params, params,
}); });

View File

@@ -124,7 +124,7 @@ onMounted(() => {
<ElSelect <ElSelect
v-model="currentId" v-model="currentId"
placeholder="请选择公众号" placeholder="请选择公众号"
class="!w-240px" class="!w-full"
@change="onChanged" @change="onChanged"
> >
<ElOption <ElOption

View File

@@ -1,7 +1,9 @@
// 统一导出所有模块组件 // 统一导出所有模块组件
export { default as AccountSelect } from './account-select/account-select.vue'; export { default as AccountSelect } from './account-select/account-select.vue';
export { default as WxAccountSelect } from './account-select/account-select.vue';
// TODO @hw还是带着 wx 前缀。。。貌似好点,我的锅!!!
export { default as Location } from './location/location.vue'; export { default as Location } from './location/location.vue';
export { default as MaterialSelect } from './material-select/material-select.vue'; export { default as MaterialSelect } from './material-select/material-select.vue';

View File

@@ -2,7 +2,7 @@ import type { MpStatisticsApi } from '#/api/mp/statistics';
/** 用户增减数据图表配置项 */ /** 用户增减数据图表配置项 */
export function userSummaryOption( export function userSummaryOption(
data: MpStatisticsApi.UserSummary[], data: MpStatisticsApi.StatisticsUserSummaryRespVO[],
dates: string[], dates: string[],
): any { ): any {
return { return {
@@ -41,7 +41,7 @@ export function userSummaryOption(
/** 累计用户数据图表配置项 */ /** 累计用户数据图表配置项 */
export function userCumulateOption( export function userCumulateOption(
data: MpStatisticsApi.UserCumulate[], data: MpStatisticsApi.StatisticsUserCumulateRespVO[],
dates: string[], dates: string[],
): any { ): any {
return { return {
@@ -71,7 +71,7 @@ export function userCumulateOption(
/** 消息发送概况数据图表配置项 */ /** 消息发送概况数据图表配置项 */
export function upstreamMessageOption( export function upstreamMessageOption(
data: MpStatisticsApi.UpstreamMessage[], data: MpStatisticsApi.StatisticsUpstreamMessageRespVO[],
dates: string[], dates: string[],
): any { ): any {
return { return {
@@ -111,7 +111,7 @@ export function upstreamMessageOption(
/** 接口分析况数据图表配置项 */ /** 接口分析况数据图表配置项 */
export function interfaceSummaryOption( export function interfaceSummaryOption(
data: MpStatisticsApi.InterfaceSummary[], data: MpStatisticsApi.StatisticsInterfaceSummaryRespVO[],
dates: string[], dates: string[],
): any { ): any {
return { return {

View File

@@ -1,29 +1,14 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { MpAccountApi } from '#/api/mp/account';
import { beginOfDay, endOfDay, formatDateTime } from '@vben/utils'; import { beginOfDay, endOfDay, formatDateTime } from '@vben/utils';
import { getSimpleAccountList } from '#/api/mp/account';
/** 关联数据 */
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 列表的搜索表单 */ /** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] { export function useGridFormSchema(): VbenFormSchema[] {
return [ return [
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'ApiSelect', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
{ {
fieldName: 'dateRange', fieldName: 'dateRange',
@@ -36,7 +21,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
defaultValue: [ defaultValue: [
formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))), formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))),
formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))), formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))),
] as [Date, Date], ],
}, },
]; ];
} }

View File

@@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts'; import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue'; import { ref } from 'vue';
import { ContentWrap, Page } from '@vben/common-ui'; import { ContentWrap, Page } from '@vben/common-ui';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts'; import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
@@ -16,6 +16,7 @@ import {
getUserCumulate, getUserCumulate,
getUserSummary, getUserSummary,
} from '#/api/mp/statistics'; } from '#/api/mp/statistics';
import { WxAccountSelect } from '#/views/mp/components';
import { import {
interfaceSummaryOption, interfaceSummaryOption,
@@ -95,6 +96,12 @@ async function getSummary(values: Record<string, any>) {
); );
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
queryFormApi.setValues({ accountId });
queryFormApi.submitForm();
}
const [QueryForm, queryFormApi] = useVbenForm({ const [QueryForm, queryFormApi] = useVbenForm({
commonConfig: { commonConfig: {
componentProps: { componentProps: {
@@ -106,17 +113,16 @@ const [QueryForm, queryFormApi] = useVbenForm({
wrapperClass: 'grid-cols-1 md:grid-cols-2', wrapperClass: 'grid-cols-1 md:grid-cols-2',
handleSubmit: getSummary, handleSubmit: getSummary,
}); });
/** 初始化 */
onMounted(() => {
queryFormApi.submitForm();
});
</script> </script>
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<ContentWrap class="h-full w-full"> <ContentWrap class="h-full w-full">
<QueryForm /> <QueryForm>
<template #accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
</QueryForm>
<div class="flex h-1/3 w-full gap-4"> <div class="flex h-1/3 w-full gap-4">
<ElCard class="h-full w-1/2"> <ElCard class="h-full w-1/2">

View File

@@ -1,12 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridPropTypes } from '#/adapter/vxe-table'; import type { VxeGridPropTypes } from '#/adapter/vxe-table';
import type { MpAccountApi } from '#/api/mp/account';
import { getSimpleAccountList } from '#/api/mp/account';
/** 关联数据 */
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
@@ -46,15 +39,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'ApiSelect', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
]; ];
} }

View File

@@ -9,6 +9,7 @@ import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag'; import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { WxAccountSelect } from '#/views/mp/components';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
@@ -23,6 +24,12 @@ function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
gridApi.formApi.setValues({ accountId });
gridApi.formApi.submitForm();
}
/** 创建标签 */ /** 创建标签 */
async function handleCreate() { async function handleCreate() {
const formValues = await gridApi.formApi.getValues(); const formValues = await gridApi.formApi.getValues();
@@ -99,6 +106,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
}, },
}, },
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
@@ -116,6 +124,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<Page auto-content-height> <Page auto-content-height>
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="公众号标签列表"> <Grid table-title="公众号标签列表">
<template #form-accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[

View File

@@ -1,11 +1,5 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MpAccountApi } from '#/api/mp/account';
import { getSimpleAccountList } from '#/api/mp/account';
let accountList: MpAccountApi.AccountSimple[] = [];
getSimpleAccountList().then((data) => (accountList = data));
/** 修改的表单 */ /** 修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
@@ -43,15 +37,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'accountId', fieldName: 'accountId',
label: '公众号', label: '公众号',
component: 'Select', component: 'Input',
componentProps: {
options: accountList.map((item) => ({
label: item.name,
value: item.id,
})),
placeholder: '请选择公众号',
},
defaultValue: accountList[0]?.id,
}, },
{ {
fieldName: 'openid', fieldName: 'openid',

View File

@@ -9,6 +9,7 @@ import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getUserPage, syncUser } from '#/api/mp/user'; import { getUserPage, syncUser } from '#/api/mp/user';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { WxAccountSelect } from '#/views/mp/components';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue'; import Form from './modules/form.vue';
@@ -25,6 +26,12 @@ function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 公众号变化时查询数据 */
function handleAccountChange(accountId: number) {
gridApi.formApi.setValues({ accountId });
gridApi.formApi.submitForm();
}
/** 编辑用户 */ /** 编辑用户 */
function handleEdit(row: MpUserApi.User) { function handleEdit(row: MpUserApi.User) {
formModalApi.setData({ id: row.id }).open(); formModalApi.setData({ id: row.id }).open();
@@ -72,6 +79,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
}, },
}, },
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
@@ -94,6 +102,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="粉丝列表"> <Grid table-title="粉丝列表">
<template #form-accountId>
<WxAccountSelect @change="handleAccountChange" />
</template>
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[