@antv/dumi-theme-antv 0.8.0-beta.5 → 0.8.0-beta.7
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/dist/model/AIChat.js +51 -1
- package/dist/model/auth.js +45 -25
- package/dist/slots/Header/index.js +29 -3
- package/dist/utils/request.js +2 -6
- package/package.json +1 -1
package/dist/model/AIChat.js
CHANGED
|
@@ -13,6 +13,7 @@ import { derive, subscribeKey } from 'valtio/utils';
|
|
|
13
13
|
import localforage from 'localforage';
|
|
14
14
|
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
15
15
|
import { history } from "dumi";
|
|
16
|
+
import { message } from "antd";
|
|
16
17
|
|
|
17
18
|
// --- 配置 ---
|
|
18
19
|
// 定义需要持久化的 state key
|
|
@@ -223,4 +224,53 @@ export var createNewSession = function createNewSession(config) {
|
|
|
223
224
|
var _config$lang;
|
|
224
225
|
history.push("/".concat((_config$lang = config.lang) !== null && _config$lang !== void 0 ? _config$lang : 'zh', "/ai-playground"));
|
|
225
226
|
}
|
|
226
|
-
};
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 清空所有本地AI对话记录和相关状态。用户注销账户或手动请求清除数据时调用。
|
|
231
|
+
*
|
|
232
|
+
* 该函数会执行以下操作:
|
|
233
|
+
* 1. 从 localforage 中删除持久化的状态数据。
|
|
234
|
+
* 2. 将内存中的 AIChatStore 重置为初始状态。
|
|
235
|
+
*
|
|
236
|
+
*/
|
|
237
|
+
export var clearAllChatData = /*#__PURE__*/function () {
|
|
238
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
239
|
+
var initialKeys, _i, _initialKeys, key;
|
|
240
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
241
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
242
|
+
case 0:
|
|
243
|
+
_context2.prev = 0;
|
|
244
|
+
_context2.next = 3;
|
|
245
|
+
return localforage.removeItem(STORAGE_KEY);
|
|
246
|
+
case 3:
|
|
247
|
+
console.log("[AIChat] Persistent state with key \"".concat(STORAGE_KEY, "\" has been removed."));
|
|
248
|
+
|
|
249
|
+
// 步骤 2: 将内存中的 valtio store 重置为初始状态。
|
|
250
|
+
// 这会立即更新UI,让所有对话记录从界面上消失。
|
|
251
|
+
// 注意:我们不能直接做 AIChatStore = initialState,
|
|
252
|
+
// 因为 proxy 对象是不可替换的。我们必须逐个属性地重置。
|
|
253
|
+
initialKeys = Object.keys(initialState);
|
|
254
|
+
for (_i = 0, _initialKeys = initialKeys; _i < _initialKeys.length; _i++) {
|
|
255
|
+
key = _initialKeys[_i];
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
AIChatStore[key] = initialState[key];
|
|
258
|
+
}
|
|
259
|
+
console.log('[AIChat] In-memory state has been reset to initial values.');
|
|
260
|
+
_context2.next = 13;
|
|
261
|
+
break;
|
|
262
|
+
case 9:
|
|
263
|
+
_context2.prev = 9;
|
|
264
|
+
_context2.t0 = _context2["catch"](0);
|
|
265
|
+
console.error('[AIChat] Failed to clear all chat data:', _context2.t0);
|
|
266
|
+
message.error('清空对话记录失败,请刷新页面后重试。');
|
|
267
|
+
case 13:
|
|
268
|
+
case "end":
|
|
269
|
+
return _context2.stop();
|
|
270
|
+
}
|
|
271
|
+
}, _callee2, null, [[0, 9]]);
|
|
272
|
+
}));
|
|
273
|
+
return function clearAllChatData() {
|
|
274
|
+
return _ref2.apply(this, arguments);
|
|
275
|
+
};
|
|
276
|
+
}();
|
package/dist/model/auth.js
CHANGED
|
@@ -24,7 +24,7 @@ function hasSkipLoginParam() {
|
|
|
24
24
|
// 1. 定义 State (只包含数据)
|
|
25
25
|
export var authStore = proxy({
|
|
26
26
|
isModalOpen: false,
|
|
27
|
-
isAuthenticated:
|
|
27
|
+
isAuthenticated: false,
|
|
28
28
|
token: localStorage.getItem('authToken')
|
|
29
29
|
});
|
|
30
30
|
|
|
@@ -68,48 +68,68 @@ export var loginOrRegister = /*#__PURE__*/function () {
|
|
|
68
68
|
return _ref.apply(this, arguments);
|
|
69
69
|
};
|
|
70
70
|
}();
|
|
71
|
-
export var logout = function
|
|
72
|
-
try {
|
|
73
|
-
request.delete('/api/modules/user/api/accounts/logout');
|
|
74
|
-
} catch (e) {
|
|
75
|
-
console.error('Logout failed in store:', e);
|
|
76
|
-
} finally {
|
|
77
|
-
authStore.token = null;
|
|
78
|
-
authStore.isAuthenticated = false;
|
|
79
|
-
localStorage.removeItem('authToken');
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
export function sendValidationCode(data) {
|
|
83
|
-
return request.post('/api/modules/user/api/validation_code/send', data);
|
|
84
|
-
}
|
|
85
|
-
export var initializeAuth = /*#__PURE__*/function () {
|
|
71
|
+
export var logout = /*#__PURE__*/function () {
|
|
86
72
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
87
73
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
88
74
|
while (1) switch (_context2.prev = _context2.next) {
|
|
89
75
|
case 0:
|
|
90
76
|
_context2.prev = 0;
|
|
77
|
+
_context2.next = 3;
|
|
78
|
+
return request.delete('/api/modules/user/api/accounts/logout');
|
|
79
|
+
case 3:
|
|
80
|
+
_context2.next = 8;
|
|
81
|
+
break;
|
|
82
|
+
case 5:
|
|
83
|
+
_context2.prev = 5;
|
|
84
|
+
_context2.t0 = _context2["catch"](0);
|
|
85
|
+
console.error('Logout failed in store:', _context2.t0);
|
|
86
|
+
case 8:
|
|
87
|
+
_context2.prev = 8;
|
|
88
|
+
authStore.token = null;
|
|
89
|
+
authStore.isAuthenticated = false;
|
|
90
|
+
localStorage.removeItem('authToken');
|
|
91
|
+
return _context2.finish(8);
|
|
92
|
+
case 13:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context2.stop();
|
|
95
|
+
}
|
|
96
|
+
}, _callee2, null, [[0, 5, 8, 13]]);
|
|
97
|
+
}));
|
|
98
|
+
return function logout() {
|
|
99
|
+
return _ref2.apply(this, arguments);
|
|
100
|
+
};
|
|
101
|
+
}();
|
|
102
|
+
export function sendValidationCode(data) {
|
|
103
|
+
return request.post('/api/modules/user/api/validation_code/send', data);
|
|
104
|
+
}
|
|
105
|
+
export var initializeAuth = /*#__PURE__*/function () {
|
|
106
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
107
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
108
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
_context3.prev = 0;
|
|
91
111
|
if (hasSkipLoginParam()) {
|
|
92
|
-
|
|
112
|
+
_context3.next = 4;
|
|
93
113
|
break;
|
|
94
114
|
}
|
|
95
|
-
|
|
115
|
+
_context3.next = 4;
|
|
96
116
|
return request.get('/api/modules/user/api/accounts/get_company_info');
|
|
97
117
|
case 4:
|
|
98
118
|
authStore.isAuthenticated = true;
|
|
99
|
-
|
|
119
|
+
_context3.next = 11;
|
|
100
120
|
break;
|
|
101
121
|
case 7:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
console.error('Initialize auth failed in store:',
|
|
122
|
+
_context3.prev = 7;
|
|
123
|
+
_context3.t0 = _context3["catch"](0);
|
|
124
|
+
console.error('Initialize auth failed in store:', _context3.t0);
|
|
105
125
|
authStore.isAuthenticated = false;
|
|
106
126
|
case 11:
|
|
107
127
|
case "end":
|
|
108
|
-
return
|
|
128
|
+
return _context3.stop();
|
|
109
129
|
}
|
|
110
|
-
},
|
|
130
|
+
}, _callee3, null, [[0, 7]]);
|
|
111
131
|
}));
|
|
112
132
|
return function initializeAuth() {
|
|
113
|
-
return
|
|
133
|
+
return _ref3.apply(this, arguments);
|
|
114
134
|
};
|
|
115
135
|
}();
|
|
@@ -13,7 +13,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
14
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
-
import { CaretDownFilled, DownOutlined, GithubOutlined, LinkOutlined, MenuOutlined, WechatOutlined } from '@ant-design/icons';
|
|
16
|
+
import { CaretDownFilled, DownOutlined, GithubOutlined, LinkOutlined, LogoutOutlined, MenuOutlined, UserDeleteOutlined, UserOutlined, WechatOutlined } from '@ant-design/icons';
|
|
17
17
|
import { Alert, Button, Dropdown, Menu, Modal, Popover } from 'antd';
|
|
18
18
|
import cx from 'classnames';
|
|
19
19
|
import { FormattedMessage, Link, useLocale, useSiteData } from 'dumi';
|
|
@@ -31,6 +31,9 @@ import '@petercatai/assistant/style';
|
|
|
31
31
|
import { useLocation } from 'react-router-dom';
|
|
32
32
|
import { determineUserType } from "../../utils/user";
|
|
33
33
|
import styles from "./index.module.less";
|
|
34
|
+
import { useSnapshot } from "valtio";
|
|
35
|
+
import { authStore, logout } from "../../model/auth";
|
|
36
|
+
import { clearAllChatData } from "../../model/AIChat";
|
|
34
37
|
function redirectChinaMirror(chinaMirrorOrigin) {
|
|
35
38
|
window.location.href = window.location.href.replace(window.location.origin, chinaMirrorOrigin);
|
|
36
39
|
}
|
|
@@ -76,7 +79,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
|
|
|
76
79
|
ecosystems = _ref.ecosystems,
|
|
77
80
|
announcement = _ref.announcement;
|
|
78
81
|
var isAntVHome = isAntVSite && isHomePage; // 是否为AntV官网首页
|
|
79
|
-
|
|
82
|
+
var authSnap = useSnapshot(authStore);
|
|
80
83
|
var _useState = useState(false),
|
|
81
84
|
_useState2 = _slicedToArray(_useState, 2),
|
|
82
85
|
bannerVisible = _useState2[0],
|
|
@@ -403,7 +406,30 @@ var HeaderComponent = function HeaderComponent(_ref) {
|
|
|
403
406
|
href: githubUrl,
|
|
404
407
|
target: "_blank",
|
|
405
408
|
rel: "noreferrer"
|
|
406
|
-
}, /*#__PURE__*/React.createElement(GithubOutlined, null)))
|
|
409
|
+
}, /*#__PURE__*/React.createElement(GithubOutlined, null))), authSnap.isAuthenticated && /*#__PURE__*/React.createElement("li", {
|
|
410
|
+
className: cx(styles.navIcon, styles.githubCorner)
|
|
411
|
+
}, /*#__PURE__*/React.createElement(Dropdown, {
|
|
412
|
+
menu: {
|
|
413
|
+
items: [{
|
|
414
|
+
key: 'logout',
|
|
415
|
+
label: /*#__PURE__*/React.createElement("a", {
|
|
416
|
+
onClick: function onClick() {
|
|
417
|
+
return logout();
|
|
418
|
+
}
|
|
419
|
+
}, "\u9000\u51FA\u767B\u5F55"),
|
|
420
|
+
icon: /*#__PURE__*/React.createElement(LogoutOutlined, null)
|
|
421
|
+
}, {
|
|
422
|
+
key: 'deleteAccount',
|
|
423
|
+
label: /*#__PURE__*/React.createElement("a", {
|
|
424
|
+
onClick: function onClick() {
|
|
425
|
+
logout();
|
|
426
|
+
clearAllChatData();
|
|
427
|
+
}
|
|
428
|
+
}, "\u6CE8\u9500\u8D26\u53F7"),
|
|
429
|
+
icon: /*#__PURE__*/React.createElement(UserDeleteOutlined, null)
|
|
430
|
+
}]
|
|
431
|
+
}
|
|
432
|
+
}, /*#__PURE__*/React.createElement("a", null, /*#__PURE__*/React.createElement(UserOutlined, null)))));
|
|
407
433
|
return /*#__PURE__*/React.createElement("header", {
|
|
408
434
|
className: cx(styles.header, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.transparent, !!transparent && !productMenuVisible), styles.isHomePage, !!isHomePage && !isAntVHome), styles.lightTheme, !!isAntVHome && !productMenuVisible && isWide), styles.isAntVHome, !!isAntVHome), styles.fixed, popupMenuVisible))
|
|
409
435
|
}, bannerVisible && announcementTitle && /*#__PURE__*/React.createElement(Alert, {
|
package/dist/utils/request.js
CHANGED
|
@@ -5,12 +5,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import axios from 'axios';
|
|
8
|
-
import { message } from 'antd';
|
|
9
8
|
import { getBaseURL } from "./env";
|
|
10
9
|
import { getToken } from "./auth";
|
|
11
10
|
var req = axios.create({
|
|
12
11
|
baseURL: getBaseURL(),
|
|
13
|
-
timeout: 60000
|
|
12
|
+
timeout: 60000,
|
|
13
|
+
withCredentials: true
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
// 请求拦截器
|
|
@@ -29,10 +29,6 @@ req.interceptors.response.use(
|
|
|
29
29
|
// @ts-ignore - Temporarily ignore type mismatch if it occurs with custom ApiResponse
|
|
30
30
|
function (response) {
|
|
31
31
|
return response.data;
|
|
32
|
-
}, function (error) {
|
|
33
|
-
var errorMessage = error.message;
|
|
34
|
-
message.error(errorMessage);
|
|
35
|
-
return Promise.reject(error);
|
|
36
32
|
});
|
|
37
33
|
|
|
38
34
|
/**
|