ai-story-zip,课件模板打包

服务端 Koa

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
/**
* 奥点云直播录制功能调整
*/
const router = require('koa-router')();
const _ = require('lodash');
const axios = require('axios');
const moment = require('moment');
const { URL } = require('url')
const path = require('path');

const request = require('request')
const JSZip = require('jszip')
const newZip = new JSZip()

const api = require('./api');

let picbookJson = {}
let picbookJsonStr = ''

// 拉取Story项目模板
function getTemplate() {
return new Promise((resolve, reject) => {
request({
method: 'GET',
encoding: null,
uri: 'http://public.yitong.com/demo/story-template/story.zip?_t=' + new Date().getTime()
}, function (err, response, body) {
if (err) {
return reject(err)
}
resolve(body)
})
})
}

// 拉取临时文件列表
function getFile(json) {
const arr = []
json.resourceList.forEach((item, index) => {
arr.push(new Promise((resolve, reject) => {
request({
method: 'GET',
encoding: null,
uri: item.replace('https://', 'http://')
}, function (err, response, body) {
if (err) {
return reject(err)
}
const arr = item.split('/') || []
const fName = arr.length > 0 ? arr[arr.length - 1] : index
picbookJsonStr = picbookJsonStr.replace(item, fName)
console.log(fName, item)
resolve({
name: fName,
body
})
})
}))
})
return Promise.all(arr)
}

// stream 转 buffer
function streamToBuffer(stream) {
return new Promise((resolve, reject) => {
const buffers = []
stream.on('error', reject)
stream.on('data', data => buffers.push(data))
stream.on('end', () => resolve(Buffer.concat(buffers)))
})
}

// buffer 转 stream
// let Duplex = require('stream').Duplex

// function bufferToStream(buffer) {
// let stream = new Duplex();
// stream.push(buffer);
// stream.push(null);
// return stream;
// }


router.post('/gw/ai/zip', async (ctx) => {
console.log(ctx.request.body)
picbookJson = ctx.request.body
picbookJsonStr = JSON.stringify(picbookJson)
// 配置远端镜像路径
picbookJson.baseUrl = ''
const body = await getTemplate()
if (!body) {
ctx.body = api.error({
code: 9,
message: '出错啦',
result: null
})
return
}
// 写入资源文件
const zip = await newZip.loadAsync(body)
// 仅支持一级相对路径,例如 'resource/'
const resourceFile = zip.folder(picbookJson.prefix.replace('/', ''))
const resourceObject = await getFile(picbookJson)
resourceObject.forEach((item) => {
resourceFile.file(item.name, item.body, { base64: true })
})
// 写入配置文件
console.log('-----------', picbookJsonStr)
picbookJson = JSON.parse(picbookJsonStr)
zip.file('config.json', JSON.stringify({
version: 1,
packageDate: new Date().getTime(),
picbook: picbookJson
}))
// https://stuk.github.io/jszip/documentation/howto/write_zip.html
const stream = zip.generateNodeStream({
type: 'nodebuffer', // 压缩类型选择nodebuffer,在回调函数中会返回zip压缩包的Buffer的值
// 压缩算法
compression: "DEFLATE",
compressionOptions: {
level: 9
},
streamFiles: true
})
// res.head('Content-Type', 'application/octet-stream')
// res.header('Content-Type', 'text/plain')
// res.write(await streamToBuffer(stream), 'utf8')
// res.end()
ctx.set('Content-Type', 'application/octet-stream');
ctx.body = await streamToBuffer(stream)
})

/**
* 查询课程录播文件
*/
router.post('/gw/aodianyun/getCourseData1', async (ctx) => {
let { courseId } = ctx.request.body;
const LiveLookback = Parse.Object.extend("LiveLookback");
const search = new Parse.Query(LiveLookback);
//search.equalTo("status", 'success');
search.limit(2);
const results = await search.find();
let response = {
list: results
};
ctx.body = api.ok(response);
});

