@jx3box/jx3box-common-ui 9.4.1 → 9.4.2

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "qq机器人": "/qqbot"
3
+ }
@@ -1,15 +1,21 @@
1
- import { Notification } from 'element-ui';
1
+ import { Notification } from "element-ui";
2
+ import { __Root } from "@jx3box/jx3box-common/data/jx3box.json";
3
+ import searchMap from "../data/search_map.json";
4
+
2
5
  // 复制
3
6
  export function copyText(text) {
4
7
  if (window.navigator.clipboard) {
5
- window.navigator.clipboard.writeText(text).then(function () {
6
- Notification.success({
7
- title: '复制成功',
8
- });
9
- console.log('Async: Copying to clipboard was successful!');
10
- }, function (err) {
11
- console.error('Async: Could not copy text: ', err);
12
- });
8
+ window.navigator.clipboard.writeText(text).then(
9
+ function () {
10
+ Notification.success({
11
+ title: "复制成功",
12
+ });
13
+ console.log("Async: Copying to clipboard was successful!");
14
+ },
15
+ function (err) {
16
+ console.error("Async: Could not copy text: ", err);
17
+ }
18
+ );
13
19
  } else {
14
20
  var textArea = document.createElement("textarea");
15
21
  textArea.value = text;
@@ -17,11 +23,11 @@ export function copyText(text) {
17
23
  textArea.focus();
18
24
  textArea.select();
19
25
  try {
20
- var successful = document.execCommand('copy');
21
- var msg = successful ? 'successful' : 'unsuccessful';
22
- console.log('Fallback: Copying text command was ' + msg);
26
+ var successful = document.execCommand("copy");
27
+ var msg = successful ? "successful" : "unsuccessful";
28
+ console.log("Fallback: Copying text command was " + msg);
23
29
  } catch (err) {
24
- console.error('Fallback: Oops, unable to copy', err);
30
+ console.error("Fallback: Oops, unable to copy", err);
25
31
  }
26
32
  document.body.removeChild(textArea);
27
33
  }
@@ -34,17 +40,65 @@ export function trimSlash(str) {
34
40
 
35
41
  // 监听 localStorage 的改变
36
42
  export function dispatchEventStorage() {
37
- const _setItem = localStorage.setItem
43
+ const _setItem = localStorage.setItem;
38
44
 
39
45
  localStorage.setItem = function (key, val) {
40
46
  // 注册一个名称为 setItemEvent 的事件
41
- let setEvent = new Event('setItemEvent')
47
+ let setEvent = new Event("setItemEvent");
42
48
  // key 为改变的 key, newVal 为改变的 value
43
- setEvent.key = key
44
- setEvent.newVal = val
49
+ setEvent.key = key;
50
+ setEvent.newVal = val;
51
+
52
+ window.dispatchEvent(setEvent);
53
+
54
+ _setItem.apply(this, arguments);
55
+ };
56
+ }
57
+
58
+ // search 跳转公共函数
59
+ export function searchJump({ searchValue, isPhone = false, client = "std", url }) {
60
+ searchValue = searchValue.trim()?.toLowerCase();
61
+ // 检查输入是否为纯数字
62
+ if (/^\d+$/.test(searchValue)) {
63
+ // 如果是纯数字,直接跳转到 /{id}
64
+ const target = isPhone ? "_self" : "_blank";
65
+ const url = __Root + `post/${searchValue}`;
66
+ if (target === "_blank") {
67
+ window.open(url, "_blank");
68
+ } else {
69
+ window.location.href = url;
70
+ }
71
+ } else if (searchMap[searchValue]) {
72
+ // 如果是 searchMap 中的关键词,跳转到对应的 URL
73
+ const target = isPhone ? "_self" : "_blank";
74
+ const url = searchMap[searchValue];
75
+ if (target === "_blank") {
76
+ window.open(url, "_blank");
77
+ } else {
78
+ window.location.href = url;
79
+ }
80
+
81
+ } else {
82
+ // 如果不是纯数字,使用原有搜索功能
83
+ const form = document.createElement("form");
84
+ form.method = "GET";
85
+ form.action = url;
86
+ form.target = isPhone ? "_self" : "_blank";
87
+
88
+ const searchInput = document.createElement("input");
89
+ searchInput.type = "hidden";
90
+ searchInput.name = "q";
91
+ searchInput.value = searchValue;
45
92
 
46
- window.dispatchEvent(setEvent)
93
+ const clientInput = document.createElement("input");
94
+ clientInput.type = "hidden";
95
+ clientInput.name = "client";
96
+ clientInput.value = client;
47
97
 
48
- _setItem.apply(this, arguments)
98
+ form.appendChild(searchInput);
99
+ form.appendChild(clientInput);
100
+ document.body.appendChild(form);
101
+ form.submit();
102
+ document.body.removeChild(form);
49
103
  }
50
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-common-ui",
3
- "version": "9.4.1",
3
+ "version": "9.4.2",
4
4
  "description": "JX3BOX UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,6 +14,7 @@
14
14
 
15
15
  <script>
16
16
  import { __Root } from "@jx3box/jx3box-common/data/jx3box.json";
17
+ import {searchJump} from "../../assets/js/utils";
17
18
  export default {
18
19
  name: "search",
19
20
  data: function () {
@@ -25,44 +26,17 @@ export default {
25
26
  },
26
27
  computed: {},
27
28
  methods: {
28
- handleSubmit(e) {
29
+ handleSubmit() {
29
30
  // 获取输入框的值
30
31
  const searchValue = this.$refs.searchInput.value;
31
32
  if (!searchValue) return;
32
33
 
33
- // 检查输入是否为纯数字
34
- if (/^\d+$/.test(searchValue)) {
35
- // 如果是纯数字,直接跳转到 /{id}
36
- const target = this.isPhone ? "_self" : "_blank";
37
- const url = __Root + `post/${searchValue}`;
38
- if (target === "_blank") {
39
- window.open(url, "_blank");
40
- } else {
41
- window.location.href = url;
42
- }
43
- } else {
44
- // 如果不是纯数字,使用原有搜索功能
45
- const form = document.createElement("form");
46
- form.method = "GET";
47
- form.action = this.url;
48
- form.target = this.isPhone ? "_self" : "_blank";
49
-
50
- const searchInput = document.createElement("input");
51
- searchInput.type = "hidden";
52
- searchInput.name = "q";
53
- searchInput.value = searchValue;
54
-
55
- const clientInput = document.createElement("input");
56
- clientInput.type = "hidden";
57
- clientInput.name = "client";
58
- clientInput.value = this.client;
59
-
60
- form.appendChild(searchInput);
61
- form.appendChild(clientInput);
62
- document.body.appendChild(form);
63
- form.submit();
64
- document.body.removeChild(form);
65
- }
34
+ searchJump({
35
+ searchValue: searchValue,
36
+ isPhone: this.isPhone,
37
+ url: this.url,
38
+ client: this.client,
39
+ });
66
40
  },
67
41
  },
68
42
  created: function () {},