ny
23 小时以前 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
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
162
163
164
<script lang="ts" setup>
import type { ScrollActionType } from '@jnpf/ui';
 
import { onMounted, reactive, ref, toRefs, watch } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { ScrollContainer, ymCustomJson, ymIconJson } from '@jnpf/ui';
import { BasicForm, useForm } from '@jnpf/ui/form';
 
import { useClipboard } from '@vueuse/core';
import { cloneDeep } from 'lodash-es';
 
defineOptions({ name: 'SysDataIcons' });
 
const ymIcon = ymIconJson.glyphs.map((o) => `icon-ym icon-ym-${o.font_class}`);
const ymCustom = ymCustomJson.glyphs.map((o) => `ym-custom ym-custom-${o.font_class}`);
 
const { createMessage } = useMessage();
const [registerForm, { resetFields }] = useForm({
  baseColProps: { span: 6 },
  showActionButtonGroup: true,
  showAdvancedButton: true,
  compact: true,
  schemas: [
    {
      field: 'keyword',
      label: '关键词',
      component: 'Input',
      componentProps: {
        placeholder: '请输入关键词',
        submitOnPressEnter: true,
      },
    },
  ],
});
const state = reactive({
  activeKey: '1',
  currentPage: 1,
  keyword: '',
  pageSize: 100,
  loading: false,
  finish: false,
  ymIcon,
  ymCustom,
  cacheList: [],
  iconList: [],
});
const { activeKey, iconList } = toRefs(state);
const infiniteBody = ref<Nullable<ScrollActionType>>(null);
 
watch(
  () => state.activeKey,
  () => {
    resetFields();
  },
);
 
function handleSubmit(values) {
  state.keyword = values?.keyword || '';
  handleSearch();
}
function handleReset() {
  state.keyword = '';
  handleSearch();
}
function handleSearch() {
  infiniteBody.value?.scrollTo(0, 0);
  state.currentPage = 1;
  state.finish = false;
  const key: string = state.activeKey === '1' ? 'ymIcon' : 'ymCustom';
  state.iconList = [];
  state.cacheList = state.keyword ? state[key].filter((o) => o.includes(state.keyword)) : cloneDeep(state[key]);
  getList();
}
function getList() {
  state.loading = true;
  setTimeout(() => {
    const res = state.cacheList.slice((state.currentPage - 1) * state.pageSize, state.currentPage * state.pageSize);
    if (res.length < state.pageSize) state.finish = true;
    state.iconList = [...state.iconList, ...res];
    state.loading = false;
  }, 0);
}
function bindScroll() {
  const bodyRef = infiniteBody.value;
  const vBody = bodyRef?.getScrollWrap();
  vBody?.addEventListener('scroll', () => {
    if (vBody.scrollHeight - vBody.clientHeight - vBody.scrollTop <= 200 && !state.loading && !state.finish) {
      state.currentPage += 1;
      getList();
    }
  });
}
function handleCopy(item) {
  const { copy } = useClipboard({ legacy: true });
  copy(item);
  createMessage.success('复制成功');
}
onMounted(() => {
  handleReset();
  bindScroll();
});
</script>
<template>
  <div class="jnpf-content-wrapper icons-wrapper">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-search-box">
        <BasicForm class="search-form" @register="registerForm" @submit="handleSubmit" @reset="handleReset" />
      </div>
      <div class="jnpf-content-wrapper-content flex flex-col bg-white">
        <a-tabs v-model:active-key="activeKey" class="jnpf-content-wrapper-tabs">
          <a-tab-pane key="1" tab="ymIcon图标" />
          <a-tab-pane key="2" tab="更多图标" />
        </a-tabs>
        <div class="flex-1 overflow-hidden">
          <ScrollContainer ref="infiniteBody">
            <a-row>
              <a-col :span="6" v-for="item in iconList" :key="item" @click="handleCopy(item)" :title="item" class="icon-item">
                <i :class="item"></i>
                <span>{{ item }}</span>
              </a-col>
            </a-row>
            <jnpf-empty v-if="iconList.length === 0" />
          </ScrollContainer>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.icons-wrapper {
  .icon-item {
    height: 40px;
    padding: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 38px;
    color: #6b7a99;
    white-space: nowrap;
    cursor: pointer;
    border: 1px dashed transparent;
 
    i {
      margin-right: 14px;
      font-size: 16px;
      line-height: 40px;
      vertical-align: top;
    }
 
    span {
      line-height: 40px;
      vertical-align: top;
    }
 
    &:hover {
      border-color: var(--primary-color);
 
      i {
        font-size: 30px;
      }
    }
  }
}
</style>