RichTextEditor.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="d-flex flex-col">
  3. <Parse v-if="modelValue" :content="modelValue" />
  4. <text v-else>未编写内容,点击编写</text>
  5. <view class="d-flex flex-row align-center gap-s mt-3">
  6. <Button @click="preview">预览内容</Button>
  7. <Button @click="edit" type="primary">编辑内容</Button>
  8. </view>
  9. </view>
  10. </template>
  11. <script setup lang="ts">
  12. import { onPageShow } from '@dcloudio/uni-app';
  13. import { navTo } from '@/components/utils/PageAction';
  14. import Parse from '@/components/display/parse/Parse.vue';
  15. import Button from '@/components/basic/Button.vue';
  16. const props = defineProps({
  17. modelValue: {
  18. type: String,
  19. default: null
  20. },
  21. })
  22. const emit = defineEmits(['update:modelValue'])
  23. let editorOpened = false;
  24. function preview() {
  25. uni.setStorage({
  26. key: 'editorContent',
  27. data: props.modelValue,
  28. success: () => navTo('/pages/editor/preview'),
  29. })
  30. }
  31. function edit() {
  32. editorOpened = true;
  33. uni.setStorage({
  34. key: 'editorContent',
  35. data: props.modelValue,
  36. success: () => navTo('/pages/editor/editor'),
  37. })
  38. }
  39. onPageShow(() => {
  40. if (editorOpened) {
  41. editorOpened = false;
  42. uni.getStorage({
  43. key: 'editorContent',
  44. success: (success) => emit('update:modelValue', success.data),
  45. })
  46. }
  47. })
  48. </script>