module.exports = router;

服务端(Nuxt servermiddleware - Express)

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
// 在具体页面中检测接口是否就绪
// const { result } = await this.$axios.$post('http://localhost:3000/api/ready')
// console.log('localhost:8000/api', result)
const JSZip = require('jszip')
const request = require('request')
const configJson = {
baseUrl: 'https://public.yitong.com/demo/story/picbook/',
name: 'Sharing (Story)',
coverImageUrl: '1573803206931407.jpg',
coverAudioUrl: '170f173622a46ff.mp3',
wordCount: 16,
pageContents: [
{
imageUrl: 'this_is_a_simple_example.jpg',
audioUrl: 'this_is_a_simple_example.mp3',
text: 'This is a simple example.',
wordStartTimes: [
100, 200, 500, 800, 1100
],
translation: '这是一个样本案例。'
},
{
imageUrl: '15281012820093872.jpg',
audioUrl: '170f16a30fb178d.mp3',
text: 'Your egg.',
wordStartTimes: [
490,
1150
],
translation: '你的鸡蛋。'
},
{
imageUrl: '1528101315937327.jpg',
audioUrl: '170f16a70f44791.mp3',
text: 'Your juice.',
wordStartTimes: [
530,
1200
],
translation: '你的果汁。'
},
{
imageUrl: '1528101341373822.jpg',
audioUrl: '170f16aaf007cf8.mp3',
text: 'Your cake.',
wordStartTimes: [
480,
1030
],
translation: '你的蛋糕。'
},
{
imageUrl: '152810136774110.jpg',
audioUrl: '170f16aea4e8cb7.mp3',
text: 'I\u0027m hungry.',
wordStartTimes: [
540,
1070
],
translation: '我饿了。'
},
{
imageUrl: '15281013914784154.jpg',
audioUrl: '170f16b27602718.mp3',
text: 'My egg!',
wordStartTimes: [
510,
1190
],
translation: '我的鸡蛋!'
},
{
imageUrl: '15281014154594103.jpg',
audioUrl: '170f16b640658ac.mp3',
text: 'My juice!',
wordStartTimes: [
490,
1040
],
translation: '我的果汁!'
},
{
imageUrl: '15281014415395255.jpg',
audioUrl: '170f16bb14251fa.mp3',
text: 'My cake!',
wordStartTimes: [
480,
1080
],
translation: '我的蛋糕!'
},
{
imageUrl: '1528101466094874.jpg',
audioUrl: '170f16bea952816.mp3',
text: 'Yay! Candy!',
wordStartTimes: [
510,
1490
],
translation: '耶!糖果!'
}
],
resourceList: [
'1573803206931407.jpg',
'this_is_a_simple_example.jpg',
'15281012820093872.jpg',
'1528101315937327.jpg',
'1528101341373822.jpg',
'152810136774110.jpg',
'15281013914784154.jpg',
'15281014154594103.jpg',
'15281014415395255.jpg',
'1528101466094874.jpg',
'170f173622a46ff.mp3',
'this_is_a_simple_example.mp3',
'170f16a30fb178d.mp3',
'170f16a70f44791.mp3',
'170f16aaf007cf8.mp3',
'170f16aea4e8cb7.mp3',
'170f16b27602718.mp3',
'170f16b640658ac.mp3',
'170f16bb14251fa.mp3',
'170f16bea952816.mp3'
]
}
const newZip = new JSZip()

function getTemplate() {
return new Promise((resolve, reject) => {
request({
method: 'GET',
encoding: null,
uri: 'https://public.yitong.com/demo/story-template/story.zip?_t=' + new Date().getTime()
}, function(err, response, body) {
if (err) {
return reject(err)
}
resolve(body)
})
})
}

