gc_i18n 1.5.5 → 1.5.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/example/vue3-test/lang/index.js +27 -27
- package/example/vue3-test/lang/index.json +32 -0
- package/example/vue3-test/package.json +2 -1
- package/example/vue3-test/src/App.vue +19 -0
- package/example/vue3-test/src/auth.js +43 -0
- package/example/vue3-test/src/main.js +3 -18
- package/example/vue3-test/vite.config.js +1 -1
- package/lib/gc_i18n.css +1 -1
- package/lib/gc_i18n.es.js +1427 -1256
- package/lib/gc_i18n.umd.js +50 -50
- package/package.json +1 -1
- package/packages/components/earth.js +29 -0
- package/packages/index.js +342 -62
- package/packages/libs/service.js +68 -29
- package/packages/libs/textEditMode.js +21 -36
- package/packages/swal.css +10 -2
- package/vite.config.js +9 -7
|
@@ -1,29 +1,29 @@
|
|
|
1
|
+
import pro_zh_CN from "pro_iview_v3/lib/locales/zh-CN";
|
|
2
|
+
import iview_zh_CN from "view-ui-plus/dist/locale/zh-CN";
|
|
3
|
+
import pro_zh_TW from "pro_iview_v3/lib/locales/zh-TW";
|
|
4
|
+
import iview_zh_TW from "view-ui-plus/dist/locale/zh-TW";
|
|
1
5
|
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
name: "繁体中文"
|
|
14
|
-
}]
|
|
6
|
+
import gc_i18n from "../../../packages/index";
|
|
7
|
+
export const languages = [
|
|
8
|
+
{
|
|
9
|
+
code: "zh-CN",
|
|
10
|
+
name: "简体中文"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
code: "zh-TW",
|
|
14
|
+
name: "繁体中文"
|
|
15
|
+
}
|
|
16
|
+
];
|
|
15
17
|
export default {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
18
|
+
install(app, router) {
|
|
19
|
+
const { i18n } = new gc_i18n({
|
|
20
|
+
appCode: "TEST_VUE3",
|
|
21
|
+
router,
|
|
22
|
+
messages: {
|
|
23
|
+
"zh-CN": { ...pro_zh_CN, ...iview_zh_CN },
|
|
24
|
+
"zh-TW": { ...pro_zh_TW, ...iview_zh_TW }
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
app.use(i18n);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -14,5 +14,37 @@
|
|
|
14
14
|
"lws22": {
|
|
15
15
|
"zh-cn": "繁体",
|
|
16
16
|
"zh-tw": "繁體"
|
|
17
|
+
},
|
|
18
|
+
"lggagb5": {
|
|
19
|
+
"zh-cn": "登录状态:",
|
|
20
|
+
"zh-tw": "登錄狀態:"
|
|
21
|
+
},
|
|
22
|
+
"ec1po3": {
|
|
23
|
+
"zh-cn": "已登录",
|
|
24
|
+
"zh-tw": "已登錄"
|
|
25
|
+
},
|
|
26
|
+
"fonok3": {
|
|
27
|
+
"zh-cn": "未登录",
|
|
28
|
+
"zh-tw": "未登錄"
|
|
29
|
+
},
|
|
30
|
+
"koca2": {
|
|
31
|
+
"zh-cn": "登录",
|
|
32
|
+
"zh-tw": "登錄"
|
|
33
|
+
},
|
|
34
|
+
"klpb2": {
|
|
35
|
+
"zh-cn": "登出",
|
|
36
|
+
"zh-tw": "登出"
|
|
37
|
+
},
|
|
38
|
+
"gkc0dp4": {
|
|
39
|
+
"zh-cn": "繁體中文",
|
|
40
|
+
"zh-tw": "繁體中文"
|
|
41
|
+
},
|
|
42
|
+
"kgsv2": {
|
|
43
|
+
"zh-cn": "用户",
|
|
44
|
+
"zh-tw": "用戶"
|
|
45
|
+
},
|
|
46
|
+
"f6tq2o4": {
|
|
47
|
+
"zh-cn": "用户房子",
|
|
48
|
+
"zh-tw": "用戶房子"
|
|
17
49
|
}
|
|
18
50
|
}
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
<div id="app">
|
|
3
3
|
<h1>{{ $t("welcome") }}</h1>
|
|
4
4
|
<p>{{ $t("description") }}</p>
|
|
5
|
+
<p class="status">登录状态: {{ authState.token ? "已登录" : "未登录" }}</p>
|
|
6
|
+
<p class="status">Scope: {{ authState.scope || "登录" }}</p>
|
|
5
7
|
<div>
|
|
6
8
|
<button @click="changeLang('zh-CN')">中文</button>
|
|
9
|
+
<button @click="changeLang('zh-TW')">繁體中文</button>
|
|
7
10
|
<button @click="changeLang('en-US')">English</button>
|
|
11
|
+
<button @click="login">登录</button>
|
|
12
|
+
<button @click="logout">登出</button>
|
|
8
13
|
</div>
|
|
9
14
|
<router-view />
|
|
10
15
|
</div>
|
|
@@ -12,12 +17,21 @@
|
|
|
12
17
|
|
|
13
18
|
<script setup>
|
|
14
19
|
import { getCurrentInstance } from "vue";
|
|
20
|
+
import { authState, auth } from "./auth";
|
|
15
21
|
|
|
16
22
|
const { proxy } = getCurrentInstance();
|
|
17
23
|
|
|
18
24
|
const changeLang = (lang) => {
|
|
19
25
|
proxy.$i18n.changeLocale(lang);
|
|
20
26
|
};
|
|
27
|
+
|
|
28
|
+
const login = () => {
|
|
29
|
+
auth.login("demo-user");
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const logout = () => {
|
|
33
|
+
auth.logout();
|
|
34
|
+
};
|
|
21
35
|
</script>
|
|
22
36
|
|
|
23
37
|
<style>
|
|
@@ -42,4 +56,9 @@ button {
|
|
|
42
56
|
button:hover {
|
|
43
57
|
background: #f0f0f0;
|
|
44
58
|
}
|
|
59
|
+
|
|
60
|
+
.status {
|
|
61
|
+
margin: 8px 0;
|
|
62
|
+
color: #666;
|
|
63
|
+
}
|
|
45
64
|
</style>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { reactive } from "vue";
|
|
2
|
+
|
|
3
|
+
const TOKEN_KEY = "I18N_TOKEN";
|
|
4
|
+
const SCOPE_KEY = "I18N_SCOPE";
|
|
5
|
+
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
|
|
8
|
+
export const authState = reactive({
|
|
9
|
+
token: localStorage.getItem(TOKEN_KEY) || "",
|
|
10
|
+
scope: localStorage.getItem(SCOPE_KEY) || ""
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const emit = () => {
|
|
14
|
+
const state = {
|
|
15
|
+
token: authState.token,
|
|
16
|
+
scope: authState.scope,
|
|
17
|
+
isAuthenticated: !!authState.token
|
|
18
|
+
};
|
|
19
|
+
listeners.forEach((listener) => listener(state));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const auth = {
|
|
23
|
+
getToken: () => authState.token,
|
|
24
|
+
getScope: () => authState.scope,
|
|
25
|
+
subscribe(listener) {
|
|
26
|
+
listeners.add(listener);
|
|
27
|
+
return () => listeners.delete(listener);
|
|
28
|
+
},
|
|
29
|
+
login(scope = "demo-user") {
|
|
30
|
+
authState.token = `test-token-${scope}`;
|
|
31
|
+
authState.scope = scope;
|
|
32
|
+
localStorage.setItem(TOKEN_KEY, authState.token);
|
|
33
|
+
localStorage.setItem(SCOPE_KEY, authState.scope);
|
|
34
|
+
emit();
|
|
35
|
+
},
|
|
36
|
+
logout() {
|
|
37
|
+
authState.token = "";
|
|
38
|
+
authState.scope = "";
|
|
39
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
40
|
+
localStorage.removeItem(SCOPE_KEY);
|
|
41
|
+
emit();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createApp } from "vue";
|
|
2
2
|
import { createRouter, createWebHistory } from "vue-router";
|
|
3
|
-
import I18n from "
|
|
3
|
+
import I18n from "../../../packages/index";
|
|
4
4
|
import App from "./App.vue";
|
|
5
|
+
import { auth } from "./auth";
|
|
5
6
|
|
|
6
7
|
// 创建路由实例
|
|
7
8
|
const router = createRouter({
|
|
@@ -23,29 +24,13 @@ const i18n = new I18n({
|
|
|
23
24
|
appCode: "TEST_VUE3",
|
|
24
25
|
router,
|
|
25
26
|
env: "dev",
|
|
26
|
-
|
|
27
|
-
"zh-CN": {
|
|
28
|
-
welcome: "你好"
|
|
29
|
-
},
|
|
30
|
-
"en-US": {
|
|
31
|
-
welcome: "Hello"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
27
|
+
auth
|
|
34
28
|
});
|
|
35
29
|
|
|
36
|
-
console.log("i18n instance:", i18n);
|
|
37
|
-
console.log("i18n.install:", i18n.install);
|
|
38
|
-
|
|
39
30
|
// 使用插件
|
|
40
31
|
app.use(router);
|
|
41
32
|
app.use(i18n);
|
|
42
33
|
|
|
43
|
-
// 手动测试
|
|
44
|
-
console.log(
|
|
45
|
-
"After app.use, app.config.globalProperties.$t:",
|
|
46
|
-
app.config.globalProperties.$t
|
|
47
|
-
);
|
|
48
|
-
|
|
49
34
|
// 挂载应用
|
|
50
35
|
app.mount("#app");
|
|
51
36
|
|
package/lib/gc_i18n.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.i18n-editable-text{position:relative;outline:1px dashed #2d8cf0!important;cursor:pointer!important;background-color:#2d8cf00d;border-radius:2px;transition:all .2s ease}.i18n-editable-text:hover{outline:2px solid #2d8cf0!important;background-color:#2d8cf01a;box-shadow:0 0 8px #2d8cf04d}.i18n-edit-modal-popup{padding:20px}.i18n-edit-modal-title{font-size:18px;font-weight:600;color:#333;margin-bottom:15px}.i18n-edit-modal-content{text-align:left}.i18n-edit-form{max-height:400px;overflow-y:auto;padding-right:10px}.i18n-edit-key{background-color:#f0f9ff;border:1px solid #2d8cf0;border-radius:4px;padding:10px 12px;margin-bottom:15px;font-family:monospace;font-size:13px;color:#2d8cf0;word-break:break-all}.i18n-edit-field{margin-bottom:15px}.i18n-edit-label{display:block;font-weight:500;color:#333;margin-bottom:5px;font-size:14px}.i18n-edit-input{width:100%;height:36px;padding:8px 12px;font-size:14px;border:1px solid #dcdee2;border-radius:4px;color:#515a6e;background-color:#fff;transition:border-color .2s,box-shadow .2s;box-sizing:border-box}.i18n-edit-form::-webkit-scrollbar{width:6px}.i18n-edit-form::-webkit-scrollbar-track{background:#f1f1f1;border-radius:3px}.i18n-edit-form::-webkit-scrollbar-thumb{background:#c5c8ce;border-radius:3px}.i18n-edit-form::-webkit-scrollbar-thumb:hover{background:#999}[disabled] .i18n-editable-text,.i18n-editable-text[disabled]{outline:none!important;cursor:not-allowed!important;background-color:transparent}.i18n-edit-mode-active a.i18n-editable-text,.i18n-edit-mode-active button.i18n-editable-text,.i18n-edit-mode-active .i18n-editable-text,button .i18n-editable-text{pointer-events:auto}.i18n-edit-modal-container .swal2-confirm{background-color:#2d8cf0!important}.i18n-edit-modal-container .swal2-cancel{background-color:#f90!important}.earth{display:flex;align-items:center}.earth .icon{cursor:pointer;color:#666;transition:color .2s}.earth .icon:hover{color:#2d8cf0}.earth .input{display:inline-block;width:100%;height:32px;line-height:1.5;padding:4px 7px;font-size:14px;border:1px solid #dcdee2;border-radius:4px;color:#515a6e;background-color:#fff;background-image:none;position:relative;margin-right:10px}.earth .input:read-only{background-color:#f5f5f5;cursor:default}.earth .input:disabled{background-color:#f5f5f5;cursor:not-allowed;opacity:.7}.i18n-earth-modal-popup{padding:20px}.i18n-earth-modal-title{font-size:18px;font-weight:600;color:#333;margin-bottom:15px}.i18n-modal-content{text-align:left}.i18n-current-lang{background-color:#f0f9ff;border:1px solid #2d8cf0;border-radius:4px;padding:12px;margin-bottom:15px}.i18n-current-lang strong{color:#2d8cf0;display:block;margin-bottom:5px}.i18n-other-langs{border-top:1px solid #e8e8e8;padding-top:15px}.i18n-other-langs strong{display:block;margin-bottom:10px;color:#666}.i18n-lang-item{display:flex;align-items:center;padding:8px 0;border-bottom:1px solid #f0f0f0}.i18n-lang-item:last-child{border-bottom:none}.i18n-lang-code{font-weight:500;color:#333;min-width:80px;margin-right:10px}.i18n-lang-value{color:#666;flex:1}.i18n-earth-edit-popup{padding:20px}.i18n-edit-form{text-align:left;max-height:400px;overflow-y:auto}.i18n-edit-field{display:flex;align-items:center;margin-bottom:15px;padding:8px 0;border-bottom:1px solid #f0f0f0}.i18n-edit-field:last-child{border-bottom:none}.i18n-edit-label{font-weight:500;color:#333;min-width:100px;margin-right:15px;text-align:right}.i18n-edit-input{flex:1;height:36px;padding:0 12px;font-size:14px;border:1px solid #dcdee2;border-radius:4px;color:#515a6e;background-color:#fff;transition:border-color .2s}.i18n-edit-input:focus{outline:none;border-color:#2d8cf0;box-shadow:0 0 0 2px #2d8cf033}.i18n-edit-input::placeholder{color:#c5c8ce}.gc_i18n_html_container{overflow:hidden;padding:0;margin:5px 15px}.gc_i18n_title{font-size:18px;text-align:left}.gc_i18n_close_button{border:none;outline:none;box-shadow:none;position:absolute;right:0;top:0}.gc_i18n_close_button::-moz-focus-inner{border:0;outline:none}div:where(.swal2-container) button:where(.swal2-close):focus-visible{box-shadow:none!important;outline:none!important}div:where(.swal2-container) button:where(.swal2-close)::-moz-focus-inner{border:0;outline:none}.swal2-container{z-index:
|
|
1
|
+
.i18n-editable-text{position:relative;outline:1px dashed #2d8cf0!important;cursor:pointer!important;background-color:#2d8cf00d;border-radius:2px;transition:all .2s ease}.i18n-editable-text:hover{outline:2px solid #2d8cf0!important;background-color:#2d8cf01a;box-shadow:0 0 8px #2d8cf04d}.i18n-edit-modal-popup{padding:20px}.i18n-edit-modal-title{font-size:18px;font-weight:600;color:#333;margin-bottom:15px}.i18n-edit-modal-content{text-align:left}.i18n-edit-form{max-height:400px;overflow-y:auto;padding-right:10px}.i18n-edit-key{background-color:#f0f9ff;border:1px solid #2d8cf0;border-radius:4px;padding:10px 12px;margin-bottom:15px;font-family:monospace;font-size:13px;color:#2d8cf0;word-break:break-all}.i18n-edit-field{margin-bottom:15px}.i18n-edit-label{display:block;font-weight:500;color:#333;margin-bottom:5px;font-size:14px}.i18n-edit-input{width:100%;height:36px;padding:8px 12px;font-size:14px;border:1px solid #dcdee2;border-radius:4px;color:#515a6e;background-color:#fff;transition:border-color .2s,box-shadow .2s;box-sizing:border-box}.i18n-edit-form::-webkit-scrollbar{width:6px}.i18n-edit-form::-webkit-scrollbar-track{background:#f1f1f1;border-radius:3px}.i18n-edit-form::-webkit-scrollbar-thumb{background:#c5c8ce;border-radius:3px}.i18n-edit-form::-webkit-scrollbar-thumb:hover{background:#999}[disabled] .i18n-editable-text,.i18n-editable-text[disabled]{outline:none!important;cursor:not-allowed!important;background-color:transparent}.i18n-edit-mode-active a.i18n-editable-text,.i18n-edit-mode-active button.i18n-editable-text,.i18n-edit-mode-active .i18n-editable-text,button .i18n-editable-text{pointer-events:auto}.i18n-edit-modal-container .swal2-confirm{background-color:#2d8cf0!important}.i18n-edit-modal-container .swal2-cancel{background-color:#f90!important}.earth{display:flex;align-items:center}.earth .icon{cursor:pointer;color:#666;transition:color .2s}.earth .icon:hover{color:#2d8cf0}.earth .input{display:inline-block;width:100%;height:32px;line-height:1.5;padding:4px 7px;font-size:14px;border:1px solid #dcdee2;border-radius:4px;color:#515a6e;background-color:#fff;background-image:none;position:relative;margin-right:10px}.earth .input:read-only{background-color:#f5f5f5;cursor:default}.earth .input:disabled{background-color:#f5f5f5;cursor:not-allowed;opacity:.7}.i18n-earth-modal-popup{padding:20px}.i18n-earth-modal-title{font-size:18px;font-weight:600;color:#333;margin-bottom:15px}.i18n-modal-content{text-align:left}.i18n-current-lang{background-color:#f0f9ff;border:1px solid #2d8cf0;border-radius:4px;padding:12px;margin-bottom:15px}.i18n-current-lang strong{color:#2d8cf0;display:block;margin-bottom:5px}.i18n-other-langs{border-top:1px solid #e8e8e8;padding-top:15px}.i18n-other-langs strong{display:block;margin-bottom:10px;color:#666}.i18n-lang-item{display:flex;align-items:center;padding:8px 0;border-bottom:1px solid #f0f0f0}.i18n-lang-item:last-child{border-bottom:none}.i18n-lang-code{font-weight:500;color:#333;min-width:80px;margin-right:10px}.i18n-lang-value{color:#666;flex:1}.i18n-earth-edit-popup{padding:20px}.i18n-edit-form{text-align:left;max-height:400px;overflow-y:auto}.i18n-edit-field{display:flex;align-items:center;margin-bottom:15px;padding:8px 0;border-bottom:1px solid #f0f0f0}.i18n-edit-field:last-child{border-bottom:none}.i18n-edit-label{font-weight:500;color:#333;min-width:100px;margin-right:15px;text-align:right}.i18n-edit-input{flex:1;height:36px;padding:0 12px;font-size:14px;border:1px solid #dcdee2;border-radius:4px;color:#515a6e;background-color:#fff;transition:border-color .2s}.i18n-edit-input:focus{outline:none;border-color:#2d8cf0;box-shadow:0 0 0 2px #2d8cf033}.i18n-edit-input::placeholder{color:#c5c8ce}:root{--gc-i18n-modal-z-index: 2147483647}.gc_i18n_html_container{overflow:hidden;padding:0;margin:5px 15px}.gc_i18n_title{font-size:18px;text-align:left}.gc_i18n_close_button{border:none;outline:none;box-shadow:none;position:absolute;right:0;top:0}.gc_i18n_close_button::-moz-focus-inner{border:0;outline:none}div:where(.swal2-container) button:where(.swal2-close):focus-visible{box-shadow:none!important;outline:none!important}div:where(.swal2-container) button:where(.swal2-close)::-moz-focus-inner{border:0;outline:none}.swal2-container,.gc_i18n_container,.i18n-edit-modal-container,.i18n-earth-modal-container{z-index:var(--gc-i18n-modal-z-index)!important}
|