12. Given the function $f(x)=x|x-2a|$. Try to find the maximum value $g(a)$ of $f(x)$ on the interval $[0,1]$.
12. When $x \in[0,1]$,
$$
\begin{array}{l}
f(x)=x|x-2 a|=\left|x^{2}-2 a x\right| \\
=\left|(x-a)^{2}-a^{2}\right| .
\end{array}
$$

Let $h(x)=(x-a)^{2}-a^{2}$.
(1) $a \leqslant 0$.

Then $h(x)$ is an increasing function on the interval $[0,1]$, and $h(x) \geqslant 0$, at this time, $g(a)=h(1)=1-2 a$.
(2) $a \geqslant 1$.
Then $h(x)$ is a decreasing function on the interval $[0,1]$, and $h(x) \leqslant 0$, at this time, $g(a)=-h(1)=2 a-1$.
(3) $0<|1-2 a| \text {. }$
$$

Thus, when $0<a<\sqrt{2}-1$, $g(a)=1-2 a$;
when $\sqrt{2}-1 \leqslant a<1$, $g(a)=a^{2}$.
In summary, we have
$$
g(a)=\left\{\begin{array}{ll}
1-2 a, & a<\sqrt{2}-1 ; \\
a^{2}, & \sqrt{2}-1 \leqslant a<1 ; \\
2 a-1, & a \geqslant 1 .
\end{array}\right.
$$