function getFile(json) {
const arr = []
json.resourceList.forEach(item => {
arr.push(new Promise((resolve, reject) => {
request({
method: 'GET',
encoding: null,
uri: json.baseUrl + item
}, function(err, response, body) {
if (err) {
return reject(err)
}
resolve({
name: item,
body
})
})
}))
})
return Promise.all(arr)
}

// stream 转 buffer
function streamToBuffer (stream) {
return new Promise((resolve, reject) => {
const buffers = []
stream.on('error', reject)
stream.on('data', data => buffers.push(data))
stream.on('end', () => resolve(Buffer.concat(buffers)))
})
}

// buffer 转 stream
// let Duplex = require('stream').Duplex

// function bufferToStream(buffer) {
// let stream = new Duplex();
// stream.push(buffer);
// stream.push(null);
// return stream;
// }

export default async function (req, res, next) {
// req is the Node.js http request object
const body = await getTemplate()
if (!body) {
res.write(JSON.stringify({
code: 9,
message: '出错啦',
result: null
}))
return
}
const zip = await newZip.loadAsync(body)
zip.file('story.json', JSON.stringify(configJson))
const picbook = zip.folder('picbook')
const resources = await getFile(configJson)
resources.forEach((item) => {
picbook.file(item.name, item.body, { base64: true })
})
// https://stuk.github.io/jszip/documentation/howto/write_zip.html
const stream = zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader('Access-Control-Allow-Methods', '*')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type,Access-Token') // 这里“Access-Token”是我要传到后台的内容key
res.setHeader('Access-Control-Expose-Headers', '*')
// res.setHeader('Content-Type', 'application/octet-stream')
res.setHeader('Content-Type', 'text/plain')
// res is the Node.js http response object
res.write(await streamToBuffer(stream), 'utf8')
res.end()

// next is a function to call to invoke the next middleware
// Don't forget to call next at the end if your middleware is not an endpoint!
// next()
}


// 参考资料:
// 【node-http】http://nodejs.cn/api/http.html#http_response_write_chunk_encoding_callback
// 【jszip】https://stuk.github.io/jszip/documentation/howto/write_zip.html
// 【file-saver】https://www.npmjs.com/package/file-saver
// 【服务器渲染中间件】https://zh.nuxtjs.org/api/configuration-servermiddleware/
// 【node - connect】https://github.com/senchalabs/connect#appusefn
// 【文件类型对照表】https://tool.oschina.net/commons/
// 【后台传输arraybuffer,前台用Uint8Array转】https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array

