ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
<script lang="ts" setup>
import { computed, reactive, toRefs } from 'vue';
 
import { $t } from '#/locales';
 
interface State {
  popoverVisible: boolean;
  loading: boolean;
  list: any[];
  keyword: string;
}
 
const props = defineProps({
  list: { type: Array, default: () => [] },
});
 
const emit = defineEmits(['confirm']);
 
defineExpose({ closePopover });
 
const columns: any[] = [{ title: '常用语', dataIndex: 'commonWordsText', key: 'commonWordsText', ellipsis: true }];
const state = reactive<State>({
  popoverVisible: false,
  loading: false,
  list: [],
  keyword: '',
});
const { popoverVisible, loading, keyword } = toRefs(state);
 
const getList = computed(() => (state.keyword ? props.list.filter((o: any) => o.commonWordsText.includes(state.keyword)) : props.list));
 
function openPopover() {
  state.keyword = '';
}
function closePopover() {
  state.popoverVisible = false;
}
async function handleSubmit(commonWordsText) {
  emit('confirm', commonWordsText || '');
  state.popoverVisible = false;
}
</script>
<template>
  <a-popover placement="top" trigger="click" overlay-class-name="commonWords-popover" v-model:open="popoverVisible" @open-change="openPopover">
    <a-button type="link" post-icon="icon-ym icon-ym-arrow-down" class="!px-0">{{ $t('common.moreText') }}</a-button>
    <template #content>
      <div class="commonWords-content">
        <a-input-search :placeholder="$t('common.enterKeyword')" allow-clear v-model:value="keyword" />
        <a-table :data-source="getList" :columns="columns" size="small" :pagination="false" :show-header="false" :loading="loading" :scroll="{ y: 220 }">
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'commonWordsText'">
              <span class="cursor-pointer" @click="handleSubmit(record.commonWordsText)">{{ record.commonWordsText }}</span>
            </template>
          </template>
        </a-table>
      </div>
    </template>
  </a-popover>
</template>
<style lang="scss">
.commonWords-popover {
  z-index: 1001 !important;
 
  .ant-popover-inner-content {
    width: 300px;
    padding: 10px;
 
    .commonWords-content {
      display: flex;
      flex-direction: column;
    }
  }
}
</style>