10 changed files with 144 additions and 120 deletions
@ -0,0 +1,112 @@ |
|||||||
|
<template> |
||||||
|
<PageWrapper title="useAceEditor高级进阶使用示例" |
||||||
|
contentFullHeight |
||||||
|
fixedHeight |
||||||
|
contentBackground |
||||||
|
> |
||||||
|
<template #extra> |
||||||
|
<div class="mb-4"> |
||||||
|
<div class="mb-4"> |
||||||
|
<a-button class="mr-2" @click="handleFocus"> 获得焦点 </a-button> |
||||||
|
<a-button class="mr-2" @click="handleBlur"> 失去焦点 </a-button> |
||||||
|
<a-button class="mr-2" @click="handleSelectAll"> 全选 </a-button> |
||||||
|
<a-button class="mr-2" @click="handleGetAceInstance"> 获取Ace编辑器实例 </a-button> |
||||||
|
</div> |
||||||
|
<a-space size="middle"> |
||||||
|
语言<a-select v-model:value="state.lang"> |
||||||
|
<a-select-option v-for="(lang, index) of langs" :key="index" :value="lang"> {{ lang }} </a-select-option> |
||||||
|
</a-select> |
||||||
|
主题<a-select v-model:value="state.theme"> |
||||||
|
<a-select-option v-for="(theme, index) of themes" :key="index" :value="theme"> {{ theme }} </a-select-option> |
||||||
|
</a-select> |
||||||
|
</a-space> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
<AceEditor class="vue-ace-editor" |
||||||
|
@register="register" |
||||||
|
@focus="handleEmitFocus" |
||||||
|
@blur="handleEmitBlur" |
||||||
|
/> |
||||||
|
</PageWrapper> |
||||||
|
</template> |
||||||
|
<script setup lang="ts"> |
||||||
|
import { reactive, watch } from 'vue'; |
||||||
|
import { AceEditor, useAceEditor } from '/@/components/AceEditor'; |
||||||
|
import { PageWrapper } from '/@/components/Page'; |
||||||
|
import { useMessage } from '/@/hooks/web/useMessage'; |
||||||
|
|
||||||
|
const { createMessage } = useMessage(); |
||||||
|
const langs = ['json', 'javascript', 'html', 'yaml']; |
||||||
|
const themes = ['chrome', 'github', 'monokai', 'dracula']; |
||||||
|
const state = reactive({ |
||||||
|
lang: 'json', |
||||||
|
theme: 'chrome', |
||||||
|
content: '', |
||||||
|
}); |
||||||
|
|
||||||
|
const [register, { setProps, blur, focus, getAceInstance, selectAll }] = useAceEditor({ |
||||||
|
value: state.content, |
||||||
|
lang: state.lang, |
||||||
|
theme: state.theme, |
||||||
|
options: { |
||||||
|
useWorker: true, |
||||||
|
enableBasicAutocompletion: true, |
||||||
|
enableSnippets: true, |
||||||
|
enableLiveAutocompletion: true, |
||||||
|
}, |
||||||
|
onChange: content => state.content = content |
||||||
|
}); |
||||||
|
|
||||||
|
watch( |
||||||
|
() => state.lang, |
||||||
|
async lang => { |
||||||
|
state.content = ( |
||||||
|
await { |
||||||
|
json: import('../../../../../package.json?raw'), |
||||||
|
javascript: import('/@/components/AceEditor/src/ace-config.js?raw'), |
||||||
|
html: import('../../../../../index.html?raw'), |
||||||
|
yaml: import('../../../../../pnpm-lock.yaml?raw'), |
||||||
|
}[lang] || {}).default!; |
||||||
|
setProps({ value: state.content, lang }); |
||||||
|
}, |
||||||
|
{ immediate: true } |
||||||
|
); |
||||||
|
|
||||||
|
watch(() => state.theme, theme => setProps({ theme })); |
||||||
|
|
||||||
|
function handleEmitFocus() { |
||||||
|
console.log('获取ACE编辑焦点.'); |
||||||
|
} |
||||||
|
|
||||||
|
function handleEmitBlur() { |
||||||
|
console.log('失去ACE编辑焦点.'); |
||||||
|
} |
||||||
|
|
||||||
|
function handleFocus() { |
||||||
|
createMessage.info('请在控制台查看!'); |
||||||
|
focus(); |
||||||
|
} |
||||||
|
|
||||||
|
function handleBlur() { |
||||||
|
createMessage.info('请在控制台查看!'); |
||||||
|
blur(); |
||||||
|
} |
||||||
|
|
||||||
|
function handleSelectAll() { |
||||||
|
selectAll(); |
||||||
|
} |
||||||
|
|
||||||
|
function handleGetAceInstance() { |
||||||
|
createMessage.info('请在控制台查看!'); |
||||||
|
console.log(getAceInstance()); |
||||||
|
} |
||||||
|
|
||||||
|
</script> |
||||||
|
<style lang="less" scoped> |
||||||
|
|
||||||
|
.vue-ace-editor { |
||||||
|
font-size: 12px; |
||||||
|
} |
||||||
|
|
||||||
|
</style> |
||||||
|
|
@ -1,82 +0,0 @@ |
|||||||
<template> |
|
||||||
<PageWrapper title="useAceEditor响应式组件示例" |
|
||||||
contentFullHeight |
|
||||||
fixedHeight |
|
||||||
contentBackground |
|
||||||
> |
|
||||||
<template #extra> |
|
||||||
<a-space size="middle"> |
|
||||||
<a-select v-model:value="state.lang"> |
|
||||||
<a-select-option v-for="(lang, index) of langs" :key="index" :value="lang"> {{ lang }} </a-select-option> |
|
||||||
</a-select> |
|
||||||
<a-select v-model:value="state.theme"> |
|
||||||
<a-select-option v-for="(theme, index) of themes" :key="index" :value="theme"> {{ theme }} </a-select-option> |
|
||||||
</a-select> |
|
||||||
</a-space> |
|
||||||
</template> |
|
||||||
<AceEditor v-model:value="state.content" |
|
||||||
class="vue-ace-editor" |
|
||||||
@register="register" |
|
||||||
/> |
|
||||||
</PageWrapper> |
|
||||||
</template> |
|
||||||
<script setup lang="ts"> |
|
||||||
import { reactive, watch } from 'vue'; |
|
||||||
import { AceEditor, useAceEditor } from '/@/components/AceEditor'; |
|
||||||
import { PageWrapper } from '/@/components/Page'; |
|
||||||
|
|
||||||
const langs = ['json', 'javascript', 'html', 'yaml']; |
|
||||||
const themes = ['chrome', 'github', 'monokai', 'dracula']; |
|
||||||
const state = reactive({ |
|
||||||
lang: 'json', |
|
||||||
theme: 'chrome', |
|
||||||
content: '', |
|
||||||
}); |
|
||||||
|
|
||||||
const [ |
|
||||||
register, |
|
||||||
{ |
|
||||||
setProps, |
|
||||||
blur, |
|
||||||
focus, |
|
||||||
getAceInstance, |
|
||||||
selectAll |
|
||||||
}, |
|
||||||
] = useAceEditor({ |
|
||||||
lang: state.lang, |
|
||||||
theme: state.theme, |
|
||||||
options: { |
|
||||||
useWorker: true, |
|
||||||
enableBasicAutocompletion: true, |
|
||||||
enableSnippets: true, |
|
||||||
enableLiveAutocompletion: true, |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
watch( |
|
||||||
() => state.lang, |
|
||||||
async lang => { |
|
||||||
state.content = ( |
|
||||||
await { |
|
||||||
json: import('../../../../../package.json?raw'), |
|
||||||
javascript: import('/@/components/AceEditor/src/ace-config.js?raw'), |
|
||||||
html: import('../../../../../index.html?raw'), |
|
||||||
yaml: import('../../../../../pnpm-lock.yaml?raw'), |
|
||||||
}[lang] |
|
||||||
|| {}).default!; |
|
||||||
setProps({ lang }); |
|
||||||
}, |
|
||||||
{ immediate: true } |
|
||||||
); |
|
||||||
|
|
||||||
watch(() => state.theme, theme => setProps({ theme })); |
|
||||||
|
|
||||||
</script> |
|
||||||
<style lang="less" scoped> |
|
||||||
|
|
||||||
.vue-ace-editor { |
|
||||||
font-size: 12px; |
|
||||||
} |
|
||||||
|
|
||||||
</style> |
|
||||||
|
|
Loading…
Reference in new issue