This commit is contained in:
dev01 2023-01-06 10:16:45 +08:00
commit 01caf2df06
8 changed files with 295 additions and 104 deletions

View File

@ -6,15 +6,18 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
namespace Backend.Controllers
{
public class VariableController : MybaseController<VariableController>
{
private readonly IBackendRepository backendRepository;
private string variableFilePath = "";
public VariableController(IBackendRepository backendRepository)
{
this.backendRepository = backendRepository;
variableFilePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img");
}
@ -119,7 +122,7 @@ namespace Backend.Controllers
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> SaveVariable(VariableInfo post)
public async Task<ApiResult<string>> SaveVariable([FromForm] VariableInfo post)
{
ApiResult<string> apiResult = new ApiResult<string>();
@ -130,6 +133,22 @@ namespace Backend.Controllers
object param = new { Id = post.id };
var variableInfo = await backendRepository.GetOneAsync<VariableInfo>("variable", sWhere, param);
Guid file_guid = Guid.Empty;
if (post.file != null)
{
file_guid = Guid.NewGuid();
var fileName = file_guid + "." + post.extName;
var fullPath = Path.Combine(variableFilePath, fileName);
if (!System.IO.Directory.Exists(variableFilePath))
System.IO.Directory.CreateDirectory(variableFilePath);
using (var stream = new FileStream(fullPath, FileMode.Create))
{
post.file.CopyTo(stream);
}
}
if (variableInfo == null)
{
@ -139,7 +158,7 @@ namespace Backend.Controllers
{
{ "@system_type", post.System_type},
{ "@system_key", post.System_key},
{ "@system_value", post.system_value},
{ "@system_value", file_guid != Guid.Empty ? file_guid.ToString() + "." + post.extName : post.system_value},
{ "@system_remark", post.system_remark},
{ "@system_priority", post.system_priority},
{ "@system_parent_id", post.system_parent_id},
@ -156,7 +175,7 @@ namespace Backend.Controllers
{
{ "@system_type", post.System_type},
{ "@system_key", post.System_key},
{ "@system_value", post.system_value},
{ "@system_value", file_guid != Guid.Empty ? file_guid.ToString() + "." + post.extName : post.system_value},
{ "@system_remark", post.system_remark},
{ "@system_priority", post.system_priority},
{ "@system_parent_id", post.system_parent_id},

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -67,6 +68,8 @@ namespace Backend.Models
public string system_remark { get; set; }
public int system_priority { get; set; }
public int system_parent_id { get; set; }
public IFormFile file { get; set; }
public string extName { get; set; }
}
public class PostVariableInfoFilter

View File

@ -510,7 +510,9 @@
},
{
"data": null,
"defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
"render": function (data, type, row, meta){
return '<button bg-guid="'+row.building_tag+'" ms-guid="'+row.main_system_tag+'" ss-guid="'+row.sub_system_tag+'" class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>';
}
}
],
'createdRow': function (row, data, dataIndex) {
@ -886,9 +888,9 @@
$('#buildMenu_table').on("click", "button.edit-btn", function () {
var url = "/BuildMenu/GetBuildMenu";
var send_data = {
building_tag: $(this).parents('tr').attr('bg-guid'),
main_system_tag: $(this).parents('tr').attr('ms-guid'),
sub_system_tag: $(this).parents('tr').attr('ss-guid')
building_tag: $(this).attr('bg-guid'),
main_system_tag: $(this).attr('ms-guid'),
sub_system_tag: $(this).attr('ss-guid')
};
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
@ -1007,10 +1009,11 @@
}
$('#buildMenu_table').on("click", "button.del-btn", function () {
var send_data = {
building_tag: $(this).parents('tr').attr('bg-guid'),
main_system_tag: $(this).parents('tr').attr('ms-guid'),
sub_system_tag: $(this).parents('tr').attr('ss-guid')
building_tag: $(this).attr('bg-guid'),
main_system_tag: $(this).attr('ms-guid'),
sub_system_tag: $(this).attr('ss-guid')
};
Swal.fire(
{
@ -1048,6 +1051,8 @@
});
});
$('#buildMenu_table').on("click", "tbody>tr", function () {
if ($(this).attr('role'))
{
$(this).parents().find('tr').css('background-color', '#fff');
$(this).css('background-color', '#67B4AC');
SelectBuild = $(this).attr('bg-guid');
@ -1060,6 +1065,7 @@
$('#floorcard').show();
$('#floorcard').find('.card-title').html($(this).attr('ms-name') + "-" + $(this).attr('ss-name') + "-樓層設定");
buildMenuFloorTable.ajax.reload(null, false);
}
});
function AddFloor() {
var send_data = {

View File

@ -77,6 +77,10 @@
<label class="form-label" for="variable_system_value_modal"><span class="text-danger">*</span>system_value</label>
<input type="text" id="variable_system_value_modal" class="form-control" name="variable_system_value_modal">
</div>
<div class="form-group col-12" hidden>
<label class="form-label" for="variable_picture_path">圖檔</label>
<input type="file" id="variable_picture_path" class="form-control" name="variable_picture_path" onchange="changeImage(this)">
</div>
<div class="form-group col-12">
<label class="form-label" for="variable_system_remark_modal">備註</label>
<textarea id="variable_system_remark_modal" class="form-control" name="variable_system_remark_modal"></textarea>
@ -104,6 +108,7 @@
@section Scripts {
<script>
var variableTable;
var variableFile = null;
$(function () {
GetSystemTypeList()
@ -134,7 +139,10 @@
},
{
"data": null,
"defaultContent": '<button class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>'
"render": function (data, type, row, meta) {
var name = row.system_type == "logo" ? "pic_edit_btn" : "edit_btn ";
return `<button name="`+ name +`" class="btn btn-primary edit-btn">修改</button> <button class="btn btn-danger del-btn">刪除</button>`;
}
}
],
//"order": [[2, "desc"]],
@ -178,7 +186,7 @@
$("#variable-modal .modal-title").html("系統變數 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
name = $(this).prop('name');
//取得單一系統變數
var url = "/Variable/GetOneVariable/";
@ -186,6 +194,19 @@
id: selected_id
}
if (name == 'pic_edit_btn') {
$('#variable_picture_path').parent().attr('hidden', false);
$('#variable_system_type_modal').attr('disabled', true);
$('#variable_system_key_modal').attr('disabled', true);
$('#variable_system_value_modal').attr('disabled', true);
}
else {
$('#variable_picture_path').parent().attr('hidden', true);
$('#variable_system_type_modal').attr('disabled', false);
$('#variable_system_key_modal').attr('disabled', false);
$('#variable_system_value_modal').attr('disabled', false);
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
@ -293,16 +314,29 @@
$("#save-variable-btn").html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>').attr("disabled", true);
var url = "/Variable/SaveVariable";
var send_data = {
Id: selected_id,
System_type: $("#variable_system_type_modal").val(),
System_key: $("#variable_system_key_modal").val(),
system_value: $("#variable_system_value_modal").val(),
system_remark: $("#variable_system_remark_modal").val(),
system_priority: $("#variable_system_priority_modal").val(),
system_parent_id: $("#variable_system_parent_id_modal").val()
var formData = new FormData();
formData.append("Id", selected_id);
formData.append("System_type", $("#variable_system_type_modal").val());
formData.append("System_key", $("#variable_system_key_modal").val());
formData.append("system_value", $("#variable_system_value_modal").val());
formData.append("system_remark", $("#variable_system_remark_modal").val());
formData.append("system_priority", $("#variable_system_priority_modal").val());
formData.append("system_parent_id", $("#variable_system_parent_id_modal").val());
if (variableFile != null)
{
formData.append("file", variableFile);
formData.append("extName", variableFile.name.split('.')[1]);
}
$.post(url, send_data, function (rel) {
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (rel) {
$("#save-variable-btn").html('確定').attr("disabled", false);
if (rel.code != "0000") {
if (rel.code == "9998") {
@ -316,13 +350,25 @@
$('#variable-modal').modal('hide');
variableTable.ajax.reload();
variableFile = null;
GetSystemTypeList()
}, 'json')
.fail(function (xhr, status, error) {
},
fail: function (xhr, status, error) {
$("#save-variable-btn").html('確定').attr("disabled", false);
}
});
}
}
//#endregion
//#region weblogo
function changeImage(input) {
$(`#variable_picture_path`).attr("data-src", window.URL.createObjectURL(input.files[0]));
variableFile = input.files[0];
console.log(variableFile);
$('#variable_system_key_modal').val(variableFile.name.split('.')[0]);
$('#variable_system_value_modal').val(variableFile.name);
}
//#endregion
</script>
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -31,10 +31,26 @@
<hr>
</div>
<div class="row bg-dark p-2 align-items-center" id="alr_mainList">
<div class="row bg-dark p-2 align-items-center">
<div class="col-auto">
<a href="#" id="selAllSys" onclick="selAllSysVal(this)" class="btn btn-info">全選類別</a>
</div>
<div class="col-auto">
<div id="alr_mainList" class="frame-wrap">
</div>
</div>
</div>
<div class="row bg-dark p-2 mb-5 align-items-center">
<div class="col-auto" style="padding-left: 133px">
<div id="alr_subList" class="frame-wrap">
</div>
</div>
</div>
<!--<div class="row bg-dark p-2 align-items-center" id="alr_mainList">
</div>
<div class="row bg-dark p-2 mb-5 align-items-center" id="alr_subList">
</div>
</div>-->
<div>
<div class="frame-wrap">
@ -182,6 +198,9 @@
pageAct.alr_startdate = null;
pageAct.alr_enddate = null;
pageAct.imageFile = [];
pageAct.alrSelSysMain = []
pageAct.alrSelSysSub = [];
pageAct.selAllSysSub = false;
first = true;
$(function () {
@ -192,39 +211,78 @@
sysList();
$('#nearthirty').click();
$('#alr_mainList').on('click', 'a[data-type=alr_main]', function () {
$(this).parent().parent().find('a').removeClass('btn-info');
$(this).parent().parent().find('a').addClass('btn-secondary');
$(this).addClass('btn-info');
$('a[data-type=alr_sub]').parent().parent().find('a').removeClass('btn-info');
$('a[data-type=alr_sub]').parent().parent().find('a').addClass('btn-secondary');
$('input[type=checkbox][data-type=main]').parent().on('change', function () {
pageAct.main_system_tag = $('input[type=checkbox]').map(function (i, v) {
if ($(v).data('type') == 'main') {
if ($(v).is(':checked')) {
$(`[data-main=` + $(v).prop('id') + `]`).attr('hidden', false);
return $(v).prop('id')
}
else
$(`[data-main=` + $(v).prop('id') + `]`).attr('hidden', true);
}
}).toArray();
pageAct.SysType = null;
});
$('#alr_subList, #alr_mainList').on('click', 'a[data-type=alr_sub][id!=selAllSys]', function () {
pageAct.selSysMain = $(this).parent().data('main');
pageAct.selSysSub = $(this).prop('id');
$('input[type=checkbox][data-type=sub]').on('click', function () {
if (!pageAct.selAllSysSub) {
console.log(this);
pageAct.selAllSysSub = true;
if ($('#selAllSys').hasClass('btn-info')) {
$('#selAllSys').removeClass('btn-info');
$('#selAllSys').addClass('btn-secondary');
$('#alr_mainList a[data-type=alr_main]').removeClass('btn-info');
$('#alr_mainList a[data-type=alr_main]').addClass('btn-secondary');
$(`#alr_mainList a[data-type=alr_main][id=` + pageAct.selSysMain + `]`).addClass('btn-info');
$('#alr_subList a[data-type=alr_sub]').parent().attr('hidden', true);
$('#alr_subList a[data-type=alr_sub]').parent('[data-main=' + pageAct.selSysMain + ']').attr('hidden', false);
$.each($('input[type=checkbox][data-type=sub]:checked'), function (i, v) {
$(v).click();
});
if (pageAct.SysType == "all") {
if (!$(this).is(':checked')) {
$(this).prop('checked', true);
$(this).click();
}
}
pageAct.selAllSysSub = false;
$(this).parent().parent().find('a').removeClass('btn-info');
$(this).parent().parent().find('a').addClass('btn-secondary');
$(this).addClass('btn-info');
$('#selAllSys').html('全選類別');
pageAct.SysType = null;
getData();
}
});
//$('#alr_mainList').on('click', 'a[data-type=alr_main]', function () {
// $(this).parent().parent().find('a').removeClass('btn-info');
// $(this).parent().parent().find('a').addClass('btn-secondary');
// $(this).addClass('btn-info');
// $('a[data-type=alr_sub]').parent().parent().find('a').removeClass('btn-info');
// $('a[data-type=alr_sub]').parent().parent().find('a').addClass('btn-secondary');
// pageAct.SysType = null;
//});
//$('#alr_subList, #alr_mainList').on('click', 'a[data-type=alr_sub][id!=selAllSys]', function () {
// pageAct.selSysMain = $(this).parent().data('main');
// pageAct.selSysSub = $(this).prop('id');
// if ($('#selAllSys').hasClass('btn-info')) {
// $('#selAllSys').removeClass('btn-info');
// $('#selAllSys').addClass('btn-secondary');
// $('#alr_mainList a[data-type=alr_main]').removeClass('btn-info');
// $('#alr_mainList a[data-type=alr_main]').addClass('btn-secondary');
// $(`#alr_mainList a[data-type=alr_main][id=` + pageAct.selSysMain + `]`).addClass('btn-info');
// $('#alr_subList a[data-type=alr_sub]').parent().attr('hidden', true);
// $('#alr_subList a[data-type=alr_sub]').parent('[data-main=' + pageAct.selSysMain + ']').attr('hidden', false);
// }
// $(this).parent().parent().find('a').removeClass('btn-info');
// $(this).parent().parent().find('a').addClass('btn-secondary');
// $(this).addClass('btn-info');
// pageAct.SysType = null;
// getData();
//});
first = false;
});
@ -438,34 +496,62 @@
let mainStrHtml = ``;
let subStrHtml = ``;
let display = pageAct.mainStatus ? "hidden" : "";
let firstSub = '';
let firstMain = '';
if (pageAct.mainStatus) {
mainStrHtml += `<div class="col-auto">
<a href="#" id="selAllSys" onclick="selAllSysVal(this)" class="btn btn-secondary">全部類別</a>
</div>`;
}
else {
subStrHtml += `<div class="col-auto">
<a href="#" id="selAllSys" onclick="selAllSysVal(this)" class="btn btn-secondary">全部類別</a>
</div>`;
}
//if (pageAct.mainStatus) {
// mainStrHtml += `<div class="col-auto">
// <a href="#" id="selAllSys" onclick="selAllSysVal(this)" class="btn btn-secondary">全部類別</a>
// </div>`;
//}
//else {
// subStrHtml += `<div class="col-auto">
// <a href="#" id="selAllSys" onclick="selAllSysVal(this)" class="btn btn-secondary">全部類別</a>
// </div>`;
//}
//$.each(res.data.history_Main_Systems, function (i, v) {
// if (pageAct.mainStatus) {
// mainStrHtml += `<div class="col-auto">
// <a href="#" class="btn btn-secondary" id=${v.main_system_tag} data-type="alr_main">${v.full_name}</a>
// </div>`;
// }
// $.each(v.history_Sub_systems, function (i2, v2) {
// let selected = (i2 == 0 && i == 0) ? "info" : "secondary";
// subStrHtml += `<div class="col-auto" data-main="${v.main_system_tag}" ${display}>
// <a href="#" class="btn btn-${selected}" id="${v2.sub_system_tag}" data-type="alr_sub">${v2.full_name}</a>
// </div>`;
// if (i2 == 0 && i == 0) {
// pageAct.selSysSub = v2.sub_system_tag;
// pageAct.selSysMain = v.main_system_tag;
// }
// });
//});
$.each(res.data.history_Main_Systems, function (i, v) {
if (pageAct.mainStatus) {
mainStrHtml += `<div class="col-auto">
<a href="#" class="btn btn-secondary" id=${v.main_system_tag} data-type="alr_main">${v.full_name}</a>
mainStrHtml += `<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" class="custom-control-input" data-type="main" id="${v.main_system_tag}">
<label class="custom-control-label" for="${v.main_system_tag}">${v.full_name}</label>
</div>`;
pageAct.alrSelSysMain.push(v);
}
$.each(v.history_Sub_systems, function (i2, v2) {
let selected = (i2 == 0 && i == 0) ? "info" : "secondary";
subStrHtml += `<div class="col-auto" data-main="${v.main_system_tag}" ${display}>
<a href="#" class="btn btn-${selected}" id="${v2.sub_system_tag}" data-type="alr_sub">${v2.full_name}</a>
var firDis = (i == 0) ? "" : display;
subStrHtml += `<div class="custom-control custom-checkbox custom-control-inline" data-main="${v.main_system_tag}" ${firDis}>
<input type="checkbox" class="custom-control-input" data-type="sub" id="${v2.sub_system_tag}">
<label class="custom-control-label" for="${v2.sub_system_tag}">${v2.full_name}</label>
</div>`;
pageAct.alrSelSysSub.push(v2);
if (i2 == 0 && i == 0) {
pageAct.selSysSub = v2.sub_system_tag;
pageAct.selSysMain = v.main_system_tag;
firstMain = v.main_system_tag;
firstSub = v2.sub_system_tag;
}
});
});
@ -473,37 +559,61 @@
if (pageAct.mainStatus) {
$('#alr_mainList').html(mainStrHtml);
$('#alr_subList').html(subStrHtml);
$('input[data-type=main][id=' + firstMain + ']').click();
}
else {
$('#alr_mainList').html(subStrHtml);
}
$('input[data-type=sub][id=' + firstSub + ']').click();
}
ytAjax = new YourTeam.Ajax(url, objSendData, success, null, "POST").send();
}
function selAllSysVal(elem) {
$(elem).parent().parent().find('a').removeClass('btn-secondary');
$(elem).parent().parent().find('a').addClass('btn-info');
if ($('a[data-type=alr_sub]').length > 0) {
$('a[data-type=alr_sub]').parent().attr('hidden', false);
$('a[data-type=alr_sub]').parent().parent().find('a').removeClass('btn-secondary');
$('a[data-type=alr_sub]').parent().parent().find('a').addClass('btn-info');
$(loadEle).Loading("start");
pageAct.selAllSysSub = true;
if ($(elem).html() == '全選類別') {
$('#alr_mainList input').map(function (i, v) {
if (!$(v).is(':checked')) {
$(v).click();
}
});
$('#alr_subList input').map(function (i, v) {
if (!$(v).is(':checked')) {
$(v).click();
}
});
$(elem).html('取消全選');
pageAct.SysType = 'all';
}
else {
$('#alr_mainList input').map(function (i, v) {
if ($(v).is(':checked'))
$(v).click();
});
$('#alr_subList input').map(function (i, v) {
if ($(v).is(':checked'))
$(v).click();
});
$(elem).html('全選類別');
pageAct.SysType = null;
}
pageAct.SysType = 'all';
getData();
pageAct.selAllSysSub = false;
}
function getData(type = null) {
$(loadEle).Loading("start");
let enddate = new Date(new Date().setDate(new Date(pageAct.alr_enddate).getDate() + 1)).getTime();
if (pageAct.SysType == "all") {
getAllDeviceAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, callBackFromAllDeviceAlert);
}
else {
let elem = $('input[type=checkbox][data-type=sub]:checked');
pageAct.selSysMain = $(elem).parent().data('main');
pageAct.selSysSub = $(elem).prop('id');
getAlarmByBaja(new Date(pageAct.alr_startdate).getTime(), enddate, pageAct.return, pageAct.confirm, pageAct.selSysMain + "_" + pageAct.selSysSub + "_AlarmClass", callBackFromOneDeviceAlert);
}
}

View File

@ -1484,6 +1484,13 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
}, null, "POST").send();
}
function getLogo() {
url = baseApiUrl + '/api/GetLogo';
ytAjax = new YourTeam.Ajax(url, null, function (res) {
$('[name=webLogo]').attr('src', baseImgUrl + '/img/' + res.data);
}, null, "POST").send();
}
function getUserInfo() {
let url = baseApiUrl + varApiUrl + "getUserFull";

View File

@ -251,7 +251,7 @@
url: baseApiUrl + '/api/GetLogo',
async: false,
success: function (rel) {
$('[name=webLogo]').attr('src', 'img/' + rel);
$('[name=webLogo]').attr('src', baseImgUrl + '/img/' + rel.data);
}
})
}