Skip to content

Commit

Permalink
fix: 解决伪静态页面光标丢失的问题 (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 authored and wanghe-fit2cloud committed May 21, 2023
1 parent 4fd8756 commit 6b3c06a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions frontend/src/views/website/website/config/basic/rewrite/index.vue
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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"
Expand All @@ -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';
Expand All @@ -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: {
Expand All @@ -69,7 +71,7 @@ const req = reactive({
const update = reactive({
websiteID: id.value,
content: '',
content: 'd',
name: '',
});
Expand All @@ -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;
Expand Down

0 comments on commit 6b3c06a

Please sign in to comment.