Skip to content

Commit

Permalink
✨ feat(codemirror): 新增codemirror #3
Browse files Browse the repository at this point in the history
✨ feat(codemirror): 新增codemirror #3
  • Loading branch information
wosiwq authored Dec 25, 2023
2 parents be58e8a + df15046 commit f323808
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 10 deletions.
176 changes: 175 additions & 1 deletion package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
"format": "prettier --write src/"
},
"dependencies": {
"@codemirror/lang-json": "^6.0.1",
"@codemirror/theme-one-dark": "^6.1.2",
"axios": "^1.6.2",
"codemirror": "^6.0.1",
"element-plus": "^2.4.3",
"qrcode.vue": "^3.4.1",
"vue": "^3.3.10"
"vue": "^3.3.10",
"vue-codemirror": "^6.1.1"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.3.3",
Expand Down
64 changes: 56 additions & 8 deletions src/views/BaseView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 items-start h-full">
<div class="p-2 bg-white rounded-lg shadow">
<h2 class="text-lg font-bold mb-2 mt-2">配置文件</h2>
<ElInput
class="mt-2"
@change="handleFormattedBilichatChange"
<Codemirror
v-if="formattedBilichat"
@blur="handleFormattedBilichatChange"
v-model="formattedBilichat"
:rows="20"
type="textarea"
placeholder="等待读取数据中"></ElInput>
placeholder="等待配置文件载入"
:extensions="getExtensions()"
:autofocus="true"
:indent-with-tab="true"
:tab-size="2"
:phrases="chinesePhrases"
style="max-height: 600px"></Codemirror>
<ElButton class="mt-2 mb-2" @click="saveChange">保存修改</ElButton>
</div>

Expand Down Expand Up @@ -228,8 +232,11 @@ import type {
PlatformOption,
Qrcode
} from '@/types'
import { json } from '@codemirror/lang-json'
import { oneDark } from '@codemirror/theme-one-dark'
import axios from 'axios'
import QrcodeVue from 'qrcode.vue'
import { Codemirror } from 'vue-codemirror'
import { version } from '../../package.json'
const isManageCookieDialogVisible = ref(false)
Expand All @@ -249,6 +256,43 @@ const authInfo = ref<AuthInfo[]>()
const platformOption = ref<PlatformOption[]>()
const chinesePhrases = {
// @codemirror/view
'Control character': '控制字符',
// @codemirror/commands
'Selection deleted': '选定删除',
// @codemirror/language
'Folded lines': '折叠块',
'Unfolded lines': '展开快',
to: '',
'folded code': '折叠代码',
unfold: '展开',
'Fold line': '折叠',
'Unfold line': '展开',
// @codemirror/search
'Go to line': '转到行',
go: '',
Find: '查找',
Replace: '替换为',
next: '下一个',
previous: '前一个',
all: '全部',
'match case': '区分大小写',
'by word': '全词匹配',
replace: '替换',
'replace all': '全部替换',
close: '关闭',
'current match': '当前匹配',
'replaced $ matches': '替换了 $ 个匹配',
'replaced match on line $': '在第 $ 行替换匹配',
'on line': '在行',
// @codemirror/autocomplete
Completions: '补全',
// @codemirror/lint
Diagnostics: '诊断',
'No diagnostics': '无诊断'
}
watch(
() => bilichat.value,
(newVal) => {
Expand Down Expand Up @@ -288,9 +332,9 @@ onMounted(() => {
})
})
const handleFormattedBilichatChange = (val: string) => {
const handleFormattedBilichatChange = () => {
try {
bilichat.value = JSON.parse(val) as BiliChat
bilichat.value = JSON.parse(formattedBilichat.value as string) as BiliChat
} catch (e) {
ElMessage.error('JSON格式错误')
formattedBilichat.value = JSON.stringify(bilichat.value, null, 2)
Expand Down Expand Up @@ -445,5 +489,9 @@ const coverDataToLocalString = (ts: number) => {
second: '2-digit'
})
}
const getExtensions = () => {
return [json(), oneDark]
}
</script>
<style scoped lang="scss"></style>

0 comments on commit f323808

Please sign in to comment.