FriendCircleContent.vue
6.59 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<script>
export default {
name: '',
components: {},
props: {
data: {
type: Object,
default: () => ({}),
},
},
data() {
return {
welcomeMsgError: '',
limit: [1440, 1080],
form: {},
}
},
computed: {},
watch: {
data: {
handler(val) {
this.form = val
},
immediate: true,
},
},
created() {},
mounted() {},
methods: {
onInsertMaterial(e) {
this.form.contentType = e
this.form.otherContent.push({
annexType: e,
annexUrl: '',
contentError: '',
})
},
onRemoveMaterial(index) {
this.form.otherContent.splice(index, 1)
if (!this.form.otherContent.length) {
this.form.contentType = ''
}
},
validateMaterial() {
let goto = true
this.form.otherContent.forEach((dd) => {
if (!dd.annexUrl) {
dd.contentError = '内容不能为空'
goto = false
} else if (dd.annexType == 'link' && !dd.other) {
dd.otherError = '封面图片不能为空'
} else {
dd.contentError = ''
dd.otherError = ''
}
})
return goto
},
validate() {
if (!this.form.content) {
this.welcomeMsgError = '请输入动态内容'
return
} else {
this.welcomeMsgError = ''
}
let goto = this.validateMaterial()
if (goto) {
this.form.otherContent.forEach((dd) => {
delete dd.contentError
delete dd.otherError
if (dd.annexType === 'link') {
let reUrl = /(http|https):\/\/([\w.]+\/?)\S*/
if (!reUrl.test(dd.annexUrl)) {
goto = false
dd.contentError = '必须以 http://或 https://开头'
}
if (!dd.other) {
goto = false
dd.otherError = '请上传封面图片'
}
}
})
this.$forceUpdate()
if (!this.form.otherContent.length) {
this.form.contentType = 'text'
}
}
if (goto) {
this.$emit('update:data', this.form)
return true
} else {
return false
}
},
},
}
</script>
<template>
<el-form label-width="110px" label-position="right">
<div class="g-card">
<el-form-item label="动态内容" required style="width: 50%; margin-bottom: 0" :error="welcomeMsgError">
<el-input
ref="msgTextarea"
type="textarea"
v-model="form.content"
maxlength="2000"
show-word-limit
placeholder="请输入"
:autosize="{ minRows: 5, maxRows: 20 }"
clearable />
</el-form-item>
</div>
<!-- 附件 -->
<div class="g-card" v-for="(item, index) in form.otherContent" :key="index">
<!-- 图片上传 -->
<div class="my-cord" v-if="item.annexType == 'image'">
<div class="operation">
<div class="algin" @click="onRemoveMaterial(index)">
<i class="el-icon-delete mr5"></i>
删除
</div>
</div>
<el-form-item label="图片上传" required :error="item.contentError">
<upload :maxImgPx="limit" class="image-uploader" :fileUrl.sync="item.annexUrl" type="0"></upload>
</el-form-item>
</div>
<!-- 图文 -->
<div class="my-cord" v-else-if="item.annexType == 'link'">
<div class="operation">
<div class="algin" @click="onRemoveMaterial(index)">
<i class="el-icon-delete mr5"></i>
删除
</div>
</div>
<el-form-item label="图文链接" style="width: 50%" required :error="item.contentError">
<el-input v-model="item.annexUrl" placeholder="请输入图文链接"></el-input>
<div class="sub-des">仅支持公众号图文链接,且必须以 http://或 https://开头</div>
</el-form-item>
<el-form-item label="封面图片" style="width: 50%" required :error="item.otherError">
<upload class="image-uploader" :fileUrl.sync="item.other" type="0"></upload>
</el-form-item>
</div>
<div class="my-cord" v-else-if="item.annexType == 'video'">
<div class="operation">
<div class="algin" @click="onRemoveMaterial(index)">
<i class="el-icon-delete mr5"></i>
删除
</div>
</div>
<el-form-item label="视频上传" required :error="item.contentError">
<upload class="image-uploader" :fileUrl.sync="item.annexUrl" type="2"></upload>
</el-form-item>
</div>
</div>
<!-- 添加附件 -->
<div
class="g-card add-continue"
v-show="form.otherContent.length <= 8 && form.contentType !== 'video' && form.contentType !== 'link'">
<el-dropdown style="margin-left: 10px" @command="onInsertMaterial">
<div style="display: flex; align-items: center">
<i class="el-icon-circle-plus-outline mr5"></i>
继续添加附件
</div>
<el-dropdown-menu slot="dropdown" trigger="click">
<!-- <el-dropdown-item :command="4">
<el-button type="text">文字</el-button>
</el-dropdown-item> -->
<el-dropdown-item v-if="form.contentType === 'image' || form.otherContent.length === 0" :command="'image'">
<el-button type="text">图片</el-button>
</el-dropdown-item>
<el-dropdown-item v-if="form.otherContent.length === 0" :command="'video'">
<el-button type="text">视频</el-button>
</el-dropdown-item>
<el-dropdown-item v-if="form.otherContent.length === 0" :command="'link'">
<el-button type="text">网页</el-button>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-form>
</template>
<style lang="scss" scoped>
::v-deep .image-uploader {
.uploader-icon {
width: 120px;
height: 114px;
line-height: 114px;
}
.upload-img {
width: 100px;
height: 94px;
}
}
.sub-des {
font-size: 12px;
font-weight: 400;
color: #999999;
}
.add-continue {
cursor: pointer;
font-size: 14px;
font-weight: 400;
color: var(--color);
display: flex;
align-items: center;
justify-content: center;
&:hover {
opacity: 0.8;
}
}
.my-cord {
position: relative;
.operation {
z-index: 100;
cursor: pointer;
position: absolute;
top: 0;
right: 0;
font-size: 12px;
font-weight: 400;
color: #1785ff;
display: flex;
align-items: center;
.algin {
margin-left: 20px;
display: flex;
align-items: center;
}
&:hover {
opacity: 0.8;
}
}
}
</style>