diff --git a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs index f554632..91a2299 100644 --- a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs @@ -261,7 +261,7 @@ namespace ZR.Admin.WebApi.Controllers FileHelper.ZipGenCode(dto); //HttpContext.Response.Headers.Add("Content-disposition", $"attachment; filename={zipFileName}"); - return SUCCESS(new { zipPath = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName }); + return SUCCESS(new { path = "/Generatecode/" + dto.ZipFileName, fileName = dto.ZipFileName }); } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs index 86e178b..9ec9fd1 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysDictDataController.cs @@ -3,9 +3,13 @@ using Infrastructure.Enums; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; +using System.Collections.Generic; +using System.Linq; using ZR.Admin.WebApi.Filters; +using ZR.Common; using ZR.Model; using ZR.Model.System; +using ZR.Model.System.Dto; using ZR.Model.Vo; using ZR.Service.System.IService; @@ -53,6 +57,30 @@ namespace ZR.Admin.WebApi.Controllers.System { return SUCCESS(SysDictDataService.SelectDictDataByType(dictType)); } + /// + /// 根据字典类型查询字典数据信息 + /// + /// + /// + [AllowAnonymous] + [HttpPost("types")] + public IActionResult DictTypes([FromBody] List dto) + { + var list = SysDictDataService.SelectDictDataByTypes(dto.Select(f => f.DictType).ToArray()); + List dataVos = new(); + + foreach (var dic in dto) + { + SysdictDataDto vo = new() + { + DictType = dic.DictType, + ColumnName = dic.ColumnName, + List = list.FindAll(f => f.DictType == dic.DictType) + }; + dataVos.Add(vo); + } + return SUCCESS(dataVos); + } /// /// 查询字典数据详细 diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt index bcdd903..d51dee7 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt @@ -148,12 +148,21 @@ $end // 列表数据查询 this.getList(); + $set(index = 0) + var dictParams = [ $foreach(item in genTable.Columns) $if((item.HtmlType == "radio" || item.HtmlType == "select" || item.HtmlType == "checkbox") && item.DictType != "") - this.getDicts("${item.DictType}").then((response) => { - this.${item.ColumnName}Options = response.data; - }) + { dictType: "${item.DictType}", columnName: "${item.ColumnName}Options" }, +$set(index = index + 1) $end +$end + ]; +$if(index > 0) + this.getMoreDicts(dictParams).then((response) => { + response.data.forEach((element) => { + this[element.columnName] = element.list; + }); + }); $end }, methods: { @@ -165,7 +174,6 @@ $if(item.HtmlType == "datetime" && item.IsQuery == true) this.queryParams["end${item.CsharpField}"] = this.addDateRange2(this.dateRange${item.CsharpField}, 1); $end $end - console.log(JSON.stringify(this.queryParams)); this.loading = true; list${genTable.BusinessName}(this.queryParams).then(res => { if (res.code == 200) { diff --git a/ZR.Model/System/Dto/SysdictDataDto.cs b/ZR.Model/System/Dto/SysdictDataDto.cs new file mode 100644 index 0000000..e17cf2d --- /dev/null +++ b/ZR.Model/System/Dto/SysdictDataDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ZR.Model.System.Dto +{ + public class SysdictDataDto + { + public string DictType { get; set; } + public string ColumnName { get; set; } + public List List { get; set; } + } +} diff --git a/ZR.Repository/System/SysDictDataRepository.cs b/ZR.Repository/System/SysDictDataRepository.cs index 9012ec5..294e655 100644 --- a/ZR.Repository/System/SysDictDataRepository.cs +++ b/ZR.Repository/System/SysDictDataRepository.cs @@ -3,6 +3,7 @@ using Infrastructure.Model; using SqlSugar; using System; using System.Collections.Generic; +using System.Linq; using ZR.Model; using ZR.Model.System; @@ -41,6 +42,17 @@ namespace ZR.Repository.System .ToList(); } + /// + /// 根据字典类型查询 + /// + /// + /// + public List SelectDictDataByTypes(string[] dictTypes) + { + return Context.Queryable().Where(f => f.Status == "0" && dictTypes.Contains(f.DictType)) + .OrderBy(it => it.DictSort) + .ToList(); + } /// /// 新增保存字典数据信息 /// diff --git a/ZR.Service/System/IService/ISysDictDataService.cs b/ZR.Service/System/IService/ISysDictDataService.cs index 8380ffa..96c81f3 100644 --- a/ZR.Service/System/IService/ISysDictDataService.cs +++ b/ZR.Service/System/IService/ISysDictDataService.cs @@ -11,6 +11,7 @@ namespace ZR.Service.System.IService { public PagedInfo SelectDictDataList(SysDictData dictData, PagerInfo pagerInfo); public List SelectDictDataByType(string dictType); + public List SelectDictDataByTypes(string[] dictTypes); public SysDictData SelectDictDataById(long dictCode); public long InsertDictData(SysDictData dict); public long UpdateDictData(SysDictData dict); diff --git a/ZR.Service/System/SysDictDataService.cs b/ZR.Service/System/SysDictDataService.cs index 7a13527..bbfdae4 100644 --- a/ZR.Service/System/SysDictDataService.cs +++ b/ZR.Service/System/SysDictDataService.cs @@ -49,7 +49,16 @@ namespace ZR.Service.System } return list; } - + public List SelectDictDataByTypes(string[] dictTypes) + { + string CK = $"SelectDictDataByTypes_{dictTypes}"; + if (CacheHelper.GetCache(CK) is not List list) + { + list = SysDictDataRepository.SelectDictDataByTypes(dictTypes); + CacheHelper.SetCache(CK, list, 30); + } + return list; + } /// /// 根据字典数据ID查询信息 /// diff --git a/ZR.Vue/src/api/system/dict/data.js b/ZR.Vue/src/api/system/dict/data.js index 8846862..fb9dfc0 100644 --- a/ZR.Vue/src/api/system/dict/data.js +++ b/ZR.Vue/src/api/system/dict/data.js @@ -25,6 +25,15 @@ export function getDicts(dictType) { }) } +// 根据多个字典类型查询字典数据信息 +export function getMoreDicts(dictType) { + return request({ + url: '/system/dict/data/types', + data: dictType , + method: 'post' + }) +} + // 新增字典数据 export function addData(data) { return request({ @@ -58,4 +67,4 @@ export function exportData(query) { method: 'get', params: query }) -} +} \ No newline at end of file diff --git a/ZR.Vue/src/main.js b/ZR.Vue/src/main.js index 3720641..4816400 100644 --- a/ZR.Vue/src/main.js +++ b/ZR.Vue/src/main.js @@ -14,7 +14,7 @@ import permission from './directive/permission' import './assets/icons' // icon import './permission' // permission control -import { getDicts } from "@/api/system/dict/data"; +import { getDicts, getMoreDicts} from "@/api/system/dict/data"; import { getConfigKey } from "@/api/system/config"; import { parseTime, resetForm, addDateRange, addDateRange2, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi"; //分页组件 @@ -34,6 +34,7 @@ import UploadFile from '@/components/FileUpload/index'; // 全局方法挂载 Vue.prototype.getDicts = getDicts +Vue.prototype.getMoreDicts = getMoreDicts Vue.prototype.getConfigKey = getConfigKey Vue.prototype.parseTime = parseTime Vue.prototype.resetForm = resetForm @@ -44,15 +45,15 @@ Vue.prototype.selectDictLabels = selectDictLabels Vue.prototype.download = download Vue.prototype.handleTree = handleTree -Vue.prototype.msgSuccess = function(msg) { +Vue.prototype.msgSuccess = function (msg) { this.$message({ showClose: true, message: msg, type: "success" }); } -Vue.prototype.msgError = function(msg) { +Vue.prototype.msgError = function (msg) { this.$message({ showClose: true, message: msg, type: "error" }); } -Vue.prototype.msgInfo = function(msg) { +Vue.prototype.msgInfo = function (msg) { this.$message.info(msg); } diff --git a/ZR.Vue/src/utils/request.js b/ZR.Vue/src/utils/request.js index 4336d66..ce72dd5 100644 --- a/ZR.Vue/src/utils/request.js +++ b/ZR.Vue/src/utils/request.js @@ -1,13 +1,10 @@ import axios from 'axios' -import { - MessageBox, - Message -} from 'element-ui' +import { MessageBox, Message } from 'element-ui' import store from '@/store' -import { - getToken -} from '@/utils/auth' +import { getToken } from '@/utils/auth' +// import { blobValidate } from "@/utils/ruoyi"; // import errorCode from '@/utils/errorCode' +// import { saveAs } from 'file-saver' // 解决后端跨域获取不到cookie问题 axios.defaults.withCredentials = true @@ -44,7 +41,10 @@ service.interceptors.response.use(res => { } // 未设置状态码则默认成功状态 const { code, msg } = res.data; - + // 二进制数据则直接返回 + if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') { + return res.data + } if (code == 401) { MessageBox.confirm('登录状态已过期,请重新登录', '系统提示', { confirmButtonText: '重新登录', @@ -138,4 +138,32 @@ export function postForm(url, data, config) { }) }) } + + +// 通用下载方法 +// export function download(url, params, filename) { +// //downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", }) +// return service.post(url, params, { +// //transformRequest: [(params) => { return tansParams(params) }], +// headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, +// responseType: 'blob' +// }).then(async (data) => { +// const isLogin = await blobValidate(data); +// if (isLogin) { +// const blob = new Blob([data]) +// saveAs(blob, filename) +// } else { +// const resText = await data.text(); +// const rspObj = JSON.parse(resText); +// const errMsg = "出錯了";// errorCode[rspObj.code] || rspObj.msg || errorCode['default'] +// Message.error(errMsg); +// } +// // downloadLoadingInstance.close(); +// }).catch((r) => { +// console.error(r) +// Message.error('下载文件出现错误,请联系管理员!') +// // downloadLoadingInstance.close(); +// }) +// } + export default service \ No newline at end of file diff --git a/ZR.Vue/src/utils/ruoyi.js b/ZR.Vue/src/utils/ruoyi.js index 03e3587..567601e 100644 --- a/ZR.Vue/src/utils/ruoyi.js +++ b/ZR.Vue/src/utils/ruoyi.js @@ -69,8 +69,8 @@ export function addDateRange2(dateRange, index) { var time = undefined; if (null != dateRange && '' != dateRange) { if (dateRange.length <= 2) { - time = dateRange[index]; - } + time = dateRange[index]; + } } return time; } @@ -119,7 +119,9 @@ export function download(fileName) { // 字符串格式化(%s ) export function sprintf(str) { - var args = arguments, flag = true, i = 1; + var args = arguments, + flag = true, + i = 1; str = str.replace(/%s/g, function () { var arg = args[i++]; if (typeof arg === 'undefined') { @@ -172,3 +174,14 @@ export function handleTree(data, id, parentId, children, rootId) { }); return treeData != '' ? treeData : data; } + +// 验证是否为blob格式 +export async function blobValidate(data) { + try { + const text = await data.text(); + JSON.parse(text); + return false; + } catch (error) { + return true; + } +} \ No newline at end of file diff --git a/ZR.Vue/src/views/tool/gen/index.vue b/ZR.Vue/src/views/tool/gen/index.vue index fcf8662..9ac9f6f 100644 --- a/ZR.Vue/src/views/tool/gen/index.vue +++ b/ZR.Vue/src/views/tool/gen/index.vue @@ -229,7 +229,7 @@ export default { if (code == 200) { this.showGenerate = false; this.msgSuccess("恭喜你,代码生成完成!"); - this.download(data.fileName); + this.download(data.path); } else { this.msgError(res.msg); }