use-table-method.tsx 6.4 KB

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