Example 6. When $|x+1| \leqslant 6$, the maximum value of the function $y=x|x|$ $-2 x+1$ is $\qquad$. (1994, National Junior High School Competition)
Solve: From $|x+1| \leqslant 6$ we get $-7 \leqslant x \leqslant 5$.
When $0 \leqslant x \leqslant 5$,
$$
y=x^{2}-2 x+1=(x-1)^{2} \text {. }
$$

Since $x=1 \in[0,5]$, and $1>\frac{-7+0}{2}, \\
\therefore y_{\text {max }}=f(5)=(5-1)^{2}=16; \\
y_{\text {min }}=f(1)=(1-1)^{2}=0 .
$$

When $-7 \leqslant x < 0$,
$$
y=x^{2}+2 x+1=(x+1)^{2} \text {. }
$$

Since $x=-1 \in[-7,0]$, and $-1>\frac{-7+0}{2}, \\
\therefore y_{\text {min }}=f(-1)=(-1+1)^{2}=0; \\
y_{\text {max }}=f(-7)=(-7+1)^{2}=36 .
$$

Comprehensive analysis shows that when $x=5$, $y$ reaches $16$.
(2) The maximum and minimum values of a quadratic function on a moving interval

Since $x=-\frac{b}{2 a}$ is fixed, such problems can be discussed in cases based on whether the moving interval $t \leqslant x \leqslant t^{\prime}$ includes $x=-\frac{b}{2 a}$.
$1^{\circ}$ The moving interval includes $x=-\frac{b}{2 a}$;
$2^{\circ}$ The moving interval does not include $x=-\frac{b}{2 a}$, and is to the left of $x=-\frac{b}{2 a}$;
$3^{\circ}$ The moving interval does not include $x=-\frac{b}{2 a}$, and is to the right of $x=-\frac{b}{2 a}$.