广丰卷烟厂数采质量分析系统
zhuguifei
8 天以前 6990c6f4934e6062b07f1fa9471c2b98d4077729
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<script lang="ts" setup>
import { nextTick, ref, useAttrs, watch } from 'vue';
import type { UmoEditorOptions } from '@umoteam/editor';
import { UmoEditor } from '@umoteam/editor';
import { fetchBatchDeleteOss, fetchUploadFile } from '@/service/api/system/oss';
import { useAppStore } from '@/store/modules/app';
import { useThemeStore } from '@/store/modules/theme';
 
defineOptions({
  name: 'UmoDocEditor'
});
 
const attrs: UmoEditorOptions = useAttrs();
const appStore = useAppStore();
const themeStore = useThemeStore();
const umoEditorRef = ref<InstanceType<typeof UmoEditor>>();
const isSave = ref(false);
 
const value = defineModel<string>('value', { required: true, default: '' });
 
watch(
  value,
  () => {
    nextTick(() => {
      if (isSave.value) {
        isSave.value = false;
        return;
      }
      umoEditorRef.value?.setContent(value.value);
    });
  },
  {
    immediate: true
  }
);
 
watch(
  () => appStore.locale,
  () => {
    umoEditorRef.value?.setLocale(appStore.locale);
  }
);
 
async function handleSave(content: { html: string }) {
  isSave.value = true;
  value.value = content.html;
  return true;
}
 
async function handleFileUpload(file: File) {
  const { error, data } = await fetchUploadFile(file);
  if (error) throw new Error(error.message || '上传失败');
 
  return {
    id: data.ossId,
    url: data.url
  };
}
 
function handleFileDelete(id: CommonType.IdType) {
  window.$dialog?.warning({
    title: '确认删除文件?',
    content: '文件删除后不可恢复,请确认是否删除!',
    positiveText: '确认删除',
    negativeText: '取消',
    onPositiveClick: async () => {
      const { error } = await fetchBatchDeleteOss([id]);
      if (error) throw new Error(error.message || '文件删除失败');
    }
  });
  return true;
}
 
defineExpose({
  saveContent: () => umoEditorRef.value?.saveContent()
});
</script>
 
<template>
  <div class="umo-editor size-full">
    <UmoEditor
      v-bind="attrs"
      ref="umoEditorRef"
      :theme="themeStore.darkMode ? 'dark' : 'light'"
      @save="handleSave"
      @file-upload="handleFileUpload"
      @file-delete="handleFileDelete"
    />
  </div>
</template>
 
<style>
body .flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}
 
.umo-editor .flex-center {
  display: inherit !important;
  align-items: inherit !important;
  justify-content: inherit !important;
}
</style>