前端

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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
<template>
<div class="main">
<div class="submit-btn" @click="package">
<i class="el-icon-goods"></i>
<p>打包课件</p>
</div>
<UploadManagement @selected="handleSelected()" :limit="99" />
<el-form ref="form" label-width="80px">
<el-form-item label="课件标题">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="单词数量">
<el-input v-model="form.wordCount"></el-input>
</el-form-item>
<el-form-item label="封面图片">
<div>
<UploadSelectManagement
@onSuccess="handleUploadImage"
:options="{
limit: 1,
mark: 'coverImageUrl',
type: 'image/',
file: form.coverImageUrl ? [{name: '', url: form.coverImageUrl}] : []
}"
/>
<!-- <UploadImage @onsuccess="handleUploadImage" :fileList="form.coverImageUrl ? [{name: '', url: form.coverImageUrl}] : []" :limit="1" /> -->
</div>
</el-form-item>
<el-form-item label="封面音频">
<UploadSelectManagement
@onSuccess="handleUploadAudio"
:options="{
limit: 1,
mark: 'coverAudioUrl',
type: 'audio/mpeg',
file: form.coverAudioUrl ? [{name: '', url: form.coverAudioUrl}] : []
}"
/>
<!-- <UploadAudio @onsuccess="handleUploadAudio" :url="form.coverAudioUrl" /> -->
</el-form-item>
<el-form-item label="内容区域">
<div class="page-list">
<div class="page-item" v-for="(item, index) in form.pageContents" :key="index">
<span class="subscript">P{{index + 1}}</span>
<div class="img-box">
<img
:src="item.imageUrl"
>
<div class="operate">
<i class="el-icon-caret-top"></i>
<i class="el-icon-edit" @click="showDialogForm($event, item, index)"></i>
<i class="el-icon-caret-bottom"></i>
</div>
</div>
<div>
<audio :src="item.audioUrl" controls></audio>
<h3>{{ item.text }}</h3>
<p>{{ item.translation }}</p>
<p>{{ item.wordStartTimes.join(',') }}</p>
</div>
</div>
<div class="page-item">
<i class="el-icon-plus add" @click="showDialogForm($event)"></i>
</div>
</div>
</el-form-item>
</el-form>
<el-dialog title="编辑内容" :visible.sync="dialogFormVisible" :close-on-click-modal="false" :close-on-press-escape="false">
<el-form :model="form">
<el-form-item label="图片" :label-width="formLabelWidth">
<UploadSelectManagement
@onSuccess="handlePageUploadImage"
:options="{
limit: 1,
mark: 'imageUrl',
type: 'image/',
file: pageForm.imageUrl ? [{name: '', url: pageForm.imageUrl}] : []
}"
/>
<!-- <UploadImage @onsuccess="handlePageUploadImage" :fileList="pageForm.imageUrl ? [{name: '', url: pageForm.imageUrl}] : []" :limit="1" /> -->
</el-form-item>
<el-form-item label="音频" :label-width="formLabelWidth">
<UploadSelectManagement
@onSuccess="handlePageUploadAudio"
:options="{
limit: 1,
mark: 'audioUrl',
type: 'audio/mpeg',
file: pageForm.audioUrl ? [{name: '', url: pageForm.audioUrl}] : []
}"
/>
<!-- <UploadAudio @onsuccess="handlePageUploadAudio" :url="pageForm.audioUrl" /> -->
</el-form-item>
<el-form-item label="文本" :label-width="formLabelWidth">
<el-input v-model="pageForm.text"></el-input>
</el-form-item>
<el-form-item label="翻译" :label-width="formLabelWidth">
<el-input v-model="pageForm.translation"></el-input>
</el-form-item>
<el-form-item label="时间节点" :label-width="formLabelWidth">
<el-input v-model="pageForm.wordStartTimes" placeholder="例如:300,600,900"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="hideDialogForm(0)">取 消</el-button>
<el-button type="primary" @click="hideDialogForm(1)">确 定</el-button>
</div>
</el-dialog>
</div>
</template>

<script lang="ts">
/** eslint-disbale */
/* global openFileDialog _ */
import moment from 'moment'
import axios from 'axios'
import UploadImage from '@/components/UploadImage/index.vue'
import UploadAudio from '@/components/UploadAudio/index.vue'
import UploadManagement from '@/components/UploadManagement/index.vue'
import UploadSelectManagement from '@/components/UploadManagement/select.vue'
import { Component, Vue, Prop } from 'vue-property-decorator'
import FileSaver from 'file-saver'

