create-jnrs-template-vue 1.2.8 → 1.2.9

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.
package/README.md CHANGED
@@ -27,29 +27,30 @@ pnpm add create-jnrs-template-vue
27
27
  ## 📂 模板项目主要结构
28
28
  ```Text
29
29
  jnrs-template-vue/
30
- ├── dist/ # 打包构建产物
31
- ├── node_modules/ # 项目依赖
32
- ├── viteMockServe/ # Mock 服务配置(用于开发环境模拟 API)
30
+ ├── viteMockServe/ # Mock 服务配置
33
31
  ├── public/ # 静态资源
34
32
  ├── src/ # 源码目录
35
33
  │ ├── components/ # Vue 组件
36
34
  │ ├── composables/ # 组合式函数
35
+ │ ├── layout/ # 布局
37
36
  │ ├── views/ # 页面视图
38
37
  │ ├── router/ # 路由配置
38
+ │ ├── api/ # 接口定义(已含 request 实例)
39
+ │ ├── types/ # 类型定义
39
40
  │ ├── store/ # 状态管理
40
41
  │ ├── utils/ # 工具函数
42
+ │ ├── locales/ # 国际化
41
43
  │ └── main.ts # 应用入口
42
44
  ├── index.html # HTML 入口文件
43
45
  ├── eslint.config.js # ESLint 配置文件
44
- ├── package.json # 项目配置(依赖、脚本等)
46
+ ├── package.json # 包管理配置
45
47
  └── vite.config.ts # Vite 构建配置
46
48
  ├── tsconfig.json # TypeScript 配置
47
49
  ├── auto-imports.d.ts # 自动导入类型声明
48
50
  ├── components.d.ts # 全局组件类型声明
49
51
  ├── README.md # 项目文档
50
- ├── .env.example # 环境变量模板(供参考)
51
- ├── .env.development # 开发环境变量(全局)
52
- ├── .env.production # 生产环境变量(全局)
52
+ ├── .env.development # 开发环境变量
53
+ ├── .env.production # 生产环境变量
53
54
  ├── .gitignore # Git 忽略规则
54
55
  ├── .prettierrc.json # Prettier 格式化配置
55
56
  ```
@@ -24,7 +24,7 @@ jnrs-template-vue/
24
24
  │ ├── layout/ # 布局
25
25
  │ ├── views/ # 页面视图
26
26
  │ ├── router/ # 路由配置
27
- │ ├── api/ # 接口定义
27
+ │ ├── api/ # 接口定义(已含 request 实例)
28
28
  │ ├── types/ # 类型定义
29
29
  │ ├── store/ # 状态管理
30
30
  │ ├── utils/ # 工具函数
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jnrs-template-vue",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "JNRS 信息化管理系统",
5
5
  "author": "talia_tan",
6
6
  "private": true,
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@element-plus/icons-vue": "^2.3.2",
22
- "@jnrs/shared": "1.1.12",
22
+ "@jnrs/shared": "1.1.13",
23
23
  "@jnrs/vue-core": "1.2.9",
24
- "@jnrs/lingshu-smart": "2.2.3",
24
+ "@jnrs/lingshu-smart": "*",
25
25
  "@vueuse/core": "^14.1.0",
26
26
  "element-plus": "^2.13.3",
27
27
  "pinia": "^3.0.4",
@@ -1,4 +1,4 @@
1
- import { axiosRequest } from '@jnrs/vue-core/request'
1
+ import { axiosRequest } from '../request'
2
2
 
3
3
  /**
4
4
  * axios 方式下载文件
@@ -1,5 +1,5 @@
1
1
  import type { Pagination, PageTableData, FileContainer } from '@/types'
2
- import { axiosRequest } from '@jnrs/vue-core/request'
2
+ import { axiosRequest } from '../request'
3
3
  import { extractFieldId } from '@/utils/file'
4
4
  import { objectToFormData } from '@/utils/packages'
5
5
 
@@ -63,6 +63,17 @@ export const NotFoundApi = () => {
63
63
  })
64
64
  }
65
65
 
66
+ /**
67
+ * 测试 不需要权限
68
+ */
69
+ export const NoNeedAuthApi = () => {
70
+ return axiosRequest({
71
+ url: '/mock/auth/no',
72
+ method: 'post',
73
+ noAuth: true
74
+ })
75
+ }
76
+
66
77
  /**
67
78
  * 测试 无权限
68
79
  * @param showErrorMsg 是否显示错误信息
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @Author : TanRui
3
+ * @WeChat : Tan578853789
4
+ * @File : request.ts
5
+ * @Date : 2025/11/10
6
+ * @Desc. : axios 网络请求实例
7
+ */
8
+
9
+ import type { BusinessRequest, BusinessResponse } from '@jnrs/shared/request'
10
+ import { createAxiosInstance } from '@jnrs/shared/request'
11
+ import { useMockStore, useAuthStore } from '@jnrs/vue-core/pinia'
12
+ import { handleRouter } from '@jnrs/vue-core/router'
13
+ import { ElMessage } from 'element-plus'
14
+
15
+ const axiosInstance = createAxiosInstance({
16
+ // options: {
17
+ // noAuth: true // 全局设置为不需要权限
18
+ // },
19
+ handleMessageFn: ElMessage,
20
+ handleGetTokenFn: () => {
21
+ const { token } = useAuthStore()
22
+ return token
23
+ },
24
+ handleNoAuthFn: () => {
25
+ handleRouter({ name: 'Login' })
26
+ }
27
+ })
28
+
29
+ /**
30
+ * axios 请求方法(泛型拓展)
31
+ * @param options 请求配置项
32
+ * @returns Promise<T> 响应数据
33
+ */
34
+ const axiosRequest = <T = BusinessResponse>(options: BusinessRequest): Promise<T> => {
35
+ if (!axiosInstance) {
36
+ throw new Error('请先调用 createRequest 初始化 axios 实例')
37
+ }
38
+
39
+ // 如果是模拟请求,则将请求地址改为模拟地址
40
+ const { isMock } = useMockStore()
41
+
42
+ if (isMock) {
43
+ options.url = options.mockUrl
44
+ ? options.mockUrl
45
+ : options.url.startsWith('/mock')
46
+ ? options.url
47
+ : '/mock' + options.url
48
+ }
49
+
50
+ return axiosInstance(options)
51
+ }
52
+
53
+ export { axiosRequest }
@@ -1,6 +1,6 @@
1
1
  import type { Dict, DictItem, User, Role } from '@jnrs/shared'
