@jx3box/jx3box-ui 2.4.22 → 2.4.23

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.
@@ -27,9 +27,9 @@ PC 端自动续期挂在公共头 `src/CommonHeader.vue`。这个组件会被各
27
27
 
28
28
  ## PC 账号切换注意事项
29
29
 
30
- PC 公共库存在马甲切换:
30
+ PC 公共库存在账号切换:
31
31
 
32
- - 马甲缓存 key:`jx3box-alternate-{uid}`
32
+ - 账号缓存 key:`jx3box-alternate-{uid}`
33
33
  - 当前请求 token 读取优先级:`__token` 优先于 `token`
34
34
 
35
35
  因此 refresh 成功后必须同时更新:
@@ -39,14 +39,14 @@ PC 公共库存在马甲切换:
39
39
  - `created_at`
40
40
  - 当前激活账号的 `jx3box-alternate-{uid}` 记录
41
41
 
42
- 否则用户切换马甲时可能拿回旧 token,或者后续请求继续优先使用旧 `__token`。
42
+ 否则用户切换账号时可能拿回旧 token,或者后续请求继续优先使用旧 `__token`。
43
43
 
44
- 马甲切换时必须先将目标马甲的 token 同步到 `localStorage.__token`;如果当前标签页存在
44
+ 账号切换时必须先将目标账号的 token 同步到 `localStorage.__token`;如果当前标签页存在
45
45
  `sessionStorage.__token`,也要一起更新,然后才能调用 refresh 接口。退出登录(包括
46
46
  `token_version` 触发的强制退出)时必须同时清理这两个 `__token`。否则业务页可能从普通
47
47
  `uid` 读取新账号,而接口仍携带旧账号的高优先级 token,最终在同一页面显示两个 UID。
48
48
 
49
- 新增马甲跳转登录页前也要先清理两个 `__token`,因为账号页登录成功默认只更新普通
49
+ 新增账号跳转登录页前也要先清理两个 `__token`,因为账号页登录成功默认只更新普通
50
50
  `token/uid`。公共头拿到 `/user/my/info` 后,如果接口 UID 与本地 UID 不一致、当前又不是
51
51
  显式 `?__token=` 入口,应清除遗留覆盖 token 并刷新一次完成自愈。显式 URL token 入口则
52
52
  强制执行一次 refresh,把普通用户缓存归一到 URL token 对应的账号;UID 发生变化时刷新页面。
@@ -61,7 +61,7 @@ localStorage.setItem("jx3box:auto_refresh_token", "false");
61
61
 
62
62
  值为 `"false"` 或 `"0"` 时不自动续期;其它情况按默认开启处理。
63
63
 
64
- 该开关只控制后台自动续期。马甲切换和显式 URL token 身份归一属于用户主动登录流程,使用
64
+ 该开关只控制后台自动续期。账号切换和显式 URL token 身份归一属于用户主动登录流程,使用
65
65
  `force` 刷新,不受此开关影响。
66
66
 
67
67
  ## 失败语义
@@ -28,7 +28,7 @@ export default {
28
28
  view: "查看",
29
29
  profileCenter: "个人中心",
30
30
  publishCenter: "发布中心",
31
- switchAlternate: "切换马甲",
31
+ switchAlternate: "切换账号",
32
32
  themeStyle: "主题风格",
33
33
  logout: "退出登录",
34
34
  roleManage: "我的角色",
@@ -60,14 +60,14 @@ export default {
60
60
  all: "全部",
61
61
 
62
62
  alternate: {
63
- title: "切换马甲",
63
+ title: "切换账号",
64
64
  userNickname: "用户昵称:",
65
65
  lastLogin: "上次登录:",
66
66
  expired: "(已过期)",
67
- expiredNeedRelogin: "该马甲已过期,请重新登录",
68
- switchConfirm: "确定要切换到该马甲吗?",
69
- deleteConfirm: "确定要删除该马甲吗?",
70
- maxFive: "最多只能添加5个马甲",
67
+ expiredNeedRelogin: "该账号已过期,请重新登录",
68
+ switchConfirm: "确定要切换到该账号吗?",
69
+ deleteConfirm: "确定要删除该账号吗?",
70
+ maxFive: "最多只能添加5个账号",
71
71
  },
72
72
  nav: {
73
73
  index: "首页",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-ui",
3
- "version": "2.4.22",
3
+ "version": "2.4.23",
4
4
  "description": "JX3BOX Vue3 UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -70,6 +70,7 @@ import _ from "lodash";
70
70
  // 子模块
71
71
  import logo from "./header/logo.vue";
72
72
  import client from "./header/client.vue";
73
+ import { getCurrentClient } from "./header/client-switch";
73
74
  import search from "./header/search.vue";
74
75
  import nav from "./header/nav.vue";
75
76
  import user from "./header/user.vue";
@@ -133,7 +134,7 @@ export default {
133
134
  },
134
135
  computed: {
135
136
  client: function () {
136
- return location.hostname.includes("origin") ? "origin" : "std";
137
+ return getCurrentClient();
137
138
  },
138
139
  siteRoot: function () {
139
140
  return location.host.includes("origin") ? JX3BOX.__OriginRoot : JX3BOX.__Root;
@@ -226,7 +227,7 @@ export default {
226
227
  })
227
228
  .then(() => {
228
229
  this.$refs.user?.logout();
229
- // 清除马甲所有马甲信息
230
+ // 清除所有账号信息
230
231
  let keys = Object.keys(localStorage);
231
232
  let alternate = keys.filter((key) => key.startsWith("jx3box-alternate-"));
232
233
 
@@ -4,7 +4,7 @@
4
4
  v-model="visible"
5
5
  custom-class="c-alternate"
6
6
  width="360px"
7
- :title="$jx3boxT('jx3boxUi.commonHeader.alternate.title', '切换马甲')"
7
+ :title="$jx3boxT('jx3boxUi.commonHeader.alternate.title', '切换账号')"
8
8
  >
9
9
  <div class="c-alternate__content">
10
10
  <div
@@ -59,7 +59,7 @@ export default {
59
59
  alternate: [
60
60
  // {
61
61
  // uid: 100,
62
- // name: "马甲1",
62
+ // name: "账号1",
63
63
  // avatar: "https://avatar.jx3box.com/avatar/1",
64
64
  // created_at: 1620000000000,
65
65
  // },
@@ -105,7 +105,7 @@ export default {
105
105
  }
106
106
  });
107
107
 
108
- // 如果当前没有马甲,添加当前登录用户
108
+ // 如果当前没有账号,添加当前登录用户
109
109
  if (!this.alternate?.length) {
110
110
  const data = {
111
111
  uid: this.profile.uid,
@@ -142,11 +142,11 @@ export default {
142
142
  isExpired(time) {
143
143
  return dayjs().diff(time, "day") > 30;
144
144
  },
145
- // 选择马甲
145
+ // 选择账号
146
146
  onSelectAlternate(item) {
147
147
  if (this.isExpired(item.created_at)) {
148
148
  this.$message.error(
149
- this.$jx3boxT("jx3boxUi.commonHeader.alternate.expiredNeedRelogin", "该马甲已过期,请重新登录")
149
+ this.$jx3boxT("jx3boxUi.commonHeader.alternate.expiredNeedRelogin", "该账号已过期,请重新登录")
150
150
  );
151
151
  return;
152
152
  }
@@ -154,7 +154,7 @@ export default {
154
154
  return;
155
155
  }
156
156
  this.$confirm(
157
- this.$jx3boxT("jx3boxUi.commonHeader.alternate.switchConfirm", "确定要切换到该马甲吗?"),
157
+ this.$jx3boxT("jx3boxUi.commonHeader.alternate.switchConfirm", "确定要切换到该账号吗?"),
158
158
  this.$jx3boxT("jx3boxUi.common.tip", "提示"),
159
159
  {
160
160
  confirmButtonText: this.$jx3boxT("jx3boxUi.common.confirm", "确定"),
@@ -164,7 +164,7 @@ export default {
164
164
  )
165
165
  .then(async () => {
166
166
  await User.update(item);
167
- // 请求层优先读取 __token;必须与刚切换的马甲 token 同步,避免继续请求旧账号。
167
+ // 请求层优先读取 __token;必须与刚切换的账号 token 同步,避免继续请求旧账号。
168
168
  syncActiveAuthToken(item.token);
169
169
  try {
170
170
  localStorage.setItem(
@@ -182,10 +182,10 @@ export default {
182
182
  })
183
183
  .catch(() => {});
184
184
  },
185
- // 删除马甲
185
+ // 删除账号
186
186
  onRemoveAlternate(item) {
187
187
  this.$confirm(
188
- this.$jx3boxT("jx3boxUi.commonHeader.alternate.deleteConfirm", "确定要删除该马甲吗?"),
188
+ this.$jx3boxT("jx3boxUi.commonHeader.alternate.deleteConfirm", "确定要删除该账号吗?"),
189
189
  this.$jx3boxT("jx3boxUi.common.tip", "提示"),
190
190
  {
191
191
  confirmButtonText: this.$jx3boxT("jx3boxUi.common.confirm", "确定"),
@@ -200,10 +200,10 @@ export default {
200
200
  })
201
201
  .catch(() => {});
202
202
  },
203
- // 新增马甲
203
+ // 新增账号
204
204
  onAddAlternate() {
205
205
  if (this.overLength) {
206
- this.$message.error(this.$jx3boxT("jx3boxUi.commonHeader.alternate.maxFive", "最多只能添加5个马甲"));
206
+ this.$message.error(this.$jx3boxT("jx3boxUi.commonHeader.alternate.maxFive", "最多只能添加5个账号"));
207
207
  return;
208
208
  }
209
209
  // 新账号登录只会写普通 token;先清掉当前账号的高优先级 token,避免登录完成后仍请求旧账号。
@@ -0,0 +1,14 @@
1
+ export function isLocalDevelopment() {
2
+ return (
3
+ process.env.NODE_ENV === "development" ||
4
+ ["localhost", "127.0.0.1", "0.0.0.0", "[::1]", "::1"].includes(window.location.hostname)
5
+ );
6
+ }
7
+
8
+ export function getCurrentClient() {
9
+ if (isLocalDevelopment()) {
10
+ const client = new URLSearchParams(window.location.search).get("client");
11
+ if (client === "std" || client === "origin") return client;
12
+ }
13
+ return window.location.hostname.includes("origin") ? "origin" : "std";
14
+ }
@@ -94,6 +94,7 @@
94
94
 
95
95
  <script>
96
96
  import i18nMixin from "../../i18n/mixin";
97
+ import { getCurrentClient, isLocalDevelopment } from "./client-switch";
97
98
  export default {
98
99
  name: "clientSwitch",
99
100
  mixins: [i18nMixin],
@@ -105,7 +106,7 @@ export default {
105
106
  },
106
107
  data: function () {
107
108
  return {
108
- activeKey: this.defaultValue || (location.host.includes("origin") ? "origin" : "std"),
109
+ activeKey: this.defaultValue || getCurrentClient(),
109
110
  isMenuOpen: false,
110
111
  };
111
112
  },
@@ -136,17 +137,16 @@ export default {
136
137
  switchGame: function (target) {
137
138
  if (!target || (target !== "std" && target !== "origin")) return;
138
139
 
139
- const currentPath = window.location.pathname;
140
- const currentSearch = window.location.search;
141
- const currentHash = window.location.hash;
142
- const protocol = window.location.protocol;
143
-
144
- const targetHost = target === "std" ? "www.jx3box.com" : "origin.jx3box.com";
145
- const finalUrl = protocol + "//" + targetHost + currentPath + currentSearch + currentHash;
140
+ const url = new URL(window.location.href);
141
+ if (isLocalDevelopment()) {
142
+ url.searchParams.set("client", target);
143
+ } else {
144
+ url.host = target === "std" ? "www.jx3box.com" : "origin.jx3box.com";
145
+ }
146
146
 
147
147
  this.activeKey = target;
148
148
  this.closeMenu();
149
- window.location.href = finalUrl;
149
+ window.location.href = url.href;
150
150
  },
151
151
  },
152
152
  mounted: function () {
@@ -72,7 +72,7 @@
72
72
 
73
73
  <el-button-group class="u-actions">
74
74
  <a class="el-button el-button--default is-plain" @click="changeAlternate">{{
75
- $jx3boxT("jx3boxUi.commonHeader.switchAlternate", "切换马甲")
75
+ $jx3boxT("jx3boxUi.commonHeader.switchAlternate", "切换账号")
76
76
  }}</a>
77
77
  <a class="el-button el-button--default is-plain" href="/dashboard/config">{{
78
78
  $jx3boxT("jx3boxUi.commonHeader.config", "偏好设置")
@@ -218,7 +218,7 @@ export default {
218
218
  .then(() => {
219
219
  this.$emit("logout");
220
220
 
221
- // 清除马甲所有马甲信息
221
+ // 清除所有账号信息
222
222
  let keys = Object.keys(localStorage);
223
223
  let alternate = keys.filter((key) => key.startsWith("jx3box-alternate-"));
224
224