fix: 解决伪静态页面光标丢失的问题 (#1086)

pull/1087/head
zhengkunwang223 2023-05-19 15:53:10 +08:00 committed by GitHub
parent d851aeed45
commit 57aa2aba74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 6 deletions

View File

@ -1,5 +1,5 @@
<template>
<div v-loading="loading">
<div>
<el-form-item :label="$t('website.rewriteMode')">
<el-select v-model="req.name" filterable @change="getRewriteConfig(req.name)">
<el-option :label="$t('website.current')" :value="'current'"></el-option>
@ -11,8 +11,9 @@
></el-option>
</el-select>
</el-form-item>
<codemirror
<Codemirror
ref="codeRef"
v-loading="loading"
:autofocus="true"
placeholder=""
:indent-with-tab="true"
@ -37,7 +38,7 @@
</template>
<script lang="ts" setup>
import { computed, onMounted, reactive, ref } from 'vue';
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
import { Codemirror } from 'vue-codemirror';
import { oneDark } from '@codemirror/theme-one-dark';
import { StreamLanguage } from '@codemirror/language';
@ -48,8 +49,9 @@ import { MsgSuccess } from '@/utils/message';
import i18n from '@/lang';
const loading = ref(false);
const content = ref('');
const content = ref(' ');
const extensions = [StreamLanguage.define(nginx), oneDark];
const codeRef = ref();
const props = defineProps({
id: {
@ -69,7 +71,7 @@ const req = reactive({
const update = reactive({
websiteID: id.value,
content: '',
content: 'd',
name: '',
});
@ -80,12 +82,24 @@ const getRewriteConfig = async (rewrite: string) => {
try {
const res = await GetRewriteConfig(req);
content.value = res.data.content;
if (res.data.content == '') {
content.value = ' ';
}
setCursorPosition();
} catch (error) {
} finally {
loading.value = false;
}
};
const setCursorPosition = () => {
nextTick(() => {
const codeMirrorInstance = codeRef.value?.codemirror;
codeMirrorInstance?.setCursor(0, 0);
});
};
const submit = async () => {
update.name = req.name;
update.websiteID = id.value;