js_ryl 1.0.33 → 1.0.34

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": "js_ryl",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "private": false,
5
5
  "description": "自定义通用js",
6
6
  "author": "renyuliang <785788909@qq.com>",
package/src/App.vue CHANGED
@@ -57,6 +57,7 @@ import verCode from "./verCode";
57
57
  import filterTable from "./filterTable";
58
58
  import getMonthDays from "./getMonthDays";
59
59
  import emoji from "./emoji";
60
+ import emojiToUnicode from "./emojiToUnicode";
60
61
  import highLight from "./highLight";
61
62
  import flyToCart from "./flyToCart";
62
63
  import downExcel from "./downExcel";
@@ -174,6 +175,8 @@ export default {
174
175
  const emojiEx = "A0 [u+1BE4] U+1F600 \\u{1F602} U+123456";
175
176
  const output = emoji(emojiEx);
176
177
  console.log(output);
178
+ const sssttt = 'A0 ᯤ 😀 😂 U+123456'
179
+ console.log(emojiToUnicode(sssttt))
177
180
 
178
181
  },
179
182
  methods: {
@@ -1,53 +1,50 @@
1
1
  // 处理字符串中的base64图片上传和替换
2
- export default function base64Img(content, apiUrl, token, data) {
3
- // 匹配所有 base64 图片(支持多种格式)
2
+ export default function base64Img(content, apiUrl, token, data, callback = function () { }) {
4
3
  const base64Regex = /<img [^>]*src=['"](data:image[^'"]+base64,[^'"]+)['"][^>]*>/gi;
5
4
  let match;
6
5
  const replacements = [];
7
6
 
8
- // 第一步:收集所有需要替换的 base64 数据
9
7
  while ((match = base64Regex.exec(content)) !== null) {
10
8
  replacements.push({
11
- original: match[1],
12
- base64: match[1]
9
+ original: match[1],
10
+ base64: match[1]
13
11
  });
14
12
  }
15
13
 
16
- // 第二步:并行上传所有图片
17
14
  if (replacements.length > 0) {
18
15
  const uploadPromises = replacements.map((replacement) => {
19
- return fetch(apiUrl, {
20
- method: "POST",
21
- headers: {
22
- "Authorization": "Bearer " + token,
23
- "Content-Type": "application/json"
24
- },
25
- body: JSON.stringify({image: replacement.base64,...data})
26
- })
27
- .then(res => res.json())
28
- .then(data => {
29
- if (data.code === 200) {
30
- replacement.url = data.data.url;
31
- }
32
- return replacement;
33
- })
34
- .catch(error => {
35
- console.error('上传图片失败:', error);
36
- return replacement;
37
- });
16
+ return fetch(apiUrl, {
17
+ method: "POST",
18
+ headers: {
19
+ "Authorization": "Bearer " + token,
20
+ "Content-Type": "application/json"
21
+ },
22
+ body: JSON.stringify({ image: replacement.base64, ...data })
23
+ })
24
+ .then(res => res.json())
25
+ .then(result => {
26
+ if (result.code === 200) {
27
+ replacement.url = result.data.url;
28
+ } else {
29
+ callback(replacement.original, result.msg);
30
+ }
31
+ return replacement;
32
+ })
33
+ .catch(error => {
34
+ callback(replacement.original, error);
35
+ return replacement;
36
+ });
38
37
  });
39
38
 
40
- // 等待所有上传完成
41
39
  return Promise.all(uploadPromises)
42
- .then(results => {
43
- // 第三步:替换所有 base64 为图片 URL
44
- results.forEach((result) => {
45
- if (result.url) {
46
- content = content.replace(result.original, result.url);
47
- }
40
+ .then(results => {
41
+ results.forEach((result) => {
42
+ if (result.url) {
43
+ content = content.replace(result.original, result.url);
44
+ }
45
+ });
46
+ return content;
48
47
  });
49
- return content;
50
- });
51
48
  }
52
49
 
53
50
  return Promise.resolve(content);
@@ -1,4 +1,4 @@
1
- // 主转换函数
1
+ // 主转换函数-- unicode转化emoji表情
2
2
  export default function emoji(str) {
3
3
  // 支持多种 Unicode 表示格式:U+xxxx, [u+xxxx], \u{xxxx}
4
4
  const regex = /U\+([0-9A-Fa-f]{4,6})|\[u\+([0-9A-Fa-f]{4,6})\]|\\u\{([0-9A-Fa-f]{4,6})\}/g;
@@ -0,0 +1,10 @@
1
+ // 将字符串中的emoji表情转为unicode
2
+ export default function emojiToUnicode(msg) {
3
+ const rex =
4
+ /[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/gu;
5
+ const updated = msg.replace(
6
+ rex,
7
+ (match) => `[u+${match.codePointAt(0).toString(16)}]`
8
+ );1
9
+ return updated;
10
+ }
package/src/index.js CHANGED
@@ -19,8 +19,10 @@ import verCode from "./verCode";
19
19
  import filterTable from "./filterTable";
20
20
  // 获取当前年份中,指定月份的天数
21
21
  import getMonthDays from "./getMonthDays";
22
- // emoji表情转化
22
+ // unicode转化emoji表情
23
23
  import emoji from "./emoji";
24
+ // 将字符串中的emoji表情转为unicode
25
+ import emojiToUnicode from "./emojiToUnicode";
24
26
  // 高亮显示搜索匹配的文字
25
27
  import highLight from "./highLight";
26
28
  // 飞入购物车效果
@@ -29,7 +31,7 @@ import flyToCart from "./flyToCart";
29
31
  import downExcel from "./downExcel";
30
32
  // 处理base64的图片为链接
31
33
  import base64Img from "./base64Img";
32
- // 处理base64的图片为链接
34
+ // 字符串参数处理
33
35
  import getParamsUtil from "./getParamsUtil";
34
36
 
35
37
  export default {
@@ -44,6 +46,7 @@ export default {
44
46
  filterTable,
45
47
  getMonthDays,
46
48
  emoji,
49
+ emojiToUnicode,
47
50
  highLight,
48
51
  flyToCart,
49
52
  downExcel,