@euflyapp/one-vue3 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ import * as info from './info';
2
+ import * as permission from './permission';
3
+
4
+ export { info, permission };
@@ -0,0 +1,17 @@
1
+ import axios from 'axios';
2
+
3
+ const defaultBaseUrl = 'https://gateway-staging.ftlapp.io';
4
+
5
+ export async function getInfoResource(baseUrl: string, route: any, callBack: (params: any) => void) {
6
+ if (route.query.token) {
7
+ localStorage.setItem('token', route.query.token);
8
+ const res: any = await axios.post(`${baseUrl ? baseUrl : defaultBaseUrl}/api/auth/loginWithToken`, null, {
9
+ headers: {
10
+ Authorization: route.query.token
11
+ }
12
+ });
13
+ if (callBack) {
14
+ callBack(res.data);
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @param {*} asyncRoutes 需要筛选的路由表
3
+ * @param {*} resources auth返回的平铺资源列表
4
+ * @returns 返回需要筛选路由存在于平铺资源列表里的路由
5
+ */
6
+ export function filterAsyncRoutes(asyncRoutes: any, resources: any) {
7
+ const filterRoutes: any[] = [];
8
+ asyncRoutes.forEach((asy) => {
9
+ if (resources.find((res) => res.name === asy.name)) {
10
+ if (asy.children) {
11
+ asy.children = filterAsyncRoutes(asy.children, resources);
12
+ }
13
+ filterRoutes.push(asy);
14
+ }
15
+ });
16
+ return filterRoutes;
17
+ }
package/global.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ declare module '@ftlab/one-vue3/utils' {
2
+ import { Dayjs } from 'dayjs';
3
+
4
+ type dateFormat = (date: string | Date | null | undefined, format?: string, defaultStr?: string) => string;
5
+ type dateTransform = (date: string | Date | null | undefined, defaultStr?: string) => Date | string;
6
+ type tzTransform = (date: string | Date | null | undefined, tz: string) => Date | string;
7
+ type dateValidate = (date: any) => boolean;
8
+
9
+ export const TIME_FORMAT: string;
10
+
11
+ export const isValidDate: dateValidate;
12
+
13
+ export const utc_cn: dateFormat;
14
+ export const utc_fr: dateFormat;
15
+
16
+ export const local_utc_date: dateTransform;
17
+ export const local_tz_date: tzTransform;
18
+ export const local_cn_date: dateTransform;
19
+ export const local_fr_date: dateTransform;
20
+
21
+ export const dayjs: typeof import('dayjs');
22
+
23
+ export { dateFormat, dateTransform, tzTransform, dateValidate };
24
+ }
25
+
26
+ declare module '@ftlab/one-vue3/store' {
27
+ import { Pinia, StoreDefinition } from 'pinia';
28
+
29
+ const store: Pinia;
30
+ export default store;
31
+
32
+ export const useAuthStore: StoreDefinition<
33
+ 'auth',
34
+ {
35
+ userInfo: Record<string, any>;
36
+ username: string;
37
+ owner: string;
38
+ roles: any[];
39
+ menus: any[];
40
+ resources: any[];
41
+ },
42
+ {},
43
+ {
44
+ setInfo(authInfo: Record<string, any>): void;
45
+ setMenu(menus: any[]): void;
46
+ setResources(resources: any[]): void;
47
+ logout(): void;
48
+ }
49
+ >;
50
+
51
+ export const useLangStore: StoreDefinition<
52
+ 'lang',
53
+ {
54
+ language: string;
55
+ },
56
+ {},
57
+ {
58
+ setLanguage(lang: string): void;
59
+ }
60
+ >;
61
+ }
62
+
63
+ declare module '@ftlab/one-vue3' {}
package/i18n/cn.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "ftlOne.text.trackingNumber": "包裹号",
3
+ "ftlOne.changePassword": "修改密码",
4
+ "ftlOne.changePassword.holder1": "您已经长时间未修改密码。为保证您账户的安全,请在修改密码后继续使用系统功能",
5
+ "ftlOne.changePassword.holder2": "请输入以下信息修改密码",
6
+ "ftlOne.changePassword.oldPassword": "原密码",
7
+ "ftlOne.changePassword.oldPassword.placeholder": "请输入原密码",
8
+ "ftlOne.changePassword.newPassword": "新密码",
9
+ "ftlOne.changePassword.newPassword.placeholder": "请输入新密码",
10
+ "ftlOne.changePassword.newPassword.error1": "输入的密码必须包含数字和字母大小写",
11
+ "ftlOne.changePassword.newPassword.error2": "输入的密码的长度须在8-16位",
12
+ "ftlOne.changePassword.confirmPassword": "确认密码",
13
+ "ftlOne.changePassword.confirmPassword.placeholder": "请输入确认密码",
14
+ "ftlOne.changePassword.confirmPassword.error1": "请确保输入的密码与新密码一致",
15
+ "ftlOne.changePassword.cancel": "取消",
16
+ "ftlOne.changePassword.save": "保存",
17
+ "ftlOne.exit": "退出",
18
+ "ftlOne.findPassword.confirm.button": "确定",
19
+ "ftlOne.mutipleChoose.searchText": "批量搜索{number}",
20
+ "ftlOne.mutipleChoose.list.searchText": "请输入{number}, 批量搜索请换行",
21
+ "ftlOne.mutipleChoose.list.exceed": "每次最多搜索{quantity}个{number}, 超出单号已自动删除",
22
+ "ftlOne.mutipleChoose.same": "请勿输入重复的{number}"
23
+ }
package/i18n/en.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "ftlOne.text.trackingNumber": "n°parcel",
3
+ "ftlOne.exit":"Log out",
4
+ "ftlOne.changePassword.save":"Save",
5
+ "ftlOne.changePassword.cancel":"Cancel",
6
+ "ftlOne.changePassword.confirmPassword.error1":"Please ensure that the password you enter matches the new password",
7
+ "ftlOne.changePassword.confirmPassword.placeholder":"Please confirm password",
8
+ "ftlOne.changePassword.confirmPassword":"Confirm password",
9
+ "ftlOne.changePassword.newPassword.error2":"The length of the password you enter must be between 8-16 digits",
10
+ "ftlOne.changePassword.newPassword.error1":"Must contain numbers and uppercase and lowercase letters",
11
+ "ftlOne.changePassword.newPassword.placeholder":"Please enter new password",
12
+ "ftlOne.changePassword.newPassword":"New password",
13
+ "ftlOne.changePassword.oldPassword.placeholder":"Please enter original password",
14
+ "ftlOne.changePassword.oldPassword":"Original password",
15
+ "ftlOne.changePassword.holder2":"Please enter the following information to change your password",
16
+ "ftlOne.changePassword.holder1":"You have not changed your password for a long time. To ensure the security of your account, please change your password before using the system.",
17
+ "ftlOne.changePassword":"Change password",
18
+ "ftlOne.findPassword.confirm.button": "confirm",
19
+ "ftlOne.mutipleChoose.searchText": "Search {number}",
20
+ "ftlOne.mutipleChoose.list.searchText": "Each {nunmber} occupies one ligne",
21
+ "ftlOne.mutipleChoose.list.exceed": "Search up to {quantity} of {number} at a time, the exceeding numbers has been deleted automatically.",
22
+ "ftlOne.mutipleChoose.same": "Please do not search same {number}"
23
+ }
package/i18n/fr.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "ftlOne.text.trackingNumber": "n°colis",
3
+ "ftlOne.exit":"Se déconnecter",
4
+ "ftlOne.changePassword.save":"Enregistrer",
5
+ "ftlOne.changePassword.cancel":"Annuler",
6
+ "ftlOne.changePassword.confirmPassword.error1":"Veillez à saisir deux fois le même mot de passe",
7
+ "ftlOne.changePassword.confirmPassword.placeholder":"Veuillez resaisir pour confirmer",
8
+ "ftlOne.changePassword.confirmPassword":"Confirmer le mdp",
9
+ "ftlOne.changePassword.newPassword.error2":"La longueur saisi doit être de 8 à 16 chiffres",
10
+ "ftlOne.changePassword.newPassword.error1":"Doit contenir des chiffres et des lettres majuscules et minuscules.",
11
+ "ftlOne.changePassword.newPassword.placeholder":"Veuillez entrer le nouveau mot de passe",
12
+ "ftlOne.changePassword.newPassword":"Nouveau mdp",
13
+ "ftlOne.changePassword.oldPassword.placeholder":"Veuillez entrer le mot de passe original",
14
+ "ftlOne.changePassword.oldPassword":"Mdp original",
15
+ "ftlOne.changePassword.holder2":"Veuillez entrer les informations suivantes pour modifier le mot de passe",
16
+ "ftlOne.changePassword.holder1":"Vous n'avez pas modifié votre mot de passe depuis longtemps. Pour garantir la sécurité de votre compte, veuillez modifier votre mot de passe avant d'utiliser le système.",
17
+ "ftlOne.changePassword":"Modifier le mot de passe",
18
+ "ftlOne.findPassword.confirm.button": "Valider",
19
+ "ftlOne.mutipleChoose.searchText": "Rechercher {number}",
20
+ "ftlOne.mutipleChoose.list.searchText": "Chaque {number} occupe une ligne",
21
+ "ftlOne.mutipleChoose.list.exceed": "Rechercher jusqu'à {quantity} {number} à la fois, numéros dépassés a été supprimé automatiquement.",
22
+ "ftlOne.mutipleChoose.same": "Veuillez ne pas rechercher même {number}"
23
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@euflyapp/one-vue3",
3
+ "version": "0.1.0",
4
+ "description": "One for Apps based on Element Plus",
5
+ "main": "dist/ftlOne.js",
6
+ "type": "module",
7
+ "types": "global.d.ts",
8
+ "scripts": {
9
+ "serve": "vite --host",
10
+ "push": "npm publish --access=public",
11
+ "build": "vite build",
12
+ "test": "jest",
13
+ "version": "auto-changelog -p && git add CHANGELOG.md",
14
+ "lint": "eslint --init",
15
+ "prepare": "husky"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git@gitlab.ftlapp.cn:ftl/ftlab/one-vue3.git"
20
+ },
21
+ "author": "",
22
+ "license": "ISC",
23
+ "auto-changelog": {
24
+ "output": "CHANGELOG.md",
25
+ "template": "keepachangelog",
26
+ "unreleased": true,
27
+ "commitLimit": false
28
+ },
29
+ "devDependencies": {
30
+ "@element-plus/icons-vue": "^2.1.0",
31
+ "@icon-park/vue-next": "^1.4.2",
32
+ "@jest/globals": "^29.7.0",
33
+ "@rollup/plugin-replace": "^6.0.2",
34
+ "@types/jest": "^29.5.12",
35
+ "@types/node": "^20.3.2",
36
+ "@typescript-eslint/eslint-plugin": "^5.60.1",
37
+ "@typescript-eslint/parser": "^5.60.1",
38
+ "@vitejs/plugin-vue": "^4.2.3",
39
+ "auto-changelog": "^2.4.0",
40
+ "axios": "^1.4.0",
41
+ "element-plus": "^2.3.7",
42
+ "eslint": "^8.44.0",
43
+ "eslint-plugin-vue": "^9.15.1",
44
+ "husky": "^9.0.11",
45
+ "mitt": "^3.0.0",
46
+ "pinia": "^2.1.4",
47
+ "sass": "^1.56.0",
48
+ "sass-loader": "^8.0.0",
49
+ "screenfull": "^5.0.2",
50
+ "ts-jest": "^29.1.2",
51
+ "typescript": "^4.8.4",
52
+ "unplugin-auto-import": "^0.16.4",
53
+ "unplugin-vue-components": "^0.25.1",
54
+ "vite": "^4.3.9",
55
+ "vite-plugin-dts": "^3.0.0",
56
+ "vue": "^3.3.4",
57
+ "vue-i18n": "^9.2.2",
58
+ "vue-router": "^4.2.2",
59
+ "vuex": "^4.0.2"
60
+ },
61
+ "dependencies": {
62
+ "dayjs": "^1.11.11"
63
+ },
64
+ "jest": {
65
+ "preset": "ts-jest",
66
+ "testEnvironment": "node",
67
+ "transform": {
68
+ "node_modules/variables/.+\\.(j|t)sx?$": "ts-jest"
69
+ },
70
+ "transformIgnorePatterns": [
71
+ "node_modules/(?!variables/.*)"
72
+ ]
73
+ }
74
+ }
package/store/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { createStore } from 'vuex';
2
+ import appModule from './modules/app';
3
+ import authModule from './modules/auth';
4
+ import langModule from './modules/lang';
5
+
6
+ export default createStore({
7
+ modules: {
8
+ app: appModule,
9
+ auth: authModule,
10
+ lang: langModule
11
+ }
12
+ });
@@ -0,0 +1,21 @@
1
+ export default {
2
+ namespaced: true,
3
+ state: () => ({
4
+ language: localStorage.getItem("language") || "cn",
5
+ }),
6
+ getters: {
7
+ language(state) {
8
+ return state.language;
9
+ },
10
+ },
11
+ mutations: {
12
+ SET_LANG(state, lang) {
13
+ state.language = lang;
14
+ },
15
+ },
16
+ actions: {
17
+ setLocalLang({ commit }, data) {
18
+ commit("SET_LANG", data);
19
+ },
20
+ },
21
+ };
@@ -0,0 +1,78 @@
1
+ const userInfo = localStorage.getItem('auth') ? JSON.parse(localStorage.getItem('auth')) : {};
2
+
3
+ function translateOrToName(arr) {
4
+ return arr.map((item) => {
5
+ if (item.children && item.children.length) {
6
+ item.children = translateOrToName(item.children);
7
+ }
8
+ return {
9
+ ...item,
10
+ or: item.name
11
+ };
12
+ });
13
+ }
14
+ export default {
15
+ namespaced: true,
16
+ state: () => ({
17
+ userInfo: userInfo || {},
18
+ username: userInfo.username || '',
19
+ owner: userInfo.owner || '',
20
+ roles: userInfo.roles || [],
21
+ menus: [],
22
+ resources: []
23
+ }),
24
+ getters: {
25
+ auth: (state) => state.userInfo
26
+ },
27
+ mutations: {
28
+ SET_NAME(state, name) {
29
+ state.username = name;
30
+ },
31
+ SET_OWNER(state, owner) {
32
+ state.owner = owner;
33
+ },
34
+ SET_ROLES(state, roles) {
35
+ state.roles = roles;
36
+ },
37
+ SET_MENUS(state, menus) {
38
+ if (!menus.length) {
39
+ // 在权限返回为空的时候给menus加一条空数据,防止下次路由进入再次空校验
40
+ state.menus.push({});
41
+ } else {
42
+ state.menus = translateOrToName(menus);
43
+ }
44
+ },
45
+ CLEAR_MENUS(state) {
46
+ state.menus = [];
47
+ },
48
+ SET_RESOURCES(state, resources) {
49
+ state.resources = translateOrToName(resources);
50
+ }
51
+ },
52
+ actions: {
53
+ setInfo({ commit }, authInfo) {
54
+ if (typeof authInfo === 'object') {
55
+ commit('SET_NAME', authInfo.username);
56
+ commit('SET_OWNER', authInfo.owner);
57
+ commit('SET_ROLES', authInfo.roles);
58
+ localStorage.setItem('auth', JSON.stringify(authInfo));
59
+ localStorage.setItem('token', authInfo.token);
60
+ }
61
+ },
62
+ setMenu({ commit }, menu) {
63
+ commit('SET_MENUS', menu);
64
+ },
65
+ setResources({ commit }, resources) {
66
+ commit('SET_RESOURCES', resources);
67
+ },
68
+ logout({ commit }) {
69
+ commit('SET_NAME', '');
70
+ commit('SET_OWNER', '');
71
+ commit('SET_ROLES', []);
72
+ commit('CLEAR_MENUS', []);
73
+ commit('SET_RESOURCES', []);
74
+ localStorage.removeItem('auth');
75
+ localStorage.removeItem('token');
76
+ }
77
+ }
78
+ };
@@ -0,0 +1,17 @@
1
+ export default {
2
+ namespaced: true,
3
+ state: () => ({
4
+ language: localStorage.getItem("language") || "cn",
5
+ }),
6
+ mutations: {
7
+ SET_LANG(state, lang) {
8
+ state.language = lang;
9
+ localStorage.setItem("language", lang);
10
+ },
11
+ },
12
+ actions: {
13
+ setLanguage({ commit }, data) {
14
+ commit("SET_LANG", data);
15
+ },
16
+ },
17
+ };
package/store2/auth.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { defineStore } from 'pinia';
2
+ import storage from '../utils/storage';
3
+
4
+ const userInfo = storage.getAuth();
5
+
6
+ // 同步路由的or翻译为路由name
7
+ function translateOrToName(arr) {
8
+ return arr.map((item) => {
9
+ if (item.children && item.children.length) {
10
+ item.children = translateOrToName(item.children);
11
+ }
12
+ return {
13
+ ...item,
14
+ or: item.name
15
+ };
16
+ });
17
+ }
18
+
19
+ export default defineStore('auth', {
20
+ state: () => {
21
+ return {
22
+ userInfo: userInfo || {},
23
+ username: userInfo.username || '',
24
+ owner: userInfo.owner || '',
25
+ roles: userInfo.roles || [],
26
+ menus: [],
27
+ resources: []
28
+ };
29
+ },
30
+ actions: {
31
+ setInfo(authInfo) {
32
+ if (typeof authInfo === 'object') {
33
+ this.userInfo = authInfo;
34
+ this.username = authInfo.username;
35
+ this.owner = authInfo.owner;
36
+ this.roles = authInfo.roles;
37
+ storage.setAuth(authInfo);
38
+ storage.setToken(authInfo.token);
39
+ }
40
+ },
41
+ setMenu(menus) {
42
+ if (!menus.length) {
43
+ // 在权限返回为空的时候给menus加一条空数据,防止下次路由进入再次空校验
44
+ this.menus.push({});
45
+ } else {
46
+ this.menus = translateOrToName(menus);
47
+ }
48
+ },
49
+ setResources(resources) {
50
+ this.resources = translateOrToName(resources);
51
+ },
52
+ rebuild(){
53
+ console.log('rebuild');
54
+ },
55
+ logout() {
56
+ this.userInfo = {};
57
+ this.username = '';
58
+ this.owner = [];
59
+ this.roles = [];
60
+ this.menus = [];
61
+ this.resources = [];
62
+ storage.remove('auth');
63
+ storage.remove('token');
64
+ }
65
+ }
66
+ });
@@ -0,0 +1,7 @@
1
+ import { createPinia } from 'pinia';
2
+
3
+ const store = createPinia();
4
+
5
+ export default store;
6
+ export { default as useAuthStore } from './auth';
7
+ export { default as useLangStore } from './lang';
package/store2/lang.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineStore } from 'pinia';
2
+ import storage from '../utils/storage';
3
+
4
+ export default defineStore('lang', {
5
+ state: () => {
6
+ return {
7
+ language: storage.get('language') || 'cn'
8
+ };
9
+ },
10
+ actions: {
11
+ setLanguage(lang) {
12
+ this.language = lang || 'cn';
13
+ storage.set('language', lang);
14
+ }
15
+ }
16
+ });