202012 月23
<el-cascader ref="area" v-model="infoForm.area" :props="cascaderProps" style="width: 500px;"
size="small" placeholder="请选择区域"></el-cascader>
cascaderProps: {
lazy: true,
value: 'id',
label: 'text',
lazyLoad: function (node, resolve) {
if (node.level === 0) {
var url = base + "/assets/platform/plugins/zoning/0.json";
$.get(url, function (d) {
resolve(d);
}, "json");
} else {
var pidaspath = node.data.id > 0 ? (node.data.id.substring(0, 2) + "/" + node.data.id) : 0;
var url = base + "/assets/platform/plugins/zoning/"+pidaspath+".json";
$.get(url, function (d) {
resolve(d);
}, "json");
}
}
},
infoForm: {
type: 'designer',
area: [],
areaCode: '',
areaText: '',
},
// 后台返回数据时
this.$set(this.infoForm,'area',this.infoForm.areaCode.split(','))
// 前端入库数据处理
if (this.infoForm.area) {
this.$set(this.infoForm, 'areaCode', this.infoForm.area.toString());
}
if (this.$refs['area']) {
var tree = this.$refs['area'].getCheckedNodes();
this.$set(this.infoForm, 'areaText', tree[0].pathLabels.toString());
}
202012 月22
File[] files=Files.lsDir(new File("D://node/zoning/dist/zoning-3"),"");
for(File dir:files){
if(Files.isDirectory(dir)){
File[] files2=Files.lsAll(dir.getAbsoluteFile(),"json");
for(File file:files2){
System.out.println(file.getAbsolutePath());
System.out.println(file.getName());
if(file.getName().length()==9||file.getName().equalsIgnoreCase("81.json")||file.getName().equalsIgnoreCase("82.json")){
String str=Files.read(file);
List<NutMap> list=Json.fromJsonAsList(NutMap.class,str);
List<NutMap> list2=new ArrayList<>();
for(NutMap nutMap:list){
nutMap.addv("leaf",true);
list2.add(nutMap);
}
Files.write(file,Json.toJson(list2, JsonFormat.compact()));
}
}
}
}
PS:临时用,不要纠结命名~~
202012 月16
pom.xml
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
生成验证码:
public NutMap getCode() {
String uuid = UUID.randomUUID().toString().replace("-", "");
ArithmeticCaptcha captcha = new ArithmeticCaptcha(120, 40);
captcha.getArithmeticString(); // 获取运算的公式:3+2=?
String text = captcha.text();
redisService.setex(RedisConstant.REDIS_CAPTCHA_KEY + uuid, 180, text);
return NutMap.NEW().addv("key", uuid).addv("codeUrl", captcha.toBase64());
}
验证验证码:(表单传递验证码及验证码key)
public void checkCode(String key, String code) throws CaptchaException {
String codeFromRedis = redisService.get(RedisConstant.REDIS_CAPTCHA_KEY + key);
if (Strings.isBlank(code)) {
throw new CaptchaException("请输入验证码");
}
if (Strings.isEmpty(codeFromRedis)) {
throw new CaptchaException("验证码已过期");
}
if (!Strings.equalsIgnoreCase(code, codeFromRedis)) {
throw new CaptchaException("验证码不正确");
}
redisService.del(RedisConstant.REDIS_SMSCODE_KEY + key);
}
try {
validateService.checkCode(key, code);
} catch (CaptchaException e) {
return Result.error(e.getMessage());
}
异常类:
public class CaptchaException extends Exception{
public CaptchaException(String message) {
super(message);
}
}
202012 月2
package com.budwk.app.base.utils;
import org.nutz.lang.util.NutMap;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
/**
* @author wizzer@qq.com
*/
public class FileUtil {
/**
* 分页获取文件列表
*
* @param basePath 目录
* @param pageNumber 页码
* @param pageSize 页大小
* @param sort 按文件名排序
* @return 列表
* @throws Exception
*/
public static NutMap readListPage(String basePath, Integer pageNumber, Integer pageSize, String sort)
throws Exception {
int offset = (pageNumber - 1) * pageSize;
int limit = pageNumber * pageSize;
long total = 0;
List<NutMap> list = new ArrayList<>();
Comparator<Path> comparator = Comparator.naturalOrder();
if ("desc".equals(sort)) {
comparator = Comparator.reverseOrder();
}
try (Stream<Path> fileList = Files.list(Paths.get(basePath))) {
total = fileList.count();
}
try (Stream<Path> fileList = Files.list(Paths.get(basePath)).sorted(comparator).skip(offset)
.limit(limit)) {
fileList.forEach(file -> {
NutMap nutMap = NutMap.NEW();
String fileName = file.getFileName().toString();
nutMap.addv("fileName", fileName);
if (Files.isDirectory(file.toAbsolutePath())) {
nutMap.addv("folder", true);
nutMap.addv("suffix", "folder");
} else {
String suffix = fileName.substring(fileName.indexOf(".") + 1).toLowerCase();
nutMap.addv("folder", false);
nutMap.addv("suffix", suffix);
}
list.add(nutMap);
});
return NutMap.NEW().addv("total", total).addv("list", list);
}
}
}