feat: 新增代码编辑器组件

This commit is contained in:
xlsea 2024-04-30 16:32:55 +08:00
parent 22e2c22b43
commit f4d3246d7a
8 changed files with 331 additions and 5 deletions

View File

@ -44,6 +44,9 @@
},
"dependencies": {
"@better-scroll/core": "2.5.1",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/theme-one-dark": "^6.1.2",
"@iconify/vue": "4.1.2",
"@sa/axios": "workspace:*",
"@sa/color-palette": "workspace:*",
@ -61,6 +64,7 @@
"pinia": "2.1.7",
"ts-md5": "1.3.1",
"vue": "3.4.25",
"vue-codemirror6": "^1.3.0",
"vue-draggable-plus": "0.4.0",
"vue-i18n": "9.13.1",
"vue-router": "4.3.2"

View File

@ -11,6 +11,15 @@ importers:
'@better-scroll/core':
specifier: 2.5.1
version: 2.5.1
'@codemirror/lang-javascript':
specifier: ^6.2.2
version: 6.2.2
'@codemirror/lang-json':
specifier: ^6.0.1
version: 6.0.1
'@codemirror/theme-one-dark':
specifier: ^6.1.2
version: 6.1.2
'@iconify/vue':
specifier: 4.1.2
version: 4.1.2(vue@3.4.25(typescript@5.4.5))
@ -62,6 +71,9 @@ importers:
vue:
specifier: 3.4.25
version: 3.4.25(typescript@5.4.5)
vue-codemirror6:
specifier: ^1.3.0
version: 1.3.0(@lezer/common@1.2.1)(vue@3.4.25(typescript@5.4.5))
vue-draggable-plus:
specifier: 0.4.0
version: 0.4.0(@types/sortablejs@1.15.8)
@ -469,6 +481,41 @@ packages:
'@better-scroll/shared-utils@2.5.1':
resolution: {integrity: sha512-AplkfSjXVYP9LZiD6JsKgmgQJ/mG4uuLmBuwLz8W5OsYc7AYTfN8kw6GqZ5OwCGoXkVhBGyd8NeC4xwYItp0aw==}
'@codemirror/autocomplete@6.16.0':
resolution: {integrity: sha512-P/LeCTtZHRTCU4xQsa89vSKWecYv1ZqwzOd5topheGRf+qtacFgBeIMQi3eL8Kt/BUNvxUWkx+5qP2jlGoARrg==}
peerDependencies:
'@codemirror/language': ^6.0.0
'@codemirror/state': ^6.0.0
'@codemirror/view': ^6.0.0
'@lezer/common': ^1.0.0
'@codemirror/commands@6.5.0':
resolution: {integrity: sha512-rK+sj4fCAN/QfcY9BEzYMgp4wwL/q5aj/VfNSoH1RWPF9XS/dUwBkvlL3hpWgEjOqlpdN1uLC9UkjJ4tmyjJYg==}
'@codemirror/lang-javascript@6.2.2':
resolution: {integrity: sha512-VGQfY+FCc285AhWuwjYxQyUQcYurWlxdKYT4bqwr3Twnd5wP5WSeu52t4tvvuWmljT4EmgEgZCqSieokhtY8hg==}
'@codemirror/lang-json@6.0.1':
resolution: {integrity: sha512-+T1flHdgpqDDlJZ2Lkil/rLiRy684WMLc74xUnjJH48GQdfJo/pudlTRreZmKwzP8/tGdKf83wlbAdOCzlJOGQ==}
'@codemirror/language@6.10.1':
resolution: {integrity: sha512-5GrXzrhq6k+gL5fjkAwt90nYDmjlzTIJV8THnxNFtNKWotMIlzzN+CpqxqwXOECnUdOndmSeWntVrVcv5axWRQ==}
'@codemirror/lint@6.6.0':
resolution: {integrity: sha512-RDWLZqvnTlU2k7Xc2QbeySS7hdClfca76BFsdh9iE5OgszlHRenCLLufH8SCO+CCbod0XLaukxs5DesHrxQATQ==}
'@codemirror/search@6.5.6':
resolution: {integrity: sha512-rpMgcsh7o0GuCDUXKPvww+muLA1pDJaFrpq/CCHtpQJYz8xopu4D1hPcKRoDD0YlF8gZaqTNIRa4VRBWyhyy7Q==}
'@codemirror/state@6.4.1':
resolution: {integrity: sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==}
'@codemirror/theme-one-dark@6.1.2':
resolution: {integrity: sha512-F+sH0X16j/qFLMAfbciKTxVOwkdAS336b7AXTKOZhy8BR3eH/RelsnLgLFINrpST63mmN2OuwUt0W2ndUgYwUA==}
'@codemirror/view@6.26.3':
resolution: {integrity: sha512-gmqxkPALZjkgSxIeeweY/wGQXBfwTUaLs8h7OKtSwfbj9Ct3L11lD+u1sS7XHppxFQoMDiMDp07P9f3I2jWOHw==}
'@colors/colors@1.5.0':
resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==}
engines: {node: '>=0.1.90'}
@ -863,6 +910,21 @@ packages:
'@juggle/resize-observer@3.4.0':
resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==}
'@lezer/common@1.2.1':
resolution: {integrity: sha512-yemX0ZD2xS/73llMZIK6KplkjIjf2EvAHcinDi/TfJ9hS25G0388+ClHt6/3but0oOxinTcQHJLDXh6w1crzFQ==}
'@lezer/highlight@1.2.0':
resolution: {integrity: sha512-WrS5Mw51sGrpqjlh3d4/fOwpEV2Hd3YOkp9DBt4k8XZQcoTHZFB7sx030A6OcahF4J1nDQAa3jXlTVVYH50IFA==}
'@lezer/javascript@1.4.15':
resolution: {integrity: sha512-B082ZdjI0vo2AgLqD834GlRTE9gwRX8NzHzKq5uDwEnQ9Dq+A/CEhd3nf68tiNA2f9O+8jS1NeSTUYT9IAqcTw==}
'@lezer/json@1.0.2':
resolution: {integrity: sha512-xHT2P4S5eeCYECyKNPhr4cbEL9tc8w83SPwRC373o9uEdrvGKTZoJVAGxpOsZckMlEh9W23Pc72ew918RWQOBQ==}
'@lezer/lr@1.4.0':
resolution: {integrity: sha512-Wst46p51km8gH0ZUmeNrtpRYmdlRHUpN1DQd3GFAyKANi8WVz8c2jHYTf1CVScFaCjQw1iO3ZZdqGDxQPRErTg==}
'@nodelib/fs.scandir@2.1.5':
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
engines: {node: '>= 8'}
@ -1739,6 +1801,9 @@ packages:
resolution: {integrity: sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==}
engines: {node: '>=0.8'}
codemirror@6.0.1:
resolution: {integrity: sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==}
collection-visit@1.0.0:
resolution: {integrity: sha512-lNkKvzEeMBBjUGHZ+q6z9pSJla0KWAQPvtzhEV9+iGyQYG+pBpl7xKDhxoNSOZH2hhv0v5k0y2yAM4o4SjoSkw==}
engines: {node: '>=0.10.0'}
@ -1829,6 +1894,9 @@ packages:
resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
engines: {node: '>= 0.10'}
crelt@1.0.6:
resolution: {integrity: sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==}
cron-parser@4.9.0:
resolution: {integrity: sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q==}
engines: {node: '>=12.0.0'}
@ -4269,6 +4337,9 @@ packages:
resolution: {integrity: sha512-0fk9zBqO67Nq5M/m45qHCJxylV/DhBlIOVExqgOMiCCrzrhU6tCibRXNqE3jwJLftzE9SNuZtYbpzcO+i9FiKw==}
engines: {node: '>=14.16'}
style-mod@4.1.2:
resolution: {integrity: sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==}
supports-color@2.0.0:
resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}
engines: {node: '>=0.8.0'}
@ -4643,6 +4714,12 @@ packages:
peerDependencies:
vue: ^3.0.0
vue-codemirror6@1.3.0:
resolution: {integrity: sha512-Wq+Ji0wNPF1JYT+ISrWePtJgm0QR0g3s/TwaViPbOHT9/hea1Ik7/bEZN3VCJxJsQksL8IR9T9Hm4tnHGYXiBw==}
engines: {yarn: '>=1.22.19'}
peerDependencies:
vue: ^2.7.14 || ^3.4
vue-demi@0.13.11:
resolution: {integrity: sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==}
engines: {node: '>=12'}
@ -4713,6 +4790,9 @@ packages:
peerDependencies:
vue: ^3.0.11
w3c-keyname@2.2.8:
resolution: {integrity: sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==}
webpack-sources@3.2.3:
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
engines: {node: '>=10.13.0'}
@ -5041,6 +5121,71 @@ snapshots:
'@better-scroll/shared-utils@2.5.1': {}
'@codemirror/autocomplete@6.16.0(@codemirror/language@6.10.1)(@codemirror/state@6.4.1)(@codemirror/view@6.26.3)(@lezer/common@1.2.1)':
dependencies:
'@codemirror/language': 6.10.1
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
'@lezer/common': 1.2.1
'@codemirror/commands@6.5.0':
dependencies:
'@codemirror/language': 6.10.1
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
'@lezer/common': 1.2.1
'@codemirror/lang-javascript@6.2.2':
dependencies:
'@codemirror/autocomplete': 6.16.0(@codemirror/language@6.10.1)(@codemirror/state@6.4.1)(@codemirror/view@6.26.3)(@lezer/common@1.2.1)
'@codemirror/language': 6.10.1
'@codemirror/lint': 6.6.0
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
'@lezer/common': 1.2.1
'@lezer/javascript': 1.4.15
'@codemirror/lang-json@6.0.1':
dependencies:
'@codemirror/language': 6.10.1
'@lezer/json': 1.0.2
'@codemirror/language@6.10.1':
dependencies:
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
'@lezer/common': 1.2.1
'@lezer/highlight': 1.2.0
'@lezer/lr': 1.4.0
style-mod: 4.1.2
'@codemirror/lint@6.6.0':
dependencies:
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
crelt: 1.0.6
'@codemirror/search@6.5.6':
dependencies:
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
crelt: 1.0.6
'@codemirror/state@6.4.1': {}
'@codemirror/theme-one-dark@6.1.2':
dependencies:
'@codemirror/language': 6.10.1
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
'@lezer/highlight': 1.2.0
'@codemirror/view@6.26.3':
dependencies:
'@codemirror/state': 6.4.1
style-mod: 4.1.2
w3c-keyname: 2.2.8
'@colors/colors@1.5.0':
optional: true
@ -5335,6 +5480,28 @@ snapshots:
'@juggle/resize-observer@3.4.0': {}
'@lezer/common@1.2.1': {}
'@lezer/highlight@1.2.0':
dependencies:
'@lezer/common': 1.2.1
'@lezer/javascript@1.4.15':
dependencies:
'@lezer/common': 1.2.1
'@lezer/highlight': 1.2.0
'@lezer/lr': 1.4.0
'@lezer/json@1.0.2':
dependencies:
'@lezer/common': 1.2.1
'@lezer/highlight': 1.2.0
'@lezer/lr': 1.4.0
'@lezer/lr@1.4.0':
dependencies:
'@lezer/common': 1.2.1
'@nodelib/fs.scandir@2.1.5':
dependencies:
'@nodelib/fs.stat': 2.0.5
@ -6400,6 +6567,18 @@ snapshots:
clone@2.1.2: {}
codemirror@6.0.1(@lezer/common@1.2.1):
dependencies:
'@codemirror/autocomplete': 6.16.0(@codemirror/language@6.10.1)(@codemirror/state@6.4.1)(@codemirror/view@6.26.3)(@lezer/common@1.2.1)
'@codemirror/commands': 6.5.0
'@codemirror/language': 6.10.1
'@codemirror/lint': 6.6.0
'@codemirror/search': 6.5.6
'@codemirror/state': 6.4.1
'@codemirror/view': 6.26.3
transitivePeerDependencies:
- '@lezer/common'
collection-visit@1.0.0:
dependencies:
map-visit: 1.0.0
@ -6475,6 +6654,8 @@ snapshots:
object-assign: 4.1.1
vary: 1.1.2
crelt@1.0.6: {}
cron-parser@4.9.0:
dependencies:
luxon: 3.4.4
@ -9261,6 +9442,8 @@ snapshots:
strip-json-comments@5.0.1: {}
style-mod@4.1.2: {}
supports-color@2.0.0: {}
supports-color@3.2.3:
@ -9717,6 +9900,15 @@ snapshots:
evtd: 0.2.4
vue: 3.4.25(typescript@5.4.5)
vue-codemirror6@1.3.0(@lezer/common@1.2.1)(vue@3.4.25(typescript@5.4.5)):
dependencies:
codemirror: 6.0.1(@lezer/common@1.2.1)
vue: 3.4.25(typescript@5.4.5)
vue-demi: 0.14.7(vue@3.4.25(typescript@5.4.5))
transitivePeerDependencies:
- '@lezer/common'
- '@vue/composition-api'
vue-demi@0.13.11(vue@3.4.25(typescript@5.4.5)):
dependencies:
vue: 3.4.25(typescript@5.4.5)
@ -9787,6 +9979,8 @@ snapshots:
vooks: 0.2.12(vue@3.4.25(typescript@5.4.5))
vue: 3.4.25(typescript@5.4.5)
w3c-keyname@2.2.8: {}
webpack-sources@3.2.3: {}
webpack-virtual-modules@0.6.1: {}

