@zhijiancloud/bpm 0.0.7 → 0.0.9

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.
Files changed (120) hide show
  1. package/dist/bpmArea.umd.js +1 -0
  2. package/dist/bpmAudit.umd.js +1 -1
  3. package/dist/bpmField.umd.js +6 -6
  4. package/dist/bpmFormField.umd.js +6 -6
  5. package/dist/bpmSelect.umd.js +1 -1
  6. package/dist/bpmSelectCheckItem.umd.js +1 -1
  7. package/dist/bpmSelectEntranceForm.umd.js +3 -3
  8. package/dist/bpmSelectFromField.umd.js +1 -1
  9. package/dist/bpmSubForm.umd.js +1 -1
  10. package/dist/bpmText.umd.js +1 -1
  11. package/dist/css/bpmSelectCheckItem.css +1 -1
  12. package/dist/css/bpmSubForm.css +1 -0
  13. package/dist/css/index.css +1 -1
  14. package/dist/index.umd.js +6 -6
  15. package/package.json +3 -4
  16. package/components/.DS_Store +0 -0
  17. package/components/api/batch-loader.js +0 -61
  18. package/components/api/index.js +0 -108
  19. package/components/css/bpmAudit.less +0 -13
  20. package/components/css/bpmMulFile.less +0 -62
  21. package/components/css/bpmSelectCheckItem.less +0 -4
  22. package/components/css/bpmSelectEntranceForm.less +0 -62
  23. package/components/css/bpmSelectFromForm.less +0 -10
  24. package/components/css/bpmSelectFromId.less +0 -33
  25. package/components/css/bpmSelectHouseOwner.less +0 -30
  26. package/components/css/bpmSignature.less +0 -40
  27. package/components/css/bpmText.less +0 -39
  28. package/components/css/common.less +0 -43
  29. package/components/css/demo.less +0 -3
  30. package/components/css/demo2.less +0 -3
  31. package/components/css/index.less +0 -8
  32. package/components/lib/bpmAudit/index.js +0 -7
  33. package/components/lib/bpmAudit/src/main.vue +0 -117
  34. package/components/lib/bpmAudit/src/part/auditor/audit-new.vue +0 -534
  35. package/components/lib/bpmAudit/src/part/auditor/audit-select.vue +0 -127
  36. package/components/lib/bpmAudit/src/part/auditor/audit-with-others.vue +0 -634
  37. package/components/lib/bpmAudit/src/part/auditor.vue +0 -54
  38. package/components/lib/bpmAudit/src/part/editor.vue +0 -318
  39. package/components/lib/bpmAudit/src/part/reader.vue +0 -218
  40. package/components/lib/bpmDateTime/index.js +0 -7
  41. package/components/lib/bpmDateTime/src/main.vue +0 -82
  42. package/components/lib/bpmDateTime/src/part/editor.vue +0 -126
  43. package/components/lib/bpmDateTime/src/part/reader.vue +0 -55
  44. package/components/lib/bpmField/index.js +0 -7
  45. package/components/lib/bpmField/src/main.vue +0 -31
  46. package/components/lib/bpmFieldsFilter/index.js +0 -7
  47. package/components/lib/bpmFieldsFilter/src/main.vue +0 -324
  48. package/components/lib/bpmFormField/index.js +0 -7
  49. package/components/lib/bpmFormField/src/lib/form_mixin.js +0 -818
  50. package/components/lib/bpmFormField/src/lib/mixin.js +0 -245
  51. package/components/lib/bpmFormField/src/main.vue +0 -35
  52. package/components/lib/bpmMulFile/index.js +0 -7
  53. package/components/lib/bpmMulFile/src/main.vue +0 -85
  54. package/components/lib/bpmMulFile/src/part/editor.vue +0 -433
  55. package/components/lib/bpmMulFile/src/part/lib/compressImageUtils.js +0 -226
  56. package/components/lib/bpmMulFile/src/part/lib/utils.js +0 -281
  57. package/components/lib/bpmMulFile/src/part/reader.vue +0 -282
  58. package/components/lib/bpmMulImage/index.js +0 -7
  59. package/components/lib/bpmMulImage/src/main.vue +0 -86
  60. package/components/lib/bpmMulImage/src/part/editor.vue +0 -449
  61. package/components/lib/bpmMulImage/src/part/lib/compressImageUtils.js +0 -226
  62. package/components/lib/bpmMulImage/src/part/lib/utils.js +0 -281
  63. package/components/lib/bpmMulImage/src/part/reader.vue +0 -181
  64. package/components/lib/bpmNumber/index.js +0 -7
  65. package/components/lib/bpmNumber/src/main.vue +0 -83
  66. package/components/lib/bpmNumber/src/part/editor.vue +0 -47
  67. package/components/lib/bpmNumber/src/part/reader.vue +0 -7
  68. package/components/lib/bpmSelect/index.js +0 -7
  69. package/components/lib/bpmSelect/src/main.vue +0 -90
  70. package/components/lib/bpmSelect/src/part/editor.vue +0 -75
  71. package/components/lib/bpmSelect/src/part/reader.vue +0 -53
  72. package/components/lib/bpmSelectCheckItem/index.js +0 -7
  73. package/components/lib/bpmSelectCheckItem/src/main.vue +0 -101
  74. package/components/lib/bpmSelectCheckItem/src/part/editor.vue +0 -103
  75. package/components/lib/bpmSelectCheckItem/src/part/reader.vue +0 -7
  76. package/components/lib/bpmSelectEntranceForm/index.js +0 -7
  77. package/components/lib/bpmSelectEntranceForm/src/main.vue +0 -529
  78. package/components/lib/bpmSelectFromField/index.js +0 -7
  79. package/components/lib/bpmSelectFromField/src/main.vue +0 -98
  80. package/components/lib/bpmSelectFromField/src/part/editor.vue +0 -96
  81. package/components/lib/bpmSelectFromField/src/part/reader.vue +0 -7
  82. package/components/lib/bpmSelectFromForm/index.js +0 -7
  83. package/components/lib/bpmSelectFromForm/src/main.vue +0 -103
  84. package/components/lib/bpmSelectFromForm/src/part/editor.vue +0 -178
  85. package/components/lib/bpmSelectFromForm/src/part/reader.vue +0 -7
  86. package/components/lib/bpmSelectFromId/index.js +0 -7
  87. package/components/lib/bpmSelectFromId/src/main.vue +0 -102
  88. package/components/lib/bpmSelectFromId/src/part/editor.vue +0 -260
  89. package/components/lib/bpmSelectFromId/src/part/reader.vue +0 -7
  90. package/components/lib/bpmSelectHouseOwner/index.js +0 -7
  91. package/components/lib/bpmSelectHouseOwner/src/main.vue +0 -102
  92. package/components/lib/bpmSelectHouseOwner/src/part/editor.vue +0 -101
  93. package/components/lib/bpmSelectHouseOwner/src/part/reader.vue +0 -17
  94. package/components/lib/bpmSelectIssue/index.js +0 -7
  95. package/components/lib/bpmSelectIssue/src/main.vue +0 -180
  96. package/components/lib/bpmSignature/index.js +0 -7
  97. package/components/lib/bpmSignature/src/main.vue +0 -248
  98. package/components/lib/bpmSubForm/index.js +0 -7
  99. package/components/lib/bpmSubForm/src/main.vue +0 -203
  100. package/components/lib/bpmText/index.ts +0 -13
  101. package/components/lib/bpmText/src/main.vue +0 -87
  102. package/components/lib/bpmText/src/part/editor.vue +0 -104
  103. package/components/lib/bpmText/src/part/reader.vue +0 -7
  104. package/components/lib/bpmTime/index.js +0 -7
  105. package/components/lib/bpmTime/src/main.vue +0 -83
  106. package/components/lib/bpmTime/src/part/editor.vue +0 -55
  107. package/components/lib/bpmTime/src/part/reader.vue +0 -24
  108. package/components/lib/demo/index.js +0 -7
  109. package/components/lib/demo/src/main.vue +0 -11
  110. package/components/lib/demo2/index.js +0 -7
  111. package/components/lib/demo2/src/main.vue +0 -11
  112. package/components/lib/field-const.js +0 -472
  113. package/components/lib/index.ts +0 -102
  114. package/components/lib/mixins/RemoteSelectReader.vue +0 -55
  115. package/components/lib/mixins/TextReader.vue +0 -22
  116. package/components/lib/net.js +0 -21
  117. package/components/lib/utils.js +0 -89
  118. package/components/mixins/field_base_mixin.vue +0 -188
  119. package/components/sfc.d.ts +0 -27
  120. package/components/vendor/draw.js +0 -240
