|
@@ -1,103 +1,216 @@
|
|
|
import { useState, useRef } from "react";
|
|
|
-import { ActionType, ProColumns, TableDropdown } from '@ant-design/pro-components';
|
|
|
+import {
|
|
|
+ ActionType,
|
|
|
+ ProColumns,
|
|
|
+ TableDropdown,
|
|
|
+} from "@ant-design/pro-components";
|
|
|
import { ProTable } from "@ant-design/pro-components";
|
|
|
-import { Button, Space, Tag } from 'antd';
|
|
|
+import { Popconfirm, Tag, message } from "antd";
|
|
|
import AddAppDrawer from "./AddAppDrawer";
|
|
|
-import { GetAppList, DeleteAppTemplate } from "@/api/appStore";
|
|
|
+import {
|
|
|
+ GetAppList,
|
|
|
+ DeleteAppTemplate,
|
|
|
+ OffMarketApp,
|
|
|
+ OnMarketApp,
|
|
|
+} from "@/api/appStore";
|
|
|
import type { AppItem } from "@/api/appStore";
|
|
|
+import { history } from "umi";
|
|
|
|
|
|
+export default () => {
|
|
|
+ const actionRef = useRef<ActionType>();
|
|
|
+ const [editData, setEditData] = useState<AppItem>();
|
|
|
+ const handleToDetail = (id?: string) => {
|
|
|
+ history.push(`/detail/application/${id}`);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleOffMarket = async (id?: string) => {
|
|
|
+ if (id) {
|
|
|
+ await OffMarketApp({ ids: [id] });
|
|
|
+ actionRef.current?.reload();
|
|
|
+ message.success("下架成功");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleOnMarket = async (id?: string) => {
|
|
|
+ if (id) {
|
|
|
+ await OnMarketApp({ ids: [id] });
|
|
|
+ actionRef.current?.reload();
|
|
|
+ message.success("上架成功");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleDelete = async (id?: string) => {
|
|
|
+ if (id) {
|
|
|
+ await DeleteAppTemplate({ ids: [id] });
|
|
|
+ actionRef.current?.reload();
|
|
|
+ message.success("删除成功");
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-const columns: ProColumns<AppItem>[] = [
|
|
|
- {
|
|
|
- title: '应用名称',
|
|
|
- dataIndex: 'name',
|
|
|
- copyable: true,
|
|
|
- ellipsis: true,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '作者',
|
|
|
- dataIndex: 'title',
|
|
|
- ellipsis: true,
|
|
|
- },
|
|
|
- {
|
|
|
- title: '图标',
|
|
|
- dataIndex: 'icon',
|
|
|
- render: (_, record) => (
|
|
|
- <img
|
|
|
- src={record.icon}
|
|
|
- alt=""
|
|
|
- style={{
|
|
|
- width: 30,
|
|
|
- height: 30,
|
|
|
- borderRadius: '50%',
|
|
|
- }}
|
|
|
- />
|
|
|
- ),
|
|
|
- },
|
|
|
- {
|
|
|
- disable: true,
|
|
|
- title: '标签',
|
|
|
- dataIndex: 'tags',
|
|
|
- search: false,
|
|
|
- renderFormItem: (_, { defaultRender }) => {
|
|
|
- return defaultRender(_);
|
|
|
+ const columns: ProColumns<AppItem>[] = [
|
|
|
+ {
|
|
|
+ title: "图标",
|
|
|
+ dataIndex: "icon",
|
|
|
+ search: false,
|
|
|
+ render: (_, record) => (
|
|
|
+ <img
|
|
|
+ src={`/api/File/Download?fileId=${record.icon}`}
|
|
|
+ alt=""
|
|
|
+ style={{
|
|
|
+ width: 30,
|
|
|
+ height: 30,
|
|
|
+ borderRadius: "50%",
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ ),
|
|
|
},
|
|
|
- render: (_, record) => (
|
|
|
- <Space>
|
|
|
- {record.tags.split(',').map((tag) => (
|
|
|
- <Tag color={'green'} key={tag}>
|
|
|
- {tag}
|
|
|
- </Tag>
|
|
|
- ))}
|
|
|
- </Space>
|
|
|
- ),
|
|
|
- },
|
|
|
- {
|
|
|
- title: '上架状态',
|
|
|
- dataIndex: 'state',
|
|
|
- filters: true,
|
|
|
- onFilter: true,
|
|
|
- ellipsis: true,
|
|
|
- valueType: 'select',
|
|
|
- valueEnum: {
|
|
|
- all: { text: '全部' },
|
|
|
- open: {
|
|
|
- text: '已上架',
|
|
|
- status: 'Error',
|
|
|
+ {
|
|
|
+ title: "应用名称",
|
|
|
+ dataIndex: "name",
|
|
|
+ copyable: true,
|
|
|
+ ellipsis: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "作者",
|
|
|
+ dataIndex: "createByName",
|
|
|
+ ellipsis: true,
|
|
|
+ search: false,
|
|
|
+ },
|
|
|
+ // {
|
|
|
+ // title: "应用场景",
|
|
|
+ // dataIndex: "applicationScenarios",
|
|
|
+ // ellipsis: true,
|
|
|
+ // search: false,
|
|
|
+ // renderText: (text) => {
|
|
|
+ // return (JSON.parse(text || '[]')).map((item: string) => (
|
|
|
+ // <Tag key={item}>{item}</Tag>
|
|
|
+ // ));
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // title: "应用行业",
|
|
|
+ // dataIndex: "industries",
|
|
|
+ // ellipsis: true,
|
|
|
+ // search: false,
|
|
|
+ // renderText: (text) => {
|
|
|
+ // return (JSON.parse(text || '[]')).map((item: string) => (
|
|
|
+ // <Tag key={item}>{item}</Tag>
|
|
|
+ // ));
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ {
|
|
|
+ disable: true,
|
|
|
+ title: "标签",
|
|
|
+ dataIndex: "tags",
|
|
|
+ search: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "上架状态",
|
|
|
+ dataIndex: "isOnMarket",
|
|
|
+ filters: true,
|
|
|
+ onFilter: true,
|
|
|
+ ellipsis: true,
|
|
|
+ valueType: "select",
|
|
|
+ valueEnum: {
|
|
|
+ on: {
|
|
|
+ text: "已上架",
|
|
|
+ status: "Error",
|
|
|
+ },
|
|
|
+ off: {
|
|
|
+ text: "未上架",
|
|
|
+ status: "Success",
|
|
|
+ },
|
|
|
},
|
|
|
- closed: {
|
|
|
- text: '未上架',
|
|
|
- status: 'Success',
|
|
|
+ render: (_, record) => (
|
|
|
+ <Tag color={record.isOnMarket ? "green" : "red"}>
|
|
|
+ {record.isOnMarket ? "已上架" : "未上架"}
|
|
|
+ </Tag>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "使用量",
|
|
|
+ dataIndex: "useNum",
|
|
|
+ search: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "价格",
|
|
|
+ dataIndex: "price",
|
|
|
+ search: false,
|
|
|
+ renderText: (text) => {
|
|
|
+ return text ? `¥${text}` : "免费";
|
|
|
},
|
|
|
},
|
|
|
- },
|
|
|
- {
|
|
|
- title: '使用量',
|
|
|
- dataIndex: 'useNum',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '操作',
|
|
|
- valueType: 'option',
|
|
|
- key: 'option',
|
|
|
- render: (text, record, _, action) => [
|
|
|
- <a>
|
|
|
- 编辑
|
|
|
- </a>,
|
|
|
- <a href={''} target="_blank" rel="noopener noreferrer" key="view">
|
|
|
- 详情
|
|
|
- </a>,
|
|
|
- <a href={'record'} target="_blank" rel="noopener noreferrer" key="upload">
|
|
|
- 上架
|
|
|
- </a>,
|
|
|
- <a href={'record'} target="_blank" rel="noopener noreferrer" key="delete">
|
|
|
- 删除
|
|
|
- </a>,
|
|
|
- ],
|
|
|
- },
|
|
|
-];
|
|
|
-
|
|
|
-export default () => {
|
|
|
- const actionRef = useRef<ActionType>();
|
|
|
+ {
|
|
|
+ title: "试用地址",
|
|
|
+ dataIndex: "trialUrl",
|
|
|
+ search: false,
|
|
|
+ renderText: (text) =>
|
|
|
+ text ? (
|
|
|
+ <a target="_blank" rel="noopener noreferrer" href={text}>
|
|
|
+ {text}
|
|
|
+ </a>
|
|
|
+ ) : (
|
|
|
+ "-"
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "创建时间",
|
|
|
+ dataIndex: "createTime",
|
|
|
+ search: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "更新时间",
|
|
|
+ dataIndex: "updateTime",
|
|
|
+ search: false,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: "操作",
|
|
|
+ valueType: "option",
|
|
|
+ key: "option",
|
|
|
+ width: 180,
|
|
|
+ render: (text, record, _, action) => [
|
|
|
+ <a key="edit" onClick={() => setEditData(record)}>
|
|
|
+ 编辑
|
|
|
+ </a>,
|
|
|
+ <a
|
|
|
+ target="_blank"
|
|
|
+ rel="noopener noreferrer"
|
|
|
+ key="view"
|
|
|
+ onClick={() => handleToDetail(record.id)}
|
|
|
+ >
|
|
|
+ 详情
|
|
|
+ </a>,
|
|
|
+ record.isOnMarket ? (
|
|
|
+ <a
|
|
|
+ target="_blank"
|
|
|
+ rel="noopener noreferrer"
|
|
|
+ key="off"
|
|
|
+ onClick={() => handleOffMarket(record.id)}
|
|
|
+ >
|
|
|
+ 下架
|
|
|
+ </a>
|
|
|
+ ) : (
|
|
|
+ <a
|
|
|
+ target="_blank"
|
|
|
+ rel="noopener noreferrer"
|
|
|
+ key="on"
|
|
|
+ onClick={() => handleOnMarket(record.id)}
|
|
|
+ >
|
|
|
+ 上架
|
|
|
+ </a>
|
|
|
+ ),
|
|
|
+ <Popconfirm
|
|
|
+ key="delete"
|
|
|
+ title="确定删除吗?"
|
|
|
+ onConfirm={() => handleDelete(record.id)}
|
|
|
+ >
|
|
|
+ <a className="text-red-500" target="_blank" rel="noopener noreferrer">
|
|
|
+ 删除
|
|
|
+ </a>
|
|
|
+ </Popconfirm>,
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ];
|
|
|
|
|
|
return (
|
|
|
<ProTable<AppItem>
|
|
@@ -106,35 +219,39 @@ export default () => {
|
|
|
cardBordered
|
|
|
request={async (params, sort, filter) => {
|
|
|
console.log(params, sort, filter);
|
|
|
+ const isOnMarket =
|
|
|
+ params?.isOnMarket === "on"
|
|
|
+ ? 1
|
|
|
+ : params?.isOnMarket === "off"
|
|
|
+ ? 0
|
|
|
+ : undefined;
|
|
|
const res = await GetAppList({
|
|
|
currentPage: params.current || 1,
|
|
|
pageSize: params.pageSize || 10,
|
|
|
filters: [
|
|
|
- {name: 'name', value: params?.name},
|
|
|
- {name: 'applicationScenarios', value: params?.applicationScenarios},
|
|
|
- {name: 'industries', value: params?.industries},
|
|
|
- {name: 'isFree', value: params?.isFree},
|
|
|
- {name: 'isOnMarket', value: params?.isOnMarket},
|
|
|
- {name: 'idDel', value: params?.idDel},
|
|
|
- ]
|
|
|
+ { name: "name", value: params?.name },
|
|
|
+ { name: "isFree", value: params?.isFree },
|
|
|
+ { name: "isOnMarket", value: isOnMarket },
|
|
|
+ { name: "isDel", value: 0 },
|
|
|
+ ],
|
|
|
});
|
|
|
-
|
|
|
+ const data = res?.result || {};
|
|
|
return {
|
|
|
- data: [],
|
|
|
+ data: data.model || [],
|
|
|
success: true,
|
|
|
- total: res.totalCount
|
|
|
- }
|
|
|
+ total: data.totalCount || 0,
|
|
|
+ };
|
|
|
}}
|
|
|
columnsState={{
|
|
|
- persistenceKey: 'shalu-marketplace',
|
|
|
- persistenceType: 'localStorage',
|
|
|
+ persistenceKey: "shalu-marketplace",
|
|
|
+ persistenceType: "localStorage",
|
|
|
defaultValue: {
|
|
|
- option: { fixed: 'right', disable: true },
|
|
|
+ option: { fixed: "right", disable: true },
|
|
|
},
|
|
|
}}
|
|
|
rowKey="id"
|
|
|
search={{
|
|
|
- labelWidth: 'auto',
|
|
|
+ labelWidth: "auto",
|
|
|
}}
|
|
|
options={{
|
|
|
setting: {
|
|
@@ -143,10 +260,17 @@ export default () => {
|
|
|
}}
|
|
|
pagination={{
|
|
|
pageSize: 10,
|
|
|
- onChange: (page) => console.log(page),
|
|
|
}}
|
|
|
dateFormatter="string"
|
|
|
- headerTitle={<AddAppDrawer />}
|
|
|
+ headerTitle={
|
|
|
+ <AddAppDrawer
|
|
|
+ editData={editData}
|
|
|
+ onSuccess={() => {
|
|
|
+ actionRef.current?.reload();
|
|
|
+ setEditData(undefined);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ }
|
|
|
/>
|
|
|
);
|
|
|
-}
|
|
|
+};
|