!761 代码生成:vue2 代码模版格式调整;代码生成:准备 CodegenEngineVue2Test 所需测试文件

Merge pull request !761 from puhui999/feature/sub-table
This commit is contained in:
芋道源码 2023-11-28 12:26:50 +00:00 committed by Gitee
commit d3a565f011
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
25 changed files with 393 additions and 589 deletions

View File

@ -89,7 +89,7 @@
</template>
<script>
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
#if ($hasImageUploadColumn)
import ImageUpload from '@/components/ImageUpload';
#end

View File

@ -221,7 +221,7 @@
</template>
<script>
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
#if ($hasImageUploadColumn)
import ImageUpload from '@/components/ImageUpload';
#end

View File

@ -61,9 +61,9 @@
</template>
<script>
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
#if ($table.templateType == 11)
import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'
import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue';
#end
export default {
name: "${subSimpleClassName}List",

View File

@ -107,7 +107,7 @@
</template>
<script>
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
#if ($hasImageUploadColumn)
import ImageUpload from '@/components/ImageUpload';
#end
@ -212,7 +212,7 @@
this.title = "新增${table.classComment}";
## 特殊:树表专属逻辑
#if ( $table.templateType == 2 )
this.get${simpleClassName}Tree();
await this.get${simpleClassName}Tree();
#end
},
/** 提交按钮 */

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
#foreach($column in $columns)
@ -183,7 +182,7 @@ import Editor from '@/components/Editor';
#if ( $table.templateType != 10 )
#if ( $subTables && $subTables.size() > 0 )
#foreach ($subSimpleClassName in $subSimpleClassNames)
import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue';
#end
#end
#end
@ -298,7 +297,7 @@ export default {
await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?')
try {
await ${simpleClassName}Api.delete${simpleClassName}(${primaryColumn.javaField});
this.getList();
await this.getList();
this.#[[$modal]]#.msgSuccess("删除成功");
} catch {}
},

View File

