@netang/quasar 0.1.64 → 0.1.65

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.
@@ -77,7 +77,7 @@
77
77
  @dragend="dragEnd"
78
78
  >
79
79
  <n-img
80
- :src="getImage(fileItem)"
80
+ :src="currentQuery[fileItemIndex].src"
81
81
  :spinner-size="toPx(currentSize / 2)"
82
82
  :width="toPx(currentSize)"
83
83
  :height="toPx(currentSize)"
@@ -146,9 +146,9 @@
146
146
  name="search"
147
147
  :size="settingsIconSize"
148
148
  title="预览"
149
- @click="uploader.previewImage(fileItem)"
149
+ @click="previewImage(fileItemIndex)"
150
150
  v-bind="settingsIconProps"
151
- v-if="! noPreview && getImage(fileItem)"
151
+ v-if="! noPreview && currentQuery[fileItemIndex].preview_src"
152
152
  />
153
153
 
154
154
  <!-- 删除 -->
@@ -361,10 +361,12 @@ import $n_has from 'lodash/has'
361
361
  import $n_get from 'lodash/get'
362
362
 
363
363
  import $n_px from '@netang/utils/px'
364
+ import $n_forEach from '@netang/utils/forEach'
364
365
  import $n_isValidArray from '@netang/utils/isValidArray'
365
366
  import $n_isValidString from '@netang/utils/isValidString'
366
367
 
367
368
  import $n_getImage from '../../utils/getImage'
369
+ import $n_previewImage from '../../utils/previewImage'
368
370
 
369
371
  import NDragger from '../dragger'
370
372
 
@@ -463,12 +465,55 @@ export default {
463
465
 
464
466
  // ==========【计算属性】=========================================================================================
465
467
 
468
+ /**
469
+ * 当前上传文件队列
470
+ */
471
+ const currentQuery = computed(function () {
472
+
473
+ // 如果不是图片
474
+ if (uploaderProps.type !== 'image') {
475
+ if ($n_isValidArray(query.value)) {
476
+ return query.value
477
+ }
478
+ return []
479
+ }
480
+
481
+ const lists = []
482
+
483
+ $n_forEach(query.value, function (fileItem) {
484
+ const newItem = Object.assign({}, fileItem)
485
+
486
+ let src = ''
487
+ let preview_src = ''
488
+
489
+ if ($n_has(fileItem, '__img')) {
490
+ src = fileItem.__img
491
+ preview_src = src
492
+ } else if ($n_isValidString(fileItem.hash)) {
493
+ src = $n_getImage(fileItem.hash, { w: $q.platform.is.mobile ? currentSize.value * 2 : currentSize.value })
494
+ if (src) {
495
+ // 预览地址
496
+ preview_src = fileItem.hash
497
+ }
498
+ }
499
+
500
+ lists.push(Object.assign(newItem, {
501
+ // 图片地址
502
+ src,
503
+ // 预览地址
504
+ preview_src,
505
+ }))
506
+ })
507
+
508
+ return lists
509
+ })
510
+
511
+
466
512
  /**
467
513
  * 当前是否开启拖拽
468
514
  */
469
515
  const currentDrag = computed(function() {
470
516
  return props.drag
471
- && $n_isValidArray(query.value)
472
517
  && query.value.length > 1
473
518
  && ! props.readonly
474
519
  && ! props.disable
@@ -500,8 +545,8 @@ export default {
500
545
  const showSquareButton = computed(function () {
501
546
  // 自动显示方块按钮 && 有上传文件限制数量
502
547
  return props.autoShowSquareButton && uploaderProps.count > 0 ?
503
- // 如果 上传文件列表数量 < 上传文件限制数量
504
- query.value.length < uploaderProps.count
548
+ // 如果 当前上传文件队列数量 < 上传文件限制数量
549
+ currentQuery.value.length < uploaderProps.count
505
550
  // 始终显示
506
551
  : true
507
552
  })
@@ -509,16 +554,15 @@ export default {
509
554
  // ==========【方法】=============================================================================================
510
555
 
511
556
  /**
512
- * 获取图片地址
557
+ * 预览图片
513
558
  */
514
- function getImage(fileItem) {
515
- return $n_has(fileItem, '__img') ?
516
- fileItem.__img
517
- : (
518
- $n_isValidString(fileItem.hash) ?
519
- $n_getImage(fileItem.hash, { w: $q.platform.is.mobile ? currentSize.value * 2 : currentSize.value })
520
- : ''
521
- )
559
+ function previewImage(startPosition) {
560
+ $n_previewImage({
561
+ // 需要预览的图片 URL 数组
562
+ images: currentQuery.value.map(e => e.preview_src),
563
+ // 图片预览起始位置索引
564
+ startPosition,
565
+ })
522
566
  }
523
567
 
524
568
  /**
@@ -538,8 +582,10 @@ export default {
538
582
  type: uploaderProps.type,
539
583
  // 上传文件数量(0:不限)
540
584
  count: uploaderProps.count,
541
- // 上传文件队列
585
+ // 文件队列
542
586
  query,
587
+ // 当前上传文件队列
588
+ currentQuery,
543
589
 
544
590
  // 当前是否开启拖拽
545
591
  currentDrag,
@@ -553,8 +599,8 @@ export default {
553
599
  // 上传器
554
600
  uploader,
555
601
 
556
- // 获取图片地址
557
- getImage,
602
+ // 预览图片
603
+ previewImage,
558
604
  // 获取文件名称
559
605
  getFileName,
560
606
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.1.64",
3
+ "version": "0.1.65",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/$power.js CHANGED
@@ -1358,6 +1358,36 @@ function getPageData($route) {
1358
1358
  })
1359
1359
  }
1360
1360
 
1361
+ /**
1362
+ * 新窗口
1363
+ */
1364
+ function routerPush({ path, query, pageTitle, fromPage }) {
1365
+
1366
+ if (! $n_isValidObject(query)) {
1367
+ query = {}
1368
+ }
1369
+
1370
+ // 如果有标题
1371
+ pageTitle = $n_trimString(pageTitle)
1372
+ if (pageTitle) {
1373
+ query.n_page_title = pageTitle
1374
+ }
1375
+
1376
+ // 来源页面
1377
+ if (fromPage) {
1378
+ if (fromPage === true) {
1379
+ fromPage = $n_router.getRoute().fullPath
1380
+ }
1381
+ // 来源页面是指定路由的完整路径
1382
+ query.n_from_page = encodeURIComponent(fromPage)
1383
+ }
1384
+
1385
+ $n_router.push({
1386
+ path,
1387
+ query,
1388
+ })
1389
+ }
1390
+
1361
1391
  /**
1362
1392
  * 权限业务
1363
1393
  */
@@ -1374,6 +1404,8 @@ const $power = {
1374
1404
  formatBtns,
1375
1405
  // 请求
1376
1406
  request,
1407
+ // 新窗口
1408
+ routerPush,
1377
1409
  }
1378
1410
 
1379
1411
  export default $power