gis-common 1.1.3 → 1.1.6

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 (2) hide show
  1. package/dist/resource.min.js +203 -26
  2. package/package.json +35 -32
@@ -1,13 +1,13 @@
1
1
  (function webpackUniversalModuleDefinition(root, factory) {
2
2
  if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
3
+ module.exports = factory(require("mqtt"));
4
4
  else if(typeof define === 'function' && define.amd)
5
- define("Gis", [], factory);
5
+ define("Gis", ["mqtt"], factory);
6
6
  else if(typeof exports === 'object')
7
- exports["Gis"] = factory();
7
+ exports["Gis"] = factory(require("mqtt"));
8
8
  else
9
- root["Gis"] = factory();
10
- })(window, function() {
9
+ root["Gis"] = factory(root["mqtt"]);
10
+ })(window, function(__WEBPACK_EXTERNAL_MODULE__0__) {
11
11
  return /******/ (function(modules) { // webpackBootstrap
12
12
  /******/ // The module cache
13
13
  /******/ var installedModules = {};
@@ -91,11 +91,17 @@ return /******/ (function(modules) { // webpackBootstrap
91
91
  /******/
92
92
  /******/
93
93
  /******/ // Load entry module and return exports
94
- /******/ return __webpack_require__(__webpack_require__.s = 0);
94
+ /******/ return __webpack_require__(__webpack_require__.s = 1);
95
95
  /******/ })
96
96
  /************************************************************************/
97
97
  /******/ ([
98
98
  /* 0 */
99
+ /***/ (function(module, exports) {
100
+
101
+ module.exports = __WEBPACK_EXTERNAL_MODULE__0__;
102
+
103
+ /***/ }),
104
+ /* 1 */
99
105
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
100
106
 
101
107
  "use strict";
@@ -126,6 +132,7 @@ __webpack_require__.d(__webpack_exports__, "CanvasDrawer", function() { return /
126
132
  __webpack_require__.d(__webpack_exports__, "ElQuery", function() { return /* reexport */ core_ElQuery; });
127
133
  __webpack_require__.d(__webpack_exports__, "EventDispatcher", function() { return /* reexport */ core_EventDispatcher; });
128
134
  __webpack_require__.d(__webpack_exports__, "HashMap", function() { return /* reexport */ core_HashMap; });
135
+ __webpack_require__.d(__webpack_exports__, "MqttClient", function() { return /* reexport */ core_MqttClient; });
129
136
  __webpack_require__.d(__webpack_exports__, "WebSocketClient", function() { return /* reexport */ core_WebSocketClient; });
130
137
  __webpack_require__.d(__webpack_exports__, "WebStorage", function() { return /* reexport */ core_WebStorage; });
131
138
 
@@ -1269,8 +1276,8 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1269
1276
  * @returns {*}
1270
1277
  */
1271
1278
  convertBase64ToBlob: function convertBase64ToBlob(data) {
1272
- var mimeString = data.split(",")[0].split(":")[1].split(";")[0];
1273
- var byteString = window.atob(data.split(",")[1]);
1279
+ var mimeString = data.split(',')[0].split(':')[1].split(';')[0];
1280
+ var byteString = window.atob(data.split(',')[1]);
1274
1281
  var ab = new ArrayBuffer(byteString.length);
1275
1282
  var ia = new Uint8Array(ab);
1276
1283
 
@@ -1302,19 +1309,19 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1302
1309
  convertUrlToBase64: function convertUrlToBase64(url, width, height) {
1303
1310
  return new Promise(function (resolve, reject) {
1304
1311
  var img = new Image();
1305
- img.crossOrigin = "Anonymous";
1312
+ img.crossOrigin = 'Anonymous';
1306
1313
  img.src = url;
1307
1314
  img.onload = function () {
1308
- var canvas = document.createElement("canvas");
1315
+ var canvas = document.createElement('canvas');
1309
1316
  canvas.width = width || img.width;
1310
1317
  canvas.height = height || img.height;
1311
- var ctx = canvas.getContext("2d");
1318
+ var ctx = canvas.getContext('2d');
1312
1319
  ctx.drawImage(img, 0, 0, img.width, img.height);
1313
- var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
1314
- var dataURL = canvas.toDataURL("image/" + ext);
1320
+ var ext = img.src.substring(img.src.lastIndexOf('.') + 1).toLowerCase();
1321
+ var dataURL = canvas.toDataURL('image/' + ext);
1315
1322
  var base64 = {
1316
1323
  dataURL: dataURL,
1317
- type: "image/" + ext,
1324
+ type: 'image/' + ext,
1318
1325
  ext: ext
1319
1326
  };
1320
1327
  resolve(base64);
@@ -1330,7 +1337,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1330
1337
  * @returns {*}
1331
1338
  */
1332
1339
  convertBase64ToFile: function convertBase64ToFile(dataurl, filename) {
1333
- var arr = dataurl.split(","),
1340
+ var arr = dataurl.split(','),
1334
1341
  mime = arr[0].match(/:(.*?);/)[1],
1335
1342
  bstr = atob(arr[1]),
1336
1343
  n = bstr.length,
@@ -1345,16 +1352,26 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1345
1352
  /**
1346
1353
  * 直接下载文件,支持blob类型和url类型
1347
1354
  *
1348
- * @param {*} url
1355
+ * @param {*} data
1349
1356
  * @param {*} saveName
1350
1357
  */
1351
- downloadFromFile: function downloadFromFile(url, saveName) {
1352
- if ((typeof url === "undefined" ? "undefined" : _typeof(url)) == "object" && url instanceof Blob) {
1353
- url = URL.createObjectURL(url); // 创建blob地址
1358
+ downloadFromFile: function downloadFromFile(data, saveName) {
1359
+ var url = void 0;
1360
+ if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) == 'object') {
1361
+ if (data instanceof Blob) {
1362
+ url = URL.createObjectURL(data); // 创建blob地址
1363
+ } else {
1364
+ var str = JSON.stringify(data);
1365
+ var blob = new Blob([str], { type: 'text/json' }); // json对象
1366
+ url = window.URL.createObjectURL(blob);
1367
+ }
1368
+ } else if (typeof data == 'string') {
1369
+ var _blob = new Blob([data], { type: 'text/json' }); //json文本
1370
+ url = window.URL.createObjectURL(_blob);
1354
1371
  }
1355
- var link = document.createElement("a");
1372
+ var link = document.createElement('a');
1356
1373
  link.href = url;
1357
- link.download = saveName || ""; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
1374
+ link.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
1358
1375
  link.click();
1359
1376
  window.URL.revokeObjectURL(link.href);
1360
1377
  }
@@ -1912,6 +1929,9 @@ var ElQuery = function () {
1912
1929
  var _this3 = this;
1913
1930
 
1914
1931
  this.each(function (obj) {
1932
+ obj.removeEventListener(type, function (e) {
1933
+ callback.call(_this3, e);
1934
+ });
1915
1935
  obj.addEventListener(type, function (e) {
1916
1936
  callback.call(_this3, e);
1917
1937
  });
@@ -2105,27 +2125,184 @@ var HashMap = function () {
2105
2125
  }();
2106
2126
 
2107
2127
  /* harmony default export */ var core_HashMap = (HashMap);
2128
+ // EXTERNAL MODULE: external "mqtt"
2129
+ var external_mqtt_ = __webpack_require__(0);
2130
+
2131
+ // CONCATENATED MODULE: ./src/core/MqttClient.js
2132
+ var MqttClient_createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2133
+
2134
+ function MqttClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2135
+
2136
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2137
+
2138
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2139
+
2140
+
2141
+
2142
+
2143
+
2144
+
2145
+
2146
+ var MqttClient_MqttClient = function (_EventDispatcher) {
2147
+ _inherits(MqttClient, _EventDispatcher);
2148
+
2149
+ /**
2150
+ * Creates an instance of MqttClient.
2151
+ * @param {*} config mqtt实例参数
2152
+ */
2153
+ function MqttClient() {
2154
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2155
+
2156
+ MqttClient_classCallCheck(this, MqttClient);
2157
+
2158
+ var _this = _possibleConstructorReturn(this, (MqttClient.__proto__ || Object.getPrototypeOf(MqttClient)).call(this));
2159
+
2160
+ _this.context = CommUtils.extend(MqttClient.defaultContext, config);
2161
+ _this.options = {
2162
+ connectTimeout: _this.context.MQTT_TIMEOUTM,
2163
+ clientId: CommUtils.generateGuid(),
2164
+ username: _this.context.MQTT_USERNAME,
2165
+ password: _this.context.MQTT_PASSWORD,
2166
+ clean: true
2167
+ };
2168
+ _this.client = Object(external_mqtt_["connect"])(_this.context.MQTT_SERVICE, _this.options);
2169
+ _this._onConnect();
2170
+ _this._onMessage();
2171
+ MqttClient.instance = _this;
2172
+ return _this;
2173
+ }
2174
+
2175
+ MqttClient_createClass(MqttClient, [{
2176
+ key: "_onConnect",
2177
+ value: function _onConnect() {
2178
+ var _this2 = this;
2179
+
2180
+ this.client.on("connect", function () {
2181
+ console.log("链接mqtt成功==>" + _this2.context.MQTT_SERVICE);
2182
+ _this2.dispatchEvent({ type: EventTypeConstant.MQTT_CONNECT, message: _this2 });
2183
+ });
2184
+ this.client.on("error", function (err) {
2185
+ console.log("链接mqtt报错", err);
2186
+ _this2.dispatchEvent({ type: EventTypeConstant.MQTT_ERROR, message: _this2 });
2187
+ _this2.client.end();
2188
+ _this2.client.reconnect();
2189
+ });
2190
+ }
2191
+ }, {
2192
+ key: "_onMessage",
2193
+ value: function _onMessage() {
2194
+ var _this3 = this;
2195
+
2196
+ this.client.on("message", function (topic, message) {
2197
+ var dataString = message;
2198
+ var data = "";
2199
+ if (message instanceof Uint8Array) {
2200
+ dataString = message.toString();
2201
+ }
2202
+ try {
2203
+ data = JSON.parse(dataString);
2204
+ } catch (error) {
2205
+ throw new Error(ErrorTypeConstant.JSON_PARSE_ERROR);
2206
+ }
2207
+ _this3.dispatchEvent({
2208
+ type: EventTypeConstant.MQTT_MESSAGE,
2209
+ message: { topic: topic, data: data }
2210
+ });
2211
+ });
2212
+ }
2213
+ }, {
2214
+ key: "sendMsg",
2215
+ value: function sendMsg(topic, msg) {
2216
+ if (!this.client.connected) {
2217
+ console.error("客户端未连接");
2218
+ return;
2219
+ }
2220
+ this.client.publish(topic, msg, { qos: 1, retain: true });
2221
+ }
2222
+ }, {
2223
+ key: "subscribe",
2224
+ value: function subscribe(topic) {
2225
+ this.client.subscribe(topic, { qos: 1 }, function (error, res) {
2226
+ if (error instanceof Error || res.length === 0) {
2227
+ console.error("\u8BA2\u9605\u5931\u8D25==>" + topic, error);
2228
+ } else {
2229
+ console.log("\u8BA2\u9605\u6210\u529F==>" + topic);
2230
+ }
2231
+ });
2232
+ return this;
2233
+ }
2234
+ }, {
2235
+ key: "unsubscribe",
2236
+ value: function unsubscribe(topic) {
2237
+ this.client.unsubscribe(topic, { qos: 1 }, function (error, res) {
2238
+ if (error instanceof Error || res.length === 0) {
2239
+ console.error("\u53D6\u6D88\u8BA2\u9605\u5931\u8D25==>" + topic, error);
2240
+ } else {
2241
+ console.log("\u53D6\u6D88\u8BA2\u9605\u6210\u529F==>" + topic);
2242
+ }
2243
+ });
2244
+ return this;
2245
+ }
2246
+ }, {
2247
+ key: "unconnect",
2248
+ value: function unconnect() {
2249
+ this.client.end();
2250
+ this.client = null;
2251
+ this.dispatchEvent({ type: EventTypeConstant.MQTT_CLOSE, message: null });
2252
+ console.log("断开mqtt成功==>" + this.context.MQTT_SERVICE);
2253
+ }
2254
+ /**
2255
+ * @description 获取并冻结mqtt实例
2256
+ * @static
2257
+ * @param {*} [config={}]
2258
+ * @returns {MqttClient}
2259
+ */
2260
+
2261
+ }], [{
2262
+ key: "getInstance",
2263
+ value: function getInstance() {
2264
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2265
+
2266
+ if (MqttClient.instance) {
2267
+ return Object.freeze(MqttClient.instance);
2268
+ } else {
2269
+ return Object.freeze(new MqttClient(config));
2270
+ }
2271
+ }
2272
+ }]);
2273
+
2274
+ return MqttClient;
2275
+ }(core_EventDispatcher);
2276
+
2277
+ /* harmony default export */ var core_MqttClient = (MqttClient_MqttClient);
2278
+
2279
+ MqttClient_MqttClient.defaultContext = {
2280
+ MQTT_TIMEOUTM: 20000,
2281
+ MQTT_USERNAME: "iRVMS-WEB",
2282
+ MQTT_PASSWORD: "novasky888",
2283
+ MQTT_SERVICE: "ws://" + window.document.domain + ":20007/mqtt"
2284
+ };
2108
2285
  // CONCATENATED MODULE: ./src/core/WebSocketClient.js
2109
2286
  var WebSocketClient_createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2110
2287
 
2111
2288
  function WebSocketClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2112
2289
 
2113
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2290
+ function WebSocketClient_possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2114
2291
 
2115
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2292
+ function WebSocketClient_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2116
2293
 
2117
2294
 
2118
2295
 
2119
2296
 
2120
2297
  var WebSocketClient_WebSocketClient = function (_EventDispatcher) {
2121
- _inherits(WebSocketClient, _EventDispatcher);
2298
+ WebSocketClient_inherits(WebSocketClient, _EventDispatcher);
2122
2299
 
2123
2300
  function WebSocketClient() {
2124
2301
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ws://127.0.0.1:10088';
2125
2302
 
2126
2303
  WebSocketClient_classCallCheck(this, WebSocketClient);
2127
2304
 
2128
- var _this = _possibleConstructorReturn(this, (WebSocketClient.__proto__ || Object.getPrototypeOf(WebSocketClient)).call(this));
2305
+ var _this = WebSocketClient_possibleConstructorReturn(this, (WebSocketClient.__proto__ || Object.getPrototypeOf(WebSocketClient)).call(this));
2129
2306
 
2130
2307
  _this.maxCheckTimes = 10;
2131
2308
  _this.url = url;
@@ -2362,7 +2539,7 @@ var WebStorage_WebStorage = function () {
2362
2539
 
2363
2540
 
2364
2541
 
2365
- // export { default as MqttClient } from "./core/MqttClient";
2542
+ // vite不支持?
2366
2543
 
2367
2544
 
2368
2545
 
package/package.json CHANGED
@@ -1,32 +1,35 @@
1
- {
2
- "name": "gis-common",
3
- "description": "gis-common",
4
- "main": "dist/resource.min.js",
5
- "version": "1.1.3",
6
- "author": "Guo.Yan <luv02@vip.qq.com>",
7
- "license": "MIT",
8
- "private": false,
9
- "scripts": {
10
- "dev": "cross-env NODE_ENV=development webpack-dev-server --hot --port 7000",
11
- "build": "cross-env NODE_ENV=production webpack --progress"
12
- },
13
- "browserslist": [
14
- "> 1%",
15
- "last 2 versions",
16
- "not ie <= 8"
17
- ],
18
- "files": [],
19
- "devDependencies": {
20
- "babel-core": "^6.26.0",
21
- "babel-loader": "^7.1.2",
22
- "babel-preset-env": "^1.6.0",
23
- "babel-preset-stage-3": "^6.24.1",
24
- "cross-env": "^5.0.5",
25
- "css-loader": "^0.28.7",
26
- "uglifyjs-webpack-plugin": "^2.2.0",
27
- "webpack": "^4.23.1",
28
- "webpack-cli": "^4.9.1",
29
- "webpack-dev-server": "^2.9.1",
30
- "clean-webpack-plugin": "^4.0.0-alpha.0"
31
- }
32
- }
1
+ {
2
+ "name": "gis-common",
3
+ "description": "gis-common",
4
+ "main": "dist/resource.min.js",
5
+ "version": "1.1.6",
6
+ "author": "Guo.Yan <luv02@vip.qq.com>",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "scripts": {
10
+ "dev": "cross-env NODE_ENV=development webpack-dev-server --hot --port 7000",
11
+ "build": "cross-env NODE_ENV=production webpack --progress"
12
+ },
13
+ "browserslist": [
14
+ "> 1%",
15
+ "last 2 versions",
16
+ "not ie <= 8"
17
+ ],
18
+ "files": [],
19
+ "devDependencies": {
20
+ "babel-core": "^6.26.0",
21
+ "babel-loader": "^7.1.2",
22
+ "babel-preset-env": "^1.6.0",
23
+ "babel-preset-stage-3": "^6.24.1",
24
+ "clean-webpack-plugin": "^4.0.0-alpha.0",
25
+ "cross-env": "^5.0.5",
26
+ "css-loader": "^0.28.7",
27
+ "uglifyjs-webpack-plugin": "^2.2.0",
28
+ "webpack": "^4.23.1",
29
+ "webpack-cli": "^4.9.1",
30
+ "webpack-dev-server": "^2.9.1"
31
+ },
32
+ "dependencies": {
33
+ "mqtt": "^4.3.7"
34
+ }
35
+ }