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,26 @@
|
|
1
|
+
{
|
2
|
+
"formatter": {
|
3
|
+
"ignore": [
|
4
|
+
"src/utils/**/*.js",
|
5
|
+
"src/utils/**/*.map",
|
6
|
+
"src/components/ui/**/*",
|
7
|
+
"*.d.ts",
|
8
|
+
"index.html",
|
9
|
+
"yarn.lock",
|
10
|
+
"*.json",
|
11
|
+
"README.md",
|
12
|
+
"dist/**/*"
|
13
|
+
],
|
14
|
+
"indentStyle": "space",
|
15
|
+
"indentSize": 2,
|
16
|
+
"lineWidth": 100
|
17
|
+
},
|
18
|
+
"javascript": {
|
19
|
+
"formatter": {
|
20
|
+
"quoteStyle": "single"
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"linter": {
|
24
|
+
"enabled": false
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
<!--
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-02-13 14:58:26
|
4
|
+
* @LastEditTime: 2023-07-19 17:23:20
|
5
|
+
* @Description:
|
6
|
+
-->
|
7
|
+
<script setup lang="ts">
|
8
|
+
onLaunch(async () => {
|
9
|
+
console.log('App Launch');
|
10
|
+
console.log('环境变量:', import.meta.env);
|
11
|
+
if (!getUuid()) {
|
12
|
+
setUuid();
|
13
|
+
}
|
14
|
+
await getSystemInfo();
|
15
|
+
});
|
16
|
+
|
17
|
+
onShow(async () => {
|
18
|
+
/**
|
19
|
+
* 自动更新
|
20
|
+
*/
|
21
|
+
const updateManager = uni.getUpdateManager();
|
22
|
+
|
23
|
+
updateManager.onCheckForUpdate(function (res) {
|
24
|
+
// 请求完新版本信息的回调
|
25
|
+
console.log(res.hasUpdate, 'onCheckForUpdate hasUpdate')
|
26
|
+
});
|
27
|
+
|
28
|
+
updateManager.onUpdateReady(function () {
|
29
|
+
showModal({
|
30
|
+
title: '更新提示',
|
31
|
+
content: '新版本已经准备好,是否重启应用?',
|
32
|
+
success(res) {
|
33
|
+
if (res.confirm) {
|
34
|
+
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
35
|
+
updateManager.applyUpdate()
|
36
|
+
}
|
37
|
+
}
|
38
|
+
});
|
39
|
+
});
|
40
|
+
updateManager.onUpdateFailed(function () {
|
41
|
+
// 新版本下载失败
|
42
|
+
showModal({ title: '更新提示', content: '新版本下载失败', showCancel: false });
|
43
|
+
});
|
44
|
+
console.log('App Show');
|
45
|
+
});
|
46
|
+
|
47
|
+
onHide(() => {
|
48
|
+
console.log('App Hide');
|
49
|
+
});
|
50
|
+
|
51
|
+
</script>
|
52
|
+
|
53
|
+
<style lang="scss">
|
54
|
+
@import '@dcloudio/uni-ui/lib/uni-scss/index.scss';
|
55
|
+
|
56
|
+
page {
|
57
|
+
background-color: #f6f7fb;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
.font-pf {
|
62
|
+
font-family: PingFangSC-Semibold, PingFang SC;
|
63
|
+
}
|
64
|
+
|
65
|
+
.cancel_scrollbar ::-webkit-scrollbar {
|
66
|
+
display: none;
|
67
|
+
width: 0 !important;
|
68
|
+
height: 0 !important;
|
69
|
+
-webkit-appearance: none;
|
70
|
+
background: transparent;
|
71
|
+
}
|
72
|
+
|
73
|
+
.button_bg {
|
74
|
+
background: linear-gradient(180deg, #3E3A39 0%, #0D0D0D 100%);
|
75
|
+
}
|
76
|
+
</style>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 15:35:24
|
4
|
+
* @LastEditTime: 2023-07-19 16:47:49
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import { useHttp } from './lib';
|
8
|
+
import { useGet, usePost } from './requests';
|
9
|
+
|
10
|
+
const http = useHttp({
|
11
|
+
baseURL: import.meta.env.VITE_API_BASE_URL,
|
12
|
+
loading: {
|
13
|
+
start: showLoading,
|
14
|
+
end: hideLoading,
|
15
|
+
},
|
16
|
+
headers: {
|
17
|
+
getCommonHeaders: () => ({
|
18
|
+
Accept: 'application/vnd.github.v3+json',
|
19
|
+
}),
|
20
|
+
getAuthHeaders: () => {
|
21
|
+
const token = 'todo: change to the real token that you used';
|
22
|
+
return {
|
23
|
+
Authorization: `Bearer ${token}`,
|
24
|
+
};
|
25
|
+
},
|
26
|
+
},
|
27
|
+
fail: (err) => {
|
28
|
+
// todo: 错误逻辑处理
|
29
|
+
showErrorModal(err.toString());
|
30
|
+
},
|
31
|
+
});
|
32
|
+
|
33
|
+
export const apis = {
|
34
|
+
get: useGet(http),
|
35
|
+
post: usePost(http),
|
36
|
+
};
|
@@ -0,0 +1,236 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 16:36:39
|
4
|
+
* @LastEditTime: 2023-07-18 16:51:41
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
/// <reference types="@uni-helper/axios-adapter/client" />
|
8
|
+
import type { AxiosInstance, AxiosRequestConfig, Method, AxiosAdapter } from 'axios';
|
9
|
+
import axios from 'axios';
|
10
|
+
import { defu } from 'defu';
|
11
|
+
import { createUniAppAxiosAdapter } from '@uni-helper/axios-adapter';
|
12
|
+
|
13
|
+
type Simplify<T> = {
|
14
|
+
[P in keyof T]: T[P];
|
15
|
+
};
|
16
|
+
|
17
|
+
type SetRequired<T, K extends keyof T> = Simplify<
|
18
|
+
// 将要设置为可选类型的结构取出并设置为必选
|
19
|
+
Required<Pick<T, K>> &
|
20
|
+
// 取并集
|
21
|
+
// 排除需要设置为可选属性的结构,其余的保持不变
|
22
|
+
Pick<T, Exclude<keyof T, K>>
|
23
|
+
>;
|
24
|
+
|
25
|
+
export type AllMethod = Lowercase<Method>;
|
26
|
+
export type Fn<T extends any = any, R extends any = any> = (...args: T[]) => Promise<R>;
|
27
|
+
export type Cbks = {
|
28
|
+
[k in AllMethod]?: Record<string, Fn>;
|
29
|
+
};
|
30
|
+
|
31
|
+
type Handlers<R extends Cbks> = {
|
32
|
+
[P in keyof R]?: R[P];
|
33
|
+
};
|
34
|
+
|
35
|
+
type Headers = Record<string, string>;
|
36
|
+
|
37
|
+
type Req = <X extends any = any>(config: AxiosRequestConfig<unknown>) => Promise<X>;
|
38
|
+
|
39
|
+
type Prototype = {
|
40
|
+
__instance__: AxiosInstance;
|
41
|
+
__mixin__<T extends Cbks>(
|
42
|
+
extentions: Handlers<T>,
|
43
|
+
): SetRequired<Handlers<T>, keyof T> & ThisType<Handlers<T>>;
|
44
|
+
|
45
|
+
freeReq: Req;
|
46
|
+
authReq: Req;
|
47
|
+
};
|
48
|
+
|
49
|
+
export enum UsefulContentTypes {
|
50
|
+
JSON = `application/json; charset=UTF-8`,
|
51
|
+
URLEncoded = `application/x-www-form-urlencoded; charset=UTF-8`,
|
52
|
+
FormData = `multipart/form-data; charset=UTF-8`,
|
53
|
+
}
|
54
|
+
|
55
|
+
export type DefaultMsg = {
|
56
|
+
code: number;
|
57
|
+
msg: string;
|
58
|
+
data: any;
|
59
|
+
};
|
60
|
+
|
61
|
+
export interface DefaultHttpConfig<Msg extends any = DefaultMsg> {
|
62
|
+
/**
|
63
|
+
* 基础地址
|
64
|
+
* @default /api
|
65
|
+
*/
|
66
|
+
baseURL: string;
|
67
|
+
/**
|
68
|
+
* 动态获取基础地址
|
69
|
+
*/
|
70
|
+
lazyBaseURL?: () => string;
|
71
|
+
/**
|
72
|
+
* 默认方法
|
73
|
+
* @default post
|
74
|
+
*/
|
75
|
+
method: AllMethod;
|
76
|
+
/**
|
77
|
+
* 超时时间
|
78
|
+
* @default 5e3 5s
|
79
|
+
*/
|
80
|
+
timeout: number;
|
81
|
+
/**
|
82
|
+
* 加载函数
|
83
|
+
*/
|
84
|
+
loading: {
|
85
|
+
start: () => void;
|
86
|
+
end: () => void;
|
87
|
+
};
|
88
|
+
/**
|
89
|
+
* 错误处理函数,进行错误处理或继续抛出错误
|
90
|
+
* 接受各种抛出的错误
|
91
|
+
* @default console.error
|
92
|
+
*/
|
93
|
+
fail: (err: string | number | Error | Msg) => void;
|
94
|
+
/**
|
95
|
+
* 结果校验 + 数据解析,判断此次请求是否正常,正常则返回解包数据,否则抛出异常
|
96
|
+
* 不传则默认使用标准 http 状态码作为判断结果,并原样返回
|
97
|
+
* @default () => any | never
|
98
|
+
*/
|
99
|
+
checkFn: (res: Msg) => any | never;
|
100
|
+
/**
|
101
|
+
* 请求头
|
102
|
+
*/
|
103
|
+
headers: {
|
104
|
+
/**
|
105
|
+
* 生成公共请求头
|
106
|
+
* @default () => {}
|
107
|
+
*/
|
108
|
+
getCommonHeaders?: () => Headers;
|
109
|
+
/**
|
110
|
+
* 生成鉴权请求头
|
111
|
+
* @default () => {}
|
112
|
+
*/
|
113
|
+
getAuthHeaders?: () => Headers;
|
114
|
+
};
|
115
|
+
/**
|
116
|
+
* 自定义适配器
|
117
|
+
* 微信小程序等其他非标准环境时传入
|
118
|
+
*/
|
119
|
+
adapter?: AxiosAdapter;
|
120
|
+
}
|
121
|
+
|
122
|
+
const defaultConfig: DefaultHttpConfig = {
|
123
|
+
baseURL: '/api',
|
124
|
+
method: 'post',
|
125
|
+
timeout: 5e3,
|
126
|
+
loading: {
|
127
|
+
start: console.log.bind(null, '🚀 ~ http loading start'),
|
128
|
+
end: console.log.bind(null, '🚀 ~ http loading end'),
|
129
|
+
},
|
130
|
+
fail: console.error.bind(null, '🚀 ~ http loading error'),
|
131
|
+
checkFn: (res) => res,
|
132
|
+
headers: {
|
133
|
+
getCommonHeaders: () => ({}),
|
134
|
+
getAuthHeaders: () => ({}),
|
135
|
+
},
|
136
|
+
};
|
137
|
+
|
138
|
+
declare module 'axios' {
|
139
|
+
export interface AxiosRequestConfig {
|
140
|
+
/**
|
141
|
+
* 禁用 loading 动画
|
142
|
+
* @default false
|
143
|
+
*/
|
144
|
+
notLoading?: boolean;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
export const useHttp = <Msg extends Record<string, any> = DefaultMsg, Fns extends Cbks = Cbks>(
|
149
|
+
config: Partial<DefaultHttpConfig<Msg>> = {},
|
150
|
+
) => {
|
151
|
+
const finalConfig = defu(config, defaultConfig);
|
152
|
+
|
153
|
+
const { baseURL, lazyBaseURL, method, timeout, headers, checkFn, loading, fail } = finalConfig;
|
154
|
+
|
155
|
+
const net = axios.create({
|
156
|
+
method,
|
157
|
+
timeout,
|
158
|
+
headers: headers.getCommonHeaders!(),
|
159
|
+
adapter: createUniAppAxiosAdapter(),
|
160
|
+
});
|
161
|
+
|
162
|
+
net.interceptors.request.use(
|
163
|
+
(req) => {
|
164
|
+
!req.notLoading && loading.start();
|
165
|
+
if (!req.baseURL) {
|
166
|
+
req.baseURL = lazyBaseURL?.() ?? baseURL;
|
167
|
+
}
|
168
|
+
return req;
|
169
|
+
},
|
170
|
+
(error) => {
|
171
|
+
fail(error);
|
172
|
+
return Promise.reject(error);
|
173
|
+
},
|
174
|
+
);
|
175
|
+
|
176
|
+
net.interceptors.response.use(
|
177
|
+
(response) => {
|
178
|
+
!response.config.notLoading && loading.end();
|
179
|
+
const data = response.data;
|
180
|
+
|
181
|
+
try {
|
182
|
+
return checkFn(data);
|
183
|
+
} catch (err) {
|
184
|
+
// 应用逻辑异常
|
185
|
+
fail(err as any);
|
186
|
+
}
|
187
|
+
},
|
188
|
+
(error) => {
|
189
|
+
!error.config.notLoading && loading.end();
|
190
|
+
// http 异常
|
191
|
+
fail(error);
|
192
|
+
},
|
193
|
+
);
|
194
|
+
|
195
|
+
return {
|
196
|
+
get: undefined,
|
197
|
+
post: undefined,
|
198
|
+
delete: undefined,
|
199
|
+
put: undefined,
|
200
|
+
patch: undefined,
|
201
|
+
head: undefined,
|
202
|
+
purge: undefined,
|
203
|
+
options: undefined,
|
204
|
+
link: undefined,
|
205
|
+
unlink: undefined,
|
206
|
+
__instance__: net,
|
207
|
+
__mixin__(extentions: any) {
|
208
|
+
for (const method in extentions) {
|
209
|
+
if (Object.prototype.hasOwnProperty.call(extentions, method)) {
|
210
|
+
// @ts-ignore
|
211
|
+
const originFns = this[method] || {};
|
212
|
+
const fns = extentions[method];
|
213
|
+
// @ts-ignore
|
214
|
+
this[method] = {
|
215
|
+
...originFns,
|
216
|
+
...fns,
|
217
|
+
};
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
return this;
|
222
|
+
},
|
223
|
+
|
224
|
+
freeReq: net.request,
|
225
|
+
authReq: (args: AxiosRequestConfig) =>
|
226
|
+
net.request({
|
227
|
+
...args,
|
228
|
+
headers: {
|
229
|
+
...headers.getAuthHeaders!(),
|
230
|
+
...args?.headers,
|
231
|
+
},
|
232
|
+
}),
|
233
|
+
} as unknown as Handlers<Fns> & Prototype;
|
234
|
+
};
|
235
|
+
|
236
|
+
export type Http = ReturnType<typeof useHttp>;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 16:50:32
|
4
|
+
* @LastEditTime: 2023-07-18 17:08:14
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { Http } from '../lib';
|
8
|
+
|
9
|
+
export const useGet = (http: Http) => {
|
10
|
+
const FreeReq: Http['freeReq'] = (args) => http.freeReq({ method: 'GET', ...args });
|
11
|
+
const AuthReq: Http['authReq'] = (args) => http.authReq({ method: 'GET', ...args });
|
12
|
+
|
13
|
+
return {
|
14
|
+
getByUserName: (name: string) =>
|
15
|
+
FreeReq<{
|
16
|
+
login: string;
|
17
|
+
id: number;
|
18
|
+
node_id: string;
|
19
|
+
avatar_url: string;
|
20
|
+
gravatar_id: string;
|
21
|
+
url: string;
|
22
|
+
html_url: string;
|
23
|
+
followers_url: string;
|
24
|
+
following_url: string;
|
25
|
+
gists_url: string;
|
26
|
+
starred_url: string;
|
27
|
+
subscriptions_url: string;
|
28
|
+
organizations_url: string;
|
29
|
+
repos_url: string;
|
30
|
+
events_url: string;
|
31
|
+
received_events_url: string;
|
32
|
+
type: string;
|
33
|
+
site_admin: boolean;
|
34
|
+
name: string;
|
35
|
+
company: null | string;
|
36
|
+
blog: string;
|
37
|
+
location: null | string;
|
38
|
+
email: null | string;
|
39
|
+
hireable: null | boolean;
|
40
|
+
bio: null | string;
|
41
|
+
twitter_username: null | string;
|
42
|
+
public_repos: number;
|
43
|
+
public_gists: number;
|
44
|
+
followers: number;
|
45
|
+
following: number;
|
46
|
+
created_at: string;
|
47
|
+
updated_at: string;
|
48
|
+
}>({
|
49
|
+
url: `/users/${name}`,
|
50
|
+
}),
|
51
|
+
};
|
52
|
+
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-18 16:59:34
|
4
|
+
* @LastEditTime: 2023-07-18 16:59:35
|
5
|
+
* @Description:
|
6
|
+
*/
|
7
|
+
import type { Http } from '../lib';
|
8
|
+
|
9
|
+
export const usePost = (http: Http) => {
|
10
|
+
const FreeReq: Http['freeReq'] = (args) => http.freeReq({ method: 'POST', ...args });
|
11
|
+
const AuthReq: Http['authReq'] = (args) => http.authReq({ method: 'POST', ...args });
|
12
|
+
|
13
|
+
return {
|
14
|
+
createRepo: async (name: string) => {
|
15
|
+
await AuthReq({
|
16
|
+
url: `/user/repos`,
|
17
|
+
params: {
|
18
|
+
name,
|
19
|
+
},
|
20
|
+
});
|
21
|
+
},
|
22
|
+
};
|
23
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<!--
|
2
|
+
* @Author: zhangyang
|
3
|
+
* @Date: 2023-07-19 12:12:29
|
4
|
+
* @LastEditTime: 2023-07-19 14:27:31
|
5
|
+
* @Description:
|
6
|
+
-->
|
7
|
+
<script lang="ts" setup>
|
8
|
+
withDefaults(defineProps<{
|
9
|
+
/**
|
10
|
+
* 加载中的动图
|
11
|
+
*/
|
12
|
+
loadingGif?: string;
|
13
|
+
/**
|
14
|
+
* 文本提示
|
15
|
+
*/
|
16
|
+
tip?: string;
|
17
|
+
}>(), {
|
18
|
+
loadingGif: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
|
19
|
+
tip: '加载中...'
|
20
|
+
});
|
21
|
+
|
22
|
+
const loading = ref(true);
|
23
|
+
|
24
|
+
const start = () => loading.value = true;
|
25
|
+
const stop = () => loading.value = false;
|
26
|
+
|
27
|
+
defineExpose({
|
28
|
+
start,
|
29
|
+
stop
|
30
|
+
});
|
31
|
+
</script>
|
32
|
+
<template>
|
33
|
+
<view v-if="loading"
|
34
|
+
class="w100vw h100vh fixed left-0 top-0 z-999999 bg-white flex flex-col items-center justify-center">
|
35
|
+
<image :src="loadingGif" class="w240rpx h240rpx mb-32rpx" />
|
36
|
+
<text class="text-[#999] text-24rpx leading-36rpx">{{ tip }}</text>
|
37
|
+
</view>
|
38
|
+
</template>
|