@ -43,7 +43,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -90,19 +90,17 @@
},
methods: {
/** 打开弹窗 */
open(id, studentId) {
async open(id, studentId) {
this.dialogVisible = true;
this.reset();
const that = this;
this.formData.studentId = studentId;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
StudentApi.getStudentContact(id).then(res=>{
that.formData = res.data;
that.dialogTitle = "修改学生联系人";
})
const res = await StudentApi.getStudentContact(id);
this.formData = res.data;
this.dialogTitle = "修改学生联系人";
} finally {
this.formLoading = false;
}
@ -110,32 +108,26 @@
this.dialogTitle = "新增学生联系人";
},
/** 提交按钮 */
submitForm() {
async submitForm() {
await this.$refs["formRef"].validate();
this.formLoading = true;
try {
let data = this.formData;
this.$refs["formRef"].validate(valid => {
if (!valid) {
return;
}
const data = this.formData;
// 修改的提交
if (data.id) {
StudentApi.updateStudentContact(data).then(response => {
await StudentApi.updateStudentContact(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
});
return;
}
// 添加的提交
StudentApi.createStudentContact(data).then(response => {
await StudentApi.createStudentContact(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
});
});
}finally {
this.formLoading = false
this.formLoading = false;
}
},
/** 表单重置 */

View File

@ -52,8 +52,8 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import StudentContactForm from './StudentContactForm.vue'
import * as StudentApi from '@/api/infra/demo';
import StudentContactForm from './StudentContactForm.vue';
export default {
name: "StudentContactList",
components: {
@ -91,14 +91,12 @@
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
const that = this;
StudentApi.getStudentContactPage(this.queryParams).then(response => {
that.list = response.data.list;
that.total = response.data.total;
});
const res = await StudentApi.getStudentContactPage(this.queryParams);
this.list = res.data.list;
this.total = res.data.total;
} finally {
this.loading = false;
}
@ -111,22 +109,19 @@
/** 添加/修改操作 */
openForm(id) {
if (!this.studentId) {
that.$modal.msgError('请选择一个学生');
this.$modal.msgError('请选择一个学生');
return;
}
this.$refs["formRef"].open(id, this.studentId);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{
return StudentApi.deleteStudentContact(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?');
try {
await StudentApi.deleteStudentContact(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
}

View File

@ -43,7 +43,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -89,18 +89,16 @@
},
methods: {
/** 打开弹窗 */
open(id) {
async open(id) {
this.dialogVisible = true;
this.reset();
const that = this;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
StudentApi.getStudent(id).then(res=>{
that.formData = res.data;
that.title = "修改学生";
})
const res = await StudentApi.getStudent(id);
this.formData = res.data;
this.title = "修改学生";
} finally {
this.formLoading = false;
}
@ -108,41 +106,28 @@
this.title = "新增学生";
},
/** 提交按钮 */
submitForm() {
async submitForm() {
// 校验主表
await this.$refs["formRef"].validate();
this.formLoading = true;
try {
const that = this;
let data = this.formData;
let validate = false;
// 校验主表
this.getRef("formRef").validate(valid => {
validate = valid;
});
// 所有表单校验通过后方可提交
if (!validate) {
return;
}
const data = this.formData;
// 修改的提交
if (data.id) {
StudentApi.updateStudent(data).then(response => {
that.$modal.msgSuccess("修改成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.updateStudent(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
return;
}
// 添加的提交
StudentApi.createStudent(data).then(response => {
that.$modal.msgSuccess("新增成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.createStudent(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
} finally {
this.formLoading = false;
}
},
getRef(refName){
return this.$refs[refName];
},
/** 表单重置 */
reset() {
@ -158,7 +143,7 @@
memo: undefined,
};
this.resetForm("formRef");
},
}
}
};
</script>

View File

@ -43,7 +43,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -90,19 +90,17 @@
},
methods: {
/** 打开弹窗 */
open(id, studentId) {
async open(id, studentId) {
this.dialogVisible = true;
this.reset();
const that = this;
this.formData.studentId = studentId;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
StudentApi.getStudentTeacher(id).then(res=>{
that.formData = res.data;
that.dialogTitle = "修改学生班主任";
})
const res = await StudentApi.getStudentTeacher(id);
this.formData = res.data;
this.dialogTitle = "修改学生班主任";
} finally {
this.formLoading = false;
}
@ -110,32 +108,26 @@
this.dialogTitle = "新增学生班主任";
},
/** 提交按钮 */
submitForm() {
async submitForm() {
await this.$refs["formRef"].validate();
this.formLoading = true;
try {
let data = this.formData;
this.$refs["formRef"].validate(valid => {
if (!valid) {
return;
}
const data = this.formData;
// 修改的提交
if (data.id) {
StudentApi.updateStudentTeacher(data).then(response => {
await StudentApi.updateStudentTeacher(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
});
return;
}
// 添加的提交
StudentApi.createStudentTeacher(data).then(response => {
await StudentApi.createStudentTeacher(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
});
});
}finally {
this.formLoading = false
this.formLoading = false;
}
},
/** 表单重置 */

View File

@ -52,8 +52,8 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import StudentTeacherForm from './StudentTeacherForm.vue'
import * as StudentApi from '@/api/infra/demo';
import StudentTeacherForm from './StudentTeacherForm.vue';
export default {
name: "StudentTeacherList",
components: {
@ -91,14 +91,12 @@
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
const that = this;
StudentApi.getStudentTeacherPage(this.queryParams).then(response => {
that.list = response.data.list;
that.total = response.data.total;
});
const res = await StudentApi.getStudentTeacherPage(this.queryParams);
this.list = res.data.list;
this.total = res.data.total;
} finally {
this.loading = false;
}
@ -111,22 +109,19 @@
/** 添加/修改操作 */
openForm(id) {
if (!this.studentId) {
that.$modal.msgError('请选择一个学生');
this.$modal.msgError('请选择一个学生');
return;
}
this.$refs["formRef"].open(id, this.studentId);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{
return StudentApi.deleteStudentTeacher(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?');
try {
await StudentApi.deleteStudentTeacher(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
}

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名字" prop="name">
@ -131,8 +130,8 @@
<script>
import * as StudentApi from '@/api/infra/demo';
import StudentForm from './StudentForm.vue';
import StudentContactList from './components/StudentContactList.vue'
import StudentTeacherList from './components/StudentTeacherList.vue'
import StudentContactList from './components/StudentContactList.vue';
import StudentTeacherList from './components/StudentTeacherList.vue';
export default {
name: "Student",
components: {
@ -177,13 +176,12 @@ export default {
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
StudentApi.getStudentPage(this.queryParams).then(response => {
this.list = response.data.list;
this.total = response.data.total;
});
const res = await StudentApi.getStudentPage(this.queryParams);
this.list = res.data.list;
this.total = res.data.total;
} finally {
this.loading = false;
}
@ -203,31 +201,25 @@ export default {
this.$refs["formRef"].open(id);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{
return StudentApi.deleteStudent(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?')
try {
await StudentApi.deleteStudent(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
/** 导出按钮操作 */
handleExport() {
const that = this;
async handleExport() {
await this.$modal.confirm('是否确认导出所有学生数据项?');
try {
this.$modal.confirm('是否确认导出所有学生数据项?').then(() => {
that.exportLoading = true;
return StudentApi.exportStudentExcel(params);
}).then(response => {
that.$download.excel(response, '学生.xls');
});
this.exportLoading = true;
const res = await StudentApi.exportStudentExcel(this.queryParams);
this.$download.excel(res.data, '学生.xls');
} catch {
} finally {
that.exportLoading = false;
this.exportLoading = false;
}
},
/** 选中行操作 */

View File

@ -86,7 +86,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -130,8 +130,9 @@
}
try {
this.formLoading = true;
// 这里还是需要获取一下 this 的不然取不到 formData
const that = this;
StudentApi.getStudentContactListByStudentId(val).then(res=>{
StudentApi.getStudentContactListByStudentId(val).then(function (res){
that.formData = res.data;
})
} finally {
@ -156,20 +157,20 @@
video: undefined,
memo: undefined,
}
row.studentId = this.studentId
this.formData.push(row)
row.studentId = this.studentId;
this.formData.push(row);
},
/** 删除按钮操作 */
handleDelete(index) {
this.formData.splice(index, 1)
this.formData.splice(index, 1);
},
/** 表单校验 */
validate(){
return this.$refs["formRef"].validate()
return this.$refs["formRef"].validate();
},
/** 表单值 */
getData(){
return this.formData
return this.formData;
}
}
};

View File

@ -40,7 +40,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
export default {
name: "StudentContactList",
props:[
@ -70,13 +70,11 @@
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
const that = this;
StudentApi.getStudentContactListByStudentId(this.studentId).then(response=>{
that.list = response.data;
})
const res = await StudentApi.getStudentContactListByStudentId(this.studentId);
this.list = res.data;
} finally {
this.loading = false;
}

View File

@ -52,7 +52,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -104,18 +104,16 @@
},
methods: {
/** 打开弹窗 */
open(id) {
async open(id) {
this.dialogVisible = true;
this.reset();
const that = this;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
StudentApi.getStudent(id).then(res=>{
that.formData = res.data;
that.title = "修改学生";
})
const res = await StudentApi.getStudent(id);
this.formData = res.data;
this.title = "修改学生";
} finally {
this.formLoading = false;
}
@ -123,83 +121,44 @@
this.title = "新增学生";
},
/** 提交按钮 */
submitForm() {
this.formLoading = true;
try {
const that = this;
let data = this.formData;
let validate = false;
async submitForm() {
// 校验主表
this.getRef("formRef").validate(valid => {
validate = valid;
});
await this.$refs["formRef"].validate();
// 校验子表
this.validateSubFrom01().then(() => {
// 全部校验通过-拼接子表的数据
// 拼接子表的数据
data.studentContacts = that.getRef('studentContactFormRef').getData();
data.studentTeacher = that.getRef('studentTeacherFormRef').getData();
}).catch((err) => {
validate = false;
that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单
})
// 所有表单校验通过后方可提交
if (!validate) {
try {
await this.$refs['studentContactFormRef'].validate();
} catch (e) {
this.subTabsName = 'studentContact';
return;
}
try {
await this.$refs['studentTeacherFormRef'].validate();
} catch (e) {
this.subTabsName = 'studentTeacher';
return;
}
this.formLoading = true;
try {
const data = this.formData;
// 拼接子表的数据
data.studentContacts = this.$refs['studentContactFormRef'].getData();
data.studentTeacher = this.$refs['studentTeacherFormRef'].getData();
// 修改的提交
if (data.id) {
StudentApi.updateStudent(data).then(response => {
that.$modal.msgSuccess("修改成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.updateStudent(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
return;
}
// 添加的提交
StudentApi.createStudent(data).then(response => {
that.$modal.msgSuccess("新增成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.createStudent(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
} finally {
this.formLoading = false;
}
},
getRef(refName){
return this.$refs[refName];
},
/** 校验子表单 */
validateSubFrom(item) {
return new Promise((resolve, reject) => {
this.getRef(item).validate()
.then(() => {
resolve();
})
.catch(() => {
reject(item);
})
})
},
/** 校验所有子表单 */
validateSubFrom01() {
// 需要校验的表单 ref
const validFormRefArr = [
"studentContactFormRef",
"studentTeacherFormRef",
];
const validArr = []; // 校验
for (const item of validFormRefArr) {
validArr.push(this.validateSubFrom(item));
}
return new Promise((resolve, reject) => {
// 校验所有
Promise.all(validArr).then(() => {
resolve();
}).catch((err) => {
reject(err);
})
})
},
/** 表单重置 */
reset() {
@ -215,7 +174,7 @@
memo: undefined,
};
this.resetForm("formRef");
},
}
}
};
</script>

View File

@ -42,7 +42,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -97,8 +97,9 @@
}
try {
this.formLoading = true;
// 这里还是需要获取一下 this 的不然取不到 formData
const that = this;
StudentApi.getStudentTeacherByStudentId(val).then(res=>{
StudentApi.getStudentTeacherByStudentId(val).then(function (res){
const data = res.data;
if (!data) {
return
@ -115,11 +116,11 @@
methods: {
/** 表单校验 */
validate(){
return this.$refs["formRef"].validate()
return this.$refs["formRef"].validate();
},
/** 表单值 */
getData(){
return this.formData
return this.formData;
}
}
};

View File

@ -40,7 +40,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
export default {
name: "StudentTeacherList",
props:[
@ -70,17 +70,15 @@
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
const that = this;
StudentApi.getStudentTeacherByStudentId(this.studentId).then(response=>{
const data = response.data;
const res = await StudentApi.getStudentTeacherByStudentId(this.studentId);
const data = res.data;
if (!data) {
return
return;
}
that.list.push(data)
})
this.list.push(data);
} finally {
this.loading = false;
}

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名字" prop="name">
@ -128,8 +127,8 @@
<script>
import * as StudentApi from '@/api/infra/demo';
import StudentForm from './StudentForm.vue';
import StudentContactList from './components/StudentContactList.vue'
import StudentTeacherList from './components/StudentTeacherList.vue'
import StudentContactList from './components/StudentContactList.vue';
import StudentTeacherList from './components/StudentTeacherList.vue';
export default {
name: "Student",
components: {
@ -172,13 +171,12 @@ export default {
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
StudentApi.getStudentPage(this.queryParams).then(response => {
this.list = response.data.list;
this.total = response.data.total;
});
const res = await StudentApi.getStudentPage(this.queryParams);
this.list = res.data.list;
this.total = res.data.total;
} finally {
this.loading = false;
}
@ -198,31 +196,25 @@ export default {
this.$refs["formRef"].open(id);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{
return StudentApi.deleteStudent(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?')
try {
await StudentApi.deleteStudent(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
/** 导出按钮操作 */
handleExport() {
const that = this;
async handleExport() {
await this.$modal.confirm('是否确认导出所有学生数据项?');
try {
this.$modal.confirm('是否确认导出所有学生数据项?').then(() => {
that.exportLoading = true;
return StudentApi.exportStudentExcel(params);
}).then(response => {
that.$download.excel(response, '学生.xls');
});
this.exportLoading = true;
const res = await StudentApi.exportStudentExcel(this.queryParams);
this.$download.excel(res.data, '学生.xls');
} catch {
} finally {
that.exportLoading = false;
this.exportLoading = false;
}
},
}

View File

@ -86,7 +86,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -130,8 +130,9 @@
}
try {
this.formLoading = true;
// 这里还是需要获取一下 this 的不然取不到 formData
const that = this;
StudentApi.getStudentContactListByStudentId(val).then(res=>{
StudentApi.getStudentContactListByStudentId(val).then(function (res){
that.formData = res.data;
})
} finally {
@ -156,20 +157,20 @@
video: undefined,
memo: undefined,
}
row.studentId = this.studentId
this.formData.push(row)
row.studentId = this.studentId;
this.formData.push(row);
},
/** 删除按钮操作 */
handleDelete(index) {
this.formData.splice(index, 1)
this.formData.splice(index, 1);
},
/** 表单校验 */
validate(){
return this.$refs["formRef"].validate()
return this.$refs["formRef"].validate();
},
/** 表单值 */
getData(){
return this.formData
return this.formData;
}
}
};

View File

@ -52,7 +52,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -104,18 +104,16 @@
},
methods: {
/** 打开弹窗 */
open(id) {
async open(id) {
this.dialogVisible = true;
this.reset();
const that = this;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
StudentApi.getStudent(id).then(res=>{
that.formData = res.data;
that.title = "修改学生";
})
const res = await StudentApi.getStudent(id);
this.formData = res.data;
this.title = "修改学生";
} finally {
this.formLoading = false;
}
@ -123,83 +121,44 @@
this.title = "新增学生";
},
/** 提交按钮 */
submitForm() {
this.formLoading = true;
try {
const that = this;
let data = this.formData;
let validate = false;
async submitForm() {
// 校验主表
this.getRef("formRef").validate(valid => {
validate = valid;
});
await this.$refs["formRef"].validate();
// 校验子表
this.validateSubFrom01().then(() => {
// 全部校验通过-拼接子表的数据
// 拼接子表的数据
data.studentContacts = that.getRef('studentContactFormRef').getData();
data.studentTeacher = that.getRef('studentTeacherFormRef').getData();
}).catch((err) => {
validate = false;
that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单
})
// 所有表单校验通过后方可提交
if (!validate) {
try {
await this.$refs['studentContactFormRef'].validate();
} catch (e) {
this.subTabsName = 'studentContact';
return;
}
try {
await this.$refs['studentTeacherFormRef'].validate();
} catch (e) {
this.subTabsName = 'studentTeacher';
return;
}
this.formLoading = true;
try {
const data = this.formData;
// 拼接子表的数据
data.studentContacts = this.$refs['studentContactFormRef'].getData();
data.studentTeacher = this.$refs['studentTeacherFormRef'].getData();
// 修改的提交
if (data.id) {
StudentApi.updateStudent(data).then(response => {
that.$modal.msgSuccess("修改成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.updateStudent(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
return;
}
// 添加的提交
StudentApi.createStudent(data).then(response => {
that.$modal.msgSuccess("新增成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.createStudent(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
} finally {
this.formLoading = false;
}
},
getRef(refName){
return this.$refs[refName];
},
/** 校验子表单 */
validateSubFrom(item) {
return new Promise((resolve, reject) => {
this.getRef(item).validate()
.then(() => {
resolve();
})
.catch(() => {
reject(item);
})
})
},
/** 校验所有子表单 */
validateSubFrom01() {
// 需要校验的表单 ref
const validFormRefArr = [
"studentContactFormRef",
"studentTeacherFormRef",
];
const validArr = []; // 校验
for (const item of validFormRefArr) {
validArr.push(this.validateSubFrom(item));
}
return new Promise((resolve, reject) => {
// 校验所有
Promise.all(validArr).then(() => {
resolve();
}).catch((err) => {
reject(err);
})
})
},
/** 表单重置 */
reset() {
@ -215,7 +174,7 @@
memo: undefined,
};
this.resetForm("formRef");
},
}
}
};
</script>

View File

@ -42,7 +42,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -97,8 +97,9 @@
}
try {
this.formLoading = true;
// 这里还是需要获取一下 this 的不然取不到 formData
const that = this;
StudentApi.getStudentTeacherByStudentId(val).then(res=>{
StudentApi.getStudentTeacherByStudentId(val).then(function (res){
const data = res.data;
if (!data) {
return
@ -115,11 +116,11 @@
methods: {
/** 表单校验 */
validate(){
return this.$refs["formRef"].validate()
return this.$refs["formRef"].validate();
},
/** 表单值 */
getData(){
return this.formData
return this.formData;
}
}
};

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名字" prop="name">
@ -155,13 +154,12 @@ export default {
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
StudentApi.getStudentPage(this.queryParams).then(response => {
this.list = response.data.list;
this.total = response.data.total;
});
const res = await StudentApi.getStudentPage(this.queryParams);
this.list = res.data.list;
this.total = res.data.total;
} finally {
this.loading = false;
}
@ -181,31 +179,25 @@ export default {
this.$refs["formRef"].open(id);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{
return StudentApi.deleteStudent(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?')
try {
await StudentApi.deleteStudent(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
/** 导出按钮操作 */
handleExport() {
const that = this;
async handleExport() {
await this.$modal.confirm('是否确认导出所有学生数据项?');
try {
this.$modal.confirm('是否确认导出所有学生数据项?').then(() => {
that.exportLoading = true;
return StudentApi.exportStudentExcel(params);
}).then(response => {
that.$download.excel(response, '学生.xls');
});
this.exportLoading = true;
const res = await StudentApi.exportStudentExcel(this.queryParams);
this.$download.excel(res.data, '学生.xls');
} catch {
} finally {
that.exportLoading = false;
this.exportLoading = false;
}
},
}

View File

@ -43,7 +43,7 @@
</template>
<script>
import * as StudentApi from '@/api/infra/demo'
import * as StudentApi from '@/api/infra/demo';
import ImageUpload from '@/components/ImageUpload';
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
@ -89,18 +89,16 @@
},
methods: {
/** 打开弹窗 */
open(id) {
async open(id) {
this.dialogVisible = true;
this.reset();
const that = this;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
StudentApi.getStudent(id).then(res=>{
that.formData = res.data;
that.title = "修改学生";
})
const res = await StudentApi.getStudent(id);
this.formData = res.data;
this.title = "修改学生";
} finally {
this.formLoading = false;
}
@ -108,41 +106,28 @@
this.title = "新增学生";
},
/** 提交按钮 */
submitForm() {
async submitForm() {
// 校验主表
await this.$refs["formRef"].validate();
this.formLoading = true;
try {
const that = this;
let data = this.formData;
let validate = false;
// 校验主表
this.getRef("formRef").validate(valid => {
validate = valid;
});
// 所有表单校验通过后方可提交
if (!validate) {
return;
}
const data = this.formData;
// 修改的提交
if (data.id) {
StudentApi.updateStudent(data).then(response => {
that.$modal.msgSuccess("修改成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.updateStudent(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
return;
}
// 添加的提交
StudentApi.createStudent(data).then(response => {
that.$modal.msgSuccess("新增成功");
that.dialogVisible = false;
that.$emit('success');
});
await StudentApi.createStudent(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
} finally {
this.formLoading = false;
}
},
getRef(refName){
return this.$refs[refName];
},
/** 表单重置 */
reset() {
@ -158,7 +143,7 @@
memo: undefined,
};
this.resetForm("formRef");
},
}
}
};
</script>

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名字" prop="name">
@ -155,13 +154,12 @@ export default {
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
StudentApi.getStudentPage(this.queryParams).then(response => {
this.list = response.data.list;
this.total = response.data.total;
});
const res = await StudentApi.getStudentPage(this.queryParams);
this.list = res.data.list;
this.total = res.data.total;
} finally {
this.loading = false;
}
@ -181,31 +179,25 @@ export default {
this.$refs["formRef"].open(id);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{
return StudentApi.deleteStudent(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?')
try {
await StudentApi.deleteStudent(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
/** 导出按钮操作 */
handleExport() {
const that = this;
async handleExport() {
await this.$modal.confirm('是否确认导出所有学生数据项?');
try {
this.$modal.confirm('是否确认导出所有学生数据项?').then(() => {
that.exportLoading = true;
return StudentApi.exportStudentExcel(params);
}).then(response => {
that.$download.excel(response, '学生.xls');
});
this.exportLoading = true;
const res = await StudentApi.exportStudentExcel(this.queryParams);
this.$download.excel(res.data, '学生.xls');
} catch {
} finally {
that.exportLoading = false;
this.exportLoading = false;
}
},
}

View File

@ -24,7 +24,7 @@
</template>
<script>
import * as CategoryApi from '@/api/infra/demo'
import * as CategoryApi from '@/api/infra/demo';
import TreeSelect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
@ -56,71 +56,54 @@
},
methods: {
/** 打开弹窗 */
open(id) {
async open(id) {
this.dialogVisible = true;
this.reset();
const that = this;
// 修改时,设置数据
if (id) {
this.formLoading = true;
try {
CategoryApi.getCategory(id).then(res=>{
that.formData = res.data;
that.title = "修改分类";
})
const res = await CategoryApi.getCategory(id);
this.formData = res.data;
this.title = "修改分类";
} finally {
this.formLoading = false;
}
}
this.title = "新增分类";
this.getCategoryTree();
await this.getCategoryTree();
},
/** 提交按钮 */
submitForm() {
async submitForm() {
// 校验主表
await this.$refs["formRef"].validate();
this.formLoading = true;
try {
const that = this;
let data = this.formData;
let validate = false;
// 校验主表
this.getRef("formRef").validate(valid => {
validate = valid;
});
// 所有表单校验通过后方可提交
if (!validate) {
return;
}
const data = this.formData;
// 修改的提交
if (data.id) {
CategoryApi.updateCategory(data).then(response => {
that.$modal.msgSuccess("修改成功");
that.dialogVisible = false;
that.$emit('success');
});
await CategoryApi.updateCategory(data);
this.$modal.msgSuccess("修改成功");
this.dialogVisible = false;
this.$emit('success');
return;
}
// 添加的提交
CategoryApi.createCategory(data).then(response => {
that.$modal.msgSuccess("新增成功");
that.dialogVisible = false;
that.$emit('success');
});
await CategoryApi.createCategory(data);
this.$modal.msgSuccess("新增成功");
this.dialogVisible = false;
this.$emit('success');
} finally {
this.formLoading = false;
}
},
getRef(refName){
return this.$refs[refName];
},
/** 获得分类树 */
getCategoryTree() {
const that = this;
that.categoryTree = [];
CategoryApi.getCategoryList().then(res=>{
async getCategoryTree() {
this.categoryTree = [];
const res = await CategoryApi.getCategoryList();
const root = { id: 0, name: '顶级分类', children: [] };
root.children = this.handleTree(res.data, 'id', 'parentId')
that.categoryTree.push(root)
});
this.categoryTree.push(root)
},
/** 转换分类数据结构 */
normalizer(node) {
@ -141,7 +124,7 @@
parentId: undefined,
};
this.resetForm("formRef");
},
}
}
};
</script>

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名字" prop="name">
@ -104,12 +103,11 @@ export default {
},
methods: {
/** 查询列表 */
getList() {
async getList() {
try {
this.loading = true;
CategoryApi.getCategoryList(this.queryParams).then(response => {
this.list = this.handleTree(response.data, 'id', 'parentId');
})
const res = await CategoryApi.getCategoryList(this.queryParams);
this.list = this.handleTree(res.data, 'id', 'parentId');
} finally {
this.loading = false;
}
@ -129,31 +127,25 @@ export default {
this.$refs["formRef"].open(id);
},
/** 删除按钮操作 */
handleDelete(row) {
const that = this;
try {
async handleDelete(row) {
const id = row.id;
this.$modal.confirm('是否确认删除分类编号为"' + id + '"的数据项?').then(()=>{
return CategoryApi.deleteCategory(id);
}).then(() => {
that.getList();
that.$modal.msgSuccess("删除成功");
}).catch(() => {});
await this.$modal.confirm('是否确认删除分类编号为"' + id + '"的数据项?')
try {
await CategoryApi.deleteCategory(id);
await this.getList();
this.$modal.msgSuccess("删除成功");
} catch {}
},
/** 导出按钮操作 */
handleExport() {
const that = this;
async handleExport() {
await this.$modal.confirm('是否确认导出所有分类数据项?');
try {
this.$modal.confirm('是否确认导出所有分类数据项?').then(() => {
that.exportLoading = true;
return CategoryApi.exportCategoryExcel(params);
}).then(response => {
that.$download.excel(response, '分类.xls');
});
this.exportLoading = true;
const res = await CategoryApi.exportCategoryExcel(this.queryParams);
this.$download.excel(res.data, '分类.xls');
} catch {
} finally {
that.exportLoading = false;
this.exportLoading = false;
}
},
/** 展开/折叠操作 */