From 8e85daf28aaa65b6844ccb76565b855534245ffc Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Wed, 14 Jun 2023 15:30:02 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E8=B5=84=E6=BA=90=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 7 +- .../controllers/resourceConsumption/index.js | 10 +-- api/app/lib/models/resource_consumption.js | 9 +++ .../containers/databasesTable.js | 4 +- .../containers/filesTable.js | 4 +- .../containers/restapisTable.js | 4 +- .../resourceRetrieval/components/keyModal.js | 44 +++++++++++++ .../resourceRetrieval/containers/retrieval.js | 65 ++++++++++++++++--- .../sections/resourceRetrieval/utils/index.js | 30 +++++++++ 9 files changed, 155 insertions(+), 22 deletions(-) create mode 100644 web/client/src/sections/resourceRetrieval/components/keyModal.js create mode 100644 web/client/src/sections/resourceRetrieval/utils/index.js diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index e3c6010..b9a4d4b 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -366,6 +366,7 @@ async function delMetadataDatabases(ctx) { } else { let resourceConsumptionInfo = await models.ResourceConsumption.findOne({ where: { + resourceId: id, resourceName: metadataDatabaseInfo.name, resourceType: '库表' } @@ -516,14 +517,14 @@ async function getTagMetadata(ctx) { //申请资源 async function postMetadataResourceApplications(ctx) { try { - const { resourceName, applyBy, resourceType } = ctx.request.body; - if (!resourceName || !applyBy || !resourceType) { + const { resourceName, applyBy, resourceType, resourceId } = ctx.request.body; + if (!resourceName || !applyBy || !resourceType || !resourceId) { ctx.status = 400; ctx.body = { message: '参数不全,请重新申请资源' } } else { const models = ctx.fs.dc.models; const postOne = await models.ResourceConsumption.findOne({ - where: { applyBy: applyBy, resourceName: resourceName } + where: { applyBy: applyBy, resourceName: resourceName, resourceId, resourceType } }); if (postOne) { ctx.status = 400; diff --git a/api/app/lib/controllers/resourceConsumption/index.js b/api/app/lib/controllers/resourceConsumption/index.js index 6bf41bc..5d8dc2f 100644 --- a/api/app/lib/controllers/resourceConsumption/index.js +++ b/api/app/lib/controllers/resourceConsumption/index.js @@ -1,11 +1,11 @@ 'use strict'; const moment = require('moment') -function getApproveList (opts) { +function getApproveList(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; - const { page, limit, applyAt, approveState, resourceName, applyBy, applyById, state } = ctx.query; + const { page, limit, applyAt, approveState, resourceName, applyBy, applyById, state ,} = ctx.query; let errMsg = { message: '获取消费审批列表失败' } try { @@ -81,7 +81,7 @@ function getApproveList (opts) { } // 新增模型 -function addModelManagement (opts) { +function addModelManagement(opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; @@ -108,7 +108,7 @@ function addModelManagement (opts) { } // 修改模型 -function postApprove (opts) { +function postApprove(opts) { return async function (ctx, next) { try { @@ -132,7 +132,7 @@ function postApprove (opts) { } // 删除模型 -function deleteModelManagement (opts) { +function deleteModelManagement(opts) { return async function (ctx, next) { try { diff --git a/api/app/lib/models/resource_consumption.js b/api/app/lib/models/resource_consumption.js index a0d8e8f..e87d5b9 100644 --- a/api/app/lib/models/resource_consumption.js +++ b/api/app/lib/models/resource_consumption.js @@ -16,6 +16,15 @@ module.exports = dc => { autoIncrement: true, unique: "t_resource_consumption_id_uindex" }, + resourceId: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "资源id", + primaryKey: false, + field: "resource_id", + autoIncrement: false + }, resourceName: { type: DataTypes.STRING, allowNull: false, diff --git a/web/client/src/sections/metadataManagement/containers/databasesTable.js b/web/client/src/sections/metadataManagement/containers/databasesTable.js index db40d2e..56d081a 100644 --- a/web/client/src/sections/metadataManagement/containers/databasesTable.js +++ b/web/client/src/sections/metadataManagement/containers/databasesTable.js @@ -92,7 +92,7 @@ const DatabaseTable = (props) => { }); } const applyResources = (record) => { - setEditResourceData({ record: { resourceName: record.name, applyBy: user.id, applyByName: user.name, resourceType: '库表' } }); + setEditResourceData({ record: { resourceId: record.id, resourceName: record.name, applyBy: user.id, applyByName: user.name, resourceType: '库表' } }); setResourceModalVisible(true); } @@ -170,7 +170,7 @@ const DatabaseTable = (props) => { width: '8%', render: (text, record) => { let resourceApplicationsRecords = metadataResourceApplications.filter(ra => - ra.applyBy == user.id && ra.resourceName === record.name); + ra.applyBy == user.id && ra.resourceName === record.name && ra.resourceId == record.id); return onView(record)}>查看 {user.role == '数据消费者' ? null : diff --git a/web/client/src/sections/metadataManagement/containers/filesTable.js b/web/client/src/sections/metadataManagement/containers/filesTable.js index ea81c8b..be58619 100644 --- a/web/client/src/sections/metadataManagement/containers/filesTable.js +++ b/web/client/src/sections/metadataManagement/containers/filesTable.js @@ -102,7 +102,7 @@ const FilesTable = (props) => { }); } const applyResources = (record) => { - setEditResourceData({ record: { resourceName: record.name, applyBy: user.id, applyByName: user.name, resourceType: '文件' } }); + setEditResourceData({ record: { resourceId: record.id, resourceName: record.name, applyBy: user.id, applyByName: user.name, resourceType: '文件' } }); setResourceModalVisible(true); } @@ -205,7 +205,7 @@ const FilesTable = (props) => { width: '8%', render: (text, record) => { let resourceApplicationsRecords = metadataResourceApplications.filter(ra => - ra.applyBy == user.id && ra.resourceName === record.name); + ra.applyBy == user.id && ra.resourceName === record.name && ra.resourceId == record.id); return {user.role == '数据消费者' ? null : <> diff --git a/web/client/src/sections/metadataManagement/containers/restapisTable.js b/web/client/src/sections/metadataManagement/containers/restapisTable.js index 09e08e9..704df43 100644 --- a/web/client/src/sections/metadataManagement/containers/restapisTable.js +++ b/web/client/src/sections/metadataManagement/containers/restapisTable.js @@ -79,7 +79,7 @@ const RestapisTable = (props) => { }); } const applyResources = (record) => { - setEditResourceData({ record: { resourceName: record.name, applyBy: user.id, applyByName: user.name, resourceType: '接口' } }); + setEditResourceData({ record: { resourceId: record.id, resourceName: record.name, applyBy: user.id, applyByName: user.name, resourceType: '接口' } }); setResourceModalVisible(true); } @@ -141,7 +141,7 @@ const RestapisTable = (props) => { width: '8%', render: (text, record) => { let resourceApplicationsRecords = metadataResourceApplications.filter(ra => - ra.applyBy == user.id && ra.resourceName === record.name); + ra.applyBy == user.id && ra.resourceName === record.name && ra.resourceId == record.id); return {user.role == '数据消费者' ? null : <> diff --git a/web/client/src/sections/resourceRetrieval/components/keyModal.js b/web/client/src/sections/resourceRetrieval/components/keyModal.js new file mode 100644 index 0000000..30ae3c3 --- /dev/null +++ b/web/client/src/sections/resourceRetrieval/components/keyModal.js @@ -0,0 +1,44 @@ +import React from 'react' +import { + ModalForm, + ProFormText, +} from '@ant-design/pro-form'; +import { Form, message } from 'antd'; + +export default (props) => { + const { resourceId, onFinish, approveList } = props; + const [form] = Form.useForm(); + + return ( + 下载 + } + form={form} + layout='horizontal' + autoFocusFirstInput + modalProps={{ + destroyOnClose: true, + }} + onFinish={async (values) => { + console.log(values.name); + const token = approveList?.rows?.find(s => s.resourceId == resourceId)?.token + if (token == values.name) { + onFinish() + return true; + } else { + message.error('令牌错误') + } + }} + width={500} + > + + + ); +}; \ No newline at end of file diff --git a/web/client/src/sections/resourceRetrieval/containers/retrieval.js b/web/client/src/sections/resourceRetrieval/containers/retrieval.js index 48c075c..954f24b 100644 --- a/web/client/src/sections/resourceRetrieval/containers/retrieval.js +++ b/web/client/src/sections/resourceRetrieval/containers/retrieval.js @@ -1,12 +1,17 @@ import React, { useEffect, useState } from 'react' -import { Input, Tooltip, Empty } from 'antd' -import { InsertRowBelowOutlined, DatabaseOutlined, FileOutlined, PullRequestOutlined } from '@ant-design/icons'; +import { Input, Tooltip, Empty, Pagination, Modal, Form } from 'antd' +import { InsertRowBelowOutlined, DatabaseOutlined, FileOutlined, PullRequestOutlined, KeyOutlined } from '@ant-design/icons'; import { useFsRequest, ApiTable } from '$utils'; +import { connect } from 'react-redux'; +import { downloadImg } from '../utils/index' +import KeyModal from '../components/keyModal'; import './style.less'; function Retrieval(props) { + const { user } = props; const [keywords, setKeywords] = useState() const [firstInput, setFirstInput] = useState() - + const [page, setPage] = useState(1) + const formRef = React.createRef(); const { data: catalogs = [] } = useFsRequest({ url: ApiTable.getResourceCatalog, }); @@ -20,7 +25,14 @@ function Retrieval(props) { ready: !!keywords }); - console.log(result) + const { data: approveList = {} } = useFsRequest({ + url: ApiTable.approveList, + query: { + applyById: user?.id + }, + refreshDeps: [user?.id], + ready: !!(user?.id) + }); const renderIcon = (type) => { switch (type) { @@ -54,6 +66,19 @@ function Retrieval(props) { : text } + const downloadData = (s) => { + if (s?.type == '文件') { + const suffix = s?.fileName?.substring(s?.fileName?.length - 3, s?.fileName?.length) + if (suffix == 'png' || suffix == 'jpg') { + downloadImg(s.fileName) + } else { + window.open('/assets/files/common/' + s.fileName) + } + } else { + alert('库表下载待开发') + } + } + return !result?.rows ?
数据资源检索
{ setKeywords(firstInput) }} style={{ color: '#fff' }}>搜索一下
} @@ -66,7 +91,7 @@ function Retrieval(props) { { setKeywords(value) }} /> - {result?.rows?.map(s => { + {result?.rows?.slice((page - 1) * 10, (page - 1) * 10 + 10).map(s => { const catalogText = renderCatalog(s?.catalog).split('/').reverse().toString().replaceAll(',', '/') const tagText = s?.tagDatabases?.map(x => x.tag.name).toString() || '-' return
@@ -78,13 +103,37 @@ function Retrieval(props) { 路径:{renderText(catalogText)} 标签:{renderText(tagText)}
-
相关操作:定位 - {s?.type == '表' || s?.type == '文件' ? 下载 : ''} +
相关操作: { window.open('/metadataManagement/latestMetadata') }}>定位 + {s?.type == '表' || s?.type == '文件' ? + user?.role == '数据消费者' ? + { + downloadData(s) + }} + /> : + { downloadData(s) }}>下载 : ''}
})} + {result?.rows?.length > 0 && `共 ${total} 条数据`} + onChange={(page, pageSize) => { + setPage(page) + }} + />} {!result?.rows?.length > 0 && } } -export default Retrieval \ No newline at end of file +function mapStateToProps(state) { + const { auth, } = state; + return { + user: auth.user, + }; +} +export default connect(mapStateToProps)(Retrieval) + diff --git a/web/client/src/sections/resourceRetrieval/utils/index.js b/web/client/src/sections/resourceRetrieval/utils/index.js new file mode 100644 index 0000000..ae547ef --- /dev/null +++ b/web/client/src/sections/resourceRetrieval/utils/index.js @@ -0,0 +1,30 @@ +const imageToBase64 = (img) => { + var canvas = document.createElement("canvas"); + canvas.width = img.width; + canvas.height = img.height; + var ctx = canvas.getContext("2d"); + console.log(img, canvas) + ctx.drawImage(img, 0, 0, img.width, img.height); + var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase(); + var dataURL = canvas.toDataURL("image/" + ext); + return dataURL; +} + +export const downloadImg = (fileName) => { + const url = '/assets/files/common/' + fileName + var image = new Image(); + image.crossOrigin = ''; + image.src = url; + image.onload = function () { + let base64 = imageToBase64(image); //图片转base64 + const link = document.createElement('a') + link.style.display = 'none' + //设置下载的图片名称 + link.download = fileName + link.href = base64 + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + } +} +