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