@jx3box/jx3box-vue3-ui 0.2.1 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/service/comment.js +79 -81
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-vue3-ui",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "JX3BOX Vue3 UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,9 +26,9 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@element-plus/icons-vue": "^2.1.0",
29
- "@jx3box/jx3box-common": "^7.8.9",
30
- "@jx3box/jx3box-data": "^3.0.9",
31
- "@jx3box/jx3box-emotion": "^1.2.1",
29
+ "@jx3box/jx3box-common": "^7.9.3",
30
+ "@jx3box/jx3box-data": "^3.3.0",
31
+ "@jx3box/jx3box-emotion": "^1.2.3",
32
32
  "@vueuse/core": "^9.13.0",
33
33
  "@vueuse/head": "^0.7.6",
34
34
  "axios": "^1.3.4",
@@ -1,24 +1,26 @@
1
- import { __Links,__next } from "@jx3box/jx3box-common/data/jx3box.json"
2
- import { ElNotification as Notification } from 'element-plus'
1
+ import JX3BOX from "@jx3box/jx3box-common/data/jx3box.json";
3
2
 
3
+ import { ElNotification as Notification } from "element-plus";
4
4
  import { $cms } from "@jx3box/jx3box-common/js/https_v2";
5
5
  import User from "@jx3box/jx3box-common/js/user";
6
+
6
7
  const KEY = "cmt_order";
8
+ const { __Links, __next } = JX3BOX;
7
9
 
8
10
  export async function getOrderMode() {
9
11
  if (User.isLogin()) {
10
12
  return $cms({ mute: true })
11
13
  .get(`/api/cms/user/conf`, {
12
14
  params: {
13
- key: KEY
14
- }
15
+ key: KEY,
16
+ },
15
17
  })
16
- .then(res => {
18
+ .then((res) => {
17
19
  return res.data.data;
18
20
  });
19
21
  } else {
20
- return new Promise(resolve => {
21
- const key = localStorage.getItem(KEY) || 'DESC'
22
+ return new Promise((resolve) => {
23
+ const key = localStorage.getItem(KEY) || "DESC";
22
24
  resolve(key);
23
25
  });
24
26
  }
@@ -30,160 +32,156 @@ export async function setOrderMode(val) {
30
32
  .put(
31
33
  `/api/cms/user/conf`,
32
34
  {
33
- val: val
35
+ val: val,
34
36
  },
35
37
  {
36
38
  params: {
37
- key: KEY
38
- }
39
+ key: KEY,
40
+ },
39
41
  }
40
42
  )
41
- .then(res => {
43
+ .then((res) => {
42
44
  return res.data.data;
43
45
  });
44
46
  } else {
45
- return new Promise(resolve => {
47
+ return new Promise((resolve) => {
46
48
  resolve(localStorage.setItem(KEY, val));
47
49
  });
48
50
  }
49
51
  }
50
52
 
51
-
52
53
  export const GET = function (url, queryParams) {
53
54
  let options = {
54
- "method": "GET",
55
+ method: "GET",
55
56
  headers: {
56
- 'Accept': 'application/json',
57
- 'Content-Type': 'application/json'
57
+ Accept: "application/json",
58
+ "Content-Type": "application/json",
58
59
  },
59
- }
60
- return __fetch(url, queryParams, options)
61
-
62
- }
60
+ };
61
+ return __fetch(url, queryParams, options);
62
+ };
63
63
 
64
- const postRecord = {}
64
+ const postRecord = {};
65
65
 
66
66
  export const POST = function (url, queryParams, body) {
67
-
68
67
  if (!postRecord[url]) {
69
68
  postRecord[url] = {
70
69
  lastest: Date.now(),
71
- count: 0
72
- }
70
+ count: 0,
71
+ };
73
72
  // 60 秒内发送评论超过10条
74
73
  } else if (Date.now() - postRecord[url].lastest < 60 * 1000) {
75
-
76
74
  if (postRecord[url].count >= 6) {
77
75
  Notification.warning({
78
76
  title: "系统",
79
77
  message: "你单身多久了? 动作这么快, 系统处理不过来 ( T_T )",
80
78
  duration: 3000,
81
- position: "bottom-right"
82
- })
79
+ position: "bottom-right",
80
+ });
83
81
  return new Promise((reslove, reject) => {
84
- reject()
85
- })
82
+ reject();
83
+ });
86
84
  } else {
87
- postRecord[url].count = postRecord[url].count + 1
85
+ postRecord[url].count = postRecord[url].count + 1;
88
86
  }
89
-
90
87
  } else if (Date.now() - postRecord[url].lastest > 60 * 1000) {
91
88
  postRecord[url] = {
92
89
  lastest: Date.now(),
93
- count: 0
94
- }
90
+ count: 0,
91
+ };
95
92
  }
