scene-select.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div style="height: 550px" v-loading="!loaded">
  3. <SceneTable :tableProps="tableProps" simple>
  4. <template v-slot:table>
  5. <el-table-column type="selection" width="55" />
  6. </template>
  7. </SceneTable>
  8. </div>
  9. </template>
  10. <script lang="ts" setup>
  11. import { computed, ref, watch } from "vue";
  12. import SceneTable from "./scene.vue";
  13. import { ElMessage, ElTable } from "element-plus";
  14. import { QuiskExpose } from "@/helper/mount";
  15. import { Scene, SceneStatus, scenes as rScenes } from "@/store/scene";
  16. type SimpleScene = Pick<Scene, "sceneId" | "sceneCode">;
  17. const props = defineProps<{
  18. submit: (scenes: SimpleScene[]) => Promise<any>;
  19. scenes: SimpleScene[];
  20. selfScenes?: SimpleScene[];
  21. }>();
  22. const simpleScenes = ref([...props.scenes]);
  23. const originScenes = ref<Scene[]>([]);
  24. const scenes = computed(() =>
  25. originScenes.value.filter((scene) =>
  26. simpleScenes.value.some(({ sceneCode }) => scene.sceneCode === sceneCode)
  27. )
  28. );
  29. const sceneAlls: Scene[] = [...rScenes.value];
  30. const selectSelects = computed(() => {
  31. return simpleScenes.value.map((sScene) =>
  32. sceneAlls.find((s) => s.sceneCode === sScene.sceneCode)
  33. );
  34. });
  35. const loaded = ref(false);
  36. const tableProps = {
  37. selectionChange(val: Scene[]) {
  38. if (!loaded.value) return;
  39. const originSceneCodes = originScenes.value.map((scene) => scene.sceneCode);
  40. simpleScenes.value = simpleScenes.value.filter(
  41. ({ sceneCode }) => !originSceneCodes.includes(sceneCode)
  42. // || !val.some((scene) => scene.sceneCode === sceneCode)
  43. );
  44. let tip = false;
  45. const count = (val[0] as any)?.shootCount || 0;
  46. val.forEach((scene) => {
  47. if (
  48. selectSelects.value.length &&
  49. selectSelects.value[0].cameraType !== scene.cameraType
  50. ) {
  51. tableProps.tableRef.value!.toggleRowSelection(scene, false);
  52. tip || ElMessage.error({ message: "请添加相同类型的场景", repeatNum: 1 });
  53. tip = true;
  54. } else if (scene.calcStatus !== SceneStatus.SUCCESS) {
  55. tableProps.tableRef.value!.toggleRowSelection(scene, false);
  56. tip || ElMessage.error({ message: "计算中场景无法添加", repeatNum: 1 });
  57. tip = true;
  58. } else if (
  59. selectSelects.value.length &&
  60. selectSelects.value[0].shootCount !== scene.shootCount
  61. ) {
  62. tip ||
  63. ElMessage.error({
  64. message: "请添加相同相机类型且点位数量一致的场景",
  65. repeatNum: 1,
  66. });
  67. tableProps.tableRef.value!.toggleRowSelection(scene, false);
  68. } else {
  69. simpleScenes.value.push({ sceneCode: scene.sceneCode, sceneId: scene.sceneId });
  70. }
  71. });
  72. if (props.selfScenes) {
  73. const foreChecks = props.selfScenes.filter(
  74. ({ sceneCode }) =>
  75. !simpleScenes.value.some((scene) => scene.sceneCode === sceneCode)
  76. );
  77. if (foreChecks.length) {
  78. tip || ElMessage.error({ message: "自动场景无法取消!", repeatNum: 1 });
  79. simpleScenes.value.push(...foreChecks);
  80. originScenes.value.forEach((scene) => {
  81. if (foreChecks.some(({ sceneCode }) => sceneCode === scene.sceneCode)) {
  82. tableProps.tableRef.value!.toggleRowSelection(scene, true);
  83. }
  84. });
  85. }
  86. }
  87. tip = false;
  88. },
  89. tableDataChange(val: Scene[]) {
  90. loaded.value = false;
  91. originScenes.value = val;
  92. sceneAlls.push(...val);
  93. setTimeout(checkedTable);
  94. },
  95. tableRef: ref<InstanceType<typeof ElTable>>(),
  96. };
  97. let time: NodeJS.Timeout;
  98. const checkedTable = () => {
  99. if (tableProps.tableRef.value) {
  100. tableProps.tableRef.value!.clearSelection();
  101. scenes.value.forEach((item) => {
  102. tableProps.tableRef.value!.toggleRowSelection(item, true);
  103. });
  104. }
  105. clearTimeout(time);
  106. time = setTimeout(() => {
  107. loaded.value = true;
  108. }, 100);
  109. };
  110. watch(() => tableProps.tableRef.value, checkedTable);
  111. defineExpose<QuiskExpose>({
  112. async submit() {
  113. if (scenes.value) {
  114. await props.submit(simpleScenes.value);
  115. }
  116. },
  117. });
  118. </script>