@lambo-design/shared 1.0.0-beta.267 → 1.0.0-beta.269

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/shared",
3
- "version": "1.0.0-beta.267",
3
+ "version": "1.0.0-beta.269",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -15,9 +15,11 @@
15
15
  ]
16
16
  },
17
17
  "dependencies": {
18
+ "@e965/xlsx": "0.20.3",
18
19
  "axios": "^0.24.0",
19
20
  "axios-cache-plugin": "^0.1.0",
20
21
  "classnames": "^2.3.1",
22
+ "crypto-js": "^4.2.0",
21
23
  "css-vars-ponyfill": "^2.4.8",
22
24
  "dayjs": "^1.11.9",
23
25
  "lodash": "^4.17.21",
@@ -25,7 +27,6 @@
25
27
  "nanoid": "^3.3.7",
26
28
  "node-rsa": "^1.1.1",
27
29
  "qs": "^6.11.0",
28
- "@e965/xlsx": "0.20.3",
29
30
  "xlsx-style": "^0.8.13"
30
31
  },
31
32
  "devDependencies": {
package/utils/assist.js CHANGED
@@ -163,3 +163,50 @@ export function isJson(arg) {
163
163
  export function isObject(item) {
164
164
  return (item && typeof item === 'object' && !Array.isArray(item));
165
165
  }
166
+
167
+ export function copyToClipboard(text){
168
+ return new Promise((resolve, reject) => {
169
+ // 现代浏览器方案
170
+ if (navigator.clipboard) {
171
+ navigator.clipboard.writeText(text).then(() => {
172
+ resolve(true);
173
+ }).catch(err => {
174
+ // 现代API失败时尝试传统方案
175
+ fallbackCopy(text, resolve, reject);
176
+ });
177
+ } else {
178
+ // 传统浏览器方案
179
+ fallbackCopy(text, resolve, reject);
180
+ }
181
+ });
182
+ }
183
+
184
+ export function fallbackCopy(text, resolve, reject) {
185
+ try {
186
+ const textArea = document.createElement('textarea');
187
+ textArea.value = text;
188
+ textArea.style.position = 'fixed'; // 避免触发滚动
189
+ textArea.style.left = '-9999px';
190
+ textArea.setAttribute('readonly', '');
191
+ document.body.appendChild(textArea);
192
+ textArea.select();
193
+ // 兼容移动端
194
+ if (textArea.setSelectionRange) {
195
+ const range = document.createRange();
196
+ range.selectNodeContents(textArea);
197
+ const sel = window.getSelection();
198
+ sel.removeAllRanges();
199
+ sel.addRange(range);
200
+ textArea.setSelectionRange(0, textArea.value.length);
201
+ }
202
+ const success = document.execCommand('copy');
203
+ document.body.removeChild(textArea);
204
+ if (success) {
205
+ resolve(true);
206
+ } else {
207
+ reject(new Error('复制失败'));
208
+ }
209
+ } catch (err) {
210
+ reject(err);
211
+ }
212
+ }
@@ -0,0 +1,23 @@
1
+ import * as CryptoJS from 'crypto-js';
2
+
3
+ const AES_KEY = 'gYj2iqBV5AzxC8H0';
4
+ const AES_IV = 'z5c8fSuHX1PxWtIg';
5
+
6
+ let aes = {
7
+ encrypt(message,key = AES_KEY,iv = AES_IV) {
8
+ return CryptoJS.AES.encrypt(message, key, {
9
+ mode: CryptoJS.mode.CBC,
10
+ padding: CryptoJS.pad.Pkcs7,
11
+ iv: iv
12
+ })
13
+ },
14
+ decrypt(ciphertext,key = AES_IV,iv = AES_IV) {
15
+ return CryptoJS.AES.decrypt(ciphertext, key, {
16
+ mode: CryptoJS.mode.CBC,
17
+ padding: CryptoJS.pad.Pkcs7,
18
+ iv: iv
19
+ }).toString(CryptoJS.enc.Utf8)
20
+ }
21
+ }
22
+
23
+ export default aes;
@@ -0,0 +1,23 @@
1
+ import NodeRSA from "node-rsa";
2
+
3
+ /**
4
+ * 默认公钥
5
+ * @type {string}
6
+ */
7
+ const defaultPublicKey = `-----BEGIN PUBLIC KEY-----
8
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCyhhlApSAjPWRjzg+wSIfALbrC
9
+ Ti4GVBYYBjfMYKU0O9z6EGQAXSLPW+S4VYm4LKtKXuKoeF441KU2HvnGM63cTIYt
10
+ T4lGbTGeYfsbeWNs1u9G9J+DrfKK8HsVB1IZIqhbMf0x7KGMeoQ2SN4KtbaPIwhl
11
+ IPfXzuLZiCW90l+a/wIDAQAB
12
+ -----END PUBLIC KEY-----`;
13
+
14
+ /**
15
+ * 使用RSA算法对data进行加密
16
+ * @param data 要加密的内容
17
+ * @param publicKey 不传使用默认公钥
18
+ * @returns {string|Buffer}
19
+ */
20
+ export default function rsa(data, publicKey = defaultPublicKey) {
21
+ let nodeRSA = new NodeRSA(publicKey, "pkcs8-public");
22
+ return nodeRSA.encrypt(data, "base64");
23
+ }
@@ -38,6 +38,29 @@ export async function getServiceUrlDict(serviceKeyList,serviceUrlList) {
38
38
  }
39
39
  }
40
40
 
41
+ export async function getDynamicTextServiceUrl(serviceKeyList,serviceUrlList) {
42
+ if (serviceUrlList.length > 0) {
43
+ try {
44
+ let result = {}
45
+ let requests = []
46
+ for (const url of serviceUrlList) {
47
+ requests.push(ajax.get(url))
48
+ }
49
+ const response = await Promise.all(requests);
50
+ // 处理每个响应
51
+ response.forEach((item, index) => {
52
+ if (item.data.code === 1) {
53
+ let dynamicTextValue = item.data.data;
54
+ result[serviceKeyList[index]] = dynamicTextValue;
55
+ }
56
+ });
57
+ return result;
58
+ } catch (error) {
59
+ console.error(error)
60
+ }
61
+ }
62
+ }
63
+
41
64
  export async function getTreeSelectServiceData(serviceKeyList,serviceUrlList) {
42
65
  if (serviceUrlList.length > 0) {
43
66
  try {
package/utils/style.js CHANGED
@@ -1,24 +1,24 @@
1
- const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
2
- const MOZ_HACK_REGEXP = /^moz([A-Z])/
3
-
4
- function camelCase(name) {
5
- return name
6
- .replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
7
- return offset ? letter.toUpperCase() : letter
8
- })
9
- .replace(MOZ_HACK_REGEXP, 'Moz$1')
10
- }
11
- // getStyle
12
- export function getStyle(element, styleName) {
13
- if (!element || !styleName) return null
14
- styleName = camelCase(styleName)
15
- if (styleName === 'float') {
16
- styleName = 'cssFloat'
17
- }
18
- try {
19
- const computed = document.defaultView.getComputedStyle(element, '')
20
- return element.style[styleName] || computed ? computed[styleName] : null
21
- } catch (e) {
22
- return element.style[styleName]
23
- }
24
- }
1
+ const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
2
+ const MOZ_HACK_REGEXP = /^moz([A-Z])/
3
+
4
+ function camelCase(name) {
5
+ return name
6
+ .replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
7
+ return offset ? letter.toUpperCase() : letter
8
+ })
9
+ .replace(MOZ_HACK_REGEXP, 'Moz$1')
10
+ }
11
+ // getStyle
12
+ export function getStyle(element, styleName) {
13
+ if (!element || !styleName) return null
14
+ styleName = camelCase(styleName)
15
+ if (styleName === 'float') {
16
+ styleName = 'cssFloat'
17
+ }
18
+ try {
19
+ const computed = document.defaultView.getComputedStyle(element, '')
20
+ return element.style[styleName] || computed ? computed[styleName] : null
21
+ } catch (e) {
22
+ return element.style[styleName]
23
+ }
24
+ }
@@ -1,7 +1,7 @@
1
- let transferIndex = 1000
2
-
3
- function transferIncrease() {
4
- transferIndex++
5
- }
6
-
7
- export { transferIndex, transferIncrease }
1
+ let transferIndex = 1000
2
+
3
+ function transferIncrease() {
4
+ transferIndex++
5
+ }
6
+
7
+ export { transferIndex, transferIncrease }