interface IPage {
imageUrl: string
audioUrl: string
text: string
wordStartTimes: string | number|string[]
translation: string
}
@Component({
name: 'ai-update',
components: {
UploadImage,
UploadAudio,
UploadManagement,
UploadSelectManagement
}
})
export default class extends Vue {
showUploadManagement = false
pageIndex = -1
dialogFormVisible = false
formLabelWidth = '120px'
pageFormWordStartTimes = ''
pageForm: IPage = {
imageUrl: '',
audioUrl: '',
text: '',
wordStartTimes: '',
translation: ''
}
form: any = {
baseUrl: '',
name: '',
prefix: 'resource/',
coverImageUrl: '',
coverAudioUrl: '',
wordCount: '',
pageContents: [
],
resourceList: [
]
}
// 模板数据
formTemplate = {
baseUrl: 'https://public.yitong.com/demo/story/',
prefix: 'picbook/',
name: 'Sharing (Story)',
coverImageUrl: '1573803206931407.jpg',
coverAudioUrl: '170f173622a46ff.mp3',
wordCount: 16,
pageContents: [
{
imageUrl: 'this_is_a_simple_example.jpg',
audioUrl: 'this_is_a_simple_example.mp3',
text: 'This is a simple example.',
wordStartTimes: [
100, 200, 500, 800, 1100
],
translation: '这是一个样本案例。'
},
{
imageUrl: '15281012820093872.jpg',
audioUrl: '170f16a30fb178d.mp3',
text: 'Your egg.',
wordStartTimes: [
490,
1150
],
translation: '你的鸡蛋。'
},
{
imageUrl: '1528101315937327.jpg',
audioUrl: '170f16a70f44791.mp3',
text: 'Your juice.',
wordStartTimes: [
530,
1200
],
translation: '你的果汁。'
},
{
imageUrl: '1528101341373822.jpg',
audioUrl: '170f16aaf007cf8.mp3',
text: 'Your cake.',
wordStartTimes: [
480,
1030
],
translation: '你的蛋糕。'
},
{
imageUrl: '152810136774110.jpg',
audioUrl: '170f16aea4e8cb7.mp3',
text: 'I\u0027m hungry.',
wordStartTimes: [
540,
1070
],
translation: '我饿了。'
},
{
imageUrl: '15281013914784154.jpg',
audioUrl: '170f16b27602718.mp3',
text: 'My egg!',
wordStartTimes: [
510,
1190
],
translation: '我的鸡蛋!'
},
{
imageUrl: '15281014154594103.jpg',
audioUrl: '170f16b640658ac.mp3',
text: 'My juice!',
wordStartTimes: [
490,
1040
],
translation: '我的果汁!'
},
{
imageUrl: '15281014415395255.jpg',
audioUrl: '170f16bb14251fa.mp3',
text: 'My cake!',
wordStartTimes: [
480,
1080
],
translation: '我的蛋糕!'
},
{
imageUrl: '1528101466094874.jpg',
audioUrl: '170f16bea952816.mp3',
text: 'Yay! Candy!',
wordStartTimes: [
510,
1490
],
translation: '耶!糖果!'
}
],
resourceList: [
'1573803206931407.jpg',
'this_is_a_simple_example.jpg',
'15281012820093872.jpg',
'1528101315937327.jpg',
'1528101341373822.jpg',
'152810136774110.jpg',
'15281013914784154.jpg',
'15281014154594103.jpg',
'15281014415395255.jpg',
'1528101466094874.jpg',
'170f173622a46ff.mp3',
'this_is_a_simple_example.mp3',
'170f16a30fb178d.mp3',
'170f16a70f44791.mp3',
'170f16aaf007cf8.mp3',
'170f16aea4e8cb7.mp3',
'170f16b27602718.mp3',
'170f16b640658ac.mp3',
'170f16bb14251fa.mp3',
'170f16bea952816.mp3'
]
}
created() {
}
setCoverImageUrl(list: any) {
this.form.coverImageUrl = list && list.length > 0 ? list[0].url : ''
}
handleSelected(ref: string) {
// this.$refs[ref].
}
resetPageForm() {
this.pageForm = {
imageUrl: '',
audioUrl: '',
text: '',
wordStartTimes: '',
translation: ''
}
}
showDialogForm(e: any, item?: IPage, index?: number) {
const _index = index || -1
this.pageIndex = _index > -1 ? _index : this.form.pageContents.length
console.log(item)
console.log(index)
if (item) {
this.$set(this, 'pageForm', {
...item,
wordStartTimes: (item.wordStartTimes || [] as any).join(',')
})
} else {
this.resetPageForm()
}
this.dialogFormVisible = true
}
hideDialogForm(bool: boolean) {
if (bool) {
if (!(this.pageForm.imageUrl && this.pageForm.audioUrl && this.pageForm.text && this.pageForm.wordStartTimes && this.pageForm.translation)) {
alert('请填写完整信息!')
return
}
const params = {
...this.pageForm,
wordStartTimes: (this.pageForm.wordStartTimes as any).split(',')
}
if (this.pageIndex > -1) {
this.form.pageContents.splice(this.pageIndex, 1, params)
} else {
this.form.pageContents.push(params)
}
} else {
this.resetPageForm()
}
this.dialogFormVisible = false
}
handlePageUploadImage(info?: any) {
this.pageForm.imageUrl = info ? info.url : ''
}
handlePageUploadAudio(info?: any) {
this.pageForm.audioUrl = info ? info.url : ''
}
handleUploadImage(info: any) {
this.form.coverImageUrl = info ? info.url : ''
}
handleUploadAudio(info: any) {
this.form.coverAudioUrl = info ? info.url : ''
}
async package() {
console.log(this.form)
this.form.resourceList = []
this.form.coverImageUrl && this.form.resourceList.push(this.form.coverImageUrl)
this.form.coverAudioUrl && this.form.resourceList.push(this.form.coverAudioUrl)
this.form.pageContents.forEach((element: IPage) => {
element.imageUrl && this.form.resourceList.push(element.imageUrl)
element.audioUrl && this.form.resourceList.push(element.audioUrl)
})
const res = await axios.post('http://localhost:3000/gw/ai/zip', this.form, {
headers: { 'Content-Type': 'application/json' },
responseType: 'arraybuffer' }
)
console.log(typeof res.data)
console.log(res.data)
FileSaver.saveAs(new Blob([new Uint8Array(res.data)]), 'story.zip')
}
}
</script>

