use-table-method.tsx 6.5 KB

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