Skip to content

Commit

Permalink
产品类别没有必填提示 #515
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne-KTCSZ committed Aug 30, 2024
1 parent 1bfba28 commit 39ce85a
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 58 deletions.
7 changes: 4 additions & 3 deletions src/ZKEACMS.Product/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ public JsonResult Sort([FromBody] IEnumerable<ProductEntity> products)
}
public JsonResult GetProducts(int ProductCategoryID)
{
var ids = _productCategoryService.Get(m => m.ParentID == ProductCategoryID || m.ID == ProductCategoryID).Select(m => m.ID);
return Json(Service.Get(m => ids.Contains(m.ProductCategoryID))
var ids = _productCategoryService.Get(m => m.ParentID == ProductCategoryID || m.ID == ProductCategoryID).Select(m => m.ID).ToArray();
return Json(Service.Get(m => ids.Contains(m.ProductCategoryID ?? 0))
.OrderBy(m => m.OrderIndex)
.ThenByDescending(m => m.ID).Select(m => new { m.ID, m.Title }));
.ThenByDescending(m => m.ID)
.Select(m => new { m.ID, m.Title }));
}
[HttpPost]
public IActionResult ProduceTags(int productId, int ProductCategoryId)
Expand Down
2 changes: 1 addition & 1 deletion src/ZKEACMS.Product/Service/ProductListWidgetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override object Display(WidgetDisplayContext widgetDisplayContext)
else
{
var ids = _productCategoryService.Get(m => m.ID == currentWidget.ProductCategoryID || m.ParentID == currentWidget.ProductCategoryID).Select(m => m.ID).ToList();
filter = m => m.Status == (int)RecordStatus.Active && m.IsPublish && ids.Contains(m.ProductCategoryID);
filter = m => m.Status == (int)RecordStatus.Active && m.IsPublish && ids.Contains(m.ProductCategoryID ?? 0);
}
if (currentWidget.IsPageable)
{
Expand Down
6 changes: 3 additions & 3 deletions src/ZKEACMS.Product/Service/ProductUrlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IEnumerable<ProductUrl> GetAllPublicUrls()
if (item.DetailPageUrl.IsNotNullAndWhiteSpace() && !excuted.Contains(typeDetail))
{
var ids = _productCategoryService.Get(m => m.ID == item.ProductCategoryID || m.ParentID == item.ProductCategoryID).Select(m => m.ID).ToList();
var products = _productService.Get(m => m.IsPublish && ids.Contains(m.ProductCategoryID));
var products = _productService.Get(m => m.IsPublish && ids.Contains(m.ProductCategoryID ?? 0));
foreach (var product in products)
{
string post = product.Url.IsNullOrWhiteSpace() ? $"post-{product.ID}" : product.Url;
Expand Down Expand Up @@ -66,8 +66,8 @@ public string[] GetPublicUrl(int ID)

public string[] GetPublicUrl(ProductEntity product)
{
int categoryId = product.ProductCategoryID;
if (categoryId == 0) return null;
var categoryId = product.ProductCategoryID;
if ((categoryId ?? 0) == 0) return null;

ProductCategory productCategory = _productCategoryService.Get(categoryId);

Expand Down
6 changes: 6 additions & 0 deletions src/ZKEACMS.WebHost/DefaultResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ protected override void InitScript(Func<string, ResourceHelper> script)
script("mammoth")
.Include($"{LibraryPath}/mammoth/mammoth.browser.js", $"{LibraryPath}/mammoth/mammoth.browser.min.js");

script("dropdown-tree")
.Include($"{ScriptPath}/dropdown-tree.js", $"{ScriptPath}/dropdown-tree.min.js");

script("code-editor")
.Include($"{LibraryPath}/monaco/min/vs/loader.js")
.Include($"{LibraryPath}/monaco/code-editor.js", $"{LibraryPath}/monaco/code-editor.min.js");
Expand Down Expand Up @@ -160,6 +163,9 @@ protected override void InitStyle(Func<string, ResourceHelper> style)

style("captcha")
.Include($"{StylePath}/captcha.css", $"{StylePath}/captcha.min.css");

style("dropdown-tree")
.Include($"{StylePath}/dropdown-tree.css", $"{StylePath}/dropdown-tree.min.css");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@
@{
var descriptor = ViewData.ModelMetadata.GetViewDescriptor();
Script.Reqiured("jsTree").AtFoot();
Script.Reqiured("dropdown-tree").AtFoot();
Style.Reqiured("jsTree").AtHead();
Style.Reqiured("dropdown-tree").AtHead();
var categoryTree = Html.Tree<ArticleType>().Source("GetArticleTypeTree", "ArticleType", new { module = "admin" })
.On(Events.Loaded, "loadedArticleType")
.On(Events.ActiveNode, "activedArticleType");
.On(Events.Loaded, "dropdownTreeLoaded")
.On(Events.ActiveNode, "dropdownTreeSelectted");

string dropdownId = $"dropdown-tree-{Html.IdForModel()}";
}
<div class="input-group article-type-tree">
@Html.Hidden("", Model, descriptor?.ToHtmlProperties())
@categoryTree
</div>
@using (Script.AtFoot())
{
<script type="text/javascript">
function loadedArticleType(p) {
var category = $("input[type=hidden]", ".article-type-tree").val();
if (!category || category=="0") {
category = $(".jstree-node:first a.jstree-anchor:first", p.target).attr("id");
$("input[type=hidden]", ".article-type-tree").val(category);
}
$(p.target).jstree('select_node', category);
}
function activedArticleType(node, selected) {
$("input[name=@(ViewData.TemplateInfo.GetFullHtmlFieldName(""))]", ".article-type-tree").val(selected.node.id);
}
</script>
}
<div class="dropdown-tree">
<div class="dropdown">
<div class="dropdown-toggle" type="button" id="@dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="form-control @(descriptor.IsRequired?"required":"")"></div>
<span class="caret"></span>
</div>
<div class="dropdown-menu" aria-labelledby="@dropdownId">
@categoryTree
</div>
@Html.TextBox("", Model, descriptor?.ToHtmlProperties())
</div>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@
@{
var descriptor = ViewData.ModelMetadata.GetViewDescriptor();
Script.Reqiured("jsTree").AtFoot();
Script.Reqiured("dropdown-tree").AtFoot();
Style.Reqiured("jsTree").AtHead();
Style.Reqiured("dropdown-tree").AtHead();
var categoryTree = Html.Tree<ProductCategory>().Source("GetProductCategoryTree", "ProductCategory", new { module = "admin" })
.On(Events.Loaded, "loadedProductCategory")
.On(Events.ActiveNode, "activedProductCategory");
.On(Events.Loaded, "dropdownTreeLoaded")
.On(Events.ActiveNode, "dropdownTreeSelectted");

string dropdownId = $"dropdown-tree-{Html.IdForModel()}";
}
<div class="input-group product-category-tree">
@Html.Hidden("", Model, descriptor?.ToHtmlProperties())
@categoryTree
</div>
@using (Script.AtFoot())
{
<script type="text/javascript">
function loadedProductCategory(p) {
var category = $("input[type=hidden]", ".product-category-tree").val();
if (!category || category == "0") {
category = $(".jstree-node:first a.jstree-anchor:first", p.target).attr("id");
$("input[type=hidden]", ".product-category-tree").val(category);
}
$(p.target).jstree('select_node', category);
}
function activedProductCategory(node, selected) {
$("input[name=@(ViewData.TemplateInfo.GetFullHtmlFieldName(""))]", ".product-category-tree").val(selected.node.id)
}
</script>
}
<div class="dropdown-tree">
<div class="dropdown">
<div class="dropdown-toggle" type="button" id="@dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="form-control @(descriptor.IsRequired?"required":"")"></div>
<span class="caret"></span>
</div>
<div class="dropdown-menu" aria-labelledby="@dropdownId">
@categoryTree
</div>
@Html.TextBox("", Model, descriptor?.ToHtmlProperties())
</div>
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
12 changes: 12 additions & 0 deletions src/ZKEACMS.WebHost/bundleconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,17 @@
"inputFiles": [
"wwwroot/lib/monaco/code-editor.js"
]
},
{
"outputFileName": "wwwroot/js/dropdown-tree.min.js",
"inputFiles": [
"wwwroot/js/dropdown-tree.js"
]
},
{
"outputFileName": "wwwroot/css/dropdown-tree.min.css",
"inputFiles": [
"wwwroot/css/dropdown-tree.css"
]
}
]
2 changes: 1 addition & 1 deletion src/ZKEACMS.WebHost/wwwroot/css/captcha.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions src/ZKEACMS.WebHost/wwwroot/css/dropdown-tree.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.dropdown-tree {
position: relative;
}

.dropdown-tree .close {
position: absolute;
right: 17px;
top: 7px;
display: none;
}

.dropdown-tree.selected .close {
display: block;
}

.dropdown-tree input.form-control {
border: 0 !important;
clip: rect(0 0 0 0) !important;
-webkit-clip-path: inset(50%) !important;
clip-path: inset(50%) !important;
height: 1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
white-space: nowrap !important;
}

.dropdown-tree .caret {
position: absolute;
right: 5px;
top: 16px;
}

.dropdown-tree .open .caret {
transform: rotate(180deg);
}

.dropdown-tree .dropdown-toggle .form-control {
padding-right: 35px;
min-width: 160px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
cursor: default;
}

.dropdown-tree .dropdown-menu {
padding-right: 10px;
}
1 change: 1 addition & 0 deletions src/ZKEACMS.WebHost/wwwroot/css/dropdown-tree.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ZKEACMS.WebHost/wwwroot/css/site.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 39ce85a

Please sign in to comment.