фича: числа с разделением по тысячам

This commit is contained in:
2025-01-21 15:41:10 +03:00
parent 2c2cbf4249
commit 073bf43d8b
7 changed files with 118 additions and 44 deletions

View File

@@ -154,8 +154,8 @@
"values": [{"label": "Ethernet", "value": "false"}, {"label": "Тест", "value": "true"}]
},
{"widget": "h3", "label": "Параметры передачи"},
{"widget": "number", "label": "Центральная частота, КГц", "name": "txCentralFreq", "min": 900000, "step": 0.01},
{"widget": "number", "label": "Символьная скорость, Бод", "name": "txBaudrate", "min": 0, "step": 1},
{"widget": "number-int", "label": "Центральная частота, КГц", "name": "txCentralFreq", "min": 950000, "max": 6000000},
{"widget": "number-int", "label": "Символьная скорость, Бод", "name": "txBaudrate", "min": 200000, "max": 54000000},
{
"widget": "select", "label": "Roll-off", "name": "txRolloff",
"values": [{"label": "0.02", "value": "2"}, {"label": "0.05", "value": "5"}, {"label": "0.10", "value": "10"}, {"label": "0.15", "value": "15"}, {"label": "0.20", "value": "20"}, {"label": "0.25", "value": "25"}]
@@ -214,8 +214,8 @@
{"widget": "number", "label": "Усиление, дБ", "name": "rxManualGain", "min": -40, "step": 0.01, "max": 40, "v_show": "paramRxtx.rxAgcEn === false"},
{"widget": "watch-expr", "label": "Текущее усиление", "expr": "paramRxtx.rxManualGain", "v_show": "paramRxtx.rxAgcEn === true"},
{"widget": "checkbox", "label": "Инверсия спектра", "name": "rxSpectrumInversion"},
{"widget": "number", "label": "Центральная частота, КГц", "name": "rxCentralFreq", "min": 900000, "step": 0.01},
{"widget": "number", "label": "Символьная скорость, Бод", "name": "rxBaudrate", "min": 0, "step": 1},
{"widget": "number-int", "label": "Центральная частота, КГц", "name": "rxCentralFreq", "min": 950000, "max": 6000000},
{"widget": "number-int", "label": "Символьная скорость, Бод", "name": "rxBaudrate", "min": 200000, "max": 54000000},
{
"widget": "select", "label": "Roll-off", "name": "rxRolloff",
"values": [{"label": "0.02", "value": "2"}, {"label": "0.05", "value": "5"}, {"label": "0.10", "value": "10"}, {"label": "0.15", "value": "15"}, {"label": "0.20", "value": "20"}, {"label": "0.25", "value": "25"}]

View File

@@ -17,15 +17,22 @@ def extract_param_names(mc):
r += helper_extract(child)
return r
elif 'name' in widget:
copy_fields = {"widget": widget['widget'], "name": widget['name']}
if 'min' in widget:
copy_fields['min'] = widget['min']
if 'max' in widget:
copy_fields['max'] = widget['max']
match widget['widget']:
case 'select': return [{"name": widget['name'], "initValue": widget['values'][0]['value']}]
case 'checkbox': return [{"name": widget['name'], "initValue": 'false'}]
case 'number': return [{"name": widget['name'], "initValue": widget['min'] if widget['min'] else '0'}]
case 'modulation-modcod': return [{"name": widget['name'] + "Modulation", "initValue": '"QPSK"'}]
case 'modulation-speed': return [{"name": widget['name'] + "Speed", "initValue": '"1/4"'}]
case 'select': return [{"initValue": widget['values'][0]['value']} | copy_fields]
case 'checkbox': return [{"initValue": 'false'} | copy_fields]
case 'number': return [{"initValue": widget['min'] if widget['min'] else '0'} | copy_fields]
case 'number-int': return [{"initValue": "0"} | copy_fields]
case 'modulation-modcod': return [{"name": widget['name'] + "Modulation", "initValue": '"QPSK"'} | copy_fields]
case 'modulation-speed': return [{"name": widget['name'] + "Speed", "initValue": '"1/4"'} | copy_fields]
case 'watch': return []
return [{"name": widget['name'], "initValue": 'null'}]
return [{"initValue": 'null'} | copy_fields]
return []
for cat in mc['params']:

View File

@@ -1,3 +1,4 @@
{% from 'common/widgets.j2' import build_getter_js, build_setter_js %}
{% for g in paramGroups %}
settingsSubmit{{ g['group'] | title }}() {
if (this.submitStatus.{{ g['group'] }}) { return }
@@ -7,7 +8,7 @@
let query = {
{% for p in g['params'] %}
"{{ p['name'] }}": this.param{{ g['group'] | title }}.{{ p['name'] }},
"{{ p['name'] }}": {{ build_getter_js(g['group'], p) }},
{% endfor %}
}
@@ -23,7 +24,7 @@
update{{ g['group'] | title }}Settings(vals) {
this.submitStatus.{{ g['group'] }} = false
{% for p in g['params'] %}
this.param{{ g['group'] | title }}.{{ p['name'] }} = vals["settings"]["{{ p['name'] }}"]
{{ build_setter_js(g['group'], p, "vals[\"settings\"][\"" ~ p['name'] ~ "\"]") }}
{% endfor %}
},
{% endfor %}

View File

@@ -6,6 +6,14 @@
{# https://ru.stackoverflow.com/questions/1241064 #}
{% macro build_widget_number(param_group, widget) %}<label{% if widget.v_show %} v-show="{{ widget.v_show }}"{% endif %}><span>{{ widget.label }}</span><input type="number" v-model="param{{ param_group | title }}.{{ widget.name }}"{% if widget['min'] %} min="{{ widget['min'] }}"{% endif %}{% if widget['max'] %} max="{{ widget['max'] }}"{% endif %}{% if widget['step'] %} step="{{ widget['step'] }}"{% endif %}/></label>{% endmacro %}
{% macro js_build_number_int_validator(widget) %}{{ '{' }}{% if widget['min'] %}min:{{ widget['min'] }},{% endif %}{% if widget['max'] %}max:{{ widget['max'] }}{% endif %}{{ '}' }}{% endmacro %}
{% macro build_widget_number_int(param_group, widget) %}<label{% if widget.v_show %} v-show="{{ widget.v_show }}"{% endif %}>
<span>{{ widget.label }}</span>
<input type="text" v-model.lazy="param{{ param_group | title }}.{{ widget.name }}" @change="e => {{ build_setter(param_group, widget, "inputFormatInt(e.target.value, " ~ js_build_number_int_validator(widget) ~ ")") }}"/>
</label>{% endmacro %}
{% macro build_widget_select(param_group, widget) %}<label{% if widget.v_show %} v-show="{{ widget.v_show }}"{% endif %}>
<span>{{ widget.label }}</span>
<select v-model="param{{ param_group | title }}.{{ widget.name }}">
@@ -58,6 +66,7 @@
{% elif widget.widget == 'submit' %}<button class="action-button" @click="settingsSubmit{{ param_group | title }}()"{% if widget.v_show %} v-show="{{ widget.v_show }}"{% endif %}>Сохранить <span class="submit-spinner" v-show="submitStatus.{{ param_group }}"></span></button>
{% elif widget.widget == 'checkbox' %}{{ build_widget_checkbox(param_group, widget) }}
{% elif widget.widget == 'number' %}{{ build_widget_number(param_group, widget) }}
{% elif widget.widget == 'number-int' %}{{ build_widget_number_int(param_group, widget) }}
{% elif widget.widget == 'watch' %}{{ build_widget_watch(param_group, widget) }}
{% elif widget.widget == 'watch-expr' %}{{ build_widget_watch_expr(param_group, widget) }}
{% elif widget.widget == 'select' %}{{ build_widget_select(param_group, widget) }}
@@ -67,3 +76,24 @@
{% else %}<p>Widget '{{ widget.widget }}' not defined!</p><p>{{ widget }}</p>
{% endif %}
{% endmacro %}
{% macro build_getter_js(param_group, widget) %}{% if widget.widget in ['flex-container', 'settings-container', 'h2', 'h3', 'submit', 'watch', 'watch-expr'] %}null{%
elif widget.widget == 'checkbox' or widget.widget == 'number' or widget.widget == 'select' or widget.widget == 'ip-address' %}this.param{{ param_group | title }}.{{ widget.name }}{%
elif widget.widget == 'modulation-modcod' %}this.param{{ param_group | title }}.{{ widget.name }}Modulation{%
elif widget.widget == 'modulation-speed' %}this.param{{ param_group | title }}.{{ widget.name }}Speed{%
elif widget.widget == 'number-int' %}parseInt(this.param{{ param_group | title }}.{{ widget.name }}.replace(/[^0-9]/g, '')){%
else %}<p>Widget '{{ widget.widget }}' not defined!</p><p>{{ widget }}</p>{% endif %}{% endmacro %}
{% macro build_setter_js(param_group, widget, expr) %}{% if widget.widget in ['flex-container', 'settings-container', 'h2', 'h3', 'submit', 'watch', 'watch-expr'] %}null{%
elif widget.widget in ['checkbox', 'number', 'select', 'ip-address'] %}this.param{{ param_group | title }}.{{ widget.name }} = {{ expr }}{%
elif widget.widget == 'modulation-modcod' %}this.param{{ param_group | title }}.{{ widget.name }}Modulation = {{ expr }}{%
elif widget.widget == 'modulation-speed' %}this.param{{ param_group | title }}.{{ widget.name }}Speed = {{ expr }}{%
elif widget.widget == 'number-int' %}this.param{{ param_group | title }}.{{ widget.name }} = this.inputFormatInt({{ expr }}, {{ js_build_number_int_validator(widget) }}){%
else %}<p>Widget '{{ widget.widget }}' not defined!</p><p>{{ widget }}</p>{% endif %}{% endmacro %}
{% macro build_setter(param_group, widget, expr) %}{% if widget.widget in ['flex-container', 'settings-container', 'h2', 'h3', 'submit', 'watch', 'watch-expr'] %}null{%
elif widget.widget in ['checkbox', 'number', 'select', 'ip-address'] %}param{{ param_group | title }}.{{ widget.name }} = {{ expr }}{%
elif widget.widget == 'modulation-modcod' %}param{{ param_group | title }}.{{ widget.name }}Modulation = {{ expr }}{%
elif widget.widget == 'modulation-speed' %}param{{ param_group | title }}.{{ widget.name }}Speed = {{ expr }}{%
elif widget.widget == 'number-int' %}param{{ param_group | title }}.{{ widget.name }} = ({{ expr }}).toString(){%
else %}<p>Widget '{{ widget.widget }}' not defined!</p><p>{{ widget }}</p>{% endif %}{% endmacro %}

View File

@@ -153,6 +153,14 @@
return []
}
},
inputFormatInt(src, validation) {
if (validation === null || validation === undefined) { validation = {} }
const rawVal = src.toString().replace(/[^0-9]/g, '')
let result = rawVal === '' ? 0 : parseInt(rawVal)
if ('min' in validation) { if (result <= validation['min']) { result = validation['min'] } }
if ('max' in validation) { if (result >= validation['max']) { result = validation['max'] } }
return result.toLocaleString()
},
// ========== include from 'common/all-params-methods.js.j2'
{% include 'common/all-params-methods.js.j2' %}