yyg1378265336
2025-02-26 61900b1f71f4c9048cbc48ed6f4b41ccfa1a6ce4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
  <div>
    <a-transfer
      v-model:target-keys="oritargetKeys"
      :data-source="dataSource"
      :disabled="disabled"
      :show-search="true"
      :filter-option="(inputValue, item) => item.title.indexOf(inputValue) !== -1 || item.description.indexOf(inputValue) !==-1"
      :show-select-all="false"
      :titles="Titles"
      @change="onChange"
    >
      <template
        #children="{
          direction,
          filteredItems,
          selectedKeys,
          disabled: listDisabled,
          onItemSelectAll,
          onItemSelect,
        }"
      >
        <a-table
          :row-selection="
            getRowSelection({
              disabled: listDisabled,
              selectedKeys,
              onItemSelectAll,
              onItemSelect,
            })
          "
          :columns="direction === 'left' ? LeftColumns : RightColumns"
          :data-source="filteredItems"
          size="small"
          :style="{ pointerEvents: listDisabled ? 'none' : null }"
          :custom-row="
            ({ key, disabled: itemDisabled }) => ({
              onClick: () => {
                if (itemDisabled || listDisabled) return;
                onItemSelect(key, !selectedKeys.includes(key));
              },
            })
          "
        />
      </template>
    </a-transfer>
    <!-- <a-switch
      v-model:checked="disabled"
      un-checked-children="disabled"
      checked-children="disabled"
      style="margin-top: 16px"
    />
    <a-switch
      v-model:checked="showSearch"
      un-checked-children="showSearch"
      checked-children="showSearch"
      style="margin-top: 16px"
    /> -->
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref, watch, toRef } from 'vue';
  // import { useVmodel } from '/@/components/Transfer/src/hooks/useVmodel';
  import { Transfer, Table, notification } from 'ant-design-vue';
  import { TransferData, TableColumns } from '/@/components/Transfer/src/types/transfer';
 
  export default defineComponent({
    components: {
      ATransfer: Transfer,
      ATable: Table,
      // ASwitch: Switch,
    },
    props: {
      targetKeys: {
        type: Array as PropType<string[]>,
        default: () => [],
      },
      dataSource: {
        type: Array as PropType<TransferData[]>,
        default: () => [],
      },
      leftColumns: {
        type: Array as PropType<TableColumns[]>,
        default: () => [],
      },
      rightColumns: {
        type: Array as PropType<TableColumns[]>,
        default: () => [],
      },
      titles: {
        type: Array as PropType<string[]>,
        default: () => [],
      },
    },
    emits: ['changeKeys'],
    setup(props, { emit }) {
      // const DataSource = toRef(props, 'dataSource');
      // const oritargetKeys = useVmodel(props, 'targetKeys', emit);
      const oritargetKeys = toRef(props, 'targetKeys');
      // const targetKeys = ref<string[]>(props.targetKeys);
      //const disabled = ref<boolean>(false);
      //const showSearch = ref<boolean>(false);
      const LeftColumns = toRef(props, 'leftColumns');
      const RightColumns = toRef(props, 'rightColumns');
      const Titles = toRef(props, 'titles');
 
      // watch(
      //   () => targetKeys.value,
      //   (newProps) => {
      //     console.log(newProps); //查看新值
      //     emit('update:targetKeys', newProps);
      //   },
      //   {
      //     immediate: true,
      //     deep: true,
      //   },
      // );
      /** 穿梭更改 */
      const onChange = (nextTargetKeys: string[]) => {
        console.log('nextTargetKeys', nextTargetKeys);
        // notification['success']({
        //   message: 'Notification Title',
        //   description: 'This is the content: ' + nextTargetKeys,
        // });
        emit('changeKeys', nextTargetKeys);
      };
 
      const getRowSelection = ({
        disabled,
        selectedKeys,
        onItemSelectAll,
        onItemSelect,
      }: Record<string, any>) => {
        return {
          getCheckboxProps: (item: Record<string, string | boolean>) => ({
            disabled: disabled || item.disabled,
          }),
          onSelectAll(selected: boolean, selectedRows: Record<string, string | boolean>[]) {
            const treeSelectedKeys = selectedRows
              .filter((item) => !item.disabled)
              .map(({ key }) => key);
            onItemSelectAll(treeSelectedKeys, selected);
          },
          onSelect({ key }: Record<string, string>, selected: boolean) {
            onItemSelect(key, selected);
          },
          selectedRowKeys: selectedKeys,
        };
      };
      return {
        // DataSource,
        oritargetKeys,
        LeftColumns,
        RightColumns,
        Titles,
        onChange,
        getRowSelection,
      };
    },
  });
</script>