create-young-proj 0.12.0 → 0.13.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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/template-nuxt-admin/package.json +5 -5
  3. package/template-nuxt-admin/yarn.lock +706 -854
  4. package/template-uni-app/auto-imports.d.ts +9 -6
  5. package/template-uni-app/custom-plugins/index.ts +1 -2
  6. package/template-uni-app/dist/dev/mp-weixin/apis/index.js +5 -6
  7. package/template-uni-app/dist/dev/mp-weixin/apis/requests/get.js +2 -2
  8. package/template-uni-app/dist/dev/mp-weixin/apis/requests/post.js +4 -4
  9. package/template-uni-app/dist/dev/mp-weixin/app.js +4 -5
  10. package/template-uni-app/dist/dev/mp-weixin/common/vendor.js +1448 -2471
  11. package/template-uni-app/dist/dev/mp-weixin/components/young-navbar/young-navbar.js +7 -8
  12. package/template-uni-app/dist/dev/mp-weixin/components/young-navbar/young-navbar.wxml +1 -1
  13. package/template-uni-app/dist/dev/mp-weixin/components/young-tabbar/young-tabbar.js +7 -8
  14. package/template-uni-app/dist/dev/mp-weixin/components/young-tabbar/young-tabbar.wxml +1 -1
  15. package/template-uni-app/dist/dev/mp-weixin/layouts/default.js +1 -2
  16. package/template-uni-app/dist/dev/mp-weixin/layouts/tabbar.wxml +1 -1
  17. package/template-uni-app/dist/dev/mp-weixin/pages/demo/index.js +4 -5
  18. package/template-uni-app/dist/dev/mp-weixin/pages/demo/index.wxml +1 -1
  19. package/template-uni-app/dist/dev/mp-weixin/pages/index.js +4 -5
  20. package/template-uni-app/dist/dev/mp-weixin/pages/index.wxml +1 -1
  21. package/template-uni-app/dist/dev/mp-weixin/pages/my.wxml +1 -1
  22. package/template-uni-app/dist/dev/mp-weixin/project.config.json +1 -2
  23. package/template-uni-app/dist/dev/mp-weixin/project.private.config.json +6 -0
  24. package/template-uni-app/dist/dev/mp-weixin/store/local/index.js +3 -1
  25. package/template-uni-app/dist/dev/mp-weixin/utils/modal.js +10 -14
  26. package/template-uni-app/dist/dev/mp-weixin/utils/route.js +4 -6
  27. package/template-uni-app/dist/dev/mp-weixin/utils/system.js +4 -4
  28. package/template-uni-app/package.json +2 -3
  29. package/template-uni-app/pnpm-lock.yaml +154 -105
  30. package/template-uni-app/src/apis/index.ts +2 -2
  31. package/template-uni-app/src/apis/requests/get.ts +5 -5
  32. package/template-uni-app/src/apis/requests/post.ts +5 -5
  33. package/template-uni-app/vite.config.ts +2 -3
  34. package/template-uni-app/custom-plugins/polyfill.ts +0 -32
  35. package/template-uni-app/dist/dev/mp-weixin/apis/lib/index.js +0 -90
  36. package/template-uni-app/src/apis/lib/index.ts +0 -235
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-07-18 16:50:32
4
- * @LastEditTime: 2023-07-18 17:08:14
4
+ * @LastEditTime: 2023-09-19 10:19:44
5
5
  * @Description:
6
6
  */
7
- import type { Http } from '../lib'
7
+ import type { YoungHttp, YoungHttpAuthReq, YoungHttpFreeReq } from '@bluesyoung/http'
8
8
 