2
2
  import type { MenuItem } from '@jnrs/vue-core'
3
- import { axiosRequest } from '@jnrs/vue-core/request'
3
+ import { axiosRequest } from '../request'
4
4
  import { objectToFormData } from '@/utils/packages'
5
5
 
6
6
  // 菜单
@@ -8,7 +8,8 @@ export const MenuApi = (): Promise<MenuItem[]> => {
8
8
  return axiosRequest({
9
9
  url: '/system/menu.json', // /public 文件夹下
10
10
  mockUrl: '/mock/menu',
11
- method: 'get'
11
+ method: 'get',
12
+ noAuth: true // 本地数据忽略 token 验证
12
13
  })
13
14
  }
14
15
 
@@ -1,4 +1,4 @@
1
- import { axiosRequest } from '@jnrs/vue-core/request'
1
+ import { axiosRequest } from '../request'
2
2
 
3
3
  // 获取用户信息
4
4
  export const UserApi = (id: string) => {
@@ -10,19 +10,6 @@ export const LAYOUT_NAME = 'Layout'
10
10
  export const GLOBAL_COMPONENT = import('@/layout/BlankLayout.vue')
11
11
 
12
12
  export const routes = [
13
- // {
14
- // path: '/login',
15
- // component: () => import('@/layout/BlankLayout.vue'),
16
- // meta: { title: '登录' },
17
- // children: [
18
- // {
19
- // path: '',
20
- // name: 'Login',
21
- // meta: { title: '登录', noAuth: true },
22
- // component: () => import('@/views/login/index.vue')
23
- // }
24
- // ]
25
- // },
26
13
  {
27
14
  name: '403',
28
15
  path: '/403',
@@ -94,9 +94,9 @@ const handleFileView = async () => {
94
94
  <p>网络请求测试</p>
95
95
  <el-button-group>
96
96
  <el-button type="success" size="small" @click="handleInfoApi">获取用户数据</el-button>
97
- <el-button type="primary" size="small" @click="handleNotFoundApi">404</el-button>
98
- <el-button type="primary" size="small" @click="handleNoAuth()">暂无权限</el-button>
99
- <el-button type="primary" size="small" @click="handleNoAuth(false)">暂无权限(不显示 Message)</el-button>
97
+ <el-button type="primary" size="small" @click="handleNotFoundApi">接口返回404</el-button>
98
+ <el-button type="primary" size="small" @click="handleNoAuth()">接口返回暂无权限</el-button>
99
+ <el-button type="primary" size="small" @click="handleNoAuth(false)">接口返回暂无权限(不显示 Message)</el-button>
100
100
  </el-button-group>
101
101
  <el-input v-model="loginParams.account" size="small" style="width: 200px">
102
102
  <template #append>
@@ -40,14 +40,15 @@ const submitForm = async () => {
40
40
  ruleFormRef.value.validate(async (valid) => {
41
41
  if (!valid) return
42
42
  loading.value = true
43
+
43
44
  try {
44
45
  const loginRes = await LoginApi(ruleForm.value)
45
46
  const { token, dict, ...restParameter } = loginRes
46
47
  const loginDateTime = formatDateTime() + ' ' + formatWeekday()
47
48
 
49
+ // 登录成功后,获取角色列表,将登录人角色对应的权限叠加给当前登录人(一次性获取叠加)
48
50
  let permissionsMerger = restParameter.permissions
49
51
  try {
50
- // 获取角色列表,将登录人角色对应的权限叠加给当前登录人(一次性获取叠加)
51
52
  const roleRes = await RoleApi()
52
53
  if (Array.isArray(restParameter.permissions)) {
53
54
  permissionsMerger = [
@@ -62,6 +63,7 @@ const submitForm = async () => {
62
63
  console.log(e)
63
64
  }
64
65
 
66
+ // 保存用户信息到全局状态
65
67
  setUserInfo({
66
68
  ...restParameter,
67
69
  permissions: permissionsMerger,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-jnrs-template-vue",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "巨能前端工程化开发,Vue 项目模板脚手架",
5
5
  "keywords": [
6
6
  "vue",