View File

@ -0,0 +1,124 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import CodeMirror from 'vue-codemirror6';
import { oneDark } from '@codemirror/theme-one-dark';
import { json } from '@codemirror/lang-json';
import { javascript } from '@codemirror/lang-javascript';
import { useThemeStore } from '@/store/modules/theme';
defineOptions({
name: 'CodeMirror'
});
interface Props {
modelValue: string;
lang?: NaiveUI.CodeMirrorLang;
height?: string;
fontSize?: string;
readonly?: boolean;
disabled?: boolean;
placeholder: string;
}
const props = withDefaults(defineProps<Props>(), {
lang: 'js',
readonly: false,
disabled: false,
height: 'auto',
fontSize: '14px'
});
interface Emits {
(e: 'update:modelValue', modelValue: string): void;
}
const emit = defineEmits<Emits>();
const themeStore = useThemeStore();
const nodeExpression = ref<string>(props.modelValue);
const codeLang = computed(() => {
switch (props.lang) {
case 'json':
return json();
case 'js':
return javascript();
default:
return json();
}
});
const theme = computed(() => {
return {
'&': {
border: `1px solid ${themeStore.darkMode ? '#0000' : 'rgb(224, 224, 230)'}`,
borderRadius: '6px',
fontFamily: 'system-ui',
backgroundColor: 'rgba(255, 255, 255, 0.1)'
},
'.cm-line': {
height: '21px',
fontSize: props.fontSize,
fontFamily: 'system-ui'
},
'.cm-lineNumbers': {
fontFamily: 'system-ui',
marginLeft: '5px',
borderColor: '#0000',
color: 'rgba(255, 255, 255, 0.82)'
},
'.cm-activeLineGutter': {
backgroundColor: themeStore.darkMode ? '#262626' : '#a1a1a1'
},
'.cm-activeLine ': {
backgroundColor: '#0000'
},
'.cm-gutters': {
borderTopLeftRadius: '6px',
borderBottomLeftRadius: '6px',
backgroundColor: themeStore.darkMode ? '#262626' : '#a1a1a1'
},
'.cm-content': {
padding: '5px 5px 5px 0'
},
'.cm-scroller': {
height: props.height,
overflowY: 'auto',
overflowX: 'hidden'
},
'.cm-placeholder': {
color: 'rgba(255, 255, 255, 0.38)'
},
'&.cm-focused': {
outline: 'none',
borderRadius: '6px',
border: '1px solid #3388ff',
boxShadow: '0 0 0 2px rgba(19, 102, 255, 0.2)',
zIndex: '100'
}
};
});
watch(
() => nodeExpression.value,
val => {
emit('update:modelValue', val);
}
);
</script>
<template>
<CodeMirror
v-model="nodeExpression"
class="w-100%"
:readonly="readonly"
:disabled="disabled"
:theme="theme"
:placeholder="placeholder"
basic
:line-number="false"
:lang="codeLang"
:extensions="[oneDark]"
/>
</template>

