yks-element 1.0.0 → 1.0.315

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -4
  3. package/{dist → lib}/fonts/element-icons.535877f5.woff +0 -0
  4. package/{dist → lib}/fonts/element-icons.732389de.ttf +0 -0
  5. package/lib/fonts/iconfont.19124b0d.ttf +0 -0
  6. package/lib/fonts/iconfont.3ae3dd4e.woff +0 -0
  7. package/lib/yks.css +1 -0
  8. package/package.json +74 -51
  9. package/packages/Button/index.js +8 -0
  10. package/packages/Button/src/index.vue +67 -0
  11. package/packages/Dialog/index.js +8 -0
  12. package/packages/Dialog/src/index.vue +103 -0
  13. package/packages/Multimedia/index.js +8 -0
  14. package/packages/Multimedia/src/index.vue +167 -0
  15. package/packages/Pagination/index.js +8 -0
  16. package/packages/Pagination/src/index.vue +149 -0
  17. package/packages/Scrollbar/index.js +8 -0
  18. package/packages/Scrollbar/src/index.vue +27 -0
  19. package/packages/Select/index.js +8 -0
  20. package/packages/Select/src/index.vue +350 -0
  21. package/packages/Select/src/option.vue +29 -0
  22. package/packages/Table/index.js +8 -0
  23. package/packages/Table/src/index.vue +141 -0
  24. package/packages/Tinymce/index.js +8 -0
  25. package/packages/Tinymce/src/config.js +25 -0
  26. package/packages/Tinymce/src/index.vue +500 -0
  27. package/packages/UploadFile/index.js +8 -0
  28. package/packages/UploadFile/src/index.vue +388 -0
  29. package/packages/Video/index.js +8 -0
  30. package/packages/Video/src/index.vue +352 -0
  31. package/packages/assets/utils/index.js +83 -0
  32. package/packages/icon/default/icons.js +182 -0
  33. package/packages/icon/default/icons.min.js +1 -0
  34. package/packages/icon/default/index.js +7 -0
  35. package/packages/icon/ks-pdf.png +0 -0
  36. package/packages/icon/ks-ppt.png +0 -0
  37. package/packages/icon/ks-word.png +0 -0
  38. package/packages/icon/ks-xslx.png +0 -0
  39. package/packages/icon/music-bg.png +0 -0
  40. package/packages/icon/video-bg.png +0 -0
  41. package/packages/index.js +221 -0
  42. package/packages/option/index.js +6 -0
  43. package/packages/styles/_mixin.scss +93 -0
  44. package/packages/styles/_variables.scss +40 -0
  45. package/packages/styles/common.scss +167 -0
  46. package/packages/styles/element-ui.scss +135 -0
  47. package/packages/styles/element-variables.scss +794 -0
  48. package/packages/styles/fonts/element-icons.ttf +0 -0
  49. package/packages/styles/fonts/element-icons.woff +0 -0
  50. package/packages/styles/fonts/iconfont.ttf +0 -0
  51. package/packages/styles/fonts/iconfont.woff +0 -0
  52. package/packages/styles/icon.scss +69 -0
  53. package/packages/styles/index.scss +10 -0
  54. package/packages/styles/select.scss +98 -0
  55. package/packages/styles/table.scss +45 -0
  56. package/types/index.d.ts +4 -0
  57. package/dist/demo.html +0 -10
  58. package/dist/yks.common.js +0 -64801
  59. package/dist/yks.css +0 -1
  60. package/dist/yks.umd.js +0 -64811
  61. package/dist/yks.umd.min.js +0 -15
  62. package/packages/button/index.vue +0 -16
  63. package/packages/index.ts +0 -12
@@ -0,0 +1,388 @@
1
+ <template>
2
+ <yks-dialog
3
+ :before-close="onClose"
4
+ :close-on-click-modal="false"
5
+ :destroy-on-close="true"
6
+ :title="title"
7
+ :show.sync="show"
8
+ append-to-body
9
+ width="600px"
10
+ height="300px"
11
+ @close="onClose"
12
+ @sure="onSure"
13
+ >
14
+ <div v-if="fileData.fileType === 'recording'" class="dialog yks-tc">
15
+ <h1 class="dialog-title">{{ formatTimes(timestamp) }}</h1>
16
+ <div class="dialog-recording yks-flex h-center" @click="onRecord">
17
+ <i :class="['icon-recording', iconName]"></i>
18
+ </div>
19
+ <div class="yks-mt10 yks-fs-12 info">
20
+ 语音录入时长限制{{ (fileData.fileSize / 60).toFixed(2) }}分钟
21
+ </div>
22
+ <audio
23
+ ref="audioS"
24
+ :src="fileSrc"
25
+ class="dialog-audio"
26
+ @timeupdate="onTimeupdate"
27
+ ></audio>
28
+ </div>
29
+ <div v-else class="dialog yks-tc">
30
+ <Upload
31
+ ref="uploadFile"
32
+ drag
33
+ action=""
34
+ show-file-list
35
+ :multiple="false"
36
+ :accept="accept"
37
+ :auto-upload="false"
38
+ :limit="1"
39
+ :on-change="beforeUpload"
40
+ >
41
+ <i class="el-icon-upload"></i>
42
+ <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
43
+ <div slot="tip" class="el-upload__tip">{{ tipsMsg }}</div>
44
+ </Upload>
45
+ </div>
46
+ <template v-slot:footer>
47
+ <div>
48
+ <yks-button
49
+ type="primary"
50
+ :disabled="!fileSrc || loading"
51
+ :loading="loading"
52
+ icon="el-icon-upload"
53
+ @click="handleUpload"
54
+ >上传文件</yks-button
55
+ >
56
+ <yks-button
57
+ type="danger"
58
+ :disabled="!fileSrc"
59
+ icon="el-icon-delete"
60
+ @click="hanleDelete"
61
+ >删除文件</yks-button
62
+ >
63
+ </div>
64
+ </template>
65
+ </yks-dialog>
66
+ </template>
67
+
68
+ <script>
69
+ import YksDialog from '../../Dialog'
70
+ import YksButton from '../../Button'
71
+ import { Upload, Message, MessageBox } from 'element-ui'
72
+
73
+ import { formatTime } from '../../assets/utils/index'
74
+
75
+ if (navigator.mediaDevices === undefined) {
76
+ navigator.mediaDevices = {}
77
+ }
78
+
79
+ if (navigator.mediaDevices.getUserMedia === undefined) {
80
+ navigator.mediaDevices.getUserMedia = function (constraints) {
81
+ const getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia
82
+ if (!getUserMedia) {
83
+ return Promise.reject(new Error('getUserMedia is not implemented in this browser'))
84
+ }
85
+ return new Promise(function (resolve, reject) {
86
+ getUserMedia.call(navigator, constraints, resolve, reject)
87
+ })
88
+ }
89
+ }
90
+
91
+ export default {
92
+ name: 'YksUploadfile',
93
+ components: {
94
+ YksDialog,
95
+ YksButton,
96
+ Upload
97
+ },
98
+ props: {
99
+ show: {
100
+ type: Boolean,
101
+ default: false
102
+ },
103
+ title: {
104
+ type: String,
105
+ default: ''
106
+ },
107
+ /* 上传函数 */
108
+ uploadFileFunction: {
109
+ type: Function,
110
+ required: true
111
+ },
112
+ /*
113
+ fileType: 上传类型
114
+ typeList: 文件类型
115
+ fileSize: 文件大小
116
+ */
117
+ fileData: {
118
+ type: Object,
119
+ default: () => {
120
+ return {}
121
+ }
122
+ }
123
+ },
124
+ data() {
125
+ return {
126
+ /* 录音状态 */
127
+ playStatus: false,
128
+
129
+ /* 播放状态 */
130
+ playing: false,
131
+
132
+ /* 媒体流 */
133
+ mediaRecorder: null,
134
+
135
+ /* 录音文件地址 */
136
+ fileSrc: '',
137
+
138
+ /* 录音时长 */
139
+ timestamp: 0,
140
+
141
+ /* 记录录音时长 */
142
+ recordTimestamp: 0,
143
+
144
+ /* 定时器 */
145
+ interval: null,
146
+
147
+ /* 文件信息 */
148
+ data: null,
149
+
150
+ loading: false
151
+ }
152
+ },
153
+ computed: {
154
+ accept() {
155
+ const { typeList } = this.fileData
156
+ if (typeList && typeList.length > 0) {
157
+ return '.' + typeList.join(',.')
158
+ }
159
+ return ''
160
+ },
161
+ tipsMsg() {
162
+ let msg = ''
163
+ let type = ''
164
+ const { typeList, fileSize } = this.fileData
165
+ if (typeList && typeList.length > 0) {
166
+ type = typeList.join('、')
167
+ msg = `只能上传${type}文件`
168
+ if (fileSize) {
169
+ return `${msg},且不超过${fileSize}MB`
170
+ }
171
+ }
172
+ if (fileSize) {
173
+ msg += `文件大小不超过${fileSize}MB`
174
+ }
175
+ return msg
176
+ },
177
+ iconName() {
178
+ if (this.fileSrc && !this.playing) {
179
+ return 'el-icon-caret-right'
180
+ }
181
+ if (this.playStatus || this.playing) {
182
+ return 'icon-pause'
183
+ }
184
+ return 'el-icon-microphone'
185
+ }
186
+ },
187
+ watch: {
188
+ timestamp(val) {
189
+ if (val <= 0.2) {
190
+ clearInterval(this.interval)
191
+ this.playing = false
192
+ this.timestamp = this.recordTimestamp
193
+ }
194
+ },
195
+ show(val) {
196
+ if (val) {
197
+ this.resetData()
198
+ }
199
+ }
200
+ },
201
+ methods: {
202
+ formatTimes(value) {
203
+ return formatTime(value)
204
+ },
205
+ resetData() {
206
+ this.fileSrc = ''
207
+ this.data = ''
208
+ this.timestamp = 0
209
+ this.recordTimestamp = 0
210
+ this.playStatus = false
211
+ this.playing = false
212
+ },
213
+
214
+ beforeUpload(file) {
215
+ const name = file.name.substr(file.name.lastIndexOf('.') + 1).toLowerCase()
216
+ const { typeList, fileSize } = this.fileData
217
+ const isLt2M = file.size / 1024 / 1024 > fileSize
218
+ const isType = typeList.includes(name)
219
+ const type = typeList.join('、')
220
+ if (fileSize && isLt2M) {
221
+ Message.error(`上传文件大小不能超过 ${fileSize}MB!`)
222
+ this.$refs.uploadFile.clearFiles()
223
+ return false
224
+ }
225
+ if (typeList && !isType) {
226
+ Message.error(`只能上传${type}文件!`)
227
+ this.$refs.uploadFile.clearFiles()
228
+ return false
229
+ }
230
+ this.fileSrc = file
231
+ this.data = file
232
+ return true
233
+ },
234
+
235
+ async handleUpload() {
236
+ this.loading = true
237
+ try {
238
+ const data = await this.uploadFileFunction(this.data)
239
+ this.$emit('sure', data)
240
+ this.onClose()
241
+ } catch (error) {
242
+ console.log(error)
243
+ }
244
+ this.loading = false
245
+ },
246
+
247
+ onTimeupdate(el) {
248
+ this.timestamp = this.recordTimestamp - el.target.currentTime
249
+ },
250
+
251
+ hanleDelete() {
252
+ MessageBox.confirm('是否删除当前文件?', '提示', {
253
+ confirmButtonText: '确定',
254
+ cancelButtonText: '取消',
255
+ type: 'warning'
256
+ })
257
+ .then(() => {
258
+ this.fileSrc = ''
259
+ this.data = ''
260
+ this.timestamp = 0
261
+ this.recordTimestamp = 0
262
+ this.$refs.uploadFile.clearFiles()
263
+ })
264
+ .catch(() => {
265
+ //
266
+ })
267
+ },
268
+
269
+ /* 录音 */
270
+ async onRecord() {
271
+ if (this.fileSrc) {
272
+ if (this.playing) {
273
+ this.$refs.audioS.pause()
274
+ this.playing = false
275
+ } else {
276
+ this.$refs.audioS.play()
277
+ this.playing = true
278
+ }
279
+ return
280
+ }
281
+ try {
282
+ if (this.playStatus) {
283
+ this.mediaRecorder.stop()
284
+ this.playStatus = false
285
+ this.mediaRecorder = ''
286
+ clearInterval(this.interval)
287
+ this.interval = null
288
+ this.recordTimestamp = this.timestamp
289
+ } else {
290
+ this.interval = setInterval(() => {
291
+ this.timestamp += 1
292
+ if (this.fileData.fileSize <= this.timestamp) {
293
+ this.onRecord()
294
+ }
295
+ }, 1000)
296
+ const audio = await navigator.mediaDevices.getUserMedia({
297
+ audio: true,
298
+ video: false
299
+ })
300
+ this.mediaRecorder = new MediaRecorder(audio)
301
+ this.mediaRecorder.start()
302
+ this.playStatus = true
303
+ this.mediaRecorder.addEventListener('dataavailable', (el) => {
304
+ this.fileSrc = URL.createObjectURL(el.data)
305
+ this.data = el
306
+ })
307
+ }
308
+ } catch (error) {
309
+ const params = error
310
+ this.playStatus = false
311
+ this.mediaRecorder = ''
312
+ clearInterval(this.interval)
313
+ this.interval = null
314
+ this.recordTimestamp = 0
315
+ this.timestamp = 0
316
+ let errorMessage
317
+ switch (params.name) {
318
+ case 'NotAllowedError':
319
+ errorMessage = '用户拒绝,请在浏览器打开录音权限!'
320
+ break
321
+ case 'PermissionDeniedError':
322
+ errorMessage = '用户已禁止网页调用录音设备'
323
+ break
324
+ case 'NotFoundError':
325
+ errorMessage = '没接入录音设备'
326
+ break
327
+ case 'DevicesNotFoundError':
328
+ errorMessage = '录音设备未找到'
329
+ break
330
+ case 'NotSupportedError':
331
+ errorMessage = '不支持录音功能'
332
+ break
333
+ default:
334
+ errorMessage = '录音调用错误'
335
+ break
336
+ }
337
+ Message.error(errorMessage)
338
+ }
339
+ },
340
+
341
+ onClose() {
342
+ this.$emit('update:show', false)
343
+ },
344
+
345
+ onSure() {
346
+ this.onClose()
347
+ }
348
+ }
349
+ }
350
+ </script>
351
+
352
+ <style lang="scss" scoped>
353
+ .dialog {
354
+ position: relative;
355
+ .dialog-title {
356
+ margin-top: 20px;
357
+ }
358
+ .dialog-audio {
359
+ display: none;
360
+ }
361
+ .dialog-recording {
362
+ width: 100px;
363
+ height: 100px;
364
+ margin: 0 auto;
365
+ border-radius: 50%;
366
+ cursor: pointer;
367
+ background-color: #03a9f4;
368
+ &:hover {
369
+ opacity: 0.7;
370
+ }
371
+ .icon-recording {
372
+ font-size: 30px;
373
+ color: #fff;
374
+ }
375
+ }
376
+ .dialog-button {
377
+ position: absolute;
378
+ right: 0;
379
+ bottom: 20px;
380
+ }
381
+ .icon-pause {
382
+ width: 20px;
383
+ height: 20px;
384
+ border-left: #fff solid 5px;
385
+ border-right: #fff solid 5px;
386
+ }
387
+ }
388
+ </style>
@@ -0,0 +1,8 @@
1
+ import YksVideo from './src/index';
2
+
3
+ /* istanbul ignore next */
4
+ YksVideo.install = function(Vue) {
5
+ Vue.component(YksVideo.name, YksVideo);
6
+ };
7
+
8
+ export default YksVideo;