xctc-utils 1.6.67 → 1.6.69
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.
- package/README.md +1 -4
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/index.js +267 -266
- package/dist/crypto/index.js +16 -16
- package/dist/event/changed.js +13 -13
- package/dist/event/drop.js +6 -6
- package/dist/event/index.js +5 -5
- package/dist/event/mouse-down.js +6 -6
- package/dist/event/mouse-move.js +6 -6
- package/dist/event/mouse-up.js +8 -8
- package/dist/event/mouse-wheel.js +2 -2
- package/dist/format/index.js +1 -1
- package/dist/handle/create.js +84 -60
- package/dist/handle/index.js +9 -9
- package/dist/handle/query.js +22 -22
- package/dist/handle/register.js +3 -3
- package/dist/handle/update.js +17 -17
- package/dist/iframe/index.js +30 -30
- package/dist/index.js +29 -24
- package/dist/is/has.js +2 -2
- package/dist/is/index.js +4 -4
- package/dist/modal/index.js +32 -23
- package/dist/params/index.js +59 -59
- package/dist/storage/index.js +4 -4
- package/dist/test.js +3 -3
- package/dist/time/index.js +32 -32
- package/dist/update/index.d.ts +1 -0
- package/dist/update/index.js +48 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +46 -27
- package/dist/weixin/index.d.ts +1 -0
- package/dist/weixin/index.js +109 -106
- package/package.json +1 -1
- package/tsconfig.json +1 -1
package/dist/params/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatDataToPath = exports.formatDataToUrl = exports.urlStateParams = exports.get = exports.set = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const crypto_1 = require("../crypto");
|
|
5
|
+
const storage_1 = require("../storage");
|
|
6
|
+
const defaultKey = "5uMz4R8r0926DkC8";
|
|
7
|
+
const defaultIv = "5uMz4R8r0926DkC8";
|
|
8
|
+
const is_1 = require("../is");
|
|
9
|
+
const win = window;
|
|
10
|
+
const loc = win.location;
|
|
11
|
+
const set = (options) => {
|
|
12
|
+
const { url = "", data = "", keyword = "state", key = defaultKey, iv = defaultIv } = options;
|
|
13
13
|
if (!data || !url)
|
|
14
14
|
return;
|
|
15
15
|
if (url.length < 10 || !url.includes("http") || !url.includes(".")) {
|
|
@@ -20,37 +20,37 @@ var set = function (options) {
|
|
|
20
20
|
console.error("params.set函数data参数必须传入合法的字符串,如id=1&age=22");
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const val = (0, crypto_1.encrypt)(data, key, iv);
|
|
24
|
+
const urlData = `${url}?${keyword}=${val}`;
|
|
25
25
|
return urlData;
|
|
26
26
|
};
|
|
27
27
|
exports.set = set;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const get = (options) => {
|
|
29
|
+
const { keys = [], cache = "", cacheKey = "urlParamsData", key = defaultKey, iv = defaultIv } = options || {};
|
|
30
30
|
console.log("get-options:", options);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const win = window;
|
|
32
|
+
const loc = win.location;
|
|
33
|
+
let search = loc.search;
|
|
34
34
|
console.log("get-search:", search);
|
|
35
35
|
if (search.startsWith("?")) {
|
|
36
36
|
search = search.substring(1);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
let urlArr = search.split("&");
|
|
39
39
|
console.log("get-urlArr:", urlArr);
|
|
40
|
-
|
|
40
|
+
let paramsData = (0, storage_1.getSessionStorage)(cacheKey) || {};
|
|
41
41
|
if (!((keys === null || keys === void 0 ? void 0 : keys.length) && (urlArr === null || urlArr === void 0 ? void 0 : urlArr.length))) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
console.log("get-paramsData:", paramsData);
|
|
45
|
-
for (
|
|
46
|
-
|
|
45
|
+
for (let k = 0; k < keys.length; k++) {
|
|
46
|
+
const keyItem = keys[k];
|
|
47
47
|
console.log("get-keyItem:", keyItem);
|
|
48
48
|
if (keyItem.includes("=")) {
|
|
49
49
|
console.error("传入的参数不能含有=字符,合法格式:['code','state']");
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
for (
|
|
52
|
+
let urlItem = "";
|
|
53
|
+
for (let i = 0; k < urlArr.length; i++) {
|
|
54
54
|
console.log("get-urlItem--1:", urlItem);
|
|
55
55
|
if (urlItem === null || urlItem === void 0 ? void 0 : urlItem.includes(keyItem)) {
|
|
56
56
|
urlItem = "";
|
|
@@ -59,9 +59,9 @@ var get = function (options) {
|
|
|
59
59
|
urlItem = urlArr[i];
|
|
60
60
|
console.log("get-urlItem--2:", urlItem);
|
|
61
61
|
if (urlItem === null || urlItem === void 0 ? void 0 : urlItem.includes(keyItem)) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const dataStr = urlItem.substring(urlItem.indexOf(keyItem) + keyItem.length + 1);
|
|
63
|
+
const decryptData = (0, crypto_1.decrypt)(dataStr, key, iv);
|
|
64
|
+
const decryptStr = (0, crypto_1.decrypt)(dataStr, key, iv);
|
|
65
65
|
console.log("get-decryptData:", decryptData);
|
|
66
66
|
// decryptData 格式为 "path=/user/user-login&id=1"
|
|
67
67
|
paramsData[keyItem] = {
|
|
@@ -81,14 +81,14 @@ var get = function (options) {
|
|
|
81
81
|
return paramsData;
|
|
82
82
|
};
|
|
83
83
|
exports.get = get;
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const getParamsObj = (objStr) => {
|
|
85
|
+
let objData = {};
|
|
86
86
|
if ((0, is_1.isString)(objStr) && (objStr === null || objStr === void 0 ? void 0 : objStr.includes("="))) {
|
|
87
|
-
|
|
88
|
-
for (
|
|
89
|
-
|
|
87
|
+
let objArr = objStr.split("&");
|
|
88
|
+
for (let k = 0; k < objArr.length; k++) {
|
|
89
|
+
const item = objArr[k];
|
|
90
90
|
if (item.includes("=")) {
|
|
91
|
-
|
|
91
|
+
const indexVal = item.indexOf("=");
|
|
92
92
|
objData[item.substring(0, indexVal)] = item.substring(indexVal + 1);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -98,28 +98,28 @@ var getParamsObj = function (objStr) {
|
|
|
98
98
|
}
|
|
99
99
|
return objData;
|
|
100
100
|
};
|
|
101
|
-
|
|
101
|
+
const urlStateParams = (cacheKey, key, iv) => {
|
|
102
102
|
if (!cacheKey)
|
|
103
103
|
cacheKey = "urlParamsData";
|
|
104
104
|
if (!key)
|
|
105
105
|
key = defaultKey;
|
|
106
106
|
if (!iv)
|
|
107
107
|
iv = defaultIv;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const win = window;
|
|
109
|
+
const loc = win.location;
|
|
110
|
+
let search = loc.search;
|
|
111
111
|
if (search.startsWith("?")) {
|
|
112
112
|
search = search.substring(1);
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
for (
|
|
116
|
-
|
|
114
|
+
let urlArr = search.split("&");
|
|
115
|
+
for (let k = 0; k < urlArr.length; k++) {
|
|
116
|
+
const item = urlArr[k];
|
|
117
117
|
if (item.includes("state=")) {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
const indexVal = item.indexOf("=");
|
|
119
|
+
let keys = item.substring(0, indexVal);
|
|
120
120
|
keys = keys[0].toUpperCase() + keys.substring(1);
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const val = item.substring(indexVal + 1);
|
|
122
|
+
const data = (0, crypto_1.decrypt)(val, key, iv);
|
|
123
123
|
// data 格式为 "path=/user/user-login&id=1"
|
|
124
124
|
(0, storage_1.useSessionStorage)(cacheKey, { state: { str: val, data: getParamsObj(data) } });
|
|
125
125
|
}
|
|
@@ -132,49 +132,49 @@ exports.urlStateParams = urlStateParams;
|
|
|
132
132
|
* @param data 需要处理的 data 对象
|
|
133
133
|
* @returns
|
|
134
134
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
const formatDataToUrl = (data) => {
|
|
136
|
+
let url = loc.origin;
|
|
137
|
+
let str = "";
|
|
138
|
+
const hashVal = loc.hash;
|
|
139
139
|
if ((0, is_1.isObject)(data)) {
|
|
140
|
-
for (
|
|
140
|
+
for (let key in data) {
|
|
141
141
|
if (key == "path") {
|
|
142
142
|
if (data[key][0] == "/") {
|
|
143
|
-
url =
|
|
143
|
+
url = `${url}/#${data.path}`;
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
|
-
url =
|
|
146
|
+
url = `${url}/#/${data.path}`;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
else {
|
|
150
|
-
str +=
|
|
150
|
+
str += `${key}=${data[key]}&`;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
if (data === null || data === void 0 ? void 0 : data.path) {
|
|
154
154
|
if (str) {
|
|
155
|
-
url =
|
|
155
|
+
url = `${url}?${str}`;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
else if (hashVal) {
|
|
160
|
-
url =
|
|
160
|
+
url = `${url}/${hashVal}`;
|
|
161
161
|
}
|
|
162
162
|
return url;
|
|
163
163
|
};
|
|
164
164
|
exports.formatDataToUrl = formatDataToUrl;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
const formatDataToPath = (data) => {
|
|
166
|
+
let path = "";
|
|
167
|
+
let str = "";
|
|
168
|
+
const hashVal = loc.hash;
|
|
169
169
|
if ((0, is_1.isObject)(data)) {
|
|
170
|
-
for (
|
|
170
|
+
for (let key in data) {
|
|
171
171
|
if (key != "path") {
|
|
172
|
-
str +=
|
|
172
|
+
str += `${key}=${data[key]}&`;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
if (data === null || data === void 0 ? void 0 : data.path) {
|
|
176
176
|
if (str) {
|
|
177
|
-
path =
|
|
177
|
+
path = `${data === null || data === void 0 ? void 0 : data.path}?${str}`;
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
else {
|
package/dist/storage/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeLocalStorage = exports.removeSessionStorage = exports.getSessionStorage = exports.useSessionStorage = exports.getLocalStorage = exports.useLocalStorage = void 0;
|
|
4
|
-
|
|
4
|
+
const is_1 = require("../is");
|
|
5
5
|
var wls = window.localStorage;
|
|
6
6
|
var wss = window.sessionStorage;
|
|
7
|
-
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* @param key 需要存储的数据key值
|
|
@@ -66,11 +66,11 @@ function useStorage(key, value, obj) {
|
|
|
66
66
|
* @returns
|
|
67
67
|
*/
|
|
68
68
|
function getStorage(key, obj) {
|
|
69
|
-
|
|
69
|
+
let val = obj.getItem(key);
|
|
70
70
|
if (val == 'undefined' || val == null) {
|
|
71
71
|
return "";
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
let data = (0, utils_1.isJson)(val);
|
|
74
74
|
if (data)
|
|
75
75
|
val = data;
|
|
76
76
|
return val;
|
package/dist/test.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// var crypto = require("./crypto/index")
|
|
4
4
|
function testcrypto() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const hrefState = "219281DA5170E6A003B47D8143F049E3E54F2EE0FA2487EE302BA86B3110045A2047367251B76089F3343B974BBC265A";
|
|
6
|
+
const key = "5uMz4R8rop26DkC8";
|
|
7
|
+
const iv = "5uMz4Rsd0926DkC8";
|
|
8
8
|
// let data = crypto.decrypt( hrefState , key , iv )
|
|
9
9
|
console.log(iv);
|
|
10
10
|
}
|
package/dist/time/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findIdcardAge = exports.getDateData = exports.formatStrTime = exports.formatTimeStamp = exports.getTime = void 0;
|
|
4
4
|
//获取当前时间戳
|
|
5
5
|
function getTime() {
|
|
6
|
-
|
|
6
|
+
let now = new Date().getTime() / 1000;
|
|
7
7
|
now = parseInt(now);
|
|
8
8
|
return now;
|
|
9
9
|
}
|
|
@@ -22,7 +22,7 @@ function formatTimeStamp(num, format) {
|
|
|
22
22
|
num = Number(num); // 先将数据转换为数据类型
|
|
23
23
|
if (!num)
|
|
24
24
|
return "";
|
|
25
|
-
|
|
25
|
+
const dateObj = getDateData(num, format) || {};
|
|
26
26
|
// // 传入秒 时间戳
|
|
27
27
|
// let date:any=""
|
|
28
28
|
// if ( typeof num == 'number') {
|
|
@@ -60,7 +60,7 @@ function isExist(str, key) {
|
|
|
60
60
|
return;
|
|
61
61
|
if (!key)
|
|
62
62
|
return;
|
|
63
|
-
|
|
63
|
+
let index = str.indexOf(key);
|
|
64
64
|
if (index != -1)
|
|
65
65
|
return true;
|
|
66
66
|
return false;
|
|
@@ -88,13 +88,13 @@ exports.formatStrTime = formatStrTime;
|
|
|
88
88
|
* @returns
|
|
89
89
|
*/
|
|
90
90
|
function getDateData(value, format) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
let now = new Date();
|
|
92
|
+
let year = "";
|
|
93
|
+
let month = "";
|
|
94
|
+
let day = "";
|
|
95
|
+
let hour = "";
|
|
96
|
+
let minute = "";
|
|
97
|
+
let second = "";
|
|
98
98
|
if (typeof value == 'number') {
|
|
99
99
|
now = new Date(value * 1000);
|
|
100
100
|
year = now.getFullYear();
|
|
@@ -113,56 +113,56 @@ function getDateData(value, format) {
|
|
|
113
113
|
if (!format)
|
|
114
114
|
format = "YYYY-MM-DD HH:mm:ss";
|
|
115
115
|
year = value.substring(0, 4);
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
let str = `${year}`;
|
|
117
|
+
const monthIndex = format.indexOf("MM");
|
|
118
118
|
console.log("monthIndex==", monthIndex);
|
|
119
119
|
if (monthIndex != -1) {
|
|
120
120
|
month = value.substring(monthIndex, monthIndex + 2) || "01";
|
|
121
|
-
str =
|
|
121
|
+
str = `${str}/${month}`;
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
124
|
month = "01";
|
|
125
|
-
str =
|
|
125
|
+
str = `${str}/01`;
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
const dayIndex = format.indexOf("DD");
|
|
128
128
|
if (dayIndex != -1) {
|
|
129
129
|
day = value.substring(dayIndex, dayIndex + 2) || "01";
|
|
130
|
-
str =
|
|
130
|
+
str = `${str}/${day}`;
|
|
131
131
|
}
|
|
132
132
|
else {
|
|
133
133
|
day = "01";
|
|
134
|
-
str =
|
|
134
|
+
str = `${str}/01`;
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
const hourIndex = format.indexOf("HH");
|
|
137
137
|
if (hourIndex != -1) {
|
|
138
138
|
hour = value.substring(hourIndex, hourIndex + 2) || "00";
|
|
139
|
-
str =
|
|
139
|
+
str = `${str} ${hour}`;
|
|
140
140
|
}
|
|
141
141
|
else {
|
|
142
142
|
hour = "00";
|
|
143
|
-
str =
|
|
143
|
+
str = `${str} 00`;
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
const minuteIndex = format.indexOf("mm");
|
|
146
146
|
if (minuteIndex != -1) {
|
|
147
147
|
minute = value.substring(minuteIndex, minuteIndex + 2) || "00";
|
|
148
|
-
str =
|
|
148
|
+
str = `${str}:${minute}`;
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
151
|
minute = "00";
|
|
152
|
-
str =
|
|
152
|
+
str = `${str}:00`;
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
const secondIndex = format.indexOf("ss");
|
|
155
155
|
if (secondIndex != -1) {
|
|
156
156
|
second = value.substring(secondIndex, secondIndex + 2) || "00";
|
|
157
|
-
str =
|
|
157
|
+
str = `${str}:${second}`;
|
|
158
158
|
}
|
|
159
159
|
else {
|
|
160
160
|
second = "01";
|
|
161
|
-
str =
|
|
161
|
+
str = `${str}:01`;
|
|
162
162
|
}
|
|
163
163
|
now = new Date(str);
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
let nowNumber = now.getTime() / 1000;
|
|
166
166
|
nowNumber = parseInt(nowNumber);
|
|
167
167
|
return {
|
|
168
168
|
year: year,
|
|
@@ -186,13 +186,13 @@ function findIdcardAge(idcard) {
|
|
|
186
186
|
return "";
|
|
187
187
|
}
|
|
188
188
|
// 提取身份证号中的出生日期部分
|
|
189
|
-
|
|
189
|
+
const birthday = idcard.substring(6, 14);
|
|
190
190
|
if (birthday) {
|
|
191
191
|
// 解析出生日期
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
const year = birthday.substring(0, 4);
|
|
193
|
+
const month = birthday.substring(4, 6);
|
|
194
|
+
const day = birthday.substring(6, 8);
|
|
195
|
+
const str = `${year}-${month}-${day}`;
|
|
196
196
|
return getDateData(str, "YYYY-MM-DD HH:mm:ss");
|
|
197
197
|
}
|
|
198
198
|
return "";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function autoUpdateLastVersion(): void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.autoUpdateLastVersion = void 0;
|
|
4
|
+
let autoUpdateLastSrcs;
|
|
5
|
+
let autoUpdateScriptReg = /\<script.*src=["'](?<src>[^"']+)/gm;
|
|
6
|
+
async function getNewScripts() {
|
|
7
|
+
const html = await fetch("/").then(res => res.text());
|
|
8
|
+
autoUpdateScriptReg['lastIndex'] = 0;
|
|
9
|
+
let result = [];
|
|
10
|
+
let match;
|
|
11
|
+
while ((match = autoUpdateScriptReg.exec(html))) {
|
|
12
|
+
result.push(match.groups.src);
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
async function needUpdate() {
|
|
17
|
+
const newScripts = await getNewScripts();
|
|
18
|
+
if (!autoUpdateLastSrcs) {
|
|
19
|
+
autoUpdateLastSrcs = newScripts;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
let result = false;
|
|
23
|
+
if (newScripts.length !== autoUpdateLastSrcs.length) {
|
|
24
|
+
result = true;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < autoUpdateLastSrcs.length; i++) {
|
|
27
|
+
if (autoUpdateLastSrcs[i] !== newScripts[i]) {
|
|
28
|
+
result = true;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
autoUpdateLastSrcs = newScripts;
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
const autoUpdateDuration = 5000;
|
|
36
|
+
function autoRefresh() {
|
|
37
|
+
setTimeout(async () => {
|
|
38
|
+
const willUpdate = await needUpdate();
|
|
39
|
+
if (willUpdate) {
|
|
40
|
+
location.reload();
|
|
41
|
+
}
|
|
42
|
+
autoRefresh();
|
|
43
|
+
}, autoUpdateDuration);
|
|
44
|
+
}
|
|
45
|
+
function autoUpdateLastVersion() {
|
|
46
|
+
autoRefresh();
|
|
47
|
+
}
|
|
48
|
+
exports.autoUpdateLastVersion = autoUpdateLastVersion;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UeditorHeightOption } from "./types";
|
|
2
2
|
export declare function isMobile(): boolean;
|
|
3
3
|
export declare function loadScript(url: string, callback?: any): void;
|
|
4
|
+
export declare const isScriptLoaded: (src: string) => boolean;
|
|
4
5
|
/**
|
|
5
6
|
* 判断当前传入的字符串是否为 json格式 字符串
|
|
6
7
|
* @param str
|
package/dist/utils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleCopyValue = exports.weixinBrowser = exports.deviceEnvironment = exports.getIframeContentHeight = exports.checkIframeContentHeight = exports.getDomFn = exports.isJson = exports.loadScript = exports.isMobile = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.handleCopyValue = exports.weixinBrowser = exports.deviceEnvironment = exports.getIframeContentHeight = exports.checkIframeContentHeight = exports.getDomFn = exports.isJson = exports.isScriptLoaded = exports.loadScript = exports.isMobile = void 0;
|
|
4
|
+
const is_1 = require("./is");
|
|
5
|
+
const win = window;
|
|
6
6
|
// 是否是手机端环境
|
|
7
7
|
function isMobile() {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const info = win.navigator.userAgent;
|
|
9
|
+
const isPhone = /mobile/i.test(info);
|
|
10
10
|
return isPhone;
|
|
11
11
|
}
|
|
12
12
|
exports.isMobile = isMobile;
|
|
@@ -14,7 +14,10 @@ function loadScript(url, callback) {
|
|
|
14
14
|
if (!url) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
if ((0, exports.isScriptLoaded)(url)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const script = document.createElement('script');
|
|
18
21
|
script.type = 'text/javascript';
|
|
19
22
|
if (script === null || script === void 0 ? void 0 : script.readyState) { // IE
|
|
20
23
|
script.onreadystatechange = function () {
|
|
@@ -29,11 +32,27 @@ function loadScript(url, callback) {
|
|
|
29
32
|
callback();
|
|
30
33
|
};
|
|
31
34
|
}
|
|
35
|
+
// 错误处理
|
|
36
|
+
script.onerror = function (error) {
|
|
37
|
+
console.error('Error loading script:', error);
|
|
38
|
+
};
|
|
32
39
|
script.src = url;
|
|
33
|
-
|
|
40
|
+
const head = document.getElementsByTagName('head')[0];
|
|
34
41
|
head.appendChild(script);
|
|
35
42
|
}
|
|
36
43
|
exports.loadScript = loadScript;
|
|
44
|
+
const isScriptLoaded = (src) => {
|
|
45
|
+
if (!src)
|
|
46
|
+
return false;
|
|
47
|
+
const scripts = document.scripts;
|
|
48
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
49
|
+
if (scripts[i].src === src) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
exports.isScriptLoaded = isScriptLoaded;
|
|
37
56
|
/**
|
|
38
57
|
* 判断当前传入的字符串是否为 json格式 字符串
|
|
39
58
|
* @param str
|
|
@@ -49,7 +68,7 @@ function isJson(str) {
|
|
|
49
68
|
return str;
|
|
50
69
|
}
|
|
51
70
|
try {
|
|
52
|
-
|
|
71
|
+
const obj = JSON.parse(str);
|
|
53
72
|
if (obj && typeof obj == "object") {
|
|
54
73
|
return obj;
|
|
55
74
|
}
|
|
@@ -66,7 +85,7 @@ exports.isJson = isJson;
|
|
|
66
85
|
function getDomFn(id) {
|
|
67
86
|
if (!id)
|
|
68
87
|
return false;
|
|
69
|
-
|
|
88
|
+
let dom = document.getElementById(id);
|
|
70
89
|
if (id && dom instanceof HTMLElement) {
|
|
71
90
|
return dom;
|
|
72
91
|
}
|
|
@@ -75,10 +94,10 @@ function getDomFn(id) {
|
|
|
75
94
|
exports.getDomFn = getDomFn;
|
|
76
95
|
// 设置当前富文本内容高度
|
|
77
96
|
function checkIframeContentHeight(option) {
|
|
78
|
-
|
|
97
|
+
let { id = "ueditor_0", content = "" } = option;
|
|
79
98
|
var ifm = getDomFn(id); // 当前富文本id获取到iframe
|
|
80
99
|
var subWeb = { body: "" };
|
|
81
|
-
|
|
100
|
+
let tags = document.body.getElementsByTagName("iframe");
|
|
82
101
|
if (tags && tags[0]) {
|
|
83
102
|
subWeb = tags[0]['contentDocument'];
|
|
84
103
|
}
|
|
@@ -88,12 +107,12 @@ function checkIframeContentHeight(option) {
|
|
|
88
107
|
}
|
|
89
108
|
if (subWeb && subWeb.body) {
|
|
90
109
|
var ifmBody = subWeb.body;
|
|
91
|
-
|
|
92
|
-
|
|
110
|
+
let last = ifmBody.lastElementChild;
|
|
111
|
+
let height = 0;
|
|
93
112
|
if (last) {
|
|
94
113
|
height = last.offsetTop;
|
|
95
114
|
}
|
|
96
|
-
return
|
|
115
|
+
return `<input type="hidden" content-data-height="${height}" id="ueditorHeight" />${content}`;
|
|
97
116
|
}
|
|
98
117
|
return content;
|
|
99
118
|
}
|
|
@@ -103,9 +122,9 @@ function getIframeContentHeight(id) {
|
|
|
103
122
|
if (!id) {
|
|
104
123
|
id = "ueditorHeight";
|
|
105
124
|
}
|
|
106
|
-
|
|
125
|
+
const dom = getDomFn(id);
|
|
107
126
|
if (dom) {
|
|
108
|
-
|
|
127
|
+
let height = dom.getAttribute("content-data-height");
|
|
109
128
|
return height;
|
|
110
129
|
}
|
|
111
130
|
return 0;
|
|
@@ -150,7 +169,7 @@ function handleCopyValue(text) {
|
|
|
150
169
|
return console.error("请传入需要复制到粘贴板的数据");
|
|
151
170
|
//浏览器禁用了非安全域的 navigator.clipboard 对象
|
|
152
171
|
//在线上环境会报错 TypeError: Cannot read properties of undefined (reading 'writeText')
|
|
153
|
-
|
|
172
|
+
const clipboard = (navigator === null || navigator === void 0 ? void 0 : navigator.clipboard) || "";
|
|
154
173
|
if (!clipboard && window.isSecureContext) {
|
|
155
174
|
return clipboard === null || clipboard === void 0 ? void 0 : clipboard.writeText(text);
|
|
156
175
|
}
|
|
@@ -159,19 +178,19 @@ function handleCopyValue(text) {
|
|
|
159
178
|
if (!document.execCommand('copy'))
|
|
160
179
|
return Promise.reject();
|
|
161
180
|
// 创建标签,并隐藏
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
document.body.appendChild(
|
|
181
|
+
const textArea = document.createElement('textarea');
|
|
182
|
+
textArea.style.position = 'fixed';
|
|
183
|
+
textArea.style.top = textArea.style.left = '-100vh';
|
|
184
|
+
textArea.style.opacity = '0';
|
|
185
|
+
textArea.value = text;
|
|
186
|
+
document.body.appendChild(textArea);
|
|
168
187
|
// 聚焦、复制
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return new Promise(
|
|
188
|
+
textArea.focus();
|
|
189
|
+
textArea.select();
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
172
191
|
// 不知为何,必须写这个三目,不然copy不上
|
|
173
192
|
document.execCommand('copy') ? resolve() : reject();
|
|
174
|
-
|
|
193
|
+
textArea.remove();
|
|
175
194
|
});
|
|
176
195
|
}
|
|
177
196
|
}
|
package/dist/weixin/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface configOption {
|
|
|
14
14
|
cb?: any;
|
|
15
15
|
}
|
|
16
16
|
export declare function loadWeiXinSDK(url?: string, callback?: any): void;
|
|
17
|
+
export declare function initWeixinConfig(config: configOption): void;
|
|
17
18
|
export declare function getUrlCode(config: configOption): void;
|
|
18
19
|
export declare function envSDK(): any;
|
|
19
20
|
export declare function getCode(appId?: string, scope?: string): void;
|