后端分享功能实现
This commit is contained in:
parent
47f79ff458
commit
77191b4d3a
@ -1,5 +1,8 @@
|
||||
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.RestController;
|
||||
import xyz.longicorn.driver.dto.ApiResult;
|
||||
@ -18,7 +21,18 @@ public class ShareController {
|
||||
* @return
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
@RequestMapping("/info")
|
||||
|
@ -1,5 +1,8 @@
|
||||
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.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -17,7 +20,7 @@ import java.util.Date;
|
||||
@Accessors(chain = true)
|
||||
public class FileInfo implements Serializable {
|
||||
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private Integer uid;
|
||||
private String name;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package xyz.longicorn.driver.pojo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@ -16,7 +17,9 @@ import java.util.Date;
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class ShareInfo {
|
||||
@TableId
|
||||
|
||||
@TableId(type= IdType.AUTO)
|
||||
private Integer no;
|
||||
private String id;
|
||||
private String title;
|
||||
private Integer uid;
|
||||
|
@ -9,6 +9,6 @@ import xyz.longicorn.driver.pojo.ShareInfo;
|
||||
public class ShareService extends ServiceImpl<ShareInfoMapper, ShareInfo> {
|
||||
public ShareInfo create(ShareInfo info) {
|
||||
this.save(info);
|
||||
return null;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ spring:
|
||||
redis:
|
||||
database: 1
|
||||
rabbitmq:
|
||||
host: 127.0.0.1
|
||||
host: mq.1688cd.cn
|
||||
port: 5672
|
||||
username: client
|
||||
password: 123123
|
||||
|
@ -33,16 +33,16 @@ create table file_info
|
||||
-- 编号、分享名称、用户编号、分享的数据编号、分类类型(file|folder)、提取码、分享有效期、状态
|
||||
create table share_info
|
||||
(
|
||||
id varchar(20) not null primary key,
|
||||
title varchar(20) not null,
|
||||
uid int(10) not null,
|
||||
file_id bigint(20) not null,
|
||||
type tinyint(1) default 1 comment '分类类型 1:文件 2:文件夹',
|
||||
password varchar(20) null,
|
||||
live int default 0 comment '有效期',
|
||||
create_time datetime default current_timestamp,
|
||||
update_time datetime on update current_timestamp,
|
||||
status tinyint(1) default 1,
|
||||
id varchar(20) not null primary key,
|
||||
title varchar(20) not null,
|
||||
uid int(10) not null,
|
||||
file_id bigint not null comment '要分享文件的真是数据编号',
|
||||
type tinyint(1) default 1 null comment '分类类型 1:文件 2:文件夹',
|
||||
password varchar(20) null comment '分享密码',
|
||||
live int default -1 null comment '有效期 时长-单位是秒,-1表示长期有效',
|
||||
create_time datetime default CURRENT_TIMESTAMP null,
|
||||
update_time datetime null on update CURRENT_TIMESTAMP,
|
||||
status tinyint(1) default 1 null,
|
||||
index ix_file_name (title)
|
||||
);
|
||||
CREATE TABLE user_info
|
||||
|
@ -65,7 +65,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" width="200">
|
||||
<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>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@ -99,31 +99,39 @@
|
||||
<!-- 分享 -->
|
||||
<el-dialog v-model="share.visible" title="分享文件" width="600px">
|
||||
<div class="share-create-dialog">
|
||||
<h2>{{ share.current?.name }}</h2>
|
||||
<div class="live d-flex item">
|
||||
<div class="title">有效期:</div>
|
||||
<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 v-if="share.showResult">
|
||||
<h3 style="margin-bottom: 10px;">分享成功</h3>
|
||||
<el-input v-model="share.shareData" />
|
||||
</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 v-else>
|
||||
<h2>{{ share.current?.name }}</h2>
|
||||
<div class="live d-flex item">
|
||||
<div class="title">有效期:</div>
|
||||
<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-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>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<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>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@ -203,12 +211,14 @@ export default {
|
||||
*/
|
||||
info: null,
|
||||
live: 1,
|
||||
password: 'yes'
|
||||
password: 'yes',
|
||||
showResult: false,
|
||||
shareData: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
'$route'(){
|
||||
watch: {
|
||||
'$route'() {
|
||||
// console.log(this.$route)
|
||||
this.handleHashChange();
|
||||
}
|
||||
@ -284,13 +294,40 @@ export default {
|
||||
if (option.slug == 'share') {
|
||||
// 分享
|
||||
this.share.current = item
|
||||
// 还原分享的数据
|
||||
this.share.info = {}
|
||||
this.share.showResult = false
|
||||
this.share.visible = true;
|
||||
|
||||
} else if (option.slug == 'rename') {
|
||||
this.renameFile(item);
|
||||
} else if (option.slug == 'delete') {
|
||||
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
|
||||
@ -370,17 +407,19 @@ export default {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.list-file-info{
|
||||
.list-file-info {
|
||||
display: flex;
|
||||
line-height: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
.list-file-icon{
|
||||
|
||||
.list-file-icon {
|
||||
width: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.list-file-name{
|
||||
|
||||
.list-file-name {
|
||||
margin-left: 5px;
|
||||
}
|
||||
</style>
|
@ -53,12 +53,16 @@ function request(api, method = 'GET', postData = {}, progressChange = null) {
|
||||
}
|
||||
let Authorization = store.getters.userToken
|
||||
if (Authorization) {
|
||||
options = {
|
||||
headers: {
|
||||
Authorization
|
||||
},
|
||||
...options
|
||||
if(!options.headers) {
|
||||
options.headers = {}
|
||||
}
|
||||
options.headers.Authorization = Authorization;
|
||||
// options = {
|
||||
// ...options,
|
||||
// headers: {
|
||||
// Authorization
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
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 = {
|
||||
createTime: string,
|
||||
id: number,
|
||||
@ -8,8 +12,8 @@ declare type FileItem = {
|
||||
* 缩略图
|
||||
*/
|
||||
thumb: string,
|
||||
size: number,
|
||||
type: 'folder' | string,
|
||||
size: number
|
||||
type: 'folder' | string
|
||||
updateTime: string
|
||||
}
|
||||
declare type FileIconInstance = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user