Browse Source

应用删除禁用接口

release_1.2.1
wenlele 2 years ago
parent
commit
b5a95f5b33
  1. 81
      code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js
  2. 10
      code/VideoAccess-VCMP/api/app/lib/routes/application/index.js
  3. 42
      code/VideoAccess-VCMP/web/client/src/sections/application/actions/application.js
  4. 5
      code/VideoAccess-VCMP/web/client/src/sections/application/actions/index.js

81
code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js

@ -16,7 +16,7 @@ async function edit (ctx, next) {
const storageData = Object.assign({}, data,)
await models.Application.update(storageData, {
where: {
id: data.id
id: data.appId
},
transaction
})
@ -46,11 +46,90 @@ async function edit (ctx, next) {
}
}
async function get (ctx) {
try {
const models = ctx.fs.dc.models;
const { userId } = ctx.fs.api
const { limit, page, orderBy, orderDirection } = ctx.query
let findOption = {
where: {
createUserId: userId,
},
order: [
[orderBy || 'id', orderDirection || 'DESC'] //查询排序
],
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
const nvrRes = await models.Application.findAndCountAll(findOption)
ctx.status = 200;
ctx.body = {
total: nvrRes.count,
data: nvrRes.rows
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
async function put (ctx) {
try {
const { models } = ctx.fs.dc;
const data = ctx.request.body;
// TODO 向视频服务发送通知
// 库记录
await models.Application.update({
forbidden: data.forbidden
}, {
where: {
id: data.appId
}
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
async function del (ctx, next) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models;
const { appId } = ctx.params
await models.Application.destroy({
where: {
id: appId
},
transaction
})
await transaction.commit();
ctx.status = 204;
} catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
module.exports = {
edit,
get,
put,
del
};

10
code/VideoAccess-VCMP/api/app/lib/routes/application/index.js

@ -5,10 +5,16 @@ const application = require('../../controllers/application');
module.exports = function (app, router, opts) {
// app.fs.api.logAttr['GET/application'] = { content: '获取应用信息', visible: false };
// router.get('/application', application.get);
app.fs.api.logAttr['GET/application'] = { content: '获取应用信息', visible: false };
router.get('/application', application.get);
app.fs.api.logAttr['POST/application'] = { content: '创建/修改应用', visible: false };
router.post('/application', application.edit);
app.fs.api.logAttr['PUT/application'] = { content: '禁用应用', visible: false }
router.put('/application', application.put);
app.fs.api.logAttr['DEL/application/:appId'] = { content: '删除应用', visible: false };
router.del('/application/:appId', application.del);
};

42
code/VideoAccess-VCMP/web/client/src/sections/application/actions/application.js

@ -0,0 +1,42 @@
"use strict";
import { basicAction } from "@peace/utils";
import { ApiTable } from "$utils";
export function getCamera(query) {
return (dispatch) =>
basicAction({
type: "get",
dispatch: dispatch,
actionType: "GET_APPLICATION",
query: query,
url: `${ApiTable.getCamera}`,
msg: { option: "获取摄像头列表信息" },
reducer: { name: "applicationData", params: { noClear: true } },
});
}
export function putForbidden(data, forbidden) {
return (dispatch) =>
basicAction({
type: "put",
dispatch: dispatch,
actionType: "PUT_APPLICATION",
data,
url: `${ApiTable.putForbidden}`,
msg: { option: forbidden ? "启用" : "禁用" }, //禁用摄像头
reducer: {},
});
}
export function delCamera(orgId) {
return (dispatch) =>
basicAction({
type: "del",
dispatch: dispatch,
actionType: "DEL_APPLICATION",
url: `${ApiTable.delCamera.replace("{cameraId}", orgId)}`,
msg: { option: "设备会被存放在“设备回收站”中,删除" }, //删除摄像头
reducer: {},
});
}

5
code/VideoAccess-VCMP/web/client/src/sections/application/actions/index.js

@ -1,5 +1,8 @@
'use strict';
export default {
import * as application from './application'
export default {
...application
}
Loading…
Cancel
Save