后端分享功能实现
This commit is contained in:
parent
47f79ff458
commit
77191b4d3a
@ -1,5 +1,8 @@
|
|||||||
package xyz.longicorn.driver.controller;
|
package xyz.longicorn.driver.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.captcha.generator.RandomGenerator;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import xyz.longicorn.driver.dto.ApiResult;
|
import xyz.longicorn.driver.dto.ApiResult;
|
||||||
@ -18,7 +21,18 @@ public class ShareController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/create")
|
@RequestMapping("/create")
|
||||||
public ApiResult create(ShareInfo info){
|
public ApiResult create(@RequestBody ShareInfo info){
|
||||||
|
String id = StpUtil.getLoginId().toString();
|
||||||
|
// 设置分享者
|
||||||
|
info.setUid(Integer.parseInt(id));
|
||||||
|
// 设置密码
|
||||||
|
if("yes".equalsIgnoreCase(info.getPassword())){
|
||||||
|
RandomGenerator generator = new RandomGenerator("0123456789abcdefg", 4);
|
||||||
|
info.setPassword(generator.generate());
|
||||||
|
}else{
|
||||||
|
info.setPassword(null); // 不需要密码
|
||||||
|
}
|
||||||
|
info.setId((new RandomGenerator(10)).generate());
|
||||||
return ApiResult.success(shareService.create(info));
|
return ApiResult.success(shareService.create(info));
|
||||||
}
|
}
|
||||||
@RequestMapping("/info")
|
@RequestMapping("/info")
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package xyz.longicorn.driver.pojo;
|
package xyz.longicorn.driver.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -17,7 +20,7 @@ import java.util.Date;
|
|||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class FileInfo implements Serializable {
|
public class FileInfo implements Serializable {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
private Integer uid;
|
private Integer uid;
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package xyz.longicorn.driver.pojo;
|
package xyz.longicorn.driver.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -16,7 +17,9 @@ import java.util.Date;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class ShareInfo {
|
public class ShareInfo {
|
||||||
@TableId
|
|
||||||
|
@TableId(type= IdType.AUTO)
|
||||||
|
private Integer no;
|
||||||
private String id;
|
private String id;
|
||||||
private String title;
|
private String title;
|
||||||
private Integer uid;
|
private Integer uid;
|
||||||
|
@ -9,6 +9,6 @@ import xyz.longicorn.driver.pojo.ShareInfo;
|
|||||||
public class ShareService extends ServiceImpl<ShareInfoMapper, ShareInfo> {
|
public class ShareService extends ServiceImpl<ShareInfoMapper, ShareInfo> {
|
||||||
public ShareInfo create(ShareInfo info) {
|
public ShareInfo create(ShareInfo info) {
|
||||||
this.save(info);
|
this.save(info);
|
||||||
return null;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ spring:
|
|||||||
redis:
|
redis:
|
||||||
database: 1
|
database: 1
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
host: 127.0.0.1
|
host: mq.1688cd.cn
|
||||||
port: 5672
|
port: 5672
|
||||||
username: client
|
username: client
|
||||||
password: 123123
|
password: 123123
|
||||||
|
@ -33,16 +33,16 @@ create table file_info
|
|||||||
-- 编号、分享名称、用户编号、分享的数据编号、分类类型(file|folder)、提取码、分享有效期、状态
|
-- 编号、分享名称、用户编号、分享的数据编号、分类类型(file|folder)、提取码、分享有效期、状态
|
||||||
create table share_info
|
create table share_info
|
||||||
(
|
(
|
||||||
id varchar(20) not null primary key,
|
id varchar(20) not null primary key,
|
||||||
title varchar(20) not null,
|
title varchar(20) not null,
|
||||||
uid int(10) not null,
|
uid int(10) not null,
|
||||||
file_id bigint(20) not null,
|
file_id bigint not null comment '要分享文件的真是数据编号',
|
||||||
type tinyint(1) default 1 comment '分类类型 1:文件 2:文件夹',
|
type tinyint(1) default 1 null comment '分类类型 1:文件 2:文件夹',
|
||||||
password varchar(20) null,
|
password varchar(20) null comment '分享密码',
|
||||||
live int default 0 comment '有效期',
|
live int default -1 null comment '有效期 时长-单位是秒,-1表示长期有效',
|
||||||
create_time datetime default current_timestamp,
|
create_time datetime default CURRENT_TIMESTAMP null,
|
||||||
update_time datetime on update current_timestamp,
|
update_time datetime null on update CURRENT_TIMESTAMP,
|
||||||
status tinyint(1) default 1,
|
status tinyint(1) default 1 null,
|
||||||
index ix_file_name (title)
|
index ix_file_name (title)
|
||||||
);
|
);
|
||||||
CREATE TABLE user_info
|
CREATE TABLE user_info
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" width="200">
|
<el-table-column label="创建时间" width="200">
|
||||||
<template #default="file">
|
<template #default="file">
|
||||||
<span class="list-file-time">{{ formatDate(file.row.createTime,'YYYY-MM-DD HH:mm') }}</span>
|
<span class="list-file-time">{{ formatDate(file.row.createTime, 'YYYY-MM-DD HH:mm') }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@ -99,31 +99,39 @@
|
|||||||
<!-- 分享 -->
|
<!-- 分享 -->
|
||||||
<el-dialog v-model="share.visible" title="分享文件" width="600px">
|
<el-dialog v-model="share.visible" title="分享文件" width="600px">
|
||||||
<div class="share-create-dialog">
|
<div class="share-create-dialog">
|
||||||
<h2>{{ share.current?.name }}</h2>
|
<div v-if="share.showResult">
|
||||||
<div class="live d-flex item">
|
<h3 style="margin-bottom: 10px;">分享成功</h3>
|
||||||
<div class="title">有效期:</div>
|
<el-input v-model="share.shareData" />
|
||||||
<div class="content">
|
|
||||||
<el-radio-group v-model="share.live">
|
|
||||||
<el-radio-button label="1">1天</el-radio-button>
|
|
||||||
<el-radio-button label="7">7天</el-radio-button>
|
|
||||||
<el-radio-button label="30">30天</el-radio-button>
|
|
||||||
</el-radio-group>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="password d-flex item">
|
<div v-else>
|
||||||
<div class="title">提取码:</div>
|
<h2>{{ share.current?.name }}</h2>
|
||||||
<div class="content">
|
<div class="live d-flex item">
|
||||||
<el-radio-group v-model="share.password">
|
<div class="title">有效期:</div>
|
||||||
<el-radio-button label="yes">需要</el-radio-button>
|
<div class="content">
|
||||||
<el-radio-button label="no">不需要</el-radio-button>
|
<el-radio-group v-model="share.live">
|
||||||
</el-radio-group>
|
<el-radio-button label="1">1天</el-radio-button>
|
||||||
|
<el-radio-button label="7">7天</el-radio-button>
|
||||||
|
<el-radio-button label="30">30天</el-radio-button>
|
||||||
|
<el-radio-button label="-1">长期有效</el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="password d-flex item">
|
||||||
|
<div class="title">提取码:</div>
|
||||||
|
<div class="content">
|
||||||
|
<el-radio-group v-model="share.password">
|
||||||
|
<el-radio-button label="yes">需要</el-radio-button>
|
||||||
|
<el-radio-button label="no">不需要</el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="dialog-footer">
|
<div class="dialog-footer">
|
||||||
<span style="color: #999;font-size: 12px;float: left;">配合净网行动, 网盘严厉打击色情低俗等不良信息的传播行为</span>
|
<span style="color: #999;font-size: 12px;float: left;">配合净网行动, 网盘严厉打击色情低俗等不良信息的传播行为</span>
|
||||||
<el-button type="primary" :loading="share.loading" @click="handleCreateFolder">创建分享</el-button>
|
<el-button type="primary" v-if="share.showResult">关闭</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="share.loading" @click="handleCreateShare">创建分享</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -203,12 +211,14 @@ export default {
|
|||||||
*/
|
*/
|
||||||
info: null,
|
info: null,
|
||||||
live: 1,
|
live: 1,
|
||||||
password: 'yes'
|
password: 'yes',
|
||||||
|
showResult: false,
|
||||||
|
shareData: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch:{
|
watch: {
|
||||||
'$route'(){
|
'$route'() {
|
||||||
// console.log(this.$route)
|
// console.log(this.$route)
|
||||||
this.handleHashChange();
|
this.handleHashChange();
|
||||||
}
|
}
|
||||||
@ -284,13 +294,40 @@ export default {
|
|||||||
if (option.slug == 'share') {
|
if (option.slug == 'share') {
|
||||||
// 分享
|
// 分享
|
||||||
this.share.current = item
|
this.share.current = item
|
||||||
|
// 还原分享的数据
|
||||||
|
this.share.info = {}
|
||||||
|
this.share.showResult = false
|
||||||
this.share.visible = true;
|
this.share.visible = true;
|
||||||
|
|
||||||
} else if (option.slug == 'rename') {
|
} else if (option.slug == 'rename') {
|
||||||
this.renameFile(item);
|
this.renameFile(item);
|
||||||
} else if (option.slug == 'delete') {
|
} else if (option.slug == 'delete') {
|
||||||
this.deleteFile(item);
|
this.deleteFile(item);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
handleCreateShare() {
|
||||||
|
this.share.info = {
|
||||||
|
title: this.share.current.name,
|
||||||
|
fileId: this.share.current.id,
|
||||||
|
//1:文件 2:文件夹
|
||||||
|
type: this.share.current.type == 'folder' ? 2 : 1,
|
||||||
|
password: this.share.password,
|
||||||
|
live: this.share.live === '-1' ? -1 : (this.share.live * 24 * 3600),
|
||||||
|
}
|
||||||
|
api.share.create(this.share.info).then(
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {ShareInfo} ret
|
||||||
|
*/
|
||||||
|
(ret) => {
|
||||||
|
console.log(ret)
|
||||||
|
this.share.info = ret;
|
||||||
|
this.share.showResult = true
|
||||||
|
this.share.shareData = 'http://localhost:3000/s/' + ret.id + (
|
||||||
|
ret.password ? ' 提取码:' + ret.password : ''
|
||||||
|
)
|
||||||
|
}).catch(e => ElMessage.error('分享失败(' + e.message + ')'));
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {FileItem} file
|
* @param {FileItem} file
|
||||||
@ -370,17 +407,19 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.list-file-info{
|
.list-file-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
}
|
}
|
||||||
.list-file-icon{
|
|
||||||
|
.list-file-icon {
|
||||||
width: 40px;
|
width: 40px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
.list-file-name{
|
|
||||||
|
.list-file-name {
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
@ -53,12 +53,16 @@ function request(api, method = 'GET', postData = {}, progressChange = null) {
|
|||||||
}
|
}
|
||||||
let Authorization = store.getters.userToken
|
let Authorization = store.getters.userToken
|
||||||
if (Authorization) {
|
if (Authorization) {
|
||||||
options = {
|
if(!options.headers) {
|
||||||
headers: {
|
options.headers = {}
|
||||||
Authorization
|
|
||||||
},
|
|
||||||
...options
|
|
||||||
}
|
}
|
||||||
|
options.headers.Authorization = Authorization;
|
||||||
|
// options = {
|
||||||
|
// ...options,
|
||||||
|
// headers: {
|
||||||
|
// Authorization
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
10
web/src/service/type.d.ts
vendored
10
web/src/service/type.d.ts
vendored
@ -1,4 +1,8 @@
|
|||||||
declare type ApiResult = { code: number, message: string, data: any }
|
interface ApiResult<T> {
|
||||||
|
code: number
|
||||||
|
message: string
|
||||||
|
data: T
|
||||||
|
}
|
||||||
declare type FileItem = {
|
declare type FileItem = {
|
||||||
createTime: string,
|
createTime: string,
|
||||||
id: number,
|
id: number,
|
||||||
@ -8,8 +12,8 @@ declare type FileItem = {
|
|||||||
* 缩略图
|
* 缩略图
|
||||||
*/
|
*/
|
||||||
thumb: string,
|
thumb: string,
|
||||||
size: number,
|
size: number
|
||||||
type: 'folder' | string,
|
type: 'folder' | string
|
||||||
updateTime: string
|
updateTime: string
|
||||||
}
|
}
|
||||||
declare type FileIconInstance = {
|
declare type FileIconInstance = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user