-
Notifications
You must be signed in to change notification settings - Fork 65
/
DataList.vue
145 lines (134 loc) · 3.25 KB
/
DataList.vue
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
<template>
<div ref="scrollContainer" class="list-container">
<template v-for="(item, i) in props.items" :key="i">
<v-card
class="mx-1 my-1 py-1 card"
:href="panUrls[i]"
target="_blank"
append-icon="mdi-open-in-new"
>
<template #title>
<span v-html="item.raw.highlight"></span>
</template>
<v-card-actions>
<v-snackbar :timeout="2000">
<template #activator="{ props }">
<v-btn
v-bind="props"
class="ml-2"
prepend-icon="mdi-code-block-brackets"
@click.prevent
@click.stop="copy(item.raw.extract_code)"
>提取码</v-btn
>
</template>
<template #actions>
<v-icon
:icon="item.raw.extract_code ? 'mdi-check' : 'mdi-bell-outline'"
></v-icon>
</template>
{{ item.raw.extract_code ? "复制成功" : "无需提取码" }}
</v-snackbar>
<v-snackbar :timeout="2000">
<template #activator="{ props }">
<v-btn
v-bind="props"
prepend-icon="mdi-link-box-variant-outline"
@click.prevent
@click.stop="copy(item.raw.pan_url)"
>复制链接</v-btn
>
</template>
<template #actions>
<v-icon icon="mdi-check"></v-icon>
</template>
复制成功
</v-snackbar>
</v-card-actions>
<template #subtitle>
<v-chip
size="x-small"
:color="item.raw.extract_code ? 'warning' : 'primary'"
label
>
{{ item.raw.extract_code ? "需提取码" : "无提取码" }}
</v-chip>
</template>
</v-card>
</template>
<v-pagination
class="mt-12 mb-6"
v-model="page"
:length="paginationLength"
:total-visible="4"
></v-pagination>
<v-snackbar ref="snackbarRef"></v-snackbar>
</div>
</template>
<script lang="ts" setup>
import { copyText } from "../utils/copyText";
interface IResultItem {
raw: {
title: string;
pan_url: string;
extract_code: string;
highlight: string;
};
}
interface IProps {
items: IResultItem[];
page: number;
total: number;
}
// TODO 还可以增加一个历史浏览的功能,并在列表展示时增加tag,在菜单里面增加历史浏览的选项
const props = withDefaults(defineProps<IProps>(), {
items: () => [],
page: 1,
total: 0,
});
const panUrls = computed(() => {
return props.items.map((item) => "//" + item.raw.pan_url);
});
interface IEmits {
(e: "pageChange", page: number): void;
}
const emit = defineEmits<IEmits>();
const page = ref(props.page); // 如果父组件传入了这个属性,则用其初始化page
watch(page, (newPage) => {
emit("pageChange", newPage);
scrollToTop();
});
const paginationLength = computed(() => {
return Math.ceil(props.total / 10);
});
const snackbarRef = ref();
function copy(text: string) {
copyText(text);
snackbarRef.value.show({
message: "复制成功",
timeout: 3000, // 设置显示时间
color: "success", // 设置颜色
});
}
const scrollContainer = ref();
function scrollToTop() {
scrollContainer.value.scrollTo({
top: 0,
// behavior: "smooth",
});
}
</script>
<style lang="scss" scoped>
.list-container {
height: calc(100vh - 160px);
overflow-y: scroll;
}
.list-container::-webkit-scrollbar {
display: none;
}
</style>
<style>
.highlight {
background-color: rgba(var(--v-theme-primary), 0.2);
}
</style>