1
+ <!--
2
+ * @Author: 秦少卫
3
+ * @Date: 2024-05-17 15:31:24
4
+ * @LastEditors: 秦少卫
5
+ * @LastEditTime: 2024-05-17 15:31:25
6
+ * @Description: file content
7
+ -->
1
8
<!--
2
9
* @Author: 秦少卫
3
10
* @Date: 2023-08-05 17:47:35
4
11
* @LastEditors: 秦少卫
5
- * @LastEditTime: 2024-05-09 15:05:49
12
+ * @LastEditTime: 2024-05-17 15:16:59
6
13
* @Description: file content
7
14
-->
8
15
9
16
<template >
10
17
<div >
11
18
<!-- 搜索组件 -->
12
19
<div class =" search-box" >
13
- <Select
14
- class =" select"
15
- v-model =" materialType"
16
- @on-change =" startGetMaterialList"
17
- :disabled =" loading"
18
- >
19
- <Option key =" 全部" value =" " >全部</Option >
20
- <Option v-for =" item in materialTypeList" :value =" item.value" :key =" item.value" >
20
+ <Select class =" select" v-model =" typeValue" @on-change =" startGetList" :disabled =" pageLoading" >
21
+ <Option v-for =" item in typeList" :value =" item.value" :key =" item.value" >
21
22
{{ item.label }}
22
23
</Option >
23
24
</Select >
24
25
<Input
25
26
class =" input"
26
- :placeholder =" `在${getSearchTypeText() }中搜索`"
27
- v-model =" searchKeyword "
27
+ :placeholder =" `在${typeText }中搜索`"
28
+ v-model =" searchKeyWord "
28
29
search
29
- :disabled =" loading "
30
- @on-search =" startGetMaterialList "
30
+ :disabled =" pageLoading "
31
+ @on-search =" startGetList "
31
32
/>
32
33
</div >
33
-
34
34
<!-- 列表 -->
35
- <div style =" height : calc (100vh - 110 px )" id =" myTemplBox " >
35
+ <div style =" height : calc (100vh - 108 px )" id =" myTemplBox1 " >
36
36
<Scroll
37
- key =" mysscroll "
37
+ key =" mysscroll2 "
38
38
v-if =" showScroll"
39
- :on-reach-bottom =" handleReachBottom "
39
+ :on-reach-bottom =" nextPage "
40
40
:height =" scrollHeight"
41
41
:distance-to-edge =" [-1, -1]"
42
42
>
43
43
<!-- 列表 -->
44
- <div >
45
- <Tooltip
46
- :content =" info.name"
47
- v-for =" info in materialList"
48
- :key =" info.src"
49
- placement =" top"
50
- >
44
+ <div class =" img-group" >
45
+ <Tooltip :content =" info.name" v-for =" info in pageData" :key =" info.src" placement =" top" >
51
46
<div class =" tmpl-img-box" >
52
47
<Image
53
48
lazy
61
56
</div >
62
57
</Tooltip >
63
58
</div >
64
- <Spin size =" large" fix :show =" loading " ></Spin >
59
+ <Spin size =" large" fix :show =" pageLoading " ></Spin >
65
60
66
- <Divider plain v-if =" isDownBottm() " >已经到底了</Divider >
61
+ <Divider plain v-if =" isDownBottm" >已经到底了</Divider >
67
62
</Scroll >
68
63
</div >
69
64
</div >
70
65
</template >
71
66
72
67
<script setup name="ImportSvg">
73
68
import useSelect from ' @/hooks/select' ;
69
+ import usePageList from ' @/hooks/pageList' ;
74
70
import { fabric } from ' fabric' ;
75
71
import { v4 as uuid } from ' uuid' ;
76
72
import { useRoute } from ' vue-router' ;
77
73
import { Utils } from ' @kuaitu/core' ;
78
74
79
- const { canvasEditor } = useSelect ();
80
-
81
- // 素材类型
82
- const materialType = ref (' ' );
83
- materialType .value = ' ' ;
84
- // 素材类型列表
85
- const materialTypeList = ref ([]);
86
- // 素材列表
87
- const materialList = ref ([]);
88
- // 搜索关键字
89
- const searchKeyword = ref (' ' );
90
- // 面板加载
91
- const loading = ref (false );
92
-
93
- // 分页信息
94
- const page = ref (1 );
95
- const pagination = reactive ({
96
- page: 0 ,
97
- pageCount: 0 ,
98
- pageSize: 10 ,
99
- total: 0 ,
75
+ const {
76
+ startPage ,
77
+ typeValue ,
78
+ typeText ,
79
+ typeList ,
80
+ pageLoading ,
81
+ pageData ,
82
+ searchKeyWord ,
83
+ isDownBottm ,
84
+ startGetList ,
85
+ nextPage ,
86
+ showScroll ,
87
+ scrollHeight ,
88
+ } = usePageList ({
89
+ typeUrl: ' material-types' ,
90
+ listUrl: ' materials' ,
91
+ searchTypeKey: ' material_type' ,
92
+ searchWordKey: ' name' ,
93
+ pageSize: 50 ,
94
+ scrollElement: ' #myTemplBox1' ,
100
95
});
101
96
102
- const getSearchTypeText = () => {
103
- const info = materialTypeList .value .find ((item ) => item .value === materialType .value );
104
- const type = info? .label || ' 全部' ;
105
- return type;
106
- };
107
-
108
- const isDownBottm = () => {
109
- return pagination .page === page .value && pagination .page >= pagination .pageCount ;
110
- };
111
-
112
- // 获取素材分类
113
- canvasEditor .getMaterialTypeList ().then ((list ) => {
114
- materialTypeList .value = list;
115
- });
116
-
117
- // 获取素材列表
118
- const getMaterialList = () => {
119
- loading .value = true ;
120
- canvasEditor .getMaterialList (materialType .value , page .value , searchKeyword .value ).then ((res ) => {
121
- const { list , pagination: resPagination } = res;
122
- Object .keys (resPagination).forEach ((key ) => {
123
- pagination[key] = resPagination[key];
124
- });
125
- materialList .value = [... materialList .value , ... list];
126
- loading .value = false ;
127
- });
128
- };
129
-
130
- const startGetMaterialList = () => {
131
- materialList .value = [];
132
- page .value = 1 ;
133
- getMaterialList ();
134
- };
135
-
136
- const handleReachBottom = () => {
137
- if (page .value >= pagination .pageCount ) return ;
138
- page .value ++ ;
139
- setTimeout (() => {
140
- getMaterialList ();
141
- }, 1000 );
142
- };
97
+ const { canvasEditor } = useSelect ();
143
98
144
- // // 按照类型渲染
99
+ // 按照类型渲染
145
100
const dragItem = (e ) => {
146
101
const target = e .target ;
147
102
const imgType = canvasEditor .getImageExtension (target .src );
@@ -198,8 +153,6 @@ const addItem = (e) => {
198
153
}
199
154
};
200
155
201
- const showScroll = ref (false );
202
- const scrollHeight = ref (0 );
203
156
onMounted (async () => {
204
157
// 默认添加图片
205
158
const route = useRoute ();
@@ -209,11 +162,7 @@ onMounted(async () => {
209
162
addItem ({ target: image });
210
163
}
211
164
212
- // 滚动
213
- const myTemplBox = document .querySelector (' #myTemplBox' );
214
- scrollHeight .value = myTemplBox .offsetHeight - 10 ;
215
- showScroll .value = true ;
216
- getMaterialList ();
165
+ startPage ();
217
166
});
218
167
< / script>
219
168
0 commit comments