網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
,from表單
有兩個(gè)parmas,展示的數(shù)據(jù),rules,校驗(yàn)規(guī)則
看代碼,雖然沒(méi)用
1,如果彈窗后關(guān)閉彈窗,再打開(kāi)發(fā)現(xiàn)有校驗(yàn)問(wèn)題,這個(gè)需要重置表單,使用resetfields() 方法,這個(gè)方法可以對(duì)整個(gè)表單進(jìn)行重置,將所有字段值重置為初始值并移除校驗(yàn)結(jié)果;
坑:也會(huì)清除并初始化所有的默認(rèn)數(shù)據(jù),所以要注意使用
2,如果再點(diǎn)擊彈窗,彈窗中有類(lèi)似于切換的頁(yè)面的,如

彈出后后面需要往彈窗傳數(shù)據(jù),并且點(diǎn)擊對(duì)應(yīng)的編輯彈出對(duì)應(yīng)的導(dǎo)航數(shù)據(jù)時(shí),要在關(guān)閉彈窗的時(shí)候?qū)?dǎo)航腳標(biāo)設(shè)置為初始值;
export const BASE_FORM = [
{
label: '單號(hào)',
key: 'superviseNo',
type: 'input',
disabled: true,
loading: false,
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '事項(xiàng)',
key: 'superviseDesc',
type: 'input',
maxLength: 50,
loading: false,
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '部門(mén)',
key: 'creatorId',
labelKey: 'creatorName',
addKey: {
label: {
getLable: 'deptName',
subLable: 'deptName',
},
value: {
getLable: 'deptId',
subLable: 'deptId',
},
}, // 附帶值,下拉選之后,其他內(nèi)容默認(rèn)展示
type: 'selectRemote',
apiUrl: 'getStaffList',
isFilterable: true,
isRemote: true,
loading: false,
disabled: true,
optionList: [],
class: 'hasAddKey',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '日期',
key: 'createTime',
type: 'input',
disabled: true,
loading: false,
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '聯(lián)系電話',
key: 'contactNumber',
type: 'input',
disabled: true,
loading: false,
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '類(lèi)別',
key: 'superviseCategory',
labelKey: 'superviseCategoryName',
type: 'select',
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '來(lái)源',
key: 'superviseSource',
labelKey: 'superviseSourceName',
type: 'select',
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '簽發(fā)人',
key: 'signerId',
labelKey: 'signerName', // 需要給后臺(tái)同時(shí)傳label 和 value 2個(gè)值
type: 'selectRemote',
apiUrl: 'getUserLeader',
defaultValue: 'gyh',
defaultLabelValue: '',
isFilterable: true,
isRemote: true,
loading: false,
optionList: [{
deptId: '2',
deptName: '公司領(lǐng)導(dǎo)',
loginId: '',
userName: '',
workCode: 'CT00142',
}],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '反饋周期',
key: 'feedbackPeriod',
defaultValue: 'week',
type: 'select',
loading: false,
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '計(jì)劃辦結(jié)時(shí)限',
key: 'planFinishDate',
type: 'date',
optionList: [],
class: '',
xl: 6,
lg: 8,
md: 12,
sm: 12,
},
{
label: '要求',
key: 'superviseRequirements',
type: 'textarea',
optionList: [],
class: '',
xl: 24,
lg: 24,
md: 24,
sm: 24,
},
{
label: '備注',
key: 'remark',
type: 'textarea',
notRequired: true,
optionList: [],
class: '',
xl: 24,
lg: 24,
md: 24,
sm: 24,
},
{
label: '附件',
key: 'attachmentList',
type: 'uploadFile',
isMultiple: true,
loading: false,
notRequired: true,
optionList: [],
class: '',
xl: 24,
lg: 24,
md: 24,
sm: 24,
},
];
<template>
<el-form
class="supervise-detail__form"
ref="baseForm"
:rules="baseRules"
:model="baseForm"
label-position="top"
>
<el-row :gutter="32">
<el-col
v-for="item in baseFormList"
:key="item.key"
:xl="item.xl"
:lg="item.lg"
:md="item.md"
:sm="item.sm"
>
<el-form-item v-if="!item.notShow" :class="item.class" :prop="item.key">
<template slot="label">
{{ item.label }}
<!-- 提示 -->
<el-popover
v-if="item.tipsType"
popper-class="supervise-detail__tips"
placement="bottom"
trigger="hover"
>
<div v-if="item.tipsType === 'text'" style="max-width: 600px">
{{ item.tips }}
</div>
<div v-else-if="item.tipsType === 'table'" style="max-width: 600px">
<el-table
stripe
tooltip-effect="light"
:cell-style="getCellStyle"
:data="baseForm[item.tipsKey]"
style="width: 100%;">
<el-table-column
show-overflow-tooltip
v-for="tableItem in item.tipsHeader"
:key="tableItem.key"
:prop="tableItem.key"
:label="tableItem.label"
:width="tableItem.width || 'auto'"
:align="tableItem.algin || 'left'"
>
<template slot-scope="scope">
{{ scope.row[tableItem.key] }}
</template>
</el-table-column>
</el-table>
</div>
<svg-icon
style="margin-left: 5px;"
slot="reference"
class="icon"
icon-class="infoTips"
/>
</el-popover>
</template>
<!-- 輸入框 -->
<el-input
:disabled="item.disabled ? true : false"
v-emoji
:maxlength="item.maxLength || 500"
v-if="item.type === 'input'"
v-model.trim="baseForm[item.key]"
:placeholder="`請(qǐng)輸入${item.label}`"
>
</el-input>
<!-- 下拉選 -->
<el-select
:disabled="item.disabled ? true : false"
v-else-if="item.type === 'select'"
v-model="baseForm[item.key]"
:filterable="item.isFilterable"
:multiple="item.isMultiple"
:placeholder="`請(qǐng)選擇${item.label}`"
collapse-tags
@change="(val) => changeSelect(val, item, baseForm)"
>
<el-option
v-for="optionItem in item.optionList"
:key="optionItem.value"
:label="optionItem.label"
:value="optionItem.value"
></el-option>
</el-select>
<!-- 遠(yuǎn)程選擇(員工) -->
<el-select
:disabled="item.disabled ? true : false"
v-else-if="item.type === 'selectRemote'"
v-model="baseForm[item.key]"
:filterable="item.isFilterable"
:remote="item.isRemote"
:multiple="item.isMultiple"
:placeholder="`請(qǐng)輸入${item.label}`"
:remote-method="(query) => getRemoteOption(query, item)"
:loading="item.loading"
@focus="getRemoteOption('', item)"
@change="(str) => changeUserSelect(str, item, baseForm)"
>
<div slot="prefix">
<i class="el-icon-search"></i>
</div>
<el-option
v-for="optionItem in item.optionList"
:key="optionItem.loginId"
:label="optionItem.userName"
:value="optionItem.loginId"
>
{{ `${optionItem.userName} - ${optionItem.workCode}` }}
</el-option>
</el-select>
<el-input
v-emoji
disabled
class="addKey"
:maxlength="item.maxLength || 500"
v-if="item.addKey"
v-model.trim="baseForm[item.addKey.label.subLable]"
>
</el-input>
<!-- 時(shí)間選擇 -->
<el-date-picker
:disabled="item.disabled ? true : false"
v-else-if="item.type === 'date'"
v-model="baseForm[item.key]"
type="date"
:editable="false"
:clearable="false"
value-format="yyyy-MM-dd"
:placeholder="`請(qǐng)選擇${item.label}`"
>
</el-date-picker>
<!-- 級(jí)聯(lián) -->
<el-cascader
:disabled="item.disabled ? true : false"
v-else-if="item.type === 'cascader'"
:props="{
checkStrictly: item.isCheckStrictly,
multiple: item.isMultiple,
}"
collapse-tags
v-model="baseForm[item.key]"
:options="item.optionList"
@change="(val) => changeDepSelect(val, item, baseForm)"
:placeholder="`請(qǐng)選擇${item.label}`"
>
</el-cascader>
<!-- 文本域 -->
<el-input
:disabled="item.disabled ? true : false"
:maxlength="item.maxLength || 500"
show-word-limit
v-emoji
v-else-if="item.type === 'textarea'"
type="textarea"
:rows="2"
:autosize="{
minRows: 3,
}"
v-model.trim="baseForm[item.key]"
:placeholder="`請(qǐng)輸入${item.label}`"
>
</el-input>
<!-- 附件上傳 -->
<el-upload
:class="{hideBtn: item.hideBtn}"
v-else-if="item.type === 'uploadFile'"
class="upload"
accept="*"
:disabled="item.disabled || uploading"
:action="uploadUrl"
:file-list="baseForm[item.key]"
:before-upload="fileBeforeUpload"
:on-preview="downloadFile"
:on-error="uploadError"
:on-progress="uploadProgress"
:on-remove="(file)=>fileRemove(file, item)"
:on-success="(res) => uploadSuccess(res, item)"
>
<el-button type="primary" :disabled="uploading">
上傳附件
</el-button>
<div slot="tip" class="el-upload__tip">
僅支持上傳以下類(lèi)型文件: .pdf,.xls,.xlsx,.doc,.docx,.zip,.png,.jpg,.jpeg,.rar,且單個(gè)文件不超過(guò)50MB
</div>
</el-upload>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
// import { api } from '@/api';
import { flat } from '@/util/validate';
import myForm from '@/mixins/my-form';
export default {
name: 'my-form',
mixins: [myForm],
components: {},
props: {
// 輸入框類(lèi)型
baseFormList: {
type: Array,
default: () => [],
},
// 輸入框選中后的傳參
baseForm: {
type: Object,
default: () => {},
},
},
watch: {
baseForm: {
handler(val) {
console.log('查看baseForm', val);
if (val) {
this.updateForm();
}
},
deep: true,
},
baseFormList: {
handler(val) {
console.log('myfrom的表單數(shù)據(jù)baseFormList', val);
},
deep: true,
},
},
data() {
return {
// 督辦立項(xiàng)單
baseRules: {},
// 扁平化部門(mén)
depOptions: [],
// 附件上傳地址
uploadUrl: `${process.env.VUE_APP_BASE_URL}common/file/upload`,
uploading: false,
};
},
created() {
this.initData();
this.initOption();
},
methods: {
...mapActions(['apiGetDepList']),
// 更新數(shù)據(jù)
updateForm() {
// 關(guān)閉數(shù)據(jù)后更新依然要刷新下拉框
this.initOption();
this.$emit('update:baseForm', this.baseForm);
},
// 取消校驗(yàn)
closeBaseForm() {
this.$refs.baseForm.resetFields();
},
// 校驗(yàn)必填項(xiàng)
checkValidate() {
const that = this;
console.log(this.baseFormList, this.baseForm);
return new Promise((resolve) => {
this.$refs.baseForm.validate((valid) => {
if (!valid) {
resolve(false);
return false;
}
that.updateForm();
resolve(true);
return true;
});
});
},
// 重置數(shù)據(jù)
resetForm() {
this.$refs.baseForm.resetFields();
},
/**
* 附件相關(guān)
*/
// 上傳校驗(yàn)
fileBeforeUpload(file) {
const isLt50M = file.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error('上傳文件大小不能超過(guò) 50MB!');
return false;
}
const suffix = file.name.split('.').slice(-1)[0].toLowerCase();
const types = ['pdf', 'xls', 'xlsx', 'doc', 'docx', 'zip', 'png', 'jpg', 'jpeg', 'rar'];
const isRightType = types.includes(suffix);
if (!isRightType) {
this.$message.error('僅支持上傳以下類(lèi)型文件:.pdf|.xls|.xlsx|.doc|.docx|.zip|.png|.jpg|.jpeg|.rar');
return false;
}
return isLt50M && isRightType;
},
// 移除文件
fileRemove(file, item) {
this.baseForm[item.key] = this.baseForm[item.key].filter(
(el) => (el.url !== file.url),
);
},
// 上傳中
uploadProgress() {
this.uploading = true;
},
// 上傳失敗
uploadError(res) {
this.$message.error(res.message);
},
// 上傳成功
uploadSuccess(res, item) {
this.uploading = false;
if (res.messageCode === '200') {
this.baseForm[item.key].push({
name: res.data.docName,
...res.data,
});
this.$message({
message: '上傳成功',
type: 'success',
});
} else {
this.$message({
message: res.message,
type: 'error',
});
}
},
// 下載文件
downloadFile(file) {
if (file.url) {
const link = document.createElement('a');
link.style.display = 'none';
link.href = file.location;
link.setAttribute('download', file.name);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
},
// 數(shù)據(jù)初始化
initData() {
// console.log(this.baseForm, this.baseFormList);
// 督辦立項(xiàng)單
this.baseFormList.forEach((el) => {
if (el.isMultiple && !el.labelKey) {
this.$set(this.baseForm, el.key, []);
} else if (!el.isMultiple && el.labelKey) {
this.$set(this.baseForm, el.key, '');
this.$set(this.baseForm, el.labelKey, '');
} else if (!el.isMultiple && !el.labelKey) {
this.$set(this.baseForm, el.key, '');
}
if (el.defaultValue) {
this.$set(this.baseForm, el.key, el.defaultValue);
}
if (el.defaultLabelValue) {
this.$set(this.baseForm, el.labelKey, el.defaultLabelValue);
}
if (el.notRequired) {
return false;
}
const rules = [];
const inputType = ['input', 'textarea'];
if (inputType.indexOf(el.type) > -1) {
rules.push({
required: true,
message: `請(qǐng)輸入${el.label}`,
trigger: ['change', 'blur'],
});
this.$set(this.baseRules, el.key, rules);
} else {
rules.push({
required: true,
message: `請(qǐng)選擇${el.label}`,
trigger: ['change'],
});
this.$set(this.baseRules, el.key, rules);
}
return true;
});
// console.log(this.baseForm, this.taskInfo, this.baseRules);
},
// 下拉選初始化
async initOption() {
// 部門(mén)處理
const res = await this.apiGetDepList();
// 部門(mén)扁平化處理,方便獲取名稱
this.depOptions = flat(res);
// 部門(mén)相關(guān)下拉選,在這里可以更改下拉框的重置參數(shù)
const dep = ['hostUnitId', 'assistanceUnitId', 'hostUnitName', 'assistanceUnitName'];
this.baseFormList.forEach((el) => {
if (this.getConditionObj[el.key]) {
this.$set(el, 'optionList', this.getConditionObj[el.key]);
}
if (dep.indexOf(el.key) > -1) {
this.$set(el, 'optionList', res[0].children);
}
});
},
},
computed: {
...mapGetters(['getConditionObj', 'getUserInfo']),
},
};
</script>
原文鏈接:https://blog.csdn.net/m0_64207574/article/details/129142632
- 上一篇:沒(méi)有了
- 下一篇:沒(méi)有了
相關(guān)推薦
- 2023-04-01 python加速器numba使用詳解_python
- 2022-05-10 淺談patch,以及里面的diff算法
- 2022-01-15 面試官:[‘1‘, ‘2‘, ‘3‘].map(parseInt)的結(jié)果是什么?為甚?我:[1, 2
- 2022-12-24 Python中random.shuffle()函數(shù)用法代碼案例_python
- 2022-03-29 Android頂部標(biāo)題欄的布局設(shè)計(jì)_Android
- 2022-08-02 Docker安裝Redis配置遠(yuǎn)程連接及踩坑_docker
- 2022-09-13 Oracle使用fy_recover_data恢復(fù)truncate刪除的數(shù)據(jù)_oracle
- 2022-08-16 C#?泛型List排序的實(shí)現(xiàn)_C#教程
- 欄目分類(lèi)
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支