use-table-method.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { useGlobSetting } from '@/hooks/setting';
  2. import { DrawerType } from '@/types/scene/constant.ts';
  3. const { appPCUrl } = useGlobSetting()
  4. export const colomns = [
  5. { label: '名称', prop: 'name', minWidth: 300 },
  6. {
  7. label: '设置', prop: 'labelName', minWidth: 300,
  8. render: ({ row }) => {
  9. if (row.nodeType === DrawerType.company) {
  10. return (
  11. <a
  12. href={`./#/layout/scene-config?companyId=${row.id}&companyName=${row.name}&viewType=1`}
  13. >
  14. 布局设置
  15. </a>
  16. );
  17. } else if (row.nodeType === DrawerType.workshop) {
  18. return (
  19. <a
  20. href={`./#/layout/camera-config?workshopId=${row.id}&workshopName=${row.name}&viewType=1`}
  21. >
  22. 相机导航设置
  23. </a>
  24. );
  25. }
  26. },
  27. },
  28. // { label: '场景标签', prop: 'labelName', minWidth: 300 },
  29. // { label: '代码', prop: 'code' },
  30. // {
  31. // label: '预览',
  32. // prop: 'preview',
  33. // minWidth: 300,
  34. // render: ({ row, column }) => {
  35. // if (row.nodeType === DrawerType.company) {
  36. // return (
  37. // // TODO 这里的跳转需要根据前台的路由地址来
  38. // <a
  39. // href={`${appPCUrl}#/company?companyId=${row.id}`}
  40. // target="_blank"
  41. // >
  42. // 公司预览
  43. // </a>
  44. // );
  45. // } else if (row.nodeType === DrawerType.workshop) {
  46. // return (
  47. // <a href={`${appPCUrl}#/shop?id=${row.id}`} target="_blank">
  48. // 车间预览
  49. // </a>
  50. // );
  51. // }
  52. // },
  53. // },
  54. ];
  55. // interface DataSourceUser
  56. // extends UseComType<UseWorkshopType<UseWorkspaceType>> {
  57. // parent?: UseComType<UseWorkshopType<UseWorkspaceType>> | null;
  58. // }
  59. // 修改: 现在排序车间或工位时按上一级id找 找到公司id为止
  60. // export const dataSourceWithParent = (d: DataSourceUser[], parent: DataSourceUser | null) => {
  61. // d.forEach((item, _index) => {
  62. // item.parent = parent;
  63. // if (item.children && item.children?.length > 0) {
  64. // dataSourceWithParent(item.children as DataSourceUser[], item);
  65. // }
  66. // });
  67. // return d;
  68. // };
  69. // export function removeParent(data) {
  70. // return data.map((item) => {
  71. // // 删除 tag 属性
  72. // delete item.parent;
  73. // // 递归处理子项
  74. // if (item.children && item.children.length > 0) {
  75. // item.children = removeParent(item.children);
  76. // }
  77. // return item;
  78. // });
  79. // }
  80. //找到各个层级
  81. // export function findIndexByItem(data, targetItem, path = []) {
  82. // for (let i = 0; i < data.length; i++) {
  83. // const currentPath = path.concat(i);
  84. // if (data[i].id === targetItem.id && data[i].name === targetItem.name) {
  85. // return currentPath;
  86. // }
  87. // if (data[i].children && data[i].children.length > 0) {
  88. // const childResult = findIndexByItem(data[i].children, targetItem, currentPath);
  89. // if (childResult.length > 0) {
  90. // return childResult;
  91. // }
  92. // }
  93. // }
  94. // return [];
  95. // }
  96. //用于重新修改serial
  97. // export const updateSerials = (data) => {
  98. // for (let i = 0; i < data.length; i++) {
  99. // data[i].serial = i;
  100. // // 如果有子项,递归查找
  101. // if (data[i].children && data[i].children.length > 0) {
  102. // updateSerials(data[i].children);
  103. // }
  104. // }
  105. // return data;
  106. // // return false; // 表示未找到目标项
  107. // };
  108. //用于新增数据
  109. // export const updateData = (data, targetId, newAdd) => {
  110. // for (let i = 0; i < data.length; i++) {
  111. // const currentItem = data[i];
  112. // if (currentItem.id === targetId) {
  113. // if (!currentItem.children) {
  114. // currentItem.children = [];
  115. // }
  116. // currentItem.children.push(newAdd);
  117. // return true; // 表示已经找到并修改
  118. // }
  119. // // 如果有子项,递归查找
  120. // if (currentItem.children && currentItem.children.length > 0) {
  121. // const found = updateData(currentItem.children, targetId, newAdd);
  122. // if (found) {
  123. // return true; // 如果在子项中找到目标项,停止继续查找
  124. // }
  125. // }
  126. // }
  127. // return false; // 表示未找到目标项
  128. // };
  129. //判断该条数据的层级
  130. // export const findItemLevel = (data, targetId, targetName, currentLevel = 0) => {
  131. // for (let i = 0; i < data.length; i++) {
  132. // const item = data[i];
  133. // if (item.id === targetId && item.name === targetName) {
  134. // return currentLevel;
  135. // }
  136. // if (item.children && item.children.length > 0) {
  137. // const childLevel = findItemLevel(item.children, targetId, targetName, currentLevel + 1);
  138. // if (childLevel !== -1) {
  139. // return childLevel;
  140. // }
  141. // }
  142. // }
  143. // return -1;
  144. // };
  145. //得到parent
  146. // export const getParent = (data: DataSourceUser[], targetCode: string) => {
  147. // //let parentNode = {} as DataSourceUser
  148. // for (let i = 0; i < data.length; i++) {
  149. // const item = data[i];
  150. // if (item.code === targetCode) {
  151. // // parentNode = item
  152. // return item
  153. // }
  154. // if (item.children && item.children.length > 0) {
  155. // const foundItem = getParent(item.children as DataSourceUser[], targetCode);
  156. // if (foundItem) {
  157. // return foundItem
  158. // }
  159. // }
  160. // }
  161. // return null;
  162. // };
  163. //删除行
  164. // export const deleteTableRow = (dataSource, targetId) => {
  165. // const deleteRecursive = (data) => {
  166. // for (let i = 0; i < data.length; i++) {
  167. // const currentItem = data[i];
  168. // if (currentItem.id === targetId) {
  169. // // 删除当前项
  170. // data.splice(i, 1);
  171. // return true;
  172. // }
  173. // // 如果有子项,递归查找
  174. // if (currentItem.children && currentItem.children.length > 0) {
  175. // const found = deleteRecursive(currentItem.children);
  176. // if (found) {
  177. // return true; // 如果在子项中找到目标项,停止继续查找
  178. // }
  179. // }
  180. // }
  181. // return false; // 表示未找到目标项
  182. // };
  183. // // 从顶层开始递归删除
  184. // deleteRecursive(dataSource);
  185. // };
  186. //找出数据中的全部code
  187. // export const flattenCodes = (data) => {
  188. // const codes: string[] = [];
  189. // const traverse = (node: { code: string; children: any[] }) => {
  190. // codes.push(node.code);
  191. // if (node.children && node.children.length > 0) {
  192. // node.children.forEach(traverse);
  193. // }
  194. // };
  195. // data.forEach(traverse);
  196. // return codes;
  197. // };
  198. // export enum ENABLED {
  199. // FALSE = 1,
  200. // TRUE = 0,
  201. // }