输入框校验
// 只能输入数字
onkeyup="value=value.replace(/[^0-9]/g,'')" onpaste="value=value.replace(/[^0-9]/g,'')" oncontextmenu ="value=value.replace(/[^0-9]/g,'')"
// 只能输入数字、小数点
onkeyup="value=value.replace(/[^\0-9\.]/g,'')" onpaste="value=value.replace(/[^\0-9\.]/g,'')" oncontextmenu ="value=value.replace(/[^\0-9\.]/g,'')"
// 只能输入英文
onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z]/g,'')" oncontextmenu ="value=value.replace(/[^\a-\z\A-\Z]/g,'')"
// 只能输入英文、数字
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" oncontextmenu="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')"
// 只能输入中文
onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onpaste="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" oncontextmenu="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
// 只能输入中文、英文、数字
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')" oncontextmenu ="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,'')"
// 只能输入中文、英文、数字、空格
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\]/g,'')" oncontextmenu ="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\]/g,'')"
// 只能输入中文、英文、数字、小数点
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'')" oncontextmenu ="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'')"
// 不可粘贴
onpaste="return false" oncontextmenu="return false;"
// 如果使用了vue没有变更,则加入事件
@blur="data.loginName = $event.target.value"
echars自适应
window.onresize = () => this.echartObj.resize();
打开弹窗
body .dialog-class .layui-layer-load {
background: white;
}
layer.open({
type: 2,
skin: 'dialog-class',
title: "仪器-试剂配置",
content: '${ctx}/reagent/deviceReagentPage',
area: ['80%', '90%'],
isOutAnim: false, // 关闭窗口动画
anim: -1, // 关闭出场动画
});
表格自定义行颜色
<el-table :row-style="handleRowStyle"
handleRowStyle({row, rowIndex}) {
if (row.alertStatus === 4) {
return {}
}
return {
background: "red",
color: "white"
};
},
用户选择列表
// 用户列表
userList : [],
<el-select v-model="formData.userId" placeholder="请选择负责人" filterable clearable :style="{width: '100%'}">
<el-option v-for="(item, index) in userList" :key="index" :label="item.name"
:value="item.id"></el-option>
</el-select>
// 包含子部门的用户列表(查询,修改)
getUserListBySubOffice(officeId) {
$.get("${ctx}/sys/user/getUserListBySubOffice/" + officeId, (res) => {
this.userList = res.data
});
},
// 不含子部门的用户列表(增加)
getUserListByOffice(officeId) {
$.get("${ctx}/sys/user/getUserListByOffice/" + officeId, (res) => {
this.userList = res.data
});
},
this.getUserListByOffice(this.queryParams.officeId)
this.getUserListBySubOffice(this.queryParams.officeId)
部门树
html, body, #app, .el-container {
width: 100%;
height: 100%;
}
<est-office-tree :office-id.sync="queryParams.officeId" width="300px" :office-name.sync="officeName" @query-method="handleQuery"></est-office-tree>
<el-divider direction="vertical" class="divider-style"></el-divider>
文件上传
.el-upload__tip {
line-height: 1.2;
}
.el-upload__input {
display: none !important;
}
.el-upload-list__item .el-icon-close-tip {
display: none !important;
}
<el-col :span="12">
<el-form-item label="上传" prop="urls">
<el-upload :file-list="uploadFileList" multiple action="${ctx}/resContract/upload"
:on-success="onSuccess" :on-preview="previewFile"
:before-remove="beforeRemove" :on-remove="onRemove">
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
</el-upload>
</el-form-item>
</el-col>
vue data添加
// 文件上传列表
uploadFileList: [],
resetForm()
this.uploadFileList = []
saveOrUpdate()
if (valid) {
// 复制这里
if (this.uploadFileList.length > 0) {
this.formData.fileName = ""
this.formData.urls = ""
this.uploadFileList.forEach((file) => {
this.formData.fileName += file.name + ","
this.formData.urls += file.minioObjectName + ","
});
this.formData.fileName = this.formData.fileName.substring(0, this.formData.fileName.length - 1)
this.formData.urls = this.formData.urls.substring(0, this.formData.urls.length - 1)
}
handleUpdate() ajax里面
// 回显上传列表
if (res.data.urls != null && res.data.urls !== "") {
let fileNameList = res.data.fileName.split(",");
let urlList = res.data.urls.split(",")
for (let i = 0; i < urlList.length; i++) {
this.uploadFileList.push({
"uid": i,
"name": fileNameList[i],
"minioObjectName": urlList[i]
});
}
}
method()
// 上传成功回调
onSuccess(res, file, fileList) {
if (res.status === "-1") {
// 移除失败文件
let index = fileList.findIndex(e => e.uid === file.uid);
fileList.splice(index, 1)
this.$message.error("文件[" + file.name + "] 上传失败:" + res.message);
return false
} else {
file.minioObjectName = res.data;
}
this.uploadFileList = fileList
},
beforeRemove(file, fileList) {
return this.$confirm('是否删除: ' + file.name)
},
onRemove(file, fileList) {
let index = this.uploadFileList.findIndex(e => e.uid === file.uid);
this.uploadFileList.splice(index, 1)
},
// 下载
previewFile(file) {
window.open("${ctx}/resContract/download?objectName=" + file.minioObjectName)
},
controller
@PostMapping(value = "/upload")
@ResponseBody
public ResponseMessage upload(MultipartFile file) throws Exception {
return ResponseMessage.newOkInstance(resContractService.upload(file));
}
@GetMapping(value = "/download")
public String download(String objectName) throws Exception {
return "redirect:" + resContractService.download(objectName);
}
service
private final String BUCKET_NAME = "rent-house";
@Autowired
private MinioService minioService;
public String upload(MultipartFile file) throws Exception {
String minioObjectName = Global.USERFILES_BASE_URL + UserUtils.getUser().getId() + "/rentHouse/" + IdGen.uuid() + "/" + file.getOriginalFilename();
minioService.updateFile(BUCKET_NAME, file, minioObjectName);
return minioObjectName;
}
public String download(String objectName) throws Exception {
return minioService.getDownloadUrl(BUCKET_NAME, objectName, null);
}
vue渲染闪烁
<style>
[v-cloak]{
display: none;
}
</style>
<div id="app" v-cloak>