dpzvc-ui 1.2.2 → 1.2.4

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,174 +1,75 @@
1
1
  /**
2
- * Created by admin on 2017/5/10.
2
+ * Created by admin on 2025/12/10
3
+ * Rewritten for Vue 2.7 + Vue CLI (runtime-only)
3
4
  */
4
- import Prompt from '../prompt/prompt.vue'
5
- import Vue from 'vue'
6
-
7
- import {camelcaseToHyphen} from '../../utils/util'
8
-
9
- const prefixCls = 'v-lc-modal';
10
-
11
- Prompt.newInstance = properties => {
12
-
13
- let _props = properties || {};
14
-
15
- let props = '';
16
-
17
- Object.keys(_props).forEach(prop => {
18
-
19
- props += ' :' + camelcaseToHyphen(prop) + '=' + prop
20
- })
21
-
22
-
23
- const div = document.createElement('div');
24
-
25
- document.body.appendChild(div);
26
-
27
- const propmt = new Vue({
28
- el: div,
29
-
30
- template: `<Prompt ${props} v-model="visible"
31
- :width="width"
32
- :text="text"
33
- :title="title"
34
- :ok-text="okText"
35
- :cancle-text="cancleText"
36
- :loading="loading"
37
- :spec="spec"
38
- :message="message"
39
- :validator="validator"
40
- :on-ok="onOk"
41
- :on-cancle="onCancle"> </Prompt>`,
42
- components: {
43
- Prompt
44
- },
45
- data: Object.assign(_props, {
46
- text:'',
47
- placeholderText: '请输入',
48
- visible: false,
49
- width: '70%',
50
- title: '',
51
- okText: '确定',
52
- cancleText: '取消',
53
- loading: false,
54
- showCancle: true,
55
- spec: '',
56
- message: '',
57
- validator: null,
58
- onOk:function(){},
59
- onCancle:function(prop){},
60
- onRemove:function(){}
61
- }),
62
- methods: {
63
- cancle(){
64
- this.$children[0].visible = false;
65
- this.onCancle();
66
- this.remove();
67
- },
68
- ok(){
69
- if (this.loading) {
70
- this.buttonLoading = true;
71
- } else {
72
- this.visible = false;
73
- this.remove();
74
- }
75
-
76
- this.onOk()
77
- },
78
- remove(){
79
- this.$children[0].visible = false;
80
- setTimeout(() => {
81
- this.destroy();
82
- }, 300)
83
- },
84
- destroy(){
85
- this.$destroy();
86
- document.body.removeChild(this.$el);
87
- this.onRemove()
88
- },
89
- mounted(){
90
-
91
-
92
- },
93
- }
94
- }).$children[0]
95
-
96
-
97
- return {
98
-
99
- show(props){
100
-
101
- propmt.$parent.showCancle = props.showCancle;
102
- propmt.$parent.onRemove = props.onRemove;
103
- propmt.visible = true;
104
5
 
105
- if ('width' in props) {
106
- propmt.$parent.width = props.width
107
- }
108
-
109
- if ('text' in props) {
110
- propmt.$parent.text = props.text
111
- }
112
-
113
- if ('spec' in props) {
114
- propmt.$parent.spec = props.spec
115
- }
116
-
117
- if ('title' in props) {
118
-
119
- propmt.$parent.title = props.title
120
- }
121
-
122
-
123
-
124
- if ('placeholderText' in props) {
125
- propmt.$parent.placeholderText = props.placeholderText
126
- }
127
-
128
- if ('content' in props) {
129
- propmt.$parent.body = props.body
130
- }
131
-
132
-
133
- if ('okText' in props) {
134
- propmt.$parent.okText = props.okText
135
- }
136
-
137
- if ('cancleText' in props) {
138
- propmt.$parent.cancleText = props.cancleText
139
- }
140
-
141
- if ('onCancle' in props) {
142
- propmt.$parent.onCancle = props.onCancle
143
- }
144
-
145
- if ('onOk' in props) {
146
- propmt.$parent.onOk = props.onOk
147
- }
148
-
149
- if ('loading' in props) {
150
- propmt.$parent.loading = props.loading
151
- }
152
-
153
- if ('message' in props) {
154
- propmt.$parent.message = props.message
155
- }
156
-
157
- if ('validator' in props) {
158
- propmt.$parent.validator = props.validator
159
- }
160
-
161
- console.log(propmt.$parent)
162
- },
163
- remove () {
164
-
165
- propmt.visible = false;
166
- propmt.$parent.buttonLoading = false;
167
- propmt.$parent.remove();
6
+ import Vue from 'vue'
7
+ import Prompt from '../prompt/prompt.vue'
168
8
 
169
- },
170
- component: propmt
9
+ Prompt.newInstance = (properties = {}) => {
10
+ // 1. 创建构造器
11
+ const PromptConstructor = Vue.extend(Prompt)
12
+
13
+ // 2. 初始化 props(等价你之前 data + v-model)
14
+ const instance = new PromptConstructor({
15
+ propsData: {
16
+ // 外部传入
17
+ ...properties,
18
+
19
+ // 默认值(保持你原来的语义)
20
+ visible: false,
21
+ text: '',
22
+ placeholderText: '请输入',
23
+ width: '70%',
24
+ title: '',
25
+ okText: '确定',
26
+ cancleText: '取消',
27
+ loading: false,
28
+ showCancle: true,
29
+ spec: '',
30
+ message: '',
31
+ validator: null,
32
+ onOk: () => {},
33
+ onCancle: () => {},
171
34
  }
172
- };
173
-
174
- export default Prompt;
35
+ })
36
+
37
+ // 3. 挂载到 DOM
38
+ instance.$mount()
39
+ document.body.appendChild(instance.$el)
40
+
41
+ // 4. 移除逻辑(统一)
42
+ const destroy = () => {
43
+ instance.visible = false
44
+ setTimeout(() => {
45
+ instance.$destroy()
46
+ instance.$el && document.body.removeChild(instance.$el)
47
+ instance.onRemove && instance.onRemove()
48
+ }, 300)
49
+ }
50
+
51
+ return {
52
+ /**
53
+ * 显示 Prompt
54
+ */
55
+ show(props = {}) {
56
+ Object.keys(props).forEach(key => {
57
+ instance[key] = props[key]
58
+ })
59
+ instance.visible = true
60
+ },
61
+
62
+ /**
63
+ * 关闭 Prompt
64
+ */
65
+ remove() {
66
+ instance.visible = false
67
+ instance.buttonLoading = false
68
+ destroy()
69
+ },
70
+
71
+ component: instance
72
+ }
73
+ }
74
+
75
+ export default Prompt
@@ -11,7 +11,7 @@
11
11
 
12
12
  import EXIF from 'exif-js'
13
13
  // import MegaPixImage from '../../lib/MegaPixImage'
14
- import * as MegaPixImage from '../../lib/MegaPixImage';
14
+ import MegaPixImage from '../../lib/MegaPixImage';
15
15
  import { JPEG } from '../../utils/util'
16
16
  const prefixCls = 'dpzvc-upload';
17
17
  export default {
@@ -1,158 +1,162 @@
1
1
  // MegaPixImage.js
2
- (function (global, factory) {
3
- if (typeof module === 'object' && typeof module.exports === 'object') {
4
- module.exports = factory(); // CommonJS
5
- } else if (typeof define === 'function' && define.amd) {
6
- define([], factory); // AMD
7
- } else {
8
- global.MegaPixImage = factory(); // Browser global
9
- }
10
- }(typeof window !== 'undefined' ? window : this, function () {
11
-
12
- // -------------------------
13
- // Helper functions
14
- // -------------------------
15
- function detectSubsampling(img) {
16
- var iw = img.naturalWidth, ih = img.naturalHeight;
17
- if (iw * ih > 1024 * 1024) {
18
- var canvas = document.createElement('canvas');
19
- canvas.width = canvas.height = 1;
20
- var ctx = canvas.getContext('2d');
21
- ctx.drawImage(img, -iw + 1, 0);
22
- return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
23
- } else {
24
- return false;
25
- }
26
- }
2
+ // 将原先的 UMD/CommonJS 改为 ESM export default
27
3
 
28
- function detectVerticalSquash(img, iw, ih) {
29
- var canvas = document.createElement('canvas');
30
- canvas.width = 1;
31
- canvas.height = ih;
32
- var ctx = canvas.getContext('2d');
33
- ctx.drawImage(img, 0, 0);
34
- var data = ctx.getImageData(0, 0, 1, ih).data;
35
- var sy = 0, ey = ih, py = ih;
36
- while (py > sy) {
37
- var alpha = data[(py - 1) * 4 + 3];
38
- if (alpha === 0) { ey = py; } else { sy = py; }
39
- py = (ey + sy) >> 1;
40
- }
41
- var ratio = py / ih;
42
- return (ratio === 0) ? 1 : ratio;
4
+ // -------------------------
5
+ // Helper functions
6
+ // -------------------------
7
+ function detectSubsampling(img) {
8
+ const iw = img.naturalWidth, ih = img.naturalHeight;
9
+ if (iw * ih > 1024 * 1024) {
10
+ const canvas = document.createElement('canvas');
11
+ canvas.width = canvas.height = 1;
12
+ const ctx = canvas.getContext('2d');
13
+ ctx.drawImage(img, -iw + 1, 0);
14
+ return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
43
15
  }
16
+ return false;
17
+ }
44
18
 
45
- function renderImageToDataURL(img, options, doSquash) {
46
- var canvas = document.createElement('canvas');
47
- renderImageToCanvas(img, canvas, options, doSquash);
48
- return canvas.toDataURL("image/jpeg", options.quality || 0.8);
19
+ function detectVerticalSquash(img, iw, ih) {
20
+ const canvas = document.createElement('canvas');
21
+ canvas.width = 1;
22
+ canvas.height = ih;
23
+ const ctx = canvas.getContext('2d');
24
+ ctx.drawImage(img, 0, 0);
25
+ const data = ctx.getImageData(0, 0, 1, ih).data;
26
+ let sy = 0, ey = ih, py = ih;
27
+ while (py > sy) {
28
+ const alpha = data[(py - 1) * 4 + 3];
29
+ if (alpha === 0) ey = py;
30
+ else sy = py;
31
+ py = (ey + sy) >> 1;
49
32
  }
33
+ const ratio = py / ih;
34
+ return ratio === 0 ? 1 : ratio;
35
+ }
36
+
37
+ function renderImageToDataURL(img, options, doSquash) {
38
+ const canvas = document.createElement('canvas');
39
+ renderImageToCanvas(img, canvas, options, doSquash);
40
+ return canvas.toDataURL("image/jpeg", options.quality || 0.8);
41
+ }
42
+
43
+ function renderImageToCanvas(img, canvas, options, doSquash) {
44
+ let iw = img.naturalWidth, ih = img.naturalHeight;
45
+ if (!(iw + ih)) return;
50
46
 
51
- function renderImageToCanvas(img, canvas, options, doSquash) {
52
- var iw = img.naturalWidth, ih = img.naturalHeight;
53
- if (!(iw + ih)) return;
54
- var width = options.width, height = options.height;
55
- var ctx = canvas.getContext('2d');
56
- ctx.save();
57
- transformCoordinate(canvas, ctx, width, height, options.orientation);
58
- var subsampled = detectSubsampling(img);
59
- if (subsampled) { iw /= 2; ih /= 2; }
60
- var d = 1024;
61
- var tmpCanvas = document.createElement('canvas');
62
- tmpCanvas.width = tmpCanvas.height = d;
63
- var tmpCtx = tmpCanvas.getContext('2d');
64
- var vertSquashRatio = doSquash ? detectVerticalSquash(img, iw, ih) : 1;
65
- var dw = Math.ceil(d * width / iw);
66
- var dh = Math.ceil(d * height / ih / vertSquashRatio);
67
- var sy = 0, dy = 0;
68
- while (sy < ih) {
69
- var sx = 0, dx = 0;
70
- while (sx < iw) {
71
- tmpCtx.clearRect(0, 0, d, d);
72
- tmpCtx.drawImage(img, -sx, -sy);
73
- ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);
74
- sx += d; dx += dw;
75
- }
76
- sy += d; dy += dh;
47
+ const width = options.width, height = options.height;
48
+ const ctx = canvas.getContext('2d');
49
+ ctx.save();
50
+ transformCoordinate(canvas, ctx, width, height, options.orientation);
51
+
52
+ const subsampled = detectSubsampling(img);
53
+ if (subsampled) { iw /= 2; ih /= 2; }
54
+
55
+ const d = 1024;
56
+ const tmpCanvas = document.createElement('canvas');
57
+ tmpCanvas.width = tmpCanvas.height = d;
58
+ const tmpCtx = tmpCanvas.getContext('2d');
59
+
60
+ const vertSquashRatio = doSquash ? detectVerticalSquash(img, iw, ih) : 1;
61
+ const dw = Math.ceil(d * width / iw);
62
+ const dh = Math.ceil(d * height / ih / vertSquashRatio);
63
+
64
+ let sy = 0, dy = 0;
65
+ while (sy < ih) {
66
+ let sx = 0, dx = 0;
67
+ while (sx < iw) {
68
+ tmpCtx.clearRect(0, 0, d, d);
69
+ tmpCtx.drawImage(img, -sx, -sy);
70
+ ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);
71
+ sx += d;
72
+ dx += dw;
77
73
  }
78
- ctx.restore();
79
- tmpCanvas = tmpCtx = null;
74
+ sy += d;
75
+ dy += dh;
80
76
  }
77
+ ctx.restore();
78
+ }
81
79
 
82
- function transformCoordinate(canvas, ctx, width, height, orientation) {
83
- switch (orientation) {
84
- case 5: case 6: case 7: case 8: canvas.width = height; canvas.height = width; break;
85
- default: canvas.width = width; canvas.height = height;
86
- }
87
- switch (orientation) {
88
- case 2: ctx.translate(width, 0); ctx.scale(-1, 1); break;
89
- case 3: ctx.translate(width, height); ctx.rotate(Math.PI); break;
90
- case 4: ctx.translate(0, height); ctx.scale(1, -1); break;
91
- case 5: ctx.rotate(0.5 * Math.PI); ctx.scale(1, -1); break;
92
- case 6: ctx.rotate(0.5 * Math.PI); ctx.translate(0, -height); break;
93
- case 7: ctx.rotate(0.5 * Math.PI); ctx.translate(width, -height); ctx.scale(-1, 1); break;
94
- case 8: ctx.rotate(-0.5 * Math.PI); ctx.translate(-width, 0); break;
95
- }
80
+ function transformCoordinate(canvas, ctx, width, height, orientation) {
81
+ switch (orientation) {
82
+ case 5: case 6: case 7: case 8:
83
+ canvas.width = height;
84
+ canvas.height = width;
85
+ break;
86
+ default:
87
+ canvas.width = width;
88
+ canvas.height = height;
89
+ }
90
+ switch (orientation) {
91
+ case 2: ctx.translate(width, 0); ctx.scale(-1, 1); break;
92
+ case 3: ctx.translate(width, height); ctx.rotate(Math.PI); break;
93
+ case 4: ctx.translate(0, height); ctx.scale(1, -1); break;
94
+ case 5: ctx.rotate(0.5 * Math.PI); ctx.scale(1, -1); break;
95
+ case 6: ctx.rotate(0.5 * Math.PI); ctx.translate(0, -height); break;
96
+ case 7: ctx.rotate(0.5 * Math.PI); ctx.translate(width, -height); ctx.scale(-1, 1); break;
97
+ case 8: ctx.rotate(-0.5 * Math.PI); ctx.translate(-width, 0); break;
96
98
  }
99
+ }
97
100
 
98
- var URL = window.URL && window.URL.createObjectURL ? window.URL :
99
- window.webkitURL && window.webkitURL.createObjectURL ? window.webkitURL : null;
101
+ const URL = window.URL && window.URL.createObjectURL ? window.URL :
102
+ window.webkitURL && window.webkitURL.createObjectURL ? window.webkitURL : null;
100
103
 
101
- // -------------------------
102
- // MegaPixImage class
103
- // -------------------------
104
- function MegaPixImage(srcImage) {
104
+ // -------------------------
105
+ // MegaPixImage class
106
+ // -------------------------
107
+ class MegaPixImage {
108
+ constructor(srcImage) {
105
109
  if (window.Blob && srcImage instanceof Blob) {
106
- if (!URL) { throw Error("No createObjectURL function found"); }
107
- var img = new Image();
110
+ if (!URL) throw Error("No createObjectURL function found");
111
+ const img = new Image();
108
112
  img.src = URL.createObjectURL(srcImage);
109
113
  this.blob = srcImage;
110
114
  srcImage = img;
111
115
  }
112
116
  if (!srcImage.naturalWidth && !srcImage.naturalHeight) {
113
- var _this = this;
117
+ this.imageLoadListeners = [];
118
+ const _this = this;
114
119
  srcImage.onload = srcImage.onerror = function () {
115
- var listeners = _this.imageLoadListeners;
120
+ const listeners = _this.imageLoadListeners;
116
121
  if (listeners) {
117
122
  _this.imageLoadListeners = null;
118
- for (var i = 0; i < listeners.length; i++) { listeners[i](); }
123
+ listeners.forEach(fn => fn());
119
124
  }
120
125
  };
121
- this.imageLoadListeners = [];
122
126
  }
123
127
  this.srcImage = srcImage;
124
128
  }
125
129
 
126
- MegaPixImage.prototype.render = function (target, options, callback) {
130
+ render(target, options, callback) {
127
131
  if (this.imageLoadListeners) {
128
- var _this = this;
129
- this.imageLoadListeners.push(function () { _this.render(target, options, callback); });
132
+ this.imageLoadListeners.push(() => { this.render(target, options, callback); });
130
133
  return;
131
134
  }
132
135
  options = options || {};
133
- var imgWidth = this.srcImage.naturalWidth, imgHeight = this.srcImage.naturalHeight,
134
- width = options.width, height = options.height,
135
- maxWidth = options.maxWidth, maxHeight = options.maxHeight,
136
- doSquash = !this.blob || this.blob.type === 'image/jpeg';
137
- if (width && !height) { height = (imgHeight * width / imgWidth) << 0; }
138
- else if (height && !width) { width = (imgWidth * height / imgHeight) << 0; }
136
+ const imgWidth = this.srcImage.naturalWidth, imgHeight = this.srcImage.naturalHeight;
137
+ let width = options.width, height = options.height;
138
+ const maxWidth = options.maxWidth, maxHeight = options.maxHeight;
139
+ const doSquash = !this.blob || this.blob.type === 'image/jpeg';
140
+
141
+ if (width && !height) height = (imgHeight * width / imgWidth) << 0;
142
+ else if (height && !width) width = (imgWidth * height / imgHeight) << 0;
139
143
  else { width = imgWidth; height = imgHeight; }
144
+
140
145
  if (maxWidth && width > maxWidth) { width = maxWidth; height = (imgHeight * width / imgWidth) << 0; }
141
146
  if (maxHeight && height > maxHeight) { height = maxHeight; width = (imgWidth * height / imgHeight) << 0; }
142
- var opt = { width: width, height: height };
143
- for (var k in options) opt[k] = options[k];
144
-
145
- var tagName = target.tagName.toLowerCase();
146
- if (tagName === 'img') { target.src = renderImageToDataURL(this.srcImage, opt, doSquash); }
147
- else if (tagName === 'canvas') { renderImageToCanvas(this.srcImage, target, opt, doSquash); }
148
- if (typeof this.onrender === 'function') { this.onrender(target); }
149
- if (callback) { callback(); }
150
- if (this.blob) { this.blob = null; URL.revokeObjectURL(this.srcImage.src); }
151
- };
152
147
 
153
- // -------------------------
154
- // Export as ESM default
155
- // -------------------------
156
- return MegaPixImage;
148
+ const opt = { width, height, ...options };
149
+ const tagName = target.tagName.toLowerCase();
150
+ if (tagName === 'img') target.src = renderImageToDataURL(this.srcImage, opt, doSquash);
151
+ else if (tagName === 'canvas') renderImageToCanvas(this.srcImage, target, opt, doSquash);
152
+
153
+ if (typeof this.onrender === 'function') this.onrender(target);
154
+ if (callback) callback();
155
+ if (this.blob) { this.blob = null; URL.revokeObjectURL(this.srcImage.src); }
156
+ }
157
+ }
157
158
 
158
- }));
159
+ // -------------------------
160
+ // ESM export default
161
+ // -------------------------
162
+ export default MegaPixImage;