feat: tag
							parent
							
								
									1074b90c6f
								
							
						
					
					
						commit
						5fa6ca78e2
					
				| 
						 | 
					@ -33,6 +33,13 @@ export function getAccount(id: number) {
 | 
				
			||||||
  return requestClient.get<MpAccountApi.Account>(`/mp/account/get?id=${id}`);
 | 
					  return requestClient.get<MpAccountApi.Account>(`/mp/account/get?id=${id}`);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 查询公众号账号列表 */
 | 
				
			||||||
 | 
					export function getSimpleAccountList() {
 | 
				
			||||||
 | 
					  return requestClient.get<MpAccountApi.Account[]>(
 | 
				
			||||||
 | 
					    '/mp/account/list-all-simple',
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 新增公众号账号 */
 | 
					/** 新增公众号账号 */
 | 
				
			||||||
export function createAccount(data: MpAccountApi.Account) {
 | 
					export function createAccount(data: MpAccountApi.Account) {
 | 
				
			||||||
  return requestClient.post('/mp/account/create', data);
 | 
					  return requestClient.post('/mp/account/create', data);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,9 @@ export namespace MpTagApi {
 | 
				
			||||||
  /** 标签信息 */
 | 
					  /** 标签信息 */
 | 
				
			||||||
  export interface Tag {
 | 
					  export interface Tag {
 | 
				
			||||||
    id?: number;
 | 
					    id?: number;
 | 
				
			||||||
    name: string;
 | 
					 | 
				
			||||||
    accountId: number;
 | 
					    accountId: number;
 | 
				
			||||||
 | 
					    name: string;
 | 
				
			||||||
 | 
					    count?: number;
 | 
				
			||||||
    createTime?: Date;
 | 
					    createTime?: Date;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,82 @@
 | 
				
			||||||
 | 
					import type { VbenFormSchema } from '#/adapter/form';
 | 
				
			||||||
 | 
					import type { VxeGridPropTypes } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { getSimpleAccountList } from '#/api/mp/account';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 新增/修改的表单 */
 | 
				
			||||||
 | 
					export function useFormSchema(): VbenFormSchema[] {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      fieldName: 'id',
 | 
				
			||||||
 | 
					      dependencies: {
 | 
				
			||||||
 | 
					        triggerFields: [''],
 | 
				
			||||||
 | 
					        show: () => false,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'accountId',
 | 
				
			||||||
 | 
					      label: '公众号',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      dependencies: {
 | 
				
			||||||
 | 
					        triggerFields: [''],
 | 
				
			||||||
 | 
					        show: () => false,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'name',
 | 
				
			||||||
 | 
					      label: '标签名称',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      rules: 'required',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        placeholder: '请输入名称',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 搜索表单配置 */
 | 
				
			||||||
 | 
					export function useGridFormSchema(): VbenFormSchema[] {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'accountId',
 | 
				
			||||||
 | 
					      label: '公众号',
 | 
				
			||||||
 | 
					      component: 'ApiSelect',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        api: getSimpleAccountList,
 | 
				
			||||||
 | 
					        labelField: 'name',
 | 
				
			||||||
 | 
					        valueField: 'id',
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 表格列配置 */
 | 
				
			||||||
 | 
					export function useGridColumns(): VxeGridPropTypes.Columns {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      title: '编号',
 | 
				
			||||||
 | 
					      field: 'id',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      title: '标签名称',
 | 
				
			||||||
 | 
					      field: 'name',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      title: '粉丝数',
 | 
				
			||||||
 | 
					      field: 'count',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      title: '创建时间',
 | 
				
			||||||
 | 
					      field: 'createTime',
 | 
				
			||||||
 | 
					      formatter: 'formatDateTime',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      title: '操作',
 | 
				
			||||||
 | 
					      width: 140,
 | 
				
			||||||
 | 
					      fixed: 'right',
 | 
				
			||||||
 | 
					      slots: { default: 'actions' },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,31 +1,157 @@
 | 
				
			||||||
<script lang="ts" setup>
 | 
					<script lang="ts" setup>
 | 
				
			||||||
import { Page } from '@vben/common-ui';
 | 
					import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import type { MpTagApi } from '#/api/mp/tag';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Button } from 'ant-design-vue';
 | 
					import { ref } from 'vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { DocAlert } from '#/components/doc-alert';
 | 
					import { Page, useVbenModal } from '@vben/common-ui';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { message } from 'ant-design-vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import { deleteTag, getTagPage, syncTag } from '#/api/mp/tag';
 | 
				
			||||||
 | 
					import { $t } from '#/locales';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useGridColumns, useGridFormSchema } from './data';
 | 
				
			||||||
 | 
					import Form from './modules/form.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const accountId = ref(-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [FormModal, formModalApi] = useVbenModal({
 | 
				
			||||||
 | 
					  connectedComponent: Form,
 | 
				
			||||||
 | 
					  destroyOnClose: true,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 刷新表格 */
 | 
				
			||||||
 | 
					function onRefresh() {
 | 
				
			||||||
 | 
					  gridApi.query();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 创建标签 */
 | 
				
			||||||
 | 
					function handleCreate() {
 | 
				
			||||||
 | 
					  formModalApi.setData(null).open();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 编辑标签 */
 | 
				
			||||||
 | 
					function handleEdit(row: MpTagApi.Tag) {
 | 
				
			||||||
 | 
					  formModalApi.setData(row).open();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 删除标签 */
 | 
				
			||||||
 | 
					async function handleDelete(row: MpTagApi.Tag) {
 | 
				
			||||||
 | 
					  const hideLoading = message.loading({
 | 
				
			||||||
 | 
					    content: $t('ui.actionMessage.deleting', [row.name]),
 | 
				
			||||||
 | 
					    key: 'action_key_msg',
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    await deleteTag(row.id as number);
 | 
				
			||||||
 | 
					    message.success({
 | 
				
			||||||
 | 
					      content: $t('ui.actionMessage.deleteSuccess', [row.name]),
 | 
				
			||||||
 | 
					      key: 'action_key_msg',
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    onRefresh();
 | 
				
			||||||
 | 
					  } finally {
 | 
				
			||||||
 | 
					    hideLoading();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/** 同步标签 */
 | 
				
			||||||
 | 
					async function handleSync() {
 | 
				
			||||||
 | 
					  const hideLoading = message.loading({
 | 
				
			||||||
 | 
					    content: '是否确认同步标签?',
 | 
				
			||||||
 | 
					    key: 'action_key_msg',
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    await syncTag(accountId.value);
 | 
				
			||||||
 | 
					    message.success({
 | 
				
			||||||
 | 
					      content: '同步标签成功',
 | 
				
			||||||
 | 
					      key: 'action_key_msg',
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    onRefresh();
 | 
				
			||||||
 | 
					  } finally {
 | 
				
			||||||
 | 
					    hideLoading();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Grid, gridApi] = useVbenVxeGrid({
 | 
				
			||||||
 | 
					  formOptions: {
 | 
				
			||||||
 | 
					    schema: useGridFormSchema(),
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  gridOptions: {
 | 
				
			||||||
 | 
					    columns: useGridColumns(),
 | 
				
			||||||
 | 
					    height: 'auto',
 | 
				
			||||||
 | 
					    keepSource: true,
 | 
				
			||||||
 | 
					    proxyConfig: {
 | 
				
			||||||
 | 
					      ajax: {
 | 
				
			||||||
 | 
					        query: async ({ page }, formValues) => {
 | 
				
			||||||
 | 
					          accountId.value = formValues.accountId;
 | 
				
			||||||
 | 
					          return await getTagPage({
 | 
				
			||||||
 | 
					            pageNo: page.currentPage,
 | 
				
			||||||
 | 
					            pageSize: page.pageSize,
 | 
				
			||||||
 | 
					            accountId: accountId.value,
 | 
				
			||||||
 | 
					            ...formValues,
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    rowConfig: {
 | 
				
			||||||
 | 
					      keyField: 'id',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    toolbarConfig: {
 | 
				
			||||||
 | 
					      refresh: { code: 'query' },
 | 
				
			||||||
 | 
					      search: true,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  } as VxeTableGridOptions<MpTagApi.Tag>,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <Page>
 | 
					  <Page auto-content-height>
 | 
				
			||||||
    <DocAlert title="公众号标签" url="https://doc.iocoder.cn/mp/tag/" />
 | 
					    <FormModal @success="onRefresh" :account-id="accountId" />
 | 
				
			||||||
    <Button
 | 
					    <Grid table-title="公众号账号列表">
 | 
				
			||||||
      danger
 | 
					      <template #toolbar-tools>
 | 
				
			||||||
      type="link"
 | 
					        <TableAction
 | 
				
			||||||
      target="_blank"
 | 
					          :actions="[
 | 
				
			||||||
      href="https://github.com/yudaocode/yudao-ui-admin-vue3"
 | 
					            {
 | 
				
			||||||
    >
 | 
					              label: $t('ui.actionTitle.create', ['公众号账号']),
 | 
				
			||||||
      该功能支持 Vue3 + element-plus 版本!
 | 
					              type: 'primary',
 | 
				
			||||||
    </Button>
 | 
					              icon: ACTION_ICON.ADD,
 | 
				
			||||||
    <br />
 | 
					              auth: ['mp:tag:create'],
 | 
				
			||||||
    <Button
 | 
					              onClick: handleCreate,
 | 
				
			||||||
      type="link"
 | 
					            },
 | 
				
			||||||
      target="_blank"
 | 
					            {
 | 
				
			||||||
      href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mp/tag/index"
 | 
					              label: '同步',
 | 
				
			||||||
    >
 | 
					              type: 'primary',
 | 
				
			||||||
      可参考
 | 
					              icon: 'lucide:refresh-ccw',
 | 
				
			||||||
      https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mp/tag/index
 | 
					              auth: ['mp:tag:sync'],
 | 
				
			||||||
      代码,pull request 贡献给我们!
 | 
					              onClick: handleSync,
 | 
				
			||||||
    </Button>
 | 
					            },
 | 
				
			||||||
 | 
					          ]"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					      <template #actions="{ row }">
 | 
				
			||||||
 | 
					        <TableAction
 | 
				
			||||||
 | 
					          :actions="[
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              label: $t('common.edit'),
 | 
				
			||||||
 | 
					              type: 'link',
 | 
				
			||||||
 | 
					              icon: ACTION_ICON.EDIT,
 | 
				
			||||||
 | 
					              auth: ['mp:tag:update'],
 | 
				
			||||||
 | 
					              onClick: handleEdit.bind(null, row),
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					              label: $t('common.delete'),
 | 
				
			||||||
 | 
					              type: 'link',
 | 
				
			||||||
 | 
					              danger: true,
 | 
				
			||||||
 | 
					              icon: ACTION_ICON.DELETE,
 | 
				
			||||||
 | 
					              auth: ['mp:tag:delete'],
 | 
				
			||||||
 | 
					              popConfirm: {
 | 
				
			||||||
 | 
					                title: $t('ui.actionMessage.deleteConfirm', [row.name]),
 | 
				
			||||||
 | 
					                confirm: handleDelete.bind(null, row),
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          ]"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					    </Grid>
 | 
				
			||||||
  </Page>
 | 
					  </Page>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,88 @@
 | 
				
			||||||
 | 
					<script lang="ts" setup>
 | 
				
			||||||
 | 
					import type { MpTagApi } from '#/api/mp/tag';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { computed, ref } from 'vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useVbenModal } from '@vben/common-ui';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { message } from 'ant-design-vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useVbenForm } from '#/adapter/form';
 | 
				
			||||||
 | 
					import { createTag, getTag, updateTag } from '#/api/mp/tag';
 | 
				
			||||||
 | 
					import { $t } from '#/locales';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useFormSchema } from '../data';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps<{
 | 
				
			||||||
 | 
					  accountId: number;
 | 
				
			||||||
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const emit = defineEmits(['success']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const formData = ref<MpTagApi.Tag>();
 | 
				
			||||||
 | 
					const getTitle = computed(() => {
 | 
				
			||||||
 | 
					  return formData.value?.id
 | 
				
			||||||
 | 
					    ? $t('ui.actionTitle.edit', ['标签'])
 | 
				
			||||||
 | 
					    : $t('ui.actionTitle.create', ['标签']);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Form, formApi] = useVbenForm({
 | 
				
			||||||
 | 
					  commonConfig: {
 | 
				
			||||||
 | 
					    componentProps: {
 | 
				
			||||||
 | 
					      class: 'w-full',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    formItemClass: 'col-span-2',
 | 
				
			||||||
 | 
					    labelWidth: 120,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  layout: 'horizontal',
 | 
				
			||||||
 | 
					  schema: useFormSchema(),
 | 
				
			||||||
 | 
					  showDefaultActions: false,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Modal, modalApi] = useVbenModal({
 | 
				
			||||||
 | 
					  async onConfirm() {
 | 
				
			||||||
 | 
					    const { valid } = await formApi.validate();
 | 
				
			||||||
 | 
					    if (!valid) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    modalApi.lock();
 | 
				
			||||||
 | 
					    // 提交表单
 | 
				
			||||||
 | 
					    const data = (await formApi.getValues()) as MpTagApi.Tag;
 | 
				
			||||||
 | 
					    data.accountId = props.accountId;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      await (formData.value?.id ? updateTag(data) : createTag(data));
 | 
				
			||||||
 | 
					      // 关闭并提示
 | 
				
			||||||
 | 
					      await modalApi.close();
 | 
				
			||||||
 | 
					      emit('success');
 | 
				
			||||||
 | 
					      message.success($t('ui.actionMessage.operationSuccess'));
 | 
				
			||||||
 | 
					    } finally {
 | 
				
			||||||
 | 
					      modalApi.unlock();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  async onOpenChange(isOpen: boolean) {
 | 
				
			||||||
 | 
					    if (!isOpen) {
 | 
				
			||||||
 | 
					      formData.value = undefined;
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // 加载数据
 | 
				
			||||||
 | 
					    const data = modalApi.getData<MpTagApi.Tag>();
 | 
				
			||||||
 | 
					    if (!data || !data.id) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    modalApi.lock();
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      formData.value = await getTag(data.id as number);
 | 
				
			||||||
 | 
					      // 设置到 values
 | 
				
			||||||
 | 
					      await formApi.setValues(formData.value);
 | 
				
			||||||
 | 
					    } finally {
 | 
				
			||||||
 | 
					      modalApi.unlock();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Modal class="w-[600px]" :title="getTitle">
 | 
				
			||||||
 | 
					    <Form class="mx-4" />
 | 
				
			||||||
 | 
					  </Modal>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
		Loading…
	
		Reference in New Issue