@netang/quasar 0.2.40 → 0.2.42

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.
@@ -99,6 +99,15 @@
99
99
  @click="handleActions('clockwise')"
100
100
  />
101
101
 
102
+ <!-- 原图 -->
103
+ <q-icon
104
+ tag="a"
105
+ :href="currentImg.origin"
106
+ target="_blank"
107
+ class="cursor-pointer non-selectable no-outline n-text-decoration-none"
108
+ name="crop_original"
109
+ color="white"
110
+ />
102
111
  </div>
103
112
  </div>
104
113
 
@@ -106,14 +115,14 @@
106
115
  <!-- 图片列表(有点击事件) -->
107
116
  <template v-if="isClickImg">
108
117
  <div
109
- v-for="(src, i) in currentImages"
110
- :key="`${src}-${i}`"
118
+ v-for="(item, i) in currentImages"
119
+ :key="`${item.src}-${i}`"
111
120
  class="non-selectable no-outline"
112
121
  @click="onClickImg({ src })"
113
122
  >
114
123
  <img
115
124
  :ref="(el) => (imgRefs[i] = el)"
116
- :src="src"
125
+ :src="item.src"
117
126
  :style="imgStyle"
118
127
  @load="handleImgLoad"
119
128
  @error="handleImgError"
@@ -124,15 +133,15 @@
124
133
  <!-- 图片列表(点击跳转原图) -->
125
134
  <template v-else>
126
135
  <a
127
- v-for="(src, i) in currentImages"
128
- :key="`${src}-${i}`"
129
- :href="src"
136
+ v-for="(item, i) in currentImages"
137
+ :key="`${item.src}-${i}`"
138
+ :href="item.src"
130
139
  target="_blank"
131
140
  class="non-selectable no-outline"
132
141
  >
133
142
  <img
134
143
  :ref="(el) => (imgRefs[i] = el)"
135
- :src="src"
144
+ :src="item.src"
136
145
  :style="imgStyle"
137
146
  @load="handleImgLoad"
138
147
  @error="handleImgError"
