{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 分步器\n", "\n", "这个元素代表了 Quasar 的 [QStepper 组件](https://quasar.dev/vue-components/stepper#qstepper-api)。它包含各个独立的步骤。\n", "\n", "为了避免在切换步骤时出现动态元素的问题,这个元素使用了 Vue 的 keep-alive 组件。如果客户端性能是一个问题,您可以禁用此功能。\n", "\n", "`value`:ui.step 或最初选择的步骤的名称(默认:`None`,表示第一步)\n", "`on_value_change`:当选定的步骤发生变化时要执行的回调函数\n", "`keep_alive`:是否在内容上使用 Vue 的 keep-alive 组件(默认:`True`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.stepper().props('vertical').classes('w-full') as stepper:\n", " with ui.step('Preheat'):\n", " ui.label('Preheat the oven to 350 degrees')\n", " with ui.stepper_navigation():\n", " ui.button('Next', on_click=stepper.next)\n", " with ui.step('Ingredients'):\n", " ui.label('Mix the ingredients')\n", " with ui.stepper_navigation():\n", " ui.button('Next', on_click=stepper.next)\n", " ui.button('Back', on_click=stepper.previous).props('flat')\n", " with ui.step('Bake'):\n", " ui.label('Bake for 20 minutes')\n", " with ui.stepper_navigation():\n", " ui.button('Done', on_click=lambda: ui.notify('Yay!', type='positive'))\n", " ui.button('Back', on_click=stepper.previous).props('flat')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 动态分步器\n", "\n", "步骤可以动态添加,并通过 `ui.move()` 定位。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "def next_step() -> None:\n", " if extra_step.value and len(stepper.default_slot.children) == 2:\n", " with stepper:\n", " with ui.step('extra') as extra:\n", " ui.label('Extra')\n", " with ui.stepper_navigation():\n", " ui.button('Back', on_click=stepper.previous).props('flat')\n", " ui.button('Next', on_click=stepper.next)\n", " extra.move(target_index=1)\n", " stepper.next()\n", "\n", "with ui.stepper().props('vertical').classes('w-full') as stepper:\n", " with ui.step('start'):\n", " ui.label('Start')\n", " extra_step = ui.checkbox('do extra step')\n", " with ui.stepper_navigation():\n", " ui.button('Next', on_click=next_step)\n", " with ui.step('finish'):\n", " ui.label('Finish')\n", " with ui.stepper_navigation():\n", " ui.button('Back', on_click=stepper.previous).props('flat')\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }