Skip to content

Commit 5350f8c

Browse files
authored
Merge pull request #4189 from zc422/feat-ide-master-0128
feat: 脚本编辑器升级Monaco #4085
2 parents 230613d + f77d588 commit 5350f8c

23 files changed

Lines changed: 1757 additions & 101 deletions

File tree

src/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"@blueking/ai-blueking": "0.2.11",
1919
"@blueking/bk-user-display-name": "1.0.1",
2020
"@blueking/bk-user-selector": "0.0.29-beta.8",
21-
"@blueking/date-picker": "3.0.4",
2221
"@blueking/crypto-js-sdk": "0.0.5",
22+
"@blueking/date-picker": "3.0.4",
2323
"@blueking/ip-selector": "1.0.1-beta.26",
2424
"@blueking/login-modal": "1.0.6",
2525
"@blueking/notice-component-vue2": "2.0.6-beta.5",
@@ -49,6 +49,7 @@
4949
"marked": "5.1.1",
5050
"marked-gfm-heading-id": "3.1.3",
5151
"marked-mangle": "1.1.10",
52+
"monaco-editor": "0.30.1",
5253
"path-browserify": "1.0.1",
5354
"tippy.js": "6.3.7",
5455
"vue": "2.7.8",
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<template>
2+
<div
3+
class="monaco-editor-ai-tool"
4+
:class="{'is-active': isActive}"
5+
@click="handleShow"
6+
@mouseenter="handleShow">
7+
<span ref="referRef">
8+
<img
9+
:src="aiImage"
10+
style="width: 16px">
11+
</span>
12+
<div
13+
ref="popoverContentRef"
14+
class="monaco-editor-ai-tool-menu">
15+
<div
16+
class="item"
17+
@click="handleCheckScript">
18+
{{ $t('脚本检查') }}
19+
</div>
20+
<div
21+
class="item"
22+
@click="handleChat">
23+
{{ $t('其它') }}
24+
</div>
25+
</div>
26+
<div
27+
v-if="showAi"
28+
class="tool-tips">
29+
<div class="wrapper">
30+
<img
31+
:src="bluekingImage"
32+
style="width: 36px">
33+
<span class="ml-8">{{ $t('AI 脚本检查已上线!') }}</span>
34+
</div>
35+
</div>
36+
</div>
37+
</template>
38+
<script setup>
39+
import Tippy from 'bk-magic-vue/lib/utils/tippy';
40+
import { onBeforeUnmount, onMounted, ref } from 'vue';
41+
42+
import eventBus from '@/utils/event-bus';
43+
44+
const emits = defineEmits(['checkScript']);
45+
46+
const editorAiHelperCacheKey = 'editor_ai_helper';
47+
const aiImage = window.__loadAssetsUrl__('/static/images/ai.png');
48+
const bluekingImage = window.__loadAssetsUrl__('/static/images/blueking.png');
49+
50+
const referRef = ref();
51+
const popoverContentRef = ref();
52+
53+
const isActive = ref(false);
54+
const showAi = ref(!localStorage.getItem(editorAiHelperCacheKey));
55+
56+
let instance;
57+
const handleShow = () => {
58+
instance && instance.show();
59+
};
60+
61+
const handleCheckScript = () => {
62+
emits('checkScript');
63+
localStorage.setItem(editorAiHelperCacheKey, true);
64+
showAi.value = false;
65+
};
66+
67+
const handleChat = () => {
68+
eventBus.$emit('ai:generaChat');
69+
localStorage.setItem(editorAiHelperCacheKey, true);
70+
showAi.value = false;
71+
};
72+
73+
onMounted(() => {
74+
instance = Tippy(referRef.value, {
75+
theme: 'dark monaco-editor-ai-tool',
76+
interactive: true,
77+
placement: 'bottom-start',
78+
content: popoverContentRef.value,
79+
trigger: 'manual',
80+
arrow: false,
81+
onShown() {
82+
isActive.value = true;
83+
},
84+
onHidden() {
85+
isActive.value = false;
86+
},
87+
});
88+
89+
onBeforeUnmount(() => {
90+
instance.hide();
91+
instance.destroy();
92+
});
93+
});
94+
</script>
95+
<style lang="postcss">
96+
@keyframes ai-tool-tips {
97+
0% {
98+
opacity: 0%;
99+
transform: translateY(-30px) scale(.8);
100+
}
101+
102+
30%{
103+
opacity: 100%;
104+
}
105+
106+
45%{
107+
transform: translateY(0) scale(1);
108+
}
109+
110+
75% {
111+
transform: translateY(-12px) scale(.92);
112+
}
113+
114+
100%{
115+
opacity: 100%;
116+
transform: translateY(0);
117+
}
118+
}
119+
120+
.monaco-editor-ai-tool {
121+
position: relative;
122+
display: flex;
123+
width: 24px;
124+
height: 24px;
125+
border-radius: 2px;
126+
align-items: center;
127+
justify-content: center;
128+
129+
&.is-active,
130+
&:hover{
131+
background: #4D4D4D;
132+
}
133+
134+
.tool-tips{
135+
position: absolute;
136+
top: -44px;
137+
left: -145px;
138+
padding: 0 6px;
139+
font-size: 12px;
140+
color: #63656E;
141+
white-space: nowrap;
142+
background: #fff;
143+
border-radius: 18px;
144+
opacity: 0%;
145+
box-shadow: 0 2px 6px 0 #0000001f;
146+
animation: 1.5s ai-tool-tips .5s ease-in-out forwards;
147+
transform-origin: right bottom;
148+
149+
.wrapper{
150+
position: relative;
151+
z-index: 1;
152+
display: flex;
153+
background: inherit;
154+
border-radius: inherit;
155+
align-items: center;
156+
justify-content: center;
157+
}
158+
159+
&::after{
160+
position: absolute;
161+
bottom: 3px;
162+
left: 133px;
163+
border: 0 solid transparent;
164+
border-bottom: 10px solid #fff;
165+
border-right-width: 16px;
166+
border-left-width: 16px;
167+
content: '';
168+
transform: rotateZ(45deg);
169+
box-shadow: 0 2px 6px 0 #0000001f;
170+
}
171+
}
172+
}
173+
174+
.monaco-editor-ai-tool-theme{
175+
width: 80px;
176+
padding: 8px 0;
177+
border: 1px solid #3D3D3D;
178+
179+
.item{
180+
display: flex;
181+
height: 32px;
182+
padding: 0 10px;
183+
font-size: 12px;
184+
color: #DCDEE5;
185+
cursor: pointer;
186+
align-items: center;
187+
188+
&:hover{
189+
background: #474747;
190+
}
191+
}
192+
}
193+
</style>

0 commit comments

Comments
 (0)