create-young-proj 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +6 -1
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
- package/template-uni-app/.vscode/css.code-snippets +398 -0
- package/template-uni-app/.vscode/extensions.json +9 -0
- package/template-uni-app/.vscode/js.code-snippets +1669 -0
- package/template-uni-app/.vscode/settings.json +7 -0
- package/template-uni-app/.vscode/vue-html.code-snippets +668 -0
- package/template-uni-app/README.md +46 -0
- package/template-uni-app/_env +1 -0
- package/template-uni-app/_env.development +11 -0
- package/template-uni-app/_env.production +11 -0
- package/template-uni-app/_env.test +14 -0
- package/template-uni-app/_gitignore +3 -0
- package/template-uni-app/auto-imports.d.ts +404 -0
- package/template-uni-app/components.d.ts +20 -0
- package/template-uni-app/custom-plugins/index.ts +8 -0
- package/template-uni-app/custom-plugins/multiconf.ts +77 -0
- package/template-uni-app/custom-plugins/polyfill.ts +32 -0
- package/template-uni-app/index.html +23 -0
- package/template-uni-app/package.json +84 -0
- package/template-uni-app/pnpm-lock.yaml +7530 -0
- package/template-uni-app/rome.json +26 -0
- package/template-uni-app/src/App.vue +76 -0
- package/template-uni-app/src/apis/index.ts +36 -0
- package/template-uni-app/src/apis/lib/index.ts +236 -0
- package/template-uni-app/src/apis/requests/get.ts +52 -0
- package/template-uni-app/src/apis/requests/index.ts +8 -0
- package/template-uni-app/src/apis/requests/post.ts +23 -0
- package/template-uni-app/src/components/young-loading/young-loading.vue +38 -0
- package/template-uni-app/src/components/young-navbar/young-navbar.vue +253 -0
- package/template-uni-app/src/components/young-tabbar/young-tabbar.vue +137 -0
- package/template-uni-app/src/components/young-tabbar-layout/young-tabbar-layout.vue +27 -0
- package/template-uni-app/src/config/enum.ts +46 -0
- package/template-uni-app/src/config/index.ts +8 -0
- package/template-uni-app/src/config/map.ts +15 -0
- package/template-uni-app/src/env.d.ts +35 -0
- package/template-uni-app/src/main.ts +20 -0
- package/template-uni-app/src/manifest.json +83 -0
- package/template-uni-app/src/pages/index.vue +52 -0
- package/template-uni-app/src/pages/my.vue +29 -0
- package/template-uni-app/src/pages.json +63 -0
- package/template-uni-app/src/store/index.ts +16 -0
- package/template-uni-app/src/store/local/index.ts +40 -0
- package/template-uni-app/src/store/system.ts +12 -0
- package/template-uni-app/src/uni.scss +76 -0
- package/template-uni-app/src/utils/auth.ts +125 -0
- package/template-uni-app/src/utils/index.ts +11 -0
- package/template-uni-app/src/utils/map.ts +97 -0
- package/template-uni-app/src/utils/modal.ts +98 -0
- package/template-uni-app/src/utils/route.ts +149 -0
- package/template-uni-app/src/utils/system.ts +66 -0
- package/template-uni-app/tsconfig.json +13 -0
- package/template-uni-app/unocss.config.ts +30 -0
- package/template-uni-app/vite.config.ts +68 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 15:24:39
|
4
|
+
* @LastEditTime: 2023-07-19 16:51:49
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { Pages } from '@/config';
|
8
|
+
|
9
|
+
interface IRoute {
|
10
|
+
/**
|
11
|
+
* 路由类型
|
12
|
+
*/
|
13
|
+
type: ENUM_ROUTE_TYPE;
|
14
|
+
/**
|
15
|
+
* 路由路径
|
16
|
+
*/
|
17
|
+
url: string;
|
18
|
+
/**
|
19
|
+
* 路由参数
|
20
|
+
*/
|
21
|
+
params?: Record<string, any>;
|
22
|
+
/**
|
23
|
+
* 回退的层数 uni.navigateBack
|
24
|
+
* @default 1
|
25
|
+
*/
|
26
|
+
delta?: number;
|
27
|
+
/**
|
28
|
+
* 是否编码
|
29
|
+
*/
|
30
|
+
encode?: boolean;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* 路由类型
|
35
|
+
*/
|
36
|
+
enum ENUM_ROUTE_TYPE {
|
37
|
+
TO = 'navigateTo',
|
38
|
+
REDIRECT = 'redirectTo',
|
39
|
+
TAB = 'switchTab',
|
40
|
+
RELAUNCH = 'reLaunch',
|
41
|
+
BACK = 'navigateBack',
|
42
|
+
}
|
43
|
+
|
44
|
+
const params2Url = (params: Record<string, any>, encode = false) => {
|
45
|
+
const arr = [];
|
46
|
+
for (const key in params) {
|
47
|
+
arr.push(`${key}=${encode ? encodeURIComponent(params[key]) : params[key]}`);
|
48
|
+
}
|
49
|
+
return arr.join('&');
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* 路由跳转
|
54
|
+
*/
|
55
|
+
export function route({ type, url, params, delta = 1, encode }: IRoute) {
|
56
|
+
if (type !== ENUM_ROUTE_TYPE.BACK && params) {
|
57
|
+
url = `${url}?${params2Url(params, encode)}`;
|
58
|
+
}
|
59
|
+
|
60
|
+
switch (type) {
|
61
|
+
case ENUM_ROUTE_TYPE.TO:
|
62
|
+
uni.navigateTo({
|
63
|
+
url,
|
64
|
+
});
|
65
|
+
break;
|
66
|
+
|
67
|
+
case ENUM_ROUTE_TYPE.REDIRECT:
|
68
|
+
uni.redirectTo({
|
69
|
+
url,
|
70
|
+
});
|
71
|
+
break;
|
72
|
+
|
73
|
+
case ENUM_ROUTE_TYPE.TAB:
|
74
|
+
uni.switchTab({
|
75
|
+
url,
|
76
|
+
});
|
77
|
+
break;
|
78
|
+
|
79
|
+
case ENUM_ROUTE_TYPE.RELAUNCH:
|
80
|
+
uni.reLaunch({
|
81
|
+
url,
|
82
|
+
});
|
83
|
+
break;
|
84
|
+
case ENUM_ROUTE_TYPE.BACK:
|
85
|
+
uni.navigateBack({
|
86
|
+
delta,
|
87
|
+
});
|
88
|
+
break;
|
89
|
+
|
90
|
+
default:
|
91
|
+
break;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
export function to(url: Pages, params?: Record<string, any>, encode?: boolean) {
|
96
|
+
if (TabbarArr.includes(url)) {
|
97
|
+
tabbar(url, params, encode);
|
98
|
+
} else {
|
99
|
+
route({
|
100
|
+
type: ENUM_ROUTE_TYPE.TO,
|
101
|
+
url,
|
102
|
+
params,
|
103
|
+
encode,
|
104
|
+
});
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
export function redirect(url: Pages, params?: Record<string, any>, encode?: boolean) {
|
109
|
+
if (TabbarArr.includes(url)) {
|
110
|
+
tabbar(url, params, encode);
|
111
|
+
} else {
|
112
|
+
route({
|
113
|
+
type: ENUM_ROUTE_TYPE.REDIRECT,
|
114
|
+
url,
|
115
|
+
params,
|
116
|
+
encode,
|
117
|
+
});
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
export function tabbar(url: Pages, params?: Record<string, any>, encode?: boolean) {
|
122
|
+
if (TabbarArr.includes(url)) {
|
123
|
+
route({
|
124
|
+
type: ENUM_ROUTE_TYPE.TAB,
|
125
|
+
url,
|
126
|
+
params,
|
127
|
+
encode,
|
128
|
+
});
|
129
|
+
} else {
|
130
|
+
to(url, params, encode);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
export function relaunch(url: Pages, params?: Record<string, any>, encode?: boolean) {
|
135
|
+
route({
|
136
|
+
type: ENUM_ROUTE_TYPE.RELAUNCH,
|
137
|
+
url,
|
138
|
+
params,
|
139
|
+
encode,
|
140
|
+
});
|
141
|
+
}
|
142
|
+
|
143
|
+
export function back(delta?: number) {
|
144
|
+
route({
|
145
|
+
type: ENUM_ROUTE_TYPE.BACK,
|
146
|
+
delta,
|
147
|
+
url: '',
|
148
|
+
});
|
149
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 14:24:35
|
4
|
+
* @LastEditTime: 2023-07-19 16:51:57
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { SubscribeMessage } from '@/config';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* 订阅指定的消息
|
11
|
+
*/
|
12
|
+
export const subscribeMessage = (tmplIds: SubscribeMessage[]) =>
|
13
|
+
new Promise((resolve) => {
|
14
|
+
uni.requestSubscribeMessage({
|
15
|
+
tmplIds,
|
16
|
+
success: (res) => {
|
17
|
+
console.log('消息订阅成功:', res);
|
18
|
+
},
|
19
|
+
fail: (err) => {
|
20
|
+
console.log('消息订阅失败:', err);
|
21
|
+
},
|
22
|
+
complete: () => resolve(true),
|
23
|
+
});
|
24
|
+
});
|
25
|
+
|
26
|
+
/**
|
27
|
+
* 获取系统信息 设置导航栏高度
|
28
|
+
*/
|
29
|
+
export const getSystemInfo = () => {
|
30
|
+
const { systemInfo } = storeToRefs(useSystemInfo());
|
31
|
+
return new Promise<UniApp.GetSystemInfoResult>((_resolve) => {
|
32
|
+
uni.getSystemInfo({
|
33
|
+
success: (e) => {
|
34
|
+
console.log(e, 'getSystemInfo');
|
35
|
+
systemInfo.value = e;
|
36
|
+
// 获取手机状态栏高度
|
37
|
+
let statusBar = e.statusBarHeight || 0;
|
38
|
+
let customBar;
|
39
|
+
|
40
|
+
// #ifndef MP
|
41
|
+
customBar = statusBar + (e.platform == 'android' ? 50 : 45);
|
42
|
+
// #endif
|
43
|
+
|
44
|
+
// #ifdef MP-WEIXIN
|
45
|
+
// 获取胶囊按钮的布局位置信息
|
46
|
+
let menu = uni.getMenuButtonBoundingClientRect();
|
47
|
+
// 导航栏高度 = 胶囊下距离 + 胶囊上距离 - 状态栏高度
|
48
|
+
customBar = menu.bottom + menu.top - statusBar;
|
49
|
+
// #endif
|
50
|
+
|
51
|
+
// #ifdef MP-ALIPAY
|
52
|
+
customBar = statusBar + (e.titleBarHeight || 0);
|
53
|
+
// #endif
|
54
|
+
|
55
|
+
const safeBottom = e.screenHeight - (e.safeArea ? (e.safeArea.height + e.safeArea.top) : 0);
|
56
|
+
|
57
|
+
setNavbarHeihgt({
|
58
|
+
statusBarH: statusBar,
|
59
|
+
customBarH: customBar,
|
60
|
+
safeBottom
|
61
|
+
});
|
62
|
+
_resolve(e);
|
63
|
+
},
|
64
|
+
});
|
65
|
+
});
|
66
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"extends": "@vue/tsconfig/tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"sourceMap": true,
|
5
|
+
"baseUrl": ".",
|
6
|
+
"paths": {
|
7
|
+
"@/*": ["./src/*"]
|
8
|
+
},
|
9
|
+
"lib": ["esnext", "dom"],
|
10
|
+
"types": ["@dcloudio/types"]
|
11
|
+
},
|
12
|
+
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "custom-plugins/*.ts", "auto-imports.d.ts", "components.d.ts"]
|
13
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-02-13 14:50:47
|
4
|
+
* @LastEditTime: 2023-02-14 12:09:16
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import presetWeapp from 'unocss-preset-weapp';
|
8
|
+
import { transformerAttributify, transformerClass } from 'unocss-preset-weapp/transformer';
|
9
|
+
import { defineConfig, transformerDirectives } from 'unocss';
|
10
|
+
|
11
|
+
export default defineConfig({
|
12
|
+
presets: [
|
13
|
+
// https://github.com/MellowCo/unocss-preset-weapp
|
14
|
+
presetWeapp(),
|
15
|
+
],
|
16
|
+
shortcuts: [
|
17
|
+
{
|
18
|
+
'flex-center': 'flex justify-center items-center',
|
19
|
+
},
|
20
|
+
],
|
21
|
+
transformers: [
|
22
|
+
transformerDirectives(),
|
23
|
+
|
24
|
+
// https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerAttributify
|
25
|
+
transformerAttributify(),
|
26
|
+
|
27
|
+
// https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerClass
|
28
|
+
transformerClass(),
|
29
|
+
],
|
30
|
+
});
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 11:03:01
|
4
|
+
* @LastEditTime: 2023-07-19 17:50:15
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { resolve } from 'node:path';
|
8
|
+
import { defineConfig } from 'vite';
|
9
|
+
import type { ConfigEnv, UserConfigExport } from 'vite';
|
10
|
+
import uni from '@dcloudio/vite-plugin-uni';
|
11
|
+
import Unocss from 'unocss/vite';
|
12
|
+
import AutoImport from 'unplugin-auto-import/vite';
|
13
|
+
import AutoComponents from 'unplugin-vue-components/vite';
|
14
|
+
import { polyfillFormData, multiConf } from './custom-plugins';
|
15
|
+
|
16
|
+
/**
|
17
|
+
* 大驼峰转中划线
|
18
|
+
*/
|
19
|
+
function camel2kebab(str: string) {
|
20
|
+
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
21
|
+
};
|
22
|
+
|
23
|
+
// https://vitejs.dev/config/
|
24
|
+
export default ({ command, mode }: ConfigEnv) => {
|
25
|
+
console.log("🚀 ~ file: vite.config.ts:18 ~ mode:", mode)
|
26
|
+
console.log("🚀 ~ file: vite.config.ts:18 ~ command:", command)
|
27
|
+
return defineConfig({
|
28
|
+
resolve: {
|
29
|
+
alias: {
|
30
|
+
'@/': `${resolve(__dirname, 'src')}/`,
|
31
|
+
},
|
32
|
+
},
|
33
|
+
plugins: [
|
34
|
+
polyfillFormData(),
|
35
|
+
// 仅用于增加语法提示,实际导入依靠 uni-app 的 easycom
|
36
|
+
AutoComponents({
|
37
|
+
dts: true,
|
38
|
+
globs: ['src/components/**/*.vue'],
|
39
|
+
resolvers: [
|
40
|
+
(componentName) => {
|
41
|
+
if (componentName.startsWith('Uni')) {
|
42
|
+
const pkgName = camel2kebab(componentName);
|
43
|
+
return { name: 'default', from: `@dcloudio/uni-ui/lib/${pkgName}/${pkgName}.vue` };
|
44
|
+
}
|
45
|
+
}
|
46
|
+
]
|
47
|
+
}),
|
48
|
+
uni(),
|
49
|
+
// https://github.com/antfu/unocss
|
50
|
+
Unocss(),
|
51
|
+
|
52
|
+
// https://github.com/antfu/unplugin-auto-import
|
53
|
+
AutoImport({
|
54
|
+
imports: ['vue', 'uni-app', 'pinia'],
|
55
|
+
dts: true,
|
56
|
+
vueTemplate: true,
|
57
|
+
dirs: [
|
58
|
+
resolve(__dirname, 'src/apis/**'),
|
59
|
+
resolve(__dirname, 'src/config/**'),
|
60
|
+
resolve(__dirname, 'src/store/**'),
|
61
|
+
resolve(__dirname, 'src/utils/**'),
|
62
|
+
]
|
63
|
+
}),
|
64
|
+
|
65
|
+
multiConf(mode)
|
66
|
+
],
|
67
|
+
});
|
68
|
+
}
|