fix: Jinja2变量避免"转义, script用save_url+disc_id模板变量

This commit is contained in:
yumoqing 2026-06-29 16:35:13 +08:00
parent 885b915d28
commit 817cb354da

View File

@ -1,4 +1,6 @@
{% set products = get_discount_setting_products(request) %} {% set products = get_discount_setting_products(request) %}
{% set save_url = entire_url('./save_discount.dspy') %}
{% set disc_id = params_kw.discountid %}
{ {
"widgettype": "VBox", "widgettype": "VBox",
"options": { "options": {
@ -47,46 +49,46 @@
}, },
"subwidgets": [ "subwidgets": [
{% for p in products %} {% for p in products %}
{
"widgettype": "HBox",
"options": {
"padding": "6px 0",
"border": "0 0 1px 0",
"borderColor": "#334155",
"alignItems": "center",
"width": "100%"
},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "{{p.category_name or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
{"widgettype": "Text", "options": {"text": "{{p.product_name or ''}}", "width": "34%", "padding": "0 12px", "fontSize": "12px", "color": "#F1F5F9"}},
{"widgettype": "Text", "options": {"text": "{{p.product_code or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
{ {
"widgettype": "UiFloat", "widgettype": "HBox",
"options": { "options": {
"width": "22%", "padding": "6px 0",
"padding": "0 12px", "border": "0 0 1px 0",
"name": "discount", "borderColor": "#334155",
"value": "{{p.discount or ''}}", "alignItems": "center",
"placeholder": "0~1", "width": "100%"
"dec_len": 2,
"fontSize": "12px"
}, },
"binds": [ "subwidgets": [
{"widgettype": "Text", "options": {"text": "{{p.category_name or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
{"widgettype": "Text", "options": {"text": "{{p.product_name or ''}}", "width": "34%", "padding": "0 12px", "fontSize": "12px", "color": "#F1F5F9"}},
{"widgettype": "Text", "options": {"text": "{{p.product_code or ''}}", "width": "22%", "padding": "0 12px", "fontSize": "12px", "color": "#E2E8F0"}},
{ {
"wid": "self", "widgettype": "UiFloat",
"event": "blur", "options": {
"actiontype": "script", "width": "22%",
"target": "self", "padding": "0 12px",
"script": "var v=this.target.dom_element.querySelector('input');if(!v)return;var nv=v.value;fetch('{{entire_url(\"./save_discount.dspy\")}}',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({discountid:'{{params_kw.discountid}}',productid:'{{p.productid}}',detail_id:'{{p.detail_id or ''}}',discount:nv})}).then(function(r){return r.json()}).then(function(r){if(r.widgettype==='Error')bricks.show_error(r.options)}).catch(function(e){console.error(e)})" "name": "discount",
"value": "{{p.discount or ''}}",
"placeholder": "0~1",
"dec_len": 2,
"fontSize": "12px"
},
"binds": [
{
"wid": "self",
"event": "blur",
"actiontype": "script",
"target": "self",
"script": "var inp=this.target.dom_element.querySelector('input');if(!inp)return;var nv=inp.value;fetch('{{save_url}}',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({discountid:'{{disc_id}}',productid:'{{p.productid}}',detail_id:'{{p.detail_id or ""}}',discount:nv})}).then(function(r){return r.json()}).then(function(r){if(r.widgettype==='Error')bricks.show_error(r.options)}).catch(function(e){console.error(e)})"
}
]
} }
] ]
} }{% if not loop.last %},{% endif %}
]
}{% if not loop.last %},{% endif %}
{% endfor %} {% endfor %}
]
}
] ]
} }
] ]
}
]
} }