create-young-proj 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -29,4 +29,4 @@
29
29
 
30
30
  ## template-admin-server
31
31
 
32
- 基于 [midwayjs] 开发的后端服务程序
32
+ 基于 [midwayjs](https://www.midwayjs.org/) 开发的后端服务程序
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-young-proj",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "create project from template",
5
5
  "main": "index.mjs",
6
6
  "bin": {
@@ -0,0 +1,30 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-01-10 14:43:13
4
+ * @LastEditTime: 2023-01-10 15:11:44
5
+ * @Description:
6
+ */
7
+ import { networkInterfaces } from 'node:os';
8
+
9
+ const virtualModuleId = 'virtual:local-server';
10
+ const ips = networkInterfaces();
11
+ export const localServer = `http://${ips['eth0'][0].address}:3000`;
12
+
13
+ /**
14
+ * 获取本机 ip 地址,拼接开发时的服务地址
15
+ */
16
+ export const serverPlugin = () => {
17
+ return {
18
+ name: 'local-server',
19
+ resolveId(id) {
20
+ if (id === virtualModuleId) {
21
+ return virtualModuleId;
22
+ }
23
+ },
24
+ load(id) {
25
+ if (id === virtualModuleId) {
26
+ return `export const server = '${localServer}';`;
27
+ }
28
+ },
29
+ };
30
+ };
@@ -0,0 +1,7 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-01-10 14:46:42
4
+ * @LastEditTime: 2023-01-10 14:46:43
5
+ * @Description:
6
+ */
7
+ export * from './plugins';
@@ -0,0 +1,59 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-01-10 14:26:01
4
+ * @LastEditTime: 2023-01-10 15:18:31
5
+ * @Description:
6
+ */
7
+ import type { PluginOption } from 'vite';
8
+ import { serverPlugin } from './custom-plugin';
9
+ import vue from '@vitejs/plugin-vue';
10
+ import vueJsx from '@vitejs/plugin-vue-jsx';
11
+ import legacy from '@vitejs/plugin-legacy';
12
+ import Unocss from 'unocss/vite';
13
+ // 自动导入
14
+ import AutoImport from 'unplugin-auto-import/vite';
15
+ import AutoComopnents from 'unplugin-vue-components/vite';
16
+ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
17
+ // 自动路由及布局
18
+ import Pages from 'vite-plugin-pages';
19
+ import Layouts from 'vite-plugin-vue-layouts';
20
+
21
+ export { localServer } from './custom-plugin';
22
+
23
+ export const usePlugins = () => {
24
+ return [
25
+ serverPlugin(),
26
+ vue(),
27
+ vueJsx(),
28
+ Pages({
29
+ extensions: ['vue', 'tsx'],
30
+ dirs: 'src/views',
31
+ exclude: ['**/components/*.{vue,tsx}', '_*'],
32
+ }),
33
+ Layouts({ defaultLayout: 'default/index' }),
34
+ AutoComopnents({
35
+ dirs: ['src/components'],
36
+ dts: './src/auto-components.d.ts',
37
+ extensions: ['vue', 'tsx'],
38
+ resolvers: [ElementPlusResolver()],
39
+ }),
40
+ AutoImport({
41
+ dts: './src/auto-imports.d.ts',
42
+ imports: [
43
+ 'vue',
44
+ 'vue-router',
45
+ '@vueuse/core',
46
+ 'pinia',
47
+ {
48
+ 'element-plus': ['ElMessage', 'ElMessageBox', 'ElLoadingService'],
49
+ },
50
+ ],
51
+ }),
52
+ Unocss(),
53
+ // 不生成同名 polyfill 文件,打包速度翻倍
54
+ // 如果出现兼容问题,可以删除此配置
55
+ legacy({
56
+ // renderLegacyChunks: false
57
+ }),
58
+ ] as PluginOption[];
59
+ };
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2022-12-03 15:57:40
4
- * @LastEditTime: 2023-01-04 14:30:48
4
+ * @LastEditTime: 2023-01-10 15:09:29
5
5
  * @Description:
6
6
  */
7
7
  // polyfill
@@ -13,6 +13,7 @@ import 'uno.css';
13
13
  import 'element-plus/dist/index.css';
14
14
 
15
15
  import { createApp } from 'vue';
16
+ import { server } from 'virtual:local-server';
16
17
  import App from './App.vue';
17
18
 
18
19
  (async () => {
@@ -23,9 +24,8 @@ import App from './App.vue';
23
24
  viteEnv = import.meta.env;
24
25
  console.log('🚀 ~ file: main.ts ~ line 19 ~ viteEnv', viteEnv);
25
26
  } else if (import.meta.env.DEV) {
26
- // 开发环境,内网其他设备访问请切换为局域网 ip
27
- // 端口号与环境变量的 SERVER_PORT 保持一致
28
- viteEnv = await (await fetch(`http://127.0.0.1:3000/get/env`)).json();
27
+ // 开发环境,局域网 ip
28
+ viteEnv = await (await fetch(server + '/get/env')).json();
29
29
  console.log('🚀 ~ file: main.ts ~ line 24 ~ viteEnv', viteEnv);
30
30
  } else {
31
31
  // 部署环境,需要配合 nginx 使用
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2022-03-01 19:40:13
4
- * @LastEditTime: 2023-01-09 09:19:41
4
+ * @LastEditTime: 2023-01-11 10:32:35
5
5
  * @Description: 权限校验
6
6
  */
7
7
  import { router } from './1-router';
@@ -84,7 +84,6 @@ export const install: UserModule = (app) => {
84
84
  (await casdoorLogin(code, state)) as UserKey;
85
85
  getToken() && (await generateNavData());
86
86
  location.search = '';
87
- changeTitle(to);
88
87
  return true;
89
88
  } else
90
89
  */
@@ -99,12 +98,10 @@ export const install: UserModule = (app) => {
99
98
  await generateNavData();
100
99
  if (hasPermission(to.meta.authPath)) {
101
100
  // 拥有对应页面的权限
102
- changeTitle(to);
103
101
  return true;
104
102
  }
105
103
  if (!hasPermission(to.meta.authPath)) {
106
104
  // 已登录,并且无权限
107
- changeTitle(from);
108
105
  return '/403';
109
106
  }
110
107
  } else {
@@ -117,6 +114,13 @@ export const install: UserModule = (app) => {
117
114
 
118
115
  router.afterEach((to) => {
119
116
  const { addView } = useTagsStore();
117
+ const nav = FlatNavArr.value.find((item) => item.component === to.path);
118
+ if (nav && nav.title) {
119
+ // console.log('before: ', to.meta);
120
+ to.meta.title = nav.title as string;
121
+ // console.log('after: ', to.meta);
122
+ }
120
123
  addView(to);
124
+ changeTitle(to);
121
125
  });
122
126
  };
@@ -0,0 +1,12 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-01-10 15:08:44
4
+ * @LastEditTime: 2023-01-10 15:08:44
5
+ * @Description:
6
+ */
7
+ declare module 'virtual:local-server' {
8
+ /**
9
+ * 本地服务地址
10
+ */
11
+ export const server: string;
12
+ }
@@ -5,5 +5,5 @@
5
5
  "moduleResolution": "Node",
6
6
  "allowSyntheticDefaultImports": true
7
7
  },
8
- "include": ["vite.config.ts"]
8
+ "include": ["vite.config.ts", "build/**/*.ts"]
9
9
  }
@@ -1,26 +1,13 @@
1
1
  /*
2
2
  * @Author: zhangyang
3
3
  * @Date: 2022-12-03 15:57:40
4
- * @LastEditTime: 2023-01-05 14:14:02
4
+ * @LastEditTime: 2023-01-10 15:12:20
5
5
  * @Description:
6
6
  */
7
7
  import { fileURLToPath, URL } from 'node:url';
8
8
  import { defineConfig, loadEnv } from 'vite';
9
9
  import type { ConfigEnv, UserConfigExport } from 'vite';
10
-
11
- import vue from '@vitejs/plugin-vue';
12
- import vueJsx from '@vitejs/plugin-vue-jsx';
13
- import legacy from '@vitejs/plugin-legacy';
14
- import Unocss from 'unocss/vite';
15
-
16
- // 自动导入
17
- import AutoImport from 'unplugin-auto-import/vite';
18
- import AutoComopnents from 'unplugin-vue-components/vite';
19
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
20
-
21
- // 自动路由及布局
22
- import Pages from 'vite-plugin-pages';
23
- import Layouts from 'vite-plugin-vue-layouts';
10
+ import { usePlugins, localServer } from './build';
24
11
 
25
12
  // https://vitejs.dev/config/
26
13
  export default ({ command, mode }: ConfigEnv): UserConfigExport => {
@@ -29,39 +16,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
29
16
  console.log('🚀 ~ file: vite.config.ts ~ line 36 ~ viteEnv', viteEnv);
30
17
  return defineConfig({
31
18
  base: './',
32
- plugins: [
33
- vue(),
34
- vueJsx(),
35
- Pages({
36
- extensions: ['vue', 'tsx'],
37
- dirs: 'src/views',
38
- exclude: ['**/components/*.{vue,tsx}', '_*'],
39
- }),
40
- Layouts({ defaultLayout: 'default/index' }),
41
- AutoComopnents({
42
- dirs: ['src/components'],
43
- dts: './src/auto-components.d.ts',
44
- extensions: ['vue', 'tsx'],
45
- resolvers: [ElementPlusResolver()],
46
- }),
47
- AutoImport({
48
- dts: './src/auto-imports.d.ts',
49
- imports: [
50
- 'vue',
51
- 'vue-router',
52
- '@vueuse/core',
53
- 'pinia',
54
- {
55
- 'element-plus': ['ElMessage', 'ElMessageBox', 'ElLoadingService'],
56
- },
57
- ],
58
- }),
59
- Unocss(),
60
- legacy({
61
- // 不生成同名 polyfill 文件,打包速度翻倍,如果出现兼容问题,可以删除此配置
62
- // renderLegacyChunks: false
63
- }),
64
- ],
19
+ plugins: usePlugins(),
65
20
  resolve: {
66
21
  alias: {
67
22
  '@': fileURLToPath(new URL('./src', import.meta.url)),
@@ -70,7 +25,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
70
25
  server: {
71
26
  host: true,
72
27
  proxy: {
73
- '/api': 'http://192.168.10.168:3000',
28
+ '/api': localServer,
74
29
  },
75
30
  },
76
31
  });