index.vue
10.2 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
<template>
<el-drawer
:title="form.id ? '编辑产品词条' : '新增产品词条'"
size="50%"
:before-close="cancelForm"
:visible.sync="dialogVisible"
direction="rtl"
custom-class="drawer-panel"
ref="drawer"
>
<div class="drawer__content">
<div class="tips-box">
<div class="tips-title">
<i class="el-icon-warning-outline"></i>功能提示
</div>
<ul>
<li>每个轻改、权益产品仅可配置单一词条。</li>
<li>该词条将用于展业助手APP上的营销话术方案的展示。</li>
<li>驻点人员可提前了解该产品在实际营销中的常见问题及合理答复。</li>
</ul>
</div>
<el-form :model="form" :rules="rules" ref="ruleForm">
<el-form-item
label="产品名称"
:label-width="formLabelWidth"
prop="headings"
>
<el-input
maxlength="20"
v-model="form.headings"
autocomplete="off"
></el-input>
</el-form-item>
<el-form-item
label="产品配套话术"
:label-width="formLabelWidth"
prop="content"
>
<el-input
type="textarea"
maxlength="5000"
v-model="form.content"
class="input-box"
autocomplete="off"
></el-input>
<div class="insert-btn" @click="insertTxtAndSetcursor('##')">
#高亮文本#
</div>
</el-form-item>
<el-form-item label-width="120px" label="录音附件:" prop="imageList">
<div v-if="form.audio">
<div class="audio-name">
<audio :key="audioKey" controls>
<source :src="form.audio" type="audio/mpeg" />
</audio>
<el-button size="small" type="text" class="import-button">
重新上传
<input
type="file"
ref="fileUpload"
class="import-input"
accept=".mp3,.aac,.m4a"
@change="importFile($event)"
/>
</el-button>
</div>
</div>
<el-button size="small" class="import-button" v-else>
<i class="el-icon-plus"></i>
上传文件
<input
type="file"
ref="fileUpload"
class="import-input"
accept=".mp3,.aac,.m4a"
@change="importFile($event)"
/>
</el-button>
<p class="photo-top-tips">支持mp3,大小不超过200M</p>
</el-form-item>
<!-- <el-form-item label-width="120px" label="录音附件:" prop="imageList">
<div v-if="form.audio">
<div class="audio-name">{{ form.audio | format }}</div>
<div class="audio-btn">重新上传</div>
</div>
<el-button size="small" class="import-button" v-else>
<i class="el-icon-plus"></i>
上传文件
<input
type="file"
ref="fileUpload"
multiple
class="import-input"
accept=".mp3,.aac,.m4a"
@change="importFile($event)"
/>
</el-button>
<p class="photo-top-tips">支持mp3,大小不超过200M</p>
</el-form-item> -->
<el-form-item label-width="120px" label="内容:">
<glsx-preview
:pic-options="picOptions"
@beforeUpload="beforeUpload"
@afterUpload="afterUpload"
:image-url-arr="form.pictureList"
limit="9"
></glsx-preview>
<p
class="photo-top-tips"
v-if="form.pictureList && form.pictureList.length"
>
图片按照以上排序进行展示,可拖动调整排序
</p>
<p class="photo-top-tips" v-else>
推荐尺寸:1173*768,单个文件不超过10M,最多上传9张
</p>
</el-form-item>
</el-form>
<div class="drawer__footer">
<el-button @click="cancelForm">取 消</el-button>
<el-button type="primary" @click="handleSave">确 定</el-button>
</div>
</div>
</el-drawer>
</template>
<script>
import preview from "../preview"
import uploadPdf from "../uploadPdf"
import * as productApi from "@api/contentManager"
import { getAliOSSToken } from "@api/serviceManage"
import OSS from "ali-oss"
export default {
name: "AddDrawer",
components: {
glsxPreview: preview,
uploadPdf
},
props: {
dialogVisible: {
type: Boolean,
default: false
},
form: {
type: Object,
default: () => {}
}
},
mounted() {
this.init()
setTimeout(() => {
console.log(this.form)
if (!this.form.pictureList) {
this.form.pictureList = []
}
}, 1000)
},
data() {
return {
audioKey: new Date().getTime(),
title: "",
isFocs: false,
picOptions: {
width: "88px",
height: "88px",
isClose: true,
limitSize: 10,
type: "img",
isDrag: true
},
formLabelWidth: "120px",
rules: {
headings: [{ required: true, message: "请产品名称", trigger: "blur" }],
content: [
{ required: true, message: "产品配套话术", trigger: "change" }
]
}
}
},
filters: {
format(val) {
return val.split("/").pop()
}
},
methods: {
async init() {
try {
const res = await getAliOSSToken()
if (res)
this.client = new OSS({
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,yourRegion填写为oss-cn-hangzhou。
region: "oss-cn-shenzhen",
// 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
accessKeyId: res.lsaccessKeyId,
accessKeySecret: res.lsaccessKeySecret,
stsToken: res.securityToken, // 从STS服务获取的安全令牌(SecurityToken)。
// 填写Bucket名称。
bucket: "glsk-oss",
secure: true
})
else this.$message.error("获取阿里云配置失败!")
} catch (error) {}
},
// 输入文本
insertTxtAndSetcursor(text) {
let element = document.querySelector(".input-box textarea") // 获取到指定标签
let startPos = element.selectionStart // 获取光标开始的位置
let endPos = element.selectionEnd // 获取光标结束的位置
let oldTxt = element.value // 获取输入框的文本内容
let result =
oldTxt.substring(0, startPos) + text + oldTxt.substring(endPos) // 将文本插入
console.log(result)
this.form.content = result // 将拼接好的文本设置为输入框的值
element.focus() // 重新聚焦输入框
setTimeout(() => {
const range = startPos + 1
element.selectionStart = range // 设置光标开始的位置
element.selectionEnd = range // 设置光标结束的位置
})
},
async importFile(event) {
try {
if (!this.client) {
this.$refs.fileUpload.value = ""
this.init()
return this.$message.error("请重试!")
}
const data = event.srcElement.files
for (let i = 0; i < data.length; i++) {
await this.putObject(data[i])
}
this.loading = true
this.loading = false
} catch (error) {
this.loading = false
}
},
async putObject(data) {
let date = "",
[originalString] = data.name.split("."),
[_day, _time] = originalString.split("_")
if (_day && _time) {
const rex = /^\d+$/
let year = originalString.slice(0, 4),
month = originalString.slice(4, 6),
day = originalString.slice(6, 8),
time = originalString.slice(9, 13)
if (
rex.test(year) &&
rex.test(month) &&
rex.test(day) &&
rex.test(time)
)
date = `${year}-${month}-${day} ${time.slice(0, 2)}:${time.slice(2)}`
}
try {
const result = await this.client.put(`quality/${data.name}`, data)
this.form.audio = result.url
this.audioKey = new Date().getTime()
} catch (error) {
console.log(error)
this.init()
this.$message.error("上传失败")
}
},
beforeUpload() {
this.uploading = true
},
afterUpload() {
this.uploading = false
},
handleSave() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
this.confirmAdd()
}
})
},
confirmAdd() {
console.log(this.form)
let api = "productSave"
if (this.form.id) {
api = "productUpdate"
}
productApi[api](this.form).then((res) => {
if (res) {
this.cancelForm()
}
})
},
cancelForm() {
this.$emit("close")
}
}
}
</script>
<style scoped lang="scss">
::v-deep .el-drawer__header {
border-bottom: 1px solid #e5e5e5;
margin-bottom: 0px;
padding-bottom: 20px;
color: #333333;
}
.drawer__content {
padding: 20px;
.tips-box {
height: 124px;
border-radius: 4px;
opacity: 1;
background: #fafafa;
padding: 14px 24px;
box-sizing: border-box;
margin-bottom: 20px;
.tips-title {
color: #333333;
font-size: 14px;
i {
margin-right: 6px;
}
}
ul {
padding-left: 20px;
li {
color: #999999;
line-height: 22px;
font-size: 12px;
}
}
}
.el-form {
height: calc(100vh - 300px);
overflow: auto;
}
}
.drawer__footer {
text-align: right;
}
.insert-btn {
width: 79px;
height: 21px;
border-radius: 4px;
opacity: 1;
background: #185efe1a;
color: #185efe;
font-size: 12px;
line-height: 21px;
text-align: center;
margin-top: 10px;
}
.import-button {
position: relative;
.import-input {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
}
.audio-name {
display: flex;
audio {
height: 36px;
}
.import-button {
margin-left: 20px;
}
}
.photo-top-tips {
color: #999999;
}
</style>