9
- export function 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 })
9
+ export function useGet(http: YoungHttp) {
10
+ const FreeReq: YoungHttpFreeReq = args => http.freeReq({ method: 'GET', ...args })
11
+ const AuthReq: YoungHttpAuthReq = args => http.authReq({ method: 'GET', ...args })
12
12
 
13
13
  return {
14
14
  getByUserName: (name: string) =>
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-07-18 16:59:34
4
- * @LastEditTime: 2023-07-18 16:59:35
4
+ * @LastEditTime: 2023-09-19 10:20:17
5
5
  * @Description:
6
6
  */
7
- import type { Http } from '../lib'
7
+ import type { YoungHttp, YoungHttpAuthReq, YoungHttpFreeReq } from '@bluesyoung/http'
8
8
 
9
- export function 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 })
9
+ export function usePost(http: YoungHttp) {
10
+ const FreeReq: YoungHttpFreeReq = args => http.freeReq({ method: 'GET', ...args })
11
+ const AuthReq: YoungHttpAuthReq = args => http.authReq({ method: 'GET', ...args })
12
12
 
13
13
  return {
14
14
  createRepo: async (name: string) => {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-07-18 11:03:01
4
- * @LastEditTime: 2023-07-20 14:10:56
4
+ * @LastEditTime: 2023-09-19 10:18:06
5
5
  * @Description:
6
6
  */
7
7
  import { resolve } from 'node:path'
@@ -15,7 +15,7 @@ import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
15
15
  import Unocss from 'unocss/vite'
16
16
  import AutoImport from 'unplugin-auto-import/vite'
17
17
  import AutoComponents from 'unplugin-vue-components/vite'
18
- import { multiConf, polyfillFormData } from './custom-plugins'
18
+ import { multiConf } from './custom-plugins'
19
19
 
20
20
  // https://vitejs.dev/config/
21
21
  export default ({ command, mode }: ConfigEnv) => {
@@ -28,7 +28,6 @@ export default ({ command, mode }: ConfigEnv) => {
28
28
  },
29
29
  },
30
30
  plugins: [
31
- polyfillFormData(),
32
31
  // 仅用于增加语法提示,实际导入依靠 uni-app 的 easycom
33
32
  AutoComponents({
34
33
  dts: true,
@@ -1,32 +0,0 @@
1
- /*
2
- * @Author: zhangyang
3
- * @Date: 2023-07-18 15:58:06
4
- * @LastEditTime: 2023-07-19 14:32:28
5
- * @Description:
6
- */
7
- import type { Plugin } from 'vite'
8
-
9
- export function polyfillFormData() {
10
- return {
11
- name: 'vite-plugin-uni-axios',
12
- transform(code, id) {
13
- if (process.env.UNI_PLATFORM?.includes('mp')) {
14
- if (id.includes('/form-data/lib/browser.js')) {
15
- return {
16
- code: code.replace('window', 'globalThis'),
17
- }
18
- }
19
- if (id.includes('/axios/lib/platform/browser/classes/FormData.js')) {
20
- return {
21
- code: 'import FormData from \'miniprogram-formdata\';\nexport default FormData;',
22
- }
23
- }
24
- if (id.includes('/axios/lib/platform/browser/classes/Blob.js')) {
25
- return {
26
- code: 'import Blob from \'miniprogram-blob\';\nexport default Blob;',
27
- }
28
- }
29
- }
30
- },
31
- } as Plugin
32
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
- const common_vendor = require("../../common/vendor.js");
3
- const defaultConfig = {
4
- baseURL: "/api",
5
- method: "post",
6
- timeout: 5e3,
7
- loading: {
8
- start: console.log.bind(null, "🚀 ~ http loading start"),
9
- end: console.log.bind(null, "🚀 ~ http loading end")
10
- },
11
- fail: console.error.bind(null, "🚀 ~ http loading error"),
12
- checkFn: (res) => res,
13
- headers: {
14
- getCommonHeaders: () => ({}),
15
- getAuthHeaders: () => ({})
16
- }
17
- };
18
- const useHttp = (config = {}) => {
19
- const finalConfig = common_vendor.defu(config, defaultConfig);
20
- const { baseURL, lazyBaseURL, method, timeout, headers, checkFn, loading, fail } = finalConfig;
21
- const net = common_vendor.axios.create({
22
- method,
23
- timeout,
24
- headers: headers.getCommonHeaders(),
25
- adapter: common_vendor.Bt()
26
- });
27
- net.interceptors.request.use(
28
- (req) => {
29
- !req.notLoading && loading.start();
30
- if (!req.baseURL) {
31
- req.baseURL = (lazyBaseURL == null ? void 0 : lazyBaseURL()) ?? baseURL;
32
- }
33
- return req;
34
- },
35
- (error) => {
36
- fail(error);
37
- return Promise.reject(error);
38
- }
39
- );
40
- net.interceptors.response.use(
41
- (response) => {
42
- !response.config.notLoading && loading.end();
43
- const data = response.data;
44
- try {
45
- return checkFn(data);
46
- } catch (err) {
47
- fail(err);
48
- }
49
- },
50
- (error) => {
51
- !error.config.notLoading && loading.end();
52
- fail(error);
53
- }
54
- );
55
- return {
56
- get: void 0,
57
- post: void 0,
58
- delete: void 0,
59
- put: void 0,
60
- patch: void 0,
61
- head: void 0,
62
- purge: void 0,
63
- options: void 0,
64
- link: void 0,
65
- unlink: void 0,
66
- __instance__: net,
67
- __mixin__(extentions) {
68
- for (const method2 in extentions) {
69
- if (Object.prototype.hasOwnProperty.call(extentions, method2)) {
70
- const originFns = this[method2] || {};
71
- const fns = extentions[method2];
72
- this[method2] = {
73
- ...originFns,
74
- ...fns
75
- };
76
- }
77
- }
78
- return this;
79
- },
80
- freeReq: net.request,
81
- authReq: (args) => net.request({
82
- ...args,
83
- headers: {
84
- ...headers.getAuthHeaders(),
85
- ...args == null ? void 0 : args.headers
86
- }
87
- })
88
- };
89
- };
90
- exports.useHttp = useHttp;
@@ -1,235 +0,0 @@
1
- /*
2
- * @Author: zhangyang
3
- * @Date: 2023-07-18 16:36:39
4
- * @LastEditTime: 2023-09-06 19:40:19
5
- * @Description:
6
- */
7
- /// <reference types="@uni-helper/axios-adapter/client" />
8
- import type { AxiosAdapter, AxiosInstance, AxiosRequestConfig, Method } 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 = any, R = 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 = any>(config: AxiosRequestConfig<unknown>) => Promise<X>
38
-
39
- interface 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 interface DefaultMsg {
56
- code: number
57
- msg: string
58
- data: any
59
- }
60
-
61
- export interface DefaultHttpConfig<Msg = 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 function useHttp<Msg extends Record<string, any> = DefaultMsg, Fns extends Cbks = Cbks>(config: Partial<DefaultHttpConfig<Msg>> = {}) {
149
- const finalConfig = defu(config, defaultConfig)
150
-
151
- const { baseURL, lazyBaseURL, method, timeout, headers, checkFn, loading, fail } = finalConfig
152
-
153
- const net = axios.create({
154
- method,
155
- timeout,
156
- headers: headers.getCommonHeaders!(),
157
- adapter: createUniAppAxiosAdapter(),
158
- })
159
-
160
- net.interceptors.request.use(
161
- (req) => {
162
- !req.notLoading && loading.start()
163
- if (!req.baseURL)
164
- req.baseURL = lazyBaseURL?.() ?? baseURL
165
-
166
- return req
167
- },
168
- (error) => {
169
- fail(error)
170
- return Promise.reject(error)
171
- },
172
- )
173
-
174
- net.interceptors.response.use(
175
- (response) => {
176
- !response.config.notLoading && loading.end()
177
- const data = response.data
178
-
179
- try {
180
- return checkFn(data)
181
- }
182
- catch (err) {
183
- // 应用逻辑异常
184
- fail(err as any)
185
- }
186
- },
187
- (error) => {
188
- !error.config.notLoading && loading.end()
189
- // http 异常
190
- fail(error)
191
- },
192
- )
193
-
194
- return {
195
- get: undefined,
196
- post: undefined,
197
- delete: undefined,
198
- put: undefined,
199
- patch: undefined,
200
- head: undefined,
201
- purge: undefined,
202
- options: undefined,
203
- link: undefined,
204
- unlink: undefined,
205
- __instance__: net,
206
- __mixin__(extentions: any) {
207
- for (const method in extentions) {
208
- if (Object.prototype.hasOwnProperty.call(extentions, method)) {
209
- // @ts-expect-error
210
- const originFns = this[method] || {}
211
- const fns = extentions[method]
212
- // @ts-expect-error
213
- this[method] = {
214
- ...originFns,
215
- ...fns,
216
- }
217
- }
218
- }
219
-
220
- return this
221
- },
222
-
223
- freeReq: net.request,
224
- authReq: (args: AxiosRequestConfig) =>
225
- net.request({
226
- ...args,
227
- headers: {
228
- ...headers.getAuthHeaders!(),
229
- ...args?.headers,
230
- },
231
- }),
232
- } as unknown as Handlers<Fns> & Prototype
233
- }
234
-
235
- export type Http = ReturnType<typeof useHttp>