welcomeWords.vue
14.5 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<template>
<div class="welcome-box">
<!-- <div class="required">入群欢迎语</div> -->
<div class="content">
<div class="content-bg">
<el-input type="textarea" :rows="9" maxlength="600" show-word-limit v-model="text" @input="textInput" placeholder="请输入内容"></el-input>
<div v-for="(itm, index) in previewList" :key="itm.id">
<div class="welcome-file" v-if="itm.attType != 1">
<template v-if="itm.attType == 2">
<img src="@/assets/img/guestCustom/icon-img.png" alt="" />
<span>{{ itm.attContent }}</span>
</template>
<template v-else-if="itm.attType == 3">
<img src="@/assets/img/guestCustom/icon-img.png" alt="" />
<span>{{ itm.attContent }}</span>
</template>
<template v-else-if="itm.attType == 4">
<img src="@/assets/img/guestCustom/icon-link.png" alt="" />
<span>{{ itm.attContent.url }}</span>
</template>
<template v-else-if="itm.attType == 5">
<img src="@/assets/img/guestCustom/icon-applet.png" alt="" />
<span>{{ itm.attContent.title }}</span>
</template>
<i class="el-icon-circle-close" @click="close(index)"></i>
</div>
</div>
<div class="btn-group">
<div class="add-btn" v-for="item in btnList" :key="item.id">
<i class="el-icon-circle-plus-outline"></i>
<span>{{ item.name }}</span>
<!-- <div id="video"></div> -->
<input v-if="item.type == 'img'" type="file" style="opacity: 0" :id="item.name + 'file'" ref="file" class="welcome-input" :accept="item.accept || 'image/png, image/jpeg, image/jpg'" @change="e => handleImgChange(e, item)" />
<input v-if="item.type == 'video'" type="file" style="opacity: 0" :id="item.name + 'file'" ref="file" class="welcome-input" :accept="item.accept || 'video/*'" @change="e => handleVideoChange(e, item)" />
<el-link v-if="item.type == 'popup'" style="opacity: 0" @click="switchDailog(item.funName)">{{ item.name }}</el-link>
</div>
</div>
</div>
<div class="tips-text">
<img src="@/assets/img/guestCustom/tips.png" class="tips-icon" alt="" />
<span>如在企业微信管理后台已为所选员工设置了欢迎语,则此处设置的将不生效。</span>
</div>
</div>
<basic-dialog :title="dialogTitle" :width="'712px'" :isVisible="dialogVisible" @confirmDialog="handleConfirm" @closeDialog="closeDialog">
<slot>
<el-form v-if="dialogTitle == '添加网页消息'" :model="linkForm" :rules="linkRules" ref="linkForm" label-width="120px">
<el-form-item label="网页标题" prop="title">
<el-input v-model="linkForm.title" placeholder="请输入网页标题"></el-input>
</el-form-item>
<el-form-item label="添加网页链接" prop="url">
<el-input v-model="linkForm.url" placeholder="以http或https开头"></el-input>
</el-form-item>
</el-form>
<el-form v-else-if="dialogTitle == '添加小程序'" :model="appletForm" :rules="appletRules" ref="appletForm" label-width="120px">
<el-form-item label="小程序标题" prop="title">
<el-input v-model="appletForm.title" placeholder="请输入小程序标题"></el-input>
</el-form-item>
<el-form-item label="小程序appID" prop="appid">
<el-input v-model="appletForm.appid" placeholder="请输入小程序appID"></el-input>
</el-form-item>
<el-form-item label="小程序路径" prop="page">
<el-input v-model="appletForm.page" placeholder="请输入小程序路径"></el-input>
<div class="form-tips">注意:小程序路径以html作为后缀</div>
</el-form-item>
<el-form-item label="小程序封面" prop="picUrl">
<div class="upload">
<div v-show="!appletForm.picUrl" class="upload-bg">
<i class="el-icon-circle-plus"></i>
<div class="upload-text">上传封面</div>
</div>
<input type="file" style="opacity: 0" ref="file" class="form-upload img-w-h" accept="image/png, image/jpeg, image/gif, image/jpg" @change="handleImg" />
<el-image v-show="appletForm.picUrl" style="width: 140px" :src="appletForm.picUrl" fit="contain"></el-image>
</div>
<div class="form-tips">建议图片大小在2M以内,建议尺寸:352*282px</div>
</el-form-item>
</el-form>
</slot>
</basic-dialog>
</div>
</template>
<script>
import basicDialog from '@/components/basic-dialog'
const ATT_TYPE = {
TEXT: 1,
IMAGE: 2,
VEDIO: 3,
URL: 4,
MINIPROGRAM: 5,
FILE: 6
}
export default {
name: 'WelcomeWords',
components: { basicDialog},
props: { eventBus: Object },
data() {
return {
btnList: [
{
id: 1,
name: '图片',
funcName: '',
type: 'img',
limitSize: 10
},
{
id: 2,
name: '视频',
funcName: '',
type: 'video',
limitSize: 10
},
{
id: 3,
name: '链接',
type: 'popup',
funName: 'link'
},
{
id: 4,
name: '小程序',
type: 'popup',
funName: 'applet'
}
],
guestForm: {},
text: '',
dialogTitle: '',
dialogVisible: false,
linkForm: {},
linkRules: {
title: [{ required: true, message: '请输入网页标题', trigger: 'blur' }],
url: [{ required: true, message: '请输入网页链接', trigger: 'blur' }]
},
appletForm: {},
appletRules: {
title: [{ required: true, message: '请输入小程序标题', trigger: 'blur' }],
appid: [{ required: true, message: '请输入小程序appID', trigger: 'blur' }],
page: [{ required: true, message: '请输入小程序路径', trigger: 'blur' }],
picUrl: [{ required: true, message: '请上传封面路径', trigger: 'change' }]
},
previewList: []
}
},
mounted() {
console.log(this.previewList)
this.eventBus.$emit('update', this.previewList)
// this.updateList(this.previewList)
// obj.init('video')
},
methods: {
handleImgChange(e, targetItem) {
console.log(e, targetItem)
var reader = new FileReader()
var file = e.srcElement.files[0]
console.log(file)
// 默认1MB
const limitSize = targetItem.limitSize || 1
const isLt = file.size / 1024 / 1024 < limitSize
if (!isLt) {
this.$message.error('上传图片大小不能超过' + limitSize + 'MB!')
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
var image = new Image()
image.src = e.target.result
image.onload = () => {
console.log(file, targetItem)
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
console.log(res)
this.previewList.push({
attType: ATT_TYPE.IMAGE,
attContent: res
})
}
})
}
}
},
handleVideoChange(e, targetItem) {
var file = e.srcElement.files[0]
var reader = new FileReader()
// 默认1MB
const limitSize = targetItem.limitSize || 1
const isLt = file.size / 1024 / 1024 < limitSize
if (!isLt) {
this.$message.error('上传视频大小不能超过' + limitSize + 'MB!')
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
console.log(res)
this.previewList.push({
attType: ATT_TYPE.VEDIO,
attContent: res
})
}
})
}
},
handleImg(e) {
var reader = new FileReader()
var file = e.srcElement.files[0]
console.log(file)
// 默认1MB
const limitSize = 10
const isLt = file.size / 1024 / 1024 < limitSize
if (!isLt) {
this.$message.error('上传图片大小不能超过' + limitSize + 'MB!')
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
var image = new Image()
image.src = e.target.result
image.onload = () => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
this.$set(this.appletForm, 'picUrl', 'dfasdfasfa')
this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
console.log(res)
this.$set(this.appletForm, 'picUrl', res)
}
})
}
}
},
switchDailog(funName) {
console.log(funName)
if (funName == 'link') {
this.dialogTitle = '添加网页消息'
} else if (funName == 'applet') {
this.dialogTitle = '添加小程序'
}
this.dialogVisible = !this.dialogVisible
},
handleConfirm() {
const { dialogTitle } = this
switch (dialogTitle) {
case '添加网页消息':
this.$refs.linkForm.validate(valid => {
if (valid) {
console.log(this.linkForm)
this.previewList.push({
attType: ATT_TYPE.URL,
attContent: this.linkForm
})
this.closeDialog('linkForm')
// this.dialogVisible = !this.dialogVisible
// this.linkForm = {}
// this.$refs.linkForm.clearValidate()
} else {
console.log('error submit!!')
return false
}
})
break
case '添加小程序':
console.log(this.appletForm)
this.$refs.appletForm.validate(valid => {
if (valid) {
console.log(this.appletForm)
this.previewList.push({
attType: ATT_TYPE.MINIPROGRAM,
attContent: this.appletForm
})
this.closeDialog('appletForm')
// this.dialogVisible = !this.dialogVisible
// this.appletForm = {}
// this.$refs.appletForm.clearValidate()
} else {
console.log('error submit!!')
return false
}
})
break
default:
console.log(dialogTitle)
}
},
close(index) {
console.log(index)
// this.previewList
this.previewList.splice(index, 1)
this.eventBus.$emit('update', this.previewList)
},
textInput(val) {
console.log(val)
const hasText = this.previewList.some(item => item.attType == 1)
console.log(hasText)
if (hasText) {
this.$set(this.previewList, 0, {
attContent: val,
attType: ATT_TYPE.TEXT
})
} else {
this.previewList.unshift({
attContent: val,
attType: ATT_TYPE.TEXT
})
}
console.log(this.previewList)
},
closeDialog() {
if (this.dialogVisible) {
if (this.$refs.linkForm) this.$refs.linkForm.clearValidate()
this.linkForm = {}
if (this.$refs.appletForm) this.$refs.appletForm.clearValidate()
this.appletForm = {}
}
this.dialogVisible = !this.dialogVisible
},
updateList(val) {
this.previewList = val
this.eventBus.$emit('update', this.previewList)
const obj = val.find(item => item.attType == 1)
if (obj) {
this.text = obj.attContent
} else {
this.text = ''
}
}
}
}
</script>
<style lang="scss" scoped>
.welcome-box {
// padding-top: 20px;
// margin-left: 87px;
}
.content {
display: inline-block;
vertical-align: text-top;
width: calc(100% - 103px);
// margin-left: 12px;
.content-bg {
background-color: #f7f7f7;
}
.welcome-file {
display: flex;
align-items: center;
color: #999;
padding: 10px;
margin-bottom: 10px;
border-left: 1px solid #dcdfe6;
border-right: 1px solid #dcdfe6;
img {
width: 20px;
height: 20px;
margin-right: 5px;
}
span {
display: inline-block;
margin-right: 20px;
max-width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 14px;
}
i {
font-size: 16px;
}
&:last-child {
margin-bottom: 0;
}
}
.btn-group {
padding: 6px 0 6px 20px;
border: 1px solid #dcdfe6;
border-top: 0;
.add-btn {
display: inline-flex;
position: relative;
align-items: center;
padding-right: 25px;
font-size: 16px;
color: #666;
cursor: pointer;
span {
font-size: 14px;
margin-left: 5px;
}
input {
position: absolute;
width: 100%;
cursor: pointer;
}
.el-link {
position: absolute;
width: 100%;
}
}
}
}
.required {
display: inline-block;
line-height: 40px;
}
.required::before {
content: '*';
color: #f56c6c;
margin-right: 4 px;
}
.form-tips {
font-size: 12px;
color: #999;
}
.form-upload {
position: absolute;
top: 0;
width: 140px;
// width: 100%;
height: 100%;
cursor: pointer;
z-index: 1;
}
/deep/ {
.el-textarea__inner {
background-color: #f7f7f7;
border-radius: 0;
}
.el-textarea__inner:focus {
border-color: #dcdfe6;
}
.el-textarea .el-input__count {
background-color: #f7f7f7;
}
}
.upload {
position: relative;
}
.upload-bg {
position: relative;
width: 140px;
height: 140px;
background-color: #f7f7f7;
color: #999;
border: 1px dashed #dcdfe6;
i {
position: absolute;
top: 40px;
left: 50%;
transform: translateX(-50%);
font-size: 30px;
}
.upload-text {
position: absolute;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
font-size: 12px;
}
}
.tips-text {
display: flex;
align-items: center;
justify-self: center;
color: #000;
font-size: 14px;
padding: 13px 16px;
margin-top: 10px;
background-color: rgba(230, 233, 255, 0.49);
border: 1px solid rgba(88, 80, 255, 0.49);
border-radius: 4px;
.tips-icon {
width: 14px;
height: 14px;
margin-right: 8px;
}
}
</style>