@@ -1,449 +0,0 @@
1
- <template>
2
- <div class="bpm-mul-image-edit">
3
- <el-upload
4
- ref="uploader"
5
- :action="url"
6
- name="userfile"
7
- :show-file-list="false"
8
- multiple
9
- :limit="maxCount"
10
- :accept="extensions"
11
- :before-upload="handleAdd"
12
- :on-success="onUploaded"
13
- :on-error="onFail"
14
- :file-list="fileList"
15
- v-bind="$attrs"
16
- v-on="$listeners"
17
- >
18
- <el-button size="small" type="primary" slot="trigger" :disabled="disabled"
19
- >点击上传</el-button
20
- >
21
- </el-upload>
22
- <div class="row gutter-sm q-my-sm file-list">
23
- <template v-if="curVal && curVal.length">
24
- <viewer
25
- :images="photo"
26
- rebuild
27
- class="row gutter-sm q-my-sm file-list"
28
- style="width: 100%"
29
- @inited="inited"
30
- >
31
- <div class="col-12 file-box" v-for="item in curVal" :key="item.md5">
32
- <span
33
- class="file-content"
34
- @click="previewImg(item)"
35
- v-if="isImageFile(item)"
36
- >
37
- <img class="preview-img" :src="fileLink(item)" />
38
- </span>
39
- <span @click="preview(item)" v-else class="file-content q-mb-xs">
40
- <div class="text-left text-faded">
41
- <i
42
- aria-hidden="true"
43
- class="q-icon fa fa-file-pdf-o"
44
- :class="getFileTypeClass(item)"
45
- ></i>
46
- </div>
47
- </span>
48
- <div
49
- class="relative-position file-link ellipsis"
50
- :title="item.name"
51
- >
52
- {{ item.name }}
53
- </div>
54
- <div class="file-remove" @click="remove(item.md5, item)">删除</div>
55
- </div>
56
- </viewer>
57
- </template>
58
- <template v-else>
59
- <div class="col-auto" style="padding-top: 0px; font-size: 12px">
60
- <!-- {{ $z("未发现上传文件", "b2.common.not_found_file") }} -->
61
- 未发现上传文件
62
- </div>
63
- </template>
64
- </div>
65
- <img id="image" src="" style="display: none" />
66
- <div
67
- id="container"
68
- style="height: 100px; width: 109px; display: none"
69
- ></div>
70
- </div>
71
- </template>
72
-
73
-
74
- <script>
75
- import _ from "lodash";
76
- import { Upload, Button, Dialog } from "element-ui";
77
- import { urlAppendParam, isMobile } from "../../../utils";
78
-
79
- Vue.use(Upload);
80
- Vue.use(Button);
81
- Vue.use(Dialog);
82
- import Vue from "vue";
83
- import Viewer from "v-viewer";
84
- import "viewerjs/dist/viewer.css";
85
- import "font-awesome/css/font-awesome.min.css";
86
- const piexif = require("piexifjs");
87
- import { comparessImg, ImageTool } from "./lib/compressImageUtils";
88
- import { showGPSInfo, getFileType, gethashcode } from "./lib/utils";
89
- Vue.use(Viewer);
90
- Viewer.setDefaults({
91
- Options: {
92
- inline: true,
93
- button: true,
94
- navbar: true,
95
- title: true,
96
- toolbar: true,
97
- tooltip: true,
98
- movable: true,
99
- zoomable: true,
100
- rotatable: true,
101
- scalable: true,
102
- transition: true,
103
- fullscreen: true,
104
- keyboard: true,
105
- url: "data-source",
106
- },
107
- });
108
- var AMap = null;
109
- export default {
110
- props: {
111
- type: {
112
- type: String,
113
- default: 'MulImage'
114
- },
115
- value: {},
116
- fieldConf: {},
117
- row: {},
118
- extensions: {
119
- type: String,
120
- default() {
121
- return "jpg,.jpeg,.png,.dwg";
122
- },
123
- },
124
- },
125
- data() {
126
- return {
127
- curVal: [],
128
- fileList: [],
129
- opened: false,
130
- officeUrl: "",
131
- windowH: 0,
132
- };
133
- },
134
- watch: {
135
- value() {
136
- this.curVal =
137
- this.isSign && _.isString(this.value) && this.value
138
- ? [
139
- {
140
- md5: this.value,
141
- name: "",
142
- type: "image/png",
143
- },
144
- ]
145
- : this.value;
146
- },
147
- },
148
- computed: {
149
- url() {
150
- return "/platform/v1/papi/app_file/upload/";
151
- },
152
- isSign() {
153
- return this.type === 'Signature' || this.fieldConf.type == "Signature";
154
- },
155
- photo() {
156
- let list = [];
157
- _.each(this.curVal, (item) => {
158
- if (this.isImageFile(item)) {
159
- let link = this.fileLink(item, 600);
160
- list.push(link);
161
- }
162
- });
163
- return list;
164
- },
165
- photoMd5s() {
166
- let list = [];
167
- _.each(this.curVal, (item) => {
168
- if (this.isImageFile(item)) {
169
- list.push(item.md5);
170
- }
171
- });
172
- return list;
173
- },
174
- maxCountConf() {
175
- return _.get(this.fieldConf, "check.max_count");
176
- },
177
- maxCount() {
178
- return this.maxCountConf - this.curVal && this.curVal.length;
179
- },
180
- disabled() {
181
- let val = this.curVal ? this.curVal : [];
182
- return val.length >= this.maxCountConf;
183
- },
184
- },
185
- created() {
186
- // getAgent.register();
187
- },
188
- mounted() {
189
- this.curVal =
190
- this.isSign && _.isString(this.value) && this.value
191
- ? [
192
- {
193
- md5: this.value,
194
- name: "签名",
195
- type: "image/png",
196
- },
197
- ]
198
- : this.value;
199
- this.windowH = (document.body.clientHeight / 100) * 99 - 50;
200
-
201
- //获取定位信息,写入图片
202
- this.appendJs(
203
- `https://webapi.amap.com/maps?v=1.4.15&key=c2195d5de1c163ebfb118bad93c8bbd3`,
204
- () => {
205
- var mapObj = new AMap.Map("container", {
206
- resizeEnable: true,
207
- });
208
- mapObj.plugin("AMap.Geolocation", () => {
209
- let geolocation = new AMap.Geolocation({
210
- enableHighAccuracy: true, //是否使用高精度定位,默认:true
211
- timeout: 10000, //超过10秒后停止定位,默认:无穷大
212
- maximumAge: 0, //定位结果缓存0毫秒,默认:0
213
- convert: true, //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
214
- showButton: true, //显示定位按钮,默认:true
215
- buttonPosition: "LB", //定位按钮停靠位置,默认:'LB',左下角
216
- buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
217
- showMarker: true, //定位成功后在定位到的位置显示点标记,默认:true
218
- showCircle: true, //定位成功后用圆圈表示定位精度范围,默认:true
219
- panToLocation: true, //定位成功后将定位到的位置作为地图中心点,默认:true
220
- zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
221
- });
222
- mapObj.addControl(geolocation);
223
- geolocation.getCurrentPosition();
224
- AMap.event.addListener(geolocation, "complete", (result) => {
225
- this.position = result.position;
226
- }); //返回定位信息
227
- AMap.event.addListener(geolocation, "error", (err) => {
228
- console.log("定位出错-error", err);
229
- }); //返回定位出错信息
230
- });
231
- }
232
- );
233
- },
234
- methods: {
235
- appendJs(url) {
236
- let link = document.createElement("script");
237
- let attrMap = {
238
- type: "text/javascript",
239
- async: /^http/.test(url) ? "async" : "",
240
- src: url,
241
- };
242
- for (var key in attrMap) {
243
- link[key] = attrMap[key];
244
- }
245
- document.head.appendChild(link);
246
- },
247
- inited(viewer) {
248
- viewer.options.view = this.view;
249
- this.$viewer = viewer;
250
- },
251
- view(e) {
252
- let index = e.detail.index;
253
- let list = _.filter(this.curVal, (item) => {
254
- return this.isImageFile(item);
255
- });
256
- let item = _.get(list, index);
257
- showGPSInfo(item);
258
- },
259
- previewImg(item) {
260
- let index = _.indexOf(this.photoMd5s, item.md5);
261
- this.$viewer.view(index);
262
- },
263
- isDwg(item) {
264
- return _.endsWith(item.name, ".dwg");
265
- },
266
- getFileTypeClass(item) {
267
- let fileSuffix = getFileType(item.type);
268
- fileSuffix = fileSuffix ? fileSuffix : getFileType(item.name);
269
-
270
- if (_.endsWith(item.name, ".dwg")) {
271
- fileSuffix = "dwg";
272
- }
273
- let typeMap = {
274
- document: "fa-file-word-o",
275
- sheet: "fa-file-excel-o",
276
- doc: "fa-file-word-o",
277
- docx: "fa-file-word-o",
278
- xlsx: "fa-file-excel-o",
279
- "ms-excel": "fa-file-excel-o",
280
- dwg: "fa-file-image-o",
281
- png: "fa-file-image-o",
282
- jpg: "fa-file-image-o",
283
- };
284
- return _.get(typeMap, fileSuffix);
285
- },
286
- handleAdd() {
287
- //图片进行压缩和地理信息写入
288
- let queue = this.fileList;
289
- _.each(queue, (file, index) => {
290
- comparessImg(file, (result, hasExif) => {
291
- if (result) {
292
- ImageTool.getSegments(new Blob([file]), (segments) => {
293
- let newFile = this.dataURLtoFile(result, file.name);
294
- let exifInfo = ImageTool.getEXIF(segments); //获取exif信息
295
- if (!_.isEmpty(exifInfo) && hasExif) {
296
- ImageTool.insertEXIF(newFile, exifInfo, (newImage) => {
297
- let bolb = new Blob([newImage], {
298
- type: file.type,
299
- });
300
- bolb.name = file.name;
301
- bolb.lastModifiedDate = new Date();
302
- this.fileList[index] = bolb;
303
- });
304
- } else {
305
- let zeroth = {};
306
- let exif = {};
307
- let gps = {};
308
- zeroth[piexif.ImageIFD.Make] = "lse";
309
- //经纬度写入
310
- let lat = this.position.lat;
311
- let lng = this.position.lng;
312
- gps[piexif.GPSIFD.GPSLatitudeRef] = lat < 0 ? "S" : "N";
313
- gps[piexif.GPSIFD.GPSLatitude] =
314
- piexif.GPSHelper.degToDmsRational(lat);
315
- gps[piexif.GPSIFD.GPSLongitudeRef] = lng < 0 ? "W" : "E";
316
- gps[piexif.GPSIFD.GPSLongitude] =
317
- piexif.GPSHelper.degToDmsRational(lng);
318
- //方位角写入
319
- gps[piexif.GPSIFD.GPSImgDirection] = [123456, 100];
320
- let exifObj = { "0th": zeroth, Exif: exif, GPS: gps }; // 定义一个 exifObj 对象
321
- let exifStr = piexif.dump(exifObj); // 通过 piexif 将 exifObj 对象转换为字符串
322
- let resultBase64 = piexif.insert(exifStr, result);
323
- let newFile = this.dataURLtoFile(resultBase64, file.name);
324
- this.fileList[index] = newFile;
325
- }
326
- });
327
- }
328
- });
329
- });
330
- // this.$refs.uploader.submit();
331
- },
332
- dataURLtoFile(dataurl, filename) {
333
- //将base64转换为文件
334
- let arr = dataurl.split(","),
335
- mime = arr[0].match(/:(.*?);/)[1],
336
- bstr = atob(arr[1]),
337
- n = bstr.length,
338
- u8arr = new Uint8Array(n);
339
- while (n--) {
340
- u8arr[n] = bstr.charCodeAt(n);
341
- }
342
- return new File([u8arr], filename, { type: mime });
343
- },
344
- isImageFile(item) {
345
- return _.startsWith(item.type, "image");
346
- },
347
- itemSideImageAttr(item) {
348
- let attrs = {};
349
- if (this.isImageFile(item)) {
350
- attrs.image = this.fileLink(item);
351
- } else {
352
- attrs.icon = "fa fa-file";
353
- }
354
- return attrs;
355
- },
356
- fileLink(item) {
357
- //获取预览的文件或图片地址
358
- if (!item || !item.md5) return;
359
- let isImg = this.isImageFile(item);
360
- let args = {
361
- file_md5: item.md5,
362
- };
363
- // let token = zj.utils.pageParam().token;
364
- // if (token) {
365
- // args.token = token;
366
- // }
367
-
368
- if (isImg) {
369
- // args.webp = 1
370
- // args.width = 600;
371
- } else {
372
- args.is_file = 1;
373
- }
374
-
375
- return urlAppendParam("/platform/v1/papi/web_file/image_view/", args);
376
- },
377
- async preview(item) {
378
- if (item.type == "dwg/dwg") return;
379
- let res = await zj.net.w.noapi({
380
- url: `/platform/v1/papi/app_file/download/?file_md5=${item.md5}&webp=0`,
381
- });
382
- let preview_url = _.get(res, "url_list.0.path.0");
383
- let fileSuffix = getFileType(preview_url);
384
- if (item.type == "application/pdf") fileSuffix = "pdf";
385
- if (item.type == "application/vnd.ms-excel") fileSuffix = "ms-excel";
386
- let typeMap = {
387
- document: "Word.Document",
388
- docx: "Word.Document",
389
- doc: "Word.Document",
390
- sheet: "Excel.Sheet",
391
- pdf: "pdf",
392
- xlsx: "Excel.Sheet",
393
- "ms-excel": "Excel.Sheet",
394
- };
395
- let hash = gethashcode();
396
- let url = `https://${window.location.host}/zj_of/v1/papi/file/read_only/?md5=${item.md5}&type=${typeMap[fileSuffix]}&sign=${hash}`;
397
- let result = await zj.net.w.noapi({
398
- url: `/zj_of/v1/papi/file/using_engine/`,
399
- });
400
- if (result.engine != "wps")
401
- url =
402
- "https://view.officeapps.live.com/op/embed.aspx?src=" +
403
- encodeURIComponent(preview_url);
404
- if (fileSuffix == "pdf") {
405
- let index = preview_url.lastIndexOf(".com");
406
- preview_url = preview_url.substring(index + 4, preview_url.length);
407
- preview_url = encodeURIComponent(preview_url);
408
- if (isMobile())
409
- url = `/public/app3/bpm/view_pdf.html?url=${preview_url}`;
410
- else url = `/public/bpm/app/view_pdf.html?url=${preview_url}`;
411
- }
412
- this.officeUrl = url;
413
- this.opened = true;
414
- },
415
- onFail(err, file) {
416
- let message = `${file.name}上传失败`;
417
- console.log("err:", message);
418
- },
419
- onUploaded(response, file) {
420
- console.log("file", file);
421
-
422
- let items = _.isArray(this.curVal) ? this.curVal : [];
423
-
424
- items.push({
425
- name: file.name,
426
- type: _.get(file, "raw.type"),
427
- md5: _.get(response, "data.file_md5"),
428
- });
429
- this.curVal = _.cloneDeep(items);
430
- let result = this.isSign ? _.get( this.curVal, "0.md5", "") : this.curVal;
431
- this.$emit("input", result);
432
-
433
- },
434
- remove(md5) {
435
- this.curVal = _.filter(this.curVal, (item) => item.md5 != md5);
436
- this.$refs.uploader.queue = [];
437
- let result = this.isSign ? _.get( this.curVal, "0.md5", "") : this.curVal;
438
- this.$emit("input", result);
439
- },
440
- onHide() {
441
- this.opened = false;
442
- },
443
- onOpen() {
444
- this.opened = true;
445
- },
446
- },
447
- };
448
- </script>
449
-
@@ -1,226 +0,0 @@
1
- import Exif from 'exif-js'
2
- // let Orientation
3
- export function comparessImg(file, callback) {
4
- //判断是否为图片文件
5
- if (file.type.indexOf('image') == -1) {
6
- callback(null)
7
- } else {
8
-
9
- let reader = new FileReader();
10
- let image = new Image();
11
- reader.readAsDataURL(file);
12
- reader.onload = function () {
13
- file.src = this.result;
14
- image.onload = function () {
15
- let width = image.width;
16
- let height = image.height;
17
- file.width = width;
18
- file.height = height;
19
-
20
- };
21
- image.src = file.src; //页面上显示所选择的图片
22
- imgCompress(file, {
23
- quality: 0.4
24
- }, file, callback)
25
-
26
- }
27
-
28
- }
29
- }
30
-
31
- function imgCompress(path, obj, file, callback) { //path是指上传的图片,obj是压缩的品质,越低越模糊
32
- var img = new Image();
33
- img.src = path.src;
34
- img.onload = function () {
35
- var that = this; //这里的this 是把img的对象指向改变为that
36
- // 默认按比例压缩
37
- var w = that.width,
38
- h = that.height,
39
- scale = w / h;
40
- w = obj.width || w;
41
- h = obj.height || (w / scale);
42
- var quality = 0.7; // 默认图片质量为0.7
43
- //生成canvas
44
- var canvas = document.createElement('canvas');
45
- var ctx = canvas.getContext('2d');
46
- // 创建属性节点
47
- var anw = document.createAttribute("width");
48
- anw.nodeValue = w;
49
- var anh = document.createAttribute("height");
50
- anh.nodeValue = h;
51
- canvas.setAttributeNode(anw);
52
- canvas.setAttributeNode(anh);
53
- try {
54
- Exif.getData(file, function () {
55
- let GPSLatitude = Exif.getTag(this, 'GPSLatitude')
56
- // Orientation = Exif.getTag(this, 'Orientation');
57
- // console.log("Orientation", Orientation)
58
- // if (Orientation == 6) {
59
- // // canvas.width= that.height;
60
- // // canvas.height= that.width;
61
- // // ctx.rotate(0.5*Math.PI);
62
- // // ctx.drawImage(that, 0, -h, w, h);
63
- // }
64
- // else{
65
- // ctx.drawImage(that, 0, 0, w, h);
66
- // }
67
- ctx.drawImage(that, 0, 0, w, h);
68
-
69
-
70
- // 图像质量
71
- if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
72
- quality = obj.quality;
73
- }
74
- // quality值越小,所绘制出的图像越模糊
75
- var base64 = canvas.toDataURL('image/jpeg', quality);
76
- // 回调函数返回base64的值
77
- // debugger
78
- callback(base64, GPSLatitude)
79
- })
80
- } catch (error) {
81
- ctx.drawImage(that, 0, 0, w, h);
82
- if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
83
- quality = obj.quality;
84
- }
85
- // quality值越小,所绘制出的图像越模糊
86
- var base64 = canvas.toDataURL('image/jpeg', quality);
87
- // 回调函数返回base64的值
88
- // debugger
89
- callback(base64, null)
90
- }
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- }
100
- }
101
-
102
- export function convertBase64UrlToBlob(urlData) {
103
- var arr = urlData.split(','),
104
- mime = arr[0].match(/:(.*?);/)[1],
105
- bstr = atob(arr[1]),
106
- n = bstr.length,
107
- u8arr = new Uint8Array(n);
108
- while (n--) {
109
- u8arr[n] = bstr.charCodeAt(n);
110
- }
111
- return new Blob([u8arr], {
112
- type: mime
113
- });
114
- }
115
-
116
-
117
- export var ImageTool = {
118
-
119
- /*
120
- * @param resizedImg{ArrayBuffer|Blob}
121
- * @param exifArr{Array|Uint8Array}
122
- */
123
- insertEXIF: function (resizedImg, exifArr, callback) {
124
- if (resizedImg instanceof Blob) {
125
- var that = this;
126
- var fileReader = new FileReader();
127
- fileReader.onload = function () {
128
- that.insertEXIF(fileReader.result, exifArr, callback);
129
- };
130
- fileReader.readAsArrayBuffer(resizedImg);
131
- } else {
132
- var arr = [].slice.call(new Uint8Array(resizedImg), 0);
133
- if (arr[2] !== 0xff || arr[3] !== 0xe0) {
134
- // throw new Error("Couldn't find APP0 marker from resized image data.");
135
- return resizedImg; //不是标准的JPEG文件
136
- }
137
-
138
- var app0_length = arr[4] * 256 + arr[5]; //两个字节
139
-
140
- var newImage = [0xff, 0xd8].concat(exifArr, arr.slice(4 + app0_length)); //合并文件 SOI + EXIF + 去除APP0的图像信息
141
-
142
- callback(new Uint8Array(newImage));
143
- }
144
- },
145
- /*
146
- * @param segments{Array|Uint8Array}
147
- */
148
- getEXIF: function (segments) {
149
- if (!segments.length) {
150
- return [];
151
- }
152
- var seg = [];
153
- for (var x = 0; x < segments.length; x++) {
154
- var s = segments[x];
155
- //TODO segments
156
- if (s[0] === 0xff && s[1] === 0xe1) { // app1 exif 0xff 0xe1
157
- seg = seg.concat(s);
158
- }
159
- }
160
- return seg;
161
- },
162
- getSegments: function (rawImage, callback) {
163
- if (rawImage instanceof Blob) {
164
- var that = this;
165
- var fileReader = new FileReader();
166
- fileReader.onload = function () {
167
- that.getSegments(fileReader.result,
168
- callback);
169
- };
170
- fileReader.readAsArrayBuffer(rawImage);
171
- } else {
172
- if (!rawImage.length && !rawImage.byteLength) {
173
- return [];
174
- }
175
- var head = 0,
176
- segments = [];
177
- var length, endPoint, seg;
178
- var arr = [].slice.call(new Uint8Array(rawImage), 0);
179
- let x = 1
180
- while (x) {
181
- if (arr[head] === 0xff && arr[head + 1] === 0xda) { //Start of Scan 0xff 0xda SOS
182
- break;
183
- }
184
- if (arr[head] === 0xff && arr[head +
185
- 1] === 0xd8) { //Start of Image 0xff 0xd8 SOI
186
- head += 2;
187
- } else { //找到每个marker
188
- length = arr[head + 2] * 256 + arr[head + 3]; //每个marker 后 的两个字节为 该marker信息的长度
189
- endPoint = head + length + 2;
190
- seg = arr.slice(head, endPoint); //截取信息
191
- head = endPoint;
192
- segments.push(seg); //将每个marker + 信息 push 进去。
193
- }
194
- if (head > arr.length) {
195
- break;
196
- }
197
- }
198
- callback(segments);
199
- }
200
- },
201
- /*
202
- *@param base64{String}
203
- */
204
- decode64: function (base64) {
205
- var b64 = "data:image/jpeg;base64,";
206
- if (base64.slice(0, 23) !== b64) {
207
- return [];
208
- }
209
- var binStr = window.atob(base64.replace(b64, ""));
210
- var buf = new Uint8Array(binStr.length);
211
- for (var i = 0, len = binStr.length; i < len; i++) {
212
- buf[i] = binStr.charCodeAt(i);
213
- }
214
- return buf;
215
- },
216
- /*
217
- *@param arr{Array}
218
- */
219
- encode64: function (arr) {
220
- var data = "";
221
- for (var i = 0, len = arr.length; i < len; i++) {
222
- data += String.fromCharCode(arr[i]);
223
- }
224
- return "data:image/jpeg;base64," + window.btoa(data);
225
- }
226
- };