edit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <ui-group borderBottom class="path-header">
  3. <template #header>
  4. <div class="path-header-content">
  5. <ui-input type="checkbox" v-model="all" :label="$t('sys.selectAll')" />
  6. <ui-icon type="add" ctrl @click="edit()" />
  7. </div>
  8. </template>
  9. </ui-group>
  10. <ui-group class="path-group">
  11. <div v-for="path in paths" :key="path.id" class="path-item">
  12. <ui-input
  13. type="checkbox"
  14. :modelValue="selects.some((item) => item.id === path.id)"
  15. @update:modelValue="(select: boolean) => updateSelect(path, select)"
  16. />
  17. <PathSign
  18. :path="path"
  19. @edit="edit(path)"
  20. @delete="deletePath(path)"
  21. class="path-content"
  22. />
  23. </div>
  24. </ui-group>
  25. <EditPath :data="currentPath" v-if="currentPath" @applyGlobal="applyGlobal" />
  26. </template>
  27. <script lang="ts" setup>
  28. import { computed, ref, watchEffect } from "vue";
  29. import PathSign from "./sign.vue";
  30. import EditPath from "./edit-path.vue";
  31. import { getPathNode, pathsGroup } from "@/sdk/association/path";
  32. import { useViewStack } from "@/hook";
  33. import {
  34. paths,
  35. enterEdit,
  36. sysBus,
  37. autoSavePaths,
  38. createPath,
  39. enterOld,
  40. selectPaths,
  41. save,
  42. } from "@/store";
  43. import type { Path } from "@/store";
  44. import { Dialog } from "bill/expose-common";
  45. import { showPathsStack, showPathStack } from "@/env";
  46. import { asyncTimeout } from "@/utils";
  47. import { ui18n } from "@/lang";
  48. const { all, selects, updateSelect } = selectPaths;
  49. const currentPath = ref<Path | null>(null);
  50. const emit = defineEmits<{ (e: "update:current", v: Path | null): void }>();
  51. watchEffect(() => emit("update:current", currentPath.value));
  52. const leaveEdit = () => {
  53. currentPath.value = null;
  54. // pathsGroup.visibility(true);
  55. // showPathsStack.pop();
  56. // showPathStack.pop();
  57. };
  58. const edit = async (path?: Path) => {
  59. await save();
  60. await asyncTimeout(16);
  61. if (!path) {
  62. path = createPath();
  63. paths.value.unshift(path);
  64. }
  65. currentPath.value = path;
  66. enterEdit();
  67. sysBus.on("leave", leaveEdit);
  68. // showPathsStack.push(ref(false));
  69. // showPathStack.push(computed(() => path.id));
  70. };
  71. const deletePath = (path: Path) => {
  72. const index = paths.value.indexOf(path);
  73. paths.value.splice(index, 1);
  74. };
  75. const applyGlobal = async (keys: string | string[]) => {
  76. if (!(await Dialog.confirm(ui18n.t("guide.path.applyConfirm")))) return;
  77. keys = Array.isArray(keys) ? keys : [keys];
  78. for (const current of paths.value!) {
  79. let val: any = current;
  80. let newVal: any = currentPath.value;
  81. for (let i = 0; i < keys.length; i++) {
  82. if (i === keys.length - 1) {
  83. val[keys[i]] = newVal[keys[i]];
  84. } else {
  85. val = val[keys[i]];
  86. newVal = newVal[keys[i]];
  87. }
  88. }
  89. }
  90. };
  91. useViewStack(autoSavePaths);
  92. defineExpose({
  93. add: () => {
  94. edit();
  95. },
  96. });
  97. </script>
  98. <style lang="scss" scoped>
  99. .video-toolbar {
  100. height: auto;
  101. display: block;
  102. }
  103. .guide-list {
  104. padding-bottom: 30px;
  105. }
  106. .path-group {
  107. padding-bottom: 50px;
  108. .path-item {
  109. width: 100%;
  110. display: flex;
  111. align-items: center;
  112. border-bottom: 1px solid var(--colors-border-color);
  113. }
  114. .path-content {
  115. flex: 1;
  116. }
  117. }
  118. .path-header-content {
  119. display: flex;
  120. align-items: center;
  121. justify-content: space-between;
  122. }
  123. </style>
  124. <style>
  125. .path-header.ui-group .border-bottom,
  126. .path-header.ui-group {
  127. margin-bottom: 0;
  128. }
  129. </style>