|
|
1 tydzień temu | |
|---|---|---|
| .idea | 2 tygodni temu | |
| .vscode | 2 tygodni temu | |
| cacp | 2 tygodni temu | |
| public | 1 tydzień temu | |
| src | 1 tydzień temu | |
| .env.development | 2 tygodni temu | |
| .env.production | 2 tygodni temu | |
| .gitignore | 2 tygodni temu | |
| .prettierrc.json | 2 tygodni temu | |
| Dockerfile | 2 tygodni temu | |
| Dockerfile-arm | 2 tygodni temu | |
| README.md | 2 tygodni temu | |
| env.d.ts | 2 tygodni temu | |
| eslint.config.js | 2 tygodni temu | |
| index.html | 2 tygodni temu | |
| nginx.conf | 2 tygodni temu | |
| node_version | 2 tygodni temu | |
| package-lock.json__ | 2 tygodni temu | |
| package.json | 1 tydzień temu | |
| tsconfig.app.json | 2 tygodni temu | |
| tsconfig.json | 2 tygodni temu | |
| tsconfig.node.json | 2 tygodni temu | |
| vite.config.ts | 1 tydzień temu | |
| yarn.lock | 1 tydzień temu |
|── public // 公共资源
│ ├── config.js // 项目部署后使用此配置,本地开发无需关注
│ ├── favicon.ico // 项目favicon小图标
├── src // 源代码
│ ├── apis // 所有 HTTP 请求
│ │ ├── user.ts //(根据业务模块命名,和 /views/* 一一对应)
│ │ ├── authority.ts // 根据用户获取角色与权限
│ │ ├── frame.ts // 获取用户信息
│ ├── assets // 图片样式等静态资源
| ├── components // 公共组件
| ├── directives // 通用指令封装
│ │ ├── index.ts // directives文件整合入口
│ │ ├── permission.ts // 校验页面功能权限方法
| ├── hooks // 公共方法封装
| ├── plugins // 插件配置
│ │ ├── index.ts // 插件文件整合入口
│ │ ├── icon.ts // cacp/svg-icons图标全局注册
│ ├── router // 路由
│ │ ├── app-router.ts // 根据项目大小调整,项目模块少可以集中在app-router.ts里面配置,反之(根据业务模块命名,和 /views/* 一一对应)
│ │ ├── index.ts // 路由入口
│ ├── stores // 全局 store 管理
│ │ ├── index.ts // store文件整合入口
│ │ ├── core.ts // 获取用户信息
│ │ ├── pinia.ts // pinia配置
│ ├── types // TS类型定义
│ │ ├── user.ts //(根据业务模块命名,和 /views/* 一一对应)
│ ├── utils // 全局公用方法
│ │ ├── authhelper.ts // 401报错消息发送给门户框架,以及框架处理
│ │ ├── frame.ts // 监听门户发送过来的用户信息消息,以及监听cookie消息
│ │ ├── http.ts // 调用不同应用接口服务,全url访问
│ │ ├── request.ts // 全局 http 请求方法封装,调用相同应用接口服务,相对路径
│ ├── views // 页面视图
│ │ ├── user // 响应路由切换的 vue 组件(根据业务模块命名,和 /apis/* 一一对应)
│ │ ├── ErrorView // 错误页面
│ │ ├── HomeView // 首页
│ ├── App.vue // 入口vue
│ ├── main.ts // vue 入口加载组件初始化等
│ ├── config.ts // 自定义配置,本地开发与后台接口联调参数配置
├── vite.config.ts // vite配置
├── .gitignore // 文件提交忽略配置
├── .prettierrc.json // 代码格式化配置
├── nginx.conf // ng配置,部署后生效
├── node_version // node版本设置,部署后生效
├── Dockerfile // 项目部署X86环境Dockerfile配置,部署后生效
├── Dockerfile-arm // 项目部署arm环境Dockerfile配置,部署后生效
└── package.json // 包配置
└── package-lock.json // 包下载地址,误删除tsf-consul-template-docker-x86.tar
└── tsf-consul-template-docker-x86.tar // X86环境tsf配置,部署后生效
└── tsf-consul-template-docker-arm.tar // arm环境tsf配置,部署后生效
根据项目实际需求开发修改以下文件:
src/apis/*src/assets/*src/components/*src/directives/*src/hooks/*src/plugins/*src/router/*src/stores/*src/types/*src/utils/*src/views/*src/App.vueconfig.ts/src/views文件夹下创建新的业务文件夹,根据业务模块添加user文件夹,相关功能页面全部写在该文件夹下,目录的层级不要太深,添加src/views/user/UserInfoView.vue
<template>
<div>
<h3>人员信息</h3>
<el-table :data="personArr">
<el-table-column label="编号" prop="id">
</el-table-column>
<el-table-column label="姓名" prop="name">
</el-table-column>
<el-table-column label="关区号" prop="customsCode">
</el-table-column>
</el-table>
</div>
</template>
<script setup lang="ts">
import { reactive } from 'vue'
import type { User } from '@/types/user'
const personArr = reactive<Array<User>>([
{ id: '1', name: '张三', customsCode: '4200', },
{ id: '2', name: '李四', customsCode: '5200', },
{ id: '3', name: '王五', customsCode: '0100', },
])
</script>
<style scoped lang="less">
</style>
src/router/app-router.ts
import type { RouteRecordRaw } from 'vue-router'
const routers: Array<RouteRecordRaw> = [
{
path: '/user-info',
name: 'userInfo',
component: () => import('@/views/user/UserInfoView.vue'),
meta: {
title: '用户信息',
anonymous: true,
keepAlive: true
}
},
]
export default routers
src/router/index.ts中。-), 不要使用下划线(_)。
import { createRouter, createWebHashHistory, RouterView } from 'vue-router'
import appRouter from './app-router'
const router = createRouter({
history: createWebHashHistory(),
routes: [
{
path: '/',
component: RouterView,
children: [
{
path: '/',
redirect: '/home'
},
{
path: 'home',
name: 'home',
component: () => import('@/views/HomeView.vue'),
meta: {
title: '首页',
anonymous: true,
keepAlive: true
}
},
...appRouter
]
}
]
})
// ...
src/App.vue,侧边栏导航只在开发环境展示;
// ...
<router-link to="/user-info">
<el-menu-item index="UserInfo">
<el-icon><House /></el-icon>
<span>用户信息</span>
</el-menu-item>
</router-link>
// ...
/src/apis下创建同views中一样的同名文件/src/apis/user.tsrequest(/src/utils/request.ts)和http(/src/utils/http.ts),采用axios的请求,增加了请求拦截和响应拦截,如果需要在请求前增加统一参数,或者响应时对数据统一处理可在此修改;
备注:request.ts调用相同应用接口服务,使用相对路径,http.ts调用不同应用接口服务,全url访问,使用绝对路径,使用场景前端与后端不是同一个服务;
import type { AxiosResponse } from 'axios'
import request from '@/utils/request'
import type { Result } from '@cacp/ui'
import type { Custom } from '@/types/user'
const contextPath = '/后端服务名'
// 关区翻译
export async function queryCustom(query: Array<String>): Promise<Result<Array<Custom>>> {
const res: AxiosResponse<Result<Array<Custom>>> = await request.post(`${contextPath}/customs/query-customs`, query)
return res.data
}
/src/views/user/UserInfoView.vue
<template>
<div>
<h3>人员信息</h3>
<el-table :data="personArr">
<el-table-column label="编号" prop="id">
</el-table-column>
<el-table-column label="姓名" prop="name">
</el-table-column>
<el-table-column label="关区号" prop="customsCode">
</el-table-column>
<el-table-column label="关区" prop="customsName">
</el-table-column>
</el-table>
</div>
</template>
<script setup lang="ts">
import { reactive } from 'vue'
import type { User, Custom } from '@/types/user'
import type { Result } from '@cacp/ui'
import * as userInfoApis from '@/apis/user'
const personArr = reactive<Array<User>>([
{ id: '1', name: '张三', customsCode: '4200', },
{ id: '2', name: '李四', customsCode: '5200', },
{ id: '3', name: '王五', customsCode: '0100', },
])
queryCustomInfo()
async function queryCustomInfo(): Promise<void> {
const customCodes: Array<string> = []
for (const preson of personArr) {
customCodes.push(preson.customsCode)
}
const res: Result<Array<Custom>> = await userInfoApis.queryCustom(customCodes)
if (res.code === SuccessResultCode) {
for (const preson of personArr) {
for (const custom of res.data) {
if (preson.customsCode === custom.code) {
preson.customsName = custom.name
}
}
}
}
}
</script>
<style scoped lang="less">
</style>
nginx.conf 进行配置,保持默认即可,配置代理到 API网关 上;
// ...
import type { CacpConfig } from '@cacp/ui'
const devConfig: CacpConfig = {
SERVICE_ID: 'demo',
SERVICE_NAME: 'Demo',
SERVICE_API: 'http://10.200.**.**:24001/', // 对应本地后台服务的ip+端口
SERVICE_PAGESIZE: 20,
SERVICE_TIMEOUT: 10000,
FRAME_API: 'http://app-api.dev-nb.com', // 指定环境api网关域名
NEED_USER_AUTHORITY: true
}
const $config = (window as any).$config as CacpConfig
const { DEV } = import.meta.env
export default DEV ? devConfig : $config
// ...
// ...
server: {
port: 8080,
// 是否自动在浏览器打开
open: true,
proxy: {
// 将'localhost:3000/api/服务名/接口名'代理到'http://10.200.**.**:24001/接口名'
'/api/后端服务名': {
target: 'http://10.200.**.**:24001/', // 对应本地后台服务的ip+端口
changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
rewrite: (path) => path.replace('/api/后端服务名', '') // 来重写地址,将前缀 '/api' 转为 '/'。
}
}
}
// ...
127.0.0.1 local.系统缩写-模块缩写.dev-nb.com,映射域名的二级域名需要与前端框架保持一致;
// ...
queryCustomInfo()
async function queryCustomInfo(): Promise<void> {
const customCodes: Array<string> = []
for (const preson of personArr) {
customCodes.push(preson.customsCode)
}
const res: Result<Array<Custom>> = await userInfoApis.queryCustom(customCodes)
console.log('res', res)
if (res.code === SuccessResultCode) {
for (const preson of personArr) {
for (const custom of res.data) {
if (preson.customsCode === custom.code) {
preson.customsName = custom.name
}
}
}
}
}
// ...