Merge branch 'dev' of https://gitee.com/yudaocode/yudao-ui-admin-vben into dev
This commit is contained in:
@@ -72,12 +72,12 @@ async function handleDelete(row: MpDraftApi.DraftArticle) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: '删除中...',
|
content: $t('ui.actionMessage.deleting'),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteDraft(accountId, row.mediaId);
|
await deleteDraft(accountId, row.mediaId);
|
||||||
message.success('删除成功');
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
|
|||||||
59
apps/web-antd/src/views/mp/freePublish/data.ts
Normal file
59
apps/web-antd/src/views/mp/freePublish/data.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
|
||||||
|
import type { MpAccountApi } from '#/api/mp/account';
|
||||||
|
|
||||||
|
import { formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
|
import { getSimpleAccountList } from '#/api/mp/account';
|
||||||
|
|
||||||
|
let accountList: MpAccountApi.AccountSimple[] = [];
|
||||||
|
getSimpleAccountList().then((data) => (accountList = data));
|
||||||
|
|
||||||
|
/** 搜索表单配置 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'accountId',
|
||||||
|
label: '公众号',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: accountList.map((item) => ({
|
||||||
|
label: item.name,
|
||||||
|
value: item.id,
|
||||||
|
})),
|
||||||
|
placeholder: '请选择公众号',
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格列配置 */
|
||||||
|
export function useGridColumns(): VxeGridPropTypes.Columns {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'cover',
|
||||||
|
title: '图片',
|
||||||
|
width: 360,
|
||||||
|
slots: { default: 'cover' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'title',
|
||||||
|
title: '标题',
|
||||||
|
slots: { default: 'title' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'updateTime',
|
||||||
|
title: '修改时间',
|
||||||
|
formatter: ({ row }) => {
|
||||||
|
return formatDateTime(row.updateTime * 1000);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -1,29 +1,173 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { MpFreePublishApi } from '#/api/mp/freePublish';
|
||||||
|
|
||||||
import { DocAlert, Page } from '@vben/common-ui';
|
import { DocAlert, Page } from '@vben/common-ui';
|
||||||
|
|
||||||
import { Button } from 'ant-design-vue';
|
import { Image, message, Typography } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { deleteFreePublish, getFreePublishPage } from '#/api/mp/freePublish';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { WxAccountSelect } from '#/views/mp/components';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 公众号变化时查询数据 */
|
||||||
|
function handleAccountChange(accountId: number) {
|
||||||
|
gridApi.formApi.setValues({ accountId });
|
||||||
|
gridApi.formApi.submitForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除文章 */
|
||||||
|
async function handleDelete(row: MpFreePublishApi.FreePublish) {
|
||||||
|
const formValues = await gridApi.formApi.getValues();
|
||||||
|
const accountId = formValues.accountId;
|
||||||
|
if (!accountId) {
|
||||||
|
message.warning('请先选择公众号');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hideLoading = message.loading({
|
||||||
|
content: $t('ui.actionMessage.deleting'),
|
||||||
|
duration: 0,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteFreePublish(accountId, row.articleId!);
|
||||||
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
handleRefresh();
|
||||||
|
} finally {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
schema: useGridFormSchema(),
|
||||||
|
submitOnChange: true,
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
keepSource: true,
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
if (!formValues.accountId) {
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const res = await getFreePublishPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
// 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面
|
||||||
|
res.list.forEach((record: any) => {
|
||||||
|
const newsList = record.content?.newsItem;
|
||||||
|
if (newsList) {
|
||||||
|
newsList.forEach((item: any) => {
|
||||||
|
item.picUrl = item.thumbUrl || item.picUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// TODO @jawe:Article 类型,报错;
|
||||||
|
return {
|
||||||
|
list: res.list as unknown as Article[],
|
||||||
|
total: res.total,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'articleId',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: true,
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Article>,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page>
|
<Page auto-content-height>
|
||||||
<DocAlert title="公众号图文" url="https://doc.iocoder.cn/mp/article/" />
|
<template #doc>
|
||||||
<Button
|
<DocAlert title="公众号图文" url="https://doc.iocoder.cn/mp/article/" />
|
||||||
danger
|
</template>
|
||||||
type="link"
|
<Grid table-title="发表记录">
|
||||||
target="_blank"
|
<template #form-accountId>
|
||||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
|
<WxAccountSelect @change="handleAccountChange" />
|
||||||
>
|
</template>
|
||||||
该功能支持 Vue3 + element-plus 版本!
|
<template #cover="{ row }">
|
||||||
</Button>
|
<div
|
||||||
<br />
|
v-if="row.content?.newsItem && row.content.newsItem.length > 0"
|
||||||
<Button
|
class="flex flex-col items-center justify-center gap-1"
|
||||||
type="link"
|
>
|
||||||
target="_blank"
|
<Image
|
||||||
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mp/freePublish/index"
|
v-for="(item, index) in row.content.newsItem"
|
||||||
>
|
:key="index"
|
||||||
可参考
|
:src="item.picUrl || item.thumbUrl"
|
||||||
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mp/freePublish/index
|
class="h-36 !w-[300px] rounded object-cover"
|
||||||
代码,pull request 贡献给我们!
|
:alt="`文章 ${index + 1} 封面图`"
|
||||||
</Button>
|
/>
|
||||||
|
</div>
|
||||||
|
<span v-else class="text-gray-400">-</span>
|
||||||
|
</template>
|
||||||
|
<template #title="{ row }">
|
||||||
|
<div
|
||||||
|
v-if="row.content?.newsItem && row.content.newsItem.length > 0"
|
||||||
|
class="space-y-1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in row.content.newsItem"
|
||||||
|
:key="index"
|
||||||
|
class="flex h-36 items-center justify-center"
|
||||||
|
>
|
||||||
|
<Typography.Link :href="(item as any).url" target="_blank">
|
||||||
|
{{ item.title }}
|
||||||
|
</Typography.Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span v-else class="text-gray-400">-</span>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
type: 'link',
|
||||||
|
danger: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['mp:free-publish:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: '是否确认删除此数据?',
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(.vxe-table--body-wrapper) {
|
||||||
|
.vxe-table--body {
|
||||||
|
.vxe-body--column {
|
||||||
|
.vxe-cell {
|
||||||
|
height: auto !important;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ async function handleDelete(row: MpDraftApi.DraftArticle) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const hideLoading = ElLoading.service({
|
const hideLoading = ElLoading.service({
|
||||||
text: '删除中...',
|
text: $t('ui.actionMessage.deleting'),
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteDraft(accountId, row.mediaId);
|
await deleteDraft(accountId, row.mediaId);
|
||||||
ElMessage.success('删除成功');
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading.close();
|
hideLoading.close();
|
||||||
|
|||||||
59
apps/web-ele/src/views/mp/freePublish/data.ts
Normal file
59
apps/web-ele/src/views/mp/freePublish/data.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
|
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
|
||||||
|
import type { MpAccountApi } from '#/api/mp/account';
|
||||||
|
|
||||||
|
import { formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
|
import { getSimpleAccountList } from '#/api/mp/account';
|
||||||
|
|
||||||
|
let accountList: MpAccountApi.AccountSimple[] = [];
|
||||||
|
getSimpleAccountList().then((data) => (accountList = data));
|
||||||
|
|
||||||
|
/** 搜索表单配置 */
|
||||||
|
export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
fieldName: 'accountId',
|
||||||
|
label: '公众号',
|
||||||
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
options: accountList.map((item) => ({
|
||||||
|
label: item.name,
|
||||||
|
value: item.id,
|
||||||
|
})),
|
||||||
|
placeholder: '请选择公众号',
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 表格列配置 */
|
||||||
|
export function useGridColumns(): VxeGridPropTypes.Columns {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
field: 'cover',
|
||||||
|
title: '图片',
|
||||||
|
width: 360,
|
||||||
|
slots: { default: 'cover' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'title',
|
||||||
|
title: '标题',
|
||||||
|
slots: { default: 'title' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'updateTime',
|
||||||
|
title: '修改时间',
|
||||||
|
formatter: ({ row }) => {
|
||||||
|
return formatDateTime(row.updateTime * 1000);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
|
fixed: 'right',
|
||||||
|
slots: { default: 'actions' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
173
apps/web-ele/src/views/mp/freePublish/index.vue
Normal file
173
apps/web-ele/src/views/mp/freePublish/index.vue
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
import type { MpFreePublishApi } from '#/api/mp/freePublish';
|
||||||
|
|
||||||
|
import { DocAlert, Page } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { ElImage, ElLink, ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
|
import { deleteFreePublish, getFreePublishPage } from '#/api/mp/freePublish';
|
||||||
|
import { $t } from '#/locales';
|
||||||
|
import { WxAccountSelect } from '#/views/mp/components';
|
||||||
|
|
||||||
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
|
/** 刷新表格 */
|
||||||
|
function handleRefresh() {
|
||||||
|
gridApi.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 公众号变化时查询数据 */
|
||||||
|
function handleAccountChange(accountId: number) {
|
||||||
|
gridApi.formApi.setValues({ accountId });
|
||||||
|
gridApi.formApi.submitForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除文章 */
|
||||||
|
async function handleDelete(row: MpFreePublishApi.FreePublish) {
|
||||||
|
const formValues = await gridApi.formApi.getValues();
|
||||||
|
const accountId = formValues.accountId;
|
||||||
|
if (!accountId) {
|
||||||
|
ElMessage.warning('请先选择公众号');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteFreePublish(accountId, row.articleId!);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
handleRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
formOptions: {
|
||||||
|
schema: useGridFormSchema(),
|
||||||
|
submitOnChange: true,
|
||||||
|
},
|
||||||
|
gridOptions: {
|
||||||
|
columns: useGridColumns(),
|
||||||
|
height: 'auto',
|
||||||
|
keepSource: true,
|
||||||
|
proxyConfig: {
|
||||||
|
ajax: {
|
||||||
|
query: async ({ page }, formValues) => {
|
||||||
|
if (!formValues.accountId) {
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const res = await getFreePublishPage({
|
||||||
|
pageNo: page.currentPage,
|
||||||
|
pageSize: page.pageSize,
|
||||||
|
...formValues,
|
||||||
|
});
|
||||||
|
// 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面
|
||||||
|
res.list.forEach((record: any) => {
|
||||||
|
const newsList = record.content?.newsItem;
|
||||||
|
if (newsList) {
|
||||||
|
newsList.forEach((item: any) => {
|
||||||
|
item.picUrl = item.thumbUrl || item.picUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// TODO @jawe:Article 类型,报错;
|
||||||
|
return {
|
||||||
|
list: res.list as unknown as Article[],
|
||||||
|
total: res.total,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowConfig: {
|
||||||
|
keyField: 'articleId',
|
||||||
|
isHover: true,
|
||||||
|
},
|
||||||
|
toolbarConfig: {
|
||||||
|
refresh: true,
|
||||||
|
search: true,
|
||||||
|
},
|
||||||
|
} as VxeTableGridOptions<Article>,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page auto-content-height>
|
||||||
|
<template #doc>
|
||||||
|
<DocAlert title="公众号图文" url="https://doc.iocoder.cn/mp/article/" />
|
||||||
|
</template>
|
||||||
|
<Grid table-title="发表记录">
|
||||||
|
<template #form-accountId>
|
||||||
|
<WxAccountSelect @change="handleAccountChange" />
|
||||||
|
</template>
|
||||||
|
<template #cover="{ row }">
|
||||||
|
<div
|
||||||
|
v-if="row.content?.newsItem && row.content.newsItem.length > 0"
|
||||||
|
class="flex flex-col items-center justify-center gap-1"
|
||||||
|
>
|
||||||
|
<ElImage
|
||||||
|
v-for="(item, index) in row.content.newsItem"
|
||||||
|
:key="index"
|
||||||
|
:src="item.picUrl || item.thumbUrl"
|
||||||
|
:preview-src-list="[item.picUrl || item.thumbUrl]"
|
||||||
|
class="h-36 !w-[300px] rounded object-cover"
|
||||||
|
:alt="`文章 ${index + 1} 封面图`"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span v-else class="text-gray-400">-</span>
|
||||||
|
</template>
|
||||||
|
<template #title="{ row }">
|
||||||
|
<div
|
||||||
|
v-if="row.content?.newsItem && row.content.newsItem.length > 0"
|
||||||
|
class="space-y-1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="(item, index) in row.content.newsItem"
|
||||||
|
:key="index"
|
||||||
|
class="flex h-36 items-center justify-center"
|
||||||
|
>
|
||||||
|
<ElLink :href="(item as any).url" target="_blank">
|
||||||
|
{{ item.title }}
|
||||||
|
</ElLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span v-else class="text-gray-400">-</span>
|
||||||
|
</template>
|
||||||
|
<template #actions="{ row }">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
type: 'danger',
|
||||||
|
link: true,
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
auth: ['mp:free-publish:delete'],
|
||||||
|
popConfirm: {
|
||||||
|
title: '是否确认删除此数据?',
|
||||||
|
confirm: handleDelete.bind(null, row),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Grid>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(.vxe-table--body-wrapper) {
|
||||||
|
.vxe-table--body {
|
||||||
|
.vxe-body--column {
|
||||||
|
.vxe-cell {
|
||||||
|
height: auto !important;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user