zhengyiming
2025-02-10 958b79ed89b9e742540f714a80261d222c0fc09b
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<template>
  <div class="rich-edit-wrapper">
    <div v-for="(item, index) in props.modelValue" :key="index" class="rich-edit-item-wrapper">
      <div class="rich-edit-item-top">
        <el-tooltip placement="top-start" content="上移">
          <el-button
            :disabled="index == 0"
            class="rich-edit-item-top-button"
            circle
            type="primary"
            icon="Top"
            @click="handleMoveUp(index)"
          ></el-button>
        </el-tooltip>
        <el-tooltip placement="top-start" content="下移">
          <el-button
            :disabled="index == props.modelValue.length - 1"
            class="rich-edit-item-top-button"
            circle
            type="primary"
            icon="Bottom"
            @click="handleMoveDown(index)"
          ></el-button>
        </el-tooltip>
        <el-tooltip placement="top-start" content="删除">
          <el-button
            :disabled="props.modelValue.length <= 1"
            class="rich-edit-item-top-button"
            circle
            type="primary"
            icon="Delete"
            @click="handleDelete(index)"
          ></el-button>
        </el-tooltip>
      </div>
      <div class="rich-edit-item">
        <FieldTextArea
          v-if="item.type === EditorType.Text"
          v-model="item.content"
          placeholder="请输入文本"
          :maxlength="maxLength"
        ></FieldTextArea>
        <ReadAbleImage v-else-if="item.type === EditorType.Image" :src="setOSSLink(item.path)" />
        <video-player
          v-else-if="item.type === EditorType.Video"
          class="video-player-box"
          playsinline
          :options="{
            aspectRatio: '16:9',
            autoplay: false,
            muted: false,
            language: 'en',
            fluid: false,
            poster: '', // 封面地址
            controls: true,
            controlBar: {
              timeDivider: false, // 当前时间和持续时间的分隔符
              durationDisplay: false, // 显示持续时间
              remainingTimeDisplay: false, // 是否显示剩余时间功能
              fullscreenToggle: true, // 是否显示全屏按钮
            },
            sources: [
              {
                type: 'video/mp4', // 类型
                src: setOSSLink(item.path), // url地址
              },
            ],
          }"
          src="/src/assets/boleclound.png"
        />
      </div>
    </div>
 
    <div class="rich-edit-actions">
      <el-button type="primary" icon="Plus" round @click="handleAddTextEditor">添加文本</el-button>
      <BlFileUpload
        accept="jpg/jpeg,png"
        :show-file-list="false"
        :on-success="uploadImageSuccess"
        :showTip="false"
        class="uploader-btn-wrapper"
      >
        <el-button type="primary" icon="Plus" round>添加图片</el-button>
      </BlFileUpload>
      <BlFileUpload
        :accept="'avi,mp4,wmv,mpg,mpg,mov,ram,swf,flv'"
        :show-file-list="false"
        :on-success="uploadVideoSuccess"
        :showTip="false"
        class="uploader-btn-wrapper"
      >
        <el-button type="primary" icon="Plus" round>添加视频</el-button>
      </BlFileUpload>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { FieldTextArea, ReadAbleImage, BlFileUpload } from '@bole-core/components';
import { VideoPlayer } from '@videojs-player/vue';
import { EditorType, EmptyTextEditorItem } from '@/constants';
import { setOSSLink } from '@/utils';
 
defineOptions({
  name: 'RichEdit',
});
 
type Props = {
  modelValue?: API.IntroInfo[];
  maxLength?: number;
};
 
const props = withDefaults(defineProps<Props>(), {
  modelValue: () => [] as API.IntroInfo[],
});
 
function handleMoveUp(index: number) {
  [props.modelValue[index], props.modelValue[index - 1]] = [
    props.modelValue[index - 1],
    props.modelValue[index],
  ];
  props.modelValue.forEach((item, index) => {
    item.sequence = index;
  });
}
 
function handleMoveDown(index: number) {
  [props.modelValue[index + 1], props.modelValue[index]] = [
    props.modelValue[index],
    props.modelValue[index + 1],
  ];
  props.modelValue.forEach((item, index) => {
    item.sequence = index;
  });
}
 
function handleDelete(index: number) {
  // eslint-disable-next-line vue/no-mutating-props
  props.modelValue.splice(index, 1);
}
 
const createLastSequence = () => {
  const lastSequence = props.modelValue[props.modelValue.length - 1]?.sequence ?? 0;
  return lastSequence + 1;
};
 
function handleAddTextEditor() {
  // eslint-disable-next-line vue/no-mutating-props
  props.modelValue.push({
    ...EmptyTextEditorItem,
    sequence: createLastSequence(),
  });
}
 
function uploadImageSuccess(res) {
  console.log('file: ', res);
  // eslint-disable-next-line vue/no-mutating-props
  props.modelValue.push({
    type: EditorType.Image,
    path: res.path,
    sequence: createLastSequence(),
  });
}
 
function uploadVideoSuccess(res) {
  console.log('file: ', res);
  // eslint-disable-next-line vue/no-mutating-props
  props.modelValue.push({
    type: EditorType.Video,
    path: res.path,
    sequence: createLastSequence(),
  });
}
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
 
.rich-edit-wrapper {
  width: 100%;
 
  .rich-edit-item-wrapper {
    margin-bottom: 16px;
 
    .rich-edit-item-top {
      margin-bottom: 6px;
    }
 
    .rich-edit-item-top-button {
      width: 24px;
      height: 24px !important;
      font-size: 12px;
    }
 
    .video-player-box {
      margin-bottom: 14px;
      padding-top: 0 !important;
      width: 400px;
      height: 150px;
    }
  }
 
  .uploader-btn-wrapper {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 10px;
    width: auto !important;
  }
}
</style>