..
This commit is contained in:
@@ -33,6 +33,11 @@ public class Client_user extends BaseModel implements Serializable {
|
||||
@Comment("手机号")
|
||||
private String phone;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 18)
|
||||
@Comment("身份证")
|
||||
private String idCard;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
@Comment("openId")
|
||||
|
||||
+44
-2
@@ -13,6 +13,7 @@ import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
@@ -22,6 +23,7 @@ import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.GET;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
@@ -71,13 +73,25 @@ public class ClientActivityController {
|
||||
/**
|
||||
* 报名
|
||||
*/
|
||||
@At("/sign")
|
||||
@At("/sign-up")
|
||||
@AdaptBy(type = JsonAdaptor.class)
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result sign(ClientActivitySignVO signVO) {
|
||||
public synchronized Result signUp(ClientActivitySignVO signVO) {
|
||||
clientActivityService.signUp(signVO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询报名人员
|
||||
* 报名人不见得参加活动
|
||||
*/
|
||||
@At("/list-signup-user/?")
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result listSignUpUser(Long activityId) {
|
||||
List<ActUser> list = dao.query(ActUser.class, Cnd.where(ActUser::getActivityId, "=", activityId).and(ActUser::getSignUpUserId, "=", StpClientUtil.STP.getLoginIdAsLong()));
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询我报名的活动
|
||||
*/
|
||||
@@ -89,11 +103,39 @@ public class ClientActivityController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人、报名人都可以查询
|
||||
* 查询报名签到信息
|
||||
*/
|
||||
@At("/sign-info/?")
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result signInfo(Long activityId) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.or(ActUser::getUserId, "=", StpClientUtil.STP.getLoginIdAsLong());
|
||||
seg.or(ActUser::getSignUpUserId, "=", StpClientUtil.STP.getLoginIdAsLong());
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and(seg);
|
||||
cnd.and(ActUser::getActivityId, "=", activityId);
|
||||
ActUser actUser = dao.fetch(ActUser.class, cnd);
|
||||
return Result.success(actUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到活动
|
||||
*/
|
||||
@At("/sign-in/?")
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result signIn(Long activityId) {
|
||||
clientActivityService.signIn(activityId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 个人签到信息
|
||||
*/
|
||||
@At("/sign-in-info/?")
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result signInInfo(Long activityId) {
|
||||
ActUser actUser = dao.fetch(ActUser.class, Cnd.where(ActUser::getActivityId, "=", activityId).and(ActUser::getUserId, "=", StpClientUtil.STP.getLoginIdAsLong()));
|
||||
return Result.success(actUser);
|
||||
}
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.budwk.app.client.module.activity.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.client.module.activity.service.ClientItemService;
|
||||
import com.budwk.app.client.module.activity.vo.ClientActivitySignVO;
|
||||
import com.budwk.app.client.module.activity.vo.ClientItemSignUpVO;
|
||||
import com.budwk.app.module.activity.models.ActUser;
|
||||
import com.budwk.app.module.activity.models.ActivityItem;
|
||||
import com.budwk.app.module.activity.models.ActivityItemUser;
|
||||
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.mvc.adaptor.JsonAdaptor;
|
||||
import org.nutz.mvc.annotation.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 项目报名
|
||||
*/
|
||||
@IocBean
|
||||
@At("/client/item")
|
||||
@Ok("json:full")
|
||||
public class ClientItemController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private ClientItemService clientItemService;
|
||||
|
||||
@At("/sign-up")
|
||||
@AdaptBy(type = JsonAdaptor.class)
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public synchronized Result signUp(ClientItemSignUpVO signVO) {
|
||||
clientItemService.signUp(signVO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目列表
|
||||
*/
|
||||
@At("/list/?")
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result list(Long activityId) {
|
||||
List<ActivityItem> items = dao.query(ActivityItem.class, Cnd.where(ActivityItem::getActivityId, "=", activityId));
|
||||
return Result.success(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询团队成员
|
||||
*/
|
||||
@At("/list-team-user/?")
|
||||
@SaCheckLogin(type = StpClientUtil.TYPE)
|
||||
public Result listTeamUser(Long activityId){
|
||||
List<ActUser> list = dao.query(ActUser.class, Cnd.where(ActUser::getActivityId, "=", activityId).and(ActUser::getIsSignIn, "=", 1));
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目报名人员
|
||||
*/
|
||||
@At("/list-signup-user")
|
||||
@SaCheckLogin
|
||||
public Result listSignUpUser(Long activityId,Long itemId) {
|
||||
List<ActivityItemUser> itemUsers = dao.query(ActivityItemUser.class, Cnd.where(ActivityItemUser::getActivityId, "=", activityId).and(ActivityItemUser::getItemId, "=", itemId));
|
||||
return Result.success(itemUsers);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
@@ -1,6 +1,7 @@
|
||||
package com.budwk.app.client.module.activity.service;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.client.module.activity.vo.ClientActivitySignVO;
|
||||
import com.budwk.app.module.activity.models.Activity;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
@@ -13,4 +14,15 @@ public interface ClientActivityService extends BaseService<Activity> {
|
||||
*/
|
||||
List<NutMap> listMineAct();
|
||||
|
||||
/**
|
||||
* 报名
|
||||
*/
|
||||
void signUp(ClientActivitySignVO signVO);
|
||||
|
||||
/**
|
||||
* 报名签到
|
||||
*/
|
||||
void signIn(Long activityId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.budwk.app.client.module.activity.service;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.client.module.activity.vo.ClientItemSignUpVO;
|
||||
import com.budwk.app.module.activity.models.ActivityItemUser;
|
||||
|
||||
public interface ClientItemService extends BaseService<ActivityItemUser> {
|
||||
void signUp(ClientItemSignUpVO signVO);
|
||||
}
|
||||
+67
@@ -1,15 +1,23 @@
|
||||
package com.budwk.app.client.module.activity.service.impl;
|
||||
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.client.auth.models.Client_user;
|
||||
import com.budwk.app.client.module.activity.service.ClientActivityService;
|
||||
import com.budwk.app.client.module.activity.vo.ClientActivitySignVO;
|
||||
import com.budwk.app.module.activity.models.ActUser;
|
||||
import com.budwk.app.module.activity.models.Activity;
|
||||
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@@ -33,4 +41,63 @@ public class ClientActivityServiceImpl extends BaseServiceImpl<Activity> impleme
|
||||
sql.setParam("userId", StpClientUtil.STP.getLoginIdAsLong());
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signUp(ClientActivitySignVO signVO) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
List<ActUser> userList = signVO.getUserList();
|
||||
// 首先检查报名人员是否已经在用户表中
|
||||
for (ActUser user : userList) {
|
||||
Client_user clientUser = dao().fetch(Client_user.class, Cnd.where(Client_user::getIdCard, "=", user.getIdCard()));
|
||||
if (clientUser == null) {
|
||||
// 创建用户
|
||||
clientUser = new Client_user();
|
||||
clientUser.setUserName(user.getUserName());
|
||||
clientUser.setSex(user.getSex());
|
||||
clientUser.setPhone(user.getPhone());
|
||||
clientUser.setIdCard(user.getIdCard());
|
||||
dao().insert(clientUser);
|
||||
} else {
|
||||
// 验证用户之前是不是已经报名 别人帮报 自己报 管理员报
|
||||
ActUser hisActUser = dao().fetch(ActUser.class, Cnd.where(ActUser::getUserId, "=", clientUser.getId()).and(ActUser::getActivityId, "=", signVO.getActivityId()));
|
||||
if (hisActUser != null) {
|
||||
if (!hisActUser.getSignUpUserId().equals(StpClientUtil.STP.getLoginIdAsLong())) {
|
||||
throw new BaseException("【" + hisActUser.getUnitName() + "】" + clientUser.getUserName() + "已经报名了,请勿重复报名!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user.setActivityId(signVO.getActivityId());
|
||||
user.setUserId(clientUser.getId());
|
||||
user.setUnitName(signVO.getUnitName());
|
||||
user.setSignUpContacts(signVO.getContactName());
|
||||
user.setSignUpMobile(signVO.getContactPhone());
|
||||
user.setSignUpUserId(StpClientUtil.STP.getLoginIdAsLong());
|
||||
user.setSignUpTime(now);
|
||||
}
|
||||
|
||||
// delete then insert so easy
|
||||
|
||||
// 删除旧的报名人员
|
||||
dao().clear(ActUser.class, Cnd.where(ActUser::getActivityId, "=", signVO.getActivityId()).and(ActUser::getSignUpUserId, "=", StpClientUtil.STP.getLoginIdAsLong()));
|
||||
|
||||
// 插入新的报名人员
|
||||
dao().insert(userList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signIn(Long activityId) {
|
||||
ActUser actUser = dao().fetch(ActUser.class, Cnd.where(ActUser::getActivityId, "=", activityId).and(ActUser::getUserId, "=", StpClientUtil.STP.getLoginIdAsLong()));
|
||||
if (actUser == null) {
|
||||
throw new BaseException("您未报名该活动");
|
||||
}
|
||||
if (actUser.getIsSignIn()) {
|
||||
throw new BaseException("您已签到,请勿重复签到");
|
||||
}
|
||||
// 更新签到信息
|
||||
actUser.setIsSignIn(true);
|
||||
actUser.setSignInTime(LocalDateTime.now());
|
||||
dao().update(actUser, "isSignIn|signInTime");
|
||||
}
|
||||
}
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.budwk.app.client.module.activity.service.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.client.module.activity.service.ClientItemService;
|
||||
import com.budwk.app.client.module.activity.vo.ClientItemSignUpVO;
|
||||
import com.budwk.app.module.activity.models.ActivityItemUser;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class ClientItemServiceImpl extends BaseServiceImpl<ActivityItemUser> implements ClientItemService {
|
||||
public ClientItemServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void signUp(ClientItemSignUpVO signVO) {
|
||||
// 删除掉之前的
|
||||
clear(Cnd.where(ActivityItemUser::getActivityId, "=", signVO.getActivityId())
|
||||
.and(ActivityItemUser::getGroupId, "=", signVO.getGroupId())
|
||||
.and(ActivityItemUser::getItemId, "=", signVO.getItemId())
|
||||
);
|
||||
|
||||
List<ActivityItemUser> userList = signVO.getUserList();
|
||||
for (ActivityItemUser itemUser : userList) {
|
||||
itemUser.setActivityId(signVO.getActivityId());
|
||||
itemUser.setItemId(signVO.getItemId());
|
||||
itemUser.setGroupId(signVO.getGroupId());
|
||||
}
|
||||
insert(userList);
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.budwk.app.client.module.activity.vo;
|
||||
|
||||
public class ClientActivitySignInVO {
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class ClientActivitySignVO {
|
||||
|
||||
private String activityId;
|
||||
private Long activityId;
|
||||
|
||||
private String unitName;
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.budwk.app.client.module.activity.vo;
|
||||
|
||||
import com.budwk.app.module.activity.models.ActivityItemUser;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ClientItemSignUpVO {
|
||||
|
||||
private Long activityId;
|
||||
|
||||
private Long itemId;
|
||||
|
||||
private Long groupId;
|
||||
|
||||
private List<ActivityItemUser> userList;
|
||||
|
||||
}
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class ActUserController {
|
||||
// 报名时间
|
||||
LocalDateTime localDateTime = DateUtil.date().toLocalDateTime();
|
||||
// 活动id
|
||||
Long activityId = Long.parseLong(vo.getActivityId());
|
||||
Long activityId = vo.getActivityId();
|
||||
|
||||
List<ActUser> userList = vo.getUserList();
|
||||
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ public class ActivityManageController {
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("activity.manager")
|
||||
public Result save(Activity activity) {
|
||||
public Result save(@Param("activity") Activity activity) {
|
||||
// activityService.insertWith(activity, "items");
|
||||
activityService.insert(activity);
|
||||
return Result.success();
|
||||
@@ -66,7 +66,7 @@ public class ActivityManageController {
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("activity.manager")
|
||||
public Result update(Activity activity) {
|
||||
public Result update(@Param("activity")Activity activity) {
|
||||
activityService.updateIgnoreNull(activity);
|
||||
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ public class ActUser extends BaseModel {
|
||||
@Column
|
||||
@Comment("是否签到")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Default("0")
|
||||
private Boolean isSignIn;
|
||||
|
||||
@Column
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.budwk.app.module.activity.models;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -69,11 +70,21 @@ public class Activity extends BaseModel {
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String content;
|
||||
|
||||
@Comment("承诺书")
|
||||
@Column
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String protocol;
|
||||
|
||||
@Comment("封面")
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 500)
|
||||
private String cover;
|
||||
|
||||
@Comment("附件")
|
||||
@Column
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<JSONObject> files;
|
||||
|
||||
/**
|
||||
* 项目列表
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,16 @@ public class ActivityItem extends BaseModel {
|
||||
@ColDefine(type = ColType.VARCHAR, width = 300)
|
||||
private String rule;
|
||||
|
||||
@Comment("图片")
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 300)
|
||||
private String img;
|
||||
|
||||
@Comment("项目人数")
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer num;
|
||||
|
||||
@Comment("排序")
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.budwk.app.module.activity.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
@Data
|
||||
@Table("act_item_user")
|
||||
@Comment("项目报名人员")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class ActivityItemUser extends BaseModel {
|
||||
|
||||
@Id
|
||||
@Comment("ID")
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
@Comment("活动ID")
|
||||
private Long activityId;
|
||||
|
||||
@Column
|
||||
@Comment("项目ID")
|
||||
private Long itemId;
|
||||
|
||||
@Column
|
||||
@Comment("报名人Id")
|
||||
private Long userId;
|
||||
|
||||
@Column
|
||||
@Comment("分组ID")
|
||||
private Long groupId;
|
||||
}
|
||||
+2
-1
@@ -3,6 +3,7 @@ package com.budwk.app.web.commons.auth.satoken.aop;
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
|
||||
import org.nutz.aop.InterceptorChain;
|
||||
import org.nutz.aop.MethodInterceptor;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
@@ -15,7 +16,7 @@ public class SaCheckAnyLoginInterceptor implements MethodInterceptor {
|
||||
public void filter(InterceptorChain chain) throws Throwable {
|
||||
Method method = chain.getCallingMethod();
|
||||
|
||||
boolean mini = SaManager.getStpLogic("mini").isLogin();
|
||||
boolean mini = SaManager.getStpLogic(StpClientUtil.TYPE).isLogin();
|
||||
boolean web = SaManager.getStpLogic("login").isLogin();
|
||||
if (mini || web) {
|
||||
chain.doChain();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class UploadController {
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
//AdaptorErrorContext必须是最后一个参数
|
||||
public Object file(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
|
||||
public Object file(@Param("file") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
|
||||
try {
|
||||
if (err != null && err.getAdaptorErr() != null) {
|
||||
return NutMap.NEW().addv("code", 1).addv("msg", "文件不合法");
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
<template>
|
||||
<div class="upload-container">
|
||||
<el-upload
|
||||
class="upload-demo"
|
||||
ref="upload"
|
||||
action="/open/file/upload/file"
|
||||
:on-preview="handlePreview"
|
||||
:on-remove="handleRemove"
|
||||
:before-remove="beforeRemove"
|
||||
:on-success="handleSuccess"
|
||||
:on-error="handleError"
|
||||
:on-exceed="handleExceed"
|
||||
:file-list="internalFileList"
|
||||
:auto-upload="true"
|
||||
:limit="limit"
|
||||
:multiple="multiple"
|
||||
:accept="accept"
|
||||
:before-upload="beforeUpload"
|
||||
:on-change="handleChange"
|
||||
>
|
||||
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
||||
<div slot="tip" class="el-upload__tip">
|
||||
<!-- <slot name="tip">-->
|
||||
<!-- 请上传符合要求的文件,单个文件不超过{{ maxSize }}MB-->
|
||||
<!-- </slot>-->
|
||||
{{ uploadTips }}
|
||||
</div>
|
||||
</el-upload>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
module.exports = {
|
||||
name: 'index',
|
||||
model: {
|
||||
prop: 'value',
|
||||
event: 'change'
|
||||
},
|
||||
props: {
|
||||
// v-model 绑定的值
|
||||
value: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
// 最大上传数量
|
||||
limit: {
|
||||
type: Number,
|
||||
default: 5
|
||||
},
|
||||
// 是否支持多选
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 接受的文件类型
|
||||
accept: {
|
||||
type: String,
|
||||
default: '.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx,.jpg,.jpeg,.png,.zip,.rar'
|
||||
},
|
||||
// 最大文件大小(MB)
|
||||
maxSize: {
|
||||
type: Number,
|
||||
default: 50
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
uploadTips(){
|
||||
if (this.$slots.tip) {
|
||||
return this.$slots.tip[0].text
|
||||
}
|
||||
let tips = `请上传符合要求的文件,单个文件不超过${this.maxSize}MB`
|
||||
if(this.accept){
|
||||
tips += `,支持格式:${this.accept}`
|
||||
}
|
||||
return tips
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
internalFileList: []
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value: {
|
||||
immediate: true,
|
||||
handler(newVal) {
|
||||
// 同步外部传入的值到内部状态
|
||||
this.internalFileList = newVal.map(file => ({
|
||||
name: file.name,
|
||||
url: file.url,
|
||||
uid: file.uid || this.generateUid(),
|
||||
status: 'success'
|
||||
}))
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 生成唯一ID
|
||||
generateUid() {
|
||||
return Date.now().toString(36) + Math.random().toString(36).substr(2)
|
||||
},
|
||||
|
||||
// 点击文件列表中已上传的文件时的钩子
|
||||
handlePreview(file) {
|
||||
if (file.url) {
|
||||
// 既然看到这里吧 把预览写了吧
|
||||
}
|
||||
},
|
||||
|
||||
// 文件列表移除文件
|
||||
handleRemove(file, fileList) {
|
||||
this.internalFileList = fileList
|
||||
this.emitChange(fileList)
|
||||
this.$emit('file-removed', file, fileList)
|
||||
},
|
||||
|
||||
// 文件删除
|
||||
beforeRemove(file) {
|
||||
if(file.status === 'success'){
|
||||
return this.$confirm(`确定移除 ${file.name}?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 文件上传成功时的钩子
|
||||
handleSuccess(response, file, fileList) {
|
||||
// 更新文件状态
|
||||
const index = this.internalFileList.findIndex(f => f.uid === file.uid)
|
||||
if (index !== -1) {
|
||||
if(response.code === 0){
|
||||
debugger
|
||||
this.$set(this.internalFileList, index, {
|
||||
// ...file,
|
||||
// status: 'success',
|
||||
// ...response.data
|
||||
name: file.name,
|
||||
url: response.data?.file_url,
|
||||
type: response.data?.file_type,
|
||||
size: response.data?.file_size
|
||||
})
|
||||
this.$message.success(`${file.name} 上传成功`)
|
||||
}else{
|
||||
this.$message.error(`${file.name} 上传失败`)
|
||||
}
|
||||
}
|
||||
console.log(this.internalFileList)
|
||||
this.emitChange(this.internalFileList)
|
||||
this.$emit('upload-success', response, file, fileList)
|
||||
this.$message.success(`${file.name} 上传成功`)
|
||||
},
|
||||
|
||||
// 文件上传失败时的钩子
|
||||
handleError(err, file, fileList) {
|
||||
const index = this.internalFileList.findIndex(f => f.uid === file.uid)
|
||||
if (index !== -1) {
|
||||
this.$set(this.internalFileList, index, {
|
||||
...file,
|
||||
status: 'fail'
|
||||
})
|
||||
}
|
||||
|
||||
this.emitChange(this.internalFileList)
|
||||
this.$emit('upload-error', err, file, fileList)
|
||||
this.$message.error(`${file.name} 上传失败`)
|
||||
},
|
||||
|
||||
// 文件超出数量限制时的钩子
|
||||
handleExceed(files, fileList) {
|
||||
this.$message.warning(
|
||||
`当前限制选择 ${this.limit} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
|
||||
files.length + fileList.length
|
||||
} 个文件`
|
||||
)
|
||||
},
|
||||
|
||||
// 上传前的校验
|
||||
beforeUpload(file) {
|
||||
const isLt = file.size / 1024 / 1024 < this.maxSize
|
||||
if (!isLt) {
|
||||
this.$message.error(`上传文件大小不能超过 ${this.maxSize}MB!`)
|
||||
return false
|
||||
}
|
||||
const isValid = this.validateFileType(file)
|
||||
if(!isValid){
|
||||
this.$message.error(`只能上传 ${this.accept} 格式的文件`)
|
||||
return false
|
||||
}
|
||||
return isValid
|
||||
},
|
||||
|
||||
validateFileType(file){
|
||||
const allowedExtensions = this.accept.split(',').map(ext => ext.trim().toLowerCase()).filter(ext => ext.startsWith('.'))
|
||||
const fileExtension = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
|
||||
if (allowedExtensions.includes(fileExtension)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
// 文件状态改变
|
||||
handleChange(file, fileList) {
|
||||
this.internalFileList = fileList
|
||||
// 如果是新增文件但还未上传成功,不触发change事件
|
||||
// if (file.status !== 'ready') {
|
||||
// this.emitChange(fileList)
|
||||
// }
|
||||
|
||||
if(file.status === 'ready'){
|
||||
const isValid = this.validateFileType(file)
|
||||
if (!isValid) {
|
||||
// 从文件列表中移除不符合的文件
|
||||
this.internalFileList = fileList.filter(f => f.uid !== file.uid)
|
||||
return false
|
||||
}
|
||||
}
|
||||
this.internalFileList = fileList
|
||||
return true
|
||||
},
|
||||
|
||||
// 触发v-model更新
|
||||
emitChange(fileList) {
|
||||
// 格式化输出数据,只保留必要信息
|
||||
debugger
|
||||
const formattedList = fileList.map(file => ({
|
||||
name: file.name,
|
||||
url: file.url,
|
||||
type: file.type,
|
||||
size: file.size
|
||||
}))
|
||||
|
||||
this.$emit('change', formattedList)
|
||||
},
|
||||
|
||||
// 手动清空文件列表
|
||||
clearFiles() {
|
||||
this.$refs.upload.clearFiles()
|
||||
this.internalFileList = []
|
||||
this.emitChange([])
|
||||
},
|
||||
|
||||
// 获取当前文件列表
|
||||
getFileList() {
|
||||
return this.internalFileList
|
||||
},
|
||||
|
||||
// 手动提交上传
|
||||
submit() {
|
||||
this.$refs.upload.submit()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.upload-container {
|
||||
padding: 20px;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 6px;
|
||||
background-color: #fbfdff;
|
||||
}
|
||||
|
||||
.upload-container:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.el-upload__tip {
|
||||
margin-top: 10px;
|
||||
color: #606266;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -89,6 +89,7 @@ module.exports = {
|
||||
handleSuccess(response, file, fileList) {
|
||||
if (response.code === 0) {
|
||||
if (this.maxCount === 1) {
|
||||
debugger
|
||||
this.$emit('input', response.data)
|
||||
} else {
|
||||
|
||||
@@ -122,9 +123,5 @@ module.exports = {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-upload--picture-card {
|
||||
//width: 100px;
|
||||
//height: 100px;
|
||||
//line-height: 100px;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -57,6 +57,7 @@
|
||||
Vue.component("table-tool", httpVueLoader("/components/plugins/sysTableTool/index.vue?v=" + new Date().getTime()))
|
||||
Vue.component("text-editor", httpVueLoader("/components/plugins/textEditor/index.vue?v=" + new Date().getTime()))
|
||||
Vue.component("image-upload", httpVueLoader("/components/plugins/imageUpload/index.vue?v=" + new Date().getTime()))
|
||||
Vue.component("file-upload", httpVueLoader("/components/plugins/fileUpload/index.vue?v=" + new Date().getTime()))
|
||||
</script>
|
||||
</head>
|
||||
<body class="hold-transition sidebar-mini layout-fixed">
|
||||
|
||||
@@ -55,6 +55,13 @@ const addOrUpdate = {
|
||||
<el-form-item label="活动内容" prop="content">
|
||||
<text-editor v-model="form.content" :height="200"></text-editor>
|
||||
</el-form-item>
|
||||
<el-form-item label="承诺书" prop="protocol">
|
||||
<text-editor v-model="form.protocol" :height="200"></text-editor>
|
||||
</el-form-item>
|
||||
<el-form-item label="活动附件" prop="files">
|
||||
{{form.files}}
|
||||
<file-upload v-model="form.files" accept=".pdf"></file-upload>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
@@ -91,7 +98,8 @@ const addOrUpdate = {
|
||||
hostUnit: [{required: true, message: '请输入主办单位', trigger: ['blur', 'change']}],
|
||||
coHostUnit: [{required: true, message: '请输入承办单位', trigger: ['blur', 'change']}],
|
||||
contact: [{required: true, message: '请输入联系人', trigger: ['blur', 'change']}],
|
||||
content: [{required: true, message: '请输入活动内容', trigger: ['blur', 'change']}]
|
||||
content: [{required: true, message: '请输入活动内容', trigger: ['blur', 'change']}],
|
||||
protocol: [{required: true, message: '请输入承诺书', trigger: ['blur', 'change']}],
|
||||
},
|
||||
stepActive: 0
|
||||
}
|
||||
@@ -117,7 +125,7 @@ const addOrUpdate = {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消'
|
||||
}).then(() => {
|
||||
$.post('/platform/activity/manage/' + (this.form.id ? 'update' : 'save'), this.form).then(res => {
|
||||
$.post('/platform/activity/manage/' + (this.form.id ? 'update' : 'save'), {"activity": JSON.stringify(this.form)}).then(res => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success(this.form.id ? '修改成功' : '新增成功')
|
||||
this.$emit('refresh')
|
||||
|
||||
@@ -20,6 +20,12 @@ const itemForm = {
|
||||
<el-input v-model="row.rule" placeholder="请输入评分规则"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="图片">
|
||||
<template #default="{row}">
|
||||
{{row.img}}
|
||||
<image-upload v-model="row.img" :max-count="1"></image-upload>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" fixed="right" width="100px">
|
||||
<template #default="{$index}">
|
||||
<el-button type="text" class="text-danger" @click="removeRow($index)">删除</el-button>
|
||||
|
||||
Reference in New Issue
Block a user