<style lang="scss">
.main {
.upload {
line-height: 0;
> div {
line-height: 28px;
font-size: 14px;
}
}
.el-upload--picture-card {
border: none;
height: auto;
}
}
</style>

<style lang="scss" scoped>
.main {
padding: 20px;
padding: relative;
.submit-btn {
position: fixed;
right: 30px;
bottom: 20px;
width: 120px;
height: 120px;
z-index: 10;
background-color: rgb(24, 144, 255);
color: #fff;
border-radius: 50%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transition: all .5s;
opacity: .75;
&:hover {
transform: rotateY(360deg);
opacity: 1;
}
cursor: pointer;
i {
font-size: 36px;
}
p {
margin: 5px 0 0 0;
}
}
}
.el-input {
width: 200px;
}
.page-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
audio {
border: none;
outline: none
}
}
.page-item {
border: 1px solid #ccc;
padding: 20px 0 15px;
width: 360px;
height: 400px;
text-align: center;
position: relative;
margin-right: 10px;
margin-bottom: 10px;
.add {
font-size: 100px;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
transition: all .5s;
cursor: pointer;
&:hover {
transform: rotate(180deg);
}
}
audio {
margin-top: 15px;
}
h3,p {
margin: 0;
}
.subscript {
display: flex;
justify-content: center;
align-items: center;
width: 30px;
height: 40px;
background-color: rgba($color: #000000, $alpha: 1);
color: #fff;
position: absolute;
right: 0;
top: 0;
z-index: 1;
}
.img-box {
width:150px;
height:200px;
margin: 0 auto;
position: relative;
img {
width: 100%;
height: 100%;
object-fit: contain;
}
.operate {
cursor: pointer;
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 26px;
color: #fff;
transition: all .5s;
background-color: rgba($color: #000000, $alpha: 0.5);
opacity: .75;
i {
margin: 10px;
}
&:hover {
background-color: rgba($color: #000000, $alpha: 0.75);
opacity: 1;
}
}
}
}
</style>

ai-story-zip,课件模板打包
http://example.com/20200915-ai-story-zip/
作者
csorz
发布于
2020年9月15日
许可协议