字典新增批量查询
This commit is contained in:
parent
4d373da260
commit
ac22a0e922
@ -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 });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据字典类型查询字典数据信息
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("types")]
|
||||
public IActionResult DictTypes([FromBody] List<SysdictDataDto> dto)
|
||||
{
|
||||
var list = SysDictDataService.SelectDictDataByTypes(dto.Select(f => f.DictType).ToArray());
|
||||
List<SysdictDataDto> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询字典数据详细
|
||||
|
||||
@ -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) {
|
||||
|
||||
13
ZR.Model/System/Dto/SysdictDataDto.cs
Normal file
13
ZR.Model/System/Dto/SysdictDataDto.cs
Normal file
@ -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<SysDictData> List { get; set; }
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类型查询
|
||||
/// </summary>
|
||||
/// <param name="dictData"></param>
|
||||
/// <returns></returns>
|
||||
public List<SysDictData> SelectDictDataByTypes(string[] dictTypes)
|
||||
{
|
||||
return Context.Queryable<SysDictData>().Where(f => f.Status == "0" && dictTypes.Contains(f.DictType))
|
||||
.OrderBy(it => it.DictSort)
|
||||
.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增保存字典数据信息
|
||||
/// </summary>
|
||||
|
||||
@ -11,6 +11,7 @@ namespace ZR.Service.System.IService
|
||||
{
|
||||
public PagedInfo<SysDictData> SelectDictDataList(SysDictData dictData, PagerInfo pagerInfo);
|
||||
public List<SysDictData> SelectDictDataByType(string dictType);
|
||||
public List<SysDictData> SelectDictDataByTypes(string[] dictTypes);
|
||||
public SysDictData SelectDictDataById(long dictCode);
|
||||
public long InsertDictData(SysDictData dict);
|
||||
public long UpdateDictData(SysDictData dict);
|
||||
|
||||
@ -49,7 +49,16 @@ namespace ZR.Service.System
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<SysDictData> SelectDictDataByTypes(string[] dictTypes)
|
||||
{
|
||||
string CK = $"SelectDictDataByTypes_{dictTypes}";
|
||||
if (CacheHelper.GetCache(CK) is not List<SysDictData> list)
|
||||
{
|
||||
list = SysDictDataRepository.SelectDictDataByTypes(dictTypes);
|
||||
CacheHelper.SetCache(CK, list, 30);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据字典数据ID查询信息
|
||||
/// </summary>
|
||||
|
||||
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user