提交 93634f32 编写于 作者: 璃白.'s avatar 璃白. 🌻

feat:添加语言选择

上级 087f696f
......@@ -69,6 +69,7 @@
:can-attach-file="canAttachFile"
v-if="!showPreview && canAttachFile"
/> -->
<tableSelect />
</div>
</template>
<script>
......@@ -76,13 +77,15 @@ import markdownHeader from "./components/header/md-header";
import markdownFooter from "./components/footer/md-footer";
import markdownEditor from "./components/content/md-textarea";
import markdownPreview from "./components/content/md-preview";
import tableSelect from "./components/header/components/table-select";
import { formatText, checktUrl } from "@/assets/js/utils";
export default {
components: {
markdownHeader,
markdownFooter,
markdownEditor,
markdownPreview
markdownPreview,
tableSelect
},
props: {
placeholder: {
......
<template>
<ul>
<li
@click="$emit('select', item)"
v-for="(item, index) in list"
:key="index"
>
{{ item }}
</li>
</ul>
</template>
<script>
export default {
data() {
return {
list: [
"Bash",
"C",
"C++",
"C#",
"CLike",
"CSS",
"Go",
"Html",
"Java",
"JavaScript",
"TypeScript",
"Kotlin",
"Markup",
"Objective-C",
"Peri",
"PHP",
"Shell",
"Python",
"Ruby",
"SQL",
"Swift",
"VB.Net",
"YAML",
"Erlang",
"Scala",
"Clojure",
"Cobol",
"CoffeeScript",
"CommonLisp",
"R",
"XML"
]
};
}
};
</script>
<style lang="less" scoped>
ul {
max-height: 160px;
overflow-y: auto;
margin-top: 2px;
&::-webkit-scrollbar {
display: none;
}
li {
cursor: pointer;
height: 24px;
line-height: 24px;
&:hover {
color: var(--md-editor-border-color-active);
}
}
}
</style>
<template>
<div class="block_container" ref="block_container">
<div
@mousemove.stop="getCursorPoint"
:class="['block', { active: item.active }]"
v-for="(item, index) in list"
:key="index"
></div>
</div>
</template>
<script>
import { throttle as throttleFn } from "@/assets/js/utils";
export default {
data() {
return {
list: new Array(40).fill({
index: 0,
active: false
})
};
},
computed: {},
methods: {
getCursorPoint(e) {
console.log(e.clientX, e.clientY);
const target = e.target;
const { offsetLeft, offsetTop } = target;
if (e.clientX > offsetLeft) {
target.className = "block active";
}
// console.log(offsetLeft, offsetTop);
}
}
};
</script>
<style lang="less" scoped>
@block-size: 16px;
@block-margin: 2px;
.block_container {
width: (@block-size+ @block-margin*2) * 10;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
.block {
cursor: pointer;
width: @block-size;
height: @block-size;
box-sizing: border-box;
margin: @block-margin;
border: 1px solid var(--md-editor-border-color);
&:hover,
&.active {
border: 1px solid var(--md-editor-border-color-active);
}
}
}
</style>
......@@ -6,6 +6,22 @@
>
<span :class="['icon iconfont', `icon-${info.icon}`]"></span>
</div>
<div
v-else-if="info.name === 'code'"
@click="handleTool(info.name, info.startStr, info.endStr)"
v-tip.bottom="codeOptions"
class="tool_button"
>
<span :class="['icon iconfont', `icon-${info.icon}`]"></span>
</div>
<div
v-else-if="info.name === 'table'"
@click="handleTool(info.name, info.startStr, info.endStr)"
v-tip.bottom="tableOptions"
class="tool_button"
>
<span :class="['icon iconfont', `icon-${info.icon}`]"></span>
</div>
<div
v-else
v-tip.bottom="options"
......@@ -17,7 +33,10 @@
</template>
<script>
import { formatText, checkBoswer } from "@/assets/js/utils";
import languageList from "./language-list";
import tableSelect from "./table-select";
export default {
components: { languageList, tableSelect },
props: {
info: {
type: Object,
......@@ -67,12 +86,39 @@ export default {
zIndex: parseInt(this.zIndex) + 1,
theme: this.darkMode ? "dark" : "light"
};
},
codeOptions() {
return {
content: this.info.tip,
customComponent: languageList,
customListeners: {
select: val => {
console.log(val);
const lang = val.toLowerCase().replace(/-/, "");
this.handleTool("code", "\n```" + lang, "\n\n\n```");
}
},
zIndex: parseInt(this.zIndex) + 1,
theme: this.darkMode ? "dark" : "light"
};
},
tableOptions() {
return {
content: this.info.tip,
customComponent: tableSelect,
customListeners: {
select: val => {
console.log(val);
const lang = val.toLowerCase().replace(/-/, "");
this.handleTool("code", "\n```" + lang, "\n\n\n```");
}
},
zIndex: parseInt(this.zIndex) + 1,
theme: this.darkMode ? "dark" : "light"
};
}
},
methods: {
// resetUlNum() {
// this.ulNum = 1;
// },
handleTool(type, startStr, endStr) {
switch (type) {
case "bold":
......
......@@ -41,7 +41,7 @@ import {
getPosition,
removeBlankLine
} from "@/assets/js/utils";
import toolButton from "./tool-button";
import toolButton from "./components/tool-button";
export default {
components: { toolButton },
props: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册