|
|
@@ -0,0 +1,229 @@
|
|
|
+import { ref } from 'vue';
|
|
|
+
|
|
|
+export const colomns = [
|
|
|
+ { label: '场景名称', prop: 'name', width: 300 },
|
|
|
+ { label: '场景标签', prop: 'tag', width: 300 },
|
|
|
+ { label: '代码', prop: 'code' },
|
|
|
+];
|
|
|
+
|
|
|
+export interface User {
|
|
|
+ name?: string;
|
|
|
+ tag?: string; //顶级场景下面的场景标签
|
|
|
+ Toptag?: string[]; //公司层面的标签
|
|
|
+ code?: string;
|
|
|
+ hasChildren?: boolean;
|
|
|
+ children?: User[];
|
|
|
+ status?: string;
|
|
|
+ seniorScene?: string;
|
|
|
+ templeteRoom?: string;
|
|
|
+ leader?: string;
|
|
|
+}
|
|
|
+
|
|
|
+interface DataSourceUser extends User {
|
|
|
+ parent?: User | null;
|
|
|
+}
|
|
|
+
|
|
|
+export const dataSourceWithParent = (d: DataSourceUser[], parent: DataSourceUser | null) => {
|
|
|
+ d.forEach((item, _index) => {
|
|
|
+ item.parent = parent;
|
|
|
+
|
|
|
+ if (item.children && item.children?.length > 0) {
|
|
|
+ dataSourceWithParent(item.children, item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return d;
|
|
|
+};
|
|
|
+
|
|
|
+export const options = [
|
|
|
+ {
|
|
|
+ value: 'Option1',
|
|
|
+ label: 'Option1',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'Option2',
|
|
|
+ label: 'Option2',
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+export const tableData = ref<User[]>([
|
|
|
+ {
|
|
|
+ name: '1',
|
|
|
+ tag: '6',
|
|
|
+ code: '22',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '2',
|
|
|
+ tag: '7',
|
|
|
+ code: '33',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '3',
|
|
|
+ tag: '6',
|
|
|
+ code: '333',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: '31',
|
|
|
+ tag: '6',
|
|
|
+ code: '44',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: '311',
|
|
|
+ tag: '7',
|
|
|
+ code: 'zzz',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '32',
|
|
|
+ tag: '8',
|
|
|
+ code: 'wangxiaohu',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: '321',
|
|
|
+ tag: '8',
|
|
|
+ code: 'zzqqqz',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '4',
|
|
|
+ tag: '7',
|
|
|
+ code: '55555',
|
|
|
+ },
|
|
|
+]);
|
|
|
+
|
|
|
+//用于新增数据
|
|
|
+export const updateData = (data, targetName, newAdd) => {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ const currentItem = data[i];
|
|
|
+
|
|
|
+ if (currentItem.name === targetName) {
|
|
|
+ if (!currentItem.children) {
|
|
|
+ currentItem.children = [];
|
|
|
+ }
|
|
|
+ currentItem.children.push(newAdd);
|
|
|
+ return true; // 表示已经找到并修改
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有子项,递归查找
|
|
|
+ if (currentItem.children && currentItem.children.length > 0) {
|
|
|
+ const found = updateData(currentItem.children, targetName, newAdd);
|
|
|
+
|
|
|
+ if (found) {
|
|
|
+ return true; // 如果在子项中找到目标项,停止继续查找
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false; // 表示未找到目标项
|
|
|
+};
|
|
|
+
|
|
|
+//判断该条数据的层级
|
|
|
+export const findItemLevel = (data, targetCode, currentLevel = 0) => {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ const item = data[i];
|
|
|
+
|
|
|
+ if (item.code === targetCode) {
|
|
|
+ return currentLevel;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ const childLevel = findItemLevel(item.children, targetCode, currentLevel + 1);
|
|
|
+ if (childLevel !== -1) {
|
|
|
+ return childLevel;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return -1;
|
|
|
+};
|
|
|
+
|
|
|
+//删除行
|
|
|
+export const deleteTableRow = (dataSource, name) => {
|
|
|
+ const deleteRecursive = (data) => {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ const currentItem = data[i];
|
|
|
+
|
|
|
+ if (currentItem.name === name) {
|
|
|
+ // 删除当前项
|
|
|
+ data.splice(i, 1);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有子项,递归查找
|
|
|
+ if (currentItem.children && currentItem.children.length > 0) {
|
|
|
+ const found = deleteRecursive(currentItem.children);
|
|
|
+
|
|
|
+ if (found) {
|
|
|
+ return true; // 如果在子项中找到目标项,停止继续查找
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false; // 表示未找到目标项
|
|
|
+ };
|
|
|
+
|
|
|
+ // 从顶层开始递归删除
|
|
|
+ deleteRecursive(dataSource);
|
|
|
+};
|
|
|
+
|
|
|
+//行的编辑提交功能
|
|
|
+export const editTableRow = (
|
|
|
+ dataSource,
|
|
|
+ level,
|
|
|
+ name,
|
|
|
+ newName,
|
|
|
+ newCode,
|
|
|
+ newStatus,
|
|
|
+ newLeader = '',
|
|
|
+ newTempleteRoom = '',
|
|
|
+ newTag = '',
|
|
|
+ newToptag = [] as unknown as string[],
|
|
|
+) => {
|
|
|
+ const editTRecursive = (data) => {
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ const currentItem = data[i];
|
|
|
+
|
|
|
+ if (currentItem.name === name) {
|
|
|
+ // 修改
|
|
|
+ currentItem.name = newName;
|
|
|
+ currentItem.code = newCode;
|
|
|
+ currentItem.status = newStatus;
|
|
|
+ if (level === 0) {
|
|
|
+ currentItem.Toptag = newToptag;
|
|
|
+ } else if (level === 1) {
|
|
|
+ currentItem.tag = newTag;
|
|
|
+ currentItem.templeteRoom = newTempleteRoom;
|
|
|
+ } else if (level === 2) {
|
|
|
+ currentItem.leader = newLeader;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有子项,递归查找
|
|
|
+ if (currentItem.children && currentItem.children.length > 0) {
|
|
|
+ const found = editTRecursive(currentItem.children);
|
|
|
+
|
|
|
+ if (found) {
|
|
|
+ return true; // 如果在子项中找到目标项,停止继续查找
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false; // 表示未找到目标项
|
|
|
+ };
|
|
|
+
|
|
|
+ editTRecursive(dataSource);
|
|
|
+};
|
|
|
+
|
|
|
+// export const convertArray = (inputArray) => {
|
|
|
+// return inputArray.map((item) => {
|
|
|
+// const [start, end] = item.split('-');
|
|
|
+// console.log(start, end);
|
|
|
+
|
|
|
+// return { tag: start, templete: end };
|
|
|
+// });
|
|
|
+// };
|