Skip to content

Commit

Permalink
feat: 添加代码编辑器示例 (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 authored Dec 24, 2024
1 parent 0dd6665 commit 6d26300
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 30 deletions.
2 changes: 2 additions & 0 deletions build/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const include = [
"vue-tippy",
"cropperjs",
"jsbarcode",
"codemirror",
"pinyin-pro",
"sortablejs",
"swiper/vue",
Expand All @@ -43,6 +44,7 @@ const include = [
"@howdyjs/mouse-menu",
"@logicflow/extension",
"vue-virtual-scroller",
"codemirror-editor-vue3",
"@amap/amap-jsapi-loader",
"el-table-infinite-scroll",
"vue-waterfall-plugin-next",
Expand Down
1 change: 1 addition & 0 deletions locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ menus:
pureLoginLog: Login Log
pureOperationLog: Operation Log
pureSystemLog: System Log
pureCodeMirror: CodeMirror
pureMarkdown: Markdown
pureEditor: Editor
pureAbnormal: Abnormal Page
Expand Down
1 change: 1 addition & 0 deletions locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ menus:
pureLoginLog: 登录日志
pureOperationLog: 操作日志
pureSystemLog: 系统日志
pureCodeMirror: 代码编辑器
pureMarkdown: Markdown
pureEditor: 编辑器
pureAbnormal: 异常页面
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"animate.css": "^4.1.1",
"axios": "^1.7.9",
"china-area-data": "^5.0.1",
"codemirror": "^5",
"codemirror-editor-vue3": "^2.8.0",
"cropperjs": "^1.6.2",
"dayjs": "^1.11.13",
"echarts": "^5.5.1",
Expand Down Expand Up @@ -119,6 +121,7 @@
"@iconify-icons/ri": "^1.2.10",
"@iconify/vue": "^4.2.0",
"@intlify/unplugin-vue-i18n": "^6.0.1",
"@types/codemirror": "^5.60.15",
"@types/dagre": "^0.7.52",
"@types/intro.js": "^5.1.5",
"@types/js-cookie": "^3.0.6",
Expand Down
41 changes: 41 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/layout/components/lay-notice/components/NoticeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function hoverDescription(event, description) {
max-width: 238px;
}
</style>
<style scoped lang="scss">
<style lang="scss" scoped>
.notice-container {
display: flex;
align-items: flex-start;
Expand Down
20 changes: 11 additions & 9 deletions src/router/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ const home = 0, // 平台规定只有 home 路由的 rank 才能为 0 ,所以
monitor = 14,
tabs = 15,
about = 16,
markdown = 17,
editor = 18,
flowchart = 19,
formdesign = 20,
board = 21,
ppt = 22,
mind = 23,
guide = 24,
menuoverflow = 25;
codemirror = 17,
markdown = 18,
editor = 19,
flowchart = 20,
formdesign = 21,
board = 22,
ppt = 23,
mind = 24,
guide = 25,
menuoverflow = 26;

export {
home,
Expand All @@ -45,6 +46,7 @@ export {
monitor,
tabs,
about,
codemirror,
markdown,
editor,
flowchart,
Expand Down
23 changes: 23 additions & 0 deletions src/router/modules/codemirror.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { $t } from "@/plugins/i18n";
import { codemirror } from "@/router/enums";

export default {
path: "/codemirror",
redirect: "/codemirror/index",
meta: {
icon: "ri:code-box-line",
title: $t("menus.pureCodeMirror"),
rank: codemirror
},
children: [
{
path: "/codemirror/index",
name: "CodeMirror",
component: () => import("@/views/codemirror/index.vue"),
meta: {
title: $t("menus.pureCodeMirror"),
extraIcon: "IF-pure-iconfont-new svg"
}
}
]
} satisfies RouteConfigsTable;
2 changes: 1 addition & 1 deletion src/views/able/video-frame/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ onBeforeUnmount(() => {
</el-card>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
::v-deep(.el-upload-dragger) {
display: flex;
align-items: center;
Expand Down
96 changes: 96 additions & 0 deletions src/views/codemirror/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<script setup lang="ts">
import "codemirror/theme/material-darker.css";
import "codemirror/addon/hint/show-hint.css";
import "codemirror/addon/hint/show-hint";
import "codemirror/addon/hint/javascript-hint.js";
import "codemirror/mode/javascript/javascript.js";
import { useDark } from "@pureadmin/utils";
import Codemirror from "codemirror-editor-vue3";
import { ref, reactive, watch, nextTick } from "vue";
import type { Editor, EditorConfiguration } from "codemirror";
const { isDark } = useDark();
const cminstance = ref<Editor | null>(null);
const cmOptions: EditorConfiguration = reactive({
mode: "javascript",
theme: isDark.value ? "material-darker" : "default",
tabSize: 4,
readOnly: false,
autofocus: true,
autoRefresh: true,
lineNumbers: true,
lineWiseCopyCut: true,
gutters: ["CodeMirror-lint-markers"],
lint: true,
extraKeys: {
Ctrl: "autocomplete",
Tab: "autocomplete"
},
hintOptions: {
completeSingle: false
}
});
const code = ref(`function sayHello() {
console.log("Hello, World!");
}
sayHello();`);
const onReady = (cm: Editor) => {
cminstance.value = cm;
cm.on("keypress", () => cm.showHint());
// console.log(cm.getValue());
};
watch(
() => isDark.value,
async newVal => {
await nextTick();
newVal
? cminstance.value.setOption("theme", "material-darker")
: cminstance.value.setOption("theme", "default");
}
);
</script>

<template>
<el-card shadow="never">
<template #header>
<div class="card-header">
<span class="font-medium">
代码编辑器组件,采用开源的
<el-link
href="https://rennzhang.github.io/codemirror-editor-vue3/zh-CN/guide/getting-started"
target="_blank"
style="margin: 0 4px 5px; font-size: 16px"
>
codemirror-editor-vue3
</el-link>
</span>
</div>
<el-link
class="mt-2"
href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/codemirror/index.vue"
target="_blank"
>
代码位置 src/views/codemirror/index.vue
</el-link>
</template>
<Codemirror
v-model:value="code"
width="100%"
height="400px"
:options="cmOptions"
:border="true"
@ready="onReady"
/>
</el-card>
</template>

<style lang="scss" scoped>
.codemirror-container.bordered {
border: 1px solid var(--pure-border-color);
}
</style>
12 changes: 1 addition & 11 deletions src/views/components/json-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ watch(
>
vue-json-pretty
</el-link>
(支持大数据量)。
</span>
<span class="font-medium">
当然还有一款代码编辑器推荐(这里就不做演示了),采用开源的
<el-link
href="https://github.com/surmon-china/vue-codemirror"
target="_blank"
style="margin: 0 4px 5px; font-size: 16px"
>
codemirror6
</el-link>
(支持大数据量)
</span>
</div>
<el-link
Expand Down
2 changes: 1 addition & 1 deletion src/views/components/swiper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const swiperExample: any[] = [
</el-card>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
:deep(.el-card__body) {
padding-top: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/list/card/components/ListCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const cardLogoClass = computed(() => [
</div>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
.list-card-item {
display: flex;
flex-direction: column;
Expand Down
2 changes: 1 addition & 1 deletion src/views/monitor/logs/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const {
</div>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
margin: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/monitor/logs/operation/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const {
</div>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
margin: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/monitor/logs/system/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const {
</div>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
margin: 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/monitor/online/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const {
</div>
</template>

<style scoped lang="scss">
<style lang="scss" scoped>
:deep(.el-dropdown-menu__item i) {
margin: 0;
}
Expand Down
Loading

0 comments on commit 6d26300

Please sign in to comment.