1
1
<script setup lang="ts">
2
2
import { ref , onMounted } from " vue" ;
3
+ import type { DataItem } from " ./StoreList.vue" ;
3
4
import IconVerify from " ./icons/IconVerify.vue" ;
4
5
import IconGithub from " ./icons/IconGithub.vue" ;
5
6
import IconAuthor from " ./icons/IconAuthor.vue" ;
@@ -8,41 +9,42 @@ import IconModule from "./icons/IconModules.vue";
8
9
import IconVersion from " ./icons/IconVersion.vue" ;
9
10
import IconLicense from " ./icons/IconLicense.vue" ;
10
11
import IconCopy from " ./icons/IconCopy.vue" ;
11
- const props = defineProps ([" item" ]);
12
- const version = ref (" 0.0.0" );
13
- const openGithub = (url : string ) => {
14
- window .open (url );
12
+
13
+ const props = defineProps <{ item: DataItem }>();
14
+
15
+ const version = ref (" unknown" );
16
+
17
+ const openHomepageLink = () => {
18
+ window .open (props .item .homepage );
15
19
};
16
- const copyText = () => {
17
- let input = document .createElement (" textarea" );
18
- input .style .cssText =
19
- " position: absolute; top: 0; left: 0; opacity: 0; z-index: -10;" ;
20
- input .value = " pip install " + props .item .pypi_name ;
21
- document .body .appendChild (input );
22
- input .select ();
23
- document .execCommand (" copy" );
24
- document .body .removeChild (input );
20
+
21
+ const copyInstallLink = async () => {
22
+ await navigator .clipboard .writeText (" pip install " + props .item .pypi_name );
25
23
};
24
+
26
25
onMounted (async () => {
27
- const _ = (
26
+ const v = (
28
27
await (
29
28
await fetch (" https://pypi.org/pypi/" + props .item .pypi_name + " /json" )
30
29
).json ()
31
30
)[" info" ][" version" ];
32
- !! _ && (version .value = _ );
31
+ if (!! v ) {
32
+ version .value = v ;
33
+ }
33
34
});
34
35
</script >
36
+
35
37
<template >
36
38
<div class =" card" >
37
39
<div class =" card-top" >
38
40
<div class =" card-head" >
39
41
<div class =" card-title" >
40
- {{ item.name
41
- }} <IconVerify v-if =" item.is_official" style =" margin-left : 0.1rem " />
42
+ {{ item.name }}
43
+ <IconVerify v-if =" item.is_official" style =" margin-left : 0.1rem " />
42
44
</div >
43
45
<div
44
46
class =" card-github"
45
- @click =" openGithub(item.homepage) "
47
+ @click =" openHomepageLink "
46
48
v-if =" !!item.homepage"
47
49
>
48
50
<IconGithub />
@@ -87,31 +89,30 @@ onMounted(async () => {
87
89
</div >
88
90
</div >
89
91
</div >
90
- <div class =" card-button" @click =" copyText() " >
92
+ <div class =" card-button" @click =" copyInstallLink " >
91
93
点击复制安装命令
92
- <div style =" margin-left : 0.3rem " >
93
- <IconCopy />
94
- </div >
94
+ <IconCopy style =" margin-left : 0.3rem " />
95
95
</div >
96
96
</div >
97
97
</template >
98
+
98
99
<style scoped>
99
100
.card {
100
- border : 1px solid var (--card-border );
101
- border-radius : 0.5rem ;
101
+ border : 1px solid var (--vp-c-bg-soft );
102
+ border-radius : 12px ;
103
+ background-color : var (--vp-c-bg-soft );
102
104
padding : 1.5rem ;
103
105
width : 100% ;
104
106
height : 100% ;
105
107
transition : border-color 0.25s ;
106
- cursor : pointer ;
107
108
display : flex ;
108
109
flex-direction : column ;
109
110
justify-content : space-between ;
110
111
max-width : 332px ;
111
112
}
112
113
113
114
.card :hover {
114
- border : 1px solid var (--card-hover );
115
+ border : 1px solid var (--vp-c-bg-elv );
115
116
}
116
117
117
118
.card-head {
@@ -129,15 +130,15 @@ onMounted(async () => {
129
130
130
131
.card-github {
131
132
cursor : pointer ;
132
- fill : var (--card-icon );
133
+ fill : var (--vp-c-neutral );
133
134
}
134
135
135
136
.card-github :hover {
136
- fill : var (--card-hover );
137
+ fill : var (--vp-c-brand-1 );
137
138
}
138
139
139
140
.card-des {
140
- color : var (--card-des );
141
+ color : var (--vp-c-text-2 );
141
142
opacity : 0.7 ;
142
143
font-size : 0.875rem ;
143
144
line-height : 1.25rem ;
@@ -156,7 +157,7 @@ onMounted(async () => {
156
157
.card-tag {
157
158
margin : 0.5rem 0.5rem 0 0 ;
158
159
padding : 0 0.5rem ;
159
- background-color : var (--card-tag );
160
+ background-color : var (--vp-c-default-soft );
160
161
border-radius : 0.1875rem ;
161
162
}
162
163
@@ -179,22 +180,24 @@ onMounted(async () => {
179
180
align-items : center ;
180
181
}
181
182
183
+ .card-icon {
184
+ width : 16px ;
185
+ height : 16px ;
186
+ }
187
+
182
188
.card-button {
183
189
display : flex ;
184
190
justify-content : center ;
185
191
align-items : center ;
186
192
width : 100% ;
187
193
padding : 0.4rem 1rem ;
188
- background-color : var (--card-button );
194
+ background-color : var (--vp-c-default-soft );
189
195
border-radius : 0.5rem ;
190
196
cursor : pointer ;
191
197
}
192
198
193
199
.card-button :hover {
194
- color : var (--card-hover );
195
- }
196
-
197
- .card-button :hover {
198
- fill : var (--card-hover );
200
+ color : var (--vp-c-brand-1 );
201
+ fill : var (--vp-c-brand-1 );
199
202
}
200
203
</style >
0 commit comments