|
@@ -1,4 +1,186 @@
|
|
|
-function Page() {
|
|
|
- return '小程序组件配置';
|
|
|
-}
|
|
|
+import { useAjax } from '@/Hook/useAjax';
|
|
|
+import { apiDistributorInfoList } from '@/services/distribution/info';
|
|
|
+import {
|
|
|
+ apiWxAppInfo,
|
|
|
+ apiWxAppInfoPageList,
|
|
|
+ apiWxAppInfoRemove,
|
|
|
+ apiWxAppInfoUpdate,
|
|
|
+ apiWxAppInfoUpdateEnabled,
|
|
|
+ apiWxAppInfoWxAppConfigAddOrEdit,
|
|
|
+ wechatMchAll,
|
|
|
+} from '@/services/distribution/weChatInfo';
|
|
|
+import { PlusCircleOutlined } from '@ant-design/icons';
|
|
|
+import {
|
|
|
+ ActionType,
|
|
|
+ BetaSchemaForm,
|
|
|
+ PageContainer,
|
|
|
+ ProFormInstance,
|
|
|
+ ProTable,
|
|
|
+} from '@ant-design/pro-components';
|
|
|
+import { useModel } from '@umijs/max';
|
|
|
+import { Button, message } from 'antd';
|
|
|
+import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
+import formConfig from './formConfig';
|
|
|
+import { columns } from './tableConfig';
|
|
|
+import { apiMiniappComponentInfoDel, apiMiniappComponentInfoPageList, apiMiniappComponentInfoSave, apiMiniappComponentInfoUpdate, apiMiniappComponentInfoUpdateEnabled } from '@/services/distribution/miniprogram';
|
|
|
+
|
|
|
+type DataItem = {
|
|
|
+ name: string;
|
|
|
+ state: string;
|
|
|
+};
|
|
|
+const Page: React.FC = () => {
|
|
|
+ const formRef = useRef<ProFormInstance>();
|
|
|
+ const assignRormRef = useRef<ProFormInstance>();
|
|
|
+ const actionRef = useRef<ActionType>();
|
|
|
+ let { state } = useModel('global');
|
|
|
+ let [open, setOpen] = useState<any>(null); //新增
|
|
|
+ let [assignOpen, setAssignOpen] = useState(false);
|
|
|
+ let [editValues, setEditValues] = useState<any>({});
|
|
|
+ // ======API===============
|
|
|
+ let MiniappComponentInfoPageList = useAjax((params) => apiMiniappComponentInfoPageList(params), { type: 'table' }); //列表
|
|
|
+ let MiniappComponentInfoUpdate = useAjax((params) => apiMiniappComponentInfoUpdate(params)); //更新
|
|
|
+ let MiniappComponentInfoSave = useAjax((params) => apiMiniappComponentInfoSave(params)); //新增
|
|
|
+ let MiniappComponentInfoDel = useAjax((params) => apiMiniappComponentInfoDel(params)); //删除
|
|
|
+ let MiniappComponentInfoUpdateEnabled = useAjax((params) => apiMiniappComponentInfoUpdateEnabled(params)); //启停
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ }, []);
|
|
|
+ // 删除
|
|
|
+ const del = (id: any) => {
|
|
|
+ MiniappComponentInfoDel.run(id).then((res) => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ actionRef?.current?.reload();
|
|
|
+ message.success('删除成功');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 状态更新
|
|
|
+ const stateUpdata = (id: any, ck: boolean) => {
|
|
|
+ MiniappComponentInfoUpdateEnabled.run({ id, enabled: ck }).then((res) => {
|
|
|
+ if (res.data) {
|
|
|
+ actionRef?.current?.reload();
|
|
|
+ message.success(ck ? '启动成功' : '停用成功');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 新增 or 编辑
|
|
|
+ const submit = async (values: any) => {
|
|
|
+ let api = editValues?.id ? MiniappComponentInfoUpdate : MiniappComponentInfoSave;
|
|
|
+ if (editValues?.id) {
|
|
|
+ values.id = editValues?.id;
|
|
|
+ }
|
|
|
+ api.run(values).then((res) => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ actionRef?.current?.reload();
|
|
|
+ message.success('操作成功!');
|
|
|
+ closeForm(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log(values);
|
|
|
+ };
|
|
|
+ // 关闭表单弹窗和重置表单内容
|
|
|
+ const closeForm = (b: boolean, values?: any) => {
|
|
|
+ if (!b) {
|
|
|
+ setEditValues({});
|
|
|
+ formRef?.current?.resetFields?.();
|
|
|
+ setOpen(b);
|
|
|
+ } else {
|
|
|
+ setEditValues(values);
|
|
|
+ setTimeout(() => {
|
|
|
+ formRef?.current?.setFieldsValue({ ...values, mchId: values?.mchInfo?.id });
|
|
|
+ }, 100);
|
|
|
+ setOpen(b);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return (
|
|
|
+ <PageContainer>
|
|
|
+ <ProTable<any, any>
|
|
|
+ headerTitle={'小程序组件列表'}
|
|
|
+ actionRef={actionRef}
|
|
|
+ rowKey={(r) => r.id}
|
|
|
+ search={{
|
|
|
+ labelWidth: 120,
|
|
|
+ }}
|
|
|
+ scroll={{ x: 'auto' }}
|
|
|
+ request={async (params) => {
|
|
|
+ return await MiniappComponentInfoPageList.run(params);
|
|
|
+ }}
|
|
|
+ toolBarRender={() => {
|
|
|
+ return [
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={() => {
|
|
|
+ setOpen(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <PlusCircleOutlined />
|
|
|
+ 新增组件
|
|
|
+ </Button>,
|
|
|
+ ];
|
|
|
+ }}
|
|
|
+ columns={columns(closeForm, del, stateUpdata,state?.enumList)}
|
|
|
+ // bordered
|
|
|
+ />
|
|
|
+ {/* 新增修改 */}
|
|
|
+ <BetaSchemaForm<DataItem>
|
|
|
+ title={!editValues?.id ? '新增组件' : '编辑组件'}
|
|
|
+ formRef={formRef}
|
|
|
+ width={600}
|
|
|
+ open={open}
|
|
|
+ onOpenChange={(b) => {
|
|
|
+ !b && closeForm(b);
|
|
|
+ }}
|
|
|
+ layoutType={'ModalForm'}
|
|
|
+ labelCol={{ span: 6 }}
|
|
|
+ wrapperCol={{ span: 14 }}
|
|
|
+ grid={true}
|
|
|
+ rowProps={{ gutter: [10, 10] }}
|
|
|
+ layout="horizontal"
|
|
|
+ onFinish={submit}
|
|
|
+ columns={formConfig(state?.enumList)}
|
|
|
+ loading={MiniappComponentInfoSave?.loading || MiniappComponentInfoUpdate?.loading}
|
|
|
+ />
|
|
|
+ {/*指派 */}
|
|
|
+ {/* <BetaSchemaForm<DataItem>
|
|
|
+ title={editValues?.appName + '小程序指派'}
|
|
|
+ formRef={assignRormRef}
|
|
|
+ width={400}
|
|
|
+ open={assignOpen}
|
|
|
+ onOpenChange={(b) => {
|
|
|
+ if (!b) {
|
|
|
+ setEditValues({});
|
|
|
+ setAssignOpen(false);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ layoutType={'ModalForm'}
|
|
|
+ labelCol={{ span: 6 }}
|
|
|
+ wrapperCol={{ span: 14 }}
|
|
|
+ grid={true}
|
|
|
+ rowProps={{ gutter: [20, 20] }}
|
|
|
+ layout="horizontal"
|
|
|
+ onFinish={assign}
|
|
|
+ columns={[
|
|
|
+ {
|
|
|
+ title: '分销商',
|
|
|
+ dataIndex: 'distributorId',
|
|
|
+ formItemProps: {
|
|
|
+ style: { marginTop: 20 },
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '此项为必填项',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ valueEnum: () => {
|
|
|
+ let arr = DistributorInfoList?.data?.data;
|
|
|
+ return new Map(arr?.map(({ id, companyName }: any) => [id, companyName]));
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ loading={WxAppInfoWxAppConfigAddOrEdit?.loading}
|
|
|
+ /> */}
|
|
|
+ </PageContainer>
|
|
|
+ );
|
|
|
+};
|
|
|
export default Page;
|