Browse Source

feat: 添加选择追加

DESKTOP-USV654P\pc 1 year ago
parent
commit
364603a42c

+ 8 - 2
apps/web-baicai/src/components/form/components/api-popup.vue

@@ -63,14 +63,20 @@ const handleSelect = () => {
   formQueryApi.open();
 };
 
-const handleSuccess = (data: any) => {
+const handleSuccess = (successData: any) => {
   const { fieldNames } = props;
-  options.value = props.multiple
+  const { data, type } = successData;
+
+  let selected = props.multiple
     ? data.map((item: any) => ({
         label: item[fieldNames.label],
         value: item[fieldNames.value],
       }))
     : [{ label: data[fieldNames.label], value: data[fieldNames.value] }];
+  if (type === 'append') {
+    selected = [unref(options), ...selected];
+  }
+  options.value = [...new Set(selected)] as Record<string, any>[];
 
   const value = unref(options)
     .map((item: any) => item.value)

+ 23 - 1
apps/web-baicai/src/components/form/components/api-popup/api-popup-modal-ignore.vue

@@ -38,7 +38,7 @@ const [Modal, { close, setState, getData }] = useVbenModal({
       }
 
       close();
-      emit('success', selectedData);
+      emit('success', { type: 'update', data: selectedData });
     } finally {
       setState({ confirmLoading: false });
     }
@@ -58,9 +58,31 @@ const [Modal, { close, setState, getData }] = useVbenModal({
 const handelLoadData = () => {
   setState({ loading: false });
 };
+
+const handleAppend = () => {
+  try {
+    setState({ confirmLoading: true });
+
+    const selectedData = tablePageRef.value.getSelectRow();
+    if (isEmpty(selectedData)) {
+      message.warning('请选择数据');
+      return;
+    }
+
+    close();
+    emit('success', { type: 'append', data: selectedData });
+  } finally {
+    setState({ confirmLoading: false });
+  }
+};
 </script>
 <template>
   <Modal class="h-[800px] w-[1000px]">
     <TablePage ref="tablePageRef" v-bind="state" @success="handelLoadData" />
+    <template #prepend-footer>
+      <Button v-if="state.multiple" type="link" @click="handleAppend">
+        追加
+      </Button>
+    </template>
   </Modal>
 </template>