@@ -311,11 +320,11 @@ export default {
311
320
  $n_forEach(props.images, function (url) {
312
321
  const origin = $n_getImage(url, { compress: false })
313
322
  if (origin) {
314
- lists.push($n_getImage(url, { w: 1000 }))
315
- // lists.push({
316
- // src: $n_getImage(url, { w: 1000 }),
317
- // origin,
318
- // })
323
+ // lists.push($n_getImage(url, { w: 1000 }))
324
+ lists.push({
325
+ src: $n_getImage(url, { w: 1000 }),
326
+ origin,
327
+ })
319
328
  }
320
329
  })
321
330
 
@@ -128,6 +128,17 @@ export default {
128
128
  preview: Boolean,
129
129
  // 预览参数
130
130
  previewProps: Object,
131
+
132
+ // 真实宽度
133
+ // 用于 cdn 显示真实图片宽度
134
+ realWidth: Number,
135
+ // 图片参数
136
+ options: Object,
137
+ // cdn 自动缩放
138
+ zoom: {
139
+ type: Boolean,
140
+ default: true,
141
+ },
131
142
  },
132
143
 
133
144
  /**
@@ -141,8 +152,31 @@ export default {
141
152
  * 当前图片地址
142
153
  */
143
154
  const currentSrc = computed(function () {
144
- const res = $n_getImage(props.src, { w: props.width, zoom: true })
145
- return res ? res : ''
155
+
156
+ if (props.src) {
157
+
158
+ // 获取参数
159
+ const options = {}
160
+
161
+ // 宽度
162
+ if (props.width) {
163
+ options.w = props.width
164
+ }
165
+
166
+ // 真实宽度
167
+ if (props.realWidth) {
168
+ options.realWidth = props.realWidth
169
+ }
170
+
171
+ // 自动缩放
172
+ if (props.zoom) {
173
+ options.zoom = true
174
+ }
175
+
176
+ return $n_getImage(props.src, Object.assign(options, props.options)) || ''
177
+ }
178
+
179
+ return ''
146
180
  })
147
181
 
148
182
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.2.40",
3
+ "version": "0.2.42",
4
4
 
5
5
  "description": "netang-quasar",
6
6
  "scripts": {
package/sass/common.scss CHANGED
@@ -54,6 +54,10 @@ body {
54
54
  overflow-y: auto !important;
55
55
  }
56
56
 
57
+ .n-text-decoration-none {
58
+ text-decoration: none;
59
+ }
60
+
57
61
  // 字体大小 12 像素
58
62
  .n-font-size-12 {
59
63
  font-size: 12px;
package/utils/getImage.js CHANGED
@@ -13,6 +13,50 @@ import $n_uploader from './uploader'
13
13
 
14
14
  import useFileUrl from './useFileUrl'
15
15
 
16
+ /**
17
+ * 像素转数字
18
+ */
19
+ function px2Number(w) {
20
+
21
+ if ($n_isString(w)) {
22
+ w = w.replace('px', '')
23
+ }
24
+
25
+ if ($n_isNumeric(w)) {
26
+ w = Number(w)
27
+ if (w > 0) {
28
+ return w
29
+ }
30
+ }
31
+
32
+ return 0
33
+ }
34
+
35
+ /**
36
+ * 获取宽度
37
+ */
38
+ function getW(options) {
39
+
40
+ // 如果有真实宽度
41
+ if (
42
+ $n_has(options, 'realWidth')
43
+ && $n_isNumeric(options.realWidth)
44
+ ) {
45
+ const realWidth = px2Number(options.realWidth)
46
+ return realWidth > 0 ? realWidth : 0
47
+ }
48
+
49
+ if (
50
+ $n_has(options, 'w')
51
+ && $n_isNumeric(options.w)
52
+ ) {
53
+ const w = px2Number(options.w)
54
+ return w > 0 ? w : 0
55
+ }
56
+
57
+ return null
58
+ }
59
+
16
60
  /**
17
61
  * 获取图片
18
62
  */
@@ -72,55 +116,43 @@ export default function getImage(src, options) {
72
116
  // 如果为对象定义的规格
73
117
  if ($n_isValidObject(options)) {
74
118
 
75
- // 如果有定义 w
76
- if ($n_has(options, 'w')) {
119
+ // 获取宽度
120
+ let w = getW(options)
121
+ if (w) {
77
122
 
78
123
  let {
79
- w,
80
124
  maxWidth,
81
125
  zoom,
82
126
  } = options
83
127
 
84
- // 先设为最大宽度
85
- options.w = maxWidth || 0
128
+ /* #if IS_WEB */
129
+ // 如果开启缩放
130
+ if (
131
+ zoom
132
+ // 获取设备像素比
133
+ && window.devicePixelRatio >= 2
134
+ ) {
135
+ // w *= (devicePixelRatio > 3 ? 3 : devicePixelRatio)
136
+ w *= 2
137
+ }
138
+ /* #endif */
86
139
 
87
- // 如果有宽度
88
- if (w) {
140
+ w = Math.floor(w)
89
141
 
90
- if (
91
- ! $n_isNumeric(w)
92
- && $n_isString(w)
93
- ) {
94
- w = w.replace('px', '')
95
- }
96
-
97
- if ($n_isNumeric(w)) {
98
- w = Number(w)
99
- if (w > 0) {
100
-
101
- /* #if IS_WEB */
102
- // 如果开启缩放
103
- if (
104
- zoom
105
- // 获取设备像素比
106
- && window.devicePixelRatio >= 2
107
- ) {
108
- // w *= (devicePixelRatio > 3 ? 3 : devicePixelRatio)
109
- w *= 2
110
- }
111
- /* #endif */
112
-
113
- w = Math.floor(w)
114
-
115
- // 如果有最大宽度
116
- if (maxWidth && w > maxWidth) {
117
- w = maxWidth
118
- }
119
-
120
- options.w = w
121
- }
122
- }
142
+ // 如果有最大宽度
143
+ if (maxWidth && w > maxWidth) {
144
+ w = maxWidth
123
145
  }
146
+
147
+ options.w = w
148
+
149
+ // 否则如果无宽度
150
+ } else if (w === 0) {
151
+ options.w = 0
152
+
153
+ // 否则删除宽度
154
+ } else if ($n_has(options, 'w')) {
155
+ delete options.w
124
156
  }
125
157
 
126
158
  } else {
@@ -156,7 +188,7 @@ export default function getImage(src, options) {
156
188
  // 模式
157
189
  mode: '2',
158
190
  // 宽
159
- w: 0,
191
+ w: 800,
160
192
  // 高
161
193
  h: 0,
162
194
  // 质量