diff --git a/src/main/java/io/v/nutz/fitnessWalk/controller/FitnessWalkStepManageController.java b/src/main/java/io/v/nutz/fitnessWalk/controller/FitnessWalkStepManageController.java index 004110b..845d9b7 100644 --- a/src/main/java/io/v/nutz/fitnessWalk/controller/FitnessWalkStepManageController.java +++ b/src/main/java/io/v/nutz/fitnessWalk/controller/FitnessWalkStepManageController.java @@ -1,16 +1,11 @@ package io.v.nutz.fitnessWalk.controller; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.date.DateBetween; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.wizzer.framework.base.Result; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import io.v.nutz.annontation.ViReturn; -import io.v.nutz.base.page.Pagination; import io.v.nutz.base.service.BaseService; import io.v.nutz.fitnessWalk.model.FitnessWalkActivity; import io.v.nutz.fitnessWalk.model.FitnessWalkAwardUser; @@ -20,8 +15,6 @@ import io.v.nutz.fitnessWalk.utils.WeAppCloudUtil; import org.nutz.aop.interceptor.ioc.TransAop; import org.nutz.dao.Chain; import org.nutz.dao.Cnd; -import org.nutz.dao.Sqls; -import org.nutz.dao.sql.Sql; import org.nutz.integration.jedis.RedisService; import org.nutz.ioc.aop.Aop; import org.nutz.ioc.loader.annotation.Inject; @@ -36,6 +29,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.*; +import java.util.function.BinaryOperator; +import java.util.function.Function; import java.util.stream.Collectors; @IocBean @@ -62,86 +57,81 @@ public class FitnessWalkStepManageController { * @param activityId 活动id * @param userId 用户id * @param monthSteps 步数(当天往前推30天) - * @param start_time 活动开始时间 - * @param end_time 结束时间 * @return */ @At @Ok("json:full") @ViReturn @Aop(TransAop.READ_COMMITTED) - public Object updateStepMonth(String activityId, String userId, String monthSteps, Long start_time, Long end_time) { - if (StrUtil.isBlank(userId)) { - return Result.error("上传步数失败,请重新登录后再次上传!"); + public Object updateStepMonth(String activityId, String userId, String monthSteps) { + if (StrUtil.isBlank(userId) || StrUtil.isBlank(monthSteps) || StrUtil.isBlank(activityId)) { + return Result.error("必要参数未传递!"); } - DateTime activityStartDate = DateUtil.date(start_time); - DateTime activityEndDate = DateUtil.date(end_time); - + // 获取到的用户的步数数据 List steps = Json.fromJsonAsList(NutMap.class, monthSteps); - /*//前一个月的时间 - DateTime dateTime = DateUtil.offsetMonth(new Date(), -1); - String format = DateUtil.format(dateTime, "yyyyMM"); - - //上一个月的步数 - List lastMonthSteps = steps.stream().filter(v -> { - long timestamp = v.getLong("timestamp") * 1000; - String userStep = DateUtil.format(DateUtil.date(timestamp), "yyyyMM"); - return userStep.equals(format); - }).collect(Collectors.toList()); - - List lastMonthInsertWxSteps = steps.stream().map(v -> { - FitnessWalkStep step = new FitnessWalkStep(); - step.setActivityId(activityId); - step.setUserId(userId); - step.setStep(v.getInt("step")); - DateTime date = DateUtil.date(v.getLong("timestamp") * 1000); - step.setApplyDate(date); - return step; - }).collect(Collectors.toList()); - List applyDates = lastMonthInsertWxSteps.stream().map(v -> v.getApplyDate()).collect(Collectors.toList()); - - applyDates.remove(applyDates.stream().min(Date::compareTo).orElse(null)); - - System.out.println(lastMonthInsertWxSteps.size()); - System.out.println(applyDates.size()); - System.out.println(Json.toJson(applyDates)); - - baseService.dao().clear("fitness_walk_step_" + format, Cnd.where("activityId", "=", activityId).and("userId", "=", userId).and("applyDate", "in", applyDates)); -// baseService.dao().insert("fitness_walk_step_" + format,lastMonthInsertWxSteps); - - - //本月步数 - List thisMonthSteps = (List) CollectionUtil.subtract(steps,lastMonthSteps);*/ - //判断数据是否完整 微信运动会在晚上10点多进行步数的更新 会导致31天前的步数获取变为0 所以这里去除掉第一个元素 即为31天前的数据 每次只保存最近30天的数据 if (Lang.isNotEmpty(steps) && steps.size() == 31) { steps.remove(0); } - //如果在活动开始之前进来了 就只保存近7天的数据 不然前台展示为空 不好看 - List insertWxSteps = steps.stream().map(v -> { + // 传递过来的步数数据 + List wxSteps = steps.stream().map(v -> { FitnessWalkStep step = new FitnessWalkStep(); step.setActivityId(activityId); step.setUserId(userId); step.setStep(v.getInt("step")); - DateTime date = DateUtil.date(v.getLong("timestamp") * 1000); + DateTime date = DateUtil.parse(DateUtil.format(DateUtil.date(v.getLong("timestamp") * 1000), "yyyy-MM-dd"), "yyyy-MM-dd"); step.setApplyDate(date); return step; }).collect(Collectors.toList()); - //.filter(v -> v.getApplyDate().compareTo(DateUtil.offsetDay(activityStartDate, -7)) >= 0 && v.getApplyDate().compareTo(activityEndDate) <= 0).collect(Collectors.toList()); - //.filter(v -> (v.getApplyDate().compareTo(activityStartDate) >= 0) && (v.getApplyDate().compareTo(activityEndDate) <= 0)).collect(Collectors.toList()); - List applyDates = insertWxSteps.stream().map(v -> v.getApplyDate()).collect(Collectors.toList()); - applyDates.remove(applyDates.stream().min(Date::compareTo).orElse(null)); + // 传递过来的所有日期的集合 + List dateList = wxSteps.stream().map(FitnessWalkStep::getApplyDate).collect(Collectors.toList()); - System.out.println(insertWxSteps.size()); - System.out.println(applyDates.size()); - System.out.println(Json.toJson(applyDates)); + // 去数据库查询日期,这个玩意还要保证插入到数据库的单个日期只有一条,并且这个日期数据库之前有步数,传过来没步数那就要保留数据库的步数 + // 上面日期集合数据库的步数 + List stepList = baseService.dao().query(FitnessWalkStep.class, Cnd.where("activityId", "=", activityId) + .and("userId", "=", userId).and("applyDate", "in", dateList)); - baseService.dao().clear(FitnessWalkStep.class, Cnd.where("activityId", "=", activityId).and("userId", "=", userId).and("applyDate", "in", applyDates)); - baseService.dao().insert(insertWxSteps); + // 这就是保留每天最大步数的集合,那这个集合里面applyDate就是唯一的了 + List dupStepList = new ArrayList<>(stepList.stream() + .collect(Collectors.toMap(FitnessWalkStep::getApplyDate, Function.identity(), + BinaryOperator.maxBy(Comparator.comparing(FitnessWalkStep::getStep)))) + .values()); + + // 这是过滤的相同的applyDate的集合,这些数据要删除 + List delStepIds = stepList.stream() + .filter(step -> !dupStepList.contains(step)) + .map(FitnessWalkStep::getId) + .collect(Collectors.toList()); + + // 数据库的数据 这个map就用于判断数据库的日期和传递过来日期的步数,两个是不是相等的,保留步数多的数据 + Map dateStepMap = dupStepList.stream().collect(Collectors.toMap(FitnessWalkStep::getApplyDate, v -> v)); + + List resultStepList = new ArrayList<>(); + // 这里循环就是,循环的传递过来的数据 + for (FitnessWalkStep step : wxSteps) { + // 数据库存储的步数 + FitnessWalkStep walkStep = dateStepMap.get(step.getApplyDate()); + // 如果数据库没有,那就要新增 + if (Lang.isEmpty(walkStep)) { + resultStepList.add(step); + } else { + // 如果数据库有,那就要保留步数多的 + if (walkStep.getStep() < step.getStep()) { + walkStep.setStep(step.getStep()); + resultStepList.add(walkStep); + } + } + } + + // 最后删除重复日期,更新步数数据 + baseService.dao().clear(FitnessWalkStep.class, Cnd.where("id", "in", delStepIds)); + if (Lang.isNotEmpty(resultStepList)){ + baseService.dao().insertOrUpdate(resultStepList); + } return null; } diff --git a/src/main/resources/static/components/plugins/FileUpload.vue b/src/main/resources/static/components/plugins/FileUpload.vue index 4f55530..e2a9c2b 100644 --- a/src/main/resources/static/components/plugins/FileUpload.vue +++ b/src/main/resources/static/components/plugins/FileUpload.vue @@ -1,64 +1,64 @@ @@ -70,138 +70,138 @@ * @type {{isImg: wpUploadFileTypeResolve.isImg}} */ let fileTypeResolving = { - /** - * 是否是一张图片 - */ - isImg: function (fileItem) { - return fileTypeResolving.resolvingByType(fileItem.type, /image\/(\w)*/) - }, - /** - * 通过后缀验证图片 - */ - isImgByName: function (fileItemName) { - let checkSuffixArray = ['jpg', 'png', 'jpeg', 'bmp', 'gif', 'webp', 'tif', 'svg', 'wmf']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray) - }, - /** - * 是否是视频 - */ - isVideo: function (fileItem) { - return fileTypeResolving.resolvingByType(fileItem.type, /video\/(\w)*/) - }, - /** - * 通过后缀验证图片 - */ - isVideoByName: function (fileItemName) { - let checkSuffixArray = ['mp4', 'Ogg', 'webm']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray) - }, - /** - * 是否是音频 - */ - isAudio: function (fileItem) { - return fileTypeResolving.resolvingByType(fileItem.type, /audio\/(\w)*/) - }, - /** - * 通过后缀验证图片 - */ - isAudioByName: function (fileItemName) { - let checkSuffixArray = ['mp3', 'ogg', 'wav']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray) - }, + /** + * 是否是一张图片 + */ + isImg: function (fileItem) { + return fileTypeResolving.resolvingByType(fileItem.type, /image\/(\w)*/) + }, + /** + * 通过后缀验证图片 + */ + isImgByName: function (fileItemName) { + let checkSuffixArray = ['jpg', 'png', 'jpeg', 'bmp', 'gif', 'webp', 'tif', 'svg', 'wmf']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray) + }, + /** + * 是否是视频 + */ + isVideo: function (fileItem) { + return fileTypeResolving.resolvingByType(fileItem.type, /video\/(\w)*/) + }, + /** + * 通过后缀验证图片 + */ + isVideoByName: function (fileItemName) { + let checkSuffixArray = ['mp4', 'Ogg', 'webm']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray) + }, + /** + * 是否是音频 + */ + isAudio: function (fileItem) { + return fileTypeResolving.resolvingByType(fileItem.type, /audio\/(\w)*/) + }, + /** + * 通过后缀验证图片 + */ + isAudioByName: function (fileItemName) { + let checkSuffixArray = ['mp3', 'ogg', 'wav']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray) + }, - /** - * 是否是doc文件 - */ - isDoc: function (fileItemName) { - let checkSuffixArray = ['doc', 'docx', 'dot', 'dotx']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - /** - * 是否是excel文件 - */ - isExcel: function (fileItemName) { - let checkSuffixArray = ['xls', 'xlsx', 'csv', 'xlt', 'xltx']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - /** - * 是否是PPT文件 - */ - isPPT: function (fileItemName) { - let checkSuffixArray = ['ppt', 'pptx', 'pot', 'potx', 'odp']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - /** - * 是否是Pdf文件 - */ - isPdf: function (fileItemName) { - let checkSuffixArray = ['pdf']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - /** - * 是否是压缩文件 - * @param fileItem - * @returns {boolean} - */ - isZip: function (fileItemName) { - let checkSuffixArray = ['zip', '7z', 'war', 'tar', 'rar', 'jar', 'zipx', 'zix', 'zoo']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - isWeb: function (fileItemName) { - let checkSuffixArray = ['html', 'htm']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - isTxt: function (fileItemName) { - let checkSuffixArray = ['txt']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - isPsd: function (fileItemName) { - let checkSuffixArray = ['psd']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - isCad: function (fileItemName) { - let checkSuffixArray = ['cad']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - isIso: function (fileItemName) { - let checkSuffixArray = ['iso']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - isExe: function (fileItemName) { - let checkSuffixArray = ['exe']; - return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); - }, - /** - * 根据文件类型来解析 - * @param fileType 文件类型 - * @param checkTypeModel 文件类型模型,如:image\/(\w)* - * @returns {boolean} - */ - resolvingByType: function (fileType, checkTypeModel) { - if (checkTypeModel.test(fileType)) { - return true; + /** + * 是否是doc文件 + */ + isDoc: function (fileItemName) { + let checkSuffixArray = ['doc', 'docx', 'dot', 'dotx']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + /** + * 是否是excel文件 + */ + isExcel: function (fileItemName) { + let checkSuffixArray = ['xls', 'xlsx', 'csv', 'xlt', 'xltx']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + /** + * 是否是PPT文件 + */ + isPPT: function (fileItemName) { + let checkSuffixArray = ['ppt', 'pptx', 'pot', 'potx', 'odp']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + /** + * 是否是Pdf文件 + */ + isPdf: function (fileItemName) { + let checkSuffixArray = ['pdf']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + /** + * 是否是压缩文件 + * @param fileItem + * @returns {boolean} + */ + isZip: function (fileItemName) { + let checkSuffixArray = ['zip', '7z', 'war', 'tar', 'rar', 'jar', 'zipx', 'zix', 'zoo']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + isWeb: function (fileItemName) { + let checkSuffixArray = ['html', 'htm']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + isTxt: function (fileItemName) { + let checkSuffixArray = ['txt']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + isPsd: function (fileItemName) { + let checkSuffixArray = ['psd']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + isCad: function (fileItemName) { + let checkSuffixArray = ['cad']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + isIso: function (fileItemName) { + let checkSuffixArray = ['iso']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + isExe: function (fileItemName) { + let checkSuffixArray = ['exe']; + return fileTypeResolving.resolvingByName(fileItemName, checkSuffixArray); + }, + /** + * 根据文件类型来解析 + * @param fileType 文件类型 + * @param checkTypeModel 文件类型模型,如:image\/(\w)* + * @returns {boolean} + */ + resolvingByType: function (fileType, checkTypeModel) { + if (checkTypeModel.test(fileType)) { + return true; + } + return false; + }, + /** + * 根据名字和名字后缀名来验证文件 + * @param fileName 文件名 + * @param checkSuffixArray 文件类型包含的后缀 + */ + resolvingByName: function (fileName, checkSuffixArray) { + let suffixName = wpUploadFileTools.getSuffixNameByFileName(fileName); + // 名字是否有效 + if (!wpUploadDataValid.isValidStr(suffixName)) { + // 无效直接返回false + return false; + } + suffixName = suffixName.trim(); + suffixName = suffixName.toLowerCase(); + if (checkSuffixArray.indexOf(suffixName) != -1) { + return true; + } + return false; } - return false; - }, - /** - * 根据名字和名字后缀名来验证文件 - * @param fileName 文件名 - * @param checkSuffixArray 文件类型包含的后缀 - */ - resolvingByName: function (fileName, checkSuffixArray) { - let suffixName = wpUploadFileTools.getSuffixNameByFileName(fileName); - // 名字是否有效 - if (!wpUploadDataValid.isValidStr(suffixName)) { - // 无效直接返回false - return false; - } - suffixName = suffixName.trim(); - suffixName = suffixName.toLowerCase(); - if (checkSuffixArray.indexOf(suffixName) != -1) { - return true; - } - return false; - } } @@ -210,218 +210,218 @@ let fileTypeResolving = { * @type {{}} */ let wpUploadFileTools = { - /** - * 获取文件显示模版 - * @param fileItem - */ - wapFileItemShow: function (fileItem) { - return wpUploadFileTools.wapFileItemShowBase(fileItem, false); - }, - /** - * 包装已上传的文件列表 - */ - wapFileItemShowWithUpload(uploadFile) { - return wpUploadFileTools.wapFileItemShowBase(uploadFile, true); - }, - /** - * 获取文件显示的基本操作 - */ - wapFileItemShowBase(fileItem, isUploaded = false) { - let fileName = ""; - let suffix = ""; - let show = ""; - let showIcon = ""; - if (!isUploaded) { - fileName = fileItem.name; - suffix = wpUploadFileTools.getSuffixNameByFileName(fileName); - show = wpUploadFileTools.resolvingShow(fileItem); - showIcon = wpUploadFileShowResolving.getFileItemShowIcon(show, fileItem, false); - } else { - fileName = fileItem.name ? fileItem.name : wpUploadFileTools.resolvingUrlFileName(fileItem.url); - let fileNameGetOFuRL = wpUploadFileTools.resolvingUrlFileName(fileItem.url); - suffix = wpUploadFileTools.getSuffixNameByFileName(fileNameGetOFuRL); - show = wpUploadFileTools.resolvingShowByFileName(fileNameGetOFuRL); - showIcon = wpUploadFileShowResolving.getFileItemShowIcon(show, fileItem.url, true); - } - let fileItemShow = { - // 文件的id - id: wpUploadFileTools.uuid(), - // 文件对象 - file: null, - // 文件的类型 - type: null, - // 文件的大小 - size: null, - // 文件的名字 - name: fileName, - // 文件地址 - url: null, - // 后缀 - suffix: suffix, - // 显示的类型 - show: show, - // 显示的图标或者图片地址 - showIcon: showIcon, - // 显示进度条 - processStatus: { - show: false, - width: 0, - isFail: false - }, - // 文件来源,0选择文件上传,1回显文件 - fileSource: 0, - // 状态0未上传,失败也会转到0,1正在上传,2已经上传 - status: 0, - // 上传文件的描述 - fileDes: null - } - if (!isUploaded) { - // 如果非选择文件下面三个属性为null - fileItemShow.file = fileItem; - fileItemShow.type = fileItem.type; - fileItemShow.size = fileItem.size; - } else { - // 文件描述 - fileItemShow.status = 2; - fileItemShow.fileDes = fileItem; - fileItemShow.fileSource = 1; - fileItemShow.url = fileItem.url; - } - return fileItemShow; - }, - /** - * 解析URL的文件名字 - */ - resolvingUrlFileName: function (fileUrl) { - let index = fileUrl.lastIndexOf("/"); - if (index <= 0) { - index = fileUrl.lastIndexOf("\\"); - } - index = index + 1; - let fileName = fileUrl.substring(index, fileUrl.length); - return fileName; - }, - /** - * 获取文件名后缀 - * @param fileName 文件名全名 - * */ - getSuffixNameByFileName: function (fileName) { - let str = fileName; - let index = str.lastIndexOf("."); - if (index < 0) { - return ""; - } - let pos = index + 1; - return str.substring(pos, str.length); - }, - /** - * 解析显示类型 - * @param fileItem 文件 - * @returns {number} - */ - resolvingShow: function (fileItem) { - // 默认0普通文件 - let showResult = 0; - if (wpUploadFileTypeResolving.isImg(fileItem)) { - showResult = 1; - } else if (wpUploadFileTypeResolving.isVideo(fileItem)) { - showResult = 2; - } else if (wpUploadFileTypeResolving.isAudio(fileItem)) { - showResult = 3; - } else if (wpUploadFileTypeResolving.isDoc(fileItem.name)) { - showResult = 4; - } else if (wpUploadFileTypeResolving.isExcel(fileItem.name)) { - showResult = 5; - } else if (wpUploadFileTypeResolving.isPPT(fileItem.name)) { - showResult = 6; - } else if (wpUploadFileTypeResolving.isPdf(fileItem.name)) { - showResult = 7; - } else if (wpUploadFileTypeResolving.isZip(fileItem.name)) { - showResult = 8; - } else if (wpUploadFileTypeResolving.isWeb(fileItem.name)) { - showResult = 9; - } else if (wpUploadFileTypeResolving.isTxt(fileItem.name)) { - showResult = 10; - } else if (wpUploadFileTypeResolving.isPsd(fileItem.name)) { - showResult = 11; - } else if (wpUploadFileTypeResolving.isCad(fileItem.name)) { - showResult = 12; - } else if (wpUploadFileTypeResolving.isIso(fileItem.name)) { - showResult = 13; - } else if (wpUploadFileTypeResolving.isExe(fileItem.name)) { - showResult = 14; - } - return showResult - }, + /** + * 获取文件显示模版 + * @param fileItem + */ + wapFileItemShow: function (fileItem) { + return wpUploadFileTools.wapFileItemShowBase(fileItem, false); + }, + /** + * 包装已上传的文件列表 + */ + wapFileItemShowWithUpload(uploadFile) { + return wpUploadFileTools.wapFileItemShowBase(uploadFile, true); + }, + /** + * 获取文件显示的基本操作 + */ + wapFileItemShowBase(fileItem, isUploaded = false) { + let fileName = ""; + let suffix = ""; + let show = ""; + let showIcon = ""; + if (!isUploaded) { + fileName = fileItem.name; + suffix = wpUploadFileTools.getSuffixNameByFileName(fileName); + show = wpUploadFileTools.resolvingShow(fileItem); + showIcon = wpUploadFileShowResolving.getFileItemShowIcon(show, fileItem, false); + } else { + fileName = fileItem.name ? fileItem.name : wpUploadFileTools.resolvingUrlFileName(fileItem.url); + let fileNameGetOFuRL = wpUploadFileTools.resolvingUrlFileName(fileItem.url); + suffix = wpUploadFileTools.getSuffixNameByFileName(fileNameGetOFuRL); + show = wpUploadFileTools.resolvingShowByFileName(fileNameGetOFuRL); + showIcon = wpUploadFileShowResolving.getFileItemShowIcon(show, fileItem.url, true); + } + let fileItemShow = { + // 文件的id + id: wpUploadFileTools.uuid(), + // 文件对象 + file: null, + // 文件的类型 + type: null, + // 文件的大小 + size: null, + // 文件的名字 + name: fileName, + // 文件地址 + url: null, + // 后缀 + suffix: suffix, + // 显示的类型 + show: show, + // 显示的图标或者图片地址 + showIcon: showIcon, + // 显示进度条 + processStatus: { + show: false, + width: 0, + isFail: false + }, + // 文件来源,0选择文件上传,1回显文件 + fileSource: 0, + // 状态0未上传,失败也会转到0,1正在上传,2已经上传 + status: 0, + // 上传文件的描述 + fileDes: null + } + if (!isUploaded) { + // 如果非选择文件下面三个属性为null + fileItemShow.file = fileItem; + fileItemShow.type = fileItem.type; + fileItemShow.size = fileItem.size; + } else { + // 文件描述 + fileItemShow.status = 2; + fileItemShow.fileDes = fileItem; + fileItemShow.fileSource = 1; + fileItemShow.url = fileItem.url; + } + return fileItemShow; + }, + /** + * 解析URL的文件名字 + */ + resolvingUrlFileName: function (fileUrl) { + let index = fileUrl.lastIndexOf("/"); + if (index <= 0) { + index = fileUrl.lastIndexOf("\\"); + } + index = index + 1; + let fileName = fileUrl.substring(index, fileUrl.length); + return fileName; + }, + /** + * 获取文件名后缀 + * @param fileName 文件名全名 + * */ + getSuffixNameByFileName: function (fileName) { + let str = fileName; + let index = str.lastIndexOf("."); + if (index < 0) { + return ""; + } + let pos = index + 1; + return str.substring(pos, str.length); + }, + /** + * 解析显示类型 + * @param fileItem 文件 + * @returns {number} + */ + resolvingShow: function (fileItem) { + // 默认0普通文件 + let showResult = 0; + if (wpUploadFileTypeResolving.isImg(fileItem)) { + showResult = 1; + } else if (wpUploadFileTypeResolving.isVideo(fileItem)) { + showResult = 2; + } else if (wpUploadFileTypeResolving.isAudio(fileItem)) { + showResult = 3; + } else if (wpUploadFileTypeResolving.isDoc(fileItem.name)) { + showResult = 4; + } else if (wpUploadFileTypeResolving.isExcel(fileItem.name)) { + showResult = 5; + } else if (wpUploadFileTypeResolving.isPPT(fileItem.name)) { + showResult = 6; + } else if (wpUploadFileTypeResolving.isPdf(fileItem.name)) { + showResult = 7; + } else if (wpUploadFileTypeResolving.isZip(fileItem.name)) { + showResult = 8; + } else if (wpUploadFileTypeResolving.isWeb(fileItem.name)) { + showResult = 9; + } else if (wpUploadFileTypeResolving.isTxt(fileItem.name)) { + showResult = 10; + } else if (wpUploadFileTypeResolving.isPsd(fileItem.name)) { + showResult = 11; + } else if (wpUploadFileTypeResolving.isCad(fileItem.name)) { + showResult = 12; + } else if (wpUploadFileTypeResolving.isIso(fileItem.name)) { + showResult = 13; + } else if (wpUploadFileTypeResolving.isExe(fileItem.name)) { + showResult = 14; + } + return showResult + }, - /** - * 解析显示类型 - * @param fileItem 文件 - * @returns {number} - */ - resolvingShowByFileName: function (fileItemName) { - // 默认0普通文件 - let showResult = 0; - if (wpUploadFileTypeResolving.isImgByName(fileItemName)) { - showResult = 1; - } else if (wpUploadFileTypeResolving.isVideoByName(fileItemName)) { - showResult = 2; - } else if (wpUploadFileTypeResolving.isAudioByName(fileItemName)) { - showResult = 3; - } else if (wpUploadFileTypeResolving.isDoc(fileItemName)) { - showResult = 4; - } else if (wpUploadFileTypeResolving.isExcel(fileItemName)) { - showResult = 5; - } else if (wpUploadFileTypeResolving.isPPT(fileItemName)) { - showResult = 6; - } else if (wpUploadFileTypeResolving.isPdf(fileItemName)) { - showResult = 7; - } else if (wpUploadFileTypeResolving.isZip(fileItemName)) { - showResult = 8; - } else if (wpUploadFileTypeResolving.isWeb(fileItemName)) { - showResult = 9; - } else if (wpUploadFileTypeResolving.isTxt(fileItemName)) { - showResult = 10; - } else if (wpUploadFileTypeResolving.isPsd(fileItemName)) { - showResult = 11; - } else if (wpUploadFileTypeResolving.isCad(fileItemName)) { - showResult = 12; - } else if (wpUploadFileTypeResolving.isIso(fileItemName)) { - showResult = 13; - } else if (wpUploadFileTypeResolving.isExe(fileItemName)) { - showResult = 14; + /** + * 解析显示类型 + * @param fileItem 文件 + * @returns {number} + */ + resolvingShowByFileName: function (fileItemName) { + // 默认0普通文件 + let showResult = 0; + if (wpUploadFileTypeResolving.isImgByName(fileItemName)) { + showResult = 1; + } else if (wpUploadFileTypeResolving.isVideoByName(fileItemName)) { + showResult = 2; + } else if (wpUploadFileTypeResolving.isAudioByName(fileItemName)) { + showResult = 3; + } else if (wpUploadFileTypeResolving.isDoc(fileItemName)) { + showResult = 4; + } else if (wpUploadFileTypeResolving.isExcel(fileItemName)) { + showResult = 5; + } else if (wpUploadFileTypeResolving.isPPT(fileItemName)) { + showResult = 6; + } else if (wpUploadFileTypeResolving.isPdf(fileItemName)) { + showResult = 7; + } else if (wpUploadFileTypeResolving.isZip(fileItemName)) { + showResult = 8; + } else if (wpUploadFileTypeResolving.isWeb(fileItemName)) { + showResult = 9; + } else if (wpUploadFileTypeResolving.isTxt(fileItemName)) { + showResult = 10; + } else if (wpUploadFileTypeResolving.isPsd(fileItemName)) { + showResult = 11; + } else if (wpUploadFileTypeResolving.isCad(fileItemName)) { + showResult = 12; + } else if (wpUploadFileTypeResolving.isIso(fileItemName)) { + showResult = 13; + } else if (wpUploadFileTypeResolving.isExe(fileItemName)) { + showResult = 14; + } + return showResult + }, + /** + * 生成UUID + * @returns {string} + */ + uuid: function () { + let str = wpUploadFileTools.uuidFull(); + str = str.replace(/-/g, ""); + return str; + }, + uuidFull() { + let s = [] + let hexDigits = "0123456789abcdef" + for (var i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) + } + s[14] = "4" + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) + s[8] = s[13] = s[18] = s[23] = "-" + let uuid = s.join("") + return uuid + }, + /** + * 禁止某个dom的某个事件 + */ + disableObjEvent(domObj, eventName) { + domObj.addEventListener(eventName, function (e) { + e.preventDefault(); + }) } - return showResult - }, - /** - * 生成UUID - * @returns {string} - */ - uuid: function () { - let str = wpUploadFileTools.uuidFull(); - str = str.replace(/-/g, ""); - return str; - }, - uuidFull() { - let s = [] - let hexDigits = "0123456789abcdef" - for (var i = 0; i < 36; i++) { - s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1) - } - s[14] = "4" - s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) - s[8] = s[13] = s[18] = s[23] = "-" - let uuid = s.join("") - return uuid - }, - /** - * 禁止某个dom的某个事件 - */ - disableObjEvent(domObj, eventName) { - domObj.addEventListener(eventName, function (e) { - e.preventDefault(); - }) - } } /** @@ -429,343 +429,343 @@ let wpUploadFileTools = { * @type {{isValid: wpUploadDataValid.isValid}} */ let wpUploadDataValid = { - isValid: function (obj) { - if (undefined === obj || null === obj) { - return false; + isValid: function (obj) { + if (undefined === obj || null === obj) { + return false; + } + return true; + }, + isValidStr: function (str) { + let isValidObj = wpUploadDataValid.isValid(str); + if (!isValidObj) { + return isValidObj; + } + str = str.trim(); + if ("" == str || '' == str) { + return false; + } + return true; + }, + isValidArray(array) { + if (null == array || array == undefined || array.length <= 0) { + return false; + } + return true; } - return true; - }, - isValidStr: function (str) { - let isValidObj = wpUploadDataValid.isValid(str); - if (!isValidObj) { - return isValidObj; - } - str = str.trim(); - if ("" == str || '' == str) { - return false; - } - return true; - }, - isValidArray(array) { - if (null == array || array == undefined || array.length <= 0) { - return false; - } - return true; - } } module.exports = { - props: { - files: Array, - type: { - type: Array, - default: ['jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'zip', 'war'] - }, - max: { - type: Number, - default: 5 - }, - max_size: { - type: Number, - default: 20 * 1024 * 1024 - }, - view: { - type: Boolean, - default: false - }, - card: { - type: Boolean, - default: false - }, - del: { - type: Boolean, - default: true - }, - //"来源(1.文件管理 2.业务上传)" - source: { - type: Number, - default: 2 - } - }, - data() { - return { - fileList: [] - } - }, - watch: { - files(val) { - this.updateFileList(val) - } - }, - methods: { - /** - * 查看资源 - */ - showSource(showItem, index, e) { - const viewFileParent = $(e.target).closest(".viewFile") - const show = this.resolvingShowByFileName(showItem.filename) - if (show == 1 || show == 2 || show == 3) { - const vv = new Viewer(viewFileParent.clone()[0], { - url: 'src', - initialViewIndex: index - }) - vv.show() - } else if (show == 4 || show == 5 || show == 7) { - preview(showItem.filename, showItem.id) - } - }, - /** - * 解析显示类型 - * @param fileItem 文件 - * @returns {number} - */ - resolvingShowByFileName(fileItemName) { - // 默认0普通文件 - let showResult = 0; - if (fileTypeResolving.isImgByName(fileItemName)) { - showResult = 1; - } else if (fileTypeResolving.isVideoByName(fileItemName)) { - showResult = 2; - } else if (fileTypeResolving.isAudioByName(fileItemName)) { - showResult = 3; - } else if (fileTypeResolving.isDoc(fileItemName)) { - showResult = 4; - } else if (fileTypeResolving.isExcel(fileItemName)) { - showResult = 5; - } else if (fileTypeResolving.isPPT(fileItemName)) { - showResult = 6; - } else if (fileTypeResolving.isPdf(fileItemName)) { - showResult = 7; - } else if (fileTypeResolving.isZip(fileItemName)) { - showResult = 8; - } else if (fileTypeResolving.isWeb(fileItemName)) { - showResult = 9; - } else if (fileTypeResolving.isTxt(fileItemName)) { - showResult = 10; - } else if (fileTypeResolving.isPsd(fileItemName)) { - showResult = 11; - } else if (fileTypeResolving.isCad(fileItemName)) { - showResult = 12; - } else if (fileTypeResolving.isIso(fileItemName)) { - showResult = 13; - } else if (fileTypeResolving.isExe(fileItemName)) { - showResult = 14; - } - return showResult - }, - /** - * 获取文件显示图标 - * @param filePath - * @returns {string} - */ - getFileItemShowIcon(filePath) { - let showIcon = ''; - switch (this.resolvingShowByFileName(filePath)) { - case 0: - showIcon = "#icon-yunpanlogo-3"; - break; - // 图片 - case 1: - showIcon = this.getImgShowIcon(filePath); - break; - // 视频 - case 2: - showIcon = "#icon-yunpanlogo-6"; - break; - // 音乐 - case 3: - showIcon = "#icon-yunpanlogo-4"; - break; - // doc - case 4: - showIcon = "#icon-yunpanlogo-2"; - break; - // excel - case 5: - showIcon = "#icon-yunpanlogo-"; - break; - // ppt - case 6: - showIcon = "#icon-yunpanlogo-1"; - break; - // pdf - case 7: - showIcon = "#icon-yunpanlogo-12"; - break; - // zip - case 8: - showIcon = "#icon-yasuobao"; - break; - // web文件 - case 9: - showIcon = "#icon-yunpanlogo-5"; - break; - // txt文件 - case 10: - showIcon = "#icon-yunpanlogo-7"; - break; - // PSD - case 11: - showIcon = "#icon-yunpanlogo-10"; - break; - // cad - case 12: - showIcon = "#icon-yunpanlogo-11"; - break; - // ISO - case 13: - showIcon = "#icon-yunpanlogo-8"; - break; - // 可执行 - case 14: - showIcon = "#icon-yunpanlogo-9"; - break; - // 普通文件 - default: - showIcon = "#icon-yunpanlogo-3"; - } - return showIcon; - }, - /** - * 获取图片的显示图标 - * @param fileItem - * @returns {string|*} - */ - getImgShowIcon(fileItem) { - return FILE_DOMAIN + fileItem; - }, - - - updateFileList(val) { - if (!val || !val.length) { - this.fileList = [] - return - } - this.fileList = val.map(v => { - return {data: v, uid: v.id, name: v.filename, status: 'success'} - }) - }, - change(fileList) { - this.$emit("update:files", fileList.map(v => v.data)) - }, - handleExceed(files, fileList) { - this.$message.warning(`当前限制选择 ${this.max} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`); - }, - onSuccess(response, file, fileList) { - if (response.code === 0) { - const {data} = response - file.data = data - this.change(fileList) - } else { - this.$message.warning('文件上传失败') - } - }, - beforeUpload(file) { - const lastIndexOf = file.name.lastIndexOf(".") - const type = this.type.map(v => v.toLowerCase()).includes(file.name.substr(lastIndexOf + 1).toLowerCase()) - const size = file.size < this.max_size; - if (!type) { - this.$message.warning(`上传文件只能是 ${this.type.map(v => v.toLowerCase()).join("/")} 格式!`); - } - if (!size) { - this.$message.warning(`上传文件大小不能超过 ${this.max_size / 1024 / 1024} MB!`); - } - return type && size; - }, - async handleRemove(file, fileList) { - if (file.data) { - const {id} = file.data - if (this.del) { - const resp = await $.post(FILE_DELETE_ADDRESS, {id}) - if (resp.code === 0) { - this.$message.success(resp.msg) - } else { - this.$message.warning(resp.msg) - } + props: { + files: Array, + type: { + type: Array, + default: ['jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'zip', 'war', 'rar'] + }, + max: { + type: Number, + default: 5 + }, + max_size: { + type: Number, + default: 20 * 1024 * 1024 + }, + view: { + type: Boolean, + default: false + }, + card: { + type: Boolean, + default: false + }, + del: { + type: Boolean, + default: true + }, + //"来源(1.文件管理 2.业务上传)" + source: { + type: Number, + default: 2 } - this.change(fileList) - } }, - handlePreview(file) { - if (file.data) { - const {filename, id} = file.data - preview(filename, id) - } + data() { + return { + fileList: [] + } }, - }, - created() { - this.updateFileList(this.files) - } + watch: { + files(val) { + this.updateFileList(val) + } + }, + methods: { + /** + * 查看资源 + */ + showSource(showItem, index, e) { + const viewFileParent = $(e.target).closest(".viewFile") + const show = this.resolvingShowByFileName(showItem.filename) + if (show == 1 || show == 2 || show == 3) { + const vv = new Viewer(viewFileParent.clone()[0], { + url: 'src', + initialViewIndex: index + }) + vv.show() + } else if (show == 4 || show == 5 || show == 7) { + preview(showItem.filename, showItem.id) + } + }, + /** + * 解析显示类型 + * @param fileItem 文件 + * @returns {number} + */ + resolvingShowByFileName(fileItemName) { + // 默认0普通文件 + let showResult = 0; + if (fileTypeResolving.isImgByName(fileItemName)) { + showResult = 1; + } else if (fileTypeResolving.isVideoByName(fileItemName)) { + showResult = 2; + } else if (fileTypeResolving.isAudioByName(fileItemName)) { + showResult = 3; + } else if (fileTypeResolving.isDoc(fileItemName)) { + showResult = 4; + } else if (fileTypeResolving.isExcel(fileItemName)) { + showResult = 5; + } else if (fileTypeResolving.isPPT(fileItemName)) { + showResult = 6; + } else if (fileTypeResolving.isPdf(fileItemName)) { + showResult = 7; + } else if (fileTypeResolving.isZip(fileItemName)) { + showResult = 8; + } else if (fileTypeResolving.isWeb(fileItemName)) { + showResult = 9; + } else if (fileTypeResolving.isTxt(fileItemName)) { + showResult = 10; + } else if (fileTypeResolving.isPsd(fileItemName)) { + showResult = 11; + } else if (fileTypeResolving.isCad(fileItemName)) { + showResult = 12; + } else if (fileTypeResolving.isIso(fileItemName)) { + showResult = 13; + } else if (fileTypeResolving.isExe(fileItemName)) { + showResult = 14; + } + return showResult + }, + /** + * 获取文件显示图标 + * @param filePath + * @returns {string} + */ + getFileItemShowIcon(filePath) { + let showIcon = ''; + switch (this.resolvingShowByFileName(filePath)) { + case 0: + showIcon = "#icon-yunpanlogo-3"; + break; + // 图片 + case 1: + showIcon = this.getImgShowIcon(filePath); + break; + // 视频 + case 2: + showIcon = "#icon-yunpanlogo-6"; + break; + // 音乐 + case 3: + showIcon = "#icon-yunpanlogo-4"; + break; + // doc + case 4: + showIcon = "#icon-yunpanlogo-2"; + break; + // excel + case 5: + showIcon = "#icon-yunpanlogo-"; + break; + // ppt + case 6: + showIcon = "#icon-yunpanlogo-1"; + break; + // pdf + case 7: + showIcon = "#icon-yunpanlogo-12"; + break; + // zip + case 8: + showIcon = "#icon-yasuobao"; + break; + // web文件 + case 9: + showIcon = "#icon-yunpanlogo-5"; + break; + // txt文件 + case 10: + showIcon = "#icon-yunpanlogo-7"; + break; + // PSD + case 11: + showIcon = "#icon-yunpanlogo-10"; + break; + // cad + case 12: + showIcon = "#icon-yunpanlogo-11"; + break; + // ISO + case 13: + showIcon = "#icon-yunpanlogo-8"; + break; + // 可执行 + case 14: + showIcon = "#icon-yunpanlogo-9"; + break; + // 普通文件 + default: + showIcon = "#icon-yunpanlogo-3"; + } + return showIcon; + }, + /** + * 获取图片的显示图标 + * @param fileItem + * @returns {string|*} + */ + getImgShowIcon(fileItem) { + return FILE_DOMAIN + fileItem; + }, + + + updateFileList(val) { + if (!val || !val.length) { + this.fileList = [] + return + } + this.fileList = val.map(v => { + return {data: v, uid: v.id, name: v.filename, status: 'success'} + }) + }, + change(fileList) { + this.$emit("update:files", fileList.map(v => v.data)) + }, + handleExceed(files, fileList) { + this.$message.warning(`当前限制选择 ${this.max} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`); + }, + onSuccess(response, file, fileList) { + if (response.code === 0) { + const {data} = response + file.data = data + this.change(fileList) + } else { + this.$message.warning('文件上传失败') + } + }, + beforeUpload(file) { + const lastIndexOf = file.name.lastIndexOf(".") + const type = this.type.map(v => v.toLowerCase()).includes(file.name.substr(lastIndexOf + 1).toLowerCase()) + const size = file.size < this.max_size; + if (!type) { + this.$message.warning(`上传文件只能是 ${this.type.map(v => v.toLowerCase()).join("/")} 格式!`); + } + if (!size) { + this.$message.warning(`上传文件大小不能超过 ${this.max_size / 1024 / 1024} MB!`); + } + return type && size; + }, + async handleRemove(file, fileList) { + if (file.data) { + const {id} = file.data + if (this.del) { + const resp = await $.post(FILE_DELETE_ADDRESS, {id}) + if (resp.code === 0) { + this.$message.success(resp.msg) + } else { + this.$message.warning(resp.msg) + } + } + this.change(fileList) + } + }, + handlePreview(file) { + if (file.data) { + const {filename, id} = file.data + preview(filename, id) + } + }, + }, + created() { + this.updateFileList(this.files) + } } diff --git a/src/main/resources/views/platform/fitnessWalk/activityManage.html b/src/main/resources/views/platform/fitnessWalk/activityManage.html index e4b8009..a5b35ce 100644 --- a/src/main/resources/views/platform/fitnessWalk/activityManage.html +++ b/src/main/resources/views/platform/fitnessWalk/activityManage.html @@ -890,12 +890,7 @@ layout("/layouts/platform.html"){