96
93
  let options = {
97
- "method": "POST",
94
+ method: "POST",
98
95
  headers: {
99
- 'Accept': 'application/json',
100
- 'Content-Type': 'application/json'
96
+ Accept: "application/json",
97
+ "Content-Type": "application/json",
101
98
  },
102
- body: JSON.stringify(body)
103
- }
104
- return __fetch(url, queryParams, options)
105
- }
99
+ body: JSON.stringify(body),
100
+ };
101
+ return __fetch(url, queryParams, options);
102
+ };
106
103
  export const PUT = function (url, queryParams, body) {
107
104
  let options = {
108
- "method": "PUT",
105
+ method: "PUT",
109
106
  headers: {
110
- 'Accept': 'application/json',
111
- 'Content-Type': 'application/json'
107
+ Accept: "application/json",
108
+ "Content-Type": "application/json",
112
109
  },
113
- body: JSON.stringify(body)
114
- }
115
- return __fetch(url, queryParams, options)
116
- }
110
+ body: JSON.stringify(body),
111
+ };
112
+ return __fetch(url, queryParams, options);
113
+ };
117
114
 
118
115
  export const DELETE = function (url, queryParams) {
119
116
  let options = {
120
- "method": "DELETE"
121
- }
122
- return __fetch(url, queryParams, options)
123
- }
117
+ method: "DELETE",
118
+ };
119
+ return __fetch(url, queryParams, options);
120
+ };
124
121
 
125
122
  function __fetch(url, queryParams, options) {
126
- let domain = process.env.NODE_ENV == "production" ? __next : "/"
123
+ let domain = process.env.NODE_ENV == "production" ? __next : "/";
127
124
  if (domain[domain.length - 1] == "/") {
128
- domain = domain.substring(0, domain.length - 1)
125
+ domain = domain.substring(0, domain.length - 1);
129
126
  }
130
- url = domain + url
131
- options.credentials = 'include'
127
+ url = domain + url;
128
+ options.credentials = "include";
132
129
  if (queryParams) {
133
- let queryQueue = []
130
+ let queryQueue = [];
134
131
  Object.keys(queryParams).forEach((key) => {
135
- queryQueue.push(key + "=" + queryParams[key])
136
- })
137
- let domain = __next
132
+ queryQueue.push(key + "=" + queryParams[key]);
133
+ });
134
+ let domain = __next;
138
135
  if (domain[domain.length - 1] == "/") {
139
- domain = domain.substring(0, domain.length - 1)
136
+ domain = domain.substring(0, domain.length - 1);
140
137
  }
141
- url = url + "?" + queryQueue.join("&")
138
+ url = url + "?" + queryQueue.join("&");
142
139
  }
143
140
 
144
141
  return fetch(url, options).then((resp) => {
145
142
  switch (resp.status) {
146
143
  case 200:
147
- break
144
+ break;
148
145
  case 401:
149
- window.location.href = __Links.account.login + "?redirect=" + encodeURIComponent(window.location.href)
150
- throw new Error("错误:" + resp.statusText)
146
+ window.location.href = __Links.account.login + "?redirect=" + encodeURIComponent(window.location.href);
147
+ throw new Error("错误:" + resp.statusText);
151
148
  case 403:
152
- window.location.href = __Links.account.login + "?redirect=" + encodeURIComponent(window.location.href)
153
- throw new Error("错误:" + resp.statusText)
149
+ window.location.href = __Links.account.login + "?redirect=" + encodeURIComponent(window.location.href);
150
+ throw new Error("错误:" + resp.statusText);
154
151
  case 423:
155
- window.location.href = __Links.account.email_verify + "?redirect=" + encodeURIComponent(window.location.href)
156
- throw new Error("错误:" + resp.statusText)
152
+ window.location.href =
153
+ __Links.account.email_verify + "?redirect=" + encodeURIComponent(window.location.href);
154
+ throw new Error("错误:" + resp.statusText);
157
155
  case 406:
158
156
  resp.text().then((body) => {
159
157
  Notification.warning({
160
158
  title: "系统",
161
159
  message: body || "提交内容不合法,请重新提交",
162
160
  duration: 3000,
163
- position: "bottom-right"
164
- })
165
- })
161
+ position: "bottom-right",
162
+ });
163
+ });
166
164
 
167
- throw new Error("错误:" + resp.statusText)
165
+ throw new Error("错误:" + resp.statusText);
168
166
  default:
169
167
  resp.text().then((body) => {
170
168
  Notification.error({
171
169
  title: "系统:" + resp.statusText,
172
170
  message: body || "系统错误,请稍后重试!",
173
171
  duration: 3000,
174
- position: "bottom-right"
175
- })
176
- })
172
+ position: "bottom-right",
173
+ });
174
+ });
177
175
 
178
- throw new Error("错误:" + resp.statusText)
176
+ throw new Error("错误:" + resp.statusText);
179
177
  }
180
- let contentType = resp.headers.get("Content-Type")
181
- contentType = contentType && contentType.split(";").shift()
178
+ let contentType = resp.headers.get("Content-Type");
179
+ contentType = contentType && contentType.split(";").shift();
182
180
  switch (contentType) {
183
181
  case "application/json":
184
- return resp.json()
182
+ return resp.json();
185
183
  default:
186
- return resp.text()
184
+ return resp.text();
187
185
  }
188
- })
186
+ });
189
187
  }