Skip to content

Commit 0d31783

Browse files
author
unknown
committed
feat:change cross platforms UI
1 parent d5197a2 commit 0d31783

File tree

5 files changed

+88
-70
lines changed

5 files changed

+88
-70
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@fortawesome/vue-fontawesome": "^3.0.3",
1919
"@pivot-lang/create-monaco": "link:src/hooks/monaco",
2020
"axios": "^1.3.6",
21+
"device-detector-js": "^3.0.3",
2122
"echarts": "^5.4.2",
2223
"prismjs": "^1.29.0",
2324
"vite-plugin-top-level-await": "^1.3.0",

pnpm-lock.yaml

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/crossPlatforms.vue

Lines changed: 51 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<script setup lang="ts">
2-
import { onMounted, reactive, ref, Ref } from 'vue';
2+
import { computed, Fragment, onMounted, reactive, ref, Ref } from 'vue';
33
import codeBlock from './codeBlock.vue';
4+
import { useDetectDeviceType } from '@/hooks/detectDeviceType';
5+
6+
const deviceType = useDetectDeviceType();
47
const currenClickPlatform = ref('');
8+
9+
if (deviceType.value !== 'other') {
10+
currenClickPlatform.value = deviceType.value;
11+
} else {
12+
deviceType.value = 'linux';
13+
}
14+
515
function showCode(type: string) {
6-
if (currenClickPlatform.value === type) currenClickPlatform.value = '';
7-
else currenClickPlatform.value = type;
16+
currenClickPlatform.value = type;
817
}
918
const platforms = [
1019
{
@@ -24,7 +33,7 @@ scoop install plc`,
2433
{
2534
type: 'linux',
2635
icon: 'fa-brands fa-linux',
27-
iconColor: 'rgb(220, 160, 50)',
36+
iconColor: 'rgb(200, 150, 50)',
2837
code: `apt install wget gnupg
2938
wget -O - https://lang.pivotstudio.cn/apt/public.key | apt-key add -
3039
echo "deb [arch=amd64] https://lang.pivotstudio.cn/apt/repo focal main
@@ -35,90 +44,67 @@ apt update
3544
apt install pivot-lang`,
3645
},
3746
];
47+
48+
const curShowCode = computed(() => {
49+
return platforms.find((item) => item.type === currenClickPlatform.value)?.code;
50+
});
3851
</script>
3952
<template>
4053
<div id="advantage">
4154
<div class="gradient-font title">Cross Platforms</div>
55+
<div class="detail-describe">Download Pivot Lang with the command now!</div>
4256
<div class="advantages">
43-
<div v-for="item in platforms" class="advantage-item" :key="item.type">
44-
<Transition>
45-
<codeBlock v-if="currenClickPlatform === item.type" :class="['code-block', item.type]" :code="item.code"></codeBlock>
46-
</Transition>
47-
<Transition>
48-
<font-awesome-icon
49-
@click="showCode(item.type)"
50-
inverse
51-
:icon="item.icon"
52-
:style="{
53-
color: item.iconColor,
54-
opacity: currenClickPlatform === item.type ? 0 : 1,
55-
display: currenClickPlatform === item.type ? 'hidden' : 'block',
56-
zIndex: currenClickPlatform === item.type ? -1 : 1,
57-
}"
58-
size="10x"
59-
class="picture"
60-
/>
61-
</Transition>
57+
<div v-for="item in platforms" :class="{ 'advantage-item': true, 'selected-item': item.type === currenClickPlatform }" :key="item.type">
58+
<font-awesome-icon
59+
@click="showCode(item.type)"
60+
inverse
61+
:icon="item.icon"
62+
:style="{
63+
color: item.iconColor,
64+
}"
65+
size="10x"
66+
class="picture"
67+
/>
6268
</div>
6369
</div>
70+
<codeBlock class="code-block'" :code="curShowCode"></codeBlock>
6471
</div>
6572
</template>
6673
<style lang="scss" scoped>
6774
#advantage {
68-
.text-describe {
69-
.title-text {
70-
color: white;
71-
}
72-
}
7375
.advantages {
7476
display: flex;
7577
flex-wrap: wrap;
7678
justify-content: center;
7779
align-items: center;
7880
.advantage-item {
79-
margin: 40px 0;
80-
position: relative;
81-
}
82-
.text-describe {
83-
text-align: start;
84-
font-size: 1.7vw;
85-
}
86-
.picture {
81+
margin: 10px 5vw;
8782
position: relative;
88-
flex: 0 1 auto;
89-
margin: 0 5vw;
90-
background-color: #eee;
91-
padding: 10px 24px;
92-
border-radius: 50%;
93-
cursor: pointer;
94-
transition: all 0.7s ease;
95-
// height: 30vw;
96-
}
97-
.code-block {
98-
width: calc(220px + 5vw);
99-
max-height: 220px;
100-
transition: all 0.7s ease;
101-
}
102-
@media (max-width: 800px) {
103-
.advantage-item {
104-
margin: 10px 8vw;
105-
.text-describe {
106-
font-size: 4vw;
107-
width: 70%;
108-
}
109-
.picture {
110-
margin: 0 auto 12px;
111-
transform: scale(.9);
112-
}
113-
.code-block {
114-
width: 60vw;
115-
max-height: 220px;
116-
transition: all 0.7s ease;
83+
.picture {
84+
position: relative;
85+
flex: 0 1 auto;
86+
background-color: rgba(255, 255, 255, 0.72);
87+
padding: 10px 26px;
88+
border-radius: 50%;
89+
cursor: pointer;
90+
transition: all 0.7s ease;
91+
margin: 0 auto 12px;
92+
transform: scale(0.9);
93+
&:hover {
94+
background-color: #fff;
11795
}
96+
// height: 30vw;
97+
}
98+
}
99+
100+
.selected-item {
101+
.picture {
102+
background-color: #fff;
118103
}
119104
}
120105
}
121106
}
107+
122108
/* 下面我们会解释这些 class 是做什么的 */
123109
.v-enter-active,
124110
.v-leave-active {

src/hooks/detectDeviceType.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Ref, ref } from 'vue';
2+
import DeviceDetector from 'device-detector-js';
3+
4+
type osType = 'linux' | 'windows' | 'mac' | 'other';
5+
6+
const deviceDetector = new DeviceDetector();
7+
8+
export const useDetectDeviceType = () => {
9+
const deviceType = ref<osType>('other');
10+
const useAgent = navigator.userAgent;
11+
const name = deviceDetector.parse(useAgent).os?.name;
12+
if (name === 'Mac') {
13+
deviceType.value = 'mac';
14+
} else if (name?.includes('Windows')) {
15+
deviceType.value = 'windows';
16+
} else if (name?.includes('Linux') || name?.includes('Debian') || name?.includes('Ubuntu')) {
17+
deviceType.value = 'linux';
18+
}
19+
return deviceType;
20+
};

src/style.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ body {
101101
color: #fff;
102102
}
103103
}
104+
104105
.code-toolbar {
105-
position: absolute !important;
106-
top: 50%;
107-
left: 50%;
108-
transform: translate(-50%, -50%);
106+
margin: 50px auto;
107+
max-width: 720px;
108+
@media (max-width: 800px) {
109+
width: 60vw;
110+
transition: all 0.7s ease;
111+
}
109112
}

0 commit comments

Comments
 (0)