View File

@ -69,7 +69,7 @@ const onUpdateShow = (value: boolean) => {
<template #header>
{{ props.title }}
<div
v-if="!appStore.isMobile && state.width <= 1920"
v-if="!appStore.isMobile"
quaternary
class="fullscreen text-18px color-#6a6a6a"
@click="isFullscreen = !isFullscreen"

View File

@ -114,14 +114,14 @@ function transformElegantRouteToVueRoute(
}
}
// add redirect to child
if (children?.length && !vueRoute.redirect) {
vueRoute.redirect = {
name: children[0].name
};
}
if (children?.length) {
const childRoutes = children.flatMap(child => transformElegantRouteToVueRoute(child, layouts, views));

View File

@ -44,4 +44,6 @@ declare namespace NaiveUI {
import('@sa/hooks').TableConfig<A, GetTableData<A>, TableColumn<TableDataWithIndex<GetTableData<A>>>>,
'apiFn' | 'apiParams' | 'columns' | 'immediate'
>;
type CodeMirrorLang = 'js' | 'json';
}

View File

@ -9,6 +9,7 @@ import { fetchAddJob, fetchEditJob } from '@/service/api';
import RouteKey from '@/components/common/route-key.vue';
import ExecutorType from '@/components/common/executor-type.vue';
import TaskType from '@/components/common/task-type.vue';
import CodeMirror from '@/components/common/code-mirror.vue';
defineOptions({
name: 'JobTaskOperateDrawer'
@ -284,7 +285,7 @@ watch(visible, () => {
<NInput v-model:value="model.executorInfo" :placeholder="$t('page.jobTask.form.executorInfo')" />
</NFormItem>
<NFormItem :label="$t('page.jobTask.argsStr')" path="argsStr">
<NInput v-model:value="model.argsStr" :placeholder="$t('page.jobTask.form.argsStr')" />
<CodeMirror v-model="model.argsStr" lang="json" :placeholder="$t('page.jobTask.form.argsStr')" />
</NFormItem>
<NFormItem :label="$t('page.jobTask.taskType')" path="taskType">
<TaskType v-model:value="model.taskType" :placeholder="$t('page.jobTask.form.taskType')" />

View File

@ -11,6 +11,7 @@ import {
} from '@/service/api';
import { translateOptions, translateOptions2 } from '@/utils/common';
import { retryTaskStatusTypeOptions } from '@/constants/business';
import CodeMirror from '@/components/common/code-mirror.vue';
defineOptions({
name: 'RetryTaskOperateDrawer'
@ -217,7 +218,7 @@ onMounted(() => {
/>
</NFormItem>
<NFormItem :label="$t('page.retryTask.argsStr')" path="argsStr">
<NInput v-model:value="model.argsStr" type="textarea" :placeholder="$t('page.retryTask.form.argsStr')" />
<CodeMirror v-model="model.argsStr" lang="json" :placeholder="$t('page.jobTask.form.argsStr')" />
</NFormItem>
<NFormItem :label="$t('page.retryTask.retryStatus')" path="retryStatus">
<NSelect