peng.peng
2 years ago
9 changed files with 155 additions and 22 deletions
@ -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 ( |
|||
<ModalForm |
|||
title="输入令牌" |
|||
trigger={ |
|||
<a>下载</a> |
|||
} |
|||
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} |
|||
> |
|||
<ProFormText |
|||
name="name" |
|||
label="访问令牌" |
|||
placeholder="请输入访问令牌" |
|||
rules={[{ required: true, message: '访问令牌不可空' }]} |
|||
/> |
|||
</ModalForm> |
|||
); |
|||
}; |
@ -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) |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue