vue+element-ui,如何实现当新增时,弹出表单中应用类型为企业微信小程序时,appid 和secret为必填字段,为app时,是非必填?
页面展示
目前代码展示
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" class="container-top">
<bread-crumb />
<el-form-item label="应用名称" prop="applicationName">
<el-input
v-model="queryParams.applicationName"
placeholder="请输入应用名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="展示名称" prop="displayName">
<el-input
v-model="queryParams.displayName"
placeholder="请输入展示名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="应用类型" prop="applicationType">
<el-input
v-model="queryParams.applicationType"
placeholder="请输入展示名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button class="button-search" type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button class="button-refresh" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="container-bottom">
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['system:post:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:post:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:post:remove']"
>删除</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange" :height="tableHeight" style="background-color: transparent;" header-row-class-name="header-row-style">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="应用名称" align="center" prop="applicationName" />
<el-table-column label="展示名称" align="center" prop="displayName" />
<el-table-column label="应用类型" align="center" prop="applicationType">
<!-- <template slot-scope="scope">
{{ scope.row.applicationType === '0' ? "企业微信" : "小程序" }}
</template> -->
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['system:post:edit']"
>修改</el-button>
<el-button
class="del-btn"
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['system:post:remove']"
>删除</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-view"
@click="handleView(scope.row)"
>查看详情</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
<!-- 应用管理详细 -->
<el-dialog title="应用管理详细" :visible.sync="detailOpen" width="700px" append-to-body>
<el-form ref="form" :model="detailForm" label-width="100px" size="mini">
<el-row>
<el-col :span="12">
<el-form-item label="应用名称:">{{ detailForm.applicationName }}</el-form-item>
<el-form-item label="应用类型:">{{ detailForm.applicationType }}</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="展示名称:">{{ detailForm.displayName }}</el-form-item>
<el-form-item label="appid:">{{ detailForm.appid }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="secret:">{{ detailForm.secret }}</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="detailOpen = false">关 闭</el-button>
</div>
</el-dialog>
<!-- 添加或修改岗位对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="应用名称" prop="applicationName">
<el-input v-model="form.applicationName" placeholder="请输入应用名称" :disabled="isEdit"/>
</el-form-item>
<el-form-item label="展示名称" prop="displayName">
<el-input v-model="form.displayName" placeholder="请输入展示名称" />
</el-form-item>
<el-form-item label="应用类型" prop="applicationType">
<el-select v-model="form.applicationType" placeholder="请选择应用类型">
<el-option key="app" label="app" value="app"></el-option>
<el-option key="企业微信小程序" label="企业微信小程序" value="企业微信小程序"></el-option>
</el-select>
</el-form-item>
<el-form-item label="appid" prop="appid">
<el-input v-model="form.appid" placeholder="请输入appid" :type="hidePassword ? 'password' : 'text'"/>
</el-form-item>
<el-form-item label="secret" prop="secret">
<el-input v-model="form.secret" placeholder="请输入secret" :type="hidePassword ? 'password' : 'text'"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listPost, getPost, delPost, addPost, updatePost } from "@/api/system/post";
import { listApplied,getApplied,addApplied,updateApplied,delApplied } from "@/api/confManager/appliedManager";
import breadCrumb from "@/components/Breadcrumb/index.vue"
import autoComputedH from '@/utils/mixins/autoComputedH'
export default {
name: "Post",
mixins: [autoComputedH],
dicts: ['sys_normal_disable'],
components: {
breadCrumb,
},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 岗位表格数据
postList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
detailOpen:false,
isEdit:false,
hidePassword:true,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
applicationName: undefined,
displayName: undefined,
applicationType: undefined
},
// 表单参数
form: {},
detailForm:{},
// 表单校验
rules: {
applicationName: [
{ required: true, message: "应用名称不能为空", trigger: "blur" },
{ validator: this.validateAppName, trigger: "blur" }
],
displayName: [
{ required: true, message: "展示名称不能为空", trigger: "blur" }
],
applicationType: [
{ required: true, message: "应用类型不能为空", trigger: "blur" }
],
appid: [
{ validator: this.checkAppid, message: "appid不能为空", trigger: 'blur' }
],
secret: [
{ validator: this.checkSecret, message: "secret不能为空",trigger: 'blur' }
],
},
containerTop: null,
};
},
created() {
this.getList();
},
methods: {
// 自定义校验函数
validateAppName(rule, value, callback) {
if (!value) {
callback(new Error("应用名称不能为空"));
} else if (!/^[a-zA-Z_]+$/.test(value)) {
callback(new Error("应用名称只能包含英文字母和下划线"));
} else {
callback();
}
},
/** 查询岗位列表 */
getList() {
this.loading = true;
listApplied(this.queryParams).then(response => {
console.log(response,'response')
this.postList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
applicationName: undefined,
displayName: undefined,
applicationType: undefined,
appid: undefined,
secret: undefined,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.isEdit = false;
this.hidePassword=false;
this.open = true;
this.title = "添加应用管理";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.isEdit = true;
const id = row.id || this.ids
getApplied(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改应用管理";
});
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != undefined) {
updateApplied(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addApplied(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$modal.confirm('是否确认删除所选数据项?').then(function() {
return delApplied(ids);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
handleView(row) {
const entrustId = row.entrustId;
getEntrust(entrustId).then(response => {
this.form = response.data;
this.testUserArry = this.form.testUser && this.form.testUser.split(",").map(Number);
this.methodArry = this.form.method && this.form.method.split(",").map(Number);
this.testitemsNumberArry = this.form.testitemsName && this.form.testitemsName.split(",");
this.open = true;
this.title = "委托单信息";
});
},
/** 查看详情按钮操作 */
handleView(row) {
const appliedId = row.id
getApplied(appliedId).then(response => {
this.detailForm = response.data;
this.detailOpen = true;
this.title = "应用详情";
});
/* this.detailForm = row; */
},
}
};
</script>
<style scoped>
</style>