@netang/quasar 0.2.39 → 0.2.41

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.
@@ -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.39",
3
+ "version": "0.2.41",
4
4
 
5
5
  "description": "netang-quasar",
6
6
  "scripts": {
package/utils/$power.js CHANGED
@@ -1220,6 +1220,8 @@ async function request(options) {
1220
1220
  // 点击确认执行
1221
1221
  .onOk(onConfirmRequest)
1222
1222
  }
1223
+
1224
+ return
1223
1225
  }
1224
1226
 
1225
1227
  // 否则执行确认请求事件
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
  // 质量