index.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  3. import ProTable from '@jetlinks/pro-table';
  4. import { message, Popconfirm } from 'antd';
  5. import { useRef, useState } from 'react';
  6. import { useIntl } from '@@/plugin-locale/localeExports';
  7. import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
  8. import { useHistory } from 'umi';
  9. import { model } from '@formily/reactive';
  10. import { observer } from '@formily/react';
  11. import type { FirmwareItem } from '@/pages/device/Firmware/typings';
  12. import Service from '@/pages/device/Firmware/service';
  13. import Save from '@/pages/device/Firmware/Save';
  14. import { AIcon, PermissionButton } from '@/components';
  15. import useDomFullHeight from '@/hooks/document/useDomFullHeight';
  16. import usePermissions from '@/hooks/permission';
  17. import SearchComponent from '@/components/SearchComponent';
  18. import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  19. import { onlyMessage } from '@/utils/util';
  20. import _ from 'lodash';
  21. export const service = new Service('firmware');
  22. export const state = model<{
  23. current?: FirmwareItem;
  24. visible: boolean;
  25. }>({
  26. visible: false,
  27. });
  28. const Firmware = observer(() => {
  29. const actionRef = useRef<ActionType>();
  30. const intl = useIntl();
  31. const { minHeight } = useDomFullHeight(`.firmware`, 24);
  32. const { permission } = usePermissions('device/Firmware');
  33. const [param, setParam] = useState({});
  34. const history = useHistory<Record<string, string>>();
  35. const columns: ProColumns<FirmwareItem>[] = [
  36. {
  37. title: intl.formatMessage({
  38. id: 'pages.device.firmware.name',
  39. defaultMessage: '固件名称',
  40. }),
  41. ellipsis: true,
  42. dataIndex: 'name',
  43. },
  44. {
  45. title: intl.formatMessage({
  46. id: 'pages.device.firmware.version',
  47. defaultMessage: '固件版本',
  48. }),
  49. ellipsis: true,
  50. dataIndex: 'version',
  51. },
  52. {
  53. title: intl.formatMessage({
  54. id: 'pages.device.firmware.productName',
  55. defaultMessage: '所属产品',
  56. }),
  57. ellipsis: true,
  58. dataIndex: 'productId',
  59. valueType: 'select',
  60. render: (text: any, record: any) => record?.productName,
  61. request: () =>
  62. service
  63. .queryProduct({
  64. paging: false,
  65. sorts: [{ name: 'name', order: 'desc' }],
  66. })
  67. .then((resp: any) => {
  68. const _data = resp.result.filter((it: any) => {
  69. return _.map(it?.features || [], 'id').includes('supportFirmware');
  70. });
  71. return _data.map((item: any) => ({ label: item.name, value: item.id }));
  72. }),
  73. },
  74. {
  75. title: intl.formatMessage({
  76. id: 'pages.device.firmware.signMethod',
  77. defaultMessage: '签名方式',
  78. }),
  79. ellipsis: true,
  80. valueType: 'select',
  81. dataIndex: 'signMethod',
  82. valueEnum: {
  83. md5: {
  84. text: 'MD5',
  85. status: 'md5',
  86. },
  87. sha256: {
  88. text: 'SHA256',
  89. status: 'sha256',
  90. },
  91. },
  92. },
  93. {
  94. title: intl.formatMessage({
  95. id: 'pages.device.firmware.createTime',
  96. defaultMessage: '创建时间',
  97. }),
  98. dataIndex: 'createTime',
  99. width: '200px',
  100. ellipsis: true,
  101. valueType: 'dateTime',
  102. // render: (text: any) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  103. // sorter: true,
  104. // defaultSortOrder: 'descend',
  105. },
  106. {
  107. title: intl.formatMessage({
  108. id: 'pages.table.description',
  109. defaultMessage: '说明',
  110. }),
  111. ellipsis: true,
  112. dataIndex: 'description',
  113. },
  114. {
  115. title: intl.formatMessage({
  116. id: 'pages.data.option',
  117. defaultMessage: '操作',
  118. }),
  119. valueType: 'option',
  120. width: 200,
  121. fixed: 'right',
  122. render: (text, record) => [
  123. <PermissionButton
  124. style={{ padding: 0 }}
  125. type="link"
  126. isPermission={permission.view}
  127. key="upgrade"
  128. onClick={() => {
  129. //缓存路由参数
  130. localStorage.setItem('TaskId', record.id);
  131. localStorage.setItem('TaskProductId', record.productId);
  132. const url = `${getMenuPathByParams(MENUS_CODE['device/Firmware/Task'])}`;
  133. history.push(`${url}?id=${record?.id}&productId=${record?.productId}`);
  134. }}
  135. tooltip={{
  136. title: '升级任务',
  137. }}
  138. >
  139. <AIcon type={'icon-tongzhijilu'} />
  140. </PermissionButton>,
  141. <PermissionButton
  142. style={{ padding: 0 }}
  143. type="link"
  144. isPermission={permission.update}
  145. key="editable"
  146. onClick={() => {
  147. state.visible = true;
  148. state.current = record;
  149. }}
  150. tooltip={{
  151. title: intl.formatMessage({
  152. id: 'pages.data.option.edit',
  153. defaultMessage: '编辑',
  154. }),
  155. }}
  156. >
  157. <EditOutlined />
  158. </PermissionButton>,
  159. <PermissionButton
  160. type="link"
  161. key="delete"
  162. style={{ padding: 0 }}
  163. isPermission={permission.delete}
  164. >
  165. <Popconfirm
  166. onConfirm={async () => {
  167. const resp: any = await service.remove(record.id);
  168. if (resp.status === 200) {
  169. onlyMessage(
  170. intl.formatMessage({
  171. id: 'pages.data.option.success',
  172. defaultMessage: '操作成功!',
  173. }),
  174. );
  175. actionRef.current?.reload();
  176. } else {
  177. message.error(resp?.message || '删除失败!');
  178. }
  179. }}
  180. title="确认删除?"
  181. >
  182. <DeleteOutlined />
  183. </Popconfirm>
  184. </PermissionButton>,
  185. ],
  186. },
  187. ];
  188. return (
  189. <PageContainer>
  190. <SearchComponent<FirmwareItem>
  191. field={columns}
  192. target="firmware"
  193. onSearch={(data) => {
  194. // 重置分页数据
  195. actionRef.current?.reset?.();
  196. setParam(data);
  197. }}
  198. />
  199. <ProTable<FirmwareItem>
  200. scroll={{ x: 1366 }}
  201. tableClassName={'firmware'}
  202. tableStyle={{ minHeight }}
  203. search={false}
  204. params={param}
  205. rowKey="id"
  206. columnEmptyText={''}
  207. headerTitle={
  208. <div>
  209. <PermissionButton
  210. onClick={() => {
  211. state.visible = true;
  212. state.current = undefined;
  213. }}
  214. isPermission={permission.add}
  215. key="button"
  216. icon={<PlusOutlined />}
  217. type="primary"
  218. >
  219. {intl.formatMessage({
  220. id: 'pages.data.option.add',
  221. defaultMessage: '新增',
  222. })}
  223. </PermissionButton>
  224. </div>
  225. }
  226. request={async (params) =>
  227. service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
  228. }
  229. columns={columns}
  230. actionRef={actionRef}
  231. />
  232. <Save
  233. data={state.current}
  234. visible={state.visible}
  235. close={() => {
  236. state.visible = false;
  237. actionRef.current?.reload();
  238. }}
  239. />
  240. </PageContainer>
  241. );
  242. });
  243. export default Firmware;