vue+spring boot 검사 코드 기능 구현
vue 로 검사 코드 를 써 서 놀 았 습 니 다.모양 은 다음 과 같 습 니 다.
1.img 태그
<img
="height:40px; width: 100px; cursor: pointer;"
ref="imgIdentifyingCode"
:src="selectedLogoPicture.imgUrl"
class="logoImg"
>
2.js 코드
/**
*
*/
getIdentifyingCode() {
let selft = this;
//let pic = this.$refs.imgIdentifyingCode
selft.loadingChack = true;
let uuid = Utils.getUuid(32, 16);
this.$store.state.uuid = uuid;
this.$api.reader.getVerify(
{ responseType: "arraybuffer", uuid: uuid },
r => {
selft.loadingChack = false;
selft.selectedLogoPicture.imgUrl = "data:image/png;base64," + r;
}
);
},
3.controller
@RequestMapping("/getVerify")
public void getVerify(@RequestParam String uuid, HttpServletRequest request, HttpServletResponse response) {
response.setContentType("image/jpeg");// ,
response.setHeader("Pragma", "No-cache");// ,
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expire", 0);
userService.getRandcodedDawTransparent(uuid, request, response);//
}
4.service
@Override
public void getRandcodedDawTransparent(String uuid, HttpServletRequest request, HttpServletResponse response) {
try {
Map<String, Object> map = CodeUtil.getRandcodedDawTransparent();
// session
log.info("== uuid:"+uuid);
log.info("== code:"+map.get("code"));
sessionUtil.saveCode(uuid, map.get("code"));
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
out.write((byte[]) map.get("img"));
out.flush();
out.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
5.util
public static Map<String, Object> getRandcodedDawTransparent() throws IOException {
Map<String, Object> rsMap = new HashMap<>();
// BufferedImage
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// Graphics2D
Graphics2D g2d = image.createGraphics();
//
image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
g2d.dispose();
g2d = image.createGraphics();
g2d.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18));//
g2d.setColor(getRandColor(110, 133));//
//
for (int i = 0; i <= lineSize; i++) {
drowLine(g2d, width, height);
}
//
String randomString = "";
for (int i = 1; i <= stringNum; i++) {
randomString = drowString(g2d, randomString, i);
}
log.info(randomString);
rsMap.put("code", randomString);
g2d.dispose();
ByteArrayOutputStream baos = new ByteArrayOutputStream();// io
ImageIO.write(image, "png", baos);//
byte[] bytes = baos.toByteArray();//
bytes = Base64.encodeBase64(bytes);
rsMap.put("img", bytes);
return rsMap;
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fastapi websocket 및 vue 3(Composition API)1부: FastAPI virtualenv 만들기(선택 사항) FastAPI 및 필요한 모든 것을 다음과 같이 설치하십시오. 생성main.py 파일 및 실행 - 브라우저에서 이 링크 열기http://127.0.0.1:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.