create-young-proj 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/package.json +1 -1
  3. package/template-nuxt-admin/nuxt.config.ts +4 -2
  4. package/template-nuxt-admin/server/plugins/env.ts +10 -4
  5. package/template-nuxt-website/README.md +12 -0
  6. package/template-nuxt-website/boot.mjs +10 -1
  7. package/template-nuxt-website/composables/config.ts +10 -4
  8. package/template-nuxt-website/composables/utils.ts +0 -4
  9. package/template-nuxt-website/nuxt.config.ts +19 -2
  10. package/template-nuxt-website/package.json +4 -5
  11. package/template-nuxt-website/server/api/get_footer_info.get.ts +5 -5
  12. package/template-nuxt-website/server/api/get_gray_status.get.ts +3 -2
  13. package/template-nuxt-website/server/api/get_head_nav.get.ts +3 -3
  14. package/template-nuxt-website/server/api/get_home_banner.get.ts +4 -4
  15. package/template-nuxt-website/server/api/get_seo_info.get.ts +1 -1
  16. package/template-nuxt-website/server/plugins/init.ts +16 -18
  17. package/template-nuxt-website/server/routes/get/env.ts +13 -0
  18. package/template-nuxt-website/yarn.lock +1173 -1599
  19. package/template-uni-app/.vscode/vue-html.code-snippets +2 -7
  20. package/template-uni-app/README.md +2 -0
  21. package/template-uni-app/auto-imports.d.ts +718 -1
  22. package/template-uni-app/eslint.config.js +3 -1
  23. package/template-uni-app/package.json +11 -9
  24. package/template-uni-app/pnpm-lock.yaml +531 -866
  25. package/template-uni-app/src/manifest.json +1 -1
  26. package/template-uni-app/src/pages/index.vue +12 -9
  27. package/template-uni-app/src/pages/my.vue +6 -9
  28. package/template-uni-app/src/pages.json +1 -1
  29. package/template-uni-app/uni-pages.d.ts +24 -0
  30. package/template-uni-app/vite.config.ts +6 -3
  31. package/template-uni-app/.eslintignore +0 -1
  32. package/template-uni-app/.eslintrc +0 -16
package/CHANGELOG.md CHANGED
@@ -1,6 +1,58 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ ## v1.3.0
5
+
6
+ [compare changes](https://github.com/BluesYoung-web/create-young-proj/compare/v1.2.1...v1.3.0)
7
+
8
+ ### 🚀 Enhancements
9
+
10
+ - 🚀 route json -> route yaml ([3ab111c](https://github.com/BluesYoung-web/create-young-proj/commit/3ab111c))
11
+ - 🚀 add missing /get/env api ([a48d2c1](https://github.com/BluesYoung-web/create-young-proj/commit/a48d2c1))
12
+ - 🚀 add @uni-helper/uni-use & @vueuse/core ([bd2d2cf](https://github.com/BluesYoung-web/create-young-proj/commit/bd2d2cf))
13
+ - ⚠️ 🚀 360 极速浏览器 13.5 定向兼容-css better ([51d9b33](https://github.com/BluesYoung-web/create-young-proj/commit/51d9b33))
14
+
15
+ ### 🩹 Fixes
16
+
17
+ - ⚠️ 🩹 fix build error ([1a7ad50](https://github.com/BluesYoung-web/create-young-proj/commit/1a7ad50))
18
+ - ⚠️ 🩹 360 极速浏览器 13.5 定向兼容 ([e5cefc8](https://github.com/BluesYoung-web/create-young-proj/commit/e5cefc8))
19
+
20
+ ### 🏡 Chore
21
+
22
+ - 🏡 依赖升级 ([c3bc4b6](https://github.com/BluesYoung-web/create-young-proj/commit/c3bc4b6))
23
+
24
+ ### 🎨 Styles
25
+
26
+ - 🎨 lint fix ([96c1a4e](https://github.com/BluesYoung-web/create-young-proj/commit/96c1a4e))
27
+
28
+ #### ⚠️ Breaking Changes
29
+
30
+ - ⚠️ 🚀 360 极速浏览器 13.5 定向兼容-css better ([51d9b33](https://github.com/BluesYoung-web/create-young-proj/commit/51d9b33))
31
+ - ⚠️ 🩹 fix build error ([1a7ad50](https://github.com/BluesYoung-web/create-young-proj/commit/1a7ad50))
32
+ - ⚠️ 🩹 360 极速浏览器 13.5 定向兼容 ([e5cefc8](https://github.com/BluesYoung-web/create-young-proj/commit/e5cefc8))
33
+
34
+ ### ❤️ Contributors
35
+
36
+ - 张扬 <bluesyoung_web@163.com>
37
+
38
+ ## v1.2.1
39
+
40
+ [compare changes](https://github.com/BluesYoung-web/create-young-proj/compare/v1.2.0...v1.2.1)
41
+
42
+ ### 🚀 Enhancements
43
+
44
+ - 🚀 日志 & 自适应跳转优化 ([1325277](https://github.com/BluesYoung-web/create-young-proj/commit/1325277))
45
+ - 🚀 打印请求者 ua, ip ([59fc41d](https://github.com/BluesYoung-web/create-young-proj/commit/59fc41d))
46
+ - 🚀 缓存配置 ([3573531](https://github.com/BluesYoung-web/create-young-proj/commit/3573531))
47
+
48
+ ### 🔥 Performance
49
+
50
+ - 🔥 缓存机制优化 ([cbe8bb5](https://github.com/BluesYoung-web/create-young-proj/commit/cbe8bb5))
51
+
52
+ ### ❤️ Contributors
53
+
54
+ - 张扬 <bluesyoung_web@163.com>
55
+
4
56
  ## v1.2.0
5
57
 
6
58
  [compare changes](https://github.com/BluesYoung-web/create-young-proj/compare/v1.1.0...v1.2.0)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-young-proj",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "description": "create project from template",
6
6
  "author": "BluesYoung-web",
7
7
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
- * @Date: 2023-05-25 19:45:20
4
- * @LastEditTime: 2023-11-07 15:56:03
3
+ * @Date: 2023-09-21 15:57:55
4
+ * @LastEditTime: 2023-11-15 11:52:33
5
5
  * @Description:
6
6
  */
7
7
  import { resolve } from 'node:path'
@@ -87,6 +87,8 @@ export default defineNuxtConfig({
87
87
  // 兼容钉钉浏览器
88
88
  target: 'es2015',
89
89
  sourcemap: false,
90
+ /* hack fix 360 极速浏览器 13.5 不支持 inset */
91
+ cssTarget: 'chrome61',
90
92
  },
91
93
  css: {
92
94
  preprocessorOptions: {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2022-12-30 17:19:42
4
- * @LastEditTime: 2023-11-07 14:38:26
4
+ * @LastEditTime: 2023-11-10 16:09:24
5
5
  * @Description:
6
6
  */
7
7
  import { resolve } from 'node:path'
@@ -48,13 +48,19 @@ export default defineNitroPlugin(async (nitroApp) => {
48
48
  delete config[key]
49
49
  }
50
50
 
51
+ // 仅打包之后格式化日志
52
+ if (process.env.NODE_ENV !== 'development')
53
+ useYoungLogger()
54
+
51
55
  console.log('------------------------读取配置文件------------------------')
52
56
  console.log(config)
53
57
  console.log('-------------------------------------------------------------')
54
58
 
55
- // 仅打包之后格式化日志
56
- if (process.env.NODE_ENV !== 'development')
57
- useYoungLogger()
59
+ nitroApp.hooks.hook('request', (event) => {
60
+ const headers = event.node.req.headers
61
+ console.log('ua', headers['user-agent'], 'x-forwarded-for', headers['x-forwarded-for'], 'x-real-ip', headers['x-real-ip'])
62
+ })
63
+
58
64
 
59
65
  nitroApp.hooks.hook('render:html', (html, { event }) => {
60
66
  // 直接注入环境变量到前端
@@ -27,6 +27,18 @@ navigateTo({
27
27
 
28
28
  **`asstes` 内的图片不得大于 4k**,超过大小的图片需要转换为 `webp` 后上传至 `cdn`
29
29
 
30
+ ### 接口缓存基准时间
31
+
32
+ 开发时可以修改 `nuxt.config.ts -> runtimeConfig -> public -> cacheTime` 的值
33
+
34
+ 部署时调整 `boot.mjs` 中 `NUXT_PUBLIC_CACHE_TIME` 的默认值
35
+
36
+ **系统环境变量 `NUXT_PUBLIC_CACHE_TIME` 优先级最高!!!**
37
+
38
+ ### 垃圾浏览器
39
+
40
+ [**360 极速浏览器 13.5 !!!mdzz**](https://bbs.360.cn/thread-15913525-1-1.html)
41
+
30
42
  ## 特性
31
43
 
32
44
  - 基于 [@nuxtjs/device](https://github.com/nuxt-modules/device) 的设备判断
@@ -1,12 +1,21 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2022-09-07 09:31:12
4
- * @LastEditTime: 2023-05-26 11:21:19
4
+ * @LastEditTime: 2023-11-10 09:41:43
5
5
  * @Description:
6
6
  */
7
7
  (async () => {
8
8
  const env = process.env.DEPLOY_ENV
9
9
  const listenPort = process.env.LISTEN_PORT || 3003
10
+
11
+ /**
12
+ * !!! 接口缓存时间基准配置,默认 60s
13
+ */
14
+ const NUXT_PUBLIC_CACHE_TIME = 60
15
+
16
+ if (!(+process.env.NUXT_PUBLIC_CACHE_TIME > 0))
17
+ process.env.NUXT_PUBLIC_CACHE_TIME = NUXT_PUBLIC_CACHE_TIME
18
+
10
19
  console.log('当前环境:', env)
11
20
  console.log('服务监听端口:', listenPort)
12
21
 
@@ -1,11 +1,17 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-07-26 11:48:46
4
- * @LastEditTime: 2023-09-27 12:06:20
4
+ * @LastEditTime: 2023-11-10 10:27:21
5
5
  * @Description:
6
6
  */
7
7
  /**
8
- * 接口缓存时间,单位为 s
9
- * todo: 正式部署前按需修改
8
+ * 接口缓存基准时间,单位为 s
10
9
  */
11
- export const NUXT_PUBLIC_CACHE_TIME = 1
10
+ export const NUXT_PUBLIC_CACHE_TIME = +useRuntimeConfig().public.cacheTime
11
+
12
+ if (!NUXT_PUBLIC_CACHE_TIME) {
13
+ console.error('配置异常:缓存基准时长 NUXT_PUBLIC_CACHE_TIME', NUXT_PUBLIC_CACHE_TIME)
14
+ process.exit(1)
15
+ }
16
+
17
+ console.log('缓存基准时长 NUXT_PUBLIC_CACHE_TIME:', NUXT_PUBLIC_CACHE_TIME, '秒')
@@ -34,8 +34,6 @@ export function closeWindow() {
34
34
  window.close()
35
35
  }
36
36
 
37
-
38
-
39
37
  export async function showLoading() {
40
38
  if (process.server)
41
39
  return
@@ -80,5 +78,3 @@ export function injectComponent(El: ReturnType<typeof defineComponent>) {
80
78
 
81
79
  return onDestroy
82
80
  }
83
-
84
-
@@ -1,10 +1,9 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-09-21 15:57:55
4
- * @LastEditTime: 2023-11-08 10:56:04
4
+ * @LastEditTime: 2023-11-15 11:53:36
5
5
  * @Description:
6
6
  */
7
-
8
7
  import { resolve } from 'node:path'
9
8
 
10
9
  // https://nuxt.com/docs/api/configuration/nuxt-config
@@ -88,11 +87,29 @@ export default defineNuxtConfig({
88
87
  defaultImage: '/svg/image_placeholder.svg',
89
88
  },
90
89
 
90
+ 'routeRules': {
91
+ /**
92
+ * 页面缓存,配置具体数值会被作为 max-age 的值,不过貌似 true 就足够了
93
+ * 根据具体情况自行调整各个路径的对应配置
94
+ */
95
+ '*': { swr: true },
96
+ },
97
+
91
98
  'vite': {
92
99
  build: {
93
100
  // 兼容钉钉浏览器
94
101
  target: 'es2015',
95
102
  sourcemap: false,
103
+ /* hack fix 360 极速浏览器 13.5 不支持 inset */
104
+ cssTarget: 'chrome61',
105
+ },
106
+ },
107
+ 'runtimeConfig': {
108
+ public: {
109
+ /**
110
+ * 接口缓存基准时间,会被 NUXT_PUBLIC_CACHE_TIME 环境变量覆盖
111
+ */
112
+ cacheTime: 10,
96
113
  },
97
114
  },
98
115
  })
@@ -5,9 +5,9 @@
5
5
  "private": true,
6
6
  "scripts": {
7
7
  "build": "nuxt build",
8
- "dev": "nuxt dev --host",
8
+ "dev": "nuxt dev",
9
9
  "generate": "nuxt generate",
10
- "preview": "nuxt preview --host",
10
+ "preview": "nuxt preview",
11
11
  "postinstall": "nuxt prepare",
12
12
  "lint": "eslint .",
13
13
  "lint:fix": "eslint . --fix"
@@ -31,11 +31,10 @@
31
31
  "@vueuse/nuxt": "^10.5.0",
32
32
  "element-plus": "^2.3.14",
33
33
  "eslint": "^8.51.0",
34
- "nuxt": "3.7.4",
34
+ "nuxt": "3.5.1",
35
35
  "nuxt-swiper": "^1.2.2",
36
36
  "sass": "^1.69.5",
37
37
  "typescript": "^5.2.2",
38
- "vant": "^4.7.3",
39
- "vconsole": "^3.15.1"
38
+ "vant": "^4.7.3"
40
39
  }
41
40
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-10-07 16:02:03
4
- * @LastEditTime: 2023-11-08 10:32:38
4
+ * @LastEditTime: 2023-11-10 15:02:38
5
5
  * @Description:
6
6
  */
7
7
  import { NUXT_PUBLIC_CACHE_TIME } from '~~/composables/config'
@@ -13,12 +13,12 @@ export default cachedEventHandler(async () => {
13
13
  const friend_links: FriendLinkItem[] = [
14
14
  {
15
15
  title: '来游戏',
16
- href: 'https://www.laiyouxi.com'
16
+ href: 'https://www.laiyouxi.com',
17
17
  },
18
18
  {
19
19
  title: '🌾',
20
- href: 'https://mi.com'
21
- }
20
+ href: 'https://mi.com',
21
+ },
22
22
  ]
23
23
  const follow_us: FollowItem[] = []
24
24
  const about_nav: AboutNavItem[] = []
@@ -47,6 +47,6 @@ export default cachedEventHandler(async () => {
47
47
  return false
48
48
  }
49
49
  }, {
50
- maxAge: NUXT_PUBLIC_CACHE_TIME,
50
+ maxAge: NUXT_PUBLIC_CACHE_TIME * 10,
51
51
  swr: true,
52
52
  })
@@ -1,10 +1,11 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-06-07 12:06:48
4
- * @LastEditTime: 2023-11-08 10:30:59
4
+ * @LastEditTime: 2023-11-10 15:02:45
5
5
  * @Description:
6
6
  */
7
7
  import { NUXT_PUBLIC_CACHE_TIME } from '~~/composables/config'
8
+
8
9
  /**
9
10
  * @example 服务端请求示例
10
11
  */
@@ -33,6 +34,6 @@ export default cachedEventHandler(async (event) => {
33
34
  }
34
35
  }
35
36
  }, {
36
- maxAge: NUXT_PUBLIC_CACHE_TIME * 3,
37
+ maxAge: NUXT_PUBLIC_CACHE_TIME * 5,
37
38
  swr: true,
38
39
  })
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-06-07 14:43:38
4
- * @LastEditTime: 2023-11-08 09:53:14
4
+ * @LastEditTime: 2023-11-10 15:02:52
5
5
  * @Description:
6
6
  */
7
7
  import { NUXT_PUBLIC_CACHE_TIME } from '~~/composables/config'
@@ -14,7 +14,7 @@ export default cachedEventHandler(async () => {
14
14
  { title: '首页', href: '/' },
15
15
  { title: '资讯', href: '/news.html' },
16
16
  { title: '赛事', href: '/match.html' },
17
- { title: '商城', href: '/shop.html' }
17
+ { title: '商城', href: '/shop.html' },
18
18
  ]
19
19
  const fromMobile = process.env.PROJECT_NAME === 'mobile'
20
20
 
@@ -33,6 +33,6 @@ export default cachedEventHandler(async () => {
33
33
  return false
34
34
  }
35
35
  }, {
36
- maxAge: NUXT_PUBLIC_CACHE_TIME,
36
+ maxAge: NUXT_PUBLIC_CACHE_TIME * 5,
37
37
  swr: true,
38
38
  })
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-10-07 17:43:38
4
- * @LastEditTime: 2023-10-09 12:08:35
4
+ * @LastEditTime: 2023-11-10 15:03:01
5
5
  * @Description:
6
6
  */
7
7
  import { NUXT_PUBLIC_CACHE_TIME } from '~~/composables/config'
@@ -12,8 +12,8 @@ export default cachedEventHandler(async (event) => {
12
12
  try {
13
13
  const banners: BannerItem[] = [
14
14
  {
15
- img_url: 'https://master-web-cdn.laiyouxi.com/platform_index/online/files/banner-pc.png'
16
- }
15
+ img_url: 'https://master-web-cdn.laiyouxi.com/platform_index/online/files/banner-pc.png',
16
+ },
17
17
  ]
18
18
 
19
19
  return banners
@@ -23,6 +23,6 @@ export default cachedEventHandler(async (event) => {
23
23
  return false
24
24
  }
25
25
  }, {
26
- maxAge: NUXT_PUBLIC_CACHE_TIME,
26
+ maxAge: NUXT_PUBLIC_CACHE_TIME * 3,
27
27
  swr: true,
28
28
  })
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2023-06-07 14:29:59
4
- * @LastEditTime: 2023-11-08 09:51:06
4
+ * @LastEditTime: 2023-11-10 15:03:09
5
5
  * @Description:
6
6
  */
7
7
  import { NUXT_PUBLIC_CACHE_TIME } from '~~/composables/config'
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2022-12-30 17:19:42
4
- * @LastEditTime: 2023-11-08 10:52:46
4
+ * @LastEditTime: 2023-11-10 14:59:37
5
5
  * @Description:
6
6
  */
7
7
  import { resolve } from 'node:path'
@@ -9,6 +9,9 @@ import { loadConfig } from 'c12'
9
9
  import { useYoungLogger } from '@bluesyoung/logger'
10
10
 
11
11
  export default defineNitroPlugin(async (nitroApp) => {
12
+ const IS_PROD = process.env.NODE_ENV !== 'development'
13
+ console.log('🚀 ~ file: init.ts:13 ~ IS_PROD:', IS_PROD)
14
+
12
15
  const env = (process.env.DEPLOY_ENV as 'dev' | 'test' | 'online') || 'dev'
13
16
  const { config } = await loadConfig<Record<string, any>>({
14
17
  name: env,
@@ -17,7 +20,7 @@ export default defineNitroPlugin(async (nitroApp) => {
17
20
  // 优先读取环境变量中的版本信息(自己打的 Tag)
18
21
  NUXT_PUBLIC_CURRENT_VERSION: process.env.PROJECT_VERSION || 'v0.0.1',
19
22
  // 日志等级
20
- CONSOLA_LEVEL: 1,
23
+ CONSOLA_LEVEL: 3,
21
24
  // 此处可以放置通用的环境变量
22
25
  VITE_WECHAT_APPID: 'todo: 微信公众号appid',
23
26
  VITE_OSS_URL: `https://master-web-cdn.laiyouxi.com/platform_index/${env}/`,
@@ -45,25 +48,19 @@ export default defineNitroPlugin(async (nitroApp) => {
45
48
  delete config[key]
46
49
  }
47
50
 
48
- console.log('------------------------读取配置文件------------------------')
49
- console.log(config)
50
- console.log('-------------------------------------------------------------')
51
-
52
- const IS_PROD = process.env.NODE_ENV !== 'development'
53
- console.log('🚀 ~ file: init.ts:53 ~ IS_PROD:', IS_PROD)
54
-
55
51
  if (IS_PROD) {
56
52
  // 格式化日志
57
- const { consola } = useYoungLogger()
58
- const logger = consola.create({
59
- level: +process.env.CONSOLA_LEVEL!,
60
- })
61
- logger.wrapConsole()
53
+ useYoungLogger()
62
54
  }
63
55
 
64
- nitroApp.hooks.hook('render:html', async (html, { event }) => {
56
+ console.log('------------------------读取配置文件------------------------')
57
+ console.log(config)
58
+ console.log('-------------------------------------------------------------')
59
+
60
+ nitroApp.hooks.hook('request', (event) => {
65
61
  const ua = event.node.req.headers['user-agent']
66
62
 
63
+ console.log('ua', ua, 'x-forwarded-for', event.node.req.headers['x-forwarded-for'], 'x-real-ip', event.node.req.headers['x-real-ip'])
67
64
  console.log('jump status: ', !config!.DISABLE_AUTO_LOCATION, typeof !config!.DISABLE_AUTO_LOCATION)
68
65
 
69
66
  if (ua && (IS_PROD && !config!.DISABLE_AUTO_LOCATION)) {
@@ -76,18 +73,19 @@ export default defineNitroPlugin(async (nitroApp) => {
76
73
  console.log('🚀 ~ file: init.ts:64 ~ nitroApp.hooks.hook ~ 手机访问 PC 网址:')
77
74
  event.node.res.setHeader('Location', process.env.VITE_WEBSITE_MOBILE! + event.node.req.url)
78
75
  event.node.res.statusCode = 301
79
- return
76
+ event.node.res.end()
80
77
  }
81
78
  else if (!isMobile && fromMobile) {
82
79
  // PC 访问手机网址
83
80
  console.log('🚀 ~ file: init.ts:72 ~ nitroApp.hooks.hook ~ PC 访问手机网址:')
84
81
  event.node.res.setHeader('Location', process.env.VITE_WEBSITE_PC! + event.node.req.url)
85
82
  event.node.res.statusCode = 301
86
- return
83
+ event.node.res.end()
87
84
  }
88
85
  }
86
+ })
89
87
 
90
- // 网站置灰
88
+ nitroApp.hooks.hook('render:html', async (html, { event }) => {
91
89
  try {
92
90
  const {
93
91
  is_gray,
@@ -0,0 +1,13 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-07-20 19:48:12
4
+ * @LastEditTime: 2023-07-21 11:18:40
5
+ * @Description:
6
+ */
7
+ export default defineEventHandler(async (event) => {
8
+ const envObj = {
9
+ NUXT_PUBLIC_CURRENT_VERSION: process.env.PROJECT_VERSION || 'v0.0.1',
10
+ }
11
+
12
+ return envObj
13
+ })