3 changed files with 270 additions and 1 deletions
@ -0,0 +1,49 @@
|
||||
<template> |
||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit"> |
||||
<BasicForm @register="registerForm" /> |
||||
</BasicModal> |
||||
</template> |
||||
<script lang="ts" setup name="AccountModal"> |
||||
import { ref, unref } from 'vue' |
||||
import { BasicModal, useModalInner } from '@/components/Modal' |
||||
import { BasicForm, useForm } from '@/components/Form' |
||||
import { formSchema } from './account.data' |
||||
import { createAccount, getAccount, updateAccount } from '@/api/mp/account' |
||||
|
||||
const emit = defineEmits(['success', 'register']) |
||||
const isUpdate = ref(true) |
||||
|
||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ |
||||
labelWidth: 120, |
||||
baseColProps: { span: 24 }, |
||||
schemas: formSchema, |
||||
showActionButtonGroup: false, |
||||
actionColOptions: { span: 23 } |
||||
}) |
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||
resetFields() |
||||
setModalProps({ confirmLoading: false }) |
||||
isUpdate.value = !!data?.isUpdate |
||||
if (unref(isUpdate)) { |
||||
const res = await getAccount(data.record.id) |
||||
setFieldsValue({ ...res }) |
||||
} |
||||
}) |
||||
|
||||
async function handleSubmit() { |
||||
try { |
||||
const values = await validate() |
||||
setModalProps({ confirmLoading: true }) |
||||
if (unref(isUpdate)) { |
||||
await updateAccount(values) |
||||
} else { |
||||
await createAccount(values) |
||||
} |
||||
closeModal() |
||||
emit('success') |
||||
} finally { |
||||
setModalProps({ confirmLoading: false }) |
||||
} |
||||
} |
||||
</script> |
@ -0,0 +1,107 @@
|
||||
import { BasicColumn, FormSchema, useRender } from '@/components/Table' |
||||
|
||||
export const columns: BasicColumn[] = [ |
||||
{ |
||||
title: '岗位编号', |
||||
dataIndex: 'id', |
||||
width: 100 |
||||
}, |
||||
{ |
||||
title: '名称', |
||||
dataIndex: 'name', |
||||
width: 180 |
||||
}, |
||||
{ |
||||
title: '微信号', |
||||
dataIndex: 'account', |
||||
width: 100 |
||||
}, |
||||
{ |
||||
title: 'appId', |
||||
dataIndex: 'appId', |
||||
width: 120 |
||||
}, |
||||
{ |
||||
title: '服务器地址(URL)', |
||||
dataIndex: 'appIdURL', |
||||
width: 120, |
||||
customRender: ({ record }) => { |
||||
return 'http://服务端地址/mp/open/' + record.appId |
||||
} |
||||
}, |
||||
{ |
||||
title: '二维码', |
||||
dataIndex: 'qrCodeUrl', |
||||
width: 180, |
||||
customRender: ({ text }) => { |
||||
return useRender.renderImg(text) |
||||
} |
||||
}, |
||||
{ |
||||
title: '备注', |
||||
dataIndex: 'remark', |
||||
width: 180 |
||||
} |
||||
] |
||||
|
||||
export const searchFormSchema: FormSchema[] = [ |
||||
{ |
||||
label: '名称', |
||||
field: 'name', |
||||
component: 'Input', |
||||
colProps: { span: 8 } |
||||
} |
||||
] |
||||
|
||||
export const formSchema: FormSchema[] = [ |
||||
{ |
||||
label: '编号', |
||||
field: 'id', |
||||
show: false, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '名称', |
||||
field: 'name', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '微信号', |
||||
field: 'account', |
||||
helpMessage: '在微信公众平台(mp.weixin.qq.com)的菜单 [设置与开发 - 公众号设置 - 账号详情] 中能找到「微信号」', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '公众号 appId', |
||||
field: 'appId', |
||||
helpMessage: '在微信公众平台(mp.weixin.qq.com)的菜单 [设置与开发 - 公众号设置 - 基本设置] 中能找到「开发者ID(AppID)」', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '公众号 appSecret', |
||||
field: 'appSecret', |
||||
helpMessage: '在微信公众平台(mp.weixin.qq.com)的菜单 [设置与开发 - 公众号设置 - 基本设置] 中能找到「开发者密码(AppSecret)」', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '公众号token', |
||||
field: 'token', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '消息加解密密钥', |
||||
field: 'aesKey', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '备注', |
||||
field: 'remark', |
||||
component: 'InputTextArea' |
||||
} |
||||
] |
@ -1,3 +1,116 @@
|
||||
<template> |
||||
<div>开发中</div> |
||||
<div> |
||||
<BasicTable @register="registerTable"> |
||||
<template #toolbar> |
||||
<a-button type="primary" v-auth="['mp:account:create']" :preIcon="IconEnum.ADD" @click="handleCreate"> |
||||
{{ t('action.create') }} |
||||
</a-button> |
||||
</template> |
||||
<template #bodyCell="{ column, record }"> |
||||
<template v-if="column.key === 'action'"> |
||||
<TableAction |
||||
:actions="[ |
||||
{ icon: IconEnum.EDIT, label: t('action.edit'), auth: 'mp:account:update', onClick: handleEdit.bind(null, record) }, |
||||
{ |
||||
icon: IconEnum.EDIT, |
||||
label: '生成二维码', |
||||
auth: 'mp:account:qr-code', |
||||
onClick: handleGenerateQrCode.bind(null, record) |
||||
}, |
||||
{ |
||||
icon: IconEnum.EDIT, |
||||
label: '清空 API 配额', |
||||
auth: 'mp:account:clear-quota', |
||||
onClick: handleCleanQuota.bind(null, record) |
||||
}, |
||||
{ |
||||
icon: IconEnum.DELETE, |
||||
color: 'error', |
||||
label: t('action.delete'), |
||||
auth: 'mp:account:delete', |
||||
popConfirm: { |
||||
title: t('common.delMessage'), |
||||
placement: 'left', |
||||
confirm: handleDelete.bind(null, record) |
||||
} |
||||
} |
||||
]" |
||||
/> |
||||
</template> |
||||
</template> |
||||
</BasicTable> |
||||
<AccountModal @register="registerModal" @success="reload()" /> |
||||
</div> |
||||
</template> |
||||
<script lang="ts" setup name="Account"> |
||||
import { useI18n } from '@/hooks/web/useI18n' |
||||
import { useMessage } from '@/hooks/web/useMessage' |
||||
import { useModal } from '@/components/Modal' |
||||
import AccountModal from './AccountModal.vue' |
||||
import { IconEnum } from '@/enums/appEnum' |
||||
import { BasicTable, useTable, TableAction } from '@/components/Table' |
||||
import { clearAccountQuota, deleteAccount, generateAccountQrCode, getAccountPage } from '@/api/mp/account' |
||||
import { columns, searchFormSchema } from './account.data' |
||||
|
||||
const { t } = useI18n() |
||||
const { createConfirm, createMessage } = useMessage() |
||||
const [registerModal, { openModal }] = useModal() |
||||
|
||||
const [registerTable, { reload }] = useTable({ |
||||
title: '公众号账号列表', |
||||
api: getAccountPage, |
||||
columns, |
||||
formConfig: { labelWidth: 120, schemas: searchFormSchema }, |
||||
useSearchForm: true, |
||||
showTableSetting: true, |
||||
actionColumn: { |
||||
width: 140, |
||||
title: t('common.action'), |
||||
dataIndex: 'action', |
||||
fixed: 'right' |
||||
} |
||||
}) |
||||
|
||||
/** 新增按钮操作 */ |
||||
function handleCreate() { |
||||
openModal(true, { isUpdate: false }) |
||||
} |
||||
|
||||
/** 修改按钮操作 */ |
||||
function handleEdit(record: Recordable) { |
||||
openModal(true, { record, isUpdate: true }) |
||||
} |
||||
|
||||
/** 生成二维码的按钮操作 */ |
||||
function handleGenerateQrCode(record: Recordable) { |
||||
createConfirm({ |
||||
title: '生成二维码', |
||||
iconType: 'warning', |
||||
content: '是否确认生成公众号账号' + record.name + '的二维码?', |
||||
async onOk() { |
||||
await generateAccountQrCode(record.id) |
||||
createMessage.success(t('common.exportSuccessText')) |
||||
} |
||||
}) |
||||
} |
||||
|
||||
/** 清空二维码 API 配额的按钮操作 */ |
||||
function handleCleanQuota(record: Recordable) { |
||||
createConfirm({ |
||||
title: '删除二维码', |
||||
iconType: 'warning', |
||||
content: '是否确认清空生成公众号账号' + record.name + '的 API 配额?', |
||||
async onOk() { |
||||
await clearAccountQuota(record.id) |
||||
createMessage.success('清空 API 配额成功') |
||||
} |
||||
}) |
||||
} |
||||
|
||||
/** 删除按钮操作 */ |
||||
async function handleDelete(record: Recordable) { |
||||
await deleteAccount(record.id) |
||||
createMessage.success(t('common.delSuccessText')) |
||||
reload() |
||||
} |
||||
</script> |
||||
|
Reference in new issue