diff --git a/src/views/infra/demo/demo01/Demo01ContactForm.vue b/src/views/infra/demo/demo01/Demo01ContactForm.vue index 1587ca0710b51952b1f8fc9c3902257e3106d6aa..844e7b797d22978e7894c1ab1f5363dde5ec34ad 100644 --- a/src/views/infra/demo/demo01/Demo01ContactForm.vue +++ b/src/views/infra/demo/demo01/Demo01ContactForm.vue @@ -18,9 +18,8 @@ - - - + + @@ -115,7 +111,7 @@ export default { description: null, avatar: null, createTime: [], - } + }, }; }, created() { @@ -123,13 +119,12 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - Demo01ContactApi.getDemo01ContactPage(this.queryParams).then(response => { - this.list = response.data.list; - this.total = response.data.total; - }); + const res = await Demo01ContactApi.getDemo01ContactPage(this.queryParams); + this.list = res.data.list; + this.total = res.data.total; } finally { this.loading = false; } @@ -146,34 +141,28 @@ export default { }, /** 添加/修改操作 */ openForm(id) { - this.$refs["formRef"].open(id) + this.$refs["formRef"].open(id); }, /** 删除按钮操作 */ - handleDelete(row) { - const that = this; + async handleDelete(row) { + const id = row.id; + await this.$modal.confirm('是否确认删除示例联系人编号为"' + id + '"的数据项?') try { - const id = row.id; - this.$modal.confirm('是否确认删除示例联系人编号为"' + id + '"的数据项?').then(()=>{ - return Demo01ContactApi.deleteDemo01Contact(id); - }).then(() => { - that.getList(); - that.$modal.msgSuccess("删除成功"); - }).catch(() => {}); + await Demo01ContactApi.deleteDemo01Contact(id); + 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 Demo01ContactApi.exportDemo01ContactExcel(params); - }).then(response => { - that.$download.excel(response, '示例联系人.xls'); - }); + this.exportLoading = true; + const res = await Demo01ContactApi.exportDemo01ContactExcel(this.queryParams); + this.$download.excel(res.data, '示例联系人.xls'); } catch { } finally { - that.exportLoading = false; + this.exportLoading = false; } }, } diff --git a/src/views/infra/demo/demo02/Demo02CategoryForm.vue b/src/views/infra/demo/demo02/Demo02CategoryForm.vue index 9865965114b6be85a324a3a33894b7896aebd556..ff9b78b4b44277d250385b1f88d62ab2e97c21fa 100644 --- a/src/views/infra/demo/demo02/Demo02CategoryForm.vue +++ b/src/views/infra/demo/demo02/Demo02CategoryForm.vue @@ -8,10 +8,10 @@ @@ -56,69 +56,54 @@ export default { }, methods: { /** 打开弹窗 */ - open(id) { + async open(id) { this.dialogVisible = true; this.reset(); - const that = this; // 修改时,设置数据 if (id) { this.formLoading = true; try { - Demo02CategoryApi.getDemo02Category(id).then(res=>{ - that.formData = res.data; - that.title = "修改示例分类"; - }) + const res = await Demo02CategoryApi.getDemo02Category(id); + this.formData = res.data; + this.title = "修改示例分类"; } finally { this.formLoading = false; } } this.title = "新增示例分类"; - this.getDemo02CategoryTree() + this.getDemo02CategoryTree(); }, - /** 提交按钮 */ - submitForm() { + async submitForm() { + // 校验主表 + await this.$refs["formRef"].validate(); this.formLoading = true; try { - const that = this; - let data = this.formData; - - this.getRef("formRef").validate(valid => { - if (!valid) { - return; - } - // 修改的提交 - if (data.id) { - Demo02CategoryApi.updateDemo02Category(data).then(response => { - that.$modal.msgSuccess("修改成功"); - that.dialogVisible = false; - that.$emit('success'); - }); - return; - } - // 添加的提交 - Demo02CategoryApi.createDemo02Category(data).then(response => { - that.$modal.msgSuccess("新增成功"); - that.dialogVisible = false; - that.$emit('success'); - }); - }); + const data = this.formData; + // 修改的提交 + if (data.id) { + await Demo02CategoryApi.updateDemo02Category(data); + this.$modal.msgSuccess("修改成功"); + this.dialogVisible = false; + this.$emit('success'); + return; + } + // 添加的提交 + await Demo02CategoryApi.createDemo02Category(data); + this.$modal.msgSuccess("新增成功"); + this.dialogVisible = false; + this.$emit('success'); }finally { - this.formLoading = false + this.formLoading = false; } }, - getRef(refName){ // TODO puhui999: 获得表单 ref,提取出来的目的呢是解决 $ 在 if 中 end闭合不了的问题,代码生成后可删除此方法 - return this.$refs[refName] - }, /** 获得示例分类树 */ - getDemo02CategoryTree() { - const that = this; - that.demo02CategoryTree = []; - Demo02CategoryApi.getDemo02CategoryList().then(res=>{ - const root = { id: 0, name: '顶级示例分类', children: [] }; - root.children = this.handleTree(res.data, 'id', 'parentId') - that.demo02CategoryTree.push(root) - }); + async getDemo02CategoryTree() { + this.demo02CategoryTree = []; + const res = await Demo02CategoryApi.getDemo02CategoryList(); + const root = { id: 0, name: '顶级示例分类', children: [] }; + root.children = this.handleTree(res.data, 'id', 'parentId') + this.demo02CategoryTree.push(root) }, /** 转换示例分类数据结构 */ normalizer(node) { @@ -139,7 +124,7 @@ export default { parentId: undefined, }; this.resetForm("formRef"); - }, + } } }; diff --git a/src/views/infra/demo/demo02/index.vue b/src/views/infra/demo/demo02/index.vue index 61bca72d129a9f3edddd1a701f727edfb35a1884..d7a09e289f06d14094f67b4c87d1529cdab99917 100644 --- a/src/views/infra/demo/demo02/index.vue +++ b/src/views/infra/demo/demo02/index.vue @@ -38,14 +38,14 @@ @@ -64,7 +64,6 @@ - @@ -86,7 +85,6 @@ export default { exportLoading: false, // 显示搜索条件 showSearch: true, - // 总条数 // 示例分类列表 list: [], // 是否展开,默认全部展开 @@ -100,7 +98,7 @@ export default { name: null, parentId: null, createTime: [], - } + }, }; }, created() { @@ -108,12 +106,11 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - Demo02CategoryApi.getDemo02CategoryList(this.queryParams).then(response => { - this.list = this.handleTree(response.data, 'id', 'parentId'); - }) + const res = await Demo02CategoryApi.getDemo02CategoryList(this.queryParams); + this.list = this.handleTree(res.data, 'id', 'parentId'); } finally { this.loading = false; } @@ -130,34 +127,28 @@ export default { }, /** 添加/修改操作 */ openForm(id) { - this.$refs["formRef"].open(id) + this.$refs["formRef"].open(id); }, /** 删除按钮操作 */ - handleDelete(row) { - const that = this; + async handleDelete(row) { + const id = row.id; + await this.$modal.confirm('是否确认删除示例分类编号为"' + id + '"的数据项?') try { - const id = row.id; - this.$modal.confirm('是否确认删除示例分类编号为"' + id + '"的数据项?').then(()=>{ - return Demo02CategoryApi.deleteDemo02Category(id); - }).then(() => { - that.getList(); - that.$modal.msgSuccess("删除成功"); - }).catch(() => {}); + await Demo02CategoryApi.deleteDemo02Category(id); + 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 Demo02CategoryApi.exportDemo02CategoryExcel(params); - }).then(response => { - that.$download.excel(response, '示例分类.xls'); - }); + this.exportLoading = true; + const res = await Demo02CategoryApi.exportDemo02CategoryExcel(this.queryParams); + this.$download.excel(res.data, '示例分类.xls'); } catch { } finally { - that.exportLoading = false; + this.exportLoading = false; } }, /** 展开/折叠操作 */ diff --git a/src/views/infra/demo/demo03/erp/Demo03StudentForm.vue b/src/views/infra/demo/demo03/erp/Demo03StudentForm.vue index be2638d7498516e3d3f2a22b4466d73cbba4ed5e..9d27284e211211a323883297f3cf781d55de95af 100644 --- a/src/views/infra/demo/demo03/erp/Demo03StudentForm.vue +++ b/src/views/infra/demo/demo03/erp/Demo03StudentForm.vue @@ -63,18 +63,16 @@ export default { }, methods: { /** 打开弹窗 */ - open(id) { + async open(id) { this.dialogVisible = true; this.reset(); - const that = this; // 修改时,设置数据 if (id) { this.formLoading = true; try { - Demo03StudentApi.getDemo03Student(id).then(res=>{ - that.formData = res.data; - that.title = "修改学生"; - }) + const res = await Demo03StudentApi.getDemo03Student(id); + this.formData = res.data; + this.title = "修改学生"; } finally { this.formLoading = false; } @@ -82,42 +80,29 @@ export default { 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) { - Demo03StudentApi.updateDemo03Student(data).then(response => { - that.$modal.msgSuccess("修改成功"); - that.dialogVisible = false; - that.$emit('success'); - }); + await Demo03StudentApi.updateDemo03Student(data); + this.$modal.msgSuccess("修改成功"); + this.dialogVisible = false; + this.$emit('success'); return; } // 添加的提交 - Demo03StudentApi.createDemo03Student(data).then(response => { - that.$modal.msgSuccess("新增成功"); - that.dialogVisible = false; - that.$emit('success'); - }); + await Demo03StudentApi.createDemo03Student(data); + this.$modal.msgSuccess("新增成功"); + this.dialogVisible = false; + this.$emit('success'); }finally { this.formLoading = false; } }, - getRef(refName){ // TODO puhui999: 获得表单 ref,提取出来的目的呢是解决 $ 在 if 中 end闭合不了的问题,代码生成后可删除此方法 - return this.$refs[refName] - }, /** 表单重置 */ reset() { this.formData = { @@ -128,7 +113,7 @@ export default { description: undefined, }; this.resetForm("formRef"); - }, + } } }; diff --git a/src/views/infra/demo/demo03/erp/components/Demo03CourseForm.vue b/src/views/infra/demo/demo03/erp/components/Demo03CourseForm.vue index 4cefc1647eb6be1c4b5094c567729ec3c9e3d872..a3f6943586853eda00190bf9d7b5d078686f4fbf 100644 --- a/src/views/infra/demo/demo03/erp/components/Demo03CourseForm.vue +++ b/src/views/infra/demo/demo03/erp/components/Demo03CourseForm.vue @@ -49,19 +49,17 @@ export default { }, 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 { - Demo03StudentApi.getDemo03Course(id).then(res=>{ - that.formData = res.data; - that.dialogTitle = "修改学生课程"; - }) + const res = await Demo03StudentApi.getDemo03Course(id); + this.formData = res.data; + this.dialogTitle = "修改学生课程"; } finally { this.formLoading = false; } @@ -69,32 +67,26 @@ export default { 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; - } - // 修改的提交 - if (data.id) { - Demo03StudentApi.updateDemo03Course(data).then(response => { - this.$modal.msgSuccess("修改成功"); - this.dialogVisible = false; - this.$emit('success'); - }); - return; - } - // 添加的提交 - Demo03StudentApi.createDemo03Course(data).then(response => { - this.$modal.msgSuccess("新增成功"); - this.dialogVisible = false; - this.$emit('success'); - }); - }); + const data = this.formData; + // 修改的提交 + if (data.id) { + await Demo03StudentApi.updateDemo03Course(data); + this.$modal.msgSuccess("修改成功"); + this.dialogVisible = false; + this.$emit('success'); + return; + } + // 添加的提交 + await Demo03StudentApi.createDemo03Course(data); + this.$modal.msgSuccess("新增成功"); + this.dialogVisible = false; + this.$emit('success'); }finally { - this.formLoading = false + this.formLoading = false; } }, /** 表单重置 */ diff --git a/src/views/infra/demo/demo03/erp/components/Demo03CourseList.vue b/src/views/infra/demo/demo03/erp/components/Demo03CourseList.vue index 81c9ff674862c9113c356f59b4494132d274a382..1c31ad4d557db2bf66f30e8a4868ac4cddccf0e5 100644 --- a/src/views/infra/demo/demo03/erp/components/Demo03CourseList.vue +++ b/src/views/infra/demo/demo03/erp/components/Demo03CourseList.vue @@ -73,14 +73,12 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - const that = this; - Demo03StudentApi.getDemo03CoursePage(this.queryParams).then(response => { - that.list = response.data.list; - that.total = response.data.total; - }); + const res = await Demo03StudentApi.getDemo03CoursePage(this.queryParams); + this.list = res.data.list; + this.total = res.data.total; } finally { this.loading = false; } @@ -93,22 +91,19 @@ export default { /** 添加/修改操作 */ openForm(id) { if (!this.studentId) { - that.$modal.msgError('请选择一个学生'); + this.$modal.msgError('请选择一个学生'); return; } this.$refs["formRef"].open(id, this.studentId); }, /** 删除按钮操作 */ - handleDelete(row) { - const that = this; + async handleDelete(row) { + const id = row.id; + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?'); try { - const id = row.id; - this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ - return Demo03StudentApi.deleteDemo03Course(id); - }).then(() => { - that.getList(); - that.$modal.msgSuccess("删除成功"); - }).catch(() => {}); + await Demo03StudentApi.deleteDemo03Course(id); + await this.getList(); + this.$modal.msgSuccess("删除成功"); } catch {} }, } diff --git a/src/views/infra/demo/demo03/erp/components/Demo03GradeForm.vue b/src/views/infra/demo/demo03/erp/components/Demo03GradeForm.vue index f77fa58b42cb9ef06a132ea8833b793171191106..a733de5fdd8b2b18b7726d54e8033ff20cb5e103 100644 --- a/src/views/infra/demo/demo03/erp/components/Demo03GradeForm.vue +++ b/src/views/infra/demo/demo03/erp/components/Demo03GradeForm.vue @@ -49,19 +49,17 @@ export default { }, 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 { - Demo03StudentApi.getDemo03Grade(id).then(res=>{ - that.formData = res.data; - that.dialogTitle = "修改学生班级"; - }) + const res = await Demo03StudentApi.getDemo03Grade(id); + this.formData = res.data; + this.dialogTitle = "修改学生班级"; } finally { this.formLoading = false; } @@ -69,32 +67,26 @@ export default { 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; - } - // 修改的提交 - if (data.id) { - Demo03StudentApi.updateDemo03Grade(data).then(response => { - this.$modal.msgSuccess("修改成功"); - this.dialogVisible = false; - this.$emit('success'); - }); - return; - } - // 添加的提交 - Demo03StudentApi.createDemo03Grade(data).then(response => { - this.$modal.msgSuccess("新增成功"); - this.dialogVisible = false; - this.$emit('success'); - }); - }); + const data = this.formData; + // 修改的提交 + if (data.id) { + await Demo03StudentApi.updateDemo03Grade(data); + this.$modal.msgSuccess("修改成功"); + this.dialogVisible = false; + this.$emit('success'); + return; + } + // 添加的提交 + await Demo03StudentApi.createDemo03Grade(data); + this.$modal.msgSuccess("新增成功"); + this.dialogVisible = false; + this.$emit('success'); }finally { - this.formLoading = false + this.formLoading = false; } }, /** 表单重置 */ diff --git a/src/views/infra/demo/demo03/erp/components/Demo03GradeList.vue b/src/views/infra/demo/demo03/erp/components/Demo03GradeList.vue index 298ac2610298307d096a171437c1c6d290257171..96b31bdb3678d15da024e294a353c96bef3ffdd9 100644 --- a/src/views/infra/demo/demo03/erp/components/Demo03GradeList.vue +++ b/src/views/infra/demo/demo03/erp/components/Demo03GradeList.vue @@ -73,14 +73,12 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - const that = this; - Demo03StudentApi.getDemo03GradePage(this.queryParams).then(response => { - that.list = response.data.list; - that.total = response.data.total; - }); + const res = await Demo03StudentApi.getDemo03GradePage(this.queryParams); + this.list = res.data.list; + this.total = res.data.total; } finally { this.loading = false; } @@ -93,22 +91,19 @@ export default { /** 添加/修改操作 */ openForm(id) { if (!this.studentId) { - that.$modal.msgError('请选择一个学生'); + this.$modal.msgError('请选择一个学生'); return; } this.$refs["formRef"].open(id, this.studentId); }, /** 删除按钮操作 */ - handleDelete(row) { - const that = this; + async handleDelete(row) { + const id = row.id; + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?'); try { - const id = row.id; - this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ - return Demo03StudentApi.deleteDemo03Grade(id); - }).then(() => { - that.getList(); - that.$modal.msgSuccess("删除成功"); - }).catch(() => {}); + await Demo03StudentApi.deleteDemo03Grade(id); + await this.getList(); + this.$modal.msgSuccess("删除成功"); } catch {} }, } diff --git a/src/views/infra/demo/demo03/erp/index.vue b/src/views/infra/demo/demo03/erp/index.vue index 8731ff3c32348643a5d57a171f29414144fdb92a..14b1261e8df4a43268d05ac37211f56dd7ea8fc1 100644 --- a/src/views/infra/demo/demo03/erp/index.vue +++ b/src/views/infra/demo/demo03/erp/index.vue @@ -13,14 +13,11 @@ - + - + 搜索 @@ -32,31 +29,28 @@ 新增 - + v-hasPermi="['infra:demo03-student:create']">新增 - 导出 - + 导出 - - + + - + @@ -64,7 +58,7 @@ {{ parseTime(scope.row.birthday) }} - + {{ parseTime(scope.row.createTime) }} @@ -73,11 +67,9 @@ 修改 - + v-hasPermi="['infra:demo03-student:update']">修改 删除 - + v-hasPermi="['infra:demo03-student:delete']">删除 @@ -85,14 +77,14 @@ - - + + - + - + @@ -103,7 +95,6 @@ import * as Demo03StudentApi from '@/api/infra/demo03-erp'; import Demo03StudentForm from './Demo03StudentForm.vue'; import Demo03CourseList from './components/Demo03CourseList.vue' import Demo03GradeList from './components/Demo03GradeList.vue' - export default { name: "Demo03Student", components: { @@ -148,13 +139,12 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - Demo03StudentApi.getDemo03StudentPage(this.queryParams).then(response => { - this.list = response.data.list; - this.total = response.data.total; - }); + const res = await Demo03StudentApi.getDemo03StudentPage(this.queryParams); + this.list = res.data.list; + this.total = res.data.total; } finally { this.loading = false; } @@ -174,33 +164,25 @@ export default { this.$refs["formRef"].open(id); }, /** 删除按钮操作 */ - handleDelete(row) { - const that = this; + async handleDelete(row) { + const id = row.id; + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?') try { - const id = row.id; - this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(() => { - return Demo03StudentApi.deleteDemo03Student(id); - }).then(() => { - that.getList(); - that.$modal.msgSuccess("删除成功"); - }).catch(() => { - }); - } catch { - } + await Demo03StudentApi.deleteDemo03Student(id); + 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 Demo03StudentApi.exportDemo03StudentExcel(params); - }).then(response => { - that.$download.excel(response, '学生.xls'); - }); + this.exportLoading = true; + const res = await Demo03StudentApi.exportDemo03StudentExcel(this.queryParams); + this.$download.excel(res.data, '学生.xls'); } catch { } finally { - that.exportLoading = false; + this.exportLoading = false; } }, /** 选中行操作 */ diff --git a/src/views/infra/demo/demo03/inner/Demo03StudentForm.vue b/src/views/infra/demo/demo03/inner/Demo03StudentForm.vue index bb8d4a8a21ca7fdc72c86b48b1120e27a175a04b..0ca01b469470985a0665b5ad1102e5a32626f70c 100644 --- a/src/views/infra/demo/demo03/inner/Demo03StudentForm.vue +++ b/src/views/infra/demo/demo03/inner/Demo03StudentForm.vue @@ -78,18 +78,16 @@ export default { }, methods: { /** 打开弹窗 */ - open(id) { + async open(id) { this.dialogVisible = true; this.reset(); - const that = this; // 修改时,设置数据 if (id) { this.formLoading = true; try { - Demo03StudentApi.getDemo03Student(id).then(res=>{ - that.formData = res.data; - that.title = "修改学生"; - }) + const res = await Demo03StudentApi.getDemo03Student(id); + this.formData = res.data; + this.title = "修改学生"; } finally { this.formLoading = false; } @@ -97,84 +95,45 @@ export default { this.title = "新增学生"; }, /** 提交按钮 */ - submitForm() { + async submitForm() { + // 校验主表 + await this.$refs["formRef"].validate(); + // 校验子表 + try { + await this.$refs['demo03CourseFormRef'].validate(); + } catch (e) { + this.subTabsName = 'demo03Course'; + return; + } + try { + await this.$refs['demo03GradeFormRef'].validate(); + } catch (e) { + this.subTabsName = 'demo03Grade'; + return; + } this.formLoading = true; try { - const that = this; - let data = this.formData; - let validate = false; - // 校验主表 - this.getRef("formRef").validate(valid => { - validate = valid; - }); - // 校验子表 - this.validateSubFrom01().then(() => { - // 全部校验通过-拼接子表的数据 - // 拼接子表的数据 - data.demo03Courses = that.getRef('demo03CourseFormRef').getData(); - data.demo03Grade = that.getRef('demo03GradeFormRef').getData(); - }).catch((err) => { - validate = false; - that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单 - }) - // 所有表单校验通过后方可提交 - if (!validate) { - return; - } + const data = this.formData; + // 拼接子表的数据 + data.demo03Courses = this.$refs['demo03CourseFormRef'].getData(); + data.demo03Grade = this.$refs['demo03GradeFormRef'].getData(); // 修改的提交 if (data.id) { - Demo03StudentApi.updateDemo03Student(data).then(response => { - that.$modal.msgSuccess("修改成功"); - that.dialogVisible = false; - that.$emit('success'); - }); + await Demo03StudentApi.updateDemo03Student(data); + this.$modal.msgSuccess("修改成功"); + this.dialogVisible = false; + this.$emit('success'); return; } // 添加的提交 - Demo03StudentApi.createDemo03Student(data).then(response => { - that.$modal.msgSuccess("新增成功"); - that.dialogVisible = false; - that.$emit('success'); - }); + await Demo03StudentApi.createDemo03Student(data); + this.$modal.msgSuccess("新增成功"); + this.dialogVisible = false; + this.$emit('success'); }finally { this.formLoading = false; } }, - getRef(refName){ // TODO puhui999: 获得表单 ref,提取出来的目的呢是解决 $ 在 if 中 end闭合不了的问题,代码生成后可删除此方法 - return this.$refs[refName]; - }, - /** 校验子表单 */ - validateSubFrom(item) { - return new Promise((resolve, reject) => { - this.getRef(item).validate() - .then(() => { - resolve(); - }) - .catch(() => { - reject(item); - }) - }) - }, - /** 校验所有子表单 */ - validateSubFrom01() { - // 需要校验的表单 ref - const validFormRefArr = [ - "demo03CourseFormRef", - "demo03GradeFormRef", - ]; - 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() { this.formData = { @@ -185,7 +144,7 @@ export default { description: undefined, }; this.resetForm("formRef"); - }, + } } }; diff --git a/src/views/infra/demo/demo03/inner/components/Demo03CourseForm.vue b/src/views/infra/demo/demo03/inner/components/Demo03CourseForm.vue index 5c5fe9f02129a1c242ee4abe26b213cb91cb9fdf..11544d5e8638e9bf95b23059718e3c9bcb6e70ac 100644 --- a/src/views/infra/demo/demo03/inner/components/Demo03CourseForm.vue +++ b/src/views/infra/demo/demo03/inner/components/Demo03CourseForm.vue @@ -1,12 +1,12 @@ @@ -72,7 +72,7 @@ export default { try { this.formLoading = true; const that = this; - Demo03StudentApi.getDemo03CourseListByStudentId(val).then(res=>{ + Demo03StudentApi.getDemo03CourseListByStudentId(val).then(function (res){ that.formData = res.data; }) } finally { @@ -91,20 +91,20 @@ export default { name: undefined, score: 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; } } }; diff --git a/src/views/infra/demo/demo03/inner/components/Demo03CourseList.vue b/src/views/infra/demo/demo03/inner/components/Demo03CourseList.vue index 504bad93951825891b4a53e0a09fdb1bc750cf7a..745a88cc71ae88c7c5ffd0fa27ce797513ba84e9 100644 --- a/src/views/infra/demo/demo03/inner/components/Demo03CourseList.vue +++ b/src/views/infra/demo/demo03/inner/components/Demo03CourseList.vue @@ -52,13 +52,11 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - const that = this; - Demo03StudentApi.getDemo03CourseListByStudentId(this.studentId).then(response=>{ - that.list = response.data; - }) + const res = await Demo03StudentApi.getDemo03CourseListByStudentId(this.studentId); + this.list = res.data; } finally { this.loading = false; } diff --git a/src/views/infra/demo/demo03/inner/components/Demo03GradeForm.vue b/src/views/infra/demo/demo03/inner/components/Demo03GradeForm.vue index 3a663f8529e72fe6e162df3db8a27181e0245550..4300f0808c825ec2a25b5b0c9d4eb147b484a592 100644 --- a/src/views/infra/demo/demo03/inner/components/Demo03GradeForm.vue +++ b/src/views/infra/demo/demo03/inner/components/Demo03GradeForm.vue @@ -1,11 +1,11 @@ @@ -57,7 +57,7 @@ export default { try { this.formLoading = true; const that = this; - Demo03StudentApi.getDemo03GradeByStudentId(val).then(res=>{ + Demo03StudentApi.getDemo03GradeByStudentId(val).then(function (res){ const data = res.data; if (!data) { return @@ -74,11 +74,11 @@ export default { methods: { /** 表单校验 */ validate(){ - return this.$refs["formRef"].validate() + return this.$refs["formRef"].validate(); }, /** 表单值 */ getData(){ - return this.formData + return this.formData; } } }; diff --git a/src/views/infra/demo/demo03/inner/components/Demo03GradeList.vue b/src/views/infra/demo/demo03/inner/components/Demo03GradeList.vue index e2adf2ec9eca71d2beb00d1faea74511910f9118..6e66f2e2e4e11d3edac97e5b38702f042a36f0c2 100644 --- a/src/views/infra/demo/demo03/inner/components/Demo03GradeList.vue +++ b/src/views/infra/demo/demo03/inner/components/Demo03GradeList.vue @@ -52,17 +52,15 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - const that = this; - Demo03StudentApi.getDemo03GradeByStudentId(this.studentId).then(response=>{ - const data = response.data; - if (!data) { - return - } - that.list.push(data) - }) + const res = await Demo03StudentApi.getDemo03GradeByStudentId(this.studentId); + const data = res.data; + if (!data) { + return; + } + this.list.push(data); } finally { this.loading = false; } diff --git a/src/views/infra/demo/demo03/inner/index.vue b/src/views/infra/demo/demo03/inner/index.vue index f00733ac8070259e126d05e19212c9cb1a3ff7a1..8ffd450a2afeb676342b39fc79e82a1a2a949d99 100644 --- a/src/views/infra/demo/demo03/inner/index.vue +++ b/src/views/infra/demo/demo03/inner/index.vue @@ -39,7 +39,6 @@ - @@ -135,13 +134,12 @@ export default { }, methods: { /** 查询列表 */ - getList() { + async getList() { try { this.loading = true; - Demo03StudentApi.getDemo03StudentPage(this.queryParams).then(response => { - this.list = response.data.list; - this.total = response.data.total; - }); + const res = await Demo03StudentApi.getDemo03StudentPage(this.queryParams); + this.list = res.data.list; + this.total = res.data.total; } finally { this.loading = false; } @@ -158,35 +156,28 @@ export default { }, /** 添加/修改操作 */ openForm(id) { - // TODO @puhui999:$refs 在 vm 里面怎么写,可以看看这里噢。 this.$refs["formRef"].open(id); }, /** 删除按钮操作 */ - handleDelete(row) { - const that = this; + async handleDelete(row) { + const id = row.id; + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?') try { - const id = row.id; - this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?').then(()=>{ - return Demo03StudentApi.deleteDemo03Student(id); - }).then(() => { - that.getList(); - that.$modal.msgSuccess("删除成功"); - }).catch(() => {}); + await Demo03StudentApi.deleteDemo03Student(id); + 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 Demo03StudentApi.exportDemo03StudentExcel(params); - }).then(response => { - that.$download.excel(response, '学生.xls'); - }); + this.exportLoading = true; + const res = await Demo03StudentApi.exportDemo03StudentExcel(this.queryParams); + this.$download.excel(res.data, '学生.xls'); } catch { } finally { - that.exportLoading = false; + this.exportLoading = false; } }, } diff --git a/src/views/infra/demo/demo03/normal/Demo03StudentForm.vue b/src/views/infra/demo/demo03/normal/Demo03StudentForm.vue index 6d0ca45b2dcfb7984ea760b092bef6ebc632e048..e0092355199ea808f47b6dba2749eb393ea5ad18 100644 --- a/src/views/infra/demo/demo03/normal/Demo03StudentForm.vue +++ b/src/views/infra/demo/demo03/normal/Demo03StudentForm.vue @@ -78,18 +78,16 @@ export default { }, methods: { /** 打开弹窗 */ - open(id) { + async open(id) { this.dialogVisible = true; this.reset(); - const that = this; // 修改时,设置数据 if (id) { this.formLoading = true; try { - Demo03StudentApi.getDemo03Student(id).then(res=>{ - that.formData = res.data; - that.title = "修改学生"; - }) + const res = await Demo03StudentApi.getDemo03Student(id); + this.formData = res.data; + this.title = "修改学生"; } finally { this.formLoading = false; } @@ -97,85 +95,45 @@ export default { this.title = "新增学生"; }, /** 提交按钮 */ - submitForm() { + async submitForm() { + // 校验主表 + await this.$refs["formRef"].validate(); + // 校验子表 + try { + await this.$refs['demo03CourseFormRef'].validate(); + } catch (e) { + this.subTabsName = 'demo03Course'; + return; + } + try { + await this.$refs['demo03GradeFormRef'].validate(); + } catch (e) { + this.subTabsName = 'demo03Grade'; + return; + } this.formLoading = true; try { - const that = this; - let data = this.formData; - let validate = false; - // TODO @puhui999:要不要改成 await 风格; - // 校验主表 - this.getRef("formRef").validate(valid => { - validate = valid; - }); - // 校验子表 - this.validateSubFrom01().then(() => { - // 全部校验通过-拼接子表的数据 - // 拼接子表的数据 - data.demo03Courses = that.getRef('demo03CourseFormRef').getData(); - data.demo03Grade = that.getRef('demo03GradeFormRef').getData(); - }).catch((err) => { - validate = false; - that.subTabsName = err.replace("FormRef", ""); // 定位到没有校验通过的子表单 - }) - // 所有表单校验通过后方可提交 - if (!validate) { - return; - } + const data = this.formData; + // 拼接子表的数据 + data.demo03Courses = this.$refs['demo03CourseFormRef'].getData(); + data.demo03Grade = this.$refs['demo03GradeFormRef'].getData(); // 修改的提交 if (data.id) { - Demo03StudentApi.updateDemo03Student(data).then(response => { - that.$modal.msgSuccess("修改成功"); - that.dialogVisible = false; - that.$emit('success'); - }); + await Demo03StudentApi.updateDemo03Student(data); + this.$modal.msgSuccess("修改成功"); + this.dialogVisible = false; + this.$emit('success'); return; } // 添加的提交 - Demo03StudentApi.createDemo03Student(data).then(response => { - that.$modal.msgSuccess("新增成功"); - that.dialogVisible = false; - that.$emit('success'); - }); + await Demo03StudentApi.createDemo03Student(data); + this.$modal.msgSuccess("新增成功"); + this.dialogVisible = false; + this.$emit('success'); }finally { this.formLoading = false; } }, - getRef(refName){ // TODO puhui999: 获得表单 ref,提取出来的目的呢是解决 $ 在 if 中 end闭合不了的问题,代码生成后可删除此方法 - return this.$refs[refName]; - }, - /** 校验子表单 */ - validateSubFrom(item) { - return new Promise((resolve, reject) => { - this.getRef(item).validate() - .then(() => { - resolve(); - }) - .catch(() => { - reject(item); - }) - }) - }, - /** 校验所有子表单 */ - validateSubFrom01() { - // 需要校验的表单 ref - const validFormRefArr = [ - "demo03CourseFormRef", - "demo03GradeFormRef", - ]; - 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() { this.formData = { @@ -186,7 +144,7 @@ export default { description: undefined, }; this.resetForm("formRef"); - }, + } } }; diff --git a/src/views/infra/demo/demo03/normal/components/Demo03CourseForm.vue b/src/views/infra/demo/demo03/normal/components/Demo03CourseForm.vue index f5b6d3726bca7cb7b1690d1605642e508e803f86..efa53d0fecb359a18cf019b023ebca7c322624fd 100644 --- a/src/views/infra/demo/demo03/normal/components/Demo03CourseForm.vue +++ b/src/views/infra/demo/demo03/normal/components/Demo03CourseForm.vue @@ -1,26 +1,26 @@ - + - + - + @@ -31,7 +31,6 @@ - + 添加学生课程 @@ -40,11 +39,11 @@