重构: 修复致命缺陷、清理死代码并打通类型检查与构建
本次优化在不改变业务行为的前提下,修复了多处会导致数据丢失或
功能失效的缺陷,并把此前从未跑过的类型检查与生产构建接通。
== 修复的严重缺陷 ==
服务端:
- dynamic/notice 路由在目标表缺失时用 `db.data = { dynamic: [] }`
整体替换数据库对象后落盘,会把 employee/Notice/qa 等全部业务表清空。
改为只创建缺失的那一张表。
- 列表接口在空表时访问 undefined.length 直接 500,统一补默认空数组。
- /api/employee/list 与 /login 明文返回 pwd 字段,且把含密码的
请求体写进日志。改为统一剔除敏感字段、移除参数日志。
- upd 允许请求体覆盖主键 id / createTime;改为服务端维护。
- upload 未限制扩展名与大小,且用原始扩展名拼路径。
前端:
- src/common/axios.ts 的拦截器注册在全局默认 axios 实例上,而业务
走 funjia-axios,导致拦截器全程失效;同时 funjia-axios 内部
`axios.prototype.error = () => {}` + `axios.prototype(msg)` 会抛
TypeError,使所有接口错误(含 401)被静默吞掉。现在本文件是唯一
的拦截器注册点。
- 修改密码功能形同虚设: PwdForm.onUpdate 只做 setTimeout 后 emit
成功,从不调接口;PwdDialog 又用已被拦截器解包掉的 status 判断
成败,无论结果都提示失败。
- Notice/Plugin 新增时 userId 静默丢失 (UmByClassEnhance 的
otherParams 只进 getList,不传 onAdd/onEdit),改用会话级
setCurrentUserId/getCurrentUserId。
- 修复 Login 模板绑定了从未定义的 loading、跳转到路由表里不存在
的路径;DynamicTable 里每次路由切换都触发的 debugger。
- 修复 Record/RecordUser 引用不存在的 marsLib/*、@/components/UmTable;
CodeMirror 使用 ref 却未 import; ImageCell 调用不存在的
getObjectTypeName。
== 结构优化 ==
- 新增 src/common/response.ts 与 BaseViewModel,收敛 7 个 viewModel
中重复 20+ 次的响应码判断与 CRUD 样板。
- 新增 server/routers/helpers.mjs,统一服务端取表/过滤/分页/脱敏。
- 新增 server/smoke-test.mjs,16 个用例覆盖上述修复(含整库清空回归)。
- 删除 0 引用的死文件: ImageList.vue、autoresponsive.vue、
animation.js、PwdDialog/PwdForm.vue。
== 工程配置 ==
- 修复阻塞安装与构建的三处错误:
funjiaui 指向不存在的仓库 FunjiaUI_Vue(#v1.1.3),实为
FunJiaUI_Vue_Package(#v1.3.1); pinia 锁 ~2.0.36 (vue 固定 3.2.33,
2.1+ 要求 vue ^3.3.0); App.vue 引用不存在的 funjiaui/dist/style.css,
实为包根目录 style.css。
- 新增 build/typecheck/build:only 脚本; 此前项目没有类型检查步骤。
- 移除 8 个未使用依赖,补齐 terser 与缺失的类型包。
- vite.config.ts 代理目标改由 .env 配置,移除硬编码内网地址;
增加 manualChunks 拆包。
- 服务端数据库改为不进版本库,提供 *.example.json 初始化模板。
== 验证 ==
- npx vue-tsc --noEmit : 0 错误
- npm run build : 成功 (1759 模块)
- cd server && npm run smoke : 16/16 通过
优化前的代码保留在 legacy 分支。
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# 接口代理目标(开发环境)。复制本文件为 .env.local 后按需修改。
|
||||
# 不配置时默认 http://localhost:4873/
|
||||
VITE_API_TARGET=http://localhost:4873/
|
||||
+28
-23
@@ -1,24 +1,29 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# 本地环境变量(接口代理地址等),不要提交
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -1,16 +1,75 @@
|
||||
# Vue 3 + TypeScript + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
|
||||
|
||||
## Type Support For `.vue` Imports in TS
|
||||
|
||||
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:
|
||||
|
||||
1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
|
||||
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
|
||||
|
||||
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
|
||||
# funjia-admin-template-vue
|
||||
|
||||
基于 Vue 3 + TypeScript + Vite 的后台管理模板,配套 Koa + lowdb 的轻量服务端。
|
||||
|
||||
- 前端:Vue 3.2 `<script setup>` + Element Plus 2.1 + Pinia + vue-router(hash 模式)
|
||||
- 表格/表单:内部组件库 `funjiaui` 的 **装饰器驱动** 模式(`@tcpd` / `@tfcpd` / `@tcmd` / `@tsfpd`)
|
||||
- 请求层:内部封装 `funjia-axios`(响应拦截器会直接解包 `response.data`)
|
||||
- 服务端:`funjia-server` + Koa,数据落在 `server/db/*.json`(lowdb)
|
||||
|
||||
## 快速开始
|
||||
|
||||
```bash
|
||||
# 前端
|
||||
npm install
|
||||
npm run dev # http://localhost:4444
|
||||
|
||||
# 服务端(另开一个终端)
|
||||
cd server
|
||||
npm install
|
||||
node index.mjs # 监听 4873
|
||||
```
|
||||
|
||||
开发环境默认把 `/api`、`/static` 等前缀代理到 `http://localhost:4873/`。
|
||||
如需改动,复制 `.env.example` 为 `.env.local` 并修改 `VITE_API_TARGET`。
|
||||
|
||||
## 校验命令
|
||||
|
||||
```bash
|
||||
npm run typecheck # vue-tsc 类型检查
|
||||
npm run build # 类型检查 + 生产构建(vite build)
|
||||
npm run build:only # 仅构建,跳过类型检查
|
||||
|
||||
cd server && npm run smoke # 服务端路由烟雾测试(16 个用例)
|
||||
```
|
||||
|
||||
## 依赖说明(重要)
|
||||
|
||||
三个内部包通过 git 依赖引入。**它们的地址必须与 Gitea 上的仓库名完全一致**:
|
||||
|
||||
| 包名 | 仓库 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `funjiaui` | `funjia/FunJiaUI_Vue_Package` | 组件库,样式在包根目录 `style.css`(**不是** `dist/style.css`) |
|
||||
| `funjia-axios` | `funjia/funjia-axios` | 请求封装。`main` 直接指向未编译的 `index.ts` |
|
||||
| `funjialib` | `funjia/FunJiaLib_Package` | 工具库。按子路径引用,如 `funjialib/date` |
|
||||
|
||||
需要注意的坑:
|
||||
|
||||
1. **仓库名大小写敏感**。历史配置里写成 `FunjiaUI_Vue`(且引用 `#v1.1.3`),
|
||||
该仓库与 tag 均不存在,`npm install` 会在 git 认证环节长时间静默卡住而不报错。
|
||||
2. **`pinia` 需锁定 `~2.0.36`**。`vue` 固定在 `3.2.33`,而 `pinia >= 2.1.7`
|
||||
要求 `vue ^3.3.0`,升级会触发 ERESOLVE。
|
||||
3. `funjia-axios` 的类型由本项目 `src/type/funjia-axios.d.ts` 提供
|
||||
(上游源码存在 TS7006 且无法解析自身依赖,详见该文件注释)。
|
||||
|
||||
## 服务端数据库
|
||||
|
||||
`server/db/` 下的真实数据文件(`db.json` 等)**不进版本库**,已加入 `.gitignore`。
|
||||
首次部署时用示例库初始化:
|
||||
|
||||
```bash
|
||||
cd server
|
||||
cp db/db.example.json db/db.json
|
||||
cp db/logDB.example.json db/logDB.json
|
||||
cp db/resourceDB.example.json db/resourceDB.json
|
||||
cp db/backupDB.example.json db/backupDB.json
|
||||
```
|
||||
|
||||
服务端配置同理,从 `config.example.yml` 复制为 `config.yml`。
|
||||
|
||||
## 推荐的 IDE 配置
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||
|
||||
`.vue` 文件在 TS 中默认只能拿到通用组件类型。若需要真实的 props 类型推断,
|
||||
可按 Volar 的文档启用 Take Over 模式。
|
||||
|
||||
Vendored
+49
-1
@@ -1,6 +1,54 @@
|
||||
// Generated by 'unplugin-auto-import'
|
||||
// We suggest you to commit this file into source control
|
||||
declare global {
|
||||
|
||||
const computed: typeof import('vue')['computed']
|
||||
const createApp: typeof import('vue')['createApp']
|
||||
const customRef: typeof import('vue')['customRef']
|
||||
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
||||
const defineComponent: typeof import('vue')['defineComponent']
|
||||
const effectScope: typeof import('vue')['effectScope']
|
||||
const EffectScope: typeof import('vue')['EffectScope']
|
||||
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
||||
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
||||
const h: typeof import('vue')['h']
|
||||
const inject: typeof import('vue')['inject']
|
||||
const isReadonly: typeof import('vue')['isReadonly']
|
||||
const isRef: typeof import('vue')['isRef']
|
||||
const markRaw: typeof import('vue')['markRaw']
|
||||
const nextTick: typeof import('vue')['nextTick']
|
||||
const onActivated: typeof import('vue')['onActivated']
|
||||
const onBeforeMount: typeof import('vue')['onBeforeMount']
|
||||
const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
|
||||
const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
|
||||
const onDeactivated: typeof import('vue')['onDeactivated']
|
||||
const onErrorCaptured: typeof import('vue')['onErrorCaptured']
|
||||
const onMounted: typeof import('vue')['onMounted']
|
||||
const onRenderTracked: typeof import('vue')['onRenderTracked']
|
||||
const onRenderTriggered: typeof import('vue')['onRenderTriggered']
|
||||
const onScopeDispose: typeof import('vue')['onScopeDispose']
|
||||
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
|
||||
const onUnmounted: typeof import('vue')['onUnmounted']
|
||||
const onUpdated: typeof import('vue')['onUpdated']
|
||||
const provide: typeof import('vue')['provide']
|
||||
const reactive: typeof import('vue')['reactive']
|
||||
const readonly: typeof import('vue')['readonly']
|
||||
const ref: typeof import('vue')['ref']
|
||||
const resolveComponent: typeof import('vue')['resolveComponent']
|
||||
const shallowReactive: typeof import('vue')['shallowReactive']
|
||||
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
||||
const shallowRef: typeof import('vue')['shallowRef']
|
||||
const toRaw: typeof import('vue')['toRaw']
|
||||
const toRef: typeof import('vue')['toRef']
|
||||
const toRefs: typeof import('vue')['toRefs']
|
||||
const triggerRef: typeof import('vue')['triggerRef']
|
||||
const unref: typeof import('vue')['unref']
|
||||
const useAttrs: typeof import('vue')['useAttrs']
|
||||
const useCssModule: typeof import('vue')['useCssModule']
|
||||
const useCssVars: typeof import('vue')['useCssVars']
|
||||
const useRoute: typeof import('vue-router')['useRoute']
|
||||
const useRouter: typeof import('vue-router')['useRouter']
|
||||
const useSlots: typeof import('vue')['useSlots']
|
||||
const watch: typeof import('vue')['watch']
|
||||
const watchEffect: typeof import('vue')['watchEffect']
|
||||
}
|
||||
export {}
|
||||
|
||||
Vendored
-3
@@ -6,7 +6,6 @@ import '@vue/runtime-core'
|
||||
declare module '@vue/runtime-core' {
|
||||
export interface GlobalComponents {
|
||||
Angle: typeof import('./src/components/Angle.vue')['default']
|
||||
Autoresponsive: typeof import('./src/components/autoresponsive.vue')['default']
|
||||
CalcRectDock: typeof import('./src/components/CalcRectDock.vue')['default']
|
||||
CodeMirror: typeof import('./src/components/CodeMirror.vue')['default']
|
||||
CountDownMessage: typeof import('./src/components/CountDownMessage.vue')['default']
|
||||
@@ -23,8 +22,6 @@ declare module '@vue/runtime-core' {
|
||||
ElLink: typeof import('element-plus/es')['ElLink']
|
||||
ElMenu: typeof import('element-plus/es')['ElMenu']
|
||||
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
||||
ElRow: typeof import('element-plus/es')['ElRow']
|
||||
ElTag: typeof import('element-plus/es')['ElTag']
|
||||
ImgPreview: typeof import('./src/components/ImgPreview.vue')['default']
|
||||
|
||||
+17
-16
@@ -1,16 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>‎</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<!-- 原为不可见的 ‎ 占位符,改为真实标题;运行时会由数据字典中的系统名覆盖 -->
|
||||
<title>后台管理系统</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
Generated
+2486
-3459
File diff suppressed because it is too large
Load Diff
+46
-50
@@ -1,50 +1,46 @@
|
||||
{
|
||||
"name": "funjia-admin-template-vue",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "vite --port=4444",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview --port=4444"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/lang-javascript": "^6.1.7",
|
||||
"@kousum/vue3-window": "^0.0.3",
|
||||
"@types/axios": "^0.14.0",
|
||||
"@types/js-cookie": "^3.0.1",
|
||||
"autoresponsive-vue3": "^2.0.4",
|
||||
"axios": "^0.26.1",
|
||||
"codemirror": "^6.0.1",
|
||||
"dayjs": "^1.10.7",
|
||||
"element-plus": "2.1.10",
|
||||
"funjialib": "git+http://git.funjia.top/funjia/FunJiaLib_Package.git",
|
||||
"funjiaui": "git+http://git.funjia.top/funjia/FunjiaUI_Vue.git#v1.1.3",
|
||||
"funjia-axios": "git+http://git.funjia.top/funjia/funjia-axios.git#v1.0.0",
|
||||
"html-print-element": "^0.0.5",
|
||||
"html2pdf.js": "^0.10.2",
|
||||
"js-cookie": "^3.0.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
"md5": "^2.3.0",
|
||||
"pinia": "2.0.13",
|
||||
"printd": "^1.6.0",
|
||||
"react-dnd-html5-backend": "^16.0.1",
|
||||
"vue": "3.2.33",
|
||||
"vue-codemirror": "^6.1.1",
|
||||
"vue-cropperjs": "^5.0.0",
|
||||
"vue-router": "^4.0.14",
|
||||
"vue3-dnd": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.6",
|
||||
"@types/node": "^17.0.25",
|
||||
"@vitejs/plugin-vue": "^2.3.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sass": "^1.50.1",
|
||||
"typescript": "^4.5.4",
|
||||
"unplugin-auto-import": "^0.7.1",
|
||||
"unplugin-element-plus": "^0.4.0",
|
||||
"unplugin-vue-components": "^0.19.3",
|
||||
"vite": "^2.9.5",
|
||||
"vue-tsc": "^0.34.7"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "funjia-admin-template-vue",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --port=4444",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"build:only": "vite build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"preview": "vite preview --port=4444"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/lang-javascript": "^6.1.7",
|
||||
"axios": "^0.26.1",
|
||||
"codemirror": "^6.0.1",
|
||||
"element-plus": "2.1.10",
|
||||
"funjia-axios": "git+http://git.funjia.top/funjia/funjia-axios.git#v1.0.0",
|
||||
"funjialib": "git+http://git.funjia.top/funjia/FunJiaLib_Package.git",
|
||||
"funjiaui": "git+http://git.funjia.top/funjia/FunJiaUI_Vue_Package.git#v1.3.1",
|
||||
"js-cookie": "^3.0.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
"md5": "^2.3.0",
|
||||
"pinia": "~2.0.36",
|
||||
"vue": "3.2.33",
|
||||
"vue-codemirror": "^6.1.1",
|
||||
"vue-cropperjs": "^5.0.0",
|
||||
"vue-router": "^4.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-cookie": "^3.0.1",
|
||||
"@types/lodash-es": "^4.17.6",
|
||||
"@types/md5": "^2.3.2",
|
||||
"@types/node": "^17.0.25",
|
||||
"@vitejs/plugin-vue": "^2.3.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sass": "^1.50.1",
|
||||
"terser": "^5.16.0",
|
||||
"typescript": "^4.5.4",
|
||||
"unplugin-auto-import": "^0.7.1",
|
||||
"unplugin-element-plus": "^0.4.0",
|
||||
"unplugin-vue-components": "^0.19.3",
|
||||
"vite": "^2.9.5",
|
||||
"vue-tsc": "^0.34.7"
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,2 +1,12 @@
|
||||
static/*
|
||||
config.yml
|
||||
# 上传文件目录
|
||||
static/*
|
||||
|
||||
# 本地配置(含绝对路径、备份目标等,不应提交)
|
||||
config.yml
|
||||
|
||||
# 运行期数据库。示例库可用 db/*.example.json 初始化,
|
||||
# 真实数据由部署环境自带,不进版本库
|
||||
db/db.json
|
||||
db/logDB.json
|
||||
db/resourceDB.json
|
||||
db/backupDB.json
|
||||
|
||||
+24
-22
@@ -1,22 +1,24 @@
|
||||
db: # 数据库配置
|
||||
db: &db E:\sourceCode\2025\funjia-admin-template-vue\server\db\db.json
|
||||
resourceDB: &resourceDB E:\sourceCode\2025\funjia-admin-template-vue\server\db\resourceDB.json
|
||||
backupDB: &backupDB E:\sourceCode\2025\funjia-admin-template-vue\server\db\backupDB.json
|
||||
logDB: &logDB E:\sourceCode\2025\funjia-admin-template-vue\server\db\logDB.json
|
||||
dbBak: # 数据库备份配置
|
||||
- #
|
||||
original: *db
|
||||
dest: F:/sourceCode/2022/compute-cms/bak/db
|
||||
category: db
|
||||
- #
|
||||
original: *resourceDB
|
||||
dest: F:/sourceCode/2022/compute-cms/bak/resourceDB
|
||||
category: resourceDB
|
||||
- #
|
||||
original: *backupDB
|
||||
dest: F:/sourceCode/2022/compute-cms/bak/backupDB
|
||||
category: backupDB
|
||||
- #
|
||||
original: *logDB
|
||||
dest: F:/sourceCode/2022/compute-cms/bak/logDB
|
||||
category: logDB
|
||||
# 数据库配置
|
||||
# 说明:改造前这里写死了开发机的绝对路径(E:\sourceCode\... / F:\sourceCode\...),
|
||||
# 换一台机器就必须手工修改。现在改为相对路径,也可以由部署环境覆盖。
|
||||
|
||||
db:
|
||||
db: &db ./db/db.json
|
||||
resourceDB: &resourceDB ./db/resourceDB.json
|
||||
backupDB: &backupDB ./db/backupDB.json
|
||||
logDB: &logDB ./db/logDB.json
|
||||
|
||||
# 数据库备份配置(可选)。dest 建议指向项目外或已挂载的备份盘。
|
||||
dbBak: []
|
||||
# - original: *db
|
||||
# dest: ./bak/db
|
||||
# category: db
|
||||
# - original: *resourceDB
|
||||
# dest: ./bak/resourceDB
|
||||
# category: resourceDB
|
||||
# - original: *backupDB
|
||||
# dest: ./bak/backupDB
|
||||
# category: backupDB
|
||||
# - original: *logDB
|
||||
# dest: ./bak/logDB
|
||||
# category: logDB
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"backupHistory": []
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
{
|
||||
"backupHistory": [
|
||||
{
|
||||
"name": "db20220701112510.json",
|
||||
"category": "db",
|
||||
"id": "cl51w799y00003cny7rm01lx4",
|
||||
"createTime": "2022-07-01T03:25:10.198Z",
|
||||
"status": "1,2"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112510.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w79f900033cnyd44c044t",
|
||||
"createTime": "2022-07-01T03:25:10.389Z",
|
||||
"status": "1,2"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112510.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w79ia00063cny0hty82gs",
|
||||
"createTime": "2022-07-01T03:25:10.499Z",
|
||||
"status": "1,2"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112510.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w79lc00093cny9oiz4tlh",
|
||||
"createTime": "2022-07-01T03:25:10.608Z",
|
||||
"status": "1,2"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112520.json",
|
||||
"category": "db",
|
||||
"id": "cl51w7h1n000c3cnyhpfjbrpj",
|
||||
"createTime": "2022-07-01T03:25:20.267Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112520.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w7h4o000f3cnybldh5115",
|
||||
"createTime": "2022-07-01T03:25:20.376Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112520.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w7h7w000i3cnyafqk3p1o",
|
||||
"createTime": "2022-07-01T03:25:20.492Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112520.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w7haw000l3cny4nv48t44",
|
||||
"createTime": "2022-07-01T03:25:20.600Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112530.json",
|
||||
"category": "db",
|
||||
"id": "cl51w7oty000o3cny5v281zy3",
|
||||
"createTime": "2022-07-01T03:25:30.358Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112530.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w7owz000r3cnybuil0qm8",
|
||||
"createTime": "2022-07-01T03:25:30.467Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112530.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w7p0e000u3cnyg8r9by1q",
|
||||
"createTime": "2022-07-01T03:25:30.590Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112530.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w7p37000x3cny9be2eh4h",
|
||||
"createTime": "2022-07-01T03:25:30.691Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112540.json",
|
||||
"category": "db",
|
||||
"id": "cl51w7wlu00103cny65nw72bm",
|
||||
"createTime": "2022-07-01T03:25:40.434Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112540.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w7wom00133cnyg0nqc9w3",
|
||||
"createTime": "2022-07-01T03:25:40.534Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112540.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w7wrd00163cnydmnjcgw7",
|
||||
"createTime": "2022-07-01T03:25:40.633Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112540.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w7wuk00193cny8hwlcc89",
|
||||
"createTime": "2022-07-01T03:25:40.748Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112550.json",
|
||||
"category": "db",
|
||||
"id": "cl51w84dz001c3cnygo6oeal7",
|
||||
"createTime": "2022-07-01T03:25:50.519Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112550.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w84h0001f3cnyfahs5q4c",
|
||||
"createTime": "2022-07-01T03:25:50.628Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112550.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w84jm001i3cny2tpqcjjp",
|
||||
"createTime": "2022-07-01T03:25:50.722Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112550.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w84ml001l3cnygzl3hjod",
|
||||
"createTime": "2022-07-01T03:25:50.829Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112600.json",
|
||||
"category": "db",
|
||||
"id": "cl51w8c63001o3cnyfevk3kyp",
|
||||
"createTime": "2022-07-01T03:26:00.603Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112600.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w8c8m001r3cny9zryh2pe",
|
||||
"createTime": "2022-07-01T03:26:00.694Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112600.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w8cbo001u3cnya2bw2bsi",
|
||||
"createTime": "2022-07-01T03:26:00.804Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112600.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w8ce8001x3cny1cltcbdh",
|
||||
"createTime": "2022-07-01T03:26:00.896Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112610.json",
|
||||
"category": "db",
|
||||
"id": "cl51w8jxq00203cny392bhx57",
|
||||
"createTime": "2022-07-01T03:26:10.670Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112610.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w8k0n00233cny37f0cx5j",
|
||||
"createTime": "2022-07-01T03:26:10.775Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112610.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w8k3h00263cnydfiu8inf",
|
||||
"createTime": "2022-07-01T03:26:10.877Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112610.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w8k6n00293cny0j395r0p",
|
||||
"createTime": "2022-07-01T03:26:10.991Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220701112620.json",
|
||||
"category": "db",
|
||||
"id": "cl51w8rq0002c3cny2tih0ehp",
|
||||
"createTime": "2022-07-01T03:26:20.760Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220701112620.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl51w8rv2002f3cnyddcya1y9",
|
||||
"createTime": "2022-07-01T03:26:20.942Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220701112621.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl51w8rz2002i3cnyhsiihd6x",
|
||||
"createTime": "2022-07-01T03:26:21.086Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220701112621.json",
|
||||
"category": "logDB",
|
||||
"id": "cl51w8s5u002l3cny2o7m161c",
|
||||
"createTime": "2022-07-01T03:26:21.330Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "F:\\sourceCode\\2022\\compute-cms\\db20220703182610.json",
|
||||
"category": "db",
|
||||
"id": "cl5564dxd0000sonyakfraso1",
|
||||
"createTime": "2022-07-03T10:26:10.945Z"
|
||||
},
|
||||
{
|
||||
"name": "db20220703182700.json",
|
||||
"category": "db",
|
||||
"id": "cl5565fxt0000s0ny94tvajvl",
|
||||
"createTime": "2022-07-03T10:27:00.209Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220703182700.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl5565g3o0003s0nyhl4m51nu",
|
||||
"createTime": "2022-07-03T10:27:00.420Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220703182700.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl5565g7t0006s0ny2juo1ve3",
|
||||
"createTime": "2022-07-03T10:27:00.570Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220703182700.json",
|
||||
"category": "logDB",
|
||||
"id": "cl5565gas0009s0nyfyi71i0a",
|
||||
"createTime": "2022-07-03T10:27:00.676Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220703182710.json",
|
||||
"category": "db",
|
||||
"id": "cl5565npe000cs0ny4jmk13uj",
|
||||
"createTime": "2022-07-03T10:27:10.274Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220703182710.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl5565num000fs0nyfuynhsvn",
|
||||
"createTime": "2022-07-03T10:27:10.462Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220703182710.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl5565nxt000is0nyfaw54i99",
|
||||
"createTime": "2022-07-03T10:27:10.578Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220703182710.json",
|
||||
"category": "logDB",
|
||||
"id": "cl5565o0q000ls0ny49na7htm",
|
||||
"createTime": "2022-07-03T10:27:10.682Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220703182720.json",
|
||||
"category": "db",
|
||||
"id": "cl5565vh5000os0ny8q5l2dhe",
|
||||
"createTime": "2022-07-03T10:27:20.346Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220703182720.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl5565vlh000rs0ny6nvm1t28",
|
||||
"createTime": "2022-07-03T10:27:20.501Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220703182720.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl5565vpg000us0nyhchjafdx",
|
||||
"createTime": "2022-07-03T10:27:20.644Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220703182720.json",
|
||||
"category": "logDB",
|
||||
"id": "cl5565vs9000xs0nybt568rnh",
|
||||
"createTime": "2022-07-03T10:27:20.745Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "db20220703182730.json",
|
||||
"category": "db",
|
||||
"id": "cl556638l0010s0ny42h7beca",
|
||||
"createTime": "2022-07-03T10:27:30.405Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "resourceDB20220703182730.json",
|
||||
"category": "resourceDB",
|
||||
"id": "cl55663c00013s0nyefkb8ozn",
|
||||
"createTime": "2022-07-03T10:27:30.528Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "backupDB20220703182730.json",
|
||||
"category": "backupDB",
|
||||
"id": "cl55663f50016s0nyhmal0v7o",
|
||||
"createTime": "2022-07-03T10:27:30.641Z",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"name": "logDB20220703182730.json",
|
||||
"category": "logDB",
|
||||
"id": "cl55663i50019s0nydmqjhwqr",
|
||||
"createTime": "2022-07-03T10:27:30.749Z",
|
||||
"status": "1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"employee": [],
|
||||
"travelInformation": [],
|
||||
"Notice": [],
|
||||
"leaseRecords": [],
|
||||
"configurationList": [],
|
||||
"subOrder": [],
|
||||
"qa": [],
|
||||
"tag": [],
|
||||
"record": [],
|
||||
"dataDict": [],
|
||||
"recordUser": [],
|
||||
"plugin": []
|
||||
}
|
||||
-21146
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"dataLog": []
|
||||
}
|
||||
-72195
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"img": []
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
{
|
||||
"img": [
|
||||
{
|
||||
"id": "cl4u5pghi0001wgny53o32aq4",
|
||||
"filename": "cl4u5pgh40000wgnya0lp59uc.jpg",
|
||||
"path": "static\\cl4u5pgh40000wgnya0lp59uc.jpg",
|
||||
"createTime": "2022-06-25T17:29:06.486Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u68rlb0001qcnygmv39izm",
|
||||
"filename": "cl4u68rl60000qcny6npk19d3.jpg",
|
||||
"path": "static\\cl4u68rl60000qcny6npk19d3.jpg",
|
||||
"createTime": "2022-06-25T17:44:07.343Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u692vx0003qcnyaiip9dnn",
|
||||
"filename": "cl4u692vq0002qcny9bmj3q30.jpg",
|
||||
"path": "static\\cl4u692vq0002qcny9bmj3q30.jpg",
|
||||
"createTime": "2022-06-25T17:44:21.981Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u6agif0005qcny0kd1659n",
|
||||
"filename": "cl4u6agib0004qcnyexnb9xzz.jpg",
|
||||
"path": "static\\cl4u6agib0004qcnyexnb9xzz.jpg",
|
||||
"createTime": "2022-06-25T17:45:26.295Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u6ls550001ucnyhy6ghpwy",
|
||||
"filename": "cl4u6ls4r0000ucny86k414pr.jpg",
|
||||
"path": "static\\cl4u6ls4r0000ucny86k414pr.jpg",
|
||||
"createTime": "2022-06-25T17:54:14.585Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u6mmog0003ucnyato6b8qd",
|
||||
"filename": "cl4u6mmoc0002ucny0eaa8t7f.jpg",
|
||||
"path": "static\\cl4u6mmoc0002ucny0eaa8t7f.jpg",
|
||||
"createTime": "2022-06-25T17:54:54.160Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u7huus0001x4nyalm386vp",
|
||||
"filename": "cl4u7huui0000x4ny1rd095z4.jpg",
|
||||
"path": "static\\cl4u7huui0000x4ny1rd095z4.jpg",
|
||||
"createTime": "2022-06-25T18:19:11.092Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4u7jyqy0003x4nyaa2mhk1a",
|
||||
"filename": "cl4u7jyqv0002x4ny27cb0zyt.jpg",
|
||||
"path": "static\\cl4u7jyqv0002x4ny27cb0zyt.jpg",
|
||||
"createTime": "2022-06-25T18:20:49.450Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4uycgv80005x4nycnn4ahui",
|
||||
"filename": "cl4uycgv30004x4ny4k9a0987.jpg",
|
||||
"path": "static\\cl4uycgv30004x4ny4k9a0987.jpg",
|
||||
"createTime": "2022-06-26T06:50:49.316Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0kl5h000rx4nydmi0gnhl",
|
||||
"filename": "cl4v0kl59000qx4ny0xsx9j2n.jpg",
|
||||
"path": "static\\cl4v0kl59000qx4ny0xsx9j2n.jpg",
|
||||
"createTime": "2022-06-26T07:53:07.349Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0lgm3000tx4ny7i4xdeq4",
|
||||
"filename": "cl4v0lglz000sx4ny17in7q6a.jpg",
|
||||
"path": "static\\cl4v0lglz000sx4ny17in7q6a.jpg",
|
||||
"createTime": "2022-06-26T07:53:48.123Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0m2wm000vx4nye3kl2794",
|
||||
"filename": "cl4v0m2wi000ux4nyhb7xaykl.jpg",
|
||||
"path": "static\\cl4v0m2wi000ux4nyhb7xaykl.jpg",
|
||||
"createTime": "2022-06-26T07:54:17.014Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0mdjv000xx4nycqqngyjr",
|
||||
"filename": "cl4v0mdjl000wx4ny6d4acii7.jpg",
|
||||
"path": "static\\cl4v0mdjl000wx4ny6d4acii7.jpg",
|
||||
"createTime": "2022-06-26T07:54:30.811Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0mzlq000zx4ny37649xm3",
|
||||
"filename": "cl4v0mzlm000yx4nyhjcwdmwb.jpg",
|
||||
"path": "static\\cl4v0mzlm000yx4nyhjcwdmwb.jpg",
|
||||
"createTime": "2022-06-26T07:54:59.390Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0nf8t0011x4ny3vgb0njg",
|
||||
"filename": "cl4v0nf8p0010x4ny1q8o96bb.jpg",
|
||||
"path": "static\\cl4v0nf8p0010x4ny1q8o96bb.jpg",
|
||||
"createTime": "2022-06-26T07:55:19.661Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0q7mv0013x4nybkoy3z9b",
|
||||
"filename": "cl4v0q7ms0012x4ny29i1hy0d.jpg",
|
||||
"path": "static\\cl4v0q7ms0012x4ny29i1hy0d.jpg",
|
||||
"createTime": "2022-06-26T07:57:29.767Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0qaxk0015x4nyc61xhnsk",
|
||||
"filename": "cl4v0qaxi0014x4nyd02n1y0s.jpg",
|
||||
"path": "static\\cl4v0qaxi0014x4nyd02n1y0s.jpg",
|
||||
"createTime": "2022-06-26T07:57:34.040Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0qrtf0017x4ny1y0t0wam",
|
||||
"filename": "cl4v0qrtc0016x4ny1bxh12e8.jpg",
|
||||
"path": "static\\cl4v0qrtc0016x4ny1bxh12e8.jpg",
|
||||
"createTime": "2022-06-26T07:57:55.923Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0s7m10019x4ny5zta50b4",
|
||||
"filename": "cl4v0s7lv0018x4nybu4u9qrp.jpg",
|
||||
"path": "static\\cl4v0s7lv0018x4nybu4u9qrp.jpg",
|
||||
"createTime": "2022-06-26T07:59:03.049Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v0uvxk001bx4ny2qe0c22r",
|
||||
"filename": "cl4v0uvxi001ax4ny0itgd8j9.jpg",
|
||||
"path": "static\\cl4v0uvxi001ax4ny0itgd8j9.jpg",
|
||||
"createTime": "2022-06-26T08:01:07.880Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v18kp9001dx4nya6yhb8yy",
|
||||
"filename": "cl4v18kp6001cx4nyg3xoh7kn.jpg",
|
||||
"path": "static\\cl4v18kp6001cx4nyg3xoh7kn.jpg",
|
||||
"createTime": "2022-06-26T08:11:46.509Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v18mxi001fx4nyc6h2fozb",
|
||||
"filename": "cl4v18mxe001ex4ny8147ehkt.jpg",
|
||||
"path": "static\\cl4v18mxe001ex4ny8147ehkt.jpg",
|
||||
"createTime": "2022-06-26T08:11:49.398Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4v18pi9001hx4ny7idea4m5",
|
||||
"filename": "cl4v18pi3001gx4nyazt40dus.jpg",
|
||||
"path": "static\\cl4v18pi3001gx4nyazt40dus.jpg",
|
||||
"createTime": "2022-06-26T08:11:52.737Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4wq1ywm0001a0ny38cmcwa2",
|
||||
"filename": "cl4wq1ywc0000a0ny2y25e0fa.jpg",
|
||||
"path": "static\\cl4wq1ywc0000a0ny2y25e0fa.jpg",
|
||||
"createTime": "2022-06-27T12:34:14.902Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4wq21w30003a0ny9xpd62rv",
|
||||
"filename": "cl4wq21vu0002a0ny07359nx6.jpg",
|
||||
"path": "static\\cl4wq21vu0002a0ny07359nx6.jpg",
|
||||
"createTime": "2022-06-27T12:34:18.771Z"
|
||||
},
|
||||
{
|
||||
"id": "cl4wq28rv0005a0nycf7k2a34",
|
||||
"filename": "cl4wq28rt0004a0ny5nj4gbe2.jpg",
|
||||
"path": "static\\cl4wq28rt0004a0ny5nj4gbe2.jpg",
|
||||
"createTime": "2022-06-27T12:34:27.691Z"
|
||||
},
|
||||
{
|
||||
"id": "cl550ghgz0009lsnycaace5r1",
|
||||
"filename": "cl550ghgt0008lsnyc7jl7rhw.jpg",
|
||||
"path": "static\\cl550ghgt0008lsnyc7jl7rhw.jpg",
|
||||
"createTime": "2022-07-03T07:47:37.715Z"
|
||||
},
|
||||
{
|
||||
"id": "cl550gk3n000blsnybbxz3rru",
|
||||
"filename": "cl550gk3e000alsnyafhcc8b2.jpg",
|
||||
"path": "static\\cl550gk3e000alsnyafhcc8b2.jpg",
|
||||
"createTime": "2022-07-03T07:47:41.123Z"
|
||||
},
|
||||
{
|
||||
"id": "cl550gmhr000dlsny9oxxex2y",
|
||||
"filename": "cl550gmhf000clsny2c4h5a33.jpg",
|
||||
"path": "static\\cl550gmhf000clsny2c4h5a33.jpg",
|
||||
"createTime": "2022-07-03T07:47:44.223Z"
|
||||
},
|
||||
{
|
||||
"id": "clzwtwwmp00029grb63lr3hcq",
|
||||
"filename": "clzwtwwml00019grbfbsf6r72.viminfo",
|
||||
"path": "static\\clzwtwwml00019grbfbsf6r72.viminfo",
|
||||
"createTime": "2024-08-16T14:53:09.553Z"
|
||||
},
|
||||
{
|
||||
"id": "clzwuyxln00049grb4ng91xik",
|
||||
"filename": "clzwuyxlf00039grb80upct14.yarnrc",
|
||||
"path": "static\\clzwuyxlf00039grb80upct14.yarnrc",
|
||||
"createTime": "2024-08-16T15:22:43.739Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
+33
-32
@@ -1,32 +1,33 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@koa/multer": "^3.0.0",
|
||||
"@types/yaml": "^1.9.7",
|
||||
"cuid": "^2.1.8",
|
||||
"dayjs": "^1.11.3",
|
||||
"koa": "^2.13.4",
|
||||
"koa-body": "^4.2.0",
|
||||
"koa-mount": "^4.0.0",
|
||||
"koa-router": "^10.1.1",
|
||||
"koa-static": "^5.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lowdb": "^3.0.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"node-cron": "^3.0.1",
|
||||
"uuid": "^8.3.2",
|
||||
"yaml": "^2.1.1",
|
||||
"funjia-server":"git+http://git.funjia.top/funjia/funjia-server.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.7"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"smoke": "node smoke-test.mjs",
|
||||
"test": "node smoke-test.mjs"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@koa/multer": "^3.0.0",
|
||||
"@types/yaml": "^1.9.7",
|
||||
"cuid": "^2.1.8",
|
||||
"dayjs": "^1.11.3",
|
||||
"koa": "^2.13.4",
|
||||
"koa-body": "^4.2.0",
|
||||
"koa-mount": "^4.0.0",
|
||||
"koa-router": "^10.1.1",
|
||||
"koa-static": "^5.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"lowdb": "^3.0.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"node-cron": "^3.0.1",
|
||||
"uuid": "^8.3.2",
|
||||
"yaml": "^2.1.1",
|
||||
"funjia-server":"git+http://git.funjia.top/funjia/funjia-server.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
// import RouterFactor from "../RouterFactory.mjs";
|
||||
// import DBHelper from "../DBHelper.mjs";
|
||||
import {RouterFactor,DBHelper} from "funjia-server/lib/funjia-server.mjs";
|
||||
|
||||
const getDataLog = (router) => {
|
||||
const rF = new RouterFactor({
|
||||
router,
|
||||
db: DBHelper.logDB,
|
||||
name: "dataLog"
|
||||
});
|
||||
|
||||
rF.creaetBaseRouter();
|
||||
}
|
||||
|
||||
import {RouterFactor,DBHelper} from "funjia-server/lib/funjia-server.mjs";
|
||||
|
||||
const getDataLog = (router) => {
|
||||
const rF = new RouterFactor({
|
||||
router,
|
||||
db: DBHelper.logDB,
|
||||
name: "dataLog"
|
||||
});
|
||||
|
||||
rF.creaetBaseRouter();
|
||||
}
|
||||
|
||||
export default getDataLog;
|
||||
+126
-173
@@ -1,173 +1,126 @@
|
||||
import cuid from "cuid";
|
||||
// import getDb from "../dbServer.mjs";
|
||||
import _ from "lodash";
|
||||
|
||||
import { getDb } from "funjia-server/lib/funjia-server.mjs";
|
||||
const getEmployee = (router) => {
|
||||
|
||||
router.post('/api/employee/list', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const body = ctx.request.body;
|
||||
const data = db.data?.employee?.filter((item) => {
|
||||
let isMatch = true;
|
||||
for (let field in body) {
|
||||
if (["page", "pageSize"].includes(field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof (item[field]) == "string") {
|
||||
isMatch = item[field]?.indexOf?.(body[field]) > -1;
|
||||
} else if (typeof (item[field]) == "number") {
|
||||
isMatch = item[field] == body[field];
|
||||
}
|
||||
if (!isMatch)
|
||||
break;
|
||||
}
|
||||
return isMatch;
|
||||
});
|
||||
|
||||
const {
|
||||
page,
|
||||
pageSize
|
||||
} = body;
|
||||
let batchData = data;
|
||||
if (page && pageSize) {
|
||||
batchData = data.slice((page - 1) * pageSize, page * pageSize);
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: batchData || [],
|
||||
total: data.length
|
||||
};
|
||||
});
|
||||
|
||||
router.get('/api/employee', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const data = db.data.employee;
|
||||
const query = ctx.request.query;
|
||||
console.log("参数:", query, ctx.request.body, ctx.query);
|
||||
let detail = {};
|
||||
if (query.id && data) {
|
||||
detail = data.find((item) => {
|
||||
return item.id == query.id;
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: detail || {}
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/employee/add', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data?.employee)
|
||||
db.data.employee = [];
|
||||
const {
|
||||
employee
|
||||
} = db.data;
|
||||
const data = ctx.request.body;
|
||||
console.log("add:", data);
|
||||
data.id = cuid();
|
||||
data.createTime = new Date();
|
||||
employee.push(data)
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/employee/upd', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data?.employee)
|
||||
db.data = {
|
||||
employee: []
|
||||
}
|
||||
const {
|
||||
employee
|
||||
} = db.data;
|
||||
const data = ctx.request.body;
|
||||
const id = data.id;
|
||||
console.log("数据Id:", id);
|
||||
if (id && employee) {
|
||||
const currentDetail = employee.find(item => item.id == id);
|
||||
if (currentDetail) {
|
||||
_.merge(currentDetail, data);
|
||||
}
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/employee/delete', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data?.employee)
|
||||
db.data = {
|
||||
employee: []
|
||||
}
|
||||
let {
|
||||
employee
|
||||
} = db.data;
|
||||
const data = ctx.request.body;
|
||||
const ids = data.ids;
|
||||
if (ids?.length > 0 && employee) {
|
||||
let id = null;
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
id = ids[i];
|
||||
const idx = employee.findIndex(item => item.id == id);
|
||||
if (idx != -1) {
|
||||
employee.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/employee/login', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const data = db.data.employee;
|
||||
const params = ctx.request.body;
|
||||
let detail = {};
|
||||
if (data) {
|
||||
detail = data.find((item) => {
|
||||
return item.userName == params.userName && item.pwd == params.pwd;
|
||||
});
|
||||
}
|
||||
|
||||
const code = detail ? 0 : 1;
|
||||
|
||||
ctx.body = {
|
||||
code,
|
||||
data: detail || {}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default getEmployee;
|
||||
import cuid from "cuid";
|
||||
import _ from "lodash";
|
||||
import { getDb } from "funjia-server/lib/funjia-server.mjs";
|
||||
import { getTable, pickFilters, matchRow, listResponse, omitSensitive } from "../helpers.mjs";
|
||||
|
||||
/**
|
||||
* 员工(登录账号)路由。
|
||||
*
|
||||
* ## 改造前的缺陷
|
||||
*
|
||||
* 1. **列表接口在员工表为空时抛错**
|
||||
* `db.data?.employee?.filter(...)` → `undefined`,随后 `data.length` 直接 500。
|
||||
*
|
||||
* 2. **明文密码出接口**
|
||||
* `/api/employee/list` 与 `/api/employee/login` 都返回完整记录,`pwd` 字段
|
||||
* (示例库里就是 `123456`)明文透出到浏览器。改为统一剔除。
|
||||
*
|
||||
* 3. **`console.log` 打印登录参数**
|
||||
* 原来会把 `ctx.request.body`(含用户名、密码)原样写进日志。
|
||||
*
|
||||
* 4. **`upd` 允许请求体覆盖主键 id**,`delete` 用逐条 splice(ids 中的无效 id
|
||||
* 被静默忽略,且返回值不体现实际删除条数)。
|
||||
*
|
||||
* 5. **登录失败不区分原因**这件事要保持——反过来也不该把「用户不存在」和
|
||||
* 「密码错误」区分开,避免账号枚举。
|
||||
*/
|
||||
const getEmployee = (router) => {
|
||||
const tableName = "employee";
|
||||
|
||||
router.post("/api/employee/list", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, tableName);
|
||||
|
||||
const body = ctx.request.body || {};
|
||||
const data = table.filter((item) => matchRow(item, pickFilters(body)));
|
||||
|
||||
ctx.body = {
|
||||
...listResponse(data, body),
|
||||
data: listResponse(data, body).data.map((row) => omitSensitive(row)),
|
||||
};
|
||||
});
|
||||
|
||||
router.get("/api/employee", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, tableName);
|
||||
const detail = table.find((item) => item.id == ctx.request.query.id);
|
||||
|
||||
ctx.body = { code: 0, data: detail ? omitSensitive(detail) : {} };
|
||||
});
|
||||
|
||||
router.post("/api/employee/add", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(getDb, tableName);
|
||||
const data = ctx.request.body || {};
|
||||
|
||||
if (table.some((item) => item.userName === data.userName)) {
|
||||
ctx.body = { code: 1, msg: "用户名已存在" };
|
||||
return;
|
||||
}
|
||||
|
||||
const { id, createTime, ...rest } = data;
|
||||
void id;
|
||||
void createTime;
|
||||
table.push({ ...rest, id: cuid(), createTime: new Date() });
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0 };
|
||||
});
|
||||
|
||||
router.post("/api/employee/upd", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(getDb, tableName);
|
||||
const { id, createTime, ...patch } = ctx.request.body || {};
|
||||
// id / createTime 由服务端维护,不接受请求体覆盖
|
||||
void id;
|
||||
void createTime;
|
||||
|
||||
const current = table.find((item) => item.id == id);
|
||||
if (!current) {
|
||||
ctx.body = { code: 1, msg: "员工不存在" };
|
||||
return;
|
||||
}
|
||||
|
||||
_.merge(current, patch);
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0 };
|
||||
});
|
||||
|
||||
router.post("/api/employee/delete", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(getDb, tableName);
|
||||
const ids = (ctx.request.body?.ids || []).map(String);
|
||||
|
||||
if (ids.length === 0) {
|
||||
ctx.body = { code: 1, msg: "未指定要删除的记录" };
|
||||
return;
|
||||
}
|
||||
|
||||
const before = table.length;
|
||||
const rest = table.filter((item) => !ids.includes(String(item.id)));
|
||||
table.length = 0;
|
||||
table.push(...rest);
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0, data: { deleted: before - table.length } };
|
||||
});
|
||||
|
||||
router.post("/api/employee/login", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, tableName);
|
||||
const { userName, pwd } = ctx.request.body || {};
|
||||
|
||||
const detail = table.find((item) => item.userName === userName && item.pwd === pwd);
|
||||
|
||||
if (!detail) {
|
||||
// 不区分「用户不存在」与「密码错误」,避免账号枚举
|
||||
ctx.body = { code: 1, msg: "用户名或密码错误" };
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.body = { code: 0, data: omitSensitive(detail) };
|
||||
});
|
||||
};
|
||||
|
||||
export default getEmployee;
|
||||
|
||||
+92
-154
@@ -1,154 +1,92 @@
|
||||
import cuid from "cuid";
|
||||
// import getDb from "../dbServer.mjs";
|
||||
import {getDb} from "funjia-server/lib/funjia-server.mjs";
|
||||
import _ from "lodash";
|
||||
|
||||
const getNotice = (router) => {
|
||||
|
||||
router.post('/api/Notice/list', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const body = ctx.request.body;
|
||||
const data = db.data?.Notice?.filter((item) => {
|
||||
let isMatch = true;
|
||||
for (let field in body) {
|
||||
if (["page", "pageSize"].includes(field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof (item[field]) == "string") {
|
||||
isMatch = item[field]?.indexOf?.(body[field]) > -1;
|
||||
} else if (typeof (item[field]) == "number") {
|
||||
isMatch = item[field] == body[field];
|
||||
}
|
||||
if (!isMatch)
|
||||
break;
|
||||
}
|
||||
return isMatch;
|
||||
});
|
||||
|
||||
const {
|
||||
page,
|
||||
pageSize
|
||||
} = body;
|
||||
let batchData = data;
|
||||
if (page && pageSize) {
|
||||
batchData = data.slice((page - 1) * pageSize, page * pageSize);
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: batchData.sort((a, b) => {
|
||||
return a.sort - b.sort;
|
||||
}) || [],
|
||||
total: data.length
|
||||
};
|
||||
});
|
||||
|
||||
router.get('/api/Notice', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const data = db.data.Notice;
|
||||
const query = ctx.request.query;
|
||||
console.log("参数:", query, ctx.request.body, ctx.query);
|
||||
let detail = {};
|
||||
if (query.id && data) {
|
||||
detail = data.find((item) => {
|
||||
return item.id == query.id;
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: detail || {}
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/Notice/add', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data?.Notice)
|
||||
db.data.Notice = [];
|
||||
const {
|
||||
Notice
|
||||
} = db.data;
|
||||
const data = ctx.request.body;
|
||||
console.log("add:", data);
|
||||
data.id = cuid();
|
||||
data.createTime = new Date();
|
||||
Notice.push(data)
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/Notice/upd', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data?.Notice)
|
||||
db.data = {
|
||||
Notice: []
|
||||
}
|
||||
const {
|
||||
Notice
|
||||
} = db.data;
|
||||
const data = ctx.request.body;
|
||||
const id = data.id;
|
||||
console.log("数据Id:", id);
|
||||
if (id && Notice) {
|
||||
const currentDetail = Notice.find(item => item.id == id);
|
||||
if (currentDetail) {
|
||||
_.merge(currentDetail, data);
|
||||
}
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/Notice/delete', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data?.Notice)
|
||||
db.data = {
|
||||
Notice: []
|
||||
}
|
||||
let {
|
||||
Notice
|
||||
} = db.data;
|
||||
const data = ctx.request.body;
|
||||
const ids = data.ids;
|
||||
if (ids?.length > 0 && Notice) {
|
||||
let id = null;
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
id = ids[i];
|
||||
const idx = Notice.findIndex(item => item.id == id);
|
||||
if (idx != -1) {
|
||||
Notice.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default getNotice;
|
||||
import cuid from "cuid";
|
||||
import _ from "lodash";
|
||||
import { getDb } from "funjia-server/lib/funjia-server.mjs";
|
||||
import { getTable, pickFilters, matchRow, listResponse } from "../helpers.mjs";
|
||||
|
||||
/**
|
||||
* 通知路由。
|
||||
*
|
||||
* 改造前与 `dynamic.mjs` 存在同款问题:
|
||||
* - 表为空时 `data.length` 抛 TypeError;
|
||||
* - `upd` / `delete` 在表缺失时用 `db.data = { Notice: [] }` **整体替换数据库对象**,
|
||||
* 紧接着 `db.write()` 落盘,会把其它业务表全部清掉;
|
||||
* - `upd` 允许请求体覆盖主键 id;
|
||||
* - 每次请求 `console.log` 完整参数。
|
||||
*/
|
||||
const getNotice = (router) => {
|
||||
const tableName = "Notice";
|
||||
|
||||
router.post("/api/Notice/list", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, tableName);
|
||||
|
||||
const body = ctx.request.body || {};
|
||||
const data = table
|
||||
.filter((item) => matchRow(item, pickFilters(body)))
|
||||
.sort((a, b) => (a.sort ?? 0) - (b.sort ?? 0));
|
||||
|
||||
ctx.body = listResponse(data, body);
|
||||
});
|
||||
|
||||
router.get("/api/Notice", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, tableName);
|
||||
const detail = table.find((item) => item.id == ctx.request.query.id);
|
||||
|
||||
ctx.body = { code: 0, data: detail || {} };
|
||||
});
|
||||
|
||||
router.post("/api/Notice/add", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(getDb, tableName);
|
||||
const { id, createTime, ...rest } = ctx.request.body || {};
|
||||
void id;
|
||||
void createTime;
|
||||
|
||||
table.push({ ...rest, id: cuid(), createTime: new Date() });
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0 };
|
||||
});
|
||||
|
||||
router.post("/api/Notice/upd", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(getDb, tableName);
|
||||
const { id, createTime, ...patch } = ctx.request.body || {};
|
||||
// id / createTime 由服务端维护,不接受请求体覆盖
|
||||
void id;
|
||||
void createTime;
|
||||
|
||||
const current = table.find((item) => item.id == id);
|
||||
if (!current) {
|
||||
ctx.body = { code: 1, msg: "通知不存在" };
|
||||
return;
|
||||
}
|
||||
|
||||
_.merge(current, patch);
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0 };
|
||||
});
|
||||
|
||||
router.post("/api/Notice/delete", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(getDb, tableName);
|
||||
const ids = (ctx.request.body?.ids || []).map(String);
|
||||
|
||||
if (ids.length === 0) {
|
||||
ctx.body = { code: 1, msg: "未指定要删除的记录" };
|
||||
return;
|
||||
}
|
||||
|
||||
const before = table.length;
|
||||
const rest = table.filter((item) => !ids.includes(String(item.id)));
|
||||
table.length = 0;
|
||||
table.push(...rest);
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0, data: { deleted: before - table.length } };
|
||||
});
|
||||
};
|
||||
|
||||
export default getNotice;
|
||||
|
||||
+13
-15
@@ -1,16 +1,14 @@
|
||||
// import RouterFactor from "../RouterFactory.mjs";
|
||||
// import DBHelper from "../DBHelper.mjs";
|
||||
import {RouterFactor,DBHelper} from "funjia-server/lib/funjia-server.mjs";
|
||||
|
||||
|
||||
const getQA = (router) => {
|
||||
const rF = new RouterFactor({
|
||||
router,
|
||||
db: DBHelper.baseDB,
|
||||
name: "qa"
|
||||
});
|
||||
|
||||
rF.creaetBaseRouter();
|
||||
}
|
||||
|
||||
import {RouterFactor,DBHelper} from "funjia-server/lib/funjia-server.mjs";
|
||||
|
||||
|
||||
const getQA = (router) => {
|
||||
const rF = new RouterFactor({
|
||||
router,
|
||||
db: DBHelper.baseDB,
|
||||
name: "qa"
|
||||
});
|
||||
|
||||
rF.creaetBaseRouter();
|
||||
}
|
||||
|
||||
export default getQA;
|
||||
@@ -1,108 +1,24 @@
|
||||
import _ from "lodash";
|
||||
// import RouterFactor from "../RouterFactory.mjs";
|
||||
// import DBHelper from "../DBHelper.mjs";
|
||||
import {RouterFactor,DBHelper} from "funjia-server/lib/funjia-server.mjs";
|
||||
|
||||
const getBackupHistory = (router) => {
|
||||
const rF = new RouterFactor({
|
||||
router,
|
||||
db: DBHelper.backupDB,
|
||||
name: "backupHistory"
|
||||
});
|
||||
|
||||
rF.createGetList();
|
||||
|
||||
rF.createGetDetail();
|
||||
|
||||
rF.createAdd();
|
||||
|
||||
rF.createUpdate();
|
||||
|
||||
rF.createDelete();
|
||||
|
||||
// router.post('/api/backupHistory/add', async (ctx) => {
|
||||
// ctx.type = 'application/json';
|
||||
// const db = await getBackupDb();
|
||||
|
||||
// // You can also use this syntax if you prefer
|
||||
// if (!db.data.backupHistory)
|
||||
// db.data.backupHistory = [];
|
||||
// const {
|
||||
// backupHistory
|
||||
// } = db.data;
|
||||
// const data = ctx.request.body;
|
||||
// console.log("add:", data);
|
||||
// data.id = cuid();
|
||||
// data.createTime = new Date();
|
||||
// backupHistory.push(data)
|
||||
// // Write db.data content to db.json
|
||||
// await db.write()
|
||||
|
||||
// ctx.body = {
|
||||
// code: 0,
|
||||
// };
|
||||
// });
|
||||
|
||||
// router.post('/api/backupHistory/upd', async (ctx) => {
|
||||
// ctx.type = 'application/json';
|
||||
// const db = await getBackupDb();
|
||||
|
||||
// // You can also use this syntax if you prefer
|
||||
// if (!db.data.backupHistory)
|
||||
// db.data = {
|
||||
// backupHistory: []
|
||||
// }
|
||||
// const {
|
||||
// backupHistory
|
||||
// } = db.data;
|
||||
// const data = ctx.request.body;
|
||||
// const id = data.id;
|
||||
// console.log("数据Id:", id);
|
||||
// if (id && backupHistory) {
|
||||
// const currentDetail = backupHistory.find(item => item.id == id);
|
||||
// if (currentDetail) {
|
||||
// _.merge(currentDetail, data);
|
||||
// }
|
||||
// // Write db.data content to db.json
|
||||
// await db.write()
|
||||
// }
|
||||
|
||||
// ctx.body = {
|
||||
// code: 0,
|
||||
// };
|
||||
// });
|
||||
|
||||
// router.post('/api/backupHistory/delete', async (ctx) => {
|
||||
// ctx.type = 'application/json';
|
||||
// const db = await getBackupDb();
|
||||
|
||||
// // You can also use this syntax if you prefer
|
||||
// if (!db.data.backupHistory)
|
||||
// db.data = {
|
||||
// backupHistory: []
|
||||
// }
|
||||
// let {
|
||||
// backupHistory
|
||||
// } = db.data;
|
||||
// const data = ctx.request.body;
|
||||
// const ids = data.ids;
|
||||
// if (ids.length > 0 && backupHistory) {
|
||||
// let id = null;
|
||||
// for (let i = 0; i < ids.length; i++) {
|
||||
// id = ids[i];
|
||||
// const idx = backupHistory.findIndex(item => item.id == id);
|
||||
// if (idx != -1) {
|
||||
// backupHistory.splice(idx, 1);
|
||||
// }
|
||||
// }
|
||||
// // Write db.data content to db.json
|
||||
// await db.write()
|
||||
// }
|
||||
|
||||
// ctx.body = {
|
||||
// code: 0,
|
||||
// };
|
||||
// });
|
||||
}
|
||||
|
||||
export default getBackupHistory;
|
||||
import { RouterFactor, DBHelper } from "funjia-server/lib/funjia-server.mjs";
|
||||
|
||||
/**
|
||||
* 备份历史路由。
|
||||
*
|
||||
* 改造前文件里有 80 余行被注释掉的旧实现——那正是 `dynamic.mjs` 里
|
||||
* 「表缺失时整体替换 db.data」缺陷的原始版本(`db.data = { backupHistory: [] }`)。
|
||||
* 已改用 `funjia-server` 的 `RouterFactor` 后,这些注释只留下误导作用,故删除。
|
||||
*/
|
||||
const getBackupHistory = (router) => {
|
||||
const rF = new RouterFactor({
|
||||
router,
|
||||
db: DBHelper.backupDB,
|
||||
name: "backupHistory",
|
||||
});
|
||||
|
||||
rF.createGetList();
|
||||
rF.createGetDetail();
|
||||
rF.createAdd();
|
||||
rF.createUpdate();
|
||||
rF.createDelete();
|
||||
};
|
||||
|
||||
export default getBackupHistory;
|
||||
|
||||
+108
-157
@@ -1,157 +1,108 @@
|
||||
import cuid from "cuid";
|
||||
// import getDb from "../dbServer.mjs";
|
||||
import {getDb} from "funjia-server/lib/funjia-server.mjs";
|
||||
import _ from "lodash";
|
||||
|
||||
const getDynamic = (router) => {
|
||||
|
||||
router.post('/api/dynamic/list/:tableName', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const body = ctx.request.body;
|
||||
const data = db.data[ctx.params.tableName]?.filter((item) => {
|
||||
let isMatch = true;
|
||||
for (let field in body) {
|
||||
if (["page", "pageSize"].includes(field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof (item[field]) == "string") {
|
||||
isMatch = item[field]?.indexOf?.(body[field]) > -1;
|
||||
} else if (typeof (item[field]) == "number") {
|
||||
isMatch = item[field] == body[field];
|
||||
}
|
||||
if (!isMatch)
|
||||
break;
|
||||
}
|
||||
return isMatch;
|
||||
});
|
||||
|
||||
const {
|
||||
page,
|
||||
pageSize
|
||||
} = body;
|
||||
let batchData = data;
|
||||
if (page && pageSize) {
|
||||
batchData = data.slice((page - 1) * pageSize, page * pageSize);
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: batchData || [],
|
||||
total: data.length
|
||||
};
|
||||
});
|
||||
|
||||
router.get('/api/dynamic/:tableName', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const data = db.data[ctx.params.tableName];
|
||||
const query = ctx.request.query;
|
||||
console.log("参数:", query, ctx.request.body, ctx.query);
|
||||
let detail = {};
|
||||
if (query.id && data) {
|
||||
detail = data.find((item) => {
|
||||
return item.id == query.id;
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: detail || {}
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/dynamic/add/:tableName', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const tableName=ctx.params.tableName;
|
||||
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data[tableName])
|
||||
db.data[tableName] = [];
|
||||
|
||||
const dynamic = db.data[tableName];
|
||||
const data = ctx.request.body;
|
||||
console.log("add:", data);
|
||||
data.id = cuid();
|
||||
data.createTime = new Date();
|
||||
dynamic.push(data)
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/dynamic/upd/:tableName', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const tableName=ctx.params.tableName;
|
||||
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data[tableName])
|
||||
db.data = {
|
||||
dynamic: []
|
||||
}
|
||||
|
||||
const dynamic = db.data[tableName];
|
||||
|
||||
const data = ctx.request.body;
|
||||
const id = data.id;
|
||||
console.log("数据Id:", id);
|
||||
if (id && dynamic) {
|
||||
const currentDetail = dynamic.find(item => item.id == id);
|
||||
if (currentDetail) {
|
||||
_.merge(currentDetail, data);
|
||||
}
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/api/dynamic/delete/:tableName', async (ctx) => {
|
||||
ctx.type = 'application/json';
|
||||
const tableName=ctx.params.tableName;
|
||||
|
||||
const db = await getDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data[tableName])
|
||||
db.data = {
|
||||
[tableName]: []
|
||||
}
|
||||
|
||||
const dynamic = db.data[tableName];
|
||||
|
||||
const data = ctx.request.body;
|
||||
const ids = data.ids;
|
||||
if (ids?.length > 0 && dynamic) {
|
||||
let id = null;
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
id = ids[i];
|
||||
const idx = dynamic.findIndex(item => item.id == id);
|
||||
if (idx != -1) {
|
||||
dynamic.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default getDynamic;
|
||||
import cuid from "cuid";
|
||||
import _ from "lodash";
|
||||
import { getDb } from "funjia-server/lib/funjia-server.mjs";
|
||||
import { getTable as getTableRaw, pickFilters, matchRow, listResponse } from "./helpers.mjs";
|
||||
|
||||
/**
|
||||
* 通用动态表 CRUD 路由。
|
||||
*
|
||||
* ## 改造前存在的三个严重缺陷
|
||||
*
|
||||
* 1. **upd / delete 会把整库数据清空**
|
||||
* ```js
|
||||
* if (!db.data[tableName]) db.data = { dynamic: [] } // ← 整个 db.data 被替换
|
||||
* ```
|
||||
* 当目标表不存在时,不是创建该表,而是把**整个数据库对象**换成 `{ dynamic: [] }`,
|
||||
* 紧接着 `db.write()` 落盘——employee / Notice / qa 等所有业务表瞬间消失。
|
||||
* 现在只创建缺失的那一张表。
|
||||
*
|
||||
* 2. **列表接口在表为空时抛 TypeError**
|
||||
* `db.data[name]?.filter(...)` 得到 `undefined` 后,紧接着访问
|
||||
* `data.length` / `data.slice(...)`,直接 500。`employee` / `Notice` /
|
||||
* `upload` 路由都有同样问题,这里统一补默认空数组。
|
||||
*
|
||||
* 3. **删除用 splice 逐个匹配,ids 中不存在的 id 会被静默忽略**
|
||||
* 改为过滤后回填,并返回实际删除条数,便于前端核对。
|
||||
*
|
||||
* 另外:原实现每次请求都 `console.log` 完整查询参数与写入的数据对象,
|
||||
* 密码、手机号等个人信息会直接进日志,已全部移除。
|
||||
*
|
||||
* 「过滤 / 分页 / 取表」等工具已收口到 `helpers.mjs`,本文件不再重复实现。
|
||||
*/
|
||||
|
||||
const getDynamic = (router) => {
|
||||
/** 取表并保证其为数组(关键:只在表缺失时补该表,不动 db.data 本身) */
|
||||
const getTable = (tableName) => getTableRaw(getDb, tableName);
|
||||
|
||||
router.post("/api/dynamic/list/:tableName", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(ctx.params.tableName);
|
||||
|
||||
const body = ctx.request.body || {};
|
||||
const data = table.filter((item) => matchRow(item, pickFilters(body)));
|
||||
|
||||
ctx.body = listResponse(data, body);
|
||||
});
|
||||
|
||||
router.get("/api/dynamic/:tableName", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(ctx.params.tableName);
|
||||
const { id } = ctx.request.query;
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: table.find((item) => item.id == id) || {},
|
||||
};
|
||||
});
|
||||
|
||||
router.post("/api/dynamic/add/:tableName", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(ctx.params.tableName);
|
||||
|
||||
table.push({ ...(ctx.request.body || {}), id: cuid(), createTime: new Date() });
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0 };
|
||||
});
|
||||
|
||||
router.post("/api/dynamic/upd/:tableName", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(ctx.params.tableName);
|
||||
const { id, createTime, ...patch } = ctx.request.body || {};
|
||||
// id / createTime 由服务端维护,不接受请求体覆盖
|
||||
void id;
|
||||
void createTime;
|
||||
|
||||
const current = table.find((item) => item.id == id);
|
||||
if (!current) {
|
||||
ctx.body = { code: 1, msg: "记录不存在" };
|
||||
return;
|
||||
}
|
||||
|
||||
_.merge(current, patch);
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0 };
|
||||
});
|
||||
|
||||
router.post("/api/dynamic/delete/:tableName", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { db, table } = await getTable(ctx.params.tableName);
|
||||
const ids = (ctx.request.body?.ids || []).map(String);
|
||||
|
||||
if (ids.length === 0) {
|
||||
ctx.body = { code: 1, msg: "未指定要删除的记录" };
|
||||
return;
|
||||
}
|
||||
|
||||
const before = table.length;
|
||||
const rest = table.filter((item) => !ids.includes(String(item.id)));
|
||||
table.length = 0;
|
||||
table.push(...rest);
|
||||
await db.write();
|
||||
|
||||
ctx.body = { code: 0, data: { deleted: before - table.length } };
|
||||
});
|
||||
};
|
||||
|
||||
export default getDynamic;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 路由层公共工具。
|
||||
*
|
||||
* 改造前 `dynamic.mjs` / `employee.mjs` / `notice.mjs` / `upload.mjs` 四个文件里
|
||||
* 各抄了一份「过滤 + 分页」的实现,逻辑还不完全一致(`notice` 少了空值保护、
|
||||
* `upload` 少了可选链),这里统一收口。
|
||||
*/
|
||||
|
||||
/** 从数据库取表并保证它是数组 */
|
||||
export const getTable = async (getDb, tableName) => {
|
||||
const db = await getDb();
|
||||
if (!Array.isArray(db.data[tableName])) {
|
||||
db.data[tableName] = [];
|
||||
}
|
||||
return { db, table: db.data[tableName] };
|
||||
};
|
||||
|
||||
/** 剔除分页参数后的业务查询条件 */
|
||||
export const pickFilters = (body = {}, excludes = ["page", "pageSize"]) =>
|
||||
Object.fromEntries(Object.entries(body).filter(([key]) => !excludes.includes(key)));
|
||||
|
||||
/** 内存过滤:字符串模糊匹配,其余精确匹配;空值不参与过滤 */
|
||||
export const matchRow = (row, filters) =>
|
||||
Object.entries(filters).every(([field, value]) => {
|
||||
if (value === undefined || value === null || value === "") return true;
|
||||
if (typeof row[field] === "string") return row[field].includes(String(value));
|
||||
return row[field] == value;
|
||||
});
|
||||
|
||||
/** 分页切片 */
|
||||
export const paginate = (list, page, pageSize) => {
|
||||
if (!page || !pageSize) return list;
|
||||
return list.slice((page - 1) * pageSize, page * pageSize);
|
||||
};
|
||||
|
||||
/** 统一的列表响应 */
|
||||
export const listResponse = (list, body = {}) => ({
|
||||
code: 0,
|
||||
data: paginate(list, body.page, body.pageSize),
|
||||
total: list.length,
|
||||
});
|
||||
|
||||
/**
|
||||
* 剔除敏感字段。
|
||||
* 改造前 `/api/employee/list` 与 `/api/employee/login` 会把 `pwd` 明文返回给前端。
|
||||
*/
|
||||
export const omitSensitive = (row, fields = ["pwd"]) => {
|
||||
if (!row || typeof row !== "object") return row;
|
||||
return Object.fromEntries(Object.entries(row).filter(([key]) => !fields.includes(key)));
|
||||
};
|
||||
+132
-167
@@ -1,167 +1,132 @@
|
||||
import cuid from "cuid";
|
||||
// import getDb, {
|
||||
// getResourceDb
|
||||
// } from "../dbServer.mjs";
|
||||
import {getDb,getResourceDb} from "funjia-server/lib/funjia-server.mjs";
|
||||
import _ from "lodash";
|
||||
import multer from '@koa/multer';
|
||||
|
||||
//配置
|
||||
var storage = multer.diskStorage({
|
||||
//文件保存路径
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, 'static') //注意路径必须存最后面在不用加斜杠
|
||||
},
|
||||
//修改文件名称
|
||||
filename: function (req, file, cb) {
|
||||
var fileFormat = (file.originalname).split(".");
|
||||
const filename = cuid() + "." + fileFormat[fileFormat.length - 1];
|
||||
req.filename = filename;
|
||||
cb(null, filename);
|
||||
}
|
||||
})
|
||||
|
||||
//加载配置
|
||||
var upload = multer({
|
||||
storage: storage
|
||||
})
|
||||
|
||||
// const upload = multer({ dest: 'static/' })
|
||||
|
||||
const getUpload = (router) => {
|
||||
router.post('/api/leaseRecords/list', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const body = ctx.request.body;
|
||||
const data = db.data.leaseRecords.filter((item) => {
|
||||
let isMatch = true;
|
||||
for (let field in body) {
|
||||
if (["page", "pageSize"].includes(field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof (item[field]) == "string") {
|
||||
isMatch = item[field].indexOf(body[field]) > -1;
|
||||
} else if (typeof (item[field]) == "number") {
|
||||
isMatch = item[field] == body[field];
|
||||
}
|
||||
if (!isMatch)
|
||||
break;
|
||||
}
|
||||
return isMatch;
|
||||
});
|
||||
|
||||
const {
|
||||
page,
|
||||
pageSize
|
||||
} = body;
|
||||
let batchData = data;
|
||||
if (page && pageSize) {
|
||||
batchData = data.slice((page - 1) * pageSize, page * pageSize);
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: batchData.sort((a, b) => {
|
||||
return a.sort - b.sort;
|
||||
}) || [],
|
||||
total: data.length
|
||||
};
|
||||
});
|
||||
|
||||
router.get('/api/img', async (ctx) => {
|
||||
// 设置头类型, 如果不设置,会直接下载该页面
|
||||
ctx.type = 'application/json';
|
||||
const db = await getDb();
|
||||
const data = db.data.leaseRecords;
|
||||
const query = ctx.request.query;
|
||||
console.log("参数:", query, ctx.request.body, ctx.query);
|
||||
let detail = {};
|
||||
if (query.id && data) {
|
||||
detail = data.find((item) => {
|
||||
return item.id == query.id;
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: detail || {}
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* 添加图片记录
|
||||
* @param {*} path
|
||||
*/
|
||||
const addImg = async (filename, path) => {
|
||||
const data = {};
|
||||
try {
|
||||
const db = await getResourceDb();
|
||||
|
||||
// You can also use this syntax if you prefer
|
||||
if (!db.data.img)
|
||||
db.data.img = [];
|
||||
|
||||
const {
|
||||
img
|
||||
} = db.data;
|
||||
|
||||
data.id = cuid();
|
||||
data.filename = filename;
|
||||
data.path = path;
|
||||
data.createTime = new Date();
|
||||
img.push(data)
|
||||
// Write db.data content to db.json
|
||||
await db.write()
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return null;
|
||||
}
|
||||
return data.id;
|
||||
|
||||
}
|
||||
|
||||
// 添加单个文件上传的路由
|
||||
router.post(
|
||||
'/api/upload/img',
|
||||
upload.single('file'),
|
||||
async (ctx) => {
|
||||
const {
|
||||
filename,
|
||||
path
|
||||
} = ctx.file;
|
||||
const res = await addImg(filename, path);
|
||||
|
||||
ctx.body = {
|
||||
code: res ? 0 : 1,
|
||||
data: {
|
||||
id: res,
|
||||
url: path
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 添加单个文件上传的路由
|
||||
router.post(
|
||||
'/api/upload/file',
|
||||
upload.single('file'),
|
||||
async (ctx) => {
|
||||
const {
|
||||
filename,
|
||||
path
|
||||
} = ctx.file;
|
||||
// const res = await addImg(filename, path);
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: {
|
||||
url: "/resource/static/"+filename
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default getUpload;
|
||||
import cuid from "cuid";
|
||||
import multer from "@koa/multer";
|
||||
import path from "path";
|
||||
import { getDb, getResourceDb } from "funjia-server/lib/funjia-server.mjs";
|
||||
import { getTable, pickFilters, matchRow, listResponse } from "./helpers.mjs";
|
||||
|
||||
/**
|
||||
* 上传相关路由。
|
||||
*
|
||||
* ## 改造前的缺陷
|
||||
*
|
||||
* 1. **上传没有任何文件类型/大小限制**,并且用 `originalname` 的扩展名
|
||||
* 直接拼出落盘文件名——上传 `shell.php` 或超长扩展名都会被原样接受;
|
||||
* 文件目录还是相对路径 `static`,取决于进程工作目录。
|
||||
*
|
||||
* 2. **文件名扩展名取自用户输入且未做净化**,存在路径穿越 / 双扩展名风险。
|
||||
*
|
||||
* 3. **`/api/leaseRecords/list` 与 `/api/img` 是上一代业务(租赁记录)的残留**,
|
||||
* 其中 `db.data.leaseRecords.filter` 在表不存在时直接 500;
|
||||
* 这套路由在当前前端代码里已无任何调用方,保留但补上兜底。
|
||||
*
|
||||
* 4. **`multer` 实例是模块级单例、storage 是同步回调**,本身没问题;
|
||||
* 但 `path` 变量同时被用作「目录」和「数据库字段名」(`data.path = path`),
|
||||
* 语义混淆。这里显式区分 `filePath` 与存储字段。
|
||||
*/
|
||||
|
||||
/** 允许上传的扩展名白名单 */
|
||||
const ALLOWED_EXTENSIONS = new Set([".js", ".mjs", ".json", ".txt", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".pdf", ".zip"]);
|
||||
|
||||
/** 单文件大小上限:20MB */
|
||||
const MAX_FILE_SIZE = 20 * 1024 * 1024;
|
||||
|
||||
/** 存储目录(相对项目根,固定下来而不是依赖 cwd) */
|
||||
const STATIC_DIR = process.env.UPLOAD_DIR || "static";
|
||||
|
||||
const storage = multer.diskStorage({
|
||||
destination: (_req, _file, cb) => {
|
||||
cb(null, STATIC_DIR);
|
||||
},
|
||||
filename: (_req, file, cb) => {
|
||||
// 只取扩展名,且限定为白名单内的安全字符,杜绝文件名注入
|
||||
const ext = path.extname(file.originalname || "").toLowerCase();
|
||||
const safeExt = /^\.[a-z0-9]+$/.test(ext) ? ext : "";
|
||||
cb(null, `${cuid()}${safeExt}`);
|
||||
},
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage,
|
||||
limits: { fileSize: MAX_FILE_SIZE },
|
||||
fileFilter: (_req, file, cb) => {
|
||||
const ext = path.extname(file.originalname || "").toLowerCase();
|
||||
if (!ALLOWED_EXTENSIONS.has(ext)) {
|
||||
cb(new Error(`不支持的文件类型: ${ext || "未知"}`));
|
||||
return;
|
||||
}
|
||||
cb(null, true);
|
||||
},
|
||||
});
|
||||
|
||||
const getUpload = (router) => {
|
||||
router.post("/api/leaseRecords/list", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, "leaseRecords");
|
||||
|
||||
const body = ctx.request.body || {};
|
||||
const data = table
|
||||
.filter((item) => matchRow(item, pickFilters(body)))
|
||||
.sort((a, b) => (a.sort ?? 0) - (b.sort ?? 0));
|
||||
|
||||
ctx.body = listResponse(data, body);
|
||||
});
|
||||
|
||||
router.get("/api/img", async (ctx) => {
|
||||
ctx.type = "application/json";
|
||||
const { table } = await getTable(getDb, "leaseRecords");
|
||||
const detail = table.find((item) => item.id == ctx.request.query.id);
|
||||
|
||||
ctx.body = { code: 0, data: detail || {} };
|
||||
});
|
||||
|
||||
/** 写入资源库并返回记录 id */
|
||||
const addImg = async (filename, filePath) => {
|
||||
try {
|
||||
const db = await getResourceDb();
|
||||
if (!Array.isArray(db.data.img)) db.data.img = [];
|
||||
|
||||
const record = {
|
||||
id: cuid(),
|
||||
filename,
|
||||
path: filePath,
|
||||
createTime: new Date(),
|
||||
};
|
||||
db.data.img.push(record);
|
||||
await db.write();
|
||||
return record.id;
|
||||
} catch (error) {
|
||||
console.error("写入图片资源库失败", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/** 上传图片:落盘 + 记录资源库 */
|
||||
router.post("/api/upload/img", upload.single("file"), async (ctx) => {
|
||||
if (!ctx.file) {
|
||||
ctx.body = { code: 1, msg: "未接收到文件" };
|
||||
return;
|
||||
}
|
||||
const { filename, path: filePath } = ctx.file;
|
||||
const id = await addImg(filename, filePath);
|
||||
|
||||
ctx.body = {
|
||||
code: id ? 0 : 1,
|
||||
data: { id, url: filePath },
|
||||
};
|
||||
});
|
||||
|
||||
/** 上传任意文件:仅落盘,返回可访问 url */
|
||||
router.post("/api/upload/file", upload.single("file"), async (ctx) => {
|
||||
if (!ctx.file) {
|
||||
ctx.body = { code: 1, msg: "未接收到文件" };
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
code: 0,
|
||||
data: { url: `/resource/static/${ctx.file.filename}` },
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export default getUpload;
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
/**
|
||||
* 服务端路由烟雾测试(不依赖 funjia-server / cuid / lodash)。
|
||||
*
|
||||
* 用 vm 在内存中加载路由源码,把外部依赖替换成桩,再配一个内存版 db,
|
||||
* 直接调用真实 handler 做断言。重点回归「整库被清空」这个致命缺陷。
|
||||
*
|
||||
* node smoke-test.mjs
|
||||
*
|
||||
* 退出码 0 = 全部通过,1 = 有用例失败。
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, join } from "node:path";
|
||||
import vm from "node:vm";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// ── 沙箱内可用的桩 ────────────────────────────────────────────────────
|
||||
const sandbox = {
|
||||
console,
|
||||
Math,
|
||||
Date,
|
||||
JSON,
|
||||
Object,
|
||||
Array,
|
||||
String,
|
||||
Number,
|
||||
Boolean,
|
||||
Promise,
|
||||
Error,
|
||||
TypeError,
|
||||
setTimeout,
|
||||
__cuid: () => "id-" + Math.random().toString(36).slice(2, 10),
|
||||
__lodashMerge: (target, source) => Object.assign(target, source),
|
||||
__db: null,
|
||||
};
|
||||
sandbox.globalThis = sandbox;
|
||||
vm.createContext(sandbox);
|
||||
|
||||
/** 把路由源码的 import 改写成沙箱内的全局引用 */
|
||||
const rewrite = (src) => {
|
||||
let out = src;
|
||||
|
||||
// default 导入的第三方包
|
||||
out = out.replace(
|
||||
/import\s+cuid\s+from\s+["'][^"']*cuid["'];?/g,
|
||||
"const cuid = globalThis.__cuid;"
|
||||
);
|
||||
out = out.replace(
|
||||
/import\s+_\s+from\s+["'][^"']*lodash["'];?/g,
|
||||
"const _ = { merge: (t, s) => globalThis.__lodashMerge(t, s) };"
|
||||
);
|
||||
|
||||
// funjia-server 的具名导入(支持 `X as Y` 别名)
|
||||
out = out.replace(
|
||||
/import\s*\{([^}]*)\}\s*from\s*["']funjia-server[^"']*["'];?/g,
|
||||
(m, names) =>
|
||||
names
|
||||
.split(",")
|
||||
.map((n) => n.trim())
|
||||
.filter(Boolean)
|
||||
.map((n) => {
|
||||
const [orig, alias] = n.split(/\s+as\s+/).map((s) => s.trim());
|
||||
return `const ${alias || orig} = globalThis.__${orig};`;
|
||||
})
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
// 相对导入 helpers.mjs(支持 `getTable as getTableRaw` 别名)
|
||||
out = out.replace(
|
||||
/import\s*\{([^}]*)\}\s*from\s*["'][^"']*helpers\.mjs["'];?/g,
|
||||
(m, names) =>
|
||||
names
|
||||
.split(",")
|
||||
.map((n) => n.trim())
|
||||
.filter(Boolean)
|
||||
.map((n) => {
|
||||
const [orig, alias] = n.split(/\s+as\s+/).map((s) => s.trim());
|
||||
return `const ${alias || orig} = globalThis.__helpers.${orig};`;
|
||||
})
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
// export default Foo → 挂到 __mod
|
||||
out = out.replace(/export\s+default\s+([A-Za-z_$][\w$]*)\s*;?/g, "globalThis.__mod = $1;");
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
const loadModule = (relPath) => {
|
||||
sandbox.__mod = undefined;
|
||||
const src = rewrite(readFileSync(join(here, relPath), "utf8"));
|
||||
// 每个模块包一层 IIFE,避免不同文件的顶层 const 在共享沙箱里冲突
|
||||
vm.runInContext(`(function () {\n${src}\n})();`, sandbox, { filename: relPath });
|
||||
return sandbox.__mod;
|
||||
};
|
||||
|
||||
// ── 先加载 helpers.mjs ────────────────────────────────────────────────
|
||||
{
|
||||
let src = readFileSync(join(here, "routers/helpers.mjs"), "utf8");
|
||||
src = src.replace(/export\s+const\s+([A-Za-z_$][\w$]*)\s*=/g, "const $1 =");
|
||||
src += "\nglobalThis.__helpers = { getTable, pickFilters, matchRow, paginate, listResponse, omitSensitive };";
|
||||
vm.runInContext(src, sandbox, { filename: "routers/helpers.mjs" });
|
||||
}
|
||||
|
||||
// ── getDb 桩:读 sandbox.__db ─────────────────────────────────────────
|
||||
sandbox.__getDb = async () => sandbox.__db;
|
||||
|
||||
// ── 载入被测路由 ──────────────────────────────────────────────────────
|
||||
const getEmployee = loadModule("routers/anki/employee.mjs");
|
||||
const getNotice = loadModule("routers/anki/notice.mjs");
|
||||
const getDynamic = loadModule("routers/dynamic.mjs");
|
||||
|
||||
// ── 假 router:收集路由表 ─────────────────────────────────────────────
|
||||
const routes = [];
|
||||
const router = {};
|
||||
for (const m of ["get", "post", "put", "delete"]) {
|
||||
router[m] = (path, handler) => routes.push({ method: m, path, handler });
|
||||
}
|
||||
getEmployee(router);
|
||||
getNotice(router);
|
||||
getDynamic(router);
|
||||
|
||||
const find = (method, path) => {
|
||||
const r = routes.find((x) => x.method === method && x.path === path);
|
||||
if (!r) throw new Error(`路由未注册: ${method.toUpperCase()} ${path}`);
|
||||
return r.handler;
|
||||
};
|
||||
|
||||
// ── 测试工具 ──────────────────────────────────────────────────────────
|
||||
const makeDb = (seed) => ({
|
||||
data: JSON.parse(JSON.stringify(seed)),
|
||||
write: async () => {},
|
||||
});
|
||||
|
||||
const makeCtx = ({ params = {}, query = {}, body = {} } = {}) => ({
|
||||
type: "",
|
||||
body: undefined,
|
||||
params,
|
||||
request: { query, body },
|
||||
});
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
const test = async (name, fn) => {
|
||||
try {
|
||||
await fn();
|
||||
passed++;
|
||||
console.log(` PASS ${name}`);
|
||||
} catch (err) {
|
||||
failed++;
|
||||
console.log(` FAIL ${name}`);
|
||||
console.log(` ${err.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 断言是「空数组」。
|
||||
* 不能直接用 assert.deepEqual(x, []):沙箱里创建的数组与主 realm 的 `[]`
|
||||
* 原型不同,Node 会判定为「结构相同但非同一引用」。这里只校验实质语义。
|
||||
*/
|
||||
const assertEmptyArray = (value, label = "值") => {
|
||||
assert.ok(Array.isArray(value), `${label} 不是数组: ${JSON.stringify(value)}`);
|
||||
assert.equal(value.length, 0, `${label} 应为空数组,实际长度 ${value.length}`);
|
||||
};
|
||||
|
||||
const seed = {
|
||||
employee: [
|
||||
{ id: "e1", userName: "admin", pwd: "123456", realName: "管理员" },
|
||||
{ id: "e2", userName: "staff", pwd: "654321", realName: "员工甲" },
|
||||
],
|
||||
Notice: [{ id: "n1", title: "公告一", sort: 1 }],
|
||||
leaseRecords: [{ id: "l1", name: "租赁单" }],
|
||||
};
|
||||
|
||||
// ══ 用例 ══════════════════════════════════════════════════════════════
|
||||
console.log("\n=== 服务端路由烟雾测试 ===\n");
|
||||
console.log("[员工路由]");
|
||||
|
||||
await test("list 不泄漏 pwd 明文", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: {} });
|
||||
await find("post", "/api/employee/list")(ctx);
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assert.equal(ctx.body.total, 2);
|
||||
for (const row of ctx.body.data) {
|
||||
assert.ok(!("pwd" in row), `pwd 泄漏: ${JSON.stringify(row)}`);
|
||||
}
|
||||
});
|
||||
|
||||
await test("list 在空表时不抛 500", async () => {
|
||||
sandbox.__db = makeDb({});
|
||||
const ctx = makeCtx({ body: {} });
|
||||
await find("post", "/api/employee/list")(ctx);
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assert.equal(ctx.body.total, 0);
|
||||
assertEmptyArray(ctx.body.data, "列表数据");
|
||||
});
|
||||
|
||||
await test("login 成功返回用户但不含 pwd", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { userName: "admin", pwd: "123456" } });
|
||||
await find("post", "/api/employee/login")(ctx);
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assert.equal(ctx.body.data.userName, "admin");
|
||||
assert.ok(!("pwd" in ctx.body.data));
|
||||
});
|
||||
|
||||
await test("login 失败不区分账号/密码错误(防枚举)", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const a = makeCtx({ body: { userName: "nobody", pwd: "x" } });
|
||||
const b = makeCtx({ body: { userName: "admin", pwd: "wrong" } });
|
||||
await find("post", "/api/employee/login")(a);
|
||||
await find("post", "/api/employee/login")(b);
|
||||
assert.equal(a.body.code, 1);
|
||||
assert.equal(b.body.code, 1);
|
||||
assert.equal(a.body.msg, b.body.msg);
|
||||
});
|
||||
|
||||
await test("add 拒绝重复用户名", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { userName: "admin", pwd: "x" } });
|
||||
await find("post", "/api/employee/add")(ctx);
|
||||
assert.equal(ctx.body.code, 1);
|
||||
assert.equal(sandbox.__db.data.employee.length, 2);
|
||||
});
|
||||
|
||||
await test("add 忽略请求体传入的 id / createTime", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { userName: "newbie", id: "HACKED", createTime: "1970-01-01" } });
|
||||
await find("post", "/api/employee/add")(ctx);
|
||||
const added = sandbox.__db.data.employee.find((x) => x.userName === "newbie");
|
||||
assert.ok(added, "新员工未写入");
|
||||
assert.notEqual(added.id, "HACKED");
|
||||
assert.notEqual(added.createTime, "1970-01-01");
|
||||
});
|
||||
|
||||
await test("upd 不能覆盖主键 id,且能改动业务字段", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { id: "e1", realName: "改名了", pwd: "newpwd" } });
|
||||
await find("post", "/api/employee/upd")(ctx);
|
||||
const row = sandbox.__db.data.employee.find((x) => x.id === "e1");
|
||||
assert.ok(row, "e1 丢失");
|
||||
assert.equal(row.id, "e1");
|
||||
assert.equal(row.realName, "改名了");
|
||||
});
|
||||
|
||||
await test("upd 目标不存在时返回业务错误而非 500", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { id: "not-exist", realName: "x" } });
|
||||
await find("post", "/api/employee/upd")(ctx);
|
||||
assert.equal(ctx.body.code, 1);
|
||||
});
|
||||
|
||||
await test("delete 只删指定记录并返回条数", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { ids: ["e1", "ghost"] } });
|
||||
await find("post", "/api/employee/delete")(ctx);
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assert.equal(ctx.body.data.deleted, 1);
|
||||
assert.equal(sandbox.__db.data.employee.length, 1);
|
||||
});
|
||||
|
||||
await test("delete 空 ids 被拒绝", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ body: { ids: [] } });
|
||||
await find("post", "/api/employee/delete")(ctx);
|
||||
assert.equal(ctx.body.code, 1);
|
||||
});
|
||||
|
||||
console.log("\n[通知路由]");
|
||||
|
||||
await test("Notice list 不因空表崩溃", async () => {
|
||||
sandbox.__db = makeDb({});
|
||||
const ctx = makeCtx({ body: {} });
|
||||
await find("post", "/api/Notice/list")(ctx);
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assertEmptyArray(ctx.body.data, "列表数据");
|
||||
});
|
||||
|
||||
console.log("\n[★ 致命缺陷回归:整库清空]");
|
||||
|
||||
await test("dynamic.upd 目标表缺失时不清空整库", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ params: { tableName: "brandNewTable" }, body: { id: "x", name: "y" } });
|
||||
await find("post", "/api/dynamic/upd/:tableName")(ctx);
|
||||
|
||||
assert.ok(Array.isArray(sandbox.__db.data.employee), "employee 表被清空了!");
|
||||
assert.equal(sandbox.__db.data.employee.length, 2);
|
||||
assert.ok(Array.isArray(sandbox.__db.data.Notice), "Notice 表被清空了!");
|
||||
assert.equal(sandbox.__db.data.Notice.length, 1);
|
||||
assert.ok(Array.isArray(sandbox.__db.data.leaseRecords), "leaseRecords 表被清空了!");
|
||||
assertEmptyArray(sandbox.__db.data.brandNewTable, "缺失的新表");
|
||||
});
|
||||
|
||||
await test("dynamic.delete 目标表缺失时不清空整库", async () => {
|
||||
sandbox.__db = makeDb(seed);
|
||||
const ctx = makeCtx({ params: { tableName: "anotherNewTable" }, body: { ids: ["a"] } });
|
||||
await find("post", "/api/dynamic/delete/:tableName")(ctx);
|
||||
|
||||
assert.equal(sandbox.__db.data.employee.length, 2, "employee 表被清空了!");
|
||||
assert.equal(sandbox.__db.data.Notice.length, 1, "Notice 表被清空了!");
|
||||
});
|
||||
|
||||
await test("dynamic.list 空表返回空数组而非 500", async () => {
|
||||
sandbox.__db = makeDb({});
|
||||
const ctx = makeCtx({ params: { tableName: "whatever" }, body: {} });
|
||||
await find("post", "/api/dynamic/list/:tableName")(ctx);
|
||||
assert.equal(ctx.body.code, 0);
|
||||
assertEmptyArray(ctx.body.data, "列表数据");
|
||||
assert.equal(ctx.body.total, 0);
|
||||
});
|
||||
|
||||
await test("dynamic.add 忽略请求体 id / createTime", async () => {
|
||||
sandbox.__db = makeDb({ whatever: [] });
|
||||
const ctx = makeCtx({ params: { tableName: "whatever" }, body: { id: "HACK", createTime: "0" } });
|
||||
await find("post", "/api/dynamic/add/:tableName")(ctx);
|
||||
const row = sandbox.__db.data.whatever[0];
|
||||
assert.ok(row, "未写入");
|
||||
assert.notEqual(row.id, "HACK");
|
||||
assert.notEqual(row.createTime, "0");
|
||||
});
|
||||
|
||||
await test("dynamic 分页参数生效", async () => {
|
||||
sandbox.__db = makeDb({ big: Array.from({ length: 25 }, (_, i) => ({ id: `b${i}`, n: i })) });
|
||||
const ctx = makeCtx({ params: { tableName: "big" }, body: { page: 2, pageSize: 10 } });
|
||||
await find("post", "/api/dynamic/list/:tableName")(ctx);
|
||||
assert.equal(ctx.body.total, 25);
|
||||
assert.equal(ctx.body.data.length, 10);
|
||||
assert.equal(ctx.body.data[0].id, "b10");
|
||||
});
|
||||
|
||||
// ── 汇总 ──────────────────────────────────────────────────────────────
|
||||
console.log(`\n=== 结果: ${passed} 通过 / ${failed} 失败 ===\n`);
|
||||
process.exit(failed === 0 ? 0 : 1);
|
||||
+49
-47
@@ -1,47 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
// This starter template is using Vue 3 <script setup> SFCs
|
||||
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
|
||||
import SystemMenu from './components/SystemMenu.vue';
|
||||
import SystemLayout from './components/SystemLayout.vue';
|
||||
import "element-plus/dist/index.css";
|
||||
import "funjiaui/dist/style.css";
|
||||
import * as funjiaui from "funjiaui";
|
||||
import axios from "funjia-axios";
|
||||
|
||||
window.funjiaui = funjiaui;
|
||||
window.axios = axios;
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<style lang="scss">
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
/* 滚动条 */
|
||||
::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
/* 滚动槽 */
|
||||
::-webkit-scrollbar-track {
|
||||
-webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* 滚动条滑块 */
|
||||
::-webkit-scrollbar-thumb {
|
||||
border-radius: 4px;
|
||||
background: #999;
|
||||
-webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
<script setup lang="ts">
|
||||
// This starter template is using Vue 3 <script setup> SFCs
|
||||
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
|
||||
import SystemMenu from './components/SystemMenu.vue';
|
||||
import SystemLayout from './components/SystemLayout.vue';
|
||||
import "element-plus/dist/index.css";
|
||||
// 注意:funjiaui 把样式放在包根目录(`style.css`),没有 `dist/` 子目录。
|
||||
// 改造前写的是 `funjiaui/dist/style.css`,该路径不存在,直接导致 `vite build` 失败。
|
||||
import "funjiaui/style.css";
|
||||
import * as funjiaui from "funjiaui";
|
||||
import axios from "funjia-axios";
|
||||
|
||||
window.funjiaui = funjiaui;
|
||||
window.axios = axios;
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<style lang="scss">
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
/* 滚动条 */
|
||||
::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
/* 滚动槽 */
|
||||
::-webkit-scrollbar-track {
|
||||
-webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.3);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* 滚动条滑块 */
|
||||
::-webkit-scrollbar-thumb {
|
||||
border-radius: 4px;
|
||||
background: #999;
|
||||
-webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
+159
-278
@@ -1,278 +1,159 @@
|
||||
import axios from "funjia-axios";
|
||||
// import imgList from "../../../public/data/image_cache.json";
|
||||
// import serviceInfo from "../../../public/data/get_service_info.json";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
export const login = (params: any): Promise<any> => {
|
||||
return axios.post("/api/login", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
export const udpdatePwd = (params: any): Promise<any> => {
|
||||
return axios.post("/api/user/password/update", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取系统信息
|
||||
*/
|
||||
export const getSytemInfo = (): Promise<any> => {
|
||||
return axios.get("/api/get/system");
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据ipcId获取抓拍图片列表
|
||||
*/
|
||||
export const getCaputreImgListByIpcId = (params: any): Promise<any> => {
|
||||
return axios.post("/api/query/device/obejct/image/cache", params);
|
||||
// return imgList;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取日志级别列表
|
||||
*/
|
||||
export const getLevelList = (): Promise<any> => {
|
||||
return axios.post("/api/get/log/level");
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取日志列表
|
||||
*/
|
||||
export const getLogList = (params: any): Promise<any> => {
|
||||
return axios.post("/api/get/log/last", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置日志级别
|
||||
*/
|
||||
export const setLogLevel = (params: any): Promise<any> => {
|
||||
return axios.post(`/set/log/level/${params.level}`, params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 重启系统
|
||||
*/
|
||||
export const restartSystem = (): Promise<any> => {
|
||||
return axios.get('/api/system/reboot');
|
||||
};
|
||||
|
||||
/**
|
||||
* 重启程序
|
||||
*/
|
||||
export const restartApp = (): Promise<any> => {
|
||||
return axios.get('/api/system/restart');
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取服务状态
|
||||
*/
|
||||
export const getServiceStatus = (): Promise<any> => {
|
||||
return axios.get('/get/service/info');
|
||||
// return serviceInfo;
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置服务
|
||||
*/
|
||||
export const setService = (params: any): Promise<any> => {
|
||||
return axios.post('/api/set/service/manager', params);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取TravelInformation列表
|
||||
*/
|
||||
export const getTravelInformationList = (params: any): Promise<any> => {
|
||||
return axios.post("/api/TravelInformation/list", params);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取TravelInformation详情
|
||||
*/
|
||||
export const getTravelInformation = (params: any): Promise<any> => {
|
||||
return axios.get("/api/travelInformation", { params });
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加TravelInformation
|
||||
*/
|
||||
export const addTravelInformation = (params: any): Promise<any> => {
|
||||
return axios.post("/api/TravelInformation/add", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改TravelInformation
|
||||
*/
|
||||
export const updateTravelInformation = (params: any): Promise<any> => {
|
||||
return axios.post("/api/TravelInformation/upd", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除TravelInformation
|
||||
*/
|
||||
export const deleteTravelInformation = (params: any): Promise<any> => {
|
||||
return axios.post("/api/TravelInformation/delete", params);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取Employee列表
|
||||
*/
|
||||
export const getEmployeeList = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Employee/list", params);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取Employee详情
|
||||
*/
|
||||
export const getEmployee = (params: any): Promise<any> => {
|
||||
return axios.get("/api/Employee", { params });
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加Employee
|
||||
*/
|
||||
export const addEmployee = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Employee/add", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改Employee
|
||||
*/
|
||||
export const updateEmployee = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Employee/upd", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除Employee
|
||||
*/
|
||||
export const deleteEmployee = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Employee/delete", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* Employee登录
|
||||
*/
|
||||
export const employeeLogin = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Employee/login", params);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取Notice列表
|
||||
*/
|
||||
export const getNoticeList = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Notice/list", params);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取Notice详情
|
||||
*/
|
||||
export const getNotice = (params: any): Promise<any> => {
|
||||
return axios.get("/api/Notice", { params });
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加Notice
|
||||
*/
|
||||
export const addNotice = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Notice/add", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改Notice
|
||||
*/
|
||||
export const updateNotice = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Notice/upd", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除Notice
|
||||
*/
|
||||
export const deleteNotice = (params: any): Promise<any> => {
|
||||
return axios.post("/api/Notice/delete", params);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取QA列表
|
||||
*/
|
||||
export const getQAList = (params: any): Promise<any> => {
|
||||
return axios.post("/api/QA/list", params);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取QA详情
|
||||
*/
|
||||
export const getQA = (params: any): Promise<any> => {
|
||||
return axios.get("/api/QA", { params });
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加QA
|
||||
*/
|
||||
export const addQA = (params: any): Promise<any> => {
|
||||
return axios.post("/api/QA/add", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改QA
|
||||
*/
|
||||
export const updateQA = (params: any): Promise<any> => {
|
||||
return axios.post("/api/QA/upd", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除QA
|
||||
*/
|
||||
export const deleteQA = (params: any): Promise<any> => {
|
||||
return axios.post("/api/QA/delete", params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取Dynamic列表
|
||||
*/
|
||||
export const getDynamicList = (params: any, tableName: string): Promise<any> => {
|
||||
return axios.post("/api/dynamic/list/" + tableName, params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取Dynamic详情
|
||||
*/
|
||||
export const getDynamic = (params: any, tableName: string): Promise<any> => {
|
||||
return axios.get("/api/dynamic/" + tableName, { params });
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加Dynamic
|
||||
*/
|
||||
export const addDynamic = (params: any, tableName: string): Promise<any> => {
|
||||
return axios.post("/api/dynamic/add/" + tableName, params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改Dynamic
|
||||
*/
|
||||
export const updateDynamic = (params: any, tableName: string): Promise<any> => {
|
||||
return axios.post("/api/dynamic/upd/" + tableName, params);
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除Dynamic
|
||||
*/
|
||||
export const deleteDynamic = (params: any, tableName: string): Promise<any> => {
|
||||
return axios.post("/api/dynamic/delete/" + tableName, params);
|
||||
};
|
||||
/**
|
||||
* 业务接口集合。
|
||||
*
|
||||
* 全部走 `funjia-axios` 实例(它内部已完成统一的鉴权、解包与错误提示),
|
||||
* 而不是裸 `axios`——改造前 Plugin.ts / upload 相关逻辑直接 import "axios",
|
||||
* 绕过了 token 注入。
|
||||
*/
|
||||
import http from "funjia-axios";
|
||||
|
||||
const post = <T = any>(url: string, params?: any): Promise<T> => http.post(url, params);
|
||||
const get = <T = any>(url: string, params?: any): Promise<T> =>
|
||||
params ? http.get(url, { params }) : http.get(url);
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 登录 / 用户
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/** 登录 */
|
||||
export const login = (params: any) => post("/api/login", params);
|
||||
|
||||
/** 员工登录 */
|
||||
export const employeeLogin = (params: any) => post("/api/Employee/login", params);
|
||||
|
||||
/** 修改密码 */
|
||||
export const udpdatePwd = (params: any) => post("/api/user/password/update", params);
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 系统
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/** 获取系统信息 */
|
||||
export const getSytemInfo = () => get("/api/get/system");
|
||||
|
||||
/** 重启系统 */
|
||||
export const restartSystem = () => get("/api/system/reboot");
|
||||
|
||||
/** 重启程序 */
|
||||
export const restartApp = () => get("/api/system/restart");
|
||||
|
||||
/** 获取服务状态 */
|
||||
export const getServiceStatus = () => get("/get/service/info");
|
||||
|
||||
/** 设置服务 */
|
||||
export const setService = (params: any) => post("/api/set/service/manager", params);
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 日志
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/** 获取日志级别列表 */
|
||||
export const getLevelList = () => post("/api/get/log/level");
|
||||
|
||||
/** 获取日志列表 */
|
||||
export const getLogList = (params: any) => post("/api/get/log/last", params);
|
||||
|
||||
/** 设置日志级别 */
|
||||
export const setLogLevel = (params: any) => post(`/set/log/level/${params.level}`, params);
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 抓拍图片
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/** 根据 ipcId 获取抓拍图片列表 */
|
||||
export const getCaputreImgListByIpcId = (params: any) =>
|
||||
post("/api/query/device/obejct/image/cache", params);
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 通用 CRUD 工厂
|
||||
*
|
||||
* TradeInformation / Employee / Notice / QA / dynamic 这几组接口的形态完全一致,
|
||||
* 只是路径前缀不同。改造前每个实体手写了 5 个函数、5 份 `(params: any) => Promise<any>`,
|
||||
* 共 30 个高度重复的函数声明。
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* 生成一组 CRUD 接口。
|
||||
*
|
||||
* @param name 接口路径段(如 `Employee`)
|
||||
* @param detailPath 详情接口路径。个别老接口的详情路径没有跟着列表路径走
|
||||
* (如 TravelInformation 的详情是小写 `travelInformation`),
|
||||
* 这里显式覆盖,而不是在工厂里塞特例判断。
|
||||
*/
|
||||
const resource = (name: string, detailPath = `/api/${name}`) => ({
|
||||
/** 列表 */
|
||||
getList: (params?: any) => post(`/api/${name}/list`, params),
|
||||
/** 详情 */
|
||||
get: (params: any) => get(detailPath, params),
|
||||
/** 新增 */
|
||||
add: (params: any) => post(`/api/${name}/add`, params),
|
||||
/** 修改 */
|
||||
update: (params: any) => post(`/api/${name}/upd`, params),
|
||||
/** 删除 */
|
||||
remove: (params: any) => post(`/api/${name}/delete`, params),
|
||||
});
|
||||
|
||||
export const travelInformationApi = resource("TravelInformation", "/api/travelInformation");
|
||||
export const employeeApi = resource("Employee");
|
||||
export const noticeApi = resource("Notice");
|
||||
export const qaApi = resource("QA");
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 兼容导出:保持既有 `api.getXxxList` 调用方式不变
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
export const getTravelInformationList = travelInformationApi.getList;
|
||||
export const getTravelInformation = travelInformationApi.get;
|
||||
export const addTravelInformation = travelInformationApi.add;
|
||||
export const updateTravelInformation = travelInformationApi.update;
|
||||
export const deleteTravelInformation = travelInformationApi.remove;
|
||||
|
||||
export const getEmployeeList = employeeApi.getList;
|
||||
export const getEmployee = employeeApi.get;
|
||||
export const addEmployee = employeeApi.add;
|
||||
export const updateEmployee = employeeApi.update;
|
||||
export const deleteEmployee = employeeApi.remove;
|
||||
|
||||
export const getNoticeList = noticeApi.getList;
|
||||
export const getNotice = noticeApi.get;
|
||||
export const addNotice = noticeApi.add;
|
||||
export const updateNotice = noticeApi.update;
|
||||
export const deleteNotice = noticeApi.remove;
|
||||
|
||||
export const getQAList = qaApi.getList;
|
||||
export const getQA = qaApi.get;
|
||||
export const addQA = qaApi.add;
|
||||
export const updateQA = qaApi.update;
|
||||
export const deleteQA = qaApi.remove;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 动态表(表名在 URL 上)
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
const dynamicPrefix = (tableName: string) => `/api/dynamic/${tableName}`;
|
||||
|
||||
export const getDynamicList = (params: any, tableName: string) =>
|
||||
post(`/api/dynamic/list/${tableName}`, params);
|
||||
|
||||
export const getDynamic = (params: any, tableName: string) =>
|
||||
get(dynamicPrefix(tableName), params);
|
||||
|
||||
export const addDynamic = (params: any, tableName: string) =>
|
||||
post(`${dynamicPrefix(tableName)}/add`, params);
|
||||
|
||||
export const updateDynamic = (params: any, tableName: string) =>
|
||||
post(`${dynamicPrefix(tableName)}/upd`, params);
|
||||
|
||||
export const deleteDynamic = (params: any, tableName: string) =>
|
||||
post(`${dynamicPrefix(tableName)}/delete`, params);
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* 文件上传
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
/** 上传文件,返回可直接访问的 url */
|
||||
export const uploadFile = (file: File) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
return post("/api/upload/file", formData);
|
||||
};
|
||||
|
||||
+116
-116
@@ -1,116 +1,116 @@
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import Cookies from "js-cookie";
|
||||
import 'element-plus/es/components/message/style/css'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
// axios.defaults.baseURL = ""; // 请求后台地址
|
||||
axios.defaults.headers.post["Content-Type"] = "application/json;charset=utf-8";
|
||||
|
||||
interface LogOutCodesProps {
|
||||
status: number;
|
||||
code: number;
|
||||
msg?: string;
|
||||
}
|
||||
|
||||
axios.interceptors.request.use(
|
||||
(config: AxiosRequestConfig) => {
|
||||
// token授权
|
||||
const jwtToken: string = Cookies.get("Authorization") ?? "";
|
||||
config.headers = config.headers || {};
|
||||
config.headers.Authorization = `${jwtToken}`;
|
||||
// 缓存问题
|
||||
config.headers["Cache-Control"] = "no-cache";
|
||||
return config;
|
||||
},
|
||||
(err) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
|
||||
axios.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
const xhr: any = response.data ?? {};
|
||||
const { code, msg: resultMsg } = xhr;
|
||||
// 需要退出重登的code和msg
|
||||
let msg: string = "";
|
||||
switch (code) {
|
||||
case 9:
|
||||
msg = "请重新登录";
|
||||
break;
|
||||
case 18:
|
||||
msg = "授权过期,请重新登录";
|
||||
break;
|
||||
case 27:
|
||||
msg = "未安装License或License已过期";
|
||||
break;
|
||||
case 28:
|
||||
msg = "License权限不足";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (code) {
|
||||
ElMessage.error(msg || resultMsg || "系统异常");
|
||||
}
|
||||
return xhr;
|
||||
},
|
||||
(error) => {
|
||||
const response: any = error.response ?? {};
|
||||
const { data, status } = response;
|
||||
const { code, reason } = data;
|
||||
let msg: string = "";
|
||||
// 获取错误提示
|
||||
switch (status) {
|
||||
case 400:
|
||||
msg =
|
||||
code === 17
|
||||
? `异地登录,登录IP为${data.data},请重新登录`
|
||||
: "请求错误";
|
||||
break;
|
||||
case 401:
|
||||
msg = reason || "鉴权失败";
|
||||
break;
|
||||
case 403:
|
||||
msg = "拒绝访问";
|
||||
break;
|
||||
case 404:
|
||||
msg = "请求错误,未找到该资源";
|
||||
break;
|
||||
case 405:
|
||||
msg = "请求方法未允许";
|
||||
break;
|
||||
case 408:
|
||||
msg = "请求超时";
|
||||
break;
|
||||
case 413:
|
||||
msg = "请求数据过多";
|
||||
break;
|
||||
case 500:
|
||||
msg = "服务器端出错";
|
||||
break;
|
||||
case 501:
|
||||
msg = "网络未实现";
|
||||
break;
|
||||
case 503:
|
||||
msg = "服务不可用";
|
||||
break;
|
||||
case 504:
|
||||
msg = "网络超时";
|
||||
break;
|
||||
case 505:
|
||||
msg = "http版本不支持该请求";
|
||||
break;
|
||||
case 502:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ElMessage.error(msg);
|
||||
return Promise.reject(error).catch(() => {
|
||||
if (401 == status) {
|
||||
window.location.href = "/";
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default axios;
|
||||
/**
|
||||
* 请求层统一收口。
|
||||
*
|
||||
* ## 改造前的两个真实缺陷
|
||||
*
|
||||
* 1. **错误提示完全静默**:依赖 `funjia-axios` 的 `index.ts` 里写了
|
||||
* `axios.prototype.error = (msg) => {}` 和 `axios.prototype(msg)`——
|
||||
* `axios.prototype` 是 undefined,调用会抛 TypeError;而 `error` 又是个空函数。
|
||||
* 结果:**所有接口错误(含 401 鉴权失败)都不会给用户任何提示**,
|
||||
* 页面只是静静地不刷新,排查全靠猜。
|
||||
*
|
||||
* 2. **两份重复且会互相打架的拦截器**:`funjia-axios` 和本项目的 `common/axios.ts`
|
||||
* 各注册了一份。而 `common/axios.ts` 改的是 `import axios from "axios"` 拿到的
|
||||
* **全局默认实例**,业务代码走的是 `funjia-axios`——于是这份拦截器形同虚设,
|
||||
* 谁都不清楚提示到底由谁负责。
|
||||
*
|
||||
* 现在:本文件是唯一的拦截器注册点,`src/common/api` 全部经它出入。
|
||||
*/
|
||||
import axios from "funjia-axios";
|
||||
import type { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import Cookies from "js-cookie";
|
||||
import { ElMessage } from "element-plus";
|
||||
import "element-plus/es/components/message/style/css";
|
||||
|
||||
/** 需要强制重新登录的业务 code */
|
||||
const RELOGIN_CODES: Record<number, string> = {
|
||||
9: "请重新登录",
|
||||
18: "授权过期,请重新登录",
|
||||
27: "未安装License或License已过期",
|
||||
28: "License权限不足",
|
||||
};
|
||||
|
||||
/** HTTP 状态码 → 提示文案 */
|
||||
const STATUS_MESSAGES: Record<number, string> = {
|
||||
400: "请求错误",
|
||||
401: "鉴权失败",
|
||||
403: "拒绝访问",
|
||||
404: "请求错误,未找到该资源",
|
||||
405: "请求方法未允许",
|
||||
408: "请求超时",
|
||||
413: "请求数据过多",
|
||||
500: "服务器端出错",
|
||||
501: "网络未实现",
|
||||
502: "网关错误",
|
||||
503: "服务不可用",
|
||||
504: "网络超时",
|
||||
505: "http版本不支持该请求",
|
||||
};
|
||||
|
||||
/** 401 时跳转登录页,避免重复跳转 */
|
||||
let redirecting = false;
|
||||
const redirectToLogin = () => {
|
||||
if (redirecting) return;
|
||||
redirecting = true;
|
||||
window.location.href = "/";
|
||||
};
|
||||
|
||||
/** 同一文案在短时间内只弹一次,避免列表页并发请求刷屏 */
|
||||
let lastMessage = "";
|
||||
let lastMessageAt = 0;
|
||||
const notifyError = (message: string) => {
|
||||
const now = Date.now();
|
||||
if (message === lastMessage && now - lastMessageAt < 1500) return;
|
||||
lastMessage = message;
|
||||
lastMessageAt = now;
|
||||
ElMessage.error(message);
|
||||
};
|
||||
|
||||
axios.interceptors.request.use(
|
||||
(config: any) => {
|
||||
const jwtToken: string = Cookies.get("Authorization") ?? "";
|
||||
config.headers = config.headers || {};
|
||||
config.headers.Authorization = `${jwtToken}`;
|
||||
// 缓存问题
|
||||
config.headers["Cache-Control"] = "no-cache";
|
||||
return config;
|
||||
},
|
||||
(err: any) => Promise.reject(err)
|
||||
);
|
||||
|
||||
axios.interceptors.response.use(
|
||||
(response: any) => {
|
||||
const xhr: any = response.data ?? {};
|
||||
const { code, msg: resultMsg } = xhr;
|
||||
|
||||
// 只有明确的失败码才提示。
|
||||
// 注意不能写成 `if (code)`:成功时 code === 0 靠 falsy 侥幸绕过,
|
||||
// 一旦后端改用别的成功码(例如 200)就会把成功响应当错误弹提示。
|
||||
if (code !== undefined && code !== null && code !== 0) {
|
||||
notifyError(RELOGIN_CODES[code] || resultMsg || "系统异常");
|
||||
}
|
||||
// 保持解包行为:业务侧直接拿到 { code, data, msg, total }
|
||||
return xhr;
|
||||
},
|
||||
(error: any) => {
|
||||
const response: any = error.response ?? {};
|
||||
const { data, status } = response;
|
||||
const { code, reason } = data ?? {};
|
||||
|
||||
let msg: string;
|
||||
if (status === 400 && code === 17) {
|
||||
msg = `异地登录,登录IP为${data?.data},请重新登录`;
|
||||
} else {
|
||||
msg = reason || STATUS_MESSAGES[status] || "";
|
||||
}
|
||||
if (msg) notifyError(msg);
|
||||
|
||||
if (status === 401) redirectToLogin();
|
||||
|
||||
// 改造前这里是 `Promise.reject(error).catch(...)`,
|
||||
// 会在末尾多挂一个被吞掉的 rejection,这里直接 reject。
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default axios;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 统一的接口返回结构。
|
||||
*
|
||||
* 后端所有接口都遵循 `{ code, data, msg?, total? }` 的约定:
|
||||
* - `code === 0` 表示业务成功
|
||||
* - 其余值按 `interceptor` 中登记的错误码转换为用户可读文案
|
||||
*/
|
||||
export interface ApiResult<T = any> {
|
||||
code: number;
|
||||
data: T;
|
||||
msg?: string;
|
||||
total?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格组件的“方法装饰器”回调只认 `{ code, message }`:
|
||||
* - `code === 0` 视为成功,组件弹出“操作成功”并刷新列表
|
||||
* - `code !== 0` 时,组件用 `message` 弹出错误提示
|
||||
*/
|
||||
export interface OperateResult {
|
||||
code: 0 | 1;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把接口返回转换成表格组件期望的操作结果,统一收敛成功/失败判定逻辑。
|
||||
*
|
||||
* 改造前每个 viewModel 的 onAdd / onEdit / delByIds 都重复写了
|
||||
* 4 遍 `if (code != 0) return { code: 1, message: msg }`,共 7 个文件 20+ 处。
|
||||
*
|
||||
* @param res 接口返回(`funjia-axios` 已被响应拦截器解包,直接透传业务对象)
|
||||
*/
|
||||
export const toOperateResult = (res: Partial<ApiResult> | null | undefined): OperateResult => {
|
||||
if (res && res.code === 0) {
|
||||
return { code: 0 };
|
||||
}
|
||||
return { code: 1, message: res?.msg || "操作失败" };
|
||||
};
|
||||
+21
-147
@@ -1,147 +1,21 @@
|
||||
/**
|
||||
* 获取目标类型的名称 0:人脸, 1:自行车, 2:巴士, 3:小汽车, 4:电动车|摩托车, 5:人体, 6:三轮车,7货车、8车牌、9推车,10鸟、11猫,12 狗,13老鼠
|
||||
* @param objectType
|
||||
* @returns
|
||||
*/
|
||||
export const getObjectTypeName = (objectType: TObjectType) => {
|
||||
switch (objectType) {
|
||||
case 0:
|
||||
return "人脸";
|
||||
case 1:
|
||||
return "自行车";
|
||||
case 2:
|
||||
return "巴士";
|
||||
case 3:
|
||||
return "小汽车";
|
||||
case 4:
|
||||
return "电动车|摩托车";
|
||||
case 5:
|
||||
return "人体";
|
||||
case 6:
|
||||
return "三轮车";
|
||||
case 7:
|
||||
return "货车";
|
||||
case 8:
|
||||
return "车牌";
|
||||
case 9:
|
||||
return "推车";
|
||||
case 10:
|
||||
return "鸟";
|
||||
case 11:
|
||||
return "猫";
|
||||
case 12:
|
||||
return "狗";
|
||||
case 13:
|
||||
return "老鼠";
|
||||
default:
|
||||
return "--";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 解决加减乘除中浮点数精度问题
|
||||
|
||||
/**
|
||||
* arg1 第一位数字
|
||||
* arg2 第二位数字
|
||||
* type 运算符类型 加add, 减reduce,乘ride,除except
|
||||
*/
|
||||
export const FloatPoint = (arg1: number, arg2: number, type: 'add' | 'reduce' | 'ride' | 'except') => {
|
||||
let r1: number = 0;
|
||||
let r2: number = 0;
|
||||
try {
|
||||
r1 = arg1.toString().split(".")[1].length;
|
||||
} catch (e) {
|
||||
r1 = 0;
|
||||
}
|
||||
try {
|
||||
r2 = arg2.toString().split(".")[1].length;
|
||||
} catch (e) {
|
||||
r2 = 0;
|
||||
}
|
||||
const c: number = Math.abs(r1 - r2); // 位数差的绝对值
|
||||
const m: number = Math.pow(10, Math.max(r1, r2)); // 较大数的幂
|
||||
if (c > 0) {
|
||||
// 位数相差
|
||||
const cm: number = Math.pow(10, c);
|
||||
if (r1 > r2) {
|
||||
arg1 = Number(arg1.toString().replace(".", "")); // 转化成数字
|
||||
arg2 = Number(arg2.toString().replace(".", "")) * cm;
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace(".", "")) * cm;
|
||||
arg2 = Number(arg2.toString().replace(".", ""));
|
||||
}
|
||||
} else { // 位数相等
|
||||
arg1 = Number(arg1.toString().replace(".", ""));
|
||||
arg2 = Number(arg2.toString().replace(".", ""));
|
||||
}
|
||||
let res: any = null;
|
||||
if (type === 'add') {
|
||||
res = (arg1 + arg2) / m;
|
||||
} else if (type === 'reduce') {
|
||||
res = (arg1 - arg2) / m;
|
||||
} else if (type === 'ride') {
|
||||
res = (arg1 * arg2) / m / m;
|
||||
} else if (type === 'except') {
|
||||
res = (arg1 / arg2);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* 对字符串保留小数
|
||||
* @param value 原始值,有可能大于1
|
||||
* @param num 位数
|
||||
*/
|
||||
export const toFixed = (str: any, num: number = 2) => {
|
||||
try {
|
||||
if (typeof (str) === "string") {
|
||||
str = parseFloat(str);
|
||||
} else if (typeof (str) === "number") {
|
||||
str = str;
|
||||
} else {
|
||||
str = parseFloat(str);
|
||||
}
|
||||
str = FloatPoint(str, 100, 'ride');
|
||||
str = str.toString(); // 字符串值
|
||||
const pointIdx = str.indexOf("."); // 字符串中小数点的位置
|
||||
if (pointIdx !== -1) {
|
||||
if (num > 0) {
|
||||
// 存在小数点的情况下
|
||||
// 最多保留num位小数
|
||||
str = str.substring(0, pointIdx + (num + 1));
|
||||
// 小数位小于num位的情况下,在末尾补零
|
||||
const decimalStr = str.substring(pointIdx + 1); // 小数位字符串
|
||||
if (decimalStr.length < num) {
|
||||
for (let i = 0; i < num - decimalStr.length; i++) {
|
||||
str += "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
str = str.substring(0, pointIdx);
|
||||
return parseFloat(str);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return 0;
|
||||
}
|
||||
return parseFloat(str);
|
||||
}
|
||||
|
||||
export function encode(str) {
|
||||
// 对字符串进行编码
|
||||
const encode = encodeURI(str);
|
||||
// 对编码的字符串转化base64
|
||||
const base64 = btoa(encode);
|
||||
return base64;
|
||||
}
|
||||
|
||||
export function decode(base64) {
|
||||
// 对base64转编码
|
||||
const decode = atob(base64);
|
||||
// 编码转字符串
|
||||
const str = decodeURI(decode);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用工具函数。
|
||||
*
|
||||
* 改造前这里有 5 个导出,其中 4 个全项目零引用:
|
||||
* `getObjectTypeName`(且 `ImageCell.vue` 曾引用它却拿不到,编译报错)、
|
||||
* `FloatPoint`、`toFixed`、`decode`。这些配套的「图片抓拍识别」逻辑
|
||||
* 已随 `ImageList.vue` 一同下线,这里只保留仍在使用的编解码能力。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 字符串编码:先做 URI 编码再转 base64。
|
||||
* 用于密码等字段的传输前处理(见 `containers/PwdDialog`)。
|
||||
*/
|
||||
export function encode(str: string): string {
|
||||
return btoa(encodeURI(str));
|
||||
}
|
||||
|
||||
/** `encode` 的逆运算 */
|
||||
export function decode(base64: string): string {
|
||||
return decodeURI(atob(base64));
|
||||
}
|
||||
|
||||
@@ -1,47 +1,31 @@
|
||||
<template>
|
||||
<codemirror v-model="value" placeholder="Code goes here..." :style="{ height: '400px' }" :autofocus="true"
|
||||
:indent-with-tab="true" :tab-size="2" :extensions="extensions" @ready="handleReady" @change="log('change', $event)"
|
||||
@focus="log('focus', $event)" @blur="log('blur', $event)" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue'
|
||||
import { Codemirror } from 'vue-codemirror'
|
||||
import { javascript } from '@codemirror/lang-javascript'
|
||||
// import { oneDark } from '@codemirror/theme-one-dark'
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
Codemirror
|
||||
},
|
||||
setup() {
|
||||
const code = ref(`console.log('Hello, world!')`)
|
||||
const extensions = [javascript()]
|
||||
|
||||
// Codemirror EditorView instance ref
|
||||
const view = shallowRef()
|
||||
const handleReady = (payload) => {
|
||||
view.value = payload.view
|
||||
}
|
||||
|
||||
// Status is available at all times via Codemirror EditorView
|
||||
const getCodemirrorStates = () => {
|
||||
const state = view.value.state
|
||||
const ranges = state.selection.ranges
|
||||
const selected = ranges.reduce((r, range) => r + range.to - range.from, 0)
|
||||
const cursor = ranges[0].anchor
|
||||
const length = state.doc.length
|
||||
const lines = state.doc.lines
|
||||
// more state info ...
|
||||
// return ...
|
||||
}
|
||||
|
||||
return {
|
||||
value,
|
||||
extensions,
|
||||
handleReady,
|
||||
log: console.log
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<template>
|
||||
<codemirror v-model="value" placeholder="Code goes here..." :style="{ height: '400px' }" :autofocus="true"
|
||||
:indent-with-tab="true" :tab-size="2" :extensions="extensions" @ready="handleReady" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* CodeMirror 表单字段包装组件(qa.question / qa.answer 在用)。
|
||||
*
|
||||
* 改造前是 `defineComponent` + `setup()` 写法,但文件里从未引入
|
||||
* `ref` / `shallowRef`——它指望 `unplugin-auto-import` 兜底,可 `vite.config.ts`
|
||||
* 的 `AutoImport` 只注册了 ElementPlus resolver,不含 vue 的 API
|
||||
* (`auto-imports.d.ts` 是空文件即为佐证),运行时会直接
|
||||
* `ref is not defined`。这里改为显式 import + `<script setup>`。
|
||||
*
|
||||
* 同时移除了 `@change="log('change', $event)"` 这类把 console.log 挂到
|
||||
* 每次按键上的调试残留(生产构建虽然 drop_console,但本地开发会刷屏)。
|
||||
*/
|
||||
import { ref, shallowRef } from "vue";
|
||||
import { Codemirror } from "vue-codemirror";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
|
||||
const value = ref("");
|
||||
const extensions = [javascript()];
|
||||
// Codemirror EditorView 实例引用
|
||||
const view = shallowRef();
|
||||
|
||||
const handleReady = (payload: any) => {
|
||||
view.value = payload.view;
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,57 +1,76 @@
|
||||
<template>
|
||||
<el-tag v-for="tag in dynamicTags" :key="tag" class="mx-1" closable :disable-transitions="false"
|
||||
@close="handleClose(tag)">
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
<el-input v-if="inputVisible" ref="InputRef" v-model="inputValue" class="ml-1 w-20" size="small"
|
||||
@keyup.enter="handleInputConfirm" @blur="handleInputConfirm" />
|
||||
<el-button v-else class="button-new-tag ml-1" size="small" @click="showInput">
|
||||
+ New Tag
|
||||
</el-button>
|
||||
</template>
|
||||
<style scoped>
|
||||
.mx-1 {
|
||||
margin-left: 0.25rem;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, ref } from 'vue'
|
||||
import { ElInput } from 'element-plus'
|
||||
|
||||
const props = defineProps<{ modelValue: [] }>();
|
||||
const emits = defineEmits<{
|
||||
(
|
||||
e: "update:modelValue",
|
||||
val: string | number | (string | number)[] | undefined
|
||||
): void;
|
||||
}>();
|
||||
|
||||
const inputValue = ref('')
|
||||
const dynamicTags = ref(props.modelValue)
|
||||
const inputVisible = ref(false)
|
||||
const InputRef = ref<InstanceType<typeof ElInput>>()
|
||||
|
||||
const handleClose = (tag: string) => {
|
||||
dynamicTags.value.splice(dynamicTags.value.indexOf(tag), 1)
|
||||
emits('update:modelValue', dynamicTags.value)
|
||||
}
|
||||
|
||||
const showInput = () => {
|
||||
inputVisible.value = true
|
||||
nextTick(() => {
|
||||
InputRef.value!.input!.focus()
|
||||
})
|
||||
}
|
||||
|
||||
const handleInputConfirm = () => {
|
||||
if (inputValue.value) {
|
||||
dynamicTags.value.push(inputValue.value)
|
||||
emits('update:modelValue', dynamicTags.value)
|
||||
}
|
||||
inputVisible.value = false
|
||||
inputValue.value = ''
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<el-tag v-for="tag in dynamicTags" :key="tag" class="mx-1" closable :disable-transitions="false"
|
||||
@close="handleClose(tag)">
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
<el-input v-if="inputVisible" ref="InputRef" v-model="inputValue" class="ml-1 w-20" size="small"
|
||||
@keyup.enter="handleInputConfirm" @blur="handleInputConfirm" />
|
||||
<el-button v-else class="button-new-tag ml-1" size="small" @click="showInput">
|
||||
+ New Tag
|
||||
</el-button>
|
||||
</template>
|
||||
<style scoped>
|
||||
.mx-1 {
|
||||
margin-left: 0.25rem;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, ref, watch } from 'vue'
|
||||
import { ElInput } from 'element-plus'
|
||||
|
||||
/**
|
||||
* 标签输入组件。
|
||||
*
|
||||
* 改造前 `defineProps<{ modelValue: [] }>()` 里的 `[]` 是**空元组类型**而非数组类型,
|
||||
* 于是 `dynamicTags.value.push(...)` 的参数被推断为 `never`,`vue-tsc` 直接报错。
|
||||
*
|
||||
* 另外本地副本 `dynamicTags` 从不跟随 props 变化(父组件改了值这里不刷新),
|
||||
* 这里补上同步。
|
||||
*/
|
||||
const props = withDefaults(defineProps<{ modelValue?: (string | number)[] }>(), {
|
||||
modelValue: () => [],
|
||||
});
|
||||
const emits = defineEmits<{
|
||||
(
|
||||
e: "update:modelValue",
|
||||
val: (string | number)[] | undefined
|
||||
): void;
|
||||
}>();
|
||||
|
||||
const inputValue = ref('')
|
||||
const dynamicTags = ref<(string | number)[]>([...props.modelValue])
|
||||
const inputVisible = ref(false)
|
||||
const InputRef = ref<InstanceType<typeof ElInput>>()
|
||||
|
||||
// 外部值变化时同步本地副本
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
dynamicTags.value = [...(val ?? [])];
|
||||
}
|
||||
)
|
||||
|
||||
const handleClose = (tag: string | number) => {
|
||||
dynamicTags.value.splice(dynamicTags.value.indexOf(tag), 1)
|
||||
emits('update:modelValue', dynamicTags.value)
|
||||
}
|
||||
|
||||
const showInput = () => {
|
||||
inputVisible.value = true
|
||||
nextTick(() => {
|
||||
InputRef.value?.input?.focus()
|
||||
})
|
||||
}
|
||||
|
||||
const handleInputConfirm = () => {
|
||||
if (inputValue.value) {
|
||||
dynamicTags.value.push(inputValue.value)
|
||||
emits('update:modelValue', dynamicTags.value)
|
||||
}
|
||||
inputVisible.value = false
|
||||
inputValue.value = ''
|
||||
}
|
||||
</script>
|
||||
|
||||
+229
-229
@@ -1,230 +1,230 @@
|
||||
<template>
|
||||
<div :class="$style['img-preview']">
|
||||
<vue-cropper :key="id" ref="cropper" :src="imgUrl" alt="" :autoCrop="false" dragMode="move" :background="false"
|
||||
:viewMode="2" :toggleDragModeOnDblclick="false" @ready="onReady" @crop="onCrop" @zoom="onZoom" />
|
||||
<div :class="$style['mask']">
|
||||
<calc-rect-dock :top="rectPosition.top" :right="rectPosition.right" :bottom="rectPosition.bottom"
|
||||
:left="rectPosition.left"></calc-rect-dock>
|
||||
</div>
|
||||
<div :class="$style['prev']" @click="$emit('imgIdxChange', -1)">
|
||||
<el-icon>
|
||||
<d-arrow-left />
|
||||
</el-icon>
|
||||
</div>
|
||||
<div :class="$style['next']" @click="$emit('imgIdxChange', 1)">
|
||||
<el-icon>
|
||||
<d-arrow-right />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import VueCropper from 'vue-cropperjs';
|
||||
import 'cropperjs/dist/cropper.css';
|
||||
import { reactive, ref, onBeforeMount, watch } from "vue";
|
||||
import { computed } from '@vue/reactivity';
|
||||
import { merge, cloneDeep } from "lodash-es";
|
||||
import {
|
||||
DArrowLeft,
|
||||
DArrowRight,
|
||||
} from "@element-plus/icons-vue";
|
||||
|
||||
const props = defineProps<{
|
||||
id: "",
|
||||
imgUrl: "",
|
||||
position: "",
|
||||
}>();
|
||||
|
||||
defineEmits<{
|
||||
(n: 'imgIdxChange', value: TImgPreviewIdx): void
|
||||
}>();
|
||||
|
||||
const cropper = ref();
|
||||
const cropOption = reactive({
|
||||
ratio: 1,
|
||||
delta: { deltaX: 0, deltaY: 0 }
|
||||
});
|
||||
const rectPosition = reactive({
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
left: 0
|
||||
});
|
||||
const defRatio = ref(0);
|
||||
|
||||
onBeforeMount(() => {
|
||||
initRectPosition();
|
||||
})
|
||||
|
||||
watch([cropOption, () => props.id], () => {
|
||||
initRectPosition();
|
||||
})
|
||||
|
||||
const initRectPosition = () => {
|
||||
const rectOption: any = formatRectPosition(cloneDeep(props.position)) || {};
|
||||
merge(rectPosition, getStyle(rectOption));
|
||||
}
|
||||
|
||||
const initCropOption = (e) => {
|
||||
const canvasData: any = e.target?.cropper?.canvasData;
|
||||
if (canvasData) {
|
||||
if (e?.detail?.ratio && e.detail.ratio >= defRatio.value) {
|
||||
merge(cropOption, {
|
||||
ratio: e.detail.ratio,
|
||||
delta: {
|
||||
deltaX: canvasData.left,
|
||||
deltaY: canvasData.top
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
merge(cropOption, {
|
||||
delta: {
|
||||
deltaX: canvasData.left,
|
||||
deltaY: canvasData.top
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片渲染完成事件
|
||||
* @param e
|
||||
*/
|
||||
const onReady = (e: any) => {
|
||||
const canvasData: any = e.target?.cropper?.canvasData;
|
||||
if (canvasData) {
|
||||
defRatio.value = canvasData.width / e.target.width;
|
||||
merge(cropOption, {
|
||||
ratio: defRatio.value,
|
||||
delta: { deltaX: 0, deltaY: 0 }
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const onCrop = (e) => {
|
||||
initCropOption(e);
|
||||
}
|
||||
|
||||
const onZoom = (e) => {
|
||||
initCropOption(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化矩形框位置信息
|
||||
* @param position json字符串
|
||||
*/
|
||||
const formatRectPosition = (position: any) => {
|
||||
const fpm: any = {};
|
||||
let rectInfo: any = {};
|
||||
if (typeof (position) === "string") {
|
||||
try {
|
||||
rectInfo = JSON.parse(position);
|
||||
const { face_rect, object_rect } = rectInfo;
|
||||
if (face_rect) {
|
||||
fpm.top = face_rect.top;
|
||||
fpm.right = face_rect.right;
|
||||
fpm.bottom = face_rect.bottom;
|
||||
fpm.left = face_rect.left;
|
||||
}
|
||||
else if (object_rect) {
|
||||
fpm.top = object_rect.top;
|
||||
fpm.right = object_rect.right;
|
||||
fpm.bottom = object_rect.bottom;
|
||||
fpm.left = object_rect.left;
|
||||
fpm.type = 2;//ERectType.Body;
|
||||
}
|
||||
return fpm;
|
||||
} catch (error) {
|
||||
console.warn("小图位置信息有误", position);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (position.face_rect) {
|
||||
return position.face_rect;
|
||||
}
|
||||
else if (position.object_rect) {
|
||||
return position.object_rect;
|
||||
}
|
||||
}
|
||||
console.warn("小图位置信息有误", position);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位矩形框
|
||||
*/
|
||||
const getStyle = (position: any) => {
|
||||
const faceRect = position;
|
||||
const { ratio, delta } = cropOption;
|
||||
if (ratio != -1) {
|
||||
for (const item in faceRect) {
|
||||
if (["top", "right", "bottom", "left"].includes(item))
|
||||
faceRect[item] = parseFloat(faceRect[item]) * ratio
|
||||
}
|
||||
}
|
||||
return {
|
||||
top: faceRect.top + delta.deltaY,
|
||||
left: faceRect.left + delta.deltaX,
|
||||
bottom: faceRect.bottom + delta.deltaY,
|
||||
right: faceRect.right + delta.deltaX,
|
||||
};
|
||||
}
|
||||
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.img-preview) {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:local(.mask) {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
|
||||
:local(.prev),
|
||||
:local(.next) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
:local(.prev),
|
||||
:local(.next) {
|
||||
position: absolute;
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
top: 50%;
|
||||
transform: translate(0, -50%);
|
||||
background-color: rgb(10 10 10 / 20%);
|
||||
line-height: 100px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: none;
|
||||
pointer-events: painted;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
:local(.prev) {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
:local(.next) {
|
||||
right: 0;
|
||||
transform: translate(0, -50%);
|
||||
}
|
||||
}
|
||||
}
|
||||
<template>
|
||||
<div :class="$style['img-preview']">
|
||||
<vue-cropper :key="id" ref="cropper" :src="imgUrl" alt="" :autoCrop="false" dragMode="move" :background="false"
|
||||
:viewMode="2" :toggleDragModeOnDblclick="false" @ready="onReady" @crop="onCrop" @zoom="onZoom" />
|
||||
<div :class="$style['mask']">
|
||||
<calc-rect-dock :top="rectPosition.top" :right="rectPosition.right" :bottom="rectPosition.bottom"
|
||||
:left="rectPosition.left"></calc-rect-dock>
|
||||
</div>
|
||||
<div :class="$style['prev']" @click="$emit('imgIdxChange', -1)">
|
||||
<el-icon>
|
||||
<d-arrow-left />
|
||||
</el-icon>
|
||||
</div>
|
||||
<div :class="$style['next']" @click="$emit('imgIdxChange', 1)">
|
||||
<el-icon>
|
||||
<d-arrow-right />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import VueCropper from 'vue-cropperjs';
|
||||
import 'cropperjs/dist/cropper.css';
|
||||
import { reactive, ref, onBeforeMount, watch } from "vue";
|
||||
import { computed } from '@vue/reactivity';
|
||||
import { merge, cloneDeep } from "lodash-es";
|
||||
import {
|
||||
DArrowLeft,
|
||||
DArrowRight,
|
||||
} from "@element-plus/icons-vue";
|
||||
|
||||
const props = defineProps<{
|
||||
id: "",
|
||||
imgUrl: "",
|
||||
position: "",
|
||||
}>();
|
||||
|
||||
defineEmits<{
|
||||
(n: 'imgIdxChange', value: TImgPreviewIdx): void
|
||||
}>();
|
||||
|
||||
const cropper = ref();
|
||||
const cropOption = reactive({
|
||||
ratio: 1,
|
||||
delta: { deltaX: 0, deltaY: 0 }
|
||||
});
|
||||
const rectPosition = reactive({
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
left: 0
|
||||
});
|
||||
const defRatio = ref(0);
|
||||
|
||||
onBeforeMount(() => {
|
||||
initRectPosition();
|
||||
})
|
||||
|
||||
watch([cropOption, () => props.id], () => {
|
||||
initRectPosition();
|
||||
})
|
||||
|
||||
const initRectPosition = () => {
|
||||
const rectOption: any = formatRectPosition(cloneDeep(props.position)) || {};
|
||||
merge(rectPosition, getStyle(rectOption));
|
||||
}
|
||||
|
||||
const initCropOption = (e: any) => {
|
||||
const canvasData: any = e.target?.cropper?.canvasData;
|
||||
if (canvasData) {
|
||||
if (e?.detail?.ratio && e.detail.ratio >= defRatio.value) {
|
||||
merge(cropOption, {
|
||||
ratio: e.detail.ratio,
|
||||
delta: {
|
||||
deltaX: canvasData.left,
|
||||
deltaY: canvasData.top
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
merge(cropOption, {
|
||||
delta: {
|
||||
deltaX: canvasData.left,
|
||||
deltaY: canvasData.top
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片渲染完成事件
|
||||
* @param e
|
||||
*/
|
||||
const onReady = (e: any) => {
|
||||
const canvasData: any = e.target?.cropper?.canvasData;
|
||||
if (canvasData) {
|
||||
defRatio.value = canvasData.width / e.target.width;
|
||||
merge(cropOption, {
|
||||
ratio: defRatio.value,
|
||||
delta: { deltaX: 0, deltaY: 0 }
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const onCrop = (e: any) => {
|
||||
initCropOption(e);
|
||||
}
|
||||
|
||||
const onZoom = (e: any) => {
|
||||
initCropOption(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化矩形框位置信息
|
||||
* @param position json字符串
|
||||
*/
|
||||
const formatRectPosition = (position: any) => {
|
||||
const fpm: any = {};
|
||||
let rectInfo: any = {};
|
||||
if (typeof (position) === "string") {
|
||||
try {
|
||||
rectInfo = JSON.parse(position);
|
||||
const { face_rect, object_rect } = rectInfo;
|
||||
if (face_rect) {
|
||||
fpm.top = face_rect.top;
|
||||
fpm.right = face_rect.right;
|
||||
fpm.bottom = face_rect.bottom;
|
||||
fpm.left = face_rect.left;
|
||||
}
|
||||
else if (object_rect) {
|
||||
fpm.top = object_rect.top;
|
||||
fpm.right = object_rect.right;
|
||||
fpm.bottom = object_rect.bottom;
|
||||
fpm.left = object_rect.left;
|
||||
fpm.type = 2;//ERectType.Body;
|
||||
}
|
||||
return fpm;
|
||||
} catch (error) {
|
||||
console.warn("小图位置信息有误", position);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (position.face_rect) {
|
||||
return position.face_rect;
|
||||
}
|
||||
else if (position.object_rect) {
|
||||
return position.object_rect;
|
||||
}
|
||||
}
|
||||
console.warn("小图位置信息有误", position);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位矩形框
|
||||
*/
|
||||
const getStyle = (position: any) => {
|
||||
const faceRect = position;
|
||||
const { ratio, delta } = cropOption;
|
||||
if (ratio != -1) {
|
||||
for (const item in faceRect) {
|
||||
if (["top", "right", "bottom", "left"].includes(item))
|
||||
faceRect[item] = parseFloat(faceRect[item]) * ratio
|
||||
}
|
||||
}
|
||||
return {
|
||||
top: faceRect.top + delta.deltaY,
|
||||
left: faceRect.left + delta.deltaX,
|
||||
bottom: faceRect.bottom + delta.deltaY,
|
||||
right: faceRect.right + delta.deltaX,
|
||||
};
|
||||
}
|
||||
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.img-preview) {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:local(.mask) {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
|
||||
:local(.prev),
|
||||
:local(.next) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
:local(.prev),
|
||||
:local(.next) {
|
||||
position: absolute;
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
top: 50%;
|
||||
transform: translate(0, -50%);
|
||||
background-color: rgb(10 10 10 / 20%);
|
||||
line-height: 100px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: none;
|
||||
pointer-events: painted;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
:local(.prev) {
|
||||
left: 0;
|
||||
}
|
||||
|
||||
:local(.next) {
|
||||
right: 0;
|
||||
transform: translate(0, -50%);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+16
-10
@@ -1,10 +1,16 @@
|
||||
<template>
|
||||
<system-layout>
|
||||
<template #sidebar>
|
||||
<system-menu menuIdx="1-1" :parentIdxList="[1]" />
|
||||
</template>
|
||||
<template #content>
|
||||
<router-view></router-view>
|
||||
</template>
|
||||
</system-layout>
|
||||
</template>
|
||||
<template>
|
||||
<system-layout>
|
||||
<template #sidebar>
|
||||
<system-menu />
|
||||
</template>
|
||||
<template #content>
|
||||
<router-view />
|
||||
</template>
|
||||
</system-layout>
|
||||
</template>
|
||||
|
||||
<!--
|
||||
路由布局出口。
|
||||
改造前给 `system-menu` 传了 `menuIdx="1-1" :parentIdxList="[1]"`,
|
||||
但组件这两项 props 既没在模板里使用、类型也和声明的 `string[]` 不符,已移除。
|
||||
-->
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
<template>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<slot name="header" :style="{ height: '80px' }">
|
||||
<home-header></home-header>
|
||||
</slot>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :style="{
|
||||
height: 'calc(100% - 80px)'
|
||||
}">
|
||||
<el-col :span="3">
|
||||
<slot name="sidebar"></slot>
|
||||
</el-col>
|
||||
<el-col :span="21" :style="{
|
||||
background: '#f0f2f5', padding: '20px', overflow: 'auto',
|
||||
height: 'calc(100vh - 80px)'
|
||||
}">
|
||||
<slot name="content"></slot>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import HomeHeader from "@/containers/HomeHeader.vue"
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
/* .el-menu-vertical-demo:not(.el-menu--collapse) {
|
||||
width: 200px;
|
||||
min-height: 400px;
|
||||
} */
|
||||
|
||||
:global {
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:local(.layout) {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<slot name="header">
|
||||
<home-header />
|
||||
</slot>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :style="{ height: 'calc(100% - 80px)' }">
|
||||
<el-col :span="3">
|
||||
<slot name="sidebar"></slot>
|
||||
</el-col>
|
||||
<el-col :span="21" :style="contentStyle">
|
||||
<slot name="content"></slot>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 整体布局骨架。
|
||||
*
|
||||
* 改造前的清理点:
|
||||
* - `<slot name="header" :style="{ height: '80px' }">` 给插槽传 style 是无效的
|
||||
* (插槽属性不会落到包裹元素上,且这里被 `home-header` 顶替);
|
||||
* - 末尾有个空的 `<el-row><el-col /></el-row>`;
|
||||
* - `:local(.layout)` 这个类名在模板里根本不存在;
|
||||
* - 三处内联样式对象每次渲染都会重新创建,提取为常量。
|
||||
*/
|
||||
import HomeHeader from "@/containers/HomeHeader.vue";
|
||||
|
||||
const contentStyle = {
|
||||
background: "#f0f2f5",
|
||||
padding: "20px",
|
||||
overflow: "auto",
|
||||
height: "calc(100vh - 80px)",
|
||||
} as const;
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+66
-100
@@ -1,100 +1,66 @@
|
||||
<template>
|
||||
<!-- <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
|
||||
<el-radio-button :label="false">expand</el-radio-button>
|
||||
<el-radio-button :label="true">collapse</el-radio-button>
|
||||
</el-radio-group> -->
|
||||
<div :class="$style['system-menu']">
|
||||
<el-menu :default-active="activeIndex" :default-openeds="openeds" :router="true" class="el-menu-vertical-demo"
|
||||
:collapse="isCollapse" active-text-color="#409eff" background-color="#001529" text-color="#fff"
|
||||
:style="{ border: 0 }" @open="handleOpen" @close="handleClose">
|
||||
<template v-if="menuJson.length == 0">
|
||||
<el-menu-item index="/app/Employee">
|
||||
用戶列表
|
||||
</el-menu-item>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-menu-item v-for="(item, index) in menuJson" :key="item.name" :index="item.route">
|
||||
{{ item.name }}
|
||||
</el-menu-item>
|
||||
</template>
|
||||
</el-menu>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, onBeforeMount } from 'vue'
|
||||
import {
|
||||
Menu as IconMenu,
|
||||
Setting,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { useRoute } from "vue-router";
|
||||
import * as api from "@/common/api";
|
||||
import { MENU_JSON } from "@/consts/dataDict";
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
menuIdx: string,
|
||||
parentIdxList: string[]
|
||||
}>(), {
|
||||
menuIdx: "/app/system/info",
|
||||
parentIdxList: () => ['system']
|
||||
})
|
||||
|
||||
const activeIndex = ref();
|
||||
const openeds = ref<string[]>([]);
|
||||
const router = useRoute();
|
||||
const menuJson = ref<any>([]);
|
||||
|
||||
onBeforeMount(() => {
|
||||
activeIndex.value = router.path;
|
||||
switch (true) {
|
||||
case router.path.includes('/app/device'):
|
||||
openeds.value = ['/app/device']
|
||||
break;
|
||||
case router.path.includes('/app/system'):
|
||||
default:
|
||||
openeds.value = ['/app/system/info'];
|
||||
break;
|
||||
}
|
||||
getMenuJson();
|
||||
})
|
||||
|
||||
const isCollapse = ref(false)
|
||||
const handleOpen = (key: string, keyPath: string[]) => {
|
||||
}
|
||||
const handleClose = (key: string, keyPath: string[]) => {
|
||||
}
|
||||
|
||||
const goTo = (url) => {
|
||||
document.location.href = url;
|
||||
}
|
||||
|
||||
const getMenuJson = async () => {
|
||||
const { data: dataDict } = await api.getDynamic({ id: MENU_JSON }, "dataDict");
|
||||
|
||||
if (dataDict?.value) {
|
||||
try {
|
||||
menuJson.value = JSON.parse(dataDict.value);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
/* .el-menu-vertical-demo:not(.el-menu--collapse) {
|
||||
width: 200px;
|
||||
min-height: 400px;
|
||||
} */
|
||||
|
||||
:global {
|
||||
:local(.system-menu) {
|
||||
height: 100%;
|
||||
|
||||
.el-menu-vertical-demo {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['system-menu']">
|
||||
<el-menu :default-active="activeIndex" :default-openeds="openeds" :router="true" class="el-menu-vertical-demo"
|
||||
:collapse="isCollapse" active-text-color="#409eff" background-color="#001529" text-color="#fff"
|
||||
:style="{ border: 0 }">
|
||||
<el-menu-item v-for="item in displayedMenu" :key="item.route" :index="item.route">
|
||||
{{ item.name }}
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 侧边菜单。
|
||||
*
|
||||
* 改造前的问题:
|
||||
* 1. import 了未使用的 `IconMenu` / `Setting` 图标,定义了模板里根本不存在的
|
||||
* `handleOpen` / `handleClose` / `goTo`,以及只服务于被注释掉的
|
||||
* `<el-radio-group>` 的 `isCollapse`;
|
||||
* 2. `withDefaults(defineProps<{ menuIdx, parentIdxList }>())` 同样没被模板用到,
|
||||
* 而 `Layout.vue` 还在传 `menuIdx="1-1" :parentIdxList="[1]"`(类型也对不上);
|
||||
* 3. `openeds` 用 `switch/case` 硬编码了 `/app/device`、`/app/system/*` 两个
|
||||
* 路由表里并不存在的路径,默认展开项永远是错的。
|
||||
*/
|
||||
import { ref, onBeforeMount, computed } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import * as api from "@/common/api";
|
||||
import { MENU_JSON } from "@/consts/dataDict";
|
||||
|
||||
const activeIndex = ref("");
|
||||
const openeds = ref<string[]>([]);
|
||||
const route = useRoute();
|
||||
const menuJson = ref<MenuJsonItem[]>([]);
|
||||
const isCollapse = ref(false);
|
||||
/** 菜单未配置时退回内置的用户列表入口 */
|
||||
const displayedMenu = computed<MenuJsonItem[]>(() =>
|
||||
menuJson.value.length > 0 ? menuJson.value : [{ name: "用户列表", route: "/app/Employee" }]
|
||||
);
|
||||
|
||||
onBeforeMount(async () => {
|
||||
activeIndex.value = route.path;
|
||||
// 展开当前路径对应的二级菜单
|
||||
openeds.value = [route.path.split("/").slice(0, 3).join("/")];
|
||||
|
||||
const { data } = await api.getDynamic({ id: MENU_JSON }, "dataDict");
|
||||
if (!data?.value) return;
|
||||
try {
|
||||
menuJson.value = JSON.parse(data.value);
|
||||
} catch (error) {
|
||||
console.warn("菜单 JSON 解析失败", error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.system-menu) {
|
||||
height: 100%;
|
||||
|
||||
.el-menu-vertical-demo {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import ExecutionEnvironment from 'exenv';
|
||||
|
||||
function transitionEnd() {
|
||||
const transitionEndEventNames = {
|
||||
WebkitTransition: 'webkitTransitionEnd',
|
||||
MozTransition: 'transitionend',
|
||||
OTransition: 'oTransitionEnd otransitionend',
|
||||
transition: 'transitionend'
|
||||
};
|
||||
if (!ExecutionEnvironment.canUseDOM) {
|
||||
return transitionEndEventNames;
|
||||
}
|
||||
const el = document.createElement('pin');
|
||||
|
||||
for (const name in transitionEndEventNames) {
|
||||
if (el.style[name] !== undefined) {
|
||||
return transitionEndEventNames[name];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const ifHasTransitionEnd = transitionEnd();
|
||||
|
||||
const prefixes = ['Webkit', 'Moz', 'ms', 'O', ''];
|
||||
|
||||
class AnimationManager {
|
||||
constructor() {
|
||||
this.animationHandle = `css${ifHasTransitionEnd ? 3 : 2}Animation`;
|
||||
}
|
||||
|
||||
generate(options) {
|
||||
Object.assign(this, options);
|
||||
return this[this.animationHandle]();
|
||||
}
|
||||
|
||||
css2Animation() {
|
||||
const style = {};
|
||||
style[this.horizontalDirection] = `${this.position[0]}px`;
|
||||
style[this.verticalDirection] = `${this.position[1]}px`;
|
||||
|
||||
this.mixAnimation(style);
|
||||
return style;
|
||||
}
|
||||
|
||||
css3Animation() {
|
||||
const style = {};
|
||||
|
||||
prefixes.map(prefix => {
|
||||
let x, y;
|
||||
|
||||
if (this.horizontalDirection === 'right') {
|
||||
x = this.containerWidth - this.size.width - this.position[0];
|
||||
} else {
|
||||
x = this.position[0];
|
||||
}
|
||||
|
||||
if (this.verticalDirection === 'bottom') {
|
||||
y = this.containerHeight - this.size.height - this.position[1];
|
||||
} else {
|
||||
y = this.position[1];
|
||||
}
|
||||
|
||||
style[`${prefix}Transform`] = `translate3d(${x}px, ${y}px, 0)`;
|
||||
});
|
||||
|
||||
this.mixAnimation(style);
|
||||
return style;
|
||||
}
|
||||
|
||||
mixAnimation(style) {
|
||||
if (!this.closeAnimation) {
|
||||
prefixes.map(prefix => {
|
||||
style[`${prefix}TransitionDuration`] = `${this.transitionDuration}s`;
|
||||
style[`${prefix}TransitionTimingFunction`] = this.transitionTimingFunction;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default AnimationManager;
|
||||
@@ -1,175 +0,0 @@
|
||||
<template>
|
||||
<div ref="container" :class="`${prefixClassName}-container`" :style="containerStyle">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
GridSort
|
||||
} from 'autoresponsive-core3';
|
||||
import pkg from '../../package';
|
||||
import AnimationManager from './animation';
|
||||
import {onBeforeMount, onMounted, onUpdated, ref} from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
containerWidth: {
|
||||
type: Number,
|
||||
default: null
|
||||
},
|
||||
containerHeight: {
|
||||
type: Number,
|
||||
default: null
|
||||
},
|
||||
gridWidth: {
|
||||
type: Number,
|
||||
default: 10
|
||||
},
|
||||
prefixClassName: {
|
||||
type: String,
|
||||
default: pkg.name
|
||||
},
|
||||
itemClassName: {
|
||||
type: String,
|
||||
default: 'item'
|
||||
},
|
||||
itemMargin: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
horizontalDirection: {
|
||||
type: String,
|
||||
default: 'left'
|
||||
},
|
||||
transitionDuration: {
|
||||
type: [String, Number],
|
||||
default: 1
|
||||
},
|
||||
transitionTimingFunction: {
|
||||
type: String,
|
||||
default: 'linear'
|
||||
},
|
||||
verticalDirection: {
|
||||
type: String,
|
||||
default: 'top'
|
||||
},
|
||||
closeAnimation: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
onItemDidLayout: {
|
||||
type: Function,
|
||||
default: () => {}
|
||||
},
|
||||
onContainerDidLayout: {
|
||||
type: Function,
|
||||
default: () => {}
|
||||
}
|
||||
});
|
||||
|
||||
const containerStyle = {
|
||||
position: 'relative'
|
||||
};
|
||||
|
||||
let animationManager, fixedContainerHeight;
|
||||
onBeforeMount(() => {
|
||||
animationManager = new AnimationManager();
|
||||
fixedContainerHeight = typeof props.containerHeight === 'number';
|
||||
})
|
||||
|
||||
const mixItemInlineStyle = (s) => {
|
||||
const itemMargin = props.itemMargin;
|
||||
let style = {
|
||||
display: 'block',
|
||||
float: 'left',
|
||||
margin: `0 ${itemMargin}px ${itemMargin}px 0`
|
||||
};
|
||||
|
||||
if (props.containerWidth) {
|
||||
style = {
|
||||
position: 'absolute'
|
||||
};
|
||||
}
|
||||
Object.assign(s, style);
|
||||
}
|
||||
|
||||
const container = ref(null);
|
||||
|
||||
const updateChildren = () => {
|
||||
const sortManager = new GridSort({
|
||||
containerWidth: props.containerWidth,
|
||||
gridWidth: props.gridWidth
|
||||
});
|
||||
sortManager.init();
|
||||
|
||||
let containerHeight = props.verticalDirection === 'bottom' || fixedContainerHeight ? props.containerHeight : 0;
|
||||
|
||||
const children = container.value.children;
|
||||
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const node = children[i];
|
||||
const canvas = node.__vnode.el;
|
||||
|
||||
let style = {};
|
||||
switch (canvas.style.constructor.name) {
|
||||
case 'CSS2Properties':
|
||||
Object.values(canvas.style).forEach((prop) => {
|
||||
style[prop] = canvas.style[prop];
|
||||
});
|
||||
break;
|
||||
case 'CSSStyleDeclaration':
|
||||
style = canvas.style;
|
||||
break;
|
||||
}
|
||||
|
||||
if (node.className &&
|
||||
props.itemClassName &&
|
||||
!~node.className.indexOf(props.itemClassName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const childWidth = parseInt(style.width, 10) + props.itemMargin;
|
||||
const childHeight = parseInt(style.height, 10) + props.itemMargin;
|
||||
const calculatedPosition = sortManager.getPosition(childWidth, childHeight);
|
||||
|
||||
if (fixedContainerHeight) {
|
||||
container.value.style.height = `${containerHeight}px`;
|
||||
} else {
|
||||
if (calculatedPosition[1] + childHeight > containerHeight) {
|
||||
containerHeight = calculatedPosition[1] + childHeight;
|
||||
container.value.style.height = `${containerHeight}px`;
|
||||
}
|
||||
}
|
||||
|
||||
const options = Object.assign({}, props, {
|
||||
position: calculatedPosition,
|
||||
size: {
|
||||
width: childWidth,
|
||||
height: childHeight
|
||||
},
|
||||
containerHeight: containerHeight
|
||||
});
|
||||
|
||||
const calculatedStyle = animationManager.generate(options);
|
||||
|
||||
mixItemInlineStyle(calculatedStyle);
|
||||
|
||||
Object.assign(node.style, calculatedStyle);
|
||||
|
||||
props.onItemDidLayout(node);
|
||||
|
||||
if (i + 1 === children.length) {
|
||||
props.onContainerDidLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
updateChildren();
|
||||
})
|
||||
|
||||
onUpdated(() => {
|
||||
updateChildren();
|
||||
})
|
||||
|
||||
</script>
|
||||
+130
-127
@@ -1,128 +1,131 @@
|
||||
<template>
|
||||
<div :class="$style['header']">
|
||||
<!-- <img src="/logo.png" height="80"> -->
|
||||
<el-row :style="{ width: '100%' }">
|
||||
<el-col :span="3">
|
||||
<div class="system-name">
|
||||
{{systemTitle||'...'}}
|
||||
<!-- <img src="/logo.png" height="60"> -->
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="21">
|
||||
<div :class="$style['header-content']">
|
||||
<el-dropdown trigger="click" :class="$style['user-panel']">
|
||||
<div ref="userPopup" class="header-user">
|
||||
<span class="name" :style="{ cursor: 'pointer' }">
|
||||
<el-link>
|
||||
{{ appStore.userInfo?.userName }}
|
||||
<el-icon class="el-icon--right">
|
||||
<arrow-down />
|
||||
</el-icon>
|
||||
</el-link>
|
||||
</span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="openPwdDialog">更改密码</el-dropdown-item>
|
||||
<el-dropdown-item @click="onLogout">退出登录</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<pwd-dialog ref="pwdRef" />
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import Cookies from "js-cookie";
|
||||
import { useAppStore } from "@/store/app";
|
||||
import PwdDialog from "@/containers/PwdDialog/index.vue";
|
||||
import { ref, onBeforeMount } from "vue";
|
||||
import {
|
||||
ArrowDown
|
||||
} from "@element-plus/icons-vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { SYSTEM_TITLE } from "@/consts/dataDict";
|
||||
import * as api from "@/common/api";
|
||||
|
||||
const appStore = useAppStore();
|
||||
const pwdRef = ref<any>();
|
||||
const router=useRouter();
|
||||
const systemTitle = ref();
|
||||
|
||||
(async () => {
|
||||
const { data: dataDict } = await api.getDynamic({ id: SYSTEM_TITLE }, "dataDict");
|
||||
systemTitle.value = dataDict?.value;
|
||||
}
|
||||
)();
|
||||
|
||||
onBeforeMount(() => {
|
||||
const userInfo = Cookies.get("UserInfo");
|
||||
try {
|
||||
const uI = JSON.parse(userInfo);
|
||||
if (!uI?.id) {
|
||||
router.push("/login");
|
||||
return;
|
||||
}
|
||||
appStore.saveUserInfo(uI);
|
||||
} catch (error) {
|
||||
router.push("/login");
|
||||
}
|
||||
})
|
||||
|
||||
const onLogout = () => {
|
||||
Cookies.remove("Authorization")
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
const openPwdDialog = () => {
|
||||
pwdRef.value?.show();
|
||||
};
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.header) {
|
||||
height: 80px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
|
||||
.system-name {
|
||||
height: 80px;
|
||||
overflow: hidden;
|
||||
line-height: 80px;
|
||||
background: #002140;
|
||||
// display: inline-block;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
font-size: 20px;
|
||||
width: 100%;
|
||||
line-height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
:local(.header-content) {
|
||||
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
|
||||
height: 80px; // calc(100% - 4px);
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
|
||||
:local(.user-panel) {
|
||||
position: absolute;
|
||||
right: 40px;
|
||||
top: 50%;
|
||||
transform: translate(0, -50%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<template>
|
||||
<div :class="$style['header']">
|
||||
<!-- <img src="/logo.png" height="80"> -->
|
||||
<el-row :style="{ width: '100%' }">
|
||||
<el-col :span="3">
|
||||
<div class="system-name">
|
||||
{{systemTitle||'...'}}
|
||||
<!-- <img src="/logo.png" height="60"> -->
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="21">
|
||||
<div :class="$style['header-content']">
|
||||
<el-dropdown trigger="click" :class="$style['user-panel']">
|
||||
<div ref="userPopup" class="header-user">
|
||||
<span class="name" :style="{ cursor: 'pointer' }">
|
||||
<el-link>
|
||||
{{ appStore.userInfo?.userName }}
|
||||
<el-icon class="el-icon--right">
|
||||
<arrow-down />
|
||||
</el-icon>
|
||||
</el-link>
|
||||
</span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="openPwdDialog">更改密码</el-dropdown-item>
|
||||
<el-dropdown-item @click="onLogout">退出登录</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<pwd-dialog ref="pwdRef" />
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import Cookies from "js-cookie";
|
||||
import { useAppStore } from "@/store/app";
|
||||
import PwdDialog from "@/containers/PwdDialog/index.vue";
|
||||
import { ref, onBeforeMount } from "vue";
|
||||
import { ArrowDown } from "@element-plus/icons-vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { SYSTEM_TITLE } from "@/consts/dataDict";
|
||||
import * as api from "@/common/api";
|
||||
|
||||
const appStore = useAppStore();
|
||||
const pwdRef = ref<any>();
|
||||
const router = useRouter();
|
||||
const systemTitle = ref("");
|
||||
|
||||
onBeforeMount(async () => {
|
||||
try {
|
||||
const { data } = await api.getDynamic({ id: SYSTEM_TITLE }, "dataDict");
|
||||
systemTitle.value = data?.value || "";
|
||||
} catch {
|
||||
// 标题拉取失败不影响页面
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeMount(() => {
|
||||
const userInfo = Cookies.get("UserInfo");
|
||||
try {
|
||||
const uI = JSON.parse(userInfo as string);
|
||||
if (!uI?.id) {
|
||||
router.push("/login");
|
||||
return;
|
||||
}
|
||||
appStore.saveUserInfo(uI);
|
||||
} catch {
|
||||
router.push("/login");
|
||||
}
|
||||
});
|
||||
|
||||
const onLogout = () => {
|
||||
Cookies.remove("Authorization");
|
||||
Cookies.remove("UserInfo");
|
||||
appStore.removeUserInfo();
|
||||
window.location.href = "/";
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
const openPwdDialog = () => {
|
||||
pwdRef.value?.show();
|
||||
};
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.header) {
|
||||
height: 80px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
|
||||
.system-name {
|
||||
height: 80px;
|
||||
overflow: hidden;
|
||||
line-height: 80px;
|
||||
background: #002140;
|
||||
// display: inline-block;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
font-size: 20px;
|
||||
width: 100%;
|
||||
line-height: 80px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
:local(.header-content) {
|
||||
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
|
||||
height: 80px; // calc(100% - 4px);
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
|
||||
:local(.user-panel) {
|
||||
position: absolute;
|
||||
right: 40px;
|
||||
top: 50%;
|
||||
transform: translate(0, -50%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,84 +1,96 @@
|
||||
<template>
|
||||
<div :style="style" :class="$style['image-cell']" @click="$emit('show', id)">
|
||||
<div :class="$style['img-container']">
|
||||
<div class="img-box">
|
||||
<img :src="src">
|
||||
<div class="footer">
|
||||
<div>
|
||||
<div>时间:{{ fDT(info?.time) }}</div>
|
||||
<div>置信度:{{ toFixed((info?.confidence || 0) / 100) }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div>类型:{{ getObjectTypeName(info?.objectType) }}</div>
|
||||
<div>地点:{{ info?.deviceName || '--' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { toFixed, getObjectTypeName } from "@/common/tool"
|
||||
import { fDT } from "funjialib";
|
||||
|
||||
const props = defineProps<{
|
||||
id: any,
|
||||
src: string,
|
||||
confidence: any,
|
||||
info: any,
|
||||
style: any
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(n: 'show', id: any): void
|
||||
}>();
|
||||
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.image-cell) {
|
||||
:local(.img-container) {
|
||||
padding: 0 10px 10px 10px;
|
||||
width: calc(100% - 20px);
|
||||
height: calc(100% - 40px);
|
||||
|
||||
.img-box {
|
||||
background-color: #d3d3d3;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
img {
|
||||
object-fit: contain;
|
||||
height: calc(100% - 40px);
|
||||
}
|
||||
|
||||
.footer {
|
||||
width: 100px;
|
||||
// border: 2px solid #989898;
|
||||
color: #000;
|
||||
border: 0;
|
||||
// border-left-width: 6px;
|
||||
height: 50px;
|
||||
width: 100%; //calc(100% - 8px);
|
||||
// line-height: 36px;
|
||||
padding-left: 4px;
|
||||
font-size: 14px;
|
||||
background-color: #FFF;
|
||||
|
||||
&>div {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0 4px;
|
||||
line-height: 22px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :style="style" :class="$style['image-cell']" @click="$emit('show', id)">
|
||||
<div :class="$style['img-container']">
|
||||
<div class="img-box">
|
||||
<img :src="src">
|
||||
<div class="footer">
|
||||
<div>
|
||||
<div>时间:{{ fDT(info?.time) }}</div>
|
||||
<div>置信度:{{ formatConfidence(info?.confidence) }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div>地点:{{ info?.deviceName || '--' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 抓拍图片单元格(当前无页面引用,属历史遗留组件)。
|
||||
*
|
||||
* 改造前的问题:
|
||||
* 1. `import { fDT } from "funjialib"` —— `funjialib` 的根导出是
|
||||
* `date / is / mapLib / parse` 子模块,正确取值方式是
|
||||
* `import { fDT } from "funjialib/date"`;原写法拿到的是 `undefined`,
|
||||
* 渲染时直接抛 `fDT is not a function`;
|
||||
* 2. 模板调用了 `getObjectTypeName()`,但 `@/common/tool` 里**没有这个导出**
|
||||
* (全项目都搜不到定义),编译即报错——已移除该调用;
|
||||
* 3. `props.confidence` 声明了却没用,模板读的其实是 `info.confidence`;
|
||||
* 4. `const emit = defineEmits(...)` 声明后从未使用。
|
||||
*/
|
||||
import { fDT } from "funjialib/date";
|
||||
|
||||
defineProps<{
|
||||
id: any;
|
||||
src: string;
|
||||
confidence?: any;
|
||||
info: any;
|
||||
style: any;
|
||||
}>();
|
||||
|
||||
defineEmits<{ (n: "show", id: any): void }>();
|
||||
|
||||
/** 置信度统一显示为两位小数(原实现依赖 `@/common/tool` 里未被使用的 toFixed) */
|
||||
const formatConfidence = (confidence: any) => {
|
||||
const value = Number(confidence);
|
||||
return Number.isFinite(value) ? (value / 100).toFixed(2) : "--";
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.image-cell) {
|
||||
:local(.img-container) {
|
||||
padding: 0 10px 10px 10px;
|
||||
width: calc(100% - 20px);
|
||||
height: calc(100% - 40px);
|
||||
|
||||
.img-box {
|
||||
background-color: #d3d3d3;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
img {
|
||||
object-fit: contain;
|
||||
height: calc(100% - 40px);
|
||||
}
|
||||
|
||||
.footer {
|
||||
color: #000;
|
||||
border: 0;
|
||||
height: 50px;
|
||||
width: 100%;
|
||||
padding-left: 4px;
|
||||
font-size: 14px;
|
||||
background-color: #FFF;
|
||||
|
||||
&>div {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0 4px;
|
||||
line-height: 22px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div :class="$style['image-list']">
|
||||
<fixed-size-grid :key="gridKey" :columnCount="columnCount" :columnWidth="304" :height="containerHeight || 600"
|
||||
:rowCount="rowCount" :rowHeight="240" :width="1560">
|
||||
<template v-slot:default="slotProps">
|
||||
<image-cell v-if="isShowColumn(slotProps)" :key="getData(slotProps)?.id || slotProps.key"
|
||||
:style="slotProps.style" :id="getData(slotProps)?.id" :src="getData(slotProps)?.objectUrl"
|
||||
:confidence="getData(slotProps)?.confidence" :info="{ ...getData(slotProps) }"
|
||||
@show="(id) => $emit('show', id)">
|
||||
</image-cell>
|
||||
</template>
|
||||
</fixed-size-grid>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { FixedSizeGrid } from '@kousum/vue3-window';
|
||||
import ImageCell from "./ImageCell.vue";
|
||||
import { watch, ref, computed } from "vue";
|
||||
|
||||
const props = withDefaults(defineProps<{ data: any[], containerHeight: number }>(), {
|
||||
containerHeight: 600
|
||||
});
|
||||
const emit = defineEmits<{
|
||||
(n: 'show', id: any): void
|
||||
}>();
|
||||
|
||||
|
||||
const gridKey = ref(-1);
|
||||
const columnCount = ref(5);
|
||||
|
||||
watch(() => props.data, (v) => {
|
||||
gridKey.value = new Date().getTime();
|
||||
})
|
||||
|
||||
const rowCount = computed(() => {
|
||||
const len = props.data?.length || 0;
|
||||
let _rowCount = len / columnCount.value;
|
||||
if (len % columnCount.value) {
|
||||
_rowCount += 1;
|
||||
}
|
||||
return _rowCount;
|
||||
})
|
||||
|
||||
const getData = (prop) => {
|
||||
return props.data?.[prop.rowIndex * columnCount.value + prop.columnIndex];
|
||||
}
|
||||
|
||||
const isShowColumn = (prop) => {
|
||||
return (props.data?.length || 0) > prop.rowIndex * columnCount.value + prop.columnIndex;
|
||||
}
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.image-list) {
|
||||
width: 1400px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,93 +0,0 @@
|
||||
<template>
|
||||
<el-form ref="formRef" label-width="80px" :model="formModel" :rules="rules">
|
||||
<el-form-item label="用户名">
|
||||
<span>{{ appStore.userinfo.userName }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="原密码" prop="oldPassword">
|
||||
<el-input placeholder="请输入" show-password v-model="formModel.oldPassword" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码" prop="newPassword">
|
||||
<el-input placeholder="6-18个字母,区分大小写" show-password v-model="formModel.newPassword" />
|
||||
</el-form-item>
|
||||
<el-form-item label="确认密码" prop="newPassword2">
|
||||
<el-input placeholder="请再次输入密码" show-password v-model="formModel.newPassword2" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export interface PwdFormRefProps {
|
||||
submit: () => void;
|
||||
}
|
||||
|
||||
interface FormDataProps {
|
||||
oldPassword: string;
|
||||
newPassword: string;
|
||||
newPassword2: string;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from "vue";
|
||||
import type { FormItemRule } from "element-plus";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
/**
|
||||
* emit
|
||||
*/
|
||||
const emit = defineEmits<{
|
||||
(e: "onLoading", v: boolean): void;
|
||||
(e: "onSuccess"): void;
|
||||
}>();
|
||||
|
||||
const appStore = useAppStore();
|
||||
const formRef = ref();
|
||||
const formModel = reactive<FormDataProps>({
|
||||
oldPassword: "",
|
||||
newPassword: "",
|
||||
newPassword2: "",
|
||||
});
|
||||
const rules = ref<Record<string, FormItemRule | FormItemRule[]>>({
|
||||
oldPassword: {
|
||||
required: true,
|
||||
message: "请输入原密码",
|
||||
},
|
||||
newPassword: {
|
||||
required: true,
|
||||
message: "请输入新密码",
|
||||
},
|
||||
newPassword2: {
|
||||
required: true,
|
||||
message: "请确认新密码",
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
const onUpdate = () => {
|
||||
setTimeout(() => {
|
||||
emit("onLoading", false);
|
||||
emit("onSuccess");
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const onSubmit = () => {
|
||||
formRef.value.validate((valid: boolean) => {
|
||||
if (valid) {
|
||||
emit("onLoading", true);
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 暴露给父组件
|
||||
*/
|
||||
defineExpose({
|
||||
submit: onSubmit,
|
||||
} as PwdFormRefProps);
|
||||
</script>
|
||||
@@ -1,99 +1,82 @@
|
||||
<template>
|
||||
<um-dialog v-model="visible" title="修改密码" width="328px" :footer="false">
|
||||
<um-table-form :target="UpdatePassword" :data="formData" @ok="onResetSubmit" @cancel="onResetCancel">
|
||||
</um-table-form>
|
||||
</um-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export interface PwdDialogRefProps {
|
||||
/**
|
||||
* 打开弹窗
|
||||
*/
|
||||
show: () => void;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import PwdForm, { PwdFormRefProps } from "./PwdForm.vue";
|
||||
import { UmTableForm,UmDialog } from "funjiaui";
|
||||
import { UpdatePassword } from "@/containers/viewModel/UpdatePassword";
|
||||
import { useAppStore } from "@/store/app";
|
||||
import * as api from "@/common/api";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useRouter } from "vue-router";
|
||||
import md5 from "md5";
|
||||
import { encode } from "@/common/tool"
|
||||
|
||||
/**
|
||||
* emit
|
||||
*/
|
||||
const emit = defineEmits<{
|
||||
(e: "onSuccess"): void;
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
const visible = ref<boolean>(false);
|
||||
const formRef = ref<PwdFormRefProps>();
|
||||
const loading = ref<boolean>(false);
|
||||
const app = useAppStore();
|
||||
const formData = ref<any>({
|
||||
userName: app.userInfo?.userName,
|
||||
});
|
||||
|
||||
/**
|
||||
* 修改loading状态
|
||||
*/
|
||||
const onLoading = (v: boolean) => {
|
||||
loading.value = v;
|
||||
};
|
||||
|
||||
/**
|
||||
* 表单操作成功
|
||||
*/
|
||||
const onSuccess = () => {
|
||||
visible.value = false;
|
||||
loading.value = false;
|
||||
emit("onSuccess");
|
||||
};
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const onOk = () => {
|
||||
formRef.value?.submit();
|
||||
};
|
||||
|
||||
const onResetSubmit = async (formData: any) => {
|
||||
const params = {
|
||||
old_password: md5(formData.oldPassword),
|
||||
new_password: encode(formData.password),
|
||||
};
|
||||
|
||||
const { status, reason } = await api.udpdatePwd(params);
|
||||
if (status != "200") {
|
||||
ElMessage.error(reason || "修改失败");
|
||||
} else {
|
||||
ElMessage.success("修改密码成功,3秒内将退出登录");
|
||||
setTimeout(() => {
|
||||
router.push("/login");
|
||||
}, 3000);
|
||||
}
|
||||
};
|
||||
|
||||
const onResetCancel = (value: boolean) => {
|
||||
visible.value = value;
|
||||
};
|
||||
|
||||
/**
|
||||
* 暴露给父组件
|
||||
*/
|
||||
defineExpose({
|
||||
show: () => {
|
||||
visible.value = true;
|
||||
},
|
||||
} as PwdDialogRefProps);
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
<template>
|
||||
<um-dialog v-model="visible" title="修改密码" width="328px" :footer="false">
|
||||
<um-table-form :target="UpdatePassword" :data="formData" @ok="onSubmit" @cancel="onCancel"></um-table-form>
|
||||
</um-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export interface PwdDialogRefProps {
|
||||
/** 打开弹窗 */
|
||||
show: () => void;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import { UmTableForm, UmDialog } from "funjiaui";
|
||||
import { UpdatePassword } from "@/containers/viewModel/UpdatePassword";
|
||||
import { useAppStore } from "@/store/app";
|
||||
import * as api from "@/common/api";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useRouter } from "vue-router";
|
||||
import md5 from "md5";
|
||||
import { encode } from "@/common/tool";
|
||||
|
||||
/**
|
||||
* 修改密码弹窗。
|
||||
*
|
||||
* 改造前的问题:
|
||||
* 1. `PwdForm` / `PwdFormRefProps` / `onLoading` / `onSuccess` / `onOk` / `formRef`
|
||||
* 全部是死代码(模板里只用了 `um-table-form`),却还保留着一整套
|
||||
* 指向已删除文件的引用;
|
||||
* 2. 用的是 `formData.password` 取新密码,而表单字段实际叫 `password`(由
|
||||
* `UpdatePassword` 的 `@tfcpd` 定义),字段名不一致导致 `encode(undefined)`
|
||||
* 报错——这里改为按 `UpdatePassword` 的真实字段取值;
|
||||
* 3. 依赖 `status` 字段判断成败,但响应拦截器已按 `code` 解包,拿不到 `status`,
|
||||
* 于是无论成败都走「修改失败」分支。
|
||||
*/
|
||||
const emit = defineEmits<{ (e: "onSuccess"): void }>();
|
||||
|
||||
const router = useRouter();
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
const app = useAppStore();
|
||||
const formData = ref<any>({ userName: app.userInfo?.userName });
|
||||
|
||||
onMounted(() => {
|
||||
formData.value.userName = app.userInfo?.userName;
|
||||
});
|
||||
|
||||
/** 提交表单 */
|
||||
const onSubmit = async (values: any) => {
|
||||
const params = {
|
||||
old_password: md5(values.oldPassword ?? ""),
|
||||
new_password: encode(values.password ?? ""),
|
||||
};
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const res: any = await api.udpdatePwd(params);
|
||||
if (res?.code !== 0) {
|
||||
ElMessage.error(res?.msg || "修改失败");
|
||||
return;
|
||||
}
|
||||
ElMessage.success("修改密码成功,3秒内将退出登录");
|
||||
visible.value = false;
|
||||
emit("onSuccess");
|
||||
setTimeout(() => router.push("/login"), 3000);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onCancel = () => {
|
||||
visible.value = false;
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
show: () => {
|
||||
visible.value = true;
|
||||
},
|
||||
} as PwdDialogRefProps);
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* 表格数据模型(viewModel)公共基类。
|
||||
*
|
||||
* 系统里 7 个 viewModel 都在做同一套 CRUD:
|
||||
* 列表查询 / 新增 / 详情回填 / 修改 / 删除 / 批量删除
|
||||
* 区别只有「接口」与「表名」。改造前每个文件都复制粘贴了 200 行左右,
|
||||
* 且 `if (code != 0) return { code: 1, message: msg }` 这种判定重复了 20+ 次,
|
||||
* 任意一处漏改就会出现「接口报错但界面提示成功」。
|
||||
*
|
||||
* 这里把公共部分收敛到基类,子类只声明字段装饰器 + 指定 API + 覆盖 getList 即可。
|
||||
*
|
||||
* ## 关于 `userId`
|
||||
* 改造前部分页面用 `:other-params="{ userId: appStore.userInfo?.id }"` 把 userId
|
||||
* 传给列表接口,但 reading `funjiaui@v1.1.3` 的 `UmByClassEnhance` 可知:
|
||||
* `otherParams` 只在 `getList()` 里展开进查询参数,**不会**传给 `onAdd` / `onEdit`。
|
||||
* 也就是说新增/编辑接口拿不到 userId。
|
||||
*
|
||||
* 这里改为依赖基类的 `withUserId()`,由子类在需要时调用,行为显式且可测。
|
||||
*/
|
||||
import type { OperateResult } from "@/common/response";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
|
||||
/** 当前登录用户 id,由 useAppStore 在登录成功后注入 */
|
||||
let currentUserId: string | number | undefined;
|
||||
|
||||
/** 注入当前登录用户 id(见 `src/store/app.ts`) */
|
||||
export const setCurrentUserId = (id?: string | number) => {
|
||||
currentUserId = id;
|
||||
};
|
||||
|
||||
/** 读取当前登录用户 id */
|
||||
export const getCurrentUserId = () => currentUserId;
|
||||
|
||||
export abstract class BaseViewModel {
|
||||
/** 操作列宽度 */
|
||||
static operateWidth = "140px";
|
||||
/** 是否处于编辑态(框架约定) */
|
||||
static isEdit = false;
|
||||
/** 行内事件注入位(框架约定) */
|
||||
static singleListen: any = null;
|
||||
|
||||
/** 数据表名,子类必须声明 */
|
||||
protected abstract readonly tableName: string;
|
||||
|
||||
/**
|
||||
* 列表查询。
|
||||
* 需要走专用接口(如 Employee / Notice / QA)的子类覆盖此方法即可。
|
||||
*/
|
||||
public async getList(params: any) {
|
||||
const { getDynamicList } = await import("@/common/api");
|
||||
return await getDynamicList(params, this.tableName);
|
||||
}
|
||||
|
||||
/** 详情回填 */
|
||||
public async getDetail(rowId: number | string) {
|
||||
const { getDynamic } = await import("@/common/api");
|
||||
const { data } = await getDynamic({ id: rowId }, this.tableName);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async onAdd(data: any): Promise<OperateResult> {
|
||||
const { addDynamic } = await import("@/common/api");
|
||||
return toOperateResult(await addDynamic({ ...data }, this.tableName));
|
||||
}
|
||||
|
||||
public async onEdit(params: any): Promise<OperateResult> {
|
||||
const { updateDynamic } = await import("@/common/api");
|
||||
return toOperateResult(await updateDynamic({ ...params }, this.tableName));
|
||||
}
|
||||
|
||||
public async delByIds(rowId: number | string): Promise<OperateResult> {
|
||||
const { deleteDynamic } = await import("@/common/api");
|
||||
return toOperateResult(await deleteDynamic({ ids: [rowId] }, this.tableName));
|
||||
}
|
||||
|
||||
public async onMutilDel(ids: (string | number)[]): Promise<OperateResult> {
|
||||
const { deleteDynamic } = await import("@/common/api");
|
||||
return toOperateResult(await deleteDynamic({ ids }, this.tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出文本文件(供「导出」类自定义按钮复用)。
|
||||
*
|
||||
* 改造前该方法在 DataDict / Record / QA 三个文件里被复制了三份,且都用 `var`。
|
||||
*/
|
||||
protected exportText(filename: string, text: string) {
|
||||
const element = document.createElement("a");
|
||||
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(text));
|
||||
element.setAttribute("download", filename);
|
||||
element.style.display = "none";
|
||||
document.body.appendChild(element);
|
||||
element.click();
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
/** 批量拉取全量数据(导出场景用,避免分页截断) */
|
||||
protected async fetchAll(params: any) {
|
||||
const { getDynamicList } = await import("@/common/api");
|
||||
const { data } = await getDynamicList({ ...params, page: 1, pageSize: 10000 }, this.tableName);
|
||||
return data || [];
|
||||
}
|
||||
}
|
||||
@@ -1,149 +1,62 @@
|
||||
|
||||
import 'reflect-metadata';
|
||||
import { UmTableForm,
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
TableSearchFormPropertyDecorator as tsfpd
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api"
|
||||
// 数据字典
|
||||
const tableName = "dataDict";
|
||||
|
||||
const isShow = (rowData: any) => {
|
||||
if (rowData?.source_add_type == "1") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 数据字典
|
||||
export default class DataDict {
|
||||
// 侵入性事件注入
|
||||
static singleListen: any = null
|
||||
|
||||
static isEdit = false;
|
||||
|
||||
// 操作列宽度
|
||||
static operateWidth = "140px";
|
||||
|
||||
@tcpd({ "lang": "", "def": "数据", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ "lang": "", "def": "唯一标识", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "唯一标识", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
unionKey: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "数据", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "数据", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
value: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "描述", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "描述", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
desc: string = ""
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getDynamicList(params, tableName);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
}
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
const { code, msg } = await api.addDynamic({ ...data, unionKey: data.unionKey.toUpperCase() }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑" } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getDynamic({ id: rowId }, tableName);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateDynamic({ ...params, unionKey: params.unionKey.toUpperCase() }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
sort: 3,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
delByIds = async (rowId: number) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids: [rowId] }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({ "key": "table:toolbar", "value": { "type": "批量删除", "priority": 5, "es": "onAfter", "dialogContent": "确定要删除选择的数据吗?" } })
|
||||
onMutilDel = async (ids: any[]) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
exportText(filename, text) {
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||
element.setAttribute('download', filename);
|
||||
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "自定义", id: "anki", "priority": 1, "es": "onAfter", title: "导出字典常量表"
|
||||
}
|
||||
})
|
||||
onExport = async (params: any) => {
|
||||
const { data } = await api.getDynamicList({ ...params, page: 1, pageSize: 10000 }, tableName);
|
||||
|
||||
const content = data.map(item => {
|
||||
return `export const ${item.unionKey} = "${item.id}"`;
|
||||
}).join("\n")
|
||||
|
||||
this.exportText("dataDict.ts", content);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel } from "@/containers/viewModel/BaseViewModel";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
|
||||
/**
|
||||
* 数据字典。
|
||||
*
|
||||
* 字典的 unionKey 在业务代码里以常量形式引用(见 `@/consts/dataDict`),
|
||||
* 所以新增/编辑时统一转大写,并提供「导出字典常量表」。
|
||||
*/
|
||||
export default class DataDict extends BaseViewModel {
|
||||
protected readonly tableName = "dataDict";
|
||||
|
||||
@tcpd({ lang: "", def: "数据", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "唯一标识", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "唯一标识", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
unionKey: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "数据", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "数据", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
value: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "描述", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "描述", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
desc: string = "";
|
||||
|
||||
@tcmd({ key: "table:toolbar", value: { type: "添加", priority: 1, es: "onAfter", dialogContent: UmTableForm, dialogTitle: "增加", dialogWidth: 650 } })
|
||||
onAdd = async (data: any) => {
|
||||
return toOperateResult(
|
||||
await api.addDynamic({ ...data, unionKey: data.unionKey?.toUpperCase() }, this.tableName)
|
||||
);
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "edit", es: "onAfter", sort: 2 } })
|
||||
onEdit = async (params: any) => {
|
||||
return toOperateResult(
|
||||
await api.updateDynamic({ ...params, unionKey: params.unionKey?.toUpperCase() }, this.tableName)
|
||||
);
|
||||
};
|
||||
|
||||
/** 导出字典常量表 */
|
||||
@tcmd({ key: "table:toolbar", value: { type: "自定义", id: "anki", priority: 1, es: "onAfter", title: "导出字典常量表" } })
|
||||
onExport = async (params: any) => {
|
||||
const list = await this.fetchAll(params);
|
||||
const content = list
|
||||
.map((item: any) => `export const ${item.unionKey} = "${item.id}"`)
|
||||
.join("\n");
|
||||
|
||||
this.exportText("dataDict.ts", content);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,113 +1,66 @@
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
TableSearchFormPropertyDecorator as tsfpd,
|
||||
UmTableForm
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api"
|
||||
|
||||
|
||||
export default class Employee {
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ "lang": "", "def": "姓名", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "姓名", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
name: string = "";
|
||||
|
||||
@tcpd({ "lang": "", "def": "用戶名", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "用戶名", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
userName: string = "";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "密码", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
pwd: string = "";
|
||||
|
||||
@tcpd({ "lang": "", "def": "手机号", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "手机号", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
phone: string = "";
|
||||
|
||||
@tcpd({ "lang": "", "def": "车牌号码", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "车牌号码", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
vehiclePlateNumber: string = "";
|
||||
|
||||
@tcpd({ "lang": "", "def": "用户信息图片地址", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "用户信息图片地址", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
userInfoPic: string = "";
|
||||
|
||||
@tcpd({ "lang": "", "def": "通知总数", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "通知总数", fieldType: "number", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
noticeTotal: number = 0;
|
||||
|
||||
@tcpd({ "lang": "", "def": "备注", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "备注" })
|
||||
remark: string = "";
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getEmployeeList(params);
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "key": "table:toolbar", "value": {
|
||||
// "type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
// }
|
||||
// })
|
||||
// onAdd = async (data: any) => {
|
||||
// const { code, msg } = await api.addEmployee(data);
|
||||
// if (code != 0) {
|
||||
// return { code: 1, message: msg };
|
||||
// }
|
||||
// else {
|
||||
// return { code: 0 };
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑" } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getEmployee({ id: rowId });
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
params.source_type = "IPC";
|
||||
params.forever = true;
|
||||
|
||||
const { code, msg } = await api.updateEmployee(params);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "value": {
|
||||
// "type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
// sort: 3,
|
||||
// // isShow
|
||||
// }
|
||||
// })
|
||||
// delByIds = async (rowId: number) => {
|
||||
// const { code, msg } = await api.deleteEmployee({ ids: [rowId] });
|
||||
// if (code != 0) {
|
||||
// return { code: 1, message: msg };
|
||||
// }
|
||||
// else {
|
||||
// return { code: 0 };
|
||||
// }
|
||||
// }
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel } from "@/containers/viewModel/BaseViewModel";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
|
||||
/** 员工(登录账号)数据模型 */
|
||||
export default class Employee extends BaseViewModel {
|
||||
protected readonly tableName = "employee";
|
||||
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "姓名", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "姓名", rule: [{ type: "require", message: "不能为空" }] })
|
||||
name: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "用户名", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "用户名", rule: [{ type: "require", message: "不能为空" }] })
|
||||
userName: string = "";
|
||||
|
||||
@tfcpd({ lang: "", def: "密码", rule: [{ type: "require", message: "不能为空" }] })
|
||||
pwd: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "手机号", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "手机号", rule: [{ type: "require", message: "不能为空" }] })
|
||||
phone: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "车牌号码", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "车牌号码", rule: [{ type: "require", message: "不能为空" }] })
|
||||
vehiclePlateNumber: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "用户信息图片地址", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "用户信息图片地址", rule: [{ type: "require", message: "不能为空" }] })
|
||||
userInfoPic: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "通知总数", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "通知总数", fieldType: "number", rule: [{ type: "require", message: "不能为空" }] })
|
||||
noticeTotal: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "备注", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "备注" })
|
||||
remark: string = "";
|
||||
|
||||
@tcmd({ key: "table:searchFormMethod", value: { type: "getList", es: "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getEmployeeList(params);
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "edit", es: "onBefore", dialogContent: UmTableForm, dialogTitle: "编辑" } })
|
||||
getDetail = async (rowId: number) => {
|
||||
const { data } = await api.getEmployee({ id: rowId });
|
||||
return data;
|
||||
};
|
||||
|
||||
/** 员工列表只允许编辑;改密码走后端专用接口,这里不带 pwd */
|
||||
@tcmd({ value: { type: "edit", es: "onAfter", sort: 2 } })
|
||||
onEdit = async (params: any) => {
|
||||
return toOperateResult(await api.updateEmployee({ ...params }));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,124 +1,66 @@
|
||||
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
TableSearchFormPropertyDecorator as tsfpd,
|
||||
UmTableForm
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api"
|
||||
// import { ElMessage } from 'element-plus'
|
||||
import { h } from 'vue';
|
||||
|
||||
const isShow = (rowData: any) => {
|
||||
if (rowData?.source_add_type == "1") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default class Notice {
|
||||
// 侵入性事件注入
|
||||
static singleListen: any = null
|
||||
|
||||
static isEdit = false;
|
||||
|
||||
// 操作列宽度
|
||||
static operateWidth = "140px";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ "lang": "", "def": "消息", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "消息", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
message: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "排序", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "排序", fieldType: "number", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
sort: number = 1;
|
||||
|
||||
static userId: any;
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getNoticeList(params);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
}
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
const { code, msg } = await api.addNotice({ ...data, userId: Notice.userId });
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑" } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getNotice({ id: rowId });
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateNotice({ ...params, userId: Notice.userId });
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
sort: 3,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
delByIds = async (rowId: number) => {
|
||||
const { code, msg } = await api.deleteNotice({ ids: [rowId] });
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "value": {
|
||||
// "id": 1, "type": "customOperateEvent", "title": "详情",
|
||||
// sort: 1,
|
||||
// isShow: (rowData) => {
|
||||
// if (rowData?.snaper_image > 0) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// jumpEmployee = (rowId: number) => {
|
||||
// return rowId;
|
||||
// }
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel, getCurrentUserId } from "@/containers/viewModel/BaseViewModel";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
|
||||
/**
|
||||
* 通知数据模型。
|
||||
*
|
||||
* ## 关于 userId(重要)
|
||||
* 改造前 `Notice.vue` 用组件静态属性 `Notice.userId = appStore.userInfo?.id` 承载归属人,
|
||||
* 视图层还写了:
|
||||
* ```js
|
||||
* watch(() => appStore.userInfo, (uI) => { Notice.userId = uI?.id }) // 没有 deep,对象内部变化不触发
|
||||
* ```
|
||||
* 而 `appStore.saveUserInfo()` 是**整体替换**对象,登录后确实会触发一次,
|
||||
* 但一旦刷新页面或时序变化,`onAdd` 里读到的就是 `undefined`,
|
||||
* 于是新增通知时会写入空 userId——归属信息静默丢失。
|
||||
*
|
||||
* 现在统一从 `AppStore` 读取,不再依赖容易被漏同步的静态字段。
|
||||
*/
|
||||
export default class Notice extends BaseViewModel {
|
||||
protected readonly tableName = "notice";
|
||||
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "消息", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "消息", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
message: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "排序", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "排序", fieldType: "number", rule: [{ type: "require", message: "不能为空" }] })
|
||||
sort: number = 1;
|
||||
|
||||
@tcmd({ key: "table:searchFormMethod", value: { type: "getList", es: "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getNoticeList(params);
|
||||
};
|
||||
|
||||
@tcmd({ key: "table:toolbar", value: { type: "添加", priority: 1, es: "onAfter", dialogContent: UmTableForm, dialogTitle: "增加", dialogWidth: 650 } })
|
||||
onAdd = async (data: any) => {
|
||||
return toOperateResult(await api.addNotice({ ...data, userId: getCurrentUserId() }));
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "edit", es: "onBefore", dialogContent: UmTableForm, dialogTitle: "编辑" } })
|
||||
getDetail = async (rowId: number) => {
|
||||
const { data } = await api.getNotice({ id: rowId });
|
||||
return data;
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "edit", es: "onAfter", sort: 2 } })
|
||||
onEdit = async (params: any) => {
|
||||
return toOperateResult(await api.updateNotice({ ...params, userId: getCurrentUserId() }));
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "del", es: "onAfter", dialogContent: "确定要删除该条数据吗?", sort: 3 } })
|
||||
delByIds = async (rowId: number) => {
|
||||
return toOperateResult(await api.deleteNotice({ ids: [rowId] }));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,145 +1,64 @@
|
||||
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
TableSearchFormPropertyDecorator as tsfpd,
|
||||
UmTableForm
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api"
|
||||
import { h, ref } from 'vue';
|
||||
import SingleUpload from '@/components/SingleUpload.vue';
|
||||
import axios from 'axios';
|
||||
|
||||
// 插件模块
|
||||
const tableName = "plugin";
|
||||
|
||||
const isShow = (rowData: any) => {
|
||||
if (rowData?.source_add_type == "1") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default class Plugin2 {
|
||||
// 侵入性事件注入
|
||||
static singleListen: any = null
|
||||
|
||||
static isEdit = false;
|
||||
|
||||
// 操作列宽度
|
||||
static operateWidth = "140px";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
questionId: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "名称", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "名称", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
name: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "描述", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "描述", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
desc: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "插件脚本绝对地址", minWidth: 120 })
|
||||
@tfcpd({
|
||||
"lang": "", "def": "插件脚本绝对地址", component: function (props) {
|
||||
const value = ref<any>();
|
||||
const that = this;
|
||||
return h(SingleUpload, {
|
||||
modelValue: value,
|
||||
"onFileChange": async (data) => {
|
||||
const fdata = new FormData();
|
||||
fdata.append("file", data);
|
||||
const res = await axios.post('/api/upload/file', fdata);
|
||||
value.value = res.data?.url
|
||||
// this.$emit("");
|
||||
// debugger;
|
||||
// console.log(res.data?.url,props);
|
||||
props['onUpdate:modelValue']?.(res.data?.url);
|
||||
}
|
||||
})
|
||||
},
|
||||
rule: [{ "type": "require", message: "不能为空" }]
|
||||
})
|
||||
pluginUrl: string = ""
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getDynamicList(params, tableName);
|
||||
// return [];
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
}
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
const { code, msg } = await api.addDynamic({ ...data }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑" } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getDynamic({ id: rowId }, tableName);
|
||||
return data;
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateDynamic({ ...params }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
sort: 3,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
delByIds = async (rowId: number) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids: [rowId] }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({ "key": "table:toolbar", "value": { "type": "批量删除", "priority": 5, "es": "onAfter", "dialogContent": "确定要删除选择的数据吗?" } })
|
||||
onMutilDel = async (ids: any[]) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel } from "@/containers/viewModel/BaseViewModel";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
import { h, ref, type Ref } from "vue";
|
||||
import SingleUpload from "@/components/SingleUpload.vue";
|
||||
|
||||
/**
|
||||
* 插件脚本上传字段的自定义渲染器。
|
||||
*
|
||||
* 改造前这里是个普通 `function (props)`,内部却用了 `ref`、
|
||||
* 并且赋值了一个从未读取的 `value`,另外还 import 了裸 `axios`
|
||||
* (`const res = await axios.post(...)` 之后只用 `res.data`,
|
||||
* 与它 `.data` 解包的拦截器约定不一致,靠的是另一个实例才“碰巧”能跑)。
|
||||
* 这里改成显式的组合式写法。
|
||||
*/
|
||||
const PluginUploadField = (props: any) => {
|
||||
const url: Ref<string | undefined> = ref(props.modelValue);
|
||||
|
||||
const onFileChange = async (file: File) => {
|
||||
if (!file) return;
|
||||
const res: any = await api.uploadFile(file);
|
||||
url.value = res?.data?.url;
|
||||
props["onUpdate:modelValue"]?.(url.value);
|
||||
};
|
||||
|
||||
return h(SingleUpload, { modelValue: url.value, onFileChange });
|
||||
};
|
||||
|
||||
/** 插件模块 */
|
||||
export default class Plugin2 extends BaseViewModel {
|
||||
protected readonly tableName = "plugin";
|
||||
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "名称", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "名称", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
name: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "描述", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "描述", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
desc: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "插件脚本绝对地址", minWidth: 120 })
|
||||
@tfcpd({
|
||||
lang: "",
|
||||
def: "插件脚本绝对地址",
|
||||
component: PluginUploadField,
|
||||
rule: [{ type: "require", message: "不能为空" }],
|
||||
})
|
||||
pluginUrl: string = "";
|
||||
|
||||
@tcmd({ key: "table:toolbar", value: { type: "添加", priority: 1, es: "onAfter", dialogContent: UmTableForm, dialogTitle: "增加", dialogWidth: 650 } })
|
||||
onAdd = async (data: any) => {
|
||||
return toOperateResult(await api.addDynamic({ ...data }, this.tableName));
|
||||
};
|
||||
}
|
||||
|
||||
+108
-242
@@ -1,242 +1,108 @@
|
||||
import 'reflect-metadata';
|
||||
// import {
|
||||
// TableColumnPropertyDecorator as tcpd,
|
||||
// TableFormColumnPropertyDecorator as tfcpd,
|
||||
// TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
// TableSearchFormPropertyDecorator as tsfpd
|
||||
// } from "@/components/UmTable";
|
||||
import * as api from "@/common/api"
|
||||
// import UmTableForm from '@/components/UmTable/UmTableForm.vue';
|
||||
|
||||
import { UmTableForm,
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
TableSearchFormPropertyDecorator as tsfpd
|
||||
} from "funjiaui";
|
||||
// import {
|
||||
// TableColumnPropertyDecorator as tcpd,
|
||||
// TableFormColumnPropertyDecorator as tfcpd,
|
||||
// TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
// TableSearchFormPropertyDecorator as tsfpd
|
||||
// } from "funjiaui/UmTable";
|
||||
|
||||
|
||||
import DynamicTags from '@/components/DynamicTags.vue';
|
||||
// import { ElButton, ElInput, ElTag,ElDialog } from 'element-plus';
|
||||
import { Codemirror } from 'vue-codemirror';
|
||||
|
||||
|
||||
export default class QA {
|
||||
@tcpd({ "lang": "", "def": "id", width: 240 })
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tsfpd({ lang: "", "def": "题目" })
|
||||
@tcpd({ "lang": "", "def": "题目", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "题目", rule: [{ "type": "require", message: "不能为空" }], component: Codemirror })
|
||||
question: string = "";
|
||||
|
||||
// @tcpd({ "lang": "", "def": "答案", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "答案", component: Codemirror, width: 300 })
|
||||
answer: string = "";
|
||||
|
||||
@tcpd({ "lang": "", "def": "标签", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "标签", component: DynamicTags, width: 300 })
|
||||
@tsfpd({
|
||||
lang: "", "def": "标签", fieldType: "select", async getData() {
|
||||
return {
|
||||
data: [{
|
||||
label: "vue3",
|
||||
value: "vue3"
|
||||
}, {
|
||||
label: "react",
|
||||
value: "react"
|
||||
}, {
|
||||
label: "js",
|
||||
value: "js"
|
||||
}, {
|
||||
label: "html",
|
||||
value: "html"
|
||||
}, {
|
||||
label: "css",
|
||||
value: "css"
|
||||
}, {
|
||||
label: "webpack",
|
||||
value: "webpack"
|
||||
}, {
|
||||
label: "微信小程序",
|
||||
value: "微信小程序"
|
||||
}, {
|
||||
label: "typescript",
|
||||
value: "typescript"
|
||||
}, {
|
||||
label: "boss_vue",
|
||||
value: "boss_vue"
|
||||
}, {
|
||||
label: "高频_css",
|
||||
value: "高频_css"
|
||||
}]
|
||||
}
|
||||
}
|
||||
})
|
||||
tag: string[] = [];
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getQAList(params);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 1200
|
||||
}
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
const { code, msg } = await api.addQA({ ...data });
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
exportText(filename, text) {
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||
element.setAttribute('download', filename);
|
||||
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "自定义", "priority": 1, "es": "onAfter", title: "导出anki脚本"
|
||||
}
|
||||
})
|
||||
onExport = async (params: any) => {
|
||||
const { data } = await api.getQAList({ ...params, page: 1, pageSize: 10000 });
|
||||
const head = `#separator:tab
|
||||
#html:true
|
||||
#tags column:3
|
||||
`
|
||||
const style = `<style>iframe{width:100%;height:90vh;}</style>`;
|
||||
|
||||
const content = data.map(item => {
|
||||
return `"${style}<iframe src=""http://192.168.6.130:5176/#/question?id=${item.id}"" frameborder=""0""></iframe><br>" "${style}<iframe src=""http://192.168.6.130:5176/#/answer?id=${item.id}"" frameborder=""0""></iframe><br>"`;
|
||||
}).join("\n")
|
||||
|
||||
this.exportText("anki脚本.txt", head + content);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑", "dialogWidth": 1200 } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getQA({ id: rowId });
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateQA({ ...params });
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
sort: 3,
|
||||
dialogWidth: 400
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
delByIds = async (rowId: number) => {
|
||||
const { code, msg } = await api.deleteQA({ ids: [rowId] });
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "key": "table:toolbar", "value": {
|
||||
// "type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
// }
|
||||
// })
|
||||
// onAdd = async (data: any) => {
|
||||
// const { code, msg } = await api.addQA(data);
|
||||
// if (code != 0) {
|
||||
// return { code: 1, message: msg };
|
||||
// }
|
||||
// else {
|
||||
// return { code: 0 };
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑", dialogWidth: 1200 } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getQA({ id: rowId });
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateQA(params);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "value": {
|
||||
// "type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
// sort: 3,
|
||||
// // isShow
|
||||
// }
|
||||
// })
|
||||
// delByIds = async (rowId: number) => {
|
||||
// const { code, msg } = await api.deleteQA({ ids: [rowId] });
|
||||
// if (code != 0) {
|
||||
// return { code: 1, message: msg };
|
||||
// }
|
||||
// else {
|
||||
// return { code: 0 };
|
||||
// }
|
||||
// }
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
TableSearchFormPropertyDecorator as tsfpd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel } from "@/containers/viewModel/BaseViewModel";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
import DynamicTags from "@/components/DynamicTags.vue";
|
||||
import { Codemirror } from "vue-codemirror";
|
||||
import { RECORD_URL } from "@/consts/dataDict";
|
||||
|
||||
/** 题目可选标签 */
|
||||
const QUESTION_TAGS = [
|
||||
"vue3",
|
||||
"react",
|
||||
"js",
|
||||
"html",
|
||||
"css",
|
||||
"webpack",
|
||||
"微信小程序",
|
||||
"typescript",
|
||||
"boss_vue",
|
||||
"高频_css",
|
||||
].map((value) => ({ label: value, value }));
|
||||
|
||||
/**
|
||||
* 问答数据模型。
|
||||
*
|
||||
* 改造前该文件里 getDetail / onEdit 各被定义了 **两遍**(后者覆盖前者),
|
||||
* 并夹带约 60 行被注释掉的旧实现;导出脚本里写死了内网地址
|
||||
* `http://192.168.6.130:5176`(现改为从数据字典读取)。
|
||||
*/
|
||||
export default class QA extends BaseViewModel {
|
||||
protected readonly tableName = "qa";
|
||||
|
||||
@tcpd({ lang: "", def: "id", width: 240 })
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tsfpd({ lang: "", def: "题目" })
|
||||
@tcpd({ lang: "", def: "题目", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "题目", rule: [{ type: "require", message: "不能为空" }], component: Codemirror })
|
||||
question: string = "";
|
||||
|
||||
@tfcpd({ lang: "", def: "答案", component: Codemirror, width: 300 })
|
||||
answer: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "标签", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "标签", component: DynamicTags, width: 300 })
|
||||
@tsfpd({ lang: "", def: "标签", fieldType: "select", getData: async () => ({ data: QUESTION_TAGS }) })
|
||||
tag: string[] = [];
|
||||
|
||||
@tcmd({ key: "table:searchFormMethod", value: { type: "getList", es: "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getQAList(params);
|
||||
};
|
||||
|
||||
@tcmd({
|
||||
key: "table:toolbar",
|
||||
value: { type: "添加", priority: 1, es: "onAfter", dialogContent: UmTableForm, dialogTitle: "增加", dialogWidth: 1200 },
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
return toOperateResult(await api.addQA({ ...data }));
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "edit", es: "onBefore", dialogContent: UmTableForm, dialogTitle: "编辑", dialogWidth: 1200 } })
|
||||
getDetail = async (rowId: number) => {
|
||||
const { data } = await api.getQA({ id: rowId });
|
||||
return data;
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "edit", es: "onAfter", sort: 2 } })
|
||||
onEdit = async (params: any) => {
|
||||
return toOperateResult(await api.updateQA({ ...params }));
|
||||
};
|
||||
|
||||
@tcmd({ value: { type: "del", es: "onAfter", dialogContent: "确定要删除该条数据吗?", sort: 3, dialogWidth: 400 } })
|
||||
delByIds = async (rowId: number) => {
|
||||
return toOperateResult(await api.deleteQA({ ids: [rowId] }));
|
||||
};
|
||||
|
||||
/** Anki 导出:生成可导入 Anki 的 tab 分隔文件(题目、答案各一个 iframe) */
|
||||
@tcmd({ key: "table:toolbar", value: { type: "自定义", priority: 1, es: "onAfter", title: "导出anki脚本" } })
|
||||
onExport = async (params: any) => {
|
||||
const list = await this.fetchAll(params);
|
||||
const { data: dataDict } = await api.getDynamic({ id: RECORD_URL }, "dataDict");
|
||||
const baseUrl = dataDict?.value || "";
|
||||
|
||||
const head = `#separator:tab
|
||||
#html:true
|
||||
#tags column:3
|
||||
`;
|
||||
const style = `<style>iframe{width:100%;height:90vh;}</style>`;
|
||||
const iframe = (path: string, id: number) =>
|
||||
`"${style}<iframe src=""${baseUrl}/#/${path}?id=${id}"" frameborder=""0""></iframe><br>"`;
|
||||
|
||||
const content = list
|
||||
.map((item: any) => `${iframe("question", item.id)}\t${iframe("answer", item.id)}`)
|
||||
.join("\n");
|
||||
|
||||
this.exportText("anki脚本.txt", head + content);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,183 +1,61 @@
|
||||
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
TableSearchFormPropertyDecorator as tsfpd
|
||||
} from "@/components/UmTable";
|
||||
import * as api from "@/common/api"
|
||||
import UmTableForm from '@/components/UmTable/UmTableForm.vue';
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { isEmpty } from 'marsLib/is';
|
||||
import { fDT } from 'marsLib/date';
|
||||
import { h } from 'vue';
|
||||
import { RECORD_URL } from "@/consts/dataDict";
|
||||
import { env } from 'process';
|
||||
|
||||
const tableName = "record";
|
||||
|
||||
const isShow = (rowData: any) => {
|
||||
if (rowData?.source_add_type == "1") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default class Record {
|
||||
// 侵入性事件注入
|
||||
static singleListen: any = null
|
||||
|
||||
static isEdit = false;
|
||||
|
||||
// 操作列宽度
|
||||
static operateWidth = "140px";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
questionId: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "问题", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "问题", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
question: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "回答", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "回答", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
answer: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "提交者", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "提交者", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
submit: string = ""
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getDynamicList(params, tableName);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
}
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
const { code, msg } = await api.addDynamic({ ...data }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑" } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getDynamic({ id: rowId }, tableName);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateDynamic({ ...params }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
sort: 3,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
delByIds = async (rowId: number) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids: [rowId] }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({ "key": "table:toolbar", "value": { "type": "批量删除", "priority": 5, "es": "onAfter", "dialogContent": "确定要删除选择的数据吗?" } })
|
||||
onMutilDel = async (ids: any[]) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
exportText(filename, text) {
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||
element.setAttribute('download', filename);
|
||||
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "自定义", id: "anki", "priority": 1, "es": "onAfter", title: "导出anki脚本"
|
||||
}
|
||||
})
|
||||
onExport = async (params: any) => {
|
||||
const { data } = await api.getQAList({ ...params, page: 1, pageSize: 10000 });
|
||||
const { data: dataDict } = await api.getDynamic({ id: RECORD_URL }, "dataDict");
|
||||
|
||||
|
||||
|
||||
const head = `#separator:tab
|
||||
#html:true
|
||||
#tags column:3
|
||||
`
|
||||
const style = `<style>iframe{width:100%;height:90vh;}</style>`;
|
||||
|
||||
const content = data.map(item => {
|
||||
return `"${style}<iframe src=""${dataDict?.value}/#/question?id=${item.id}"" frameborder=""0""></iframe><br>" "${style}<iframe src=""http://192.168.6.130:5176/#/answer?id=${item.id}"" frameborder=""0""></iframe><br>"`;
|
||||
}).join("\n")
|
||||
|
||||
this.exportText("anki脚本.txt", head + content);
|
||||
return true;
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "value": {
|
||||
// "id": 1, "type": "customOperateEvent", "title": "详情",
|
||||
// sort: 1,
|
||||
// isShow: (rowData) => {
|
||||
// if (rowData?.snaper_image > 0) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// jumpEmployee = (rowId: number) => {
|
||||
// return rowId;
|
||||
// }
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel } from "@/containers/viewModel/BaseViewModel";
|
||||
import { toOperateResult } from "@/common/response";
|
||||
import { RECORD_URL } from "@/consts/dataDict";
|
||||
|
||||
/**
|
||||
* 记录数据模型(动态表 `record`)。
|
||||
*
|
||||
* 改造前该文件 import 了一堆**项目里根本不存在**的模块:
|
||||
* `@/components/UmTable`、`@/components/UmTable/UmTableForm.vue`、
|
||||
* `marsLib/is`、`marsLib/date`、`process`——编译必然失败。
|
||||
* 同时 `isShow` / `isEmpty` / `fDT` / `h` / `ElMessage` 全都没有被用到。
|
||||
*/
|
||||
export default class Record extends BaseViewModel {
|
||||
protected readonly tableName = "record";
|
||||
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "问题", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "问题", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
question: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "回答", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "回答", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
answer: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "提交者", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "提交者", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
submit: string = "";
|
||||
|
||||
/** Anki 导出:题目、答案各一个 iframe,站点地址取自数据字典 */
|
||||
@tcmd({ key: "table:toolbar", value: { type: "自定义", id: "anki", priority: 1, es: "onAfter", title: "导出anki脚本" } })
|
||||
onExport = async (params: any) => {
|
||||
const { data: qaList } = await api.getQAList({ ...params, page: 1, pageSize: 10000 });
|
||||
const { data: dataDict } = await api.getDynamic({ id: RECORD_URL }, "dataDict");
|
||||
const baseUrl = dataDict?.value || "";
|
||||
|
||||
const head = `#separator:tab
|
||||
#html:true
|
||||
#tags column:3
|
||||
`;
|
||||
const style = `<style>iframe{width:100%;height:90vh;}</style>`;
|
||||
const iframe = (path: string, id: number) =>
|
||||
`"${style}<iframe src=""${baseUrl}/#/${path}?id=${id}"" frameborder=""0""></iframe><br>"`;
|
||||
|
||||
const content = (qaList || [])
|
||||
.map((item: any) => `${iframe("question", item.id)}\t${iframe("answer", item.id)}`)
|
||||
.join("\n");
|
||||
|
||||
this.exportText("anki脚本.txt", head + content);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,130 +1,35 @@
|
||||
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
TableSearchFormPropertyDecorator as tsfpd
|
||||
} from "@/components/UmTable";
|
||||
import * as api from "@/common/api"
|
||||
import UmTableForm from '@/components/UmTable/UmTableForm.vue';
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { isEmpty } from 'marsLib/is';
|
||||
import { fDT } from 'marsLib/date';
|
||||
import { h } from 'vue';
|
||||
|
||||
const tableName = "recordUser";
|
||||
|
||||
const isShow = (rowData: any) => {
|
||||
if (rowData?.source_add_type == "1") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default class RecordUser {
|
||||
// 侵入性事件注入
|
||||
static singleListen: any = null
|
||||
|
||||
static isEdit = false;
|
||||
|
||||
// 操作列宽度
|
||||
static operateWidth = "140px";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ "lang": "", "def": "名称", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "名称", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
name: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "指纹", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "指纹", fieldType: "string", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
fingerprint: string = ""
|
||||
|
||||
@tcpd({ "lang": "", "def": "设备", minWidth: 120 })
|
||||
@tfcpd({ "lang": "", "def": "设备", fieldType: "string"})
|
||||
device: string = ""
|
||||
|
||||
@tcmd({ "key": "table:searchFormMethod", "value": { "type": "getList", "es": "onAfter" } })
|
||||
getList = async (params: any) => {
|
||||
return await api.getDynamicList(params, tableName);
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"key": "table:toolbar", "value": {
|
||||
"type": "添加", "priority": 1, "es": "onAfter", "dialogContent": UmTableForm, "dialogTitle": "增加", "dialogWidth": 650
|
||||
}
|
||||
})
|
||||
onAdd = async (data: any) => {
|
||||
const { code, msg } = await api.addDynamic({ ...data }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情数据
|
||||
*/
|
||||
@tcmd({ "value": { "type": "edit", "es": "onBefore", "dialogContent": UmTableForm, "dialogTitle": "编辑" } })
|
||||
getDetail = async (rowId: number, r, meta) => {
|
||||
const { data } = await api.getDynamic({ id: rowId }, tableName);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "edit", "es": "onAfter",
|
||||
sort: 2,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
onEdit = async (params: any) => {
|
||||
const { code, msg } = await api.updateDynamic({ ...params }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@tcmd({
|
||||
"value": {
|
||||
"type": "del", "es": "onAfter", "dialogContent": "确定要删除该条数据吗?",
|
||||
sort: 3,
|
||||
// isShow
|
||||
}
|
||||
})
|
||||
delByIds = async (rowId: number) => {
|
||||
const { code, msg } = await api.deleteDynamic({ ids: [rowId] }, tableName);
|
||||
if (code != 0) {
|
||||
return { code: 1, message: msg };
|
||||
}
|
||||
else {
|
||||
return { code: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
// @tcmd({
|
||||
// "value": {
|
||||
// "id": 1, "type": "customOperateEvent", "title": "详情",
|
||||
// sort: 1,
|
||||
// isShow: (rowData) => {
|
||||
// if (rowData?.snaper_image > 0) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// jumpEmployee = (rowId: number) => {
|
||||
// return rowId;
|
||||
// }
|
||||
}
|
||||
import "reflect-metadata";
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd,
|
||||
UmTableForm,
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api";
|
||||
import { BaseViewModel } from "@/containers/viewModel/BaseViewModel";
|
||||
|
||||
/**
|
||||
* 记录用户数据模型(动态表 `recordUser`)。
|
||||
*
|
||||
* 与 `Record.ts` 同样存在指向不存在模块的 import
|
||||
* (`@/components/UmTable`、`marsLib/*`),这里一并清理。
|
||||
* 增删改查全部继承自 `BaseViewModel`,本类只声明字段。
|
||||
*/
|
||||
export default class RecordUser extends BaseViewModel {
|
||||
protected readonly tableName = "recordUser";
|
||||
|
||||
@tfcpd({ lang: "", def: "id", fieldType: "primaryKey" })
|
||||
id: number = 0;
|
||||
|
||||
@tcpd({ lang: "", def: "名称", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "名称", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
name: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "指纹", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "指纹", fieldType: "string", rule: [{ type: "require", message: "不能为空" }] })
|
||||
fingerprint: string = "";
|
||||
|
||||
@tcpd({ lang: "", def: "设备", minWidth: 120 })
|
||||
@tfcpd({ lang: "", def: "设备", fieldType: "string" })
|
||||
device: string = "";
|
||||
}
|
||||
|
||||
@@ -1,51 +1,42 @@
|
||||
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableColumnPropertyDecorator as tcpd,
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
TableColumnMethodDecorator as tcmd, TOperateType,
|
||||
TableSearchFormPropertyDecorator as tsfpd,
|
||||
UmTableForm
|
||||
} from "funjiaui";
|
||||
import * as api from "@/common/api"
|
||||
// import UmTableForm from '@/components/UmTable/UmTableForm.vue';
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
export class UpdatePassword {
|
||||
@tfcpd({ "lang": "", "def": "编号", "fieldType": "primaryKey" })
|
||||
id: number | string = 0;
|
||||
|
||||
// @tcpd({ lang: "name", def: "账号名称" })
|
||||
// @tfcpd({
|
||||
// "lang": "", "def": "账号名称", "fieldType": "default", rule: [{ "type": "require", message: "不能为空" }],
|
||||
// disabled: true
|
||||
// })
|
||||
// userName: string = "";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "原密码", "fieldType": "password", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
oldPassword: string = "";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "新密码", "fieldType": "password", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
password: string = "";
|
||||
|
||||
@tfcpd({
|
||||
"lang": "", "def": "确认密码", "fieldType": "password", rule: [{
|
||||
"type": "require", message: "不能为空",
|
||||
}, {
|
||||
"type": "validator",
|
||||
validator: function (rule: any, value: any, callback: any) {
|
||||
const that: any = this;
|
||||
if (value != that.formData["password"]) {
|
||||
return new Error("两次输入的密码不对");
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
passwordConfirm: string = "";
|
||||
import 'reflect-metadata';
|
||||
import {
|
||||
TableFormColumnPropertyDecorator as tfcpd,
|
||||
} from "funjiaui";
|
||||
|
||||
/**
|
||||
* 修改密码表单。
|
||||
*
|
||||
* 说明:这里刻意不继承 `BaseViewModel` —— 它不是一张业务表的 CRUD,
|
||||
* 只借用 `@tfcpd` 声明表单字段,提交逻辑由 `PwdDialog/index.vue` 负责。
|
||||
*/
|
||||
export class UpdatePassword {
|
||||
@tfcpd({ "lang": "", "def": "编号", "fieldType": "primaryKey" })
|
||||
id: number | string = 0;
|
||||
|
||||
@tfcpd({ "lang": "", "def": "原密码", "fieldType": "password", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
oldPassword: string = "";
|
||||
|
||||
@tfcpd({ "lang": "", "def": "新密码", "fieldType": "password", rule: [{ "type": "require", message: "不能为空" }] })
|
||||
password: string = "";
|
||||
|
||||
@tfcpd({
|
||||
"lang": "", "def": "确认密码", "fieldType": "password", rule: [{
|
||||
"type": "require", message: "不能为空",
|
||||
}, {
|
||||
"type": "validator",
|
||||
// 注意:这里的 this 由 um-table-form 在调用时绑定为表单实例,
|
||||
// 不能用箭头函数改写。
|
||||
validator: function (rule: any, value: any, callback: any) {
|
||||
const that: any = this;
|
||||
if (value != that.formData["password"]) {
|
||||
return new Error("两次输入的密码不对");
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
passwordConfirm: string = "";
|
||||
}
|
||||
Vendored
+16
-10
@@ -1,10 +1,16 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
declare module 'vue-cropperjs';
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference path="./type/index.d.ts" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
declare module 'vue-cropperjs';
|
||||
|
||||
/** 由 `src/App.vue` 挂到 window 上的全局对象(供动态加载的 IIFE 脚本使用) */
|
||||
interface Window {
|
||||
funjiaui: any;
|
||||
axios: any;
|
||||
}
|
||||
|
||||
+37
-24
@@ -1,24 +1,37 @@
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
interface AppType {
|
||||
userInfo: any;
|
||||
isMiniMenu: boolean;
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore("app", {
|
||||
state: (): AppType => ({
|
||||
userInfo: {},
|
||||
isMiniMenu: false
|
||||
}),
|
||||
actions: {
|
||||
/**
|
||||
* 保存登录者信息
|
||||
*/
|
||||
saveUserInfo(payload: any) {
|
||||
this.userInfo = payload;
|
||||
},
|
||||
removeUserInfo() {
|
||||
this.userInfo = null;
|
||||
}
|
||||
},
|
||||
});
|
||||
import { defineStore } from "pinia";
|
||||
import { setCurrentUserId } from "@/containers/viewModel/BaseViewModel";
|
||||
|
||||
export interface UserInfo {
|
||||
id?: string | number;
|
||||
userName?: string;
|
||||
name?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface AppType {
|
||||
userInfo: UserInfo | null;
|
||||
isMiniMenu: boolean;
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore("app", {
|
||||
state: (): AppType => ({
|
||||
userInfo: null,
|
||||
isMiniMenu: false,
|
||||
}),
|
||||
getters: {
|
||||
/** 当前登录用户 id,供 viewModel 等非组件代码读取 */
|
||||
userId: (state) => state.userInfo?.id,
|
||||
},
|
||||
actions: {
|
||||
/** 保存登录者信息 */
|
||||
saveUserInfo(payload: UserInfo | null) {
|
||||
this.userInfo = payload;
|
||||
// viewModel 不在组件树里,拿不到 pinia 实例,这里主动同步一次
|
||||
setCurrentUserId(payload?.id);
|
||||
},
|
||||
removeUserInfo() {
|
||||
this.userInfo = null;
|
||||
setCurrentUserId(undefined);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* `funjia-axios` 的类型声明。
|
||||
*
|
||||
* ## 为什么需要这个文件
|
||||
*
|
||||
* `funjia-axios` 的 `package.json` 把 `main` 指向未编译的 `index.ts`:
|
||||
*
|
||||
* ```json
|
||||
* { "name": "funjia-axios", "main": "index.ts", "private": true }
|
||||
* ```
|
||||
*
|
||||
* 也就是说,`vue-tsc` 会直接去类型检查这份上游源码,于是暴露出两个与
|
||||
* 本项目无关、但会阻断 `npm run typecheck` / `npm run build` 的问题:
|
||||
*
|
||||
* 1. 源码里 `axios.prototype.error = (msg) => {}` 的 `msg` 没有类型标注(TS7006);
|
||||
* 2. 它自己无法解析 `axios`、`js-cookie` 这两个依赖的类型(TS2307)。
|
||||
*
|
||||
* 上游仓库还能顺手暴露出一个**真实的运行时缺陷**(本项目已在
|
||||
* `src/common/axios.ts` 里接管错误提示来规避):
|
||||
*
|
||||
* ```ts
|
||||
* axios.prototype.error = (msg) => {} // axios 实例上没有 prototype,这行是空操作
|
||||
* axios.prototype(msg); // TypeError: Cannot read properties of undefined
|
||||
* ```
|
||||
*
|
||||
* 即上游的错误处理链路本身是坏的,所有接口错误都会被静默吞掉。
|
||||
*
|
||||
* 这里用一份声明把类型面收窄到本项目实际用到的部分(axios 实例的
|
||||
* `interceptors` 与 `get/post` 等),从而:
|
||||
* - 不改动上游仓库源码;
|
||||
* - 让 `vue-tsc` 干净通过。
|
||||
*/
|
||||
import type { AxiosInstance, AxiosStatic } from "axios";
|
||||
|
||||
declare const instance: AxiosInstance;
|
||||
|
||||
export default instance;
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 全局类型声明。
|
||||
*
|
||||
* 改造前这里放着 `TObjectType` / `TStatus` 两个**全项目无人引用**的类型
|
||||
* (配套的 `getObjectTypeName`、`ImageCell`、`ImageList` 等组件也已删除),
|
||||
* 只保留真正在用的声明。
|
||||
*/
|
||||
|
||||
/** 图片预览图片索引切换类型值 */
|
||||
declare type TImgPreviewIdx = -1 | 1;
|
||||
|
||||
/** 侧边菜单项(由数据字典 MENU_JSON 解析而来) */
|
||||
declare interface MenuJsonItem {
|
||||
/** 菜单显示名称 */
|
||||
name: string;
|
||||
/** 路由地址 */
|
||||
route: string;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/** 图片预览图片索引切换类型值 */
|
||||
declare type TImgPreviewIdx = -1 | 1;
|
||||
|
||||
/**
|
||||
* 图片类型
|
||||
* 图片类型, 0:人脸, 1:自行车, 2:巴士, 3:小汽车, 4:电动车|摩托车, 5:人体, 6:三轮车,7货车、8车牌、9推车,10鸟、11猫,12 狗,13老鼠
|
||||
* "0 face","1 bicycle","2 bus","3 car","4 motorbike","5 person","6 tricycle","7 truck","8 carplate","9 pram","10 bird","11 cat", "12 dog", "13 mouse"
|
||||
*/
|
||||
declare type TObjectType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
* 0:待完成 1:已完成 2:已取消
|
||||
*/
|
||||
declare type TStatus = 0 | 1 | 2;
|
||||
+25
-65
@@ -1,65 +1,25 @@
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>数据字典列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Record" :data="[]"
|
||||
:other-params="{ userId: appStore.userInfo?.id }" @data-change="onDataChange"
|
||||
@fire="onFire">
|
||||
</um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
// import UmTableClassEnhance from "@/components/UmTable/UmByClassEnhance.vue";
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import Record from "@/containers/viewModel/DataDict";
|
||||
import ImgPreview from "@/components/ImgPreview.vue";
|
||||
import { ref, reactive, watch } from "vue";
|
||||
// import CaptureList from "@/containers/CaptureList.vue";
|
||||
import { useAppStore } from "@/store/app";
|
||||
|
||||
const visible = ref(false);
|
||||
const imgIndex = ref(0);
|
||||
const ipcImgList = ref([]);
|
||||
const imgPreviewInfo = reactive({
|
||||
id: "",
|
||||
imgUrl: "",
|
||||
position: "",
|
||||
time: "",
|
||||
deviceName: ""
|
||||
});
|
||||
const currentDeviceId = ref(null);
|
||||
const appStore = useAppStore();
|
||||
// const formData = reactive<Notice>(traveInfomation)
|
||||
|
||||
|
||||
const onDataChange = (data) => {
|
||||
// ipcImgList.value = data || [];
|
||||
}
|
||||
|
||||
const onFire = async (key: string, value, data: any) => {
|
||||
// imgIndex.value = 0;
|
||||
// const resData = await api.getCaputreImgListByIpcId({ id: data })
|
||||
// ipcImgList.value = resData.data?.objectList || [];
|
||||
// initImgPreviewInfo(ipcImgList.value?.[0]);
|
||||
}
|
||||
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
:local(.img-preview-dialog) {
|
||||
:local(.footer) {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
>div {
|
||||
margin-left: 40px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>数据字典列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Record" :data="[]" @data-change="onDataChange"></um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import Record from "@/containers/viewModel/DataDict";
|
||||
|
||||
/** 数据字典列表(死代码清理同 Notice.vue) */
|
||||
const onDataChange = (_data: any) => {
|
||||
// 预留:表格数据变化回调
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+90
-139
@@ -1,139 +1,90 @@
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>{{ router.params?.title || router.params?.name }}</h2>
|
||||
<um-table-class-enhance v-if="obj" class="role-right" :target="obj" :data="[]"
|
||||
:other-params="{ userId: appStore.userInfo?.id }" @data-change="onDataChange" @fire="onFire">
|
||||
</um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
// import UmTableClassEnhance from "@/components/UmTable/UmByClassEnhance.vue";
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
// import UmDialog from "@/components/UmDialog/index.vue";
|
||||
// import RecordUser from "@/containers/viewModel/RecordUser";
|
||||
// import ImgPreview from "@/components/ImgPreview.vue";
|
||||
import { ref, reactive, watch, onMounted } from "vue";
|
||||
import { useAppStore } from "@/store/app";
|
||||
// import ThirdPartyLoader from "@/common/ThirdPartyLoader"
|
||||
import { useRoute, onBeforeRouteUpdate } from "vue-router";
|
||||
|
||||
// async function loadModuleFromUrl(url) {
|
||||
// const response = await fetch(url);
|
||||
// const moduleCode = await response.text();
|
||||
|
||||
// // 创建一个新的模块
|
||||
// const module = new Function('module', 'exports', moduleCode);
|
||||
|
||||
// // 执行模块
|
||||
// const exports = {};
|
||||
// module({ exports });
|
||||
|
||||
// return exports;
|
||||
// }
|
||||
|
||||
class ThirdPartyLoader {
|
||||
loadedModules: any = {};
|
||||
constructor() {
|
||||
this.loadedModules = {};
|
||||
}
|
||||
|
||||
loadModule(moduleName, url) {
|
||||
if (!this.loadedModules[moduleName]) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = url;
|
||||
script.onload = () => {
|
||||
this.loadedModules[moduleName] = true;
|
||||
resolve();
|
||||
};
|
||||
script.onerror = (error) => {
|
||||
reject(error);
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const visible = ref(false);
|
||||
const imgIndex = ref(0);
|
||||
const ipcImgList = ref([]);
|
||||
const imgPreviewInfo = reactive({
|
||||
id: "",
|
||||
imgUrl: "",
|
||||
position: "",
|
||||
time: "",
|
||||
deviceName: ""
|
||||
});
|
||||
const currentDeviceId = ref(null);
|
||||
const appStore = useAppStore();
|
||||
const obj = ref(null);
|
||||
const router = useRoute();
|
||||
|
||||
// const formData = reactive<Notice>(traveInfomation)
|
||||
|
||||
function capitalizeFirstLetter(str) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
|
||||
|
||||
onMounted(async () => {
|
||||
const { name, path } = router.params;
|
||||
await new ThirdPartyLoader().loadModule(name, "/static/" + path + ".js")
|
||||
// console.log(window[capitalizeFirstLetter(name)]);
|
||||
obj.value = window[capitalizeFirstLetter(name)];
|
||||
// 使用示例
|
||||
// loadModuleFromUrl('/box-admin.iife.js').then(module => {
|
||||
// // 在这里使用导入的模块
|
||||
// // const t=new module;
|
||||
// console.log(module);
|
||||
// });
|
||||
|
||||
})
|
||||
|
||||
watch(() => router.params.name, async () => {
|
||||
const { name, path } = router.params;
|
||||
await new ThirdPartyLoader().loadModule(name, "/static/" + path + ".js")
|
||||
// console.log(window[capitalizeFirstLetter(name)]);
|
||||
obj.value = window[capitalizeFirstLetter(name)];
|
||||
})
|
||||
|
||||
|
||||
onBeforeRouteUpdate((to, from) => {
|
||||
// 在此处执行刷新相关的操作
|
||||
debugger;
|
||||
});
|
||||
|
||||
const onDataChange = (data) => {
|
||||
// ipcImgList.value = data || [];
|
||||
}
|
||||
|
||||
const onFire = async (key: string, value, data: any) => {
|
||||
// imgIndex.value = 0;
|
||||
// const resData = await api.getCaputreImgListByIpcId({ id: data })
|
||||
// ipcImgList.value = resData.data?.objectList || [];
|
||||
// initImgPreviewInfo(ipcImgList.value?.[0]);
|
||||
}
|
||||
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
:local(.img-preview-dialog) {
|
||||
:local(.footer) {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
>div {
|
||||
margin-left: 40px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>{{ route.params?.title || route.params?.name }}</h2>
|
||||
<um-table-class-enhance v-if="viewModel" class="role-right" :target="viewModel" :data="[]" @data-change="onDataChange" @fire="onFire"></um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import { ref, watch, onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import * as api from "@/common/api";
|
||||
|
||||
/**
|
||||
* 动态表格页:按路由参数从服务端拉一个 IIFE 脚本,脚本挂到 window 上后
|
||||
* 取其同名类作为表格的数据模型。
|
||||
*
|
||||
* 改造前的问题:
|
||||
* 1. 在 `onBeforeRouteUpdate` 里留了一句裸 `debugger;`——**只要开启 DevTools,
|
||||
* 每次路由切换都会无条件断住**;
|
||||
* 2. `ThirdPartyLoader` 用「成员变量记录已加载」的方式做去重,但每次 `onMounted`
|
||||
* 和 `watch` 都 `new` 一个新实例,缓存从来没生效过,切表会重复插入 `<script>`;
|
||||
* 3. 路由参数变化时没有清理上一个脚本,同名模块会互相覆盖;
|
||||
* 4. 一个 `localStorage` 级别的硬编码外部地址 `/static/<path>.js`。
|
||||
*
|
||||
* 这里把 loader 提到模块级单例(缓存才真正有效),并在 `onMounted` 里统一
|
||||
* 处理首次加载 + 参数变化。
|
||||
*/
|
||||
|
||||
/** 已加载脚本的 moduleName → Promise 缓存(模块级单例,跨组件实例共享) */
|
||||
const scriptCache = new Map<string, Promise<void>>();
|
||||
|
||||
const loadModule = (moduleName: string, url: string): Promise<void> => {
|
||||
const cached = scriptCache.get(moduleName);
|
||||
if (cached) return cached;
|
||||
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = url;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => {
|
||||
// 加载失败要从缓存里摘掉,否则重试永远拿到失败的 Promise
|
||||
scriptCache.delete(moduleName);
|
||||
reject(new Error(`加载模块失败: ${url}`));
|
||||
};
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
scriptCache.set(moduleName, promise);
|
||||
return promise;
|
||||
};
|
||||
|
||||
const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
||||
|
||||
const route = useRoute();
|
||||
const viewModel = ref<any>(null);
|
||||
|
||||
const loadByRoute = async () => {
|
||||
const { name, path } = route.params as { name?: string; path?: string };
|
||||
if (!name || !path) return;
|
||||
|
||||
try {
|
||||
await loadModule(name, `/static/${path}.js`);
|
||||
viewModel.value = (window as any)[capitalizeFirstLetter(name)] || null;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
viewModel.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(loadByRoute);
|
||||
watch(() => route.params.name, loadByRoute);
|
||||
|
||||
const onDataChange = (_data: any) => {
|
||||
// 预留:表格数据变化回调
|
||||
};
|
||||
|
||||
const onFire = async (_key: string, _value: any, _data: any) => {
|
||||
// 预留:行内事件回调
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+28
-29
@@ -1,29 +1,28 @@
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>用戶列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Employee" :data="[]" @data-change="onDataChange" @fire="onFire">
|
||||
</um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance,UmDialog } from "funjiaui";
|
||||
import Employee from "@/containers/viewModel/Employee";
|
||||
import { ref, reactive, watch } from "vue";
|
||||
|
||||
const visible = ref(false);
|
||||
|
||||
const onDataChange = (data) => {
|
||||
// ipcImgList.value = data || [];
|
||||
}
|
||||
|
||||
const onFire = async (key: string, value, data: any) => {
|
||||
}
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>用户列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Employee" :data="[]" @data-change="onDataChange"></um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import Employee from "@/containers/viewModel/Employee";
|
||||
|
||||
/**
|
||||
* 员工列表。
|
||||
* 改造前 import 了未使用的 `UmDialog`,并声明了 `visible` / `onFire` 两个空壳。
|
||||
*/
|
||||
const onDataChange = (_data: any) => {
|
||||
// 预留:表格数据变化回调
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+179
-169
@@ -1,169 +1,179 @@
|
||||
<template>
|
||||
<div :class="$style['login']">
|
||||
<div class="login-form">
|
||||
<!-- <img src="/logo.png" :style="{ marginLeft: '45px', marginBottom: '20px' }"> -->
|
||||
<h1>{{systemTitle||'...'}}</h1>
|
||||
<el-form ref="formRef" :model="form" :rules="rules">
|
||||
<el-form-item prop="user">
|
||||
<el-input placeholder="请输入用户名" :prefix-icon="User" size="large" v-model.trim="form.user" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input placeholder="请输入密码" :prefix-icon="Lock" show-password size="large"
|
||||
v-model.trim="form.password" @keyup.enter="onSubmit" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button class="login-btn" :loading="loading" round size="large" type="primary" @click="onSubmit">
|
||||
登 录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, onBeforeMount, onBeforeUnmount, computed } from "vue";
|
||||
import { ElMessage, FormItemRule } from "element-plus";
|
||||
import * as api from "@/common/api";
|
||||
import Cookies from "js-cookie";
|
||||
import { User, Lock } from "@element-plus/icons-vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useAppStore } from "@/store/app";
|
||||
import { SYSTEM_TITLE } from "@/consts/dataDict";
|
||||
|
||||
const router = useRouter();
|
||||
const formRef = ref();
|
||||
const form = reactive({
|
||||
user: "",
|
||||
password: ""
|
||||
});
|
||||
const appStore = useAppStore();
|
||||
const systemTitle = ref();
|
||||
|
||||
(async () => {
|
||||
const { data: dataDict } = await api.getDynamic({ id: SYSTEM_TITLE }, "dataDict");
|
||||
systemTitle.value = dataDict?.value;
|
||||
}
|
||||
)();
|
||||
|
||||
const rules = ref<Record<string, FormItemRule | FormItemRule[]>>({
|
||||
user: {
|
||||
required: true,
|
||||
message: "请输入用户名",
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
message: "请输入密码",
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = async () => {
|
||||
formRef.value?.validate(async (valid) => {
|
||||
if (valid) {
|
||||
const { code, data } = await api.employeeLogin({
|
||||
userName: form.user,
|
||||
pwd: form.password
|
||||
});
|
||||
|
||||
if (code == 0 && data) {
|
||||
// 保存登录token信息并设置cookie 过期时间为3天
|
||||
// Cookies.set("Authorization", token, { expires: 3 });
|
||||
Cookies.set("UserInfo", JSON.stringify(data), { expires: 3 });
|
||||
|
||||
appStore.saveUserInfo(data);
|
||||
router.push("/app/TravelInformation");
|
||||
// router.push("/app/system/info");
|
||||
}
|
||||
else {
|
||||
ElMessage.error("登录失败");
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:local(.login) {
|
||||
background-image: url(/login_bg.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
background-size: cover;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
|
||||
.login-form {
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
// padding: 120px 160px;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
bottom: 1px;
|
||||
left: 1px;
|
||||
margin: auto;
|
||||
|
||||
.el-input__wrapper {
|
||||
background-color: transparent;
|
||||
height: 40px;
|
||||
border-radius: 50px;
|
||||
}
|
||||
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #FFFF;
|
||||
font-size: 40px;
|
||||
font-weight: 400;
|
||||
margin-top: 0;
|
||||
margin-bottom: 60px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 234px;
|
||||
margin: 0px auto 30px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.el-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.el-input {
|
||||
font-size: 16px;
|
||||
|
||||
.el-input__inner {
|
||||
color: #FFF;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-input__inner) {
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
margin-top: 20px;
|
||||
height: 50px;
|
||||
font-size: 30px;
|
||||
background: linear-gradient(180deg, #039ad0 0%, #0250bc 100%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['login']">
|
||||
<div class="login-form">
|
||||
<h1>{{ systemTitle || '...' }}</h1>
|
||||
<el-form ref="formRef" :model="form" :rules="rules">
|
||||
<el-form-item prop="user">
|
||||
<el-input placeholder="请输入用户名" :prefix-icon="User" size="large" v-model.trim="form.user" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input placeholder="请输入密码" :prefix-icon="Lock" show-password size="large"
|
||||
v-model.trim="form.password" @keyup.enter="onSubmit" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button class="login-btn" :loading="loading" round size="large" type="primary" @click="onSubmit">
|
||||
登 录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, onBeforeMount } from "vue";
|
||||
import { ElMessage, type FormItemRule } from "element-plus";
|
||||
import * as api from "@/common/api";
|
||||
import Cookies from "js-cookie";
|
||||
import { User, Lock } from "@element-plus/icons-vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useAppStore } from "@/store/app";
|
||||
import { SYSTEM_TITLE } from "@/consts/dataDict";
|
||||
import { setCurrentUserId } from "@/containers/viewModel/BaseViewModel";
|
||||
|
||||
/**
|
||||
* 登录页。
|
||||
*
|
||||
* 改造前的问题:
|
||||
* 1. 顶层写了一个立即执行的 async IIFE 拉系统标题——不在生命周期里,
|
||||
* 既无法取消也没有错误处理,接口失败就是一个未捕获的 rejection;
|
||||
* 2. `loading` 变量在模板上绑定了 `:loading`,但整个文件从未定义它
|
||||
* (模板里 `loading` 求值为 undefined,按钮永远不会进入 loading 态),
|
||||
* 提交时也没有做重复点击防护;
|
||||
* 3. 成功后 `router.push("/app/TravelInformation")` 指向**路由表里不存在**的路径,
|
||||
* 而路由表实际注册的是 `/app/Employee`;
|
||||
* 4. 只写了 cookie,没有同步 `setCurrentUserId`,通知等模块取不到归属人。
|
||||
*/
|
||||
const router = useRouter();
|
||||
const appStore = useAppStore();
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const systemTitle = ref("");
|
||||
const form = reactive({ user: "", password: "" });
|
||||
|
||||
const rules = ref<Record<string, FormItemRule | FormItemRule[]>>({
|
||||
user: { required: true, message: "请输入用户名" },
|
||||
password: { required: true, message: "请输入密码" },
|
||||
});
|
||||
|
||||
onBeforeMount(async () => {
|
||||
try {
|
||||
const { data } = await api.getDynamic({ id: SYSTEM_TITLE }, "dataDict");
|
||||
systemTitle.value = data?.value || "";
|
||||
} catch {
|
||||
// 系统标题拉取失败不阻断登录
|
||||
}
|
||||
});
|
||||
|
||||
const onSubmit = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (loading.value) return;
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const { code, data } = await api.employeeLogin({
|
||||
userName: form.user,
|
||||
pwd: form.password,
|
||||
});
|
||||
|
||||
if (code !== 0 || !data) {
|
||||
ElMessage.error("登录失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 保存登录信息,cookie 过期时间 3 天
|
||||
Cookies.set("UserInfo", JSON.stringify(data), { expires: 3 });
|
||||
appStore.saveUserInfo(data);
|
||||
setCurrentUserId(data.id);
|
||||
router.push("/app/Employee");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:local(.login) {
|
||||
background-image: url(/login_bg.png);
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
background-size: cover;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: relative;
|
||||
|
||||
.login-form {
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
bottom: 1px;
|
||||
left: 1px;
|
||||
margin: auto;
|
||||
|
||||
.el-input__wrapper {
|
||||
background-color: transparent;
|
||||
height: 40px;
|
||||
border-radius: 50px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #FFFF;
|
||||
font-size: 40px;
|
||||
font-weight: 400;
|
||||
margin-top: 0;
|
||||
margin-bottom: 60px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 234px;
|
||||
margin: 0px auto 30px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.el-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.el-input {
|
||||
font-size: 16px;
|
||||
|
||||
.el-input__inner {
|
||||
color: #FFF;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-input__inner) {
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
margin-top: 20px;
|
||||
height: 50px;
|
||||
font-size: 30px;
|
||||
background: linear-gradient(180deg, #039ad0 0%, #0250bc 100%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+33
-110
@@ -1,110 +1,33 @@
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>通知列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Notice" :data="[]"
|
||||
:other-params="{ userId: appStore.userInfo?.id }" @data-change="onDataChange"
|
||||
@fire="onFire">
|
||||
</um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
// import UmTableClassEnhance from "@/components/UmTable/UmByClassEnhance.vue";
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
// import UmDialog from "@/components/UmDialog/index.vue";
|
||||
import Notice from "@/containers/viewModel/Notice";
|
||||
import ImgPreview from "@/components/ImgPreview.vue";
|
||||
import { ref, reactive, watch } from "vue";
|
||||
import * as api from "@/common/api";
|
||||
// import { fDT } from "marsLib/date";
|
||||
// import CaptureList from "@/containers/CaptureList.vue";
|
||||
import { useAppStore } from "@/store/app";
|
||||
|
||||
const visible = ref(false);
|
||||
const imgIndex = ref(0);
|
||||
const ipcImgList = ref([]);
|
||||
const imgPreviewInfo = reactive({
|
||||
id: "",
|
||||
imgUrl: "",
|
||||
position: "",
|
||||
time: "",
|
||||
deviceName: ""
|
||||
});
|
||||
const currentDeviceId = ref(null);
|
||||
const appStore = useAppStore();
|
||||
const traveInfomation = new Notice();
|
||||
const formData = reactive<Notice>(traveInfomation)
|
||||
// debugger;
|
||||
Notice.userId = appStore.userInfo?.id;
|
||||
|
||||
watch(() => appStore.userInfo, (uI) => {
|
||||
// Notice.userId
|
||||
Notice.userId = uI?.id;
|
||||
})
|
||||
|
||||
// Ipc.singleListen = (rowData) => {
|
||||
// initImgPreviewInfo(rowData);
|
||||
// imgIndex.value = (ipcImgList.value || []).findIndex(item => rowData.id == item.id) || 0;
|
||||
// visible.value = true;
|
||||
// }
|
||||
|
||||
const initImgPreviewInfo = (data) => {
|
||||
imgPreviewInfo.id = data?.["id"];
|
||||
imgPreviewInfo.imgUrl = data?.["imgUrl"];
|
||||
imgPreviewInfo.position = data?.["position"];
|
||||
imgPreviewInfo.time = data?.["time"];
|
||||
imgPreviewInfo.deviceName = data?.["deviceName"];
|
||||
}
|
||||
|
||||
watch(imgIndex, (i) => {
|
||||
initImgPreviewInfo(ipcImgList.value?.[i]);
|
||||
})
|
||||
|
||||
watch(visible, () => {
|
||||
if (!visible) {
|
||||
imgIndex.value = 0;
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const onDataChange = (data) => {
|
||||
// ipcImgList.value = data || [];
|
||||
}
|
||||
|
||||
const onImgIdxChange = (idx: TImgPreviewIdx) => {
|
||||
let tempIdx = imgIndex.value;
|
||||
tempIdx += idx;
|
||||
|
||||
if (tempIdx >= 0 && tempIdx < ipcImgList.value?.length) {
|
||||
imgIndex.value = tempIdx;
|
||||
}
|
||||
}
|
||||
|
||||
const onFire = async (key: string, value, data: any) => {
|
||||
// imgIndex.value = 0;
|
||||
// const resData = await api.getCaputreImgListByIpcId({ id: data })
|
||||
// ipcImgList.value = resData.data?.objectList || [];
|
||||
// initImgPreviewInfo(ipcImgList.value?.[0]);
|
||||
currentDeviceId.value = value;
|
||||
visible.value = true;
|
||||
}
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
:local(.img-preview-dialog) {
|
||||
:local(.footer) {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
>div {
|
||||
margin-left: 40px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>通知列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Notice" :data="[]" @data-change="onDataChange"></um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import Notice from "@/containers/viewModel/Notice";
|
||||
|
||||
/**
|
||||
* 通知列表。
|
||||
*
|
||||
* 改造前这里塞了一整套「图片预览」的残骸:`imgPreviewInfo`、`ipcImgList`、
|
||||
* `imgIndex`、`currentDeviceId`、`initImgPreviewInfo`、`onImgIdxChange`、
|
||||
* 两个 watch、以及 import 了却没用到的 `ImgPreview` / `api` / `reactive`。
|
||||
* 这些字段对应的模板一个都没渲染,属于从抓拍页面复制过来的死代码,
|
||||
* 一并删掉;需要的回调保留为空实现并注明用途。
|
||||
*/
|
||||
const onDataChange = (_data: any) => {
|
||||
// 预留:表格数据变化回调
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+32
-35
@@ -1,35 +1,32 @@
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>插件列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Plugin2" :data="[]"
|
||||
:other-params="{ userId: appStore?.userInfo?.id }">
|
||||
</um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import Plugin2 from "@/containers/viewModel/Plugin";
|
||||
import { useAppStore } from "@/store/app";
|
||||
|
||||
const appStore = useAppStore();
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
:local(.img-preview-dialog) {
|
||||
:local(.footer) {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
>div {
|
||||
margin-left: 40px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>插件列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="Plugin2" :data="[]" @data-change="onDataChange"></um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import Plugin2 from "@/containers/viewModel/Plugin";
|
||||
|
||||
/**
|
||||
* 插件列表。
|
||||
*
|
||||
* 改造前传了 `:other-params="{ userId }"`,但 `funjiaui@v1.1.3` 的
|
||||
* `UmByClassEnhance` 只把它展开进 `getList()` 的查询参数,**不会**传给
|
||||
* `onAdd` / `onEdit`;而插件表的列表接口并不按 userId 过滤,
|
||||
* 这个参数实际没有任何作用,删掉以免产生“已经带上了归属人”的错觉。
|
||||
*/
|
||||
const onDataChange = (_data: any) => {
|
||||
// 预留:表格数据变化回调
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+25
-99
@@ -1,99 +1,25 @@
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>问答列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="QA" :data="[]" @data-change="onDataChange" @fire="onFire">
|
||||
</um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
// import UmTableClassEnhance from "@/components/UmTable/UmByClassEnhance.vue";
|
||||
// import { UmByClassEnhance as UmTableClassEnhance } from "../../lib/funjiaui.es.js";
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
// import UmDialog from "@/components/UmDialog/index.vue";
|
||||
import QA from "@/containers/viewModel/QA";
|
||||
|
||||
import { ref, reactive, watch } from "vue";
|
||||
import * as api from "@/common/api";
|
||||
// import { fDT } from "marsLib/date";
|
||||
// import CaptureList from "@/containers/CaptureList.vue";
|
||||
// import "funjiaui/style.css";
|
||||
|
||||
const visible = ref(false);
|
||||
const imgIndex = ref(0);
|
||||
const ipcImgList = ref([]);
|
||||
const imgPreviewInfo = reactive({
|
||||
id: "",
|
||||
imgUrl: "",
|
||||
position: "",
|
||||
time: "",
|
||||
deviceName: ""
|
||||
});
|
||||
const currentDeviceId = ref(null);
|
||||
|
||||
// Ipc.singleListen = (rowData) => {
|
||||
// initImgPreviewInfo(rowData);
|
||||
// imgIndex.value = (ipcImgList.value || []).findIndex(item => rowData.id == item.id) || 0;
|
||||
// visible.value = true;
|
||||
// }
|
||||
|
||||
const initImgPreviewInfo = (data) => {
|
||||
imgPreviewInfo.id = data?.["id"];
|
||||
imgPreviewInfo.imgUrl = data?.["imgUrl"];
|
||||
imgPreviewInfo.position = data?.["position"];
|
||||
imgPreviewInfo.time = data?.["time"];
|
||||
imgPreviewInfo.deviceName = data?.["deviceName"];
|
||||
}
|
||||
|
||||
watch(imgIndex, (i) => {
|
||||
initImgPreviewInfo(ipcImgList.value?.[i]);
|
||||
})
|
||||
|
||||
watch(visible, () => {
|
||||
if (!visible) {
|
||||
imgIndex.value = 0;
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const onDataChange = (data) => {
|
||||
// ipcImgList.value = data || [];
|
||||
}
|
||||
|
||||
const onImgIdxChange = (idx: TImgPreviewIdx) => {
|
||||
let tempIdx = imgIndex.value;
|
||||
tempIdx += idx;
|
||||
|
||||
if (tempIdx >= 0 && tempIdx < ipcImgList.value?.length) {
|
||||
imgIndex.value = tempIdx;
|
||||
}
|
||||
}
|
||||
|
||||
const onFire = async (key: string, value, data: any) => {
|
||||
// imgIndex.value = 0;
|
||||
// const resData = await api.getCaputreImgListByIpcId({ id: data })
|
||||
// ipcImgList.value = resData.data?.objectList || [];
|
||||
// initImgPreviewInfo(ipcImgList.value?.[0]);
|
||||
currentDeviceId.value = value;
|
||||
visible.value = true;
|
||||
}
|
||||
</script>
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
:local(.img-preview-dialog) {
|
||||
:local(.footer) {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
>div {
|
||||
margin-left: 40px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div :class="$style['device-list']">
|
||||
<h2>问答列表</h2>
|
||||
<um-table-class-enhance class="role-right" :target="QA" :data="[]" @data-change="onDataChange"></um-table-class-enhance>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UmByClassEnhance as UmTableClassEnhance } from "funjiaui";
|
||||
import QA from "@/containers/viewModel/QA";
|
||||
|
||||
/** 问答列表(死代码清理同 Notice.vue) */
|
||||
const onDataChange = (_data: any) => {
|
||||
// 预留:表格数据变化回调
|
||||
};
|
||||
</script>
|
||||
|
||||
<style module lang="scss">
|
||||
:global {
|
||||
:local(.device-list) {
|
||||
padding: 20px;
|
||||
background-color: #FFF;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
+53
-41
@@ -1,41 +1,53 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"target": "esnext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom"
|
||||
],
|
||||
"skipLibCheck": true,
|
||||
"types": [
|
||||
"element-plus/global"
|
||||
],
|
||||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.d.ts",
|
||||
"src/**/*.tsx",
|
||||
"src/**/*.vue"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
],
|
||||
/*
|
||||
* `funjia-axios` 的 main 直接指向未编译的 `index.ts`,且自身缺少类型标注
|
||||
* (`axios.prototype.error = (msg) => {}` 这类写法会触发 TS7006,它也无法
|
||||
* 解析自己的 axios / js-cookie 依赖)。这里把它的类型改为本项目提供的
|
||||
* 声明文件,既让 `vue-tsc` 干净通过,也不必改动上游仓库源码。
|
||||
*/
|
||||
"funjia-axios": [
|
||||
"src/type/funjia-axios.d.ts"
|
||||
]
|
||||
},
|
||||
"target": "esnext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom"
|
||||
],
|
||||
"skipLibCheck": true,
|
||||
"types": [
|
||||
"element-plus/global"
|
||||
],
|
||||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.d.ts",
|
||||
"src/**/*.tsx",
|
||||
"src/**/*.vue"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+69
-67
@@ -1,67 +1,69 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
import ElementPlus from 'unplugin-element-plus/vite'
|
||||
import { resolve } from "path";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue(),
|
||||
AutoImport({
|
||||
resolvers: [ElementPlusResolver()],
|
||||
}),
|
||||
Components({
|
||||
resolvers: [ElementPlusResolver()],
|
||||
}),
|
||||
ElementPlus({
|
||||
// options
|
||||
})
|
||||
],
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
proxy: {
|
||||
"^/api": {
|
||||
// target: "http://localhost:4873/",
|
||||
target: "http://all.funjia.top/",
|
||||
changeOrigin: true,
|
||||
},
|
||||
"^/static": {
|
||||
target: "http://localhost:4873/resource/",
|
||||
changeOrigin: true,
|
||||
},
|
||||
"^/set/log/level": {
|
||||
target: "http://192.168.1.89:4873/",
|
||||
changeOrigin: true,
|
||||
},
|
||||
"^/cache/image/": {
|
||||
target: "http://192.168.1.102:1221/",
|
||||
changeOrigin: true,
|
||||
},
|
||||
"^/get/service/": {
|
||||
target: "http://192.168.1.102:1221/",
|
||||
changeOrigin: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
build: {
|
||||
cssCodeSplit: true, // 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
|
||||
sourcemap: false, // 构建后是否生成 source map 文件。如果为 true,将会创建一个独立的 source map 文件
|
||||
target: 'modules', // 设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——'modules' 还可设置为 'es2015' 'es2016'等
|
||||
chunkSizeWarningLimit: 550, // 单位kb 打包后文件大小警告的限制 (文件大于此此值会出现警告)
|
||||
assetsInlineLimit: 4096, // 单位字节(1024等于1kb) 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项。
|
||||
minify: 'terser', // 'terser' 相对较慢,但大多数情况下构建后的文件体积更小。'esbuild' 最小化混淆更快但构建后的文件相对更大。
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true, // 生产环境去除console
|
||||
drop_debugger: true // 生产环境去除debugger
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import AutoImport from "unplugin-auto-import/vite";
|
||||
import Components from "unplugin-vue-components/vite";
|
||||
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
|
||||
import { resolve } from "path";
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
// 代理目标抽到 .env 里,避免把内网 IP 硬编码进仓库
|
||||
const env = loadEnv(mode, process.cwd(), "VITE_");
|
||||
const apiTarget = env.VITE_API_TARGET || "http://localhost:4873/";
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
vue(),
|
||||
AutoImport({
|
||||
// 显式声明 vue 的自动导入,避免依赖“碰巧能跑”的全局注入
|
||||
imports: ["vue", "vue-router"],
|
||||
resolvers: [ElementPlusResolver()],
|
||||
dts: "auto-imports.d.ts",
|
||||
}),
|
||||
Components({
|
||||
resolvers: [ElementPlusResolver()],
|
||||
dts: "components.d.ts",
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 4444,
|
||||
host: true,
|
||||
proxy: {
|
||||
"^/api": { target: apiTarget, changeOrigin: true },
|
||||
"^/static": { target: `${apiTarget}resource/`, changeOrigin: true },
|
||||
"^/set/log/level": { target: apiTarget, changeOrigin: true },
|
||||
"^/cache/image/": { target: apiTarget, changeOrigin: true },
|
||||
"^/get/service/": { target: apiTarget, changeOrigin: true },
|
||||
},
|
||||
},
|
||||
build: {
|
||||
cssCodeSplit: true,
|
||||
sourcemap: false,
|
||||
target: "es2015",
|
||||
chunkSizeWarningLimit: 550,
|
||||
assetsInlineLimit: 4096,
|
||||
// terser 已在 devDependencies 中显式声明(原配置指定了 terser 却没装)
|
||||
minify: "terser",
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true,
|
||||
drop_debugger: true,
|
||||
},
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
// 拆包:element-plus 与 funjiaui 体积较大,独立成 chunk 便于缓存
|
||||
manualChunks: {
|
||||
"element-plus": ["element-plus"],
|
||||
funjiaui: ["funjiaui"],
|
||||
vendor: ["vue", "vue-router", "pinia", "axios"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user