create-young-proj 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -3
- package/dist/index.mjs +9 -9
- package/package.json +1 -1
- package/template-nuxt-admin/Dockerfile +41 -0
- package/template-nuxt-admin/README.md +35 -0
- package/template-nuxt-admin/app.vue +41 -0
- package/template-nuxt-admin/boot.mjs +16 -0
- package/template-nuxt-admin/components/ScreenFull.vue +18 -0
- package/template-nuxt-admin/components/TopSearch.vue +73 -0
- package/template-nuxt-admin/components/TopUser.vue +69 -0
- package/template-nuxt-admin/components/YoungChangePassword.vue +87 -0
- package/template-nuxt-admin/components/YoungCodeInput.vue +60 -0
- package/template-nuxt-admin/components/YoungLink.vue +23 -0
- package/template-nuxt-admin/components/YoungLoading.vue +39 -0
- package/template-nuxt-admin/components/layout/Footer.vue +29 -0
- package/template-nuxt-admin/components/layout/Logo.vue +52 -0
- package/template-nuxt-admin/components/layout/Main.vue +41 -0
- package/template-nuxt-admin/components/layout/NavBar.vue +77 -0
- package/template-nuxt-admin/components/layout/SideBar.vue +90 -0
- package/template-nuxt-admin/components/layout/SubMenu.vue +46 -0
- package/template-nuxt-admin/components/layout/TabsBar.vue +183 -0
- package/template-nuxt-admin/composables/api.ts +104 -0
- package/template-nuxt-admin/composables/apis/delete.ts +37 -0
- package/template-nuxt-admin/composables/apis/get.ts +83 -0
- package/template-nuxt-admin/composables/apis/index.ts +10 -0
- package/template-nuxt-admin/composables/apis/patch.ts +74 -0
- package/template-nuxt-admin/composables/apis/post.ts +85 -0
- package/template-nuxt-admin/composables/config.ts +13 -0
- package/template-nuxt-admin/composables/icon.ts +27 -0
- package/template-nuxt-admin/composables/nav.ts +60 -0
- package/template-nuxt-admin/composables/tags.ts +108 -0
- package/template-nuxt-admin/composables/user.ts +29 -0
- package/template-nuxt-admin/config/.devrc +1 -0
- package/template-nuxt-admin/config/.onlinerc +1 -0
- package/template-nuxt-admin/config/.testrc +1 -0
- package/template-nuxt-admin/env.d.ts +47 -0
- package/template-nuxt-admin/error.vue +53 -0
- package/template-nuxt-admin/layouts/blank.vue +9 -0
- package/template-nuxt-admin/layouts/default.vue +124 -0
- package/template-nuxt-admin/middleware/auth.global.ts +39 -0
- package/template-nuxt-admin/nuxt.config.ts +101 -0
- package/template-nuxt-admin/package.json +44 -0
- package/template-nuxt-admin/pages/home/[id].vue +28 -0
- package/template-nuxt-admin/pages/index.vue +20 -0
- package/template-nuxt-admin/pages/login.vue +179 -0
- package/template-nuxt-admin/pages/system/api.vue +166 -0
- package/template-nuxt-admin/pages/system/hooks/useRole.ts +336 -0
- package/template-nuxt-admin/pages/system/menuList.vue +329 -0
- package/template-nuxt-admin/pages/system/role.vue +117 -0
- package/template-nuxt-admin/pages/system/user.vue +214 -0
- package/template-nuxt-admin/plugins/directive.ts +26 -0
- package/template-nuxt-admin/public/default_avatar.svg +1 -0
- package/template-nuxt-admin/public/favicon.ico +0 -0
- package/template-nuxt-admin/public/image_placeholder.svg +15 -0
- package/template-nuxt-admin/public/tabbar_bg.png +0 -0
- package/template-nuxt-admin/rome.json +26 -0
- package/template-nuxt-admin/server/api/[...all].ts +10 -0
- package/template-nuxt-admin/server/plugins/env.ts +89 -0
- package/template-nuxt-admin/server/routes/get/env.ts +13 -0
- package/template-nuxt-admin/server/tsconfig.json +3 -0
- package/template-nuxt-admin/server/utils/index.ts +35 -0
- package/template-nuxt-admin/styles/element.scss +30 -0
- package/template-nuxt-admin/styles/index.scss +59 -0
- package/template-nuxt-admin/styles/variable.scss +103 -0
- package/template-nuxt-admin/tsconfig.json +7 -0
- package/template-nuxt-admin/typings/global.d.ts +16 -0
- package/template-nuxt-admin/typings/system.d.ts +66 -0
- package/template-nuxt-admin/typings/user.d.ts +19 -0
- package/template-nuxt-admin/uno.config.ts +40 -0
- package/template-nuxt-admin/utils/tool.ts +207 -0
- package/template-nuxt-admin/yarn.lock +6849 -0
- package/template-uni-app/_npmrc +2 -0
- package/template-uni-app/src/layouts/tabbar.vue +6 -6
- package/template-uni-app/src/pages/index.vue +16 -12
- package/template-uni-app/src/pages/my.vue +7 -11
@@ -0,0 +1,207 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-05-28 16:01:24
|
4
|
+
* @LastEditTime: 2023-07-31 14:45:23
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { randomId } from '@bluesyoung/utils';
|
8
|
+
import YoungChangePassword from '@/components/YoungChangePassword.vue';
|
9
|
+
import { createVNode, render } from 'vue';
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 补0函数
|
13
|
+
*/
|
14
|
+
export function addZero(s: number) {
|
15
|
+
return s < 10 ? '0' + s : s;
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* 生成数组的随机索引
|
20
|
+
*/
|
21
|
+
export function getRandomIndex(length: number) {
|
22
|
+
return Math.floor(Math.random() * length);
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* 设备唯一标识
|
27
|
+
*/
|
28
|
+
export function getUUID() {
|
29
|
+
return useLocalStorage('uuid', randomId() + randomId() + randomId() + randomId()).value;
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* html 转 text
|
34
|
+
*/
|
35
|
+
export function html2text(html: string) {
|
36
|
+
if (!html) {
|
37
|
+
return '';
|
38
|
+
}
|
39
|
+
return html.toString().replace(/<[^>]+>/g, '');
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* 响应式的屏幕大小
|
44
|
+
*/
|
45
|
+
export const WindowSize = reactive({
|
46
|
+
'lt-sm': useMediaQuery('(max-width: 639.9px)'),
|
47
|
+
sm: useMediaQuery('(min-width: 640px)'),
|
48
|
+
'lt-md': useMediaQuery('(max-width: 767.9px)'),
|
49
|
+
md: useMediaQuery('(min-width: 768px)'),
|
50
|
+
'lt-lg': useMediaQuery('(max-width: 1023.9px)'),
|
51
|
+
lg: useMediaQuery('(min-width: 1024px)'),
|
52
|
+
'lt-xl': useMediaQuery('(max-width: 1279.9px)'),
|
53
|
+
xl: useMediaQuery('(min-width: 1280px)'),
|
54
|
+
'lt-2xl': useMediaQuery('(max-width: 1535.9px)'),
|
55
|
+
'2xl': useMediaQuery('(min-width: 1536px)'),
|
56
|
+
});
|
57
|
+
|
58
|
+
/**
|
59
|
+
* 分页是否超过一页
|
60
|
+
*/
|
61
|
+
export function moreThanOnePage(query: {
|
62
|
+
total: number;
|
63
|
+
limit: number;
|
64
|
+
}) {
|
65
|
+
return query.total > query.limit;
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* 当前浏览器是否支持下载
|
70
|
+
*/
|
71
|
+
export function isSupportDownload() {
|
72
|
+
const NotAllowed = [/Alipay/gim, /BYTEDANCE/gim, /DINGTALK/gim, /MICROMESSENGER/gim];
|
73
|
+
|
74
|
+
return !NotAllowed.some((reg) => reg.test(navigator.userAgent));
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* 登录校验
|
79
|
+
*/
|
80
|
+
export function checkLogin(force = true) {
|
81
|
+
const { hasLogin } = storeToRefs(useUserStore());
|
82
|
+
|
83
|
+
if (!hasLogin.value) {
|
84
|
+
force &&
|
85
|
+
showDialog({
|
86
|
+
title: '温馨提示',
|
87
|
+
message: '未登录,请登录后再继续!',
|
88
|
+
showCancelButton: true,
|
89
|
+
})
|
90
|
+
.then(() => {
|
91
|
+
navigateTo(
|
92
|
+
`/login?redirect=${encodeURIComponent(location.href.replace(location.origin, ''))}`,
|
93
|
+
);
|
94
|
+
})
|
95
|
+
.catch(() => {
|
96
|
+
navigateTo({
|
97
|
+
path: '/',
|
98
|
+
replace: true,
|
99
|
+
});
|
100
|
+
});
|
101
|
+
return false;
|
102
|
+
} else {
|
103
|
+
return true;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* 页面滚动是否超过一定距离
|
109
|
+
*/
|
110
|
+
export function useScrollOver(distance = 40) {
|
111
|
+
const { y } = useScroll(window);
|
112
|
+
const scrolled = computed(() => y.value > distance);
|
113
|
+
|
114
|
+
return {
|
115
|
+
scrolled,
|
116
|
+
};
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* 生成用户导航栏
|
121
|
+
*/
|
122
|
+
export async function generateNavData() {
|
123
|
+
const { hasLogin } = storeToRefs(useUserStore());
|
124
|
+
if (!hasLogin.value) {
|
125
|
+
showNotify({
|
126
|
+
type: 'danger',
|
127
|
+
message: '登录过期,请重新登录!',
|
128
|
+
});
|
129
|
+
|
130
|
+
return navigateTo('/login');
|
131
|
+
}
|
132
|
+
|
133
|
+
// 清除没有子元素的children
|
134
|
+
const clearChildren = (arr: NavArrItem[]) => {
|
135
|
+
for (const item of arr) {
|
136
|
+
if (
|
137
|
+
item?.children?.length === 0 ||
|
138
|
+
item.children?.filter((n) => +n.visible === 1).length === 0
|
139
|
+
) {
|
140
|
+
delete item.children;
|
141
|
+
} else if (item.children) {
|
142
|
+
clearChildren(item.children);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
return arr;
|
146
|
+
};
|
147
|
+
|
148
|
+
const { nav_arr, flat_nav_arr, auth_routes } = storeToRefs(useNavStore());
|
149
|
+
|
150
|
+
const tree = await apis.get.getUserMenuTree();
|
151
|
+
const menu = Object.values(tree);
|
152
|
+
|
153
|
+
let role_route: string[] = [];
|
154
|
+
const generateRoleRoute = (arr: NavArrItem[], num?: number): string[] => {
|
155
|
+
if (num === 1) {
|
156
|
+
role_route = [];
|
157
|
+
flat_nav_arr.value = [];
|
158
|
+
}
|
159
|
+
for (const item of arr) {
|
160
|
+
if (item.component) {
|
161
|
+
role_route.push(item.component);
|
162
|
+
+item.visible === 1 && flat_nav_arr.value.push(item);
|
163
|
+
}
|
164
|
+
// 子节点递归遍历
|
165
|
+
if (Array.isArray(item.children) && item.children.length > 0) {
|
166
|
+
const part = JSON.parse(JSON.stringify(item.children));
|
167
|
+
// 尾递归优化
|
168
|
+
generateRoleRoute(part);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
return role_route;
|
172
|
+
};
|
173
|
+
|
174
|
+
auth_routes.value = generateRoleRoute(menu, 1);
|
175
|
+
|
176
|
+
/**
|
177
|
+
* 最终导航数组
|
178
|
+
*/
|
179
|
+
nav_arr.value = clearChildren(menu.filter((item) => +item.visible === 1));
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* 权限校验
|
184
|
+
* @param path
|
185
|
+
*/
|
186
|
+
export function hasPermission(path: string) {
|
187
|
+
const { auth_routes } = storeToRefs(useNavStore());
|
188
|
+
return ['/', ...auth_routes.value].includes(path);
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* 修改密码
|
193
|
+
*/
|
194
|
+
export function useChangePassword() {
|
195
|
+
const appendTo = document.createElement('div');
|
196
|
+
|
197
|
+
const vnode = createVNode(YoungChangePassword, {
|
198
|
+
onDestroy: () => {
|
199
|
+
document.body.removeChild(appendTo);
|
200
|
+
},
|
201
|
+
});
|
202
|
+
render(vnode, appendTo);
|
203
|
+
|
204
|
+
document.body.appendChild(appendTo);
|
205
|
+
|
206
|
+
vnode.component!.exposed?.show();
|
207
|
+
}
|