Skip to content

Commit

Permalink
Merge pull request Antabot#1 from Antabot/dev
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Antabot authored Apr 13, 2019
2 parents 711d421 + 501f5cd commit 4318b35
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 48 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

作为核心功能页面之一,提供图书信息展示、图书信息管理两大功能

![图书馆](https://i.loli.net/2019/04/11/5caf26090f605.jpg)
![图书馆](https://i.loli.net/2019/04/13/5cb1e3d5acf1d.png)

图书上传界面

![图书上传](https://i.loli.net/2019/04/13/5cb1e3d562751.png)

功能实现情况

Expand All @@ -29,7 +33,6 @@
功能描述 | 实现情况
---|---
基本信息 | 完成
扩充信息 | 未完成

### 2.图书管理

Expand Down Expand Up @@ -120,6 +123,7 @@ npm run build

# 近期更新

04-13 完成图片的上传功能
04-11 完成图书分类功能
04-08 完成图书分页功能
04-06 完成图书查询功能
Expand Down
5 changes: 3 additions & 2 deletions wj-vue/src/components/common/NavMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<el-menu
:default-active="'/index'"
router="true"
router
mode="horizontal"
@select="handleSelect"
background-color="white"
Expand Down Expand Up @@ -36,7 +36,8 @@
{name: '/jotter', navItem: '笔记本'},
{name: '/library', navItem: '图书馆'},
{name: '#nowhere', navItem: '个人中心'}
]
],
keywords: ''
}
},
computed: {
Expand Down
14 changes: 7 additions & 7 deletions wj-vue/src/components/home/UpdateCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
</div>
<div class="block">
<el-timeline>
<el-timeline-item timestamp="2019/4/13" placement="top">
<el-card>
<h4>实现上传至服务器和输入 URL 两种方式添加封面</h4>
<p>Evan 提交于 2019/4/13 21:32</p>
</el-card>
</el-timeline-item>
<el-timeline-item timestamp="2019/4/11" placement="top">
<el-card>
<h4>实现图书分类功能</h4>
Expand All @@ -30,20 +36,14 @@
<p>Evan 提交于 2019/4/5 22:52</p>
</el-card>
</el-timeline-item>
<el-timeline-item timestamp="2019/4/4" placement="top">
<el-card>
<h4>实现图书删除功能</h4>
<p>Evan 提交于 2019/4/4 22:50</p>
</el-card>
</el-timeline-item>
</el-timeline>
</div>
</el-card>
</template>

<script>
export default {
name: 'Card'
name: 'UpdateCard'
}
</script>

Expand Down
28 changes: 21 additions & 7 deletions wj-vue/src/components/library/EditForm.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<template>
<div>
<i class="el-icon-circle-plus-outline" @click="buttonClick"></i>
<i class="el-icon-circle-plus-outline" @click="dialogFormVisible = true"></i>
<el-dialog
title="添加/修改图书"
:visible.sync="dialogFormVisible">
<el-form :model="form" style="text-align: left" ref="dataForm">
:visible.sync="dialogFormVisible"
@close="clear">
<el-form v-model="form" style="text-align: left" ref="dataForm">
<el-form-item label="书名" :label-width="formLabelWidth" prop="title">
<el-input v-model="form.title" autocomplete="off" placeholder="不加《》"></el-input>
</el-form-item>
Expand All @@ -18,7 +19,8 @@
<el-input v-model="form.press" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="封面" :label-width="formLabelWidth" prop="cover">
<el-input v-model="form.cover" autocomplete="off" placeholder="请输入 URL"></el-input>
<el-input v-model="form.cover" autocomplete="off" placeholder="图片 URL"></el-input>
<img-upload @onUpload="uploadImg" ref="imgUpload"></img-upload>
</el-form-item>
<el-form-item label="简介" :label-width="formLabelWidth" prop="abs">
<el-input type="textarea" v-model="form.abs" autocomplete="off"></el-input>
Expand Down Expand Up @@ -46,8 +48,10 @@
</template>

<script>
import ImgUpload from './ImgUpload'
export default {
name: 'EditForm',
components: {ImgUpload},
data () {
return {
dialogFormVisible: false,
Expand All @@ -69,11 +73,18 @@
}
},
methods: {
buttonClick () {
clear () {
this.$refs.imgUpload.clear()
this.form = {
id: ''
id: '',
title: '',
author: '',
date: '',
press: '',
cover: '',
abs: '',
cid: ''
}
this.dialogFormVisible = true
},
onSubmit () {
this.category.id = this.form.cid
Expand All @@ -93,6 +104,9 @@
this.$emit('onSubmit')
}
})
},
uploadImg () {
this.form.cover = this.$refs.imgUpload.url
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions wj-vue/src/components/library/ImgUpload.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<el-upload
class="img-upload"
ref="upload"
action="http://localhost:8443/api/covers"
:on-preview="handlePreview"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:on-success="handleSuccess"
multiple
:limit="1"
:on-exceed="handleExceed"
:file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
</el-upload>
</template>

<script>
export default {
name: 'ImgUpload',
data () {
return {
fileList: [],
url: ''
}
},
methods: {
handleRemove (file, fileList) {
console.log(file, fileList)
},
handlePreview (file) {
console.log(file)
// 此处的 file 是整个文件
// console.log(file.response)
},
handleExceed (files, fileList) {
this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
},
beforeRemove (file, fileList) {
return this.$confirm(`确定移除 ${file.name}`)
},
handleSuccess (response) {
this.url = response
// console.log(this.url)
this.$emit('onUpload')
this.$message.warning('上传成功')
},
clear () {
this.$refs.upload.clearFiles()
}
}
}
</script>

<style scoped>
.img-upload {
/*height: 200px;*/
}
</style>
3 changes: 2 additions & 1 deletion wj-vue/src/components/library/LibraryIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import Tag from './Tag'
import Books from './Books'
import About from '../common/About'
import ImgUpload from './ImgUpload'
export default {
name: 'AppLibrary',
components: {Books, Tag, SideMenu, About},
components: {Books, Tag, SideMenu, About, ImgUpload},
methods: {
listByCategory () {
var _this = this
Expand Down
9 changes: 5 additions & 4 deletions wj-vue/src/components/library/SideMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@

<style scoped>
.categories {
/*position: fixed;*/
/*margin-left: 50%;*/
/*left: -520px;*/
/*top: 100px;*/
position: fixed;
margin-left: 50%;
left: -600px;
top: 100px;
width: 150px;
}
</style>
26 changes: 14 additions & 12 deletions wj/src/main/java/com/gm/wj/config/MyWebConfigurer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.gm.wj.config;

import com.gm.wj.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.*;

@SpringBootConfiguration
public class MyWebConfigurer implements WebMvcConfigurer {
Expand All @@ -22,14 +20,18 @@ public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(getLoginIntercepter()).addPathPatterns("/**").excludePathPatterns("/index.html");
}

// @Override
// public void addCorsMappings(CorsRegistry registry) {
// //所有请求都允许跨域
// registry.addMapping("/**")
// .allowedOrigins("*")
// .allowedMethods("*")
// .allowedHeaders("*");
// }
@Override
public void addCorsMappings(CorsRegistry registry) {
//所有请求都允许跨域
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*");
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/api/file/**").addResourceLocations("file:" + "d:/workspace/img/");
}

}
59 changes: 49 additions & 10 deletions wj/src/main/java/com/gm/wj/controller/LibraryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,46 @@
import com.gm.wj.pojo.Book;
import com.gm.wj.pojo.Search;
import com.gm.wj.service.BookService;
import com.sun.imageio.plugins.common.ImageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Random;

@RestController
public class LibraryController {
@Autowired
BookService bookService;

@CrossOrigin
@GetMapping(value = "/api/books")
@GetMapping("/api/books")
public List<Book> list() throws Exception {
return bookService.list();
}

@CrossOrigin
@PostMapping(value = "/api/books")
@PostMapping("/api/books")
public Book addOrUpdate(@RequestBody Book book) throws Exception {
System.out.println(book.getCategory());
bookService.addOrUpdate(book);
return book;
}

@CrossOrigin
@PostMapping(value = "/api/delete")
@PostMapping("/api/delete")
public void delete(@RequestBody Book book) throws Exception {
bookService.deleteById(book.getId());
}

@CrossOrigin
@PostMapping(value = "/api/search")
@PostMapping("/api/search")
public List<Book> searchResult(@RequestBody Search s) throws Exception {
if ("".equals(s.getKeywords())) {
return bookService.list();
Expand All @@ -43,14 +51,45 @@ public List<Book> searchResult(@RequestBody Search s) throws Exception {
}
}

@CrossOrigin
@GetMapping("/api/categories/{cid}/books")
public List<Book> listByCategory (@PathVariable("cid")int cid) throws Exception {
public List<Book> listByCategory(@PathVariable("cid") int cid) throws Exception {
if (0 != cid) {
return bookService.listByCategory(cid);
} else {
return list();
}
}

@PostMapping("api/covers")
public String coversUpload(MultipartFile file, HttpServletRequest request) throws Exception {
String folder = "D:/workspace/img";
File imageFolder = new File(folder);
File f = new File(imageFolder, getRandomString(6) + file.getOriginalFilename()
.substring(file.getOriginalFilename().length() - 4));
String filename = file.getName();
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
try {
file.transferTo(f);
// System.out.println(file.getOriginalFilename());
// System.out.println("http://localhost:8443/api/file/" + f.getName());
String imgURL = "http://localhost:8443/api/file/" + f.getName();
return imgURL;
} catch (IOException e) {
e.printStackTrace();
return "";
}
}

public String getRandomString(int length) {
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}

}
2 changes: 1 addition & 1 deletion wj/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ spring.jpa.hibernate.ddl-auto = none


spring.mvc.static-path-pattern=/**
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
2 changes: 1 addition & 1 deletion wj/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>白卷 - White Jotter</title><link href=/static/css/app.daf84395f98af98e2b54b8f49180f33e.css rel=stylesheet></head><body style="background: #f6f6f6"><div id=app></div><script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js></script><script type=text/javascript src=/static/js/vendor.578a67f45ff71504b68d.js></script><script type=text/javascript src=/static/js/app.0d870db5dc0ca2694c6a.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>白卷 - White Jotter</title><link href=/static/css/app.dc32149923d2eba22d5855d7ada511b1.css rel=stylesheet></head><body style="background: #f6f6f6"><div id=app></div><script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js></script><script type=text/javascript src=/static/js/vendor.578a67f45ff71504b68d.js></script><script type=text/javascript src=/static/js/app.633e822534ffa18fcf67.js></script></body></html>
Loading

0 comments on commit 4318b35

Please sign in to comment.