w-web-api 1.0.26 → 1.0.28

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.
@@ -1,589 +0,0 @@
1
- <template>
2
- <div
3
- style="height:100%;"
4
- :changeApis="changeApis"
5
- >
6
-
7
- <div style="display:flex; height:100%;" v-if="hasApis">
8
-
9
- <div
10
- style="min-width:400px; height:100%; color:#444; background:#fff;"
11
- v-domresize
12
- @domresize="resizeTree"
13
- >
14
-
15
- <WTree
16
- :viewHeightMax="heightTree"
17
- :data="apisTree"
18
- :iconHeight="lineHeightTree"
19
- :defItemHeight="lineHeightTree"
20
- :activable="true"
21
- :itemActive="apiActive"
22
- :funActive="funActive"
23
- :itemTextColorActive="'#000'"
24
- :itemBackgroundColorActive ="'rgba(100,100,100,0.15)'"
25
- >
26
- <template v-slot:item="props">
27
-
28
- <div
29
- :style="`display:flex; align-items:center; min-height:${lineHeightTree}px;`"
30
- v-if="props.data.type!=='node'"
31
- >
32
- {{props.data.key}}
33
- </div>
34
-
35
- <div
36
- :style="`display:flex; align-items:center; min-height:${lineHeightTree}px; cursor:pointer;`"
37
- @click="ckItem(getItemByKey(props.data.text))"
38
- v-else
39
- >
40
-
41
- <div style="padding-right:5px;">
42
- <div :style="`padding:0px 6px; font-size:0.7rem; border-radius:10px; border:1px solid #ddd; color:#fff; background:${getMethodColorByKey(props.data.text)};`">
43
- {{getMethodByKey(props.data.text)}}
44
- </div>
45
- </div>
46
-
47
- <div>
48
- {{$ui.gv(getItemByKey(props.data.text),'name')}}
49
- </div>
50
-
51
- </div>
52
-
53
- </template>
54
- </WTree>
55
-
56
- </div>
57
-
58
- <div style="height:100%; border-right:1px solid #ddd;"></div>
59
-
60
- <div style="width:100%; height:100%; overflow-y:auto;" v-if="apiSelect">
61
- <div style="padding:15px 20px 10px 10px;">
62
-
63
- <div style="padding:5px;">
64
-
65
- <div style="padding:10px; border-radius:5px; border:1px solid #ddd; background:#fff; display:flex; align-items:center;">
66
-
67
- <div style="padding-right:5px;">
68
- <div :style="`padding:0px 6px; font-size:0.7rem; border-radius:10px; border:1px solid #ddd; color:#fff; background:${getMethodColor(apiSelect)};`">
69
- {{getMethod(apiSelect)}}
70
- </div>
71
- </div>
72
-
73
- <div style="font-size:0.8rem;">
74
- {{$ui.gv(apiSelect,'url')}}
75
- </div>
76
-
77
- </div>
78
-
79
- </div>
80
-
81
- <div style="padding:10px;">
82
-
83
- <div style="color:#485ed5;">
84
- {{$ui.gv(apiSelect,'name')}}
85
- </div>
86
-
87
- <div class="bk-title" style="">
88
- {{$ui.gv(apiSelect,'description')}}
89
- </div>
90
-
91
- </div>
92
-
93
- <div style="padding:10px;">
94
-
95
- <div class="bk" style="">
96
-
97
- <div class="bk-title" style="">
98
- {{$t('tokens')}}
99
- </div>
100
-
101
- <div class="bk-item" style="">
102
- {{$ui.gv(apiSelect,'tokens')}}
103
- </div>
104
-
105
- </div>
106
-
107
- <div class="bk" style="">
108
-
109
- <div class="bk-title" style="">
110
- {{$t('version')}}
111
- </div>
112
-
113
- <div class="bk-item" style="">
114
- {{$ui.gv(apiSelect,'version')}}
115
- </div>
116
-
117
- </div>
118
-
119
- <div class="bk" style="">
120
-
121
- <div class="bk-title" style="">
122
- {{$t('levels')}}
123
- </div>
124
-
125
- <div class="bk-item" style="">
126
- {{$ui.gv(apiSelect,'')}}
127
- </div>
128
-
129
- </div>
130
-
131
- <div class="bk" style="">
132
-
133
- <div class="bk-title" style="">
134
- {{$t('keywords')}}
135
- </div>
136
-
137
- <div class="bk-item" style="">
138
- {{$ui.gv(apiSelect,'')}}
139
- </div>
140
-
141
- </div>
142
-
143
- <div class="bk" style="">
144
-
145
- <div class="bk-title" style="">
146
- {{$t('state')}}
147
- </div>
148
-
149
- <div class="bk-item" style="">
150
- {{$ui.gv(apiSelect,'')}}
151
- </div>
152
-
153
- </div>
154
-
155
- <div class="bk" style="">
156
-
157
- <div class="bk-title" style="">
158
- {{$t('timeCreate')}}
159
- </div>
160
-
161
- <div class="bk-item" style="">
162
- {{$ui.gv(apiSelect,'timeCreate',getDay)}}
163
- </div>
164
-
165
- </div>
166
-
167
- <div class="bk" style="">
168
-
169
- <div class="bk-title" style="">
170
- {{$t('timeUpdate')}}
171
- </div>
172
-
173
- <div class="bk-item" style="">
174
- {{$ui.gv(apiSelect,'timeUpdate',getDay)}}
175
- </div>
176
-
177
- </div>
178
-
179
- <div class="bk" style="">
180
-
181
- <div class="bk-title" style="">
182
- {{$t('creator')}}
183
- </div>
184
-
185
- <div class="bk-item" style="">
186
- {{$ui.gv(apiSelect,'creator')}}
187
- </div>
188
-
189
- </div>
190
-
191
- <div class="bk" style="">
192
-
193
- <div class="bk-title" style="">
194
- {{$t('dataSource')}}
195
- </div>
196
-
197
- <div class="bk-item" style="">
198
- {{$ui.gv(apiSelect,'dataSource')}}
199
- </div>
200
-
201
- </div>
202
-
203
- <div class="bk" style="">
204
-
205
- <div class="bk-title" style="">
206
- {{$t('isActive')}}
207
- </div>
208
-
209
- <div class="bk-item" style="">
210
- {{$ui.gv(apiSelect,'isActive')}}
211
- </div>
212
-
213
- </div>
214
-
215
- </div>
216
-
217
- <div style="padding:10px;">
218
-
219
- <div class="bk-title" style="">
220
- {{$t('mdInputParams')}}
221
- </div>
222
-
223
- <div class="bk-item" style="padding:10px;">
224
- <MdPanel
225
- :md="$ui.gv(apiSelect,'mdInputParams')"
226
- ></MdPanel>
227
- </div>
228
-
229
- </div>
230
-
231
- <div style="padding:10px;">
232
-
233
- <div class="bk-title" style="">
234
- {{$t('inputExample')}}
235
- </div>
236
-
237
- <div class="bk-item" style="padding:10px;">
238
- {{$ui.gv(apiSelect,'inputExample')}}
239
- </div>
240
-
241
- </div>
242
-
243
- <div style="padding:10px;">
244
-
245
- <div class="bk-title" style="">
246
- {{$t('mdOutputParams')}}
247
- </div>
248
-
249
- <div class="bk-item" style="padding:10px;">
250
- <MdPanel
251
- :md="$ui.gv(apiSelect,'mdOutputParams')"
252
- ></MdPanel>
253
- </div>
254
-
255
- </div>
256
-
257
- <div style="padding:10px;">
258
-
259
- <div class="bk-title" style="">
260
- {{$t('outputExample')}}
261
- </div>
262
-
263
- <div style="padding-top:10px;">
264
-
265
- <div style="padding-left:10px; margin-bottom:-1px;">
266
- <!-- 因上下皆有border, 故需負margin-bottom來吃掉重複border -->
267
- <WGroupRadio
268
- :items="optputMenuItems"
269
- :value="optputMenuItemSelect"
270
- @input="changeOptputMenuItemSelect"
271
- :group="true"
272
- :group-border-radius-style="{top:true}"
273
- :group-shift="7"
274
- :border-radius="20"
275
- :border-color="'#ddd'"
276
- :border-color-hover="'#dadada'"
277
- :border-color-active="'orange lighten-2'"
278
- :margin-style="{}"
279
- ></WGroupRadio>
280
- </div>
281
-
282
- <div style="border:1px solid #ddd; background:#fff">
283
-
284
- <div style="" v-if="optputMenuItemSelectId==='tree'">
285
- <WJsonView
286
- style="width:100%;"
287
- :viewHeightMax="null"
288
- :data="getOutputJsonObj(apiSelect)"
289
- ></WJsonView>
290
- </div>
291
-
292
- <div style="padding:10px; color:#555; font-size:0.85rem;" v-if="optputMenuItemSelectId==='raw'">
293
- <pre>{{getOutputJson(apiSelect)}}</pre>
294
- </div>
295
-
296
- </div>
297
-
298
- </div>
299
-
300
- </div>
301
-
302
- </div>
303
- </div>
304
-
305
- <div
306
- style="padding:20px; font-size:0.9rem;"
307
- v-else
308
- >
309
- {{$t('noSelectApi')}}
310
- </div>
311
-
312
- </div>
313
-
314
- <div
315
- style="padding:20px; font-size:0.9rem;"
316
- v-else
317
- >
318
- {{$t('waitingData')}}
319
- </div>
320
-
321
- </div>
322
- </template>
323
-
324
- <script>
325
- import get from 'lodash/get'
326
- import set from 'lodash/set'
327
- // import map from 'lodash/map'
328
- import each from 'lodash/each'
329
- import size from 'lodash/size'
330
- // import join from 'lodash/join'
331
- import trim from 'lodash/trim'
332
- import find from 'lodash/find'
333
- import cloneDeep from 'lodash/cloneDeep'
334
- // import isestr from 'wsemi/src/isestr.mjs'
335
- // import isnum from 'wsemi/src/isnum.mjs'
336
- // import isarr from 'wsemi/src/isarr.mjs'
337
- import isobj from 'wsemi/src/isobj.mjs'
338
- import iseobj from 'wsemi/src/iseobj.mjs'
339
- import j2o from 'wsemi/src/j2o.mjs'
340
- // import cdbl from 'wsemi/src/cdbl.mjs'
341
- // import str2md5 from 'wsemi/src/str2md5.mjs'
342
- // import sep from 'wsemi/src/sep.mjs'
343
- import timemsTZ2day from 'wsemi/src/timemsTZ2day.mjs'
344
- import convertToTree from 'wsemi/src/convertToTree.mjs'
345
- import WGroupRadio from 'w-component-vue/src/components/WGroupRadio.vue'
346
- import WTree from 'w-component-vue/src/components/WTree.vue'
347
- import WJsonView from 'w-component-vue/src/components/WJsonView.vue'
348
- import MdPanel from './MdPanel.vue'
349
-
350
-
351
- export default {
352
- components: {
353
- WGroupRadio,
354
- WTree,
355
- WJsonView,
356
- MdPanel,
357
- },
358
- props: {
359
- },
360
- data: function() {
361
- return {
362
-
363
- heightTree: 2,
364
- lineHeightTree: 38,
365
-
366
- apisTree: [],
367
- kpApisTree: {},
368
- apiActive: null,
369
- apiSelect: null,
370
-
371
- kpColorMethod: {
372
- GET: '#7c2',
373
- POST: '#68f',
374
- PUT: '#f82',
375
- DEL: '#f26',
376
- },
377
-
378
- optputMenuItemSelectId: 'tree',
379
-
380
- }
381
- },
382
- computed: {
383
-
384
- apis: function() {
385
- return get(this, '$store.state.apis')
386
- },
387
-
388
- changeApis: function() {
389
- let vo = this
390
- vo.genTree(vo.apis)
391
- return ''
392
- },
393
-
394
- hasApis: function() {
395
- return size(this.apisTree) > 0
396
- },
397
-
398
- optputMenuItems: function() {
399
- let vo = this
400
- let ms = [
401
- {
402
- id: 'tree',
403
- text: vo.$t('outputMenuTree'),
404
- icon: 'mdi-vanity-light',
405
- },
406
- {
407
- id: 'raw',
408
- text: vo.$t('outputMenuRaw'),
409
- icon: 'mdi-lan',
410
- },
411
- ]
412
- return ms
413
- },
414
-
415
- optputMenuItemSelect: function() {
416
- let vo = this
417
- let r = find(vo.optputMenuItems, { id: vo.optputMenuItemSelectId })
418
- // console.log(r)
419
- return r
420
- },
421
-
422
- },
423
- methods: {
424
-
425
- resizeTree: function(msg) {
426
- // console.log('methods resizeTree', msg)
427
-
428
- let vo = this
429
-
430
- //h
431
- let h = get(msg, 'snew.clientHeight')
432
- // console.log(h)
433
-
434
- //update
435
- vo.heightTree = h
436
-
437
- },
438
-
439
- genTree: function () {
440
- let vo = this
441
-
442
- //default
443
- vo.apisTree = []
444
- vo.kpApisTree = {}
445
-
446
- //cloneDeep
447
- let apis = cloneDeep(vo.apis)
448
- // console.log('apis', cloneDeep(apis))
449
-
450
- //tr
451
- let tr = {}
452
- let kpTree = {}
453
- each(apis, (v) => {
454
-
455
- //id, levels
456
- let id = v.id
457
- let levels = `${v.levels}.${v.name}`
458
-
459
- //save
460
- kpTree[id] = v
461
-
462
- //check
463
- if (!isobj(get(tr, levels))) {
464
- set(tr, levels, id)
465
- }
466
-
467
- })
468
- // console.log('tr', cloneDeep(tr))
469
- // console.log('kpTree', cloneDeep(kpTree))
470
-
471
- //convertToTree, 由預處理tree物件轉成tree物件
472
- let tree = convertToTree(tr, { bindRoot: '全部' })
473
- // console.log('tree', cloneDeep(tree))
474
-
475
- //apiSelect, 預先選定api項目, 非tree選單active物件, 因id由convertToTree轉換提供, 故不能直接算得active選單物件id
476
- let apiSelect = get(apis, 0, null)
477
- // console.log('apiSelect', cloneDeep(apiSelect))
478
-
479
- //save
480
- vo.apiSelect = apiSelect
481
- vo.apisTree = tree
482
- vo.kpApisTree = kpTree
483
-
484
- },
485
-
486
- getItemByKey: function(key) {
487
- let vo = this
488
- // let k = `kpApisTree.${key}`
489
- // console.log('getItemByKey k', k)
490
- let r = vo.kpApisTree[key]
491
- // console.log('getItemByKey r', r, vo.kpApisTree)
492
- return r
493
- },
494
-
495
- getMethod: function(item) {
496
- // let vo = this
497
- let method = get(item, 'method', '').toUpperCase()
498
- return method
499
- },
500
-
501
- getMethodByKey: function(key) {
502
- let vo = this
503
- let item = vo.getItemByKey(key)
504
- let method = get(item, 'method', '').toUpperCase()
505
- return method
506
- },
507
-
508
- getMethodColor: function(item) {
509
- let vo = this
510
- let method = vo.getMethod(item)
511
- let color = get(vo.kpColorMethod, method, '#888')
512
- return color
513
- },
514
-
515
- getMethodColorByKey: function(key) {
516
- let vo = this
517
- let method = vo.getMethodByKey(key)
518
- let color = get(vo.kpColorMethod, method, '#888')
519
- return color
520
- },
521
-
522
- getDay: function(t) {
523
- return timemsTZ2day(t)
524
- },
525
-
526
- getOutputJson: function(item) {
527
- // let vo = this
528
- let j = get(item, 'outputExample', '')
529
- j = trim(j)
530
- return j
531
- },
532
-
533
- getOutputJsonObj: function(item) {
534
- // let vo = this
535
- let j = this.getOutputJson(item)
536
- // console.log(j)
537
- let o = j2o(j)
538
- return o
539
- },
540
-
541
- funActive: function(msg) {
542
- let vo = this
543
- let b = !Array.isArray(msg.item.children) //children非陣列代表沒有所屬節點
544
- if (b) {
545
- if (!iseobj(vo.apiActive)) { //偵測若沒有apiActive才初始化預先選擇之api項目, 非api完整資訊
546
- let id = msg.item.id
547
- vo.apiActive = { id }
548
- // console.log('!iseobj(vo.apiActive)', vo.apiActive)
549
- }
550
- }
551
- return b
552
- },
553
-
554
- changeOptputMenuItemSelect: function(msg) {
555
- // console.log('changeOptputMenuItemSelect', msg)
556
- let vo = this
557
- vo.optputMenuItemSelectId = msg.id
558
- },
559
-
560
- ckItem: function(item) {
561
- // console.log('ckItem', item)
562
- let vo = this
563
- vo.apiSelect = cloneDeep(item)
564
- },
565
-
566
- }
567
- }
568
- </script>
569
-
570
- <style scoped>
571
- .bk {
572
- display:inline-block;
573
- width:200px;
574
- padding:0px 10px 10px 0px;
575
- vertical-align:top;
576
- }
577
- .bk-title {
578
- font-size:0.8rem;
579
- color:#888;
580
- }
581
- .bk-item {
582
- padding:3px 5px;
583
- font-size:0.9rem;
584
- line-height:0.9rem;
585
- border-radius:5px;
586
- border:1px solid #ddd;
587
- background:#fff;
588
- }
589
- </style>