lt-business-component 1.0.1

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/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "lt-business-component",
3
+ "version": "1.0.1",
4
+ "private": false,
5
+ "description": "a lib base on longtec",
6
+ "main": "lib/lt-business-component.umd.min.js",
7
+ "keyword": "vue3 antd",
8
+ "author": "longtec",
9
+ "license": "MIT",
10
+ "scripts": {
11
+ "serve": "vue-cli-service serve",
12
+ "build": "vue-cli-service build",
13
+ "test:unit": "vue-cli-service test:unit",
14
+ "lint": "vue-cli-service lint",
15
+ "lib": "vue-cli-service build --target lib --name lt-business-component --dest lib packages/index.ts"
16
+ },
17
+ "dependencies": {
18
+ "@ant-design/icons-vue": "^6.1.0",
19
+ "@vueuse/core": "^9.13.0",
20
+ "ant-design-vue": "^4.2.3",
21
+ "axios": "^1.3.5",
22
+ "browserslist": "^4.23.0",
23
+ "caniuse-lite": "^1.0.30001620",
24
+ "colorpicker-v3": "^2.10.2",
25
+ "core-js": "^3.8.3",
26
+ "dayjs": "^1.11.12",
27
+ "jquery": "^3.6.4",
28
+ "less": "^4.1.3",
29
+ "less-loader": "^11.1.0",
30
+ "lodash-es": "^4.17.21",
31
+ "lt-a-baseui": "^1.0.60",
32
+ "lt-request": "^1.0.4",
33
+ "node-polyfill-webpack-plugin": "^4.0.0",
34
+ "pinia": "^2.1.7",
35
+ "register-service-worker": "^1.7.2",
36
+ "sortablejs": "^1.15.0",
37
+ "unplugin-vue-define-options": "0.7.3",
38
+ "vue": "^3.4.29",
39
+ "vue-class-component": "^8.0.0-0",
40
+ "vue-i18n": "^9.2.2",
41
+ "vue-router": "^4.0.3",
42
+ "vuex": "^4.0.0",
43
+ "webpack": "^5.93.0"
44
+ },
45
+ "devDependencies": {
46
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
47
+ "@typescript-eslint/parser": "^5.4.0",
48
+ "@vue/cli-plugin-babel": "~5.0.0",
49
+ "@vue/cli-plugin-eslint": "~5.0.0",
50
+ "@vue/cli-plugin-pwa": "~5.0.0",
51
+ "@vue/cli-plugin-router": "~5.0.0",
52
+ "@vue/cli-plugin-typescript": "~5.0.0",
53
+ "@vue/cli-plugin-vuex": "~5.0.0",
54
+ "@vue/cli-service": "~5.0.0",
55
+ "@vue/eslint-config-typescript": "^9.1.0",
56
+ "eslint": "^7.32.0",
57
+ "eslint-plugin-vue": "^8.0.3",
58
+ "sass": "^1.32.7",
59
+ "sass-loader": "^12.0.0",
60
+ "typescript": "~4.5.5"
61
+ },
62
+ "files": [
63
+ "lib",
64
+ "packages/locales"
65
+ ]
66
+ }
@@ -0,0 +1,21 @@
1
+ export type LocaleType = keyof typeof localeMap;
2
+
3
+ export const localeMap = {
4
+ zh_CN: 'zh_CN',
5
+ en_US: 'en_US',
6
+ } as const;
7
+
8
+ export const localeList = [
9
+ {
10
+ lang: localeMap.en_US,
11
+ label: 'English',
12
+ icon: '🇺🇸',
13
+ title: 'Language',
14
+ },
15
+ {
16
+ lang: localeMap.zh_CN,
17
+ label: '简体中文',
18
+ icon: '🇨🇳',
19
+ title: '语言',
20
+ },
21
+ ] as const;
@@ -0,0 +1,36 @@
1
+ import { set } from 'lodash-es';
2
+ import type { LocaleType } from './config';
3
+
4
+ export const loadLocalePool: LocaleType[] = [];
5
+
6
+ export function setHtmlPageLang(locale: LocaleType) {
7
+ document.querySelector('html')?.setAttribute('lang', locale);
8
+ }
9
+
10
+ export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
11
+ cb(loadLocalePool);
12
+ }
13
+
14
+ export function genMessage(langs: __WebpackModuleApi.RequireContext, prefix = 'lang') {
15
+ const obj: Recordable = {};
16
+
17
+ langs.keys().forEach((key) => {
18
+ const langFileModule = langs(key).default;
19
+ let fileName = key.replace(`./${prefix}/`, '').replace(/^\.\//, '');
20
+ const lastIndex = fileName.lastIndexOf('.');
21
+ fileName = fileName.substring(0, lastIndex);
22
+ const keyList = fileName.split('/');
23
+ const moduleName = keyList.shift();
24
+ const objKey = keyList.join('.');
25
+
26
+ if (moduleName) {
27
+ if (objKey) {
28
+ set(obj, moduleName, obj[moduleName] || {});
29
+ set(obj[moduleName], objKey, langFileModule);
30
+ } else {
31
+ set(obj, moduleName, langFileModule || {});
32
+ }
33
+ }
34
+ });
35
+ return obj;
36
+ }
@@ -0,0 +1,41 @@
1
+ import { type App } from "vue";
2
+ import { createI18n } from "vue-i18n";
3
+ import { localeMap } from "./config";
4
+ import { setHtmlPageLang, setLoadLocalePool } from "./helper";
5
+ import { useLocaleStoreWithOut } from "../store/modules/locale";
6
+ const enUS = require("./lang/en_US");
7
+ const zhCN = require("./lang/zh_CN");
8
+
9
+ function createI18nOptions() {
10
+ const localeStore = useLocaleStoreWithOut();
11
+ const locale = localeStore.getLocale;
12
+ const defaultLocal = locale == "zh_CN" ? zhCN : enUS;
13
+ // await import(`./lang/${locale}.ts`);
14
+ const message = defaultLocal.default?.message ?? {};
15
+
16
+ setHtmlPageLang(locale);
17
+ setLoadLocalePool((loadLocalePool) => {
18
+ loadLocalePool.push(locale);
19
+ });
20
+
21
+ return {
22
+ locale,
23
+ legacy: false,
24
+ fallbackLocale: localeMap.zh_CN, // set fallback locale
25
+ messages: {
26
+ [locale]: message as { [key: string]: string },
27
+ },
28
+ globalInjection: true,
29
+ silentTranslationWarn: true, // true - warning off
30
+ missingWarn: false,
31
+ silentFallbackWarn: true,
32
+ };
33
+ }
34
+
35
+ const options = createI18nOptions();
36
+ export const i18n = createI18n(options);
37
+
38
+ // setup i18n instance with global
39
+ export function setupI18n(app: App) {
40
+ app.use(i18n);
41
+ }
@@ -0,0 +1,23 @@
1
+ export default {
2
+ okText: 'OK',
3
+ closeText: 'Close',
4
+ cancelText: 'Cancel',
5
+ loadingText: 'Loading...',
6
+ saveText: 'Save',
7
+ delText: 'Delete',
8
+ resetText: 'Reset',
9
+ searchText: 'Search',
10
+ queryText: 'Search',
11
+ inputText: 'Please enter',
12
+ chooseText: 'Please choose',
13
+ redo: 'Refresh',
14
+ back: 'Back',
15
+ light: 'Light',
16
+ dark: 'Dark',
17
+ edit:"Edit",
18
+ fullScreen:"fullScreen",
19
+ exitfullScreen:"exitfullScreen",
20
+ LockScreen:"LockScreen",
21
+ ExitSystem:"ExitSystem",
22
+ changeLuaguage:"changeLuaguage"
23
+ };
@@ -0,0 +1,15 @@
1
+ export default {
2
+ commonList: {
3
+ New: "New",
4
+ Edit: "Edit",
5
+ Delete: "Delete",
6
+ warning: "warning",
7
+ Cancel: "Cancel",
8
+ confirm: "confirm",
9
+ Operate: "Operate",
10
+ DelWarning: "he current operation will delete the selected data?",
11
+ save: "save",
12
+ SaveSuccess: "Save Success",
13
+ DelSuccess: "Delete Success"
14
+ },
15
+ };
@@ -0,0 +1,35 @@
1
+ import antdLocale from 'ant-design-vue/es/locale/en_US';
2
+ // import { genMessage } from '../helper';
3
+ import { set } from 'lodash-es';
4
+ function genMessage(langs, prefix = 'lang') {
5
+ const obj = {};
6
+ langs.keys().forEach((key) => {
7
+ const langFileModule = langs(key).default;
8
+ let fileName = key.replace(`./${prefix}/`, '').replace(/^\.\//, '');
9
+ const lastIndex = fileName.lastIndexOf('.');
10
+ fileName = fileName.substring(0, lastIndex);
11
+ const keyList = fileName.split('/');
12
+ const moduleName = keyList.shift();
13
+ const objKey = keyList.join('.');
14
+
15
+ if (moduleName) {
16
+ if (objKey) {
17
+ set(obj, moduleName, obj[moduleName] || {});
18
+ set(obj[moduleName], objKey, langFileModule);
19
+ } else {
20
+ set(obj, moduleName, langFileModule || {});
21
+ }
22
+ }
23
+ });
24
+ return obj;
25
+ }
26
+ const modulesFiles = require.context('./en-US', true, /\.js$/);
27
+
28
+ export default {
29
+ message: {
30
+ ...genMessage(modulesFiles, 'en-US'),
31
+ antdLocale,
32
+ },
33
+ dateLocale: null,
34
+ dateLocaleName: 'en-US',
35
+ };
@@ -0,0 +1,23 @@
1
+ export default {
2
+ okText: '确认',
3
+ closeText: '关闭',
4
+ cancelText: '取消',
5
+ loadingText: '加载中...',
6
+ saveText: '保存',
7
+ delText: '删除',
8
+ resetText: '重置',
9
+ searchText: '搜索',
10
+ queryText: '查询',
11
+ inputText: '请输入',
12
+ chooseText: '请选择',
13
+ redo: '刷新',
14
+ back: '返回',
15
+ light: '亮色主题',
16
+ dark: '黑暗主题',
17
+ edit:"编辑",
18
+ fullScreen:"全屏",
19
+ exitfullScreen:"退出全屏",
20
+ LockScreen:"锁屏",
21
+ ExitSystem:"退出系统",
22
+ changeLuaguage:"切换语言"
23
+ };
@@ -0,0 +1,15 @@
1
+ export default {
2
+ commonList: {
3
+ New: "新建",
4
+ Edit: "编辑",
5
+ Delete: "删除",
6
+ warning: "警告",
7
+ Cancel: "取消",
8
+ confirm: "确定",
9
+ Operate:"操作",
10
+ DelWarning: "当前操作将删除选中数据,是否继续?",
11
+ save:"保存",
12
+ SaveSuccess:"保存成功",
13
+ DelSuccess:"删除成功"
14
+ },
15
+ };
@@ -0,0 +1,33 @@
1
+ import antdLocale from 'ant-design-vue/es/locale/zh_CN';
2
+ import { set } from 'lodash-es';
3
+
4
+ function genMessage(langs, prefix = 'lang') {
5
+ const obj = {};
6
+ langs.keys().forEach((key) => {
7
+ const langFileModule = langs(key).default;
8
+ let fileName = key.replace(`./${prefix}/`, '').replace(/^\.\//, '');
9
+ const lastIndex = fileName.lastIndexOf('.');
10
+ fileName = fileName.substring(0, lastIndex);
11
+ const keyList = fileName.split('/');
12
+ const moduleName = keyList.shift();
13
+ const objKey = keyList.join('.');
14
+ if (moduleName) {
15
+ if (objKey) {
16
+ set(obj, moduleName, obj[moduleName] || {});
17
+ set(obj[moduleName], objKey, langFileModule);
18
+ } else {
19
+ set(obj, moduleName, langFileModule || {});
20
+ }
21
+ }
22
+ });
23
+ return obj;
24
+ }
25
+
26
+ const modulesFiles = require.context('./zh-CN', true, /\.js$/);
27
+
28
+ export default {
29
+ message: {
30
+ ...genMessage(modulesFiles, 'zh-CN'),
31
+ antdLocale,
32
+ },
33
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Multi-language related operations
3
+ */
4
+ import { unref, computed } from 'vue';
5
+ import { loadLocalePool, setHtmlPageLang } from './helper';
6
+ import { i18n } from './';
7
+ import type { LocaleType } from './config';
8
+ import type { Locale } from 'ant-design-vue/es/locale-provider';
9
+
10
+ import { useLocaleStoreWithOut } from '@/store/modules/locale';
11
+
12
+ interface LangModule {
13
+ message: Recordable;
14
+ dateLocale: Recordable;
15
+ dateLocaleName: string;
16
+ }
17
+
18
+ function setI18nLanguage(locale: LocaleType) {
19
+ const localeStore = useLocaleStoreWithOut();
20
+
21
+ if (i18n.mode === 'legacy') {
22
+ i18n.global.locale = locale;
23
+ } else {
24
+ (i18n.global.locale as any).value = locale;
25
+ }
26
+ localeStore.setLocale(locale);
27
+ setHtmlPageLang(locale);
28
+ }
29
+
30
+ export function useLocale() {
31
+ const localeStore = useLocaleStoreWithOut();
32
+ const getLocale = computed(() => localeStore.getLocale);
33
+
34
+ const getAntdLocale = computed<Locale>((): any => {
35
+ return i18n.global.getLocaleMessage<{ antdLocale: Locale }>(unref(getLocale)).antdLocale;
36
+ });
37
+
38
+ // Switching the language will change the locale of useI18n
39
+ // And submit to configuration modification
40
+ async function changeLocale(locale: LocaleType) {
41
+ const globalI18n = i18n.global;
42
+ const currentLocale = unref(globalI18n.locale);
43
+ if (currentLocale === locale) {
44
+ return locale;
45
+ }
46
+
47
+ if (loadLocalePool.includes(locale)) {
48
+ setI18nLanguage(locale);
49
+ return locale;
50
+ }
51
+ const langModule = ((await import(`./lang/${locale}.ts`)) as any).default as LangModule;
52
+ if (!langModule) return;
53
+
54
+ const { message } = langModule;
55
+
56
+ globalI18n.setLocaleMessage(locale, message);
57
+ loadLocalePool.push(locale);
58
+
59
+ setI18nLanguage(locale);
60
+ return locale;
61
+ }
62
+
63
+ return {
64
+ getLocale,
65
+ changeLocale,
66
+ getAntdLocale,